fix: mem alloc size tracking safety

Make sure local mem alloc size atomic array is initialized with 0.
Add debug breaks to catch possible overflow on unregistering
allocations.

Related-To: NEO-11356

Signed-off-by: Dominik Dabek <dominik.dabek@intel.com>
This commit is contained in:
Dominik Dabek
2024-08-05 10:26:23 +00:00
committed by Compute-Runtime-Automation
parent a1a13475c7
commit e9e6cc05e3
3 changed files with 5 additions and 0 deletions

View File

@@ -78,6 +78,7 @@ MemoryManager::MemoryManager(ExecutionEnvironment &executionEnvironment) : execu
auto globalHeap = ApiSpecificConfig::getGlobalBindlessHeapConfiguration(rootDeviceEnvironment.getReleaseHelper());
heapAssigners.push_back(std::make_unique<HeapAssigner>(globalHeap));
localMemAllocsSize[rootDeviceIndex].store(0u);
}
if (anyLocalMemorySupported) {

View File

@@ -1569,8 +1569,10 @@ AllocationStatus DrmMemoryManager::registerLocalMemAlloc(GraphicsAllocation *all
void DrmMemoryManager::unregisterAllocation(GraphicsAllocation *allocation) {
if (allocation->isAllocatedInLocalMemoryPool()) {
DEBUG_BREAK_IF(allocation->getUnderlyingBufferSize() > localMemAllocsSize[allocation->getRootDeviceIndex()]);
localMemAllocsSize[allocation->getRootDeviceIndex()] -= allocation->getUnderlyingBufferSize();
} else if (MemoryPool::memoryNull != allocation->getMemoryPool()) {
DEBUG_BREAK_IF(allocation->getUnderlyingBufferSize() > sysMemAllocsSize);
sysMemAllocsSize -= allocation->getUnderlyingBufferSize();
}
std::lock_guard<std::mutex> lock(this->allocMutex);

View File

@@ -787,8 +787,10 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
}
if (gfxAllocation->isAllocatedInLocalMemoryPool()) {
DEBUG_BREAK_IF(gfxAllocation->getUnderlyingBufferSize() > localMemAllocsSize[gfxAllocation->getRootDeviceIndex()]);
localMemAllocsSize[gfxAllocation->getRootDeviceIndex()] -= gfxAllocation->getUnderlyingBufferSize();
} else if (MemoryPool::memoryNull != gfxAllocation->getMemoryPool()) {
DEBUG_BREAK_IF(gfxAllocation->getUnderlyingBufferSize() > sysMemAllocsSize);
sysMemAllocsSize -= gfxAllocation->getUnderlyingBufferSize();
}