Skip to content

Commit 8521075

Browse files
fix: handle not aligned gtt size reported by i915
when i915 reports gtt size between 47 and 48 bits we consider it as 48 bit VA space Related-To: GSD-8215 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com> Source: 420e139
1 parent dd63ad2 commit 8521075

19 files changed

+150
-73
lines changed

shared/source/memory_manager/gfx_partition.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ uint64_t GfxPartition::getHeapMinimalAddress(HeapIndex heapIndex) {
190190
}
191191
}
192192

193-
bool GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useExternalFrontWindowPool, uint64_t systemMemorySize) {
193+
bool GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useExternalFrontWindowPool, uint64_t systemMemorySize, uint64_t gfxTop) {
194194

195195
/*
196196
* I. 64-bit builds:
@@ -238,7 +238,6 @@ bool GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe
238238
* 0x0 0x100000000 gpuAddressSpace
239239
*/
240240

241-
uint64_t gfxTop = gpuAddressSpace + 1;
242241
uint64_t gfxBase = 0x0ull;
243242
const uint64_t gfxHeap32Size = 4 * MemoryConstants::gigaByte;
244243

shared/source/memory_manager/gfx_partition.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2023 Intel Corporation
2+
* Copyright (C) 2019-2024 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -39,7 +39,7 @@ class GfxPartition {
3939
GfxPartition(OSMemory::ReservedCpuAddressRange &reservedCpuAddressRangeForHeapSvm);
4040
MOCKABLE_VIRTUAL ~GfxPartition();
4141

42-
MOCKABLE_VIRTUAL bool init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useExternalFrontWindowPool, uint64_t systemMemorySize);
42+
MOCKABLE_VIRTUAL bool init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useExternalFrontWindowPool, uint64_t systemMemorySize, uint64_t gfxTop);
4343

4444
void heapInit(HeapIndex heapIndex, uint64_t base, uint64_t size) {
4545
getHeap(heapIndex).init(base, size, MemoryConstants::pageSize);

shared/source/memory_manager/os_agnostic_memory_manager.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ void OsAgnosticMemoryManager::initialize(bool aubUsage) {
4646
this->enable64kbpages[rootDeviceIndex] = is64kbPagesEnabled(hwInfo);
4747
this->localMemorySupported.push_back(gfxCoreHelper.getEnableLocalMemory(*hwInfo));
4848
auto gpuAddressSpace = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->capabilityTable.gpuAddressSpace;
49-
if (!getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, reservedCpuAddressRangeSize, rootDeviceIndex, gfxPartitions.size(), heapAssigners[rootDeviceIndex]->apiAllowExternalHeapForSshAndDsh, OsAgnosticMemoryManager::getSystemSharedMemory(rootDeviceIndex))) {
49+
auto gfxTop = gpuAddressSpace + 1;
50+
if (!getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, reservedCpuAddressRangeSize, rootDeviceIndex, gfxPartitions.size(), heapAssigners[rootDeviceIndex]->apiAllowExternalHeapForSshAndDsh, OsAgnosticMemoryManager::getSystemSharedMemory(rootDeviceIndex), gfxTop)) {
5051
initialized = false;
5152
return;
5253
}

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ void DrmMemoryManager::initialize(GemCloseWorkerMode mode) {
9999

100100
for (uint32_t rootDeviceIndex = 0; rootDeviceIndex < gfxPartitions.size(); ++rootDeviceIndex) {
101101
auto gpuAddressSpace = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo()->capabilityTable.gpuAddressSpace;
102-
if (!getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, getSizeToReserve(), rootDeviceIndex, gfxPartitions.size(), heapAssigners[rootDeviceIndex]->apiAllowExternalHeapForSshAndDsh, DrmMemoryManager::getSystemSharedMemory(rootDeviceIndex))) {
102+
uint64_t gfxTop{};
103+
getDrm(rootDeviceIndex).queryGttSize(gfxTop, false);
104+
if (!getGfxPartition(rootDeviceIndex)->init(gpuAddressSpace, getSizeToReserve(), rootDeviceIndex, gfxPartitions.size(), heapAssigners[rootDeviceIndex]->apiAllowExternalHeapForSshAndDsh, DrmMemoryManager::getSystemSharedMemory(rootDeviceIndex), gfxTop)) {
103105
initialized = false;
104106
return;
105107
}
@@ -1248,7 +1250,7 @@ uint64_t DrmMemoryManager::getSystemSharedMemory(uint32_t rootDeviceIndex) {
12481250

12491251
uint64_t gpuMemorySize = 0u;
12501252

1251-
[[maybe_unused]] auto ret = getDrm(rootDeviceIndex).queryGttSize(gpuMemorySize);
1253+
[[maybe_unused]] auto ret = getDrm(rootDeviceIndex).queryGttSize(gpuMemorySize, false);
12521254
DEBUG_BREAK_IF(ret != 0);
12531255

12541256
return std::min(hostMemorySize, gpuMemorySize);

shared/source/os_interface/linux/drm_neo.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,17 @@ bool Drm::readSysFsAsString(const std::string &relativeFilePath, std::string &re
232232
return true;
233233
}
234234

235-
int Drm::queryGttSize(uint64_t &gttSizeOutput) {
235+
int Drm::queryGttSize(uint64_t &gttSizeOutput, bool alignUpToFullRange) {
236236
GemContextParam contextParam = {0};
237237
contextParam.param = ioctlHelper->getDrmParamValue(DrmParam::contextParamGttSize);
238238

239239
int ret = ioctlHelper->ioctl(DrmIoctl::gemContextGetparam, &contextParam);
240240
if (ret == 0) {
241-
gttSizeOutput = contextParam.value;
241+
if (alignUpToFullRange) {
242+
gttSizeOutput = Drm::alignUpGttSize(contextParam.value);
243+
} else {
244+
gttSizeOutput = contextParam.value;
245+
}
242246
}
243247

244248
return ret;
@@ -1579,6 +1583,17 @@ void Drm::waitOnUserFences(const OsContextLinux &osContext, uint64_t address, ui
15791583
}
15801584
const HardwareInfo *Drm::getHardwareInfo() const { return rootDeviceEnvironment.getHardwareInfo(); }
15811585

1586+
uint64_t Drm::alignUpGttSize(uint64_t inputGttSize) {
1587+
1588+
constexpr uint64_t gttSize47bit = (1ull << 47);
1589+
constexpr uint64_t gttSize48bit = (1ull << 48);
1590+
1591+
if (inputGttSize > gttSize47bit && inputGttSize < gttSize48bit) {
1592+
return gttSize48bit;
1593+
}
1594+
return inputGttSize;
1595+
}
1596+
15821597
template std::vector<uint16_t> Drm::query<uint16_t>(uint32_t queryId, uint32_t queryItemFlags);
15831598
template std::vector<uint32_t> Drm::query<uint32_t>(uint32_t queryId, uint32_t queryItemFlags);
15841599
template std::vector<uint64_t> Drm::query<uint64_t>(uint32_t queryId, uint32_t queryItemFlags);

shared/source/os_interface/linux/drm_neo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Drm : public DriverModel {
9292
int getTimestampFrequency(int &frequency);
9393
int getOaTimestampFrequency(int &frequency);
9494

95-
MOCKABLE_VIRTUAL int queryGttSize(uint64_t &gttSizeOutput);
95+
MOCKABLE_VIRTUAL int queryGttSize(uint64_t &gttSizeOutput, bool alignUpToFullRange);
9696
bool isPreemptionSupported() const { return preemptionSupported; }
9797

9898
MOCKABLE_VIRTUAL void checkPreemptionSupport();
@@ -269,6 +269,7 @@ class Drm : public DriverModel {
269269
void queryAndSetVmBindPatIndexProgrammingSupport();
270270
bool queryDeviceIdAndRevision();
271271
bool queryI915DeviceIdAndRevision();
272+
static uint64_t alignUpGttSize(uint64_t inputGttSize);
272273

273274
#pragma pack(1)
274275
struct PCIConfig {

shared/source/os_interface/linux/product_helper_drm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ int ProductHelper::configureHwInfoDrm(const HardwareInfo *inHwInfo, HardwareInfo
125125
uint64_t gttSizeQuery = 0;
126126
featureTable->flags.ftrSVM = true;
127127

128-
ret = drm->queryGttSize(gttSizeQuery);
128+
ret = drm->queryGttSize(gttSizeQuery, true);
129129

130130
if (ret == 0) {
131131
featureTable->flags.ftrSVM = (gttSizeQuery > MemoryConstants::max64BitAppAddress);

shared/test/common/libult/linux/drm_mock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class DrmMock : public Drm {
174174
else
175175
return Drm::useVMBindImmediate();
176176
}
177-
int queryGttSize(uint64_t &gttSizeOutput) override {
177+
int queryGttSize(uint64_t &gttSizeOutput, bool alignUpToFullRange) override {
178178
gttSizeOutput = storedGTTSize;
179179
return storedRetValForGetGttSize;
180180
}
@@ -276,7 +276,7 @@ class DrmMock : public Drm {
276276
GemVmControl receivedGemVmControl{};
277277
uint32_t latestCreatedVmId = 0u;
278278

279-
uint64_t storedGTTSize = 1ull << 47;
279+
uint64_t storedGTTSize = defaultHwInfo->capabilityTable.gpuAddressSpace + 1;
280280
uint64_t storedParamSseu = ULONG_MAX;
281281

282282
Ioctls ioctlCount{};

shared/test/common/mocks/linux/mock_drm_memory_manager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2023 Intel Corporation
2+
* Copyright (C) 2020-2024 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -69,7 +69,7 @@ void TestedDrmMemoryManager::injectPinBB(BufferObject *newPinBB, uint32_t rootDe
6969
DrmGemCloseWorker *TestedDrmMemoryManager::getgemCloseWorker() { return this->gemCloseWorker.get(); }
7070
void TestedDrmMemoryManager::forceLimitedRangeAllocator(uint64_t range) {
7171
for (auto &gfxPartition : gfxPartitions) {
72-
gfxPartition->init(range, getSizeToReserve(), 0, 1, false, 0u);
72+
gfxPartition->init(range, getSizeToReserve(), 0, 1, false, 0u, range + 1);
7373
}
7474
}
7575
void TestedDrmMemoryManager::overrideGfxPartition(GfxPartition *newGfxPartition) { gfxPartitions[0].reset(newGfxPartition); }

shared/test/common/mocks/mock_gfx_partition.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2023 Intel Corporation
2+
* Copyright (C) 2019-2024 Intel Corporation
33
*
44
* SPDX-License-Identifier: MIT
55
*
@@ -92,7 +92,7 @@ class MockGfxPartitionBasic : public GfxPartition {
9292

9393
class FailedInitGfxPartition : public MockGfxPartition {
9494
public:
95-
bool init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useFrontWindowPool, uint64_t systemMemorySize) override {
95+
bool init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve, uint32_t rootDeviceIndex, size_t numRootDevices, bool useFrontWindowPool, uint64_t systemMemorySize, uint64_t gfxTop) override {
9696
return false;
9797
}
9898
};

0 commit comments

Comments
 (0)