Validate host ptr on VM it will be used

Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
Lukasz Jobczyk 2021-08-04 11:56:36 +00:00 committed by Compute-Runtime-Automation
parent 700aecb384
commit 49cf6f79f5
4 changed files with 12 additions and 7 deletions

View File

@ -34,6 +34,7 @@ StorageInfo MemoryManager::createStorageInfoFromProperties(const AllocationPrope
}
StorageInfo storageInfo{preferredTile, allTilesValue};
storageInfo.subDeviceBitfield = properties.subDevicesBitfield;
storageInfo.isLockable = GraphicsAllocation::isLockable(properties.allocationType);
storageInfo.cpuVisibleSegment = GraphicsAllocation::isCpuAccessRequired(properties.allocationType);

View File

@ -19,6 +19,7 @@ struct StorageInfo {
uint32_t getNumBanks() const;
DeviceBitfield memoryBanks;
DeviceBitfield pageTablesVisibility;
DeviceBitfield subDeviceBitfield;
bool cloningOfPageTables = true;
bool tileInstanced = false;
bool multiStorage = false;

View File

@ -221,16 +221,13 @@ void BufferObject::printExecutionBuffer(drm_i915_gem_execbuffer2 &execbuf, const
printf("%s\n", logger.str().c_str());
}
int bindBOsWithinContext(BufferObject *const boToPin[], size_t numberOfBos, OsContext *osContext, uint32_t vmHandleId, bool allContexts) {
int bindBOsWithinContext(BufferObject *const boToPin[], size_t numberOfBos, OsContext *osContext, uint32_t vmHandleId) {
auto retVal = 0;
for (auto drmIterator = 0u; drmIterator < osContext->getDeviceBitfield().size(); drmIterator++) {
if (osContext->getDeviceBitfield().test(drmIterator)) {
for (size_t i = 0; i < numberOfBos; i++) {
retVal |= boToPin[i]->bind(osContext, drmIterator);
if (!allContexts) {
return retVal;
}
}
}
}
@ -242,7 +239,7 @@ int BufferObject::pin(BufferObject *const boToPin[], size_t numberOfBos, OsConte
auto retVal = 0;
if (this->drm->isVmBindAvailable()) {
retVal = bindBOsWithinContext(boToPin, numberOfBos, osContext, vmHandleId, true);
retVal = bindBOsWithinContext(boToPin, numberOfBos, osContext, vmHandleId);
} else {
StackVec<drm_i915_gem_exec_object2, maxFragmentsCount + 1> execObject(numberOfBos + 1);
retVal = this->exec(4u, 0u, 0u, false, osContext, vmHandleId, drmContextId, boToPin, numberOfBos, &execObject[0]);
@ -255,7 +252,12 @@ int BufferObject::validateHostPtr(BufferObject *const boToPin[], size_t numberOf
auto retVal = 0;
if (this->drm->isVmBindAvailable()) {
retVal = bindBOsWithinContext(boToPin, numberOfBos, osContext, vmHandleId, false);
for (size_t i = 0; i < numberOfBos; i++) {
retVal = boToPin[i]->bind(osContext, vmHandleId);
if (retVal) {
break;
}
}
} else {
StackVec<drm_i915_gem_exec_object2, maxFragmentsCount + 1> execObject(numberOfBos + 1);
retVal = this->exec(4u, 0u, 0u, false, osContext, vmHandleId, drmContextId, boToPin, numberOfBos, &execObject[0]);

View File

@ -430,7 +430,8 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const Al
if (validateHostPtrMemory) {
auto boPtr = bo.get();
int result = pinBBs.at(rootDeviceIndex)->validateHostPtr(&boPtr, 1, registeredEngines[defaultEngineIndex[rootDeviceIndex]].osContext, 0, getDefaultDrmContextId(rootDeviceIndex));
auto vmHandleId = Math::getMinLsbSet(static_cast<uint32_t>(allocationData.storageInfo.subDeviceBitfield.to_ulong()));
int result = pinBBs.at(rootDeviceIndex)->validateHostPtr(&boPtr, 1, registeredEngines[defaultEngineIndex[rootDeviceIndex]].osContext, vmHandleId, getDefaultDrmContextId(rootDeviceIndex));
if (result != 0) {
unreference(bo.release(), true);
releaseGpuRange(reinterpret_cast<void *>(gpuVirtualAddress), alignedSize, rootDeviceIndex);