Skip to contentSkip to conversation

drm/amdkfd: Align partition memory size to page size

PATCH In review Philip Yang 2 participants 2 messages May 19, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdkfd: Align partition memory size to page size

The compute partition memory size calculated from KFD_XCP_MEMORY_SIZE may not align to page size if xcp_mgr->num_xcp_per_mem_partition is 6.

Change the KFD_XCP_MEMORY_SIZE macro to return page align size, so KFD node memory size reported in sysfs is page align size, to avoid application VRAM allocation failure because application may use the size directly and Thunk requires the memory allocation size is page size align.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
index 5de92c9ab18f..66f80b9ab0c5 100644
@@ -804,7 +804,7 @@ u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id)
 	if (adev->gmc.num_mem_partitions && xcp_id >= 0 && mem_id >= 0) {
 		tmp = adev->gmc.mem_partitions[mem_id].size;
 		do_div(tmp, adev->xcp_mgr->num_xcp_per_mem_partition);
-		return tmp;
+		return ALIGN_DOWN(tmp, PAGE_SIZE);
 	} else {
 		return adev->gmc.real_vram_size;
 	}
Signature · 1 line
2.35.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Philip Yang

The compute partition memory size calculated from KFD_XCP_MEMORY_SIZE may not align to page size if xcp_mgr->num_xcp_per_mem_partition is 6.

Change the KFD_XCP_MEMORY_SIZE macro to return page align size, so KFD node memory size reported in sysfs is page align size, to avoid application VRAM allocation failure because application may use the size directly and Thunk requires the memory allocation size is page size align.

Quoted 17 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
index 5de92c9ab18f..66f80b9ab0c5 100644
@@ -804,7 +804,7 @@ u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id)
  	if (adev->gmc.num_mem_partitions && xcp_id >= 0 && mem_id >= 0) {
  		tmp = adev->gmc.mem_partitions[mem_id].size;
  		do_div(tmp, adev->xcp_mgr->num_xcp_per_mem_partition);
-		return tmp;
+		return ALIGN_DOWN(tmp, PAGE_SIZE);
  	} else {
  		return adev->gmc.real_vram_size;
  	}