Skip to content

Commit 683d7c7

Browse files
fix: using canonized addr in xe kmd
Related-To: NEO-7313 Signed-off-by: Wojciech Konior <[email protected]>
1 parent 546e8fa commit 683d7c7

File tree

6 files changed

+49
-9
lines changed

6 files changed

+49
-9
lines changed

level_zero/tools/source/debug/linux/debug_session.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ ze_result_t DebugSessionLinux::readGpuMemory(uint64_t vmHandle, char *output, si
315315

316316
int64_t retVal = 0;
317317
auto gmmHelper = connectedDevice->getNEODevice()->getGmmHelper();
318-
gpuVa = gmmHelper->decanonize(gpuVa);
318+
gpuVa = gmmHelper->canonize(gpuVa);
319319
if (flushVmCache(vmDebugFd) != 0) {
320320
return ZE_RESULT_ERROR_UNKNOWN;
321321
}
@@ -377,7 +377,7 @@ ze_result_t DebugSessionLinux::writeGpuMemory(uint64_t vmHandle, const char *inp
377377

378378
int64_t retVal = 0;
379379
auto gmmHelper = connectedDevice->getNEODevice()->getGmmHelper();
380-
gpuVa = gmmHelper->decanonize(gpuVa);
380+
gpuVa = gmmHelper->canonize(gpuVa);
381381
if (flushVmCache(vmDebugFd) != 0) {
382382
return ZE_RESULT_ERROR_UNKNOWN;
383383
}

level_zero/tools/source/debug/linux/prelim/debug_session.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2022-2024 Intel Corporation
2+
* Copyright (C) 2022-2025 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -641,8 +641,8 @@ bool DebugSessionLinuxi915::handleVmBindEvent(prelim_drm_i915_debug_event_vm_bin
641641
std::unique_lock<std::mutex> memLock(asyncThreadMutex);
642642
isaMap[vmBind->va_start] = std::move(isa);
643643

644-
// Expect non canonical va_start
645-
DEBUG_BREAK_IF(gmmHelper->decanonize(vmBind->va_start) != vmBind->va_start);
644+
// Expect canonical va_start
645+
DEBUG_BREAK_IF(gmmHelper->canonize(vmBind->va_start) != vmBind->va_start);
646646

647647
bool apiEventNeedsAck = (vmBind->base.flags & PRELIM_DRM_I915_DEBUG_EVENT_NEED_ACK);
648648
// If ACK flag is not set when triggering MODULE LOAD event, auto-ack immediately

level_zero/tools/source/debug/linux/xe/debug_session.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,13 +466,15 @@ bool DebugSessionLinuxXe::handleVmBind(VmBindData &vmBindData) {
466466
if (vmBindOp.base.flags & euDebugInterface->getParamValue(NEO::EuDebugParam::eventBitCreate)) {
467467
{
468468
std::lock_guard<std::mutex> lock(asyncThreadMutex);
469+
469470
if (metaDataEntry.metadata.type == euDebugInterface->getParamValue(NEO::EuDebugParam::metadataSbaArea)) {
470471
connection->vmToStateBaseAreaBindInfo[vmBindData.vmBind.vmHandle] = {vmBindOp.addr, vmBindOp.range};
471472
}
472473
if (metaDataEntry.metadata.type == euDebugInterface->getParamValue(NEO::EuDebugParam::metadataSipArea)) {
473474
connection->vmToContextStateSaveAreaBindInfo[vmBindData.vmBind.vmHandle] = {vmBindOp.addr, vmBindOp.range};
474475
}
475476
if (metaDataEntry.metadata.type == euDebugInterface->getParamValue(NEO::EuDebugParam::metadataModuleArea)) {
477+
476478
isaAddr = vmBindOp.addr;
477479
if (connection->isaMap[tileIndex].find(vmBindOp.addr) == connection->isaMap[tileIndex].end()) {
478480
auto &isaMap = connection->isaMap[tileIndex];

shared/source/os_interface/linux/ioctl_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#pragma once
99
#include "shared/source/command_stream/task_count_helper.h"
10+
#include "shared/source/gmm_helper/gmm_helper.h"
1011
#include "shared/source/helpers/topology_map.h"
1112
#include "shared/source/os_interface/linux/drm_allocation.h"
1213
#include "shared/source/os_interface/linux/drm_debug.h"

shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,6 @@ int IoctlHelperXe::createDrmContext(Drm &drm, OsContextLinux &osContext, uint32_
13411341
}
13421342

13431343
int IoctlHelperXe::xeVmBind(const VmBindParams &vmBindParams, bool isBind) {
1344-
auto gmmHelper = drm.getRootDeviceEnvironment().getGmmHelper();
13451344
int ret = -1;
13461345
const char *operation = isBind ? "bind" : "unbind";
13471346

@@ -1353,14 +1352,14 @@ int IoctlHelperXe::xeVmBind(const VmBindParams &vmBindParams, bool isBind) {
13531352
for (auto i = 0u; i < bindInfo.size(); i++) {
13541353
if (vmBindParams.userptr == bindInfo[i].userptr) {
13551354
userptr = bindInfo[i].userptr;
1356-
bindInfo[i].addr = gmmHelper->decanonize(vmBindParams.start);
1355+
bindInfo[i].addr = vmBindParams.start;
13571356
break;
13581357
}
13591358
}
13601359
}
13611360
} else // unbind
13621361
{
1363-
auto address = gmmHelper->decanonize(vmBindParams.start);
1362+
auto address = vmBindParams.start;
13641363
for (auto i = 0u; i < bindInfo.size(); i++) {
13651364
if (address == bindInfo[i].addr) {
13661365
userptr = bindInfo[i].userptr;
@@ -1385,7 +1384,10 @@ int IoctlHelperXe::xeVmBind(const VmBindParams &vmBindParams, bool isBind) {
13851384
if (vmBindParams.sharedSystemUsmBind == true) {
13861385
bind.bind.addr = 0;
13871386
} else {
1388-
bind.bind.addr = gmmHelper->decanonize(vmBindParams.start);
1387+
// Expect canonical address
1388+
DEBUG_BREAK_IF(drm.getRootDeviceEnvironment().getGmmHelper()->canonize(vmBindParams.start) != vmBindParams.start);
1389+
1390+
bind.bind.addr = vmBindParams.start;
13891391
}
13901392
bind.num_syncs = 1;
13911393
UNRECOVERABLE_IF(vmBindParams.userFence == 0x0);

shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_tests.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,41 @@ TEST_F(IoctlHelperXeTest, givenMultipleBindInfosWhenVmBindIsCalledThenProperHand
20902090
ioctlHelper->bindInfo.clear();
20912091
}
20922092

2093+
TEST_F(IoctlHelperXeTest, whenVmBindIsCalledThenProperCanonicalOrNonCanonicalAddressIsExpectedInVmBindInputsList) {
2094+
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
2095+
auto drm = DrmMockXe::create(*executionEnvironment->rootDeviceEnvironments[0]);
2096+
auto ioctlHelper = static_cast<MockIoctlHelperXe *>(drm->getIoctlHelper());
2097+
unsigned int idx = 0;
2098+
2099+
auto testAddress = [&](uint64_t addr) {
2100+
MockIoctlHelperXe::UserFenceExtension userFence{};
2101+
userFence.tag = userFence.tagValue;
2102+
userFence.addr = idx + 1;
2103+
2104+
VmBindParams vmBindParams{};
2105+
vmBindParams.userFence = castToUint64(&userFence);
2106+
vmBindParams.handle = idx + 1;
2107+
vmBindParams.userptr = idx + 1;
2108+
vmBindParams.start = addr;
2109+
2110+
auto ret = ioctlHelper->vmBind(vmBindParams);
2111+
EXPECT_EQ(0, ret);
2112+
2113+
auto &list = drm->vmBindInputs;
2114+
EXPECT_EQ(list.size(), idx + 1);
2115+
2116+
if (list.size() == idx + 1) {
2117+
EXPECT_EQ(list[idx].num_binds, 1u);
2118+
EXPECT_EQ(list[idx].bind.addr, vmBindParams.start);
2119+
}
2120+
2121+
idx++;
2122+
};
2123+
2124+
testAddress(0xfffff00000000000); // canonical address test
2125+
testAddress(0xf00000000000); // non-canonical address test
2126+
}
2127+
20932128
TEST_F(IoctlHelperXeTest, givenLowPriorityContextWhenSettingPropertiesThenCorrectIndexIsUsedAndReturend) {
20942129
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
20952130
auto drm = DrmMockXe::create(*executionEnvironment->rootDeviceEnvironments[0]);

0 commit comments

Comments
 (0)