Fail when handle cannot be obtain for an allocation

If a handle cannot be obtained, like PRIME_HANDLE_TO_FD, then
properly check for the error and propagate it upwards.

Signed-off-by: Jaime Arteaga <jaime.a.arteaga.molina@intel.com>
This commit is contained in:
Jaime Arteaga
2022-11-10 02:57:51 +00:00
committed by Compute-Runtime-Automation
parent acb8186744
commit 4391ad21bb
23 changed files with 1007 additions and 115 deletions

View File

@@ -227,7 +227,9 @@ TEST(GraphicsAllocationTest, givenAlwaysResidentAllocationWhenUpdateTaskCountThe
TEST(GraphicsAllocationTest, givenDefaultGraphicsAllocationWhenInternalHandleIsBeingObtainedThenZeroIsReturned) {
MockGraphicsAllocation graphicsAllocation;
EXPECT_EQ(0llu, graphicsAllocation.peekInternalHandle(nullptr));
uint64_t handle = 0;
graphicsAllocation.peekInternalHandle(nullptr, handle);
EXPECT_EQ(0ull, handle);
}
TEST(GraphicsAllocationTest, givenDefaultGraphicsAllocationWhenGettingNumHandlesThenZeroIsReturned) {

View File

@@ -131,6 +131,46 @@ TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAnd
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
}
TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAndMemoryInfoWhenCreateMultiGraphicsAllocationAndObtainFdFromHandleFailsThenNullptrIsReturned) {
uint32_t rootDevicesNumber = 3u;
MultiGraphicsAllocation multiGraphics(rootDevicesNumber);
RootDeviceIndicesContainer rootDeviceIndices;
auto osInterface = executionEnvironment->rootDeviceEnvironments[0]->osInterface.release();
executionEnvironment->prepareRootDeviceEnvironments(rootDevicesNumber);
for (uint32_t i = 0; i < rootDevicesNumber; i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get());
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
auto mock = new DrmQueryMock(*executionEnvironment->rootDeviceEnvironments[i]);
std::vector<MemoryRegion> regionInfo(2);
regionInfo[0].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_SYSTEM, 0};
regionInfo[1].region = {drm_i915_gem_memory_class::I915_MEMORY_CLASS_DEVICE, DrmMockHelper::getEngineOrMemoryInstanceValue(0, 0)};
mock->memoryInfo.reset(new MemoryInfo(regionInfo, *mock));
mock->queryEngineInfo();
mock->ioctlCallsCount = 0;
executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique<OSInterface>();
executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
executionEnvironment->rootDeviceEnvironments[i]->memoryOperationsInterface = DrmMemoryOperationsHandler::create(*mock, 0u);
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
rootDeviceIndices.push_back(i);
}
memoryManager = new TestedDrmMemoryManager(true, false, false, *executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
size_t size = 4096u;
AllocationProperties properties(rootDeviceIndex, true, size, AllocationType::BUFFER_HOST_MEMORY, false, {});
memoryManager->failOnObtainFdFromHandle = true;
auto ptr = memoryManager->createMultiGraphicsAllocationInSystemMemoryPool(rootDeviceIndices, properties, multiGraphics);
EXPECT_EQ(ptr, nullptr);
executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(osInterface);
}
TEST_F(DrmMemoryManagerLocalMemoryPrelimTest, givenMultiRootDeviceEnvironmentAndMemoryInfoWhenCreateMultiGraphicsAllocationAndImportFailsThenNullptrIsReturned) {
uint32_t rootDevicesNumber = 3u;
MultiGraphicsAllocation multiGraphics(rootDevicesNumber);

View File

@@ -452,7 +452,25 @@ TEST_F(DrmMemoryManagerTest, whenPeekInternalHandleIsCalledThenBoIsReturned) {
mock->outputFd = 1337;
auto allocation = static_cast<DrmAllocation *>(this->memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(rootDeviceIndex, 10 * MemoryConstants::pageSize, true)));
ASSERT_NE(allocation->getBO(), nullptr);
ASSERT_EQ(allocation->peekInternalHandle(this->memoryManager), static_cast<uint64_t>(1337));
uint64_t handle = 0;
int ret = allocation->peekInternalHandle(this->memoryManager, handle);
ASSERT_EQ(ret, 0);
ASSERT_EQ(handle, static_cast<uint64_t>(1337));
memoryManager->freeGraphicsMemory(allocation);
}
TEST_F(DrmMemoryManagerTest, whenPeekInternalHandleIsCalledAndObtainFdFromHandleFailsThenErrorIsReturned) {
mock->ioctl_expected.gemUserptr = 1;
mock->ioctl_expected.gemWait = 1;
mock->ioctl_expected.gemClose = 1;
mock->outputFd = 1337;
auto allocation = static_cast<DrmAllocation *>(this->memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(rootDeviceIndex, 10 * MemoryConstants::pageSize, true)));
ASSERT_NE(allocation->getBO(), nullptr);
memoryManager->failOnObtainFdFromHandle = true;
uint64_t handle = 0;
int ret = allocation->peekInternalHandle(this->memoryManager, handle);
ASSERT_EQ(ret, -1);
memoryManager->freeGraphicsMemory(allocation);
}
@@ -469,11 +487,18 @@ TEST_F(DrmMemoryManagerTest, whenCallingPeekInternalHandleSeveralTimesThenSameHa
ASSERT_NE(allocation->getBO(), nullptr);
EXPECT_EQ(mock->outputFd, static_cast<int32_t>(expectedFd));
uint64_t handle0 = allocation->peekInternalHandle(this->memoryManager);
uint64_t handle0 = 0;
int ret = allocation->peekInternalHandle(this->memoryManager, handle0);
ASSERT_EQ(ret, 0);
EXPECT_NE(mock->outputFd, static_cast<int32_t>(expectedFd));
uint64_t handle1 = allocation->peekInternalHandle(this->memoryManager);
uint64_t handle2 = allocation->peekInternalHandle(this->memoryManager);
uint64_t handle1 = 0;
uint64_t handle2 = 0;
ret = allocation->peekInternalHandle(this->memoryManager, handle1);
ASSERT_EQ(ret, 0);
ret = allocation->peekInternalHandle(this->memoryManager, handle2);
ASSERT_EQ(ret, 0);
ASSERT_EQ(handle0, expectedFd);
ASSERT_EQ(handle1, expectedFd);
@@ -491,8 +516,11 @@ TEST_F(DrmMemoryManagerTest, whenPeekInternalHandleWithHandleIdIsCalledThenBoIsR
auto allocation = static_cast<DrmAllocation *>(this->memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(rootDeviceIndex, 10 * MemoryConstants::pageSize, true)));
ASSERT_NE(allocation->getBO(), nullptr);
uint64_t handle = 0;
uint32_t handleId = 0;
ASSERT_EQ(allocation->peekInternalHandle(this->memoryManager, handleId), static_cast<uint64_t>(1337));
int ret = allocation->peekInternalHandle(this->memoryManager, handleId, handle);
ASSERT_EQ(ret, 0);
ASSERT_EQ(handle, static_cast<uint64_t>(1337));
memoryManager->freeGraphicsMemory(allocation);
}
@@ -510,11 +538,17 @@ TEST_F(DrmMemoryManagerTest, whenCallingPeekInternalHandleWithIdSeveralTimesThen
EXPECT_EQ(mock->outputFd, static_cast<int32_t>(expectedFd));
uint32_t handleId = 0;
uint64_t handle0 = allocation->peekInternalHandle(this->memoryManager, handleId);
uint64_t handle0 = 0;
int ret = allocation->peekInternalHandle(this->memoryManager, handleId, handle0);
ASSERT_EQ(ret, 0);
EXPECT_NE(mock->outputFd, static_cast<int32_t>(expectedFd));
uint64_t handle1 = allocation->peekInternalHandle(this->memoryManager, handleId);
uint64_t handle2 = allocation->peekInternalHandle(this->memoryManager, handleId);
uint64_t handle1 = 0;
uint64_t handle2 = 0;
ret = allocation->peekInternalHandle(this->memoryManager, handleId, handle1);
ASSERT_EQ(ret, 0);
ret = allocation->peekInternalHandle(this->memoryManager, handleId, handle2);
ASSERT_EQ(ret, 0);
ASSERT_EQ(handle0, expectedFd);
ASSERT_EQ(handle1, expectedFd);
@@ -3163,6 +3197,29 @@ TEST(DrmMemoryManagerWithExplicitExpectationsTest2, whenObtainFdFromHandleIsCall
}
}
TEST(DrmMemoryManagerWithExplicitExpectationsTest2, whenFailingToObtainFdFromHandleThenErrorIsReturned) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
executionEnvironment->prepareRootDeviceEnvironments(4u);
for (auto i = 0u; i < 4u; i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(defaultHwInfo.get());
auto mock = new DrmMockCustom(*executionEnvironment->rootDeviceEnvironments[0]);
executionEnvironment->rootDeviceEnvironments[i]->osInterface = std::make_unique<OSInterface>();
executionEnvironment->rootDeviceEnvironments[i]->osInterface->setDriverModel(std::unique_ptr<DriverModel>(mock));
executionEnvironment->rootDeviceEnvironments[i]->initGmm();
}
auto memoryManager = std::make_unique<TestedDrmMemoryManager>(false, false, false, *executionEnvironment);
for (auto i = 0u; i < 4u; i++) {
auto mock = executionEnvironment->rootDeviceEnvironments[i]->osInterface->getDriverModel()->as<DrmMockCustom>();
int boHandle = 3;
mock->outputFd = -1;
mock->ioctl_res = -1;
mock->ioctl_expected.handleToPrimeFd = 1;
auto fdHandle = memoryManager->obtainFdFromHandle(boHandle, i);
EXPECT_EQ(-1, fdHandle);
}
}
TEST_F(DrmMemoryManagerTest, givenSvmCpuAllocationWhenSizeAndAlignmentProvidedThenAllocateMemoryAndReserveGpuVa) {
mock->ioctl_expected.gemUserptr = 1;
mock->ioctl_expected.gemWait = 1;