fix: handle failure on set cache region

Related-To: NEO-9038
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2023-10-10 14:15:42 +00:00
committed by Compute-Runtime-Automation
parent bede264d0d
commit af275ed341
2 changed files with 29 additions and 4 deletions

View File

@@ -2442,14 +2442,17 @@ DrmAllocation *DrmMemoryManager::createUSMHostAllocationFromSharedHandle(osHandl
pushSharedBufferObject(bo);
DrmAllocation *drmAllocation = nullptr;
drmAllocation = new DrmAllocation(properties.rootDeviceIndex, properties.allocationType, bo, cpuPointer, bo->peekAddress(), bo->peekSize(), MemoryPool::System4KBPages);
auto drmAllocation = std::make_unique<DrmAllocation>(properties.rootDeviceIndex, properties.allocationType, bo, cpuPointer, bo->peekAddress(), bo->peekSize(), MemoryPool::System4KBPages);
drmAllocation->setMmapPtr(cpuPointer);
drmAllocation->setMmapSize(size);
drmAllocation->setReservedAddressRange(reinterpret_cast<void *>(cpuPointer), size);
drmAllocation->setCacheRegion(&drm, static_cast<CacheRegion>(properties.cacheRegion));
if (!drmAllocation->setCacheRegion(&drm, static_cast<CacheRegion>(properties.cacheRegion))) {
this->munmapFunction(cpuPointer, size);
delete bo;
return nullptr;
}
return drmAllocation;
return drmAllocation.release();
}
auto gmmHelper = getGmmHelper(properties.rootDeviceIndex);

View File

@@ -1076,6 +1076,28 @@ TEST_F(DrmMemoryManagerTest, GivenDeviceSharedAllocationWhichRequiresHostMapThen
memoryManager->freeGraphicsMemory(graphicsAllocation);
}
TEST_F(DrmMemoryManagerTest, GivenDeviceSharedAllocationWhenSetCacheRegionFailsThenNullptrIsReturned) {
mock->ioctlExpected.primeFdToHandle = 1;
mock->ioctlExpected.gemWait = 0;
mock->ioctlExpected.gemClose = 0;
mock->ioctlExpected.gemMmapOffset = 1;
osHandle handle = 1u;
this->mock->outputHandle = 2u;
size_t size = 4096u;
std::vector<MemoryRegion> regionInfo(1);
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
this->mock->memoryInfo.reset(new MemoryInfo(regionInfo, *mock));
this->mock->queryEngineInfo();
AllocationProperties properties(rootDeviceIndex, false, size, AllocationType::GPU_TIMESTAMP_DEVICE_BUFFER, false, {});
properties.cacheRegion = std::numeric_limits<uint32_t>::max();
auto graphicsAllocation = memoryManager->createGraphicsAllocationFromSharedHandle(handle, properties, false, true, false, nullptr);
EXPECT_EQ(nullptr, graphicsAllocation);
}
TEST_F(DrmMemoryManagerTest, GivenAllocationWhenFreeingThenSucceeds) {
mock->ioctlExpected.gemUserptr = 1;
mock->ioctlExpected.gemWait = 1;