From 4e8d340cf187e1a9a7ac5d4ed63f9f635967c958 Mon Sep 17 00:00:00 2001 From: Brandon Yates Date: Fri, 29 Aug 2025 00:16:27 +0000 Subject: [PATCH] fix: Only primary drm context should enable eu debug Related-to: HSD-18043158665 Signed-off-by: Brandon Yates --- .../os_interface/linux/xe/ioctl_helper_xe.cpp | 7 ++-- .../os_interface/linux/xe/ioctl_helper_xe.h | 2 +- .../xe/ioctl_helper_xe_debugger_tests.cpp | 34 +++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp index 5db8c73e2c..4e74032702 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.cpp @@ -1360,7 +1360,7 @@ int IoctlHelperXe::createDrmContext(Drm &drm, OsContextLinux &osContext, uint32_ std::array extProperties{}; uint32_t extPropertyIndex{0U}; - setOptionalContextProperties(drm, &extProperties, extPropertyIndex); + setOptionalContextProperties(osContext, drm, &extProperties, extPropertyIndex); setContextProperties(osContext, deviceIndex, &extProperties, extPropertyIndex); drm_xe_exec_queue_create create{}; @@ -1716,12 +1716,13 @@ bool IoctlHelperXe::getFdFromVmExport(uint32_t vmId, uint32_t flags, int32_t *fd return false; } -void IoctlHelperXe::setOptionalContextProperties(Drm &drm, void *extProperties, uint32_t &extIndexInOut) { +void IoctlHelperXe::setOptionalContextProperties(const OsContextLinux &osContext, Drm &drm, void *extProperties, uint32_t &extIndexInOut) { auto &ext = *reinterpret_cast *>(extProperties); if ((contextParamEngine[0].engine_class == DRM_XE_ENGINE_CLASS_RENDER) || (contextParamEngine[0].engine_class == DRM_XE_ENGINE_CLASS_COMPUTE)) { - if (drm.getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled()) { + const bool isSecondaryContext = osContext.isPartOfContextGroup() && (nullptr != osContext.getPrimaryContext()); + if (!isSecondaryContext && drm.getRootDeviceEnvironment().executionEnvironment.isDebuggingEnabled()) { ext[extIndexInOut].base.next_extension = 0; ext[extIndexInOut].base.name = DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY; ext[extIndexInOut].property = getEudebugExtProperty(); diff --git a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h index 0b6573bcce..8118324d7c 100644 --- a/shared/source/os_interface/linux/xe/ioctl_helper_xe.h +++ b/shared/source/os_interface/linux/xe/ioctl_helper_xe.h @@ -177,7 +177,7 @@ class IoctlHelperXe : public IoctlHelper { }; uint16_t getDefaultEngineClass(const aub_stream::EngineType &defaultEngineType); - void setOptionalContextProperties(Drm &drm, void *extProperties, uint32_t &extIndexInOut); + void setOptionalContextProperties(const OsContextLinux &osContext, Drm &drm, void *extProperties, uint32_t &extIndexInOut); virtual void setContextProperties(const OsContextLinux &osContext, uint32_t deviceIndex, void *extProperties, uint32_t &extIndexInOut); virtual void applyContextFlags(void *execQueueCreate, bool allocateInterrupt); diff --git a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_debugger_tests.cpp b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_debugger_tests.cpp index b0a9270f58..531b2fbbd8 100644 --- a/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_debugger_tests.cpp +++ b/shared/test/unit_test/os_interface/linux/xe/ioctl_helper_xe_debugger_tests.cpp @@ -157,6 +157,40 @@ HWTEST_F(IoctlHelperXeTestFixture, GivenDebuggingEnabledWhenCreateDrmContextThen EXPECT_EQ(ext.value, static_cast(EuDebugParam::execQueueSetPropertyValueEnable)); } +HWTEST_F(IoctlHelperXeTestFixture, GivenDebuggingEnabledWhenCreateDrmContextFromGroupThenEuDebuggableContextIsSetCorrectly) { + + auto executionEnvironment = std::make_unique(); + executionEnvironment->setDebuggingMode(DebuggingMode::online); + auto &rootDeviceEnvironment = *executionEnvironment->rootDeviceEnvironments[0]; + rootDeviceEnvironment.osInterface = std::make_unique(); + rootDeviceEnvironment.osInterface->setDriverModel(std::make_unique(mockFd, rootDeviceEnvironment)); + auto drm = DrmMockXeDebug::create(*executionEnvironment->rootDeviceEnvironments[0]); + auto xeIoctlHelper = static_cast(drm->ioctlHelper.get()); + + auto engineInfo = xeIoctlHelper->createEngineInfo(false); + ASSERT_NE(nullptr, engineInfo); + drm->engineInfo = std::move(engineInfo); + + OsContextLinux osContext(*drm, 0, 4u, EngineDescriptorHelper::getDefaultDescriptor({aub_stream::EngineType::ENGINE_CCS, EngineUsage::regular})); + OsContextLinux osContext2(*drm, 0, 5u, EngineDescriptorHelper::getDefaultDescriptor({aub_stream::EngineType::ENGINE_CCS, EngineUsage::regular})); + + osContext.setContextGroup(true); + osContext2.setPrimaryContext(&osContext); + + // secondary context should not create exec_queue with EUDEBUG enable + xeIoctlHelper->createDrmContext(*drm, osContext2, 0, 1, false); + auto ext = drm->receivedContextCreateSetParam; + EXPECT_NE(ext.property, static_cast(EuDebugParam::execQueueSetPropertyEuDebug)); + + // primary context should create exec_queue with EUDEBUG enable + xeIoctlHelper->createDrmContext(*drm, osContext, 0, 1, false); + ext = drm->receivedContextCreateSetParam; + EXPECT_EQ(ext.base.name, static_cast(DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY)); + EXPECT_EQ(ext.base.next_extension, 0ULL); + EXPECT_EQ(ext.property, static_cast(EuDebugParam::execQueueSetPropertyEuDebug)); + EXPECT_EQ(ext.value, static_cast(EuDebugParam::execQueueSetPropertyValueEnable)); +} + HWTEST_F(IoctlHelperXeTestFixture, GivenContextCreatedForCopyEngineWhenCreateDrmContextThenEuDebuggableContextIsNotRequested) { DebugManagerStateRestore restorer;