Skip to contentSkip to conversation

drm/amdkfd: SVM map to gpus check vma boundary

PATCH Superseded Philip Yang 2 participants 4 messages Sep 13, 2021 – Sep 16, 2021

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

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
index 110c46cd7fac..2e3ee9c46a10 100644
@@ -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
maintainer
#1 lore raw
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.

---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
index 110c46cd7fac..2e3ee9c46a10 100644

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 -0
  		    last_domain == (dma_addr[i + 1] & SVM_RANGE_VRAM_DOMAIN))
  			continue;
 
#2 lore raw

PATCH v2 1/1 drm/amdkfd: SVM map to gpus check vma boundary

In reply to 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.

---
 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
index 110c46cd7fac..de91c7e83bb4 100644
@@ -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
maintainer Reviewed-by on v2 1/1
#3 lore raw
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.

---
  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
index 110c46cd7fac..de91c7e83bb4 100644

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;