fix: Skip adding device to list if context creation fails

Propogate error codes from ioctl failure properly up the layers
so that we skip exposing bad root devices.

Related-To: NEO-7709

Signed-off-by: Aravind Gopalakrishnan <aravind.gopalakrishnan@intel.com>
This commit is contained in:
Aravind Gopalakrishnan
2023-02-11 22:03:06 +00:00
committed by Compute-Runtime-Automation
parent 95bea7c92b
commit d75c4d3ec7
24 changed files with 132 additions and 33 deletions

View File

@@ -112,7 +112,7 @@ class DrmMock : public Drm {
queryPageFaultSupportCalled = true;
}
uint32_t createDrmContext(uint32_t drmVmId, bool isDirectSubmissionRequested, bool isCooperativeContextRequested) override {
int createDrmContext(uint32_t drmVmId, bool isDirectSubmissionRequested, bool isCooperativeContextRequested) override {
capturedCooperativeContextRequest = isCooperativeContextRequested;
if (callBaseCreateDrmContext) {
return Drm::createDrmContext(drmVmId, isDirectSubmissionRequested, isCooperativeContextRequested);

View File

@@ -18,6 +18,7 @@
#include "shared/source/memory_manager/unified_memory_manager.h"
#include "shared/source/os_interface/device_factory.h"
#include "shared/source/os_interface/hw_info_config.h"
#include "shared/source/os_interface/os_context.h"
#include "shared/source/os_interface/os_interface.h"
#include "shared/source/utilities/tag_allocator.h"
#include "shared/test/common/cmd_parse/gen_cmd_parse.h"
@@ -111,6 +112,28 @@ HWTEST_F(CommandStreamReceiverTest, WhenInitializeResourcesThenCallFillReusableA
EXPECT_EQ(1u, pDevice->getUltCommandStreamReceiver<FamilyType>().fillReusableAllocationsListCalled);
}
HWTEST_F(CommandStreamReceiverTest, whenContextCreateReturnsFalseThenExpectCSRInitializeResourcesFail) {
struct MyOsContext : OsContext {
MyOsContext(uint32_t contextId,
const EngineDescriptor &engineDescriptor) : OsContext(0, contextId, engineDescriptor) {}
bool initializeContext() override {
initializeContextCalled++;
return false;
}
size_t initializeContextCalled = 0u;
};
const EngineTypeUsage engineTypeUsageRegular{aub_stream::ENGINE_RCS, EngineUsage::Regular};
MyOsContext osContext{0, EngineDescriptorHelper::getDefaultDescriptor(engineTypeUsageRegular)};
auto &ultCsr = pDevice->getUltCommandStreamReceiver<FamilyType>();
ultCsr.resourcesInitialized = false;
ultCsr.setupContext(osContext);
bool ret = ultCsr.initializeResources();
EXPECT_FALSE(ret);
}
HWTEST_F(CommandStreamReceiverTest, givenCsrWhenCallFillReusableAllocationsListThenAllocateCommandBufferAndMakeItResident) {
DebugManagerStateRestore stateRestore;
DebugManager.flags.SetAmountOfReusableAllocations.set(1);

View File

@@ -108,7 +108,7 @@ TEST(DrmQueryTest, givenCreateContextWithAccessCountersWhenDrmContextIsCreatedTh
DrmQueryMock drm{*executionEnvironment->rootDeviceEnvironments[0]};
auto ret = drm.createDrmContext(0, false, false);
EXPECT_EQ(0u, ret);
EXPECT_EQ(0, ret);
EXPECT_TRUE(drm.receivedContextCreateFlags & I915_CONTEXT_CREATE_FLAGS_USE_EXTENSIONS);
@@ -130,6 +130,15 @@ TEST(DrmQueryTest, givenCreateContextWithAccessCountersWhenDrmContextIsCreatedTh
EXPECT_EQ(static_cast<uint8_t>(DrmPrelimHelper::getContextAcgValues()[1]), paramAcc->granularity);
}
TEST(DrmQueryTest, GivenDrmWhenAskedForContextThatFailsThenFalseIsReturned) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmMock *pDrm = new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]);
pDrm->storedRetVal = -1;
EXPECT_EQ(-1, pDrm->createDrmContext(1, false, false));
pDrm->storedRetVal = 0;
delete pDrm;
}
TEST(DrmQueryTest, givenCreateContextWithAccessCounterWhenDrmContextIsCreatedThenProgramAccessCountersWithSpecifiedTriggeringThreshold) {
DebugManagerStateRestore restorer;
DebugManager.flags.CreateContextWithAccessCounters.set(0);
@@ -141,7 +150,7 @@ TEST(DrmQueryTest, givenCreateContextWithAccessCounterWhenDrmContextIsCreatedThe
DebugManager.flags.AccessCountersTrigger.set(threshold);
auto ret = drm.createDrmContext(0, false, false);
EXPECT_EQ(0u, ret);
EXPECT_EQ(0, ret);
EXPECT_TRUE(drm.receivedContextCreateFlags & I915_CONTEXT_CREATE_FLAGS_USE_EXTENSIONS);
@@ -175,7 +184,7 @@ TEST(DrmQueryTest, givenCreateContextWithAccessCounterWhenDrmContextIsCreatedThe
DebugManager.flags.AccessCountersGranularity.set(granularity);
auto ret = drm.createDrmContext(0, false, false);
EXPECT_EQ(0u, ret);
EXPECT_EQ(0, ret);
EXPECT_TRUE(drm.receivedContextCreateFlags & I915_CONTEXT_CREATE_FLAGS_USE_EXTENSIONS);

View File

@@ -348,11 +348,19 @@ TEST(DrmTest, GivenDrmWhenAskedForContextThatFailsThenFalseIsReturned) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmMock *pDrm = new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]);
pDrm->storedRetVal = -1;
EXPECT_THROW(pDrm->createDrmContext(1, false, false), std::exception);
EXPECT_EQ(-1, pDrm->createDrmContext(1, false, false));
pDrm->storedRetVal = 0;
delete pDrm;
}
TEST(DrmTest, GivenDrmWhenAskedForContextThatIsSuccessThenTrueIsReturned) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmMock *pDrm = new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]);
pDrm->storedRetVal = 0;
EXPECT_EQ(0, pDrm->createDrmContext(1, false, false));
delete pDrm;
}
TEST(DrmTest, givenDrmWhenOsContextIsCreatedThenCreateAndDestroyNewDrmOsContext) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmMock drmMock(*executionEnvironment->rootDeviceEnvironments[0]);

View File

@@ -8,6 +8,7 @@
#include "shared/source/os_interface/linux/drm_memory_operations_handler.h"
#include "shared/source/os_interface/linux/os_context_linux.h"
#include "shared/test/common/helpers/engine_descriptor_helper.h"
#include "shared/test/common/libult/linux/drm_mock.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/os_interface/linux/device_command_stream_fixture.h"
@@ -25,3 +26,14 @@ TEST(OSContextLinux, givenReinitializeContextWhenContextIsInitThenContextIsStill
EXPECT_NO_THROW(osContext.reInitializeContext());
EXPECT_NO_THROW(osContext.ensureContextInitialized());
}
TEST(OSContextLinux, givenInitializeContextWhenContextCreateIoctlFailsThenContextNotInitialized) {
auto executionEnvironment = std::make_unique<MockExecutionEnvironment>();
DrmMock *pDrm = new DrmMock(*executionEnvironment->rootDeviceEnvironments[0]);
pDrm->storedRetVal = -1;
EXPECT_EQ(-1, pDrm->createDrmContext(1, false, false));
OsContextLinux osContext(*pDrm, 0, 0u, EngineDescriptorHelper::getDefaultDescriptor());
EXPECT_EQ(false, osContext.ensureContextInitialized());
delete pDrm;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2022 Intel Corporation
* Copyright (C) 2019-2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -166,13 +166,35 @@ TEST_F(DeferredOsContextCreationTests, givenBlitterEngineWhenCreatingOsContextTh
expectImmediateContextCreation(engineTypeUsageBlitter, false);
}
TEST_F(DeferredOsContextCreationTests, givenEnsureContextInitializeCalledAndReturnsErrorThenOsContextIsNotInitialized) {
struct MyOsContext : OsContext {
MyOsContext(uint32_t contextId,
const EngineDescriptor &engineDescriptor) : OsContext(0, contextId, engineDescriptor) {}
bool initializeContext() override {
initializeContextCalled++;
return false;
}
size_t initializeContextCalled = 0u;
};
MyOsContext osContext{0, EngineDescriptorHelper::getDefaultDescriptor(engineTypeUsageRegular)};
EXPECT_FALSE(osContext.isInitialized());
osContext.ensureContextInitialized();
EXPECT_FALSE(osContext.isInitialized());
EXPECT_EQ(1u, osContext.initializeContextCalled);
}
TEST_F(DeferredOsContextCreationTests, givenEnsureContextInitializeCalledMultipleTimesWhenOsContextIsCreatedThenInitializeOnlyOnce) {
struct MyOsContext : OsContext {
MyOsContext(uint32_t contextId,
const EngineDescriptor &engineDescriptor) : OsContext(0, contextId, engineDescriptor) {}
void initializeContext() override {
bool initializeContext() override {
initializeContextCalled++;
return true;
}
size_t initializeContextCalled = 0u;