Skip to contentSkip to conversation

drm/amdkfd: Skip handle mapping SVM range with no GPU access

PATCH In review Philip Yang 2 participants 2 messages Jun 29, 2023

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

PATCH 1/1 drm/amdkfd: Skip handle mapping SVM range with no GPU access

If the SVM range has no GPU access or access-in-place attribute, validate and map to GPU should skip the range.

Add NULL pointer check if find_first_bit(ctx->bitmap, MAX_GPU_INSTANCE) returns MAX_GPU_INSTANCE as gpuidx if ctx->bitmap is empty.

---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +5 -3
index 5ff1a5a89d96..479c4f66afa7 100644
@@ -1522,6 +1522,8 @@ static void *kfd_svm_page_owner(struct kfd_process *p, int32_t gpuidx)
 	struct kfd_process_device *pdd;
 
 	pdd = kfd_process_device_from_gpuidx(p, gpuidx);
+	if (!pdd)
+		return NULL;
 
 	return SVM_ADEV_PGMAP_OWNER(pdd->dev->adev);
 }
@@ -1596,12 +1598,12 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
 	}
 
 	if (bitmap_empty(ctx->bitmap, MAX_GPU_INSTANCE)) {
-		if (!prange->mapped_to_gpu) {
+		bitmap_copy(ctx->bitmap, prange->bitmap_access, MAX_GPU_INSTANCE);
+		if (!prange->mapped_to_gpu ||
+		    bitmap_empty(ctx->bitmap, MAX_GPU_INSTANCE)) {
 			r = 0;
 			goto free_ctx;
 		}
-
-		bitmap_copy(ctx->bitmap, prange->bitmap_access, MAX_GPU_INSTANCE);
 	}
 
 	if (prange->actual_loc && !prange->ttm_res) {
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 1 line · Philip Yang

If the SVM range has no GPU access or access-in-place attribute,

Just a nit-pick. Shouldn't be no GPU access nor access-in-place?

Quoted 6 lines

validate and map to GPU should skip the range.

Add NULL pointer check if find_first_bit(ctx->bitmap, MAX_GPU_INSTANCE) returns MAX_GPU_INSTANCE as gpuidx if ctx->bitmap is empty.

Quoted 33 lines
---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +5 -3
index 5ff1a5a89d96..479c4f66afa7 100644
@@ -1522,6 +1522,8 @@ static void *kfd_svm_page_owner(struct kfd_process *p, int32_t gpuidx)
  	struct kfd_process_device *pdd;
 
  	pdd = kfd_process_device_from_gpuidx(p, gpuidx);
+	if (!pdd)
+		return NULL;
 
  	return SVM_ADEV_PGMAP_OWNER(pdd->dev->adev);
  }
@@ -1596,12 +1598,12 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
  	}
 
  	if (bitmap_empty(ctx->bitmap, MAX_GPU_INSTANCE)) {
-		if (!prange->mapped_to_gpu) {
+		bitmap_copy(ctx->bitmap, prange->bitmap_access, MAX_GPU_INSTANCE);
+		if (!prange->mapped_to_gpu ||
+		    bitmap_empty(ctx->bitmap, MAX_GPU_INSTANCE)) {
  			r = 0;
  			goto free_ctx;
  		}
-
-		bitmap_copy(ctx->bitmap, prange->bitmap_access, MAX_GPU_INSTANCE);
  	}
 
  	if (prange->actual_loc && !prange->ttm_res) {