* [PATCH v2] drm/amdgpu: Fix incorrect VRAM GART mappings on non-4K page size systems
@ 2026-05-27 11:17 Donet Tom
2026-05-27 11:54 ` Christian König
0 siblings, 1 reply; 3+ messages in thread
From: Donet Tom @ 2026-05-27 11:17 UTC (permalink / raw)
To: amd-gfx, Felix Kuehling, Alex Deucher, Alex Deucher,
christian.koenig, Philip Yang
Cc: David.YatSin, Kent.Russell, Ritesh Harjani,
Vaidyanathan Srinivasan, donettom, timur.kristof
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)")
Signed-off-by: Donet Tom <donettom@linux.ibm.com>
---
v1 -> v2
- Addressed Felix's comment by updating the definition of
amdgpu_gart_map_vram_range() to support non-4K page sizes.
v1 - https://lore.kernel.org/all/20260522112838.1311531-1-donettom@linux.ibm.com/
---
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
index b6f849d51c2e..66a15ee13b57 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
@@ -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 = 0, 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; 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);
--
2.52.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] drm/amdgpu: Fix incorrect VRAM GART mappings on non-4K page size systems
2026-05-27 11:17 [PATCH v2] drm/amdgpu: Fix incorrect VRAM GART mappings on non-4K page size systems Donet Tom
@ 2026-05-27 11:54 ` Christian König
2026-05-27 12:56 ` Donet Tom
0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2026-05-27 11:54 UTC (permalink / raw)
To: Donet Tom, amd-gfx, Felix Kuehling, Alex Deucher, Alex Deucher,
Philip Yang
Cc: David.YatSin, Kent.Russell, Ritesh Harjani,
Vaidyanathan Srinivasan, timur.kristof
On 5/27/26 13:17, 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.
>
> 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)")
> Signed-off-by: Donet Tom <donettom@linux.ibm.com>
> ---
> v1 -> v2
> - Addressed Felix's comment by updating the definition of
> amdgpu_gart_map_vram_range() to support non-4K page sizes.
>
> v1 - https://lore.kernel.org/all/20260522112838.1311531-1-donettom@linux.ibm.com/
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c | 12 ++++++++----
> 1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
> index b6f849d51c2e..66a15ee13b57 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
> @@ -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 = 0, 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; i < num_pages; i++) {
Please make that for (i = 0, t = 0; .... and remove the initialization of t during deceleration.
I was about to complain that t isn't initialized because I missed the line above.
Apart from that Reviewed-by: Christian König <christian.koenig@amd.com>.
Regards,
Christian
> + 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);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] drm/amdgpu: Fix incorrect VRAM GART mappings on non-4K page size systems
2026-05-27 11:54 ` Christian König
@ 2026-05-27 12:56 ` Donet Tom
0 siblings, 0 replies; 3+ messages in thread
From: Donet Tom @ 2026-05-27 12:56 UTC (permalink / raw)
To: Christian König, amd-gfx, Felix Kuehling, Alex Deucher,
Alex Deucher, Philip Yang
Cc: David.YatSin, Kent.Russell, Ritesh Harjani,
Vaidyanathan Srinivasan, timur.kristof
On 5/27/26 5:24 PM, Christian König wrote:
>
> On 5/27/26 13:17, 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.
>>
>> 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)")
>> Signed-off-by: Donet Tom <donettom@linux.ibm.com>
>> ---
>> v1 -> v2
>> - Addressed Felix's comment by updating the definition of
>> amdgpu_gart_map_vram_range() to support non-4K page sizes.
>>
>> v1 - https://lore.kernel.org/all/20260522112838.1311531-1-donettom@linux.ibm.com/
>> ---
>> drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c | 12 ++++++++----
>> 1 file changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
>> index b6f849d51c2e..66a15ee13b57 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c
>> @@ -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 = 0, 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; i < num_pages; i++) {
> Please make that for (i = 0, t = 0; .... and remove the initialization of t during deceleration.
Thank you Christian
I will send a v3 with this chanage
-Donet
>
> I was about to complain that t isn't initialized because I missed the line above.
>
> Apart from that Reviewed-by: Christian König <christian.koenig@amd.com>.
>
> Regards,
> Christian
>
>> + 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);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-27 12:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-27 11:17 [PATCH v2] drm/amdgpu: Fix incorrect VRAM GART mappings on non-4K page size systems Donet Tom
2026-05-27 11:54 ` Christian König
2026-05-27 12:56 ` Donet Tom
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.