fix: add nullptr dereference check in module destroy

Related-To: GSD-9058
Signed-off-by: Fabian Zwoliński <fabian.zwolinski@intel.com>
This commit is contained in:
Fabian Zwoliński
2024-05-15 20:41:15 +02:00
committed by Compute-Runtime-Automation
parent bd89ac4b12
commit 465330ee6f
2 changed files with 37 additions and 4 deletions

View File

@@ -1568,10 +1568,12 @@ ze_result_t ModuleImp::destroy() {
auto &executionEnvironment = getDevice()->getNEODevice()->getRootDeviceEnvironment().executionEnvironment;
for (const auto &kernelImmData : this->kernelImmDatas) {
for (auto &engine : executionEnvironment.memoryManager->getRegisteredEngines(rootDeviceIndex)) {
auto contextId = engine.osContext->getContextId();
if (kernelImmData->getIsaGraphicsAllocation()->isUsedByOsContext(contextId)) {
engine.commandStreamReceiver->registerInstructionCacheFlush();
if (kernelImmData->getIsaGraphicsAllocation()) {
for (auto &engine : executionEnvironment.memoryManager->getRegisteredEngines(rootDeviceIndex)) {
auto contextId = engine.osContext->getContextId();
if (kernelImmData->getIsaGraphicsAllocation()->isUsedByOsContext(contextId)) {
engine.commandStreamReceiver->registerInstructionCacheFlush();
}
}
}
}

View File

@@ -108,6 +108,37 @@ TEST(ModuleDestroyTest, givenIsaAllocationWhenIsModuleDestroyedThenRequireInstru
EXPECT_TRUE(mockCommandStreamReceiver->requiresInstructionCacheFlush);
}
TEST(ModuleDestroyTest, givenKernelImmutableDataWithNullIsaAllocationWhenIsModuleDestroyedThenRequiresInstructionCacheFlushIsNotSetInCsr) {
const uint32_t rootDeviceIndex = 0u;
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo.get();
auto *neoMockDevice = NEO::MockDevice::createWithNewExecutionEnvironment<NEO::MockDevice>(&hwInfo, rootDeviceIndex);
MockCommandStreamReceiver *mockCommandStreamReceiver = new MockCommandStreamReceiver(*neoMockDevice->executionEnvironment, neoMockDevice->getRootDeviceIndex(), neoMockDevice->getDeviceBitfield());
mockCommandStreamReceiver->makeResidentParentCall = true;
neoMockDevice->resetCommandStreamReceiver(mockCommandStreamReceiver);
MockDeviceImp deviceImp(neoMockDevice, neoMockDevice->getExecutionEnvironment());
auto module = new MockModule{&deviceImp, nullptr, ModuleType::user};
module->translationUnit.reset(new MockModuleTranslationUnit{&deviceImp});
auto kernelInfo = new KernelInfo{};
kernelInfo->heapInfo.pKernelHeap = reinterpret_cast<const void *>(0xdeadbeef0000);
kernelInfo->heapInfo.kernelHeapSize = static_cast<uint32_t>(0x40);
module->translationUnit->programInfo.kernelInfos.push_back(kernelInfo);
module->initializeKernelImmutableDatas();
auto &kernelImmDatas = module->getKernelImmutableDataVector();
for (auto &kernelImmData : kernelImmDatas) {
kernelImmData->setIsaParentAllocation(nullptr);
}
module->destroy();
EXPECT_FALSE(mockCommandStreamReceiver->requiresInstructionCacheFlush);
}
TEST(ModuleBuildLog, WhenCreatingModuleBuildLogThenNonNullPointerReturned) {
auto moduleBuildLog = ModuleBuildLog::create();
ASSERT_NE(nullptr, moduleBuildLog);