fix: avoid race when evicting resources

Related-To: NEO-13843

DrmMemoryOperationsHandler::mutex is used for residency
handling.
However, this mutex is not being locked during eviction when vm bind
failed.
This is causing races for example when ULLS controller wants to make
resources resident, and user thread wants to evict
them.
Fix is to explicitly obtain lock in problematic path.

Signed-off-by: Szymon Morek <szymon.morek@intel.com>
This commit is contained in:
Szymon Morek
2025-03-06 17:04:43 +00:00
committed by Compute-Runtime-Automation
parent 14a8cbf5a8
commit f08b32761e
2 changed files with 3 additions and 1 deletions

View File

@@ -326,6 +326,7 @@ int BufferObject::pin(BufferObject *const boToPin[], size_t numberOfBos, OsConte
auto retVal = 0;
if (this->drm->isVmBindAvailable()) {
auto lock = static_cast<DrmMemoryOperationsHandler *>(this->drm->getRootDeviceEnvironment().memoryOperationsInterface.get())->lockHandlerIfUsed();
retVal = bindBOsWithinContext(boToPin, numberOfBos, osContext, vmHandleId, false);
} else {
StackVec<ExecObject, maxFragmentsCount + 1> execObject(numberOfBos + 1);
@@ -339,6 +340,7 @@ int BufferObject::validateHostPtr(BufferObject *const boToPin[], size_t numberOf
auto retVal = 0;
if (this->drm->isVmBindAvailable()) {
auto lock = static_cast<DrmMemoryOperationsHandler *>(this->drm->getRootDeviceEnvironment().memoryOperationsInterface.get())->lockHandlerIfUsed();
for (size_t i = 0; i < numberOfBos; i++) {
retVal = boToPin[i]->bind(osContext, vmHandleId, false);
if (retVal) {

View File

@@ -157,7 +157,7 @@ MemoryOperationsStatus DrmMemoryOperationsHandlerBind::mergeWithResidencyContain
}
std::unique_lock<std::mutex> DrmMemoryOperationsHandlerBind::lockHandlerIfUsed() {
return std::unique_lock<std::mutex>();
return std::unique_lock<std::mutex>(mutex);
}
MemoryOperationsStatus DrmMemoryOperationsHandlerBind::evictUnusedAllocations(bool waitForCompletion, bool isLockNeeded) {