fix: set ReadOnly flag when creating allocation with existing system memory

setting ReadOnly flag makes there is no ProbeForWrite call within
CreateAllocation2 function call

it doesn't make read-only access from GPU perspective, that access it
defined in MapGpuVa function

Related-To: NEO-12986, HSD-15016952776
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2025-01-29 03:12:26 +00:00
committed by Compute-Runtime-Automation
parent ef896cc799
commit bddb24124d
13 changed files with 77 additions and 156 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2024 Intel Corporation
* Copyright (C) 2021-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -65,7 +65,6 @@ struct MockWddmLinux : NEO::Wddm {
using Wddm::gfxPartition;
using Wddm::gfxPlatform;
using Wddm::gmmMemory;
using Wddm::isReadOnlyMemory;
};
struct MockGmmMemoryWddmLinux : NEO::GmmMemory {
@@ -796,16 +795,6 @@ TEST_F(WddmLinuxTest, whenCheckedIfResourcesCleanupCanBeSkippedAndDeviceIsLostTh
EXPECT_EQ(1, gdiMockConfig.getDeviceStateClb.callCount);
}
TEST_F(WddmLinuxTest, whenIsReadOnlyMemoryCalledThenCorrectValueReturned) {
EXPECT_FALSE(wddm->isReadOnlyMemory(nullptr));
static int mem[10];
EXPECT_FALSE(wddm->isReadOnlyMemory(mem));
static const int constMem[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
EXPECT_FALSE(wddm->isReadOnlyMemory(constMem));
}
class MockOsTimeLinux : public NEO::OSTimeLinux {
public:
MockOsTimeLinux(NEO::OSInterface &osInterface, std::unique_ptr<NEO::DeviceTime> deviceTime) : NEO::OSTimeLinux(osInterface, std::move(deviceTime)) {}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2024 Intel Corporation
* Copyright (C) 2020-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -1000,4 +1000,53 @@ TEST_F(WddmTests, whenInitializeFailureThenInitOsInterfaceWddmFails) {
EXPECT_FALSE(rootDeviceEnvironment->initOsInterface(std::move(hwDeviceId), 0u));
}
TEST_F(WddmTests, givenHostMemoryPassedToCreateAllocationThenAllocationCreatedWithReadOnlyFlagPassed) {
wddm->init();
setCapturingCreateAllocationFlagsFcn();
static const int constMem[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
D3DKMT_HANDLE handle, resHandle;
GmmRequirements gmmRequirements{};
Gmm gmm(executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper(), constMem, 10, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, {}, gmmRequirements);
EXPECT_EQ(STATUS_SUCCESS, wddm->createAllocation(constMem, &gmm, handle, resHandle, nullptr));
D3DKMT_CREATEALLOCATIONFLAGS createAllocationFlags{};
uint32_t createAllocation2NumCalled = 0;
getCapturedCreateAllocationFlagsFcn(createAllocationFlags, createAllocation2NumCalled);
EXPECT_TRUE(createAllocationFlags.ReadOnly);
EXPECT_EQ(1u, createAllocation2NumCalled);
}
TEST_F(WddmTests, givenHostMemoryPassedToCreateAllocationsAndMapGpuVaThenAllocationCreatedWithReadOnlyFlagPassed) {
wddm->init();
wddm->callBaseMapGpuVa = false;
setCapturingCreateAllocationFlagsFcn();
static const int constMem[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
GmmRequirements gmmRequirements{};
Gmm gmm(executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper(), constMem, 10, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, {}, gmmRequirements);
OsHandleStorage handleStorage;
OsHandleWin osHandle;
auto maxOsContextCount = 1u;
ResidencyData residency(maxOsContextCount);
handleStorage.fragmentCount = 1;
handleStorage.fragmentStorageData[0].cpuPtr = constMem;
handleStorage.fragmentStorageData[0].fragmentSize = 10;
handleStorage.fragmentStorageData[0].freeTheFragment = false;
handleStorage.fragmentStorageData[0].osHandleStorage = &osHandle;
handleStorage.fragmentStorageData[0].residency = &residency;
osHandle.gmm = &gmm;
EXPECT_EQ(STATUS_SUCCESS, wddm->createAllocationsAndMapGpuVa(handleStorage));
D3DKMT_CREATEALLOCATIONFLAGS createAllocationFlags{};
uint32_t createAllocation2NumCalled = 0;
getCapturedCreateAllocationFlagsFcn(createAllocationFlags, createAllocation2NumCalled);
EXPECT_TRUE(createAllocationFlags.ReadOnly);
EXPECT_EQ(1u, createAllocation2NumCalled);
}
} // namespace NEO

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Intel Corporation
* Copyright (C) 2023-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -405,66 +405,3 @@ TEST_F(WddmTestWithMockGdiDll, givenSetThreadPriorityStateEnabledWhenInitWddmThe
EXPECT_EQ(1u, SysCalls::setThreadPriorityCalled);
EXPECT_EQ(SysCalls::ThreadPriority::AboveNormal, SysCalls::setThreadPriorityLastValue);
}
TEST_F(WddmTestWithMockGdiDll, whenIsReadOnlyMemoryCalledThenCorrectValueReturned) {
EXPECT_FALSE(wddm->isReadOnlyMemory(nullptr));
static int mem[10];
SysCalls::virtualQueryMemoryBasicInformation.Protect = PAGE_READWRITE;
EXPECT_FALSE(wddm->isReadOnlyMemory(mem));
static const int constMem[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
SysCalls::virtualQueryMemoryBasicInformation.Protect = PAGE_READONLY;
EXPECT_TRUE(wddm->isReadOnlyMemory(constMem));
}
TEST_F(WddmTestWithMockGdiDll, givenReadOnlyHostMemoryPassedToCreateAllocationThenAllocationCreatedWithRetryAndReadOnlyFlagPassed) {
wddm->init();
setCreateAllocation2ReadOnlyFailConfigFcn(true);
static const int constMem[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
SysCalls::virtualQueryMemoryBasicInformation.Protect = PAGE_READONLY;
D3DKMT_HANDLE handle, resHandle;
GmmRequirements gmmRequirements{};
Gmm gmm(executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper(), constMem, 10, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, {}, gmmRequirements);
EXPECT_EQ(STATUS_SUCCESS, wddm->createAllocation(constMem, &gmm, handle, resHandle, nullptr));
bool readOnlyFlagWasPassed = false;
uint32_t createAllocation2NumCalled = 0;
getCreateAllocation2ReadOnlyFailConfigFcn(readOnlyFlagWasPassed, createAllocation2NumCalled);
EXPECT_TRUE(readOnlyFlagWasPassed);
EXPECT_EQ(2u, createAllocation2NumCalled);
}
TEST_F(WddmTestWithMockGdiDll, givenReadOnlyHostMemoryPassedToCreateAllocationsAndMapGpuVaThenAllocationCreatedWithRetryAndReadOnlyFlagPassed) {
wddm->init();
wddm->callBaseMapGpuVa = false;
setCreateAllocation2ReadOnlyFailConfigFcn(true);
static const int constMem[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
SysCalls::virtualQueryMemoryBasicInformation.Protect = PAGE_READONLY;
GmmRequirements gmmRequirements{};
Gmm gmm(executionEnvironment->rootDeviceEnvironments[0]->getGmmHelper(), constMem, 10, 0, GMM_RESOURCE_USAGE_OCL_BUFFER, {}, gmmRequirements);
OsHandleStorage handleStorage;
OsHandleWin osHandle;
auto maxOsContextCount = 1u;
ResidencyData residency(maxOsContextCount);
handleStorage.fragmentCount = 1;
handleStorage.fragmentStorageData[0].cpuPtr = constMem;
handleStorage.fragmentStorageData[0].fragmentSize = 10;
handleStorage.fragmentStorageData[0].freeTheFragment = false;
handleStorage.fragmentStorageData[0].osHandleStorage = &osHandle;
handleStorage.fragmentStorageData[0].residency = &residency;
osHandle.gmm = &gmm;
EXPECT_EQ(STATUS_SUCCESS, wddm->createAllocationsAndMapGpuVa(handleStorage));
bool readOnlyFlagWasPassed = false;
uint32_t createAllocation2NumCalled = 0;
getCreateAllocation2ReadOnlyFailConfigFcn(readOnlyFlagWasPassed, createAllocation2NumCalled);
EXPECT_TRUE(readOnlyFlagWasPassed);
EXPECT_EQ(2u, createAllocation2NumCalled);
}