From f14af782b36db50fbad4f4f72329ee572085d0d7 Mon Sep 17 00:00:00 2001 From: Jemale Lockett Date: Thu, 12 Sep 2024 22:23:28 +0000 Subject: [PATCH] fix: Correct mirroring module debug area Resolves: NEO-11883 Signed-off-by: Jemale Lockett --- .../debug/linux/prelim/debug_session.cpp | 22 +++- .../linux/prelim/test_debug_api_linux.cpp | 108 ++++++++++++++++++ shared/source/debugger/debugger_l0.cpp | 9 +- 3 files changed, 134 insertions(+), 5 deletions(-) diff --git a/level_zero/tools/source/debug/linux/prelim/debug_session.cpp b/level_zero/tools/source/debug/linux/prelim/debug_session.cpp index 3d1baa8383..ad0301dbd8 100644 --- a/level_zero/tools/source/debug/linux/prelim/debug_session.cpp +++ b/level_zero/tools/source/debug/linux/prelim/debug_session.cpp @@ -527,7 +527,27 @@ bool DebugSessionLinuxi915::handleVmBindEvent(prelim_drm_i915_debug_event_vm_bin if (connection->classHandleToIndex[classUuid].second == static_cast(NEO::DrmResourceClass::moduleHeapDebugArea)) { - connection->vmToModuleDebugAreaBindInfo[vmHandle] = {vmBind->va_start, vmBind->va_length}; + auto &isaMap = connection->isaMap[tileIndex]; + { + auto isa = std::make_unique(); + isa->bindInfo = {vmBind->va_start, vmBind->va_length}; + isa->vmHandle = vmHandle; + isa->elfHandle = invalidHandle; + isa->moduleBegin = 0; + isa->moduleEnd = 0; + isa->tileInstanced = !(this->debugArea.isShared); + isa->perKernelModule = false; + uint32_t deviceBitfield = 0; + auto &debugModule = connection->uuidToModule[uuid]; + memcpy_s(&deviceBitfield, sizeof(uint32_t), + &debugModule.deviceBitfield, + sizeof(debugModule.deviceBitfield)); + const NEO::DeviceBitfield devices(deviceBitfield); + isa->deviceBitfield = devices; + isaMap[vmBind->va_start] = std::move(isa); + connection->vmToModuleDebugAreaBindInfo[vmHandle] = {vmBind->va_start, + vmBind->va_length}; + } } if (connection->classHandleToIndex[classUuid].second == diff --git a/level_zero/tools/test/unit_tests/sources/debug/linux/prelim/test_debug_api_linux.cpp b/level_zero/tools/test/unit_tests/sources/debug/linux/prelim/test_debug_api_linux.cpp index 38a151ec2f..a62edcce73 100644 --- a/level_zero/tools/test/unit_tests/sources/debug/linux/prelim/test_debug_api_linux.cpp +++ b/level_zero/tools/test/unit_tests/sources/debug/linux/prelim/test_debug_api_linux.cpp @@ -8287,6 +8287,114 @@ TEST_F(DebugApiLinuxMultiDeviceVmBindTest, givenTileInstancedIsaAndZebinModuleWh givenTileInstancedIsaAndZebinModuleWhenHandlingVmBindDestroyEventsThenModuleUnloadIsTriggeredAfterAllInstancesEventsReceived(); } +template +struct RootSessionTileFixture : public DebugApiLinuxMultiDeviceFixture, public MockDebugSessionLinuxi915Helper { + void setUp() { + NEO::debugManager.flags.ExperimentalEnableTileAttach.set(1); + DebugApiLinuxMultiDeviceFixture::setUp(); + + zet_debug_config_t config = {}; + config.pid = 0x1234; + rootSession = std::make_unique(config, deviceImp, 10); + ASSERT_NE(nullptr, rootSession); + rootSession->clientHandle = MockDebugSessionLinuxi915::mockClientHandle; + rootSession->debugArea.isShared = true; + rootSession->blockOnFenceMode = blockOnFence; + + setupSessionClassHandlesAndUuidMap(rootSession.get()); + setupVmToTile(rootSession.get()); + } + + void tearDown() { + DebugApiLinuxMultiDeviceFixture::tearDown(); + } + DebugManagerStateRestore restorer; + std::unique_ptr rootSession; +}; + +using DebugApiLinuxMultiDeviceVmBindRootDeviceSessionTest = Test>; + +TEST_F(DebugApiLinuxMultiDeviceVmBindRootDeviceSessionTest, givenTileInstancedModuleDebugAreaWhenWritingDebugAreaThenBothInstancesAreWrittenTo) { + DebugSessionLinuxi915::UuidData debugAreaUUIDData = { + .handle = debugAreaUUID, + .classHandle = moduleDebugClassHandle, + .classIndex = NEO::DrmResourceClass::moduleHeapDebugArea, + .data = std::make_unique(0x1000), + .dataSize = 0x1000}; + + auto debugAreaVA = 0x1234000; + + auto handler = new MockIoctlHandlerI915; + rootSession->ioctlHandler.reset(handler); + + rootSession->clientHandle = MockDebugSessionLinuxi915::mockClientHandle; + rootSession->clientHandleToConnection[MockDebugSessionLinuxi915::mockClientHandle]->uuidMap[debugAreaUUID] = std::move(debugAreaUUIDData); + rootSession->clientHandleToConnection[MockDebugSessionLinuxi915::mockClientHandle]->vmToModuleDebugAreaBindInfo[vm0] = {0x1234000, 0x1000}; + + { + uint64_t vmBindDebugData[(sizeof(prelim_drm_i915_debug_event_vm_bind) + sizeof(typeOfUUID) + sizeof(uint64_t)) / sizeof(uint64_t)]; + prelim_drm_i915_debug_event_vm_bind *vmBindDebugArea = reinterpret_cast(vmBindDebugData); + + vmBindDebugArea->base.type = PRELIM_DRM_I915_DEBUG_EVENT_VM_BIND; + vmBindDebugArea->base.flags = PRELIM_DRM_I915_DEBUG_EVENT_CREATE; + + vmBindDebugArea->base.size = sizeof(prelim_drm_i915_debug_event_vm_bind) + sizeof(typeOfUUID); + vmBindDebugArea->base.seqno = 20u; + vmBindDebugArea->client_handle = MockDebugSessionLinuxi915::mockClientHandle; + vmBindDebugArea->va_start = debugAreaVA; + vmBindDebugArea->va_length = 0x2000; + vmBindDebugArea->vm_handle = vm0; + vmBindDebugArea->num_uuids = 1; + + typeOfUUID uuidTemp[1]; + uuidTemp[0] = debugAreaUUID; + memcpy_s(vmBindDebugArea->uuids, sizeof(uuidTemp), uuidTemp, sizeof(uuidTemp)); + + rootSession->handleEvent(&vmBindDebugArea->base); + + vmBindDebugArea->vm_handle = vm1; + rootSession->handleEvent(&vmBindDebugArea->base); + } + + DebugAreaHeader debugArea; + debugArea.reserved1 = 1; + debugArea.pgsize = uint8_t(4); + debugArea.version = 1; + debugArea.isShared = 1; + + constexpr size_t bufSize = sizeof(rootSession->debugArea); + char buffer2[bufSize]; + + handler->mmapRet = reinterpret_cast(&debugArea); + handler->pwriteRetVal = bufSize; + handler->preadRetVal = bufSize; + + handler->setPreadMemory(reinterpret_cast(&debugArea), sizeof(debugArea), debugAreaVA); + handler->setPwriteMemory(reinterpret_cast(&debugArea), sizeof(debugArea), debugAreaVA); + + rootSession->readModuleDebugArea(); + EXPECT_EQ(1u, rootSession->debugArea.version); + + ze_device_thread_t thread = {UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX}; + zet_debug_memory_space_desc_t desc{}; + desc.address = debugAreaVA; + desc.type = ZET_DEBUG_MEMORY_SPACE_TYPE_DEFAULT; + uint8_t buffer[16]; + handler->pwriteRetVal = 16; + + auto result = rootSession->writeMemory(thread, &desc, 16, buffer); + EXPECT_EQ(ZE_RESULT_SUCCESS, result); + EXPECT_EQ(2, handler->pwriteCalled); + + // Read From tile0 + rootSession->readGpuMemory(vm0, buffer2, bufSize, debugAreaVA); + EXPECT_EQ(0, memcmp(&debugArea, buffer2, bufSize)); + memset(buffer2, 0, bufSize); + // Read From tile1 + rootSession->readGpuMemory(vm1, buffer2, bufSize, debugAreaVA); + EXPECT_EQ(0, memcmp(&debugArea, buffer2, bufSize)); +} + using DebugLinuxMultiDeviceVmBindBlockOnFenceTest = Test>; TEST_F(DebugLinuxMultiDeviceVmBindBlockOnFenceTest, givenTileInstancedIsaAndZebinModuleWhenHandlingVmBindCreateEventsThenModuleLoadIsTriggeredAfterAllInstancesEventsReceived) { diff --git a/shared/source/debugger/debugger_l0.cpp b/shared/source/debugger/debugger_l0.cpp index 449e9f319d..3ea7f19f7a 100644 --- a/shared/source/debugger/debugger_l0.cpp +++ b/shared/source/debugger/debugger_l0.cpp @@ -91,6 +91,11 @@ void DebuggerL0::initialize() { debugArea.scratchBegin = sizeof(DebugAreaHeader); debugArea.scratchEnd = MemoryConstants::pageSize64k - sizeof(DebugAreaHeader); + const auto &productHelper = device->getProductHelper(); + NEO::MemoryTransferHelper::transferMemoryToAllocation(productHelper.isBlitCopyRequiredForLocalMemory(rootDeviceEnvironment, *moduleDebugArea), + *device, moduleDebugArea, 0, &debugArea, + sizeof(DebugAreaHeader)); + NEO::MemoryOperationsHandler *memoryOperationsIface = rootDeviceEnvironment.memoryOperationsInterface.get(); if (memoryOperationsIface) { memoryOperationsIface->makeResident(device, ArrayRef(&moduleDebugArea, 1)); @@ -101,10 +106,6 @@ void DebuggerL0::initialize() { } } - const auto &productHelper = device->getProductHelper(); - NEO::MemoryTransferHelper::transferMemoryToAllocation(productHelper.isBlitCopyRequiredForLocalMemory(rootDeviceEnvironment, *moduleDebugArea), - *device, moduleDebugArea, 0, &debugArea, - sizeof(DebugAreaHeader)); if (productHelper.disableL3CacheForDebug(hwInfo)) { device->getGmmHelper()->forceAllResourcesUncached(); }