fix: add unrecoverable to avoid OOB access

Related-To: NEO-9860
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2024-01-15 13:57:17 +00:00
committed by Compute-Runtime-Automation
parent 9215f3acb5
commit 556645e0c5
6 changed files with 31 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -34,6 +34,7 @@ struct TimestampPacketTests : public ::testing::Test {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfoAndInitHelpers(defaultHwInfo.get());
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
}
executionEnvironment->calculateMaxOsContextCount();
device = std::make_unique<MockClDevice>(Device::create<MockDevice>(executionEnvironment, 0u));
context = new MockContext(device.get());
kernel = std::make_unique<MockKernelWithInternals>(*device, context);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -55,6 +55,7 @@ GraphicsAllocation::GraphicsAllocation(uint32_t rootDeviceIndex, size_t numGmms,
GraphicsAllocation::~GraphicsAllocation() = default;
void GraphicsAllocation::updateTaskCount(TaskCountType newTaskCount, uint32_t contextId) {
UNRECOVERABLE_IF(contextId >= usageInfos.size());
if (usageInfos[contextId].taskCount == objectNotUsed) {
registeredContextsNum++;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -160,7 +160,13 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
bool isUsedByManyOsContexts() const { return registeredContextsNum > 1u; }
bool isUsedByOsContext(uint32_t contextId) const { return objectNotUsed != getTaskCount(contextId); }
MOCKABLE_VIRTUAL void updateTaskCount(TaskCountType newTaskCount, uint32_t contextId);
MOCKABLE_VIRTUAL TaskCountType getTaskCount(uint32_t contextId) const { return usageInfos[contextId].taskCount; }
MOCKABLE_VIRTUAL TaskCountType getTaskCount(uint32_t contextId) const {
if (contextId >= usageInfos.size()) {
return objectNotUsed;
}
return usageInfos[contextId].taskCount;
}
void releaseUsageInOsContext(uint32_t contextId) { updateTaskCount(objectNotUsed, contextId); }
uint32_t getInspectionId(uint32_t contextId) const { return usageInfos[contextId].inspectionId; }
void setInspectionId(uint32_t newInspectionId, uint32_t contextId) { usageInfos[contextId].inspectionId = newInspectionId; }

View File

@@ -1080,6 +1080,8 @@ HWCMDTEST_F(IGFX_XE_HP_CORE, DeviceTests, givenCCSEngineAndContextGroupSizeEnabl
UltDeviceFactory deviceFactory{1, 0, executionEnvironment};
MemoryManager::maxOsContextCount++;
deviceFactory.rootDevices[0]->createEngine(0, {aub_stream::EngineType::ENGINE_CCS, EngineUsage::regular});
auto defaultEngine = deviceFactory.rootDevices[0]->getDefaultEngine();

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2023 Intel Corporation
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -59,6 +59,20 @@ TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenUpdatedTaskCountThenOnly
EXPECT_EQ(MockGraphicsAllocation::objectNotUsed, graphicsAllocation.getTaskCount(i));
}
}
TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenGettingTaskCountForInvalidContextIdThenObjectNotUsedIsReturned) {
MockGraphicsAllocation graphicsAllocation;
for (auto i = 0u; i < MemoryManager::maxOsContextCount; i++) {
graphicsAllocation.updateTaskCount(1u, i);
}
EXPECT_EQ(MockGraphicsAllocation::objectNotUsed, graphicsAllocation.getTaskCount(MemoryManager::maxOsContextCount));
}
TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenUpdatingTaskCountForInvalidContextIdThenAbortExecution) {
MockGraphicsAllocation graphicsAllocation;
EXPECT_THROW(graphicsAllocation.updateTaskCount(1u, MemoryManager::maxOsContextCount), std::runtime_error);
}
TEST(GraphicsAllocationTest, givenGraphicsAllocationWhenUpdatedTaskCountToobjectNotUsedValueThenUnregisterContext) {
MockGraphicsAllocation graphicsAllocation;
EXPECT_FALSE(graphicsAllocation.isUsed());
@@ -545,4 +559,4 @@ TEST(GraphicsAllocationTest, givenGraphicsAllocationsWithFragmentsWhenCallingFor
auto residencyData = graphicsAllocation.fragmentsStorage.fragmentStorageData[allocationId].residency;
EXPECT_EQ(residencyData->getFenceValueForContextId(contextId), newFenceValue);
}
}
}

View File

@@ -683,6 +683,7 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenUseKmdMigrationSetWhenCreateS
mock->ioctlCallsCount = 0;
mock->setBindAvailable();
executionEnvironment->calculateMaxOsContextCount();
SVMAllocsManager unifiedMemoryManager(memoryManager, false);
SVMAllocsManager::UnifiedMemoryProperties unifiedMemoryProperties(InternalMemoryType::sharedUnifiedMemory, 1, rootDeviceIndices, deviceBitfields);