Update gpuAddress before soft pinning bo

bo->gpuAddress update before soft pinning of BO in Non-SVM case

Change-Id: I80cc5467673e3b3a0512d840c5eed75470fa0e7f
Signed-off-by: Dongwon Kim <dongwon.kim@intel.com>
This commit is contained in:
Dongwon Kim
2020-03-13 15:24:12 -07:00
committed by sys_ocldev
parent f423679de9
commit ec6d73e632
3 changed files with 41 additions and 2 deletions

View File

@ -154,6 +154,9 @@ class DrmMockCustom : public Drm {
//DRM_IOCTL_I915_GEM_EXECBUFFER2
drm_i915_gem_execbuffer2 execBuffer = {0};
//First exec object
drm_i915_gem_exec_object2 execBufferBufferObjects = {0};
//DRM_IOCTL_I915_GEM_CREATE
__u64 createParamsSize = 0;
__u32 createParamsHandle = 0;
@ -201,6 +204,8 @@ class DrmMockCustom : public Drm {
case DRM_IOCTL_I915_GEM_EXECBUFFER2: {
drm_i915_gem_execbuffer2 *execbuf = (drm_i915_gem_execbuffer2 *)arg;
this->execBuffer = *execbuf;
this->execBufferBufferObjects =
*reinterpret_cast<drm_i915_gem_exec_object2 *>(this->execBuffer.buffers_ptr);
ioctl_cnt.execbuffer2++;
} break;

View File

@ -721,6 +721,40 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValidationWhenHostPtrPinningWithGpuRangeAsOffsetInAlocateMemoryForNonSvmHostPtr) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(false,
false,
true,
*executionEnvironment));
memoryManager->registeredEngines = EngineControlContainer{this->device->engines};
for (auto engine : memoryManager->registeredEngines) {
engine.osContext->incRefInternal();
}
mock->reset();
DrmMockCustom::IoctlResExt ioctlResExt = {1, -1};
mock->ioctl_res_ext = &ioctlResExt;
mock->errnoValue = SUCCESS;
mock->ioctl_expected.gemUserptr = 1;
mock->ioctl_expected.execbuffer2 = 1;
AllocationData allocationData;
allocationData.size = 13u;
allocationData.hostPtr = reinterpret_cast<const void *>(0x5001);
auto allocation = memoryManager->allocateGraphicsMemoryForNonSvmHostPtr(allocationData);
EXPECT_NE(nullptr, allocation);
EXPECT_EQ(allocation->getGpuAddress() - allocation->getAllocationOffset(), mock->execBufferBufferObjects.offset);
mock->testIoctls();
mock->ioctl_res_ext = &mock->NONE;
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValidationWhenPinningFailWithErrorDifferentThanEfaultThenPopulateOsHandlesReturnsError) {
std::unique_ptr<TestedDrmMemoryManager> memoryManager(new (std::nothrow) TestedDrmMemoryManager(false,
false,

View File

@ -260,6 +260,8 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const Al
return nullptr;
}
bo->gpuAddress = gpuVirtualAddress;
if (validateHostPtrMemory) {
int result = pinBBs.at(allocationData.rootDeviceIndex)->pin(&bo, 1, getDefaultDrmContextId());
if (result != SUCCESS) {
@ -269,8 +271,6 @@ DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const Al
}
}
bo->gpuAddress = gpuVirtualAddress;
auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, allocationData.type, bo, const_cast<void *>(allocationData.hostPtr),
gpuVirtualAddress, allocationData.size, MemoryPool::System4KBPages);
allocation->setAllocationOffset(offsetInPage);