Skip to contentSkip to conversation

drm/amdgpu: Fix incorrect VRAM GART mappings on non-4K page size systems

PATCH Applied Donet Tom 3 participants 3 messages May 27

Subsystems (2)
lore
Share & tools
lore

Donet Tom

author
#0 lore raw

PATCH v3 1/1 drm/amdgpu: Fix incorrect VRAM GART mappings on non-4K page size systems

When mapping VRAM pages into the GART page table, amdgpu_gart_map_vram_range() assumes that the system page size is the same as the GPU page size.

On systems with non-4K page sizes, multiple GPU pages can exist within a single CPU page. As a result, the mappings are created incorrectly because fewer page table entries are programmed than required.

Fix this by programming the mappings correctly for non-4K page size systems.

Fixes 237d623ae659 ("drm/amdgpu/gart: Add helper to bind VRAM pages (v2)")

---
v2 -> v3
- Addressed Christian's review comments and added the Reviewed-by tag.

v2 - https://lore.kernel.org/all/[email protected]/
v1 - https://lore.kernel.org/all/[email protected]/
---

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +8 -4
index b6f849d51c2e..c4c21dbbbdbf 100644
@@ -394,7 +394,8 @@ void amdgpu_gart_map_vram_range(struct amdgpu_device *adev, uint64_t pa,
 				uint64_t start_page, uint64_t num_pages,
 				uint64_t flags, void *dst)
 {
-	u32 i, idx;
+	u32 i, j, t, idx;
+	u64 page_base;
 
 	/* The SYSTEM flag indicates the pages aren't in VRAM. */
 	WARN_ON_ONCE(flags & AMDGPU_PTE_SYSTEM);
@@ -402,9 +403,12 @@ void amdgpu_gart_map_vram_range(struct amdgpu_device *adev, uint64_t pa,
 	if (!drm_dev_enter(adev_to_drm(adev), &idx))
 		return;
 
-	for (i = 0; i < num_pages; ++i) {
-		amdgpu_gmc_set_pte_pde(adev, dst,
-			start_page + i, pa + AMDGPU_GPU_PAGE_SIZE * i, flags);
+	page_base = pa;
+	for (i = 0, t = 0; i < num_pages; i++) {
+		for (j = 0; j < AMDGPU_GPU_PAGES_IN_CPU_PAGE; j++, t++) {
+			amdgpu_gmc_set_pte_pde(adev, dst, start_page + t, page_base, flags);
+			page_base += AMDGPU_GPU_PAGE_SIZE;
+		}
 	}
 
 	drm_dev_exit(idx);
Signature · 1 line
2.52.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 8 lines · On 2026. május 27., szerda 15:19:31 közép-európai nyári idő Donet Tom wrote:

When mapping VRAM pages into the GART page table, amdgpu_gart_map_vram_range() assumes that the system page size is the same as the GPU page size.

On systems with non-4K page sizes, multiple GPU pages can exist within a single CPU page. As a result, the mappings are created incorrectly because fewer page table entries are programmed than required.

Quoted 7 lines

Fix this by programming the mappings correctly for non-4K page size systems.

Fixes 237d623ae659 ("drm/amdgpu/gart: Add helper to bind VRAM pages (v2)")

---

Thank you! The fix looks good to me.

Quoted 28 lines

v2 -> v3
- Addressed Christian's review comments and added the Reviewed-by tag.

v2 -
https://lore.kernel.org/all/[email protected]
/ v1 -
https://lore.kernel.org/all/[email protected]
/ ---

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c index b6f849d51c2e..c4c21dbbbdbf 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +2 -1
@@ -394,7 +394,8 @@ void amdgpu_gart_map_vram_range(struct amdgpu_device
 *adev, uint64_t pa, uint64_t start_page, uint64_t num_pages,
 				uint64_t flags, void *dst)
 {
-	u32 i, idx;
+	u32 i, j, t, idx;
+	u64 page_base;
 
 	/* The SYSTEM flag indicates the pages aren't in VRAM. */
 	WARN_ON_ONCE(flags & AMDGPU_PTE_SYSTEM);

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c void amdgpu_gart_map_vram_range(struct amdgpu_device · line 407

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +0 -3
@@ -402,9 +403,12 @@ void amdgpu_gart_map_vram_range(struct amdgpu_device
 *adev, uint64_t pa, if (!drm_dev_enter(adev_to_drm(adev), &idx))
 		return;
 
-	for (i = 0; i < num_pages; ++i) {
-		amdgpu_gmc_set_pte_pde(adev, dst,
-			start_page + i, pa + AMDGPU_GPU_PAGE_SIZE * 

i, flags);

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c void amdgpu_gart_map_vram_range(struct amdgpu_device *adev, uint64_t pa,

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +3 -0
+	page_base = pa;
+	for (i = 0, t = 0; i < num_pages; i++) {
+		for (j = 0; j < AMDGPU_GPU_PAGES_IN_CPU_PAGE; j++, t++) 

{

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c void amdgpu_gart_map_vram_range(struct amdgpu_device · line 409

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +1 -0
+			amdgpu_gmc_set_pte_pde(adev, dst, start_page 

+ t, page_base, flags);

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +2 -0
+			page_base += AMDGPU_GPU_PAGE_SIZE;
+		}
 	}
 
 	drm_dev_exit(idx);
Applied
#2 lore raw

Applied. Thanks!

Alex

Quoted 72 lines · Timur Kristóf
Quoted 8 lines · On 2026. május 27., szerda 15:19:31 közép-európai nyári idő Donet Tom wrote:

When mapping VRAM pages into the GART page table, amdgpu_gart_map_vram_range() assumes that the system page size is the same as the GPU page size.

On systems with non-4K page sizes, multiple GPU pages can exist within a single CPU page. As a result, the mappings are created incorrectly because fewer page table entries are programmed than required.

Quoted 7 lines

Fix this by programming the mappings correctly for non-4K page size systems.

Fixes 237d623ae659 ("drm/amdgpu/gart: Add helper to bind VRAM pages (v2)")

---

Thank you! The fix looks good to me.

Quoted 28 lines

v2 -> v3
- Addressed Christian's review comments and added the Reviewed-by tag.

v2 -
https://lore.kernel.org/all/[email protected]
/ v1 -
https://lore.kernel.org/all/[email protected]
/ ---

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c index b6f849d51c2e..c4c21dbbbdbf 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +2 -1
@@ -394,7 +394,8 @@ void amdgpu_gart_map_vram_range(struct amdgpu_device
 *adev, uint64_t pa, uint64_t start_page, uint64_t num_pages,
                              uint64_t flags, void *dst)
 {
-     u32 i, idx;
+     u32 i, j, t, idx;
+     u64 page_base;
 
      /* The SYSTEM flag indicates the pages aren't in VRAM. */
      WARN_ON_ONCE(flags & AMDGPU_PTE_SYSTEM);

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c void amdgpu_gart_map_vram_range(struct amdgpu_device · line 407

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +0 -3
@@ -402,9 +403,12 @@ void amdgpu_gart_map_vram_range(struct amdgpu_device
 *adev, uint64_t pa, if (!drm_dev_enter(adev_to_drm(adev), &idx))
              return;
 
-     for (i = 0; i < num_pages; ++i) {
-             amdgpu_gmc_set_pte_pde(adev, dst,
-                     start_page + i, pa + AMDGPU_GPU_PAGE_SIZE *

i, flags);

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c void amdgpu_gart_map_vram_range(struct amdgpu_device *adev, uint64_t pa,

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +3 -0
+     page_base = pa;
+     for (i = 0, t = 0; i < num_pages; i++) {
+             for (j = 0; j < AMDGPU_GPU_PAGES_IN_CPU_PAGE; j++, t++)

{

drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c void amdgpu_gart_map_vram_range(struct amdgpu_device · line 409

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +1 -0
+                     amdgpu_gmc_set_pte_pde(adev, dst, start_page

+ t, page_base, flags);

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +2 -0
+                     page_base += AMDGPU_GPU_PAGE_SIZE;
+             }
      }
 
      drm_dev_exit(idx);