Skip to content

Commit fb361a5

Browse files
donettom-1alexdeucher
authored andcommitted
drm/amdkfd: Fix SVM map/unmap address conversion for non-4k page sizes
SVM range size is tracked using the system page size. The range start and end are aligned to system page-sized PFNs, so the total SVM range size equals the total number of pages in the SVM range multiplied by the system page size. The SVM range map/unmap functions pass these system page-sized PFN numbers to amdgpu_vm_update_range(), which expects PFNs based on the GPU page size (4K). On non-4K page systems, this mismatch causes only part of the SVM range to be mapped in the GPU page table, while the rest remains unmapped. If the GPU accesses an unmapped address within the same range, it results in a GPU page fault. To fix this, the required conversion has been added in both svm_range_map_to_gpu() and svm_range_unmap_from_gpu(), ensuring that all pages in the SVM range are correctly mapped on non-4K systems. Acked-by: Christian König <christian.koenig@amd.com> Reviewed-by: Philip Yang <Philip.Yang@amd.com> Signed-off-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com> Signed-off-by: Donet Tom <donettom@linux.ibm.com> Signed-off-by: Felix Kuehling <felix.kuehling@amd.com> Reviewed-by: Felix Kuehling <felix.kuehling@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 42ea9cf commit fb361a5

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

drivers/gpu/drm/amd/amdkfd/kfd_svm.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,11 +1355,16 @@ svm_range_unmap_from_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm,
13551355
struct dma_fence **fence)
13561356
{
13571357
uint64_t init_pte_value = adev->gmc.init_pte_flags;
1358+
uint64_t gpu_start, gpu_end;
13581359

1359-
pr_debug("[0x%llx 0x%llx]\n", start, last);
1360+
/* Convert CPU page range to GPU page range */
1361+
gpu_start = start * AMDGPU_GPU_PAGES_IN_CPU_PAGE;
1362+
gpu_end = (last + 1) * AMDGPU_GPU_PAGES_IN_CPU_PAGE - 1;
13601363

1361-
return amdgpu_vm_update_range(adev, vm, false, true, true, false, NULL, start,
1362-
last, init_pte_value, 0, 0, NULL, NULL,
1364+
pr_debug("CPU[0x%llx 0x%llx] -> GPU[0x%llx 0x%llx]\n", start, last,
1365+
gpu_start, gpu_end);
1366+
return amdgpu_vm_update_range(adev, vm, false, true, true, false, NULL, gpu_start,
1367+
gpu_end, init_pte_value, 0, 0, NULL, NULL,
13631368
fence);
13641369
}
13651370

@@ -1439,6 +1444,9 @@ svm_range_map_to_gpu(struct kfd_process_device *pdd, struct svm_range *prange,
14391444
last_start, last_start + npages - 1, readonly);
14401445

14411446
for (i = offset; i < offset + npages; i++) {
1447+
uint64_t gpu_start;
1448+
uint64_t gpu_end;
1449+
14421450
last_domain = dma_addr[i] & SVM_RANGE_VRAM_DOMAIN;
14431451
dma_addr[i] &= ~SVM_RANGE_VRAM_DOMAIN;
14441452

@@ -1456,17 +1464,22 @@ svm_range_map_to_gpu(struct kfd_process_device *pdd, struct svm_range *prange,
14561464
if (readonly)
14571465
pte_flags &= ~AMDGPU_PTE_WRITEABLE;
14581466

1459-
pr_debug("svms 0x%p map [0x%lx 0x%llx] vram %d PTE 0x%llx\n",
1460-
prange->svms, last_start, prange->start + i,
1461-
(last_domain == SVM_RANGE_VRAM_DOMAIN) ? 1 : 0,
1462-
pte_flags);
14631467

14641468
/* For dGPU mode, we use same vm_manager to allocate VRAM for
14651469
* different memory partition based on fpfn/lpfn, we should use
14661470
* same vm_manager.vram_base_offset regardless memory partition.
14671471
*/
1472+
gpu_start = last_start * AMDGPU_GPU_PAGES_IN_CPU_PAGE;
1473+
gpu_end = (prange->start + i + 1) * AMDGPU_GPU_PAGES_IN_CPU_PAGE - 1;
1474+
1475+
pr_debug("svms 0x%p map CPU[0x%lx 0x%llx] GPU[0x%llx 0x%llx] vram %d PTE 0x%llx\n",
1476+
prange->svms, last_start, prange->start + i,
1477+
gpu_start, gpu_end,
1478+
(last_domain == SVM_RANGE_VRAM_DOMAIN) ? 1 : 0,
1479+
pte_flags);
1480+
14681481
r = amdgpu_vm_update_range(adev, vm, false, false, flush_tlb, true,
1469-
NULL, last_start, prange->start + i,
1482+
NULL, gpu_start, gpu_end,
14701483
pte_flags,
14711484
(last_start - prange->start) << PAGE_SHIFT,
14721485
bo_adev ? bo_adev->vm_manager.vram_base_offset : 0,

0 commit comments

Comments
 (0)