Skip to contentSkip to conversation

drm/amdgpu: Fix num_pages calculation in amdgpu_ttm_map_buffer() for non-4K page sizes

PATCH In review Donet Tom 2 participants 3 messages May 22 – May 24

Subsystems (2)
lore
Share & tools
lore

Donet Tom

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Fix num_pages calculation in amdgpu_ttm_map_buffer() for non-4K page sizes

amdgpu_gart_map_vram_range() expects the number of pages (num_pages) in 4K page units. However, in amdgpu_ttm_map_buffer(), the number of pages is calculated based on the system page size. On systems with non-4K page sizes, this results in an incorrect number of pages being passed to amdgpu_gart_map_vram_range().

Fix this by calculating the number of pages correctly before passing it to amdgpu_gart_map_vram_range().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
index 3d2e00efc741..2904a9400605 100644
@@ -269,6 +269,7 @@ static int amdgpu_ttm_map_buffer(struct amdgpu_ttm_buffer_entity *entity,
 		amdgpu_gart_map(adev, 0, num_pages, dma_addr, flags, cpu_addr);
 	} else {
 		u64 pa = mm_cur->start + adev->vm_manager.vram_base_offset;
+		num_pages *= AMDGPU_GPU_PAGES_IN_CPU_PAGE;
 
 		amdgpu_gart_map_vram_range(adev, pa, 0, num_pages, flags, cpu_addr);
 	}
Signature · 1 line
2.47.3
#1 lore raw
Quoted 19 lines · Donet Tom

amdgpu_gart_map_vram_range() expects the number of pages (num_pages) in 4K page units. However, in amdgpu_ttm_map_buffer(), the number of pages is calculated based on the system page size. On systems with non-4K page sizes, this results in an incorrect number of pages being passed to amdgpu_gart_map_vram_range().

Fix this by calculating the number of pages correctly before passing it to amdgpu_gart_map_vram_range().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
index 3d2e00efc741..2904a9400605 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_ttm_map_buffer(struct amdgpu_ttm_buffer_entity *entity, · line 274

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
@@ -269,6 +269,7 @@ static int amdgpu_ttm_map_buffer(struct amdgpu_ttm_buffer_entity *entity,
  		amdgpu_gart_map(adev, 0, num_pages, dma_addr, flags, cpu_addr);
  	} else {
  		u64 pa = mm_cur->start + adev->vm_manager.vram_base_offset;
+		num_pages *= AMDGPU_GPU_PAGES_IN_CPU_PAGE;
 
  		amdgpu_gart_map_vram_range(adev, pa, 0, num_pages, flags, cpu_addr);

IMO it would be cleaner to change the definition of amdgpu_gart_map_vram_range to use the same page size as amdgpu_gart_map.

Regards,
  Felix

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
  	}
author
#2 lore raw
Quoted 16 lines · Felix
Quoted 14 lines · Donet Tom

amdgpu_gart_map_vram_range() expects the number of pages (num_pages) in 4K page units. However, in amdgpu_ttm_map_buffer(), the number of pages is calculated based on the system page size. On systems with non-4K page sizes, this results in an incorrect number of pages being passed to amdgpu_gart_map_vram_range().

Fix this by calculating the number of pages correctly before passing it to amdgpu_gart_map_vram_range().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 1 +

  1 file changed, 1 insertion(+)
Quoted 13 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_ttm_map_buffer(struct · line 274

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
index 3d2e00efc741..2904a9400605 100644
@@ -269,6 +269,7 @@ static int amdgpu_ttm_map_buffer(struct 
 amdgpu_ttm_buffer_entity *entity,
           amdgpu_gart_map(adev, 0, num_pages, dma_addr, flags, cpu_addr);
       } else {
           u64 pa = mm_cur->start + adev->vm_manager.vram_base_offset;
+        num_pages *= AMDGPU_GPU_PAGES_IN_CPU_PAGE;
             amdgpu_gart_map_vram_range(adev, pa, 0, num_pages, flags, cpu_addr);

IMO it would be cleaner to change the definition of amdgpu_gart_map_vram_range to use the same page size as amdgpu_gart_map.

Thank you, Felix, for the review.

I will make the suggested changes in amdgpu_gart_map_vram_range() and post a v2 patch.

-Donet

Quoted 6 lines

Regards,
  Felix

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
       }