From ec6d73e6321b61ae9004a83254fca2cd17117620 Mon Sep 17 00:00:00 2001 From: Dongwon Kim Date: Fri, 13 Mar 2020 15:24:12 -0700 Subject: [PATCH] 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 --- .../linux/device_command_stream_fixture.h | 5 +++ .../linux/drm_memory_manager_tests.cpp | 34 +++++++++++++++++++ .../os_interface/linux/drm_memory_manager.cpp | 4 +-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h b/opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h index 4dd5522737..fd14c35e9e 100644 --- a/opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h +++ b/opencl/test/unit_test/os_interface/linux/device_command_stream_fixture.h @@ -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(this->execBuffer.buffers_ptr); ioctl_cnt.execbuffer2++; } break; diff --git a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp index 9d48cc2c70..07075f51a2 100644 --- a/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp +++ b/opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp @@ -721,6 +721,40 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid memoryManager->freeGraphicsMemory(allocation); } +TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValidationWhenHostPtrPinningWithGpuRangeAsOffsetInAlocateMemoryForNonSvmHostPtr) { + std::unique_ptr 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(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 memoryManager(new (std::nothrow) TestedDrmMemoryManager(false, false, diff --git a/shared/source/os_interface/linux/drm_memory_manager.cpp b/shared/source/os_interface/linux/drm_memory_manager.cpp index 75e423bdf8..15f7bdca08 100644 --- a/shared/source/os_interface/linux/drm_memory_manager.cpp +++ b/shared/source/os_interface/linux/drm_memory_manager.cpp @@ -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(allocationData.hostPtr), gpuVirtualAddress, allocationData.size, MemoryPool::System4KBPages); allocation->setAllocationOffset(offsetInPage);