drm/amdkfd: SVM map to gpus check vma boundary
Subsystems (3)
PATCH 1/1 drm/amdkfd: SVM map to gpus check vma boundary
SVM range may includes multiple VMAs with different vm_flags, if prange page index is the last page of the VMA offset + npages, update GPU mapping to create GPU page table with same VMA access permission.
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -0
@@ -1178,7 +1178,9 @@ svm_range_map_to_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm,for (i = offset; i < offset + npages; i++) { last_domain = dma_addr[i] &SVM_RANGE_VRAM_DOMAIN ; dma_addr[i] &= ~SVM_RANGE_VRAM_DOMAIN ; +if ((prange->start + i) < prange->last && + i +1 < offset + npages && last_domain == (dma_addr[i +1 ] &SVM_RANGE_VRAM_DOMAIN ))continue ;
Signature · 1 line
2.17.1
Felix Kuehling
maintainerQuoted 14 lines · Philip Yang
SVM range may includes multiple VMAs with different
vm_flags, if prange page index is the last page of the VMA offset + npages, update GPU mapping to create GPU page table with same VMA access permission.Signed-off-by Philip Yang <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0
-0
drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_map_to_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 1183
Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2
-0@@ -1178,7 +1178,9 @@ svm_range_map_to_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm,for (i = offset; i < offset + npages; i++) { last_domain = dma_addr[i] &SVM_RANGE_VRAM_DOMAIN ; dma_addr[i] &= ~SVM_RANGE_VRAM_DOMAIN ; + if ((prange->start + i) < prange->last && + i + 1 < offset + npages &&
I think this would be more intuitive: "i < offset + npages - 1" (meaning i is before the last page in the range)
Do we still need the the "(prange->start + i) < prange->last" condition at all now? I think it could just be replaced with "i < offset + npages - 1".
Regards,
Felix
Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0
-0last_domain == (dma_addr[i + 1] & SVM_RANGE_VRAM_DOMAIN))continue ;
PATCH v2 1/1 drm/amdkfd: SVM map to gpus check vma boundary
In reply to Philip YangSVM range may includes multiple VMAs with different vm_flags, if prange page index is the last page of the VMA offset + npages, update GPU mapping to create GPU page table with same VMA access permission.
--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +6 -1
@@ -1178,7 +1178,12 @@ svm_range_map_to_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm,for (i = offset; i < offset + npages; i++) { last_domain = dma_addr[i] &SVM_RANGE_VRAM_DOMAIN ; dma_addr[i] &= ~SVM_RANGE_VRAM_DOMAIN ; -if ((prange->start + i) < prange->last && + +/* +* If i is not the last page in the range and next page is in +* same VRAM or CPU domain +*/ +if (i < offset + npages -1 && last_domain == (dma_addr[i +1 ] &SVM_RANGE_VRAM_DOMAIN ))continue ;
Signature · 1 line
2.17.1
Quoted 14 lines · Philip Yang
SVM range may includes multiple VMAs with different
vm_flags, if prange page index is the last page of the VMA offset + npages, update GPU mapping to create GPU page table with same VMA access permission.Signed-off-by Philip Yang <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0
-0
drivers/gpu/drm/amd/amdkfd/kfd_svm.c svm_range_map_to_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 1184
Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +4
-1@@ -1178,7 +1178,12 @@ svm_range_map_to_gpu(struct amdgpu_device *adev, struct amdgpu_vm *vm,for (i = offset; i < offset + npages; i++) { last_domain = dma_addr[i] &SVM_RANGE_VRAM_DOMAIN ; dma_addr[i] &= ~SVM_RANGE_VRAM_DOMAIN ; - if ((prange->start + i) < prange->last && + +/* +* If i is not the last page in the range and next page is in +* same VRAM or CPU domain
This comment doesn't add any information. It basically just restates the condition below without explaining the intention. Maybe something like this would be helpful instead:
/* Collect all pages in the same address range and memory domain that can
* be mapped with a single call to amdgpu_vm_bo_update_mapping.
*/
With that fixed, the patch is
Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2
-0+*/ +if (i < offset + npages -1 && last_domain == (dma_addr[i +1 ] &SVM_RANGE_VRAM_DOMAIN ))continue ;