Skip to contentSkip to conversation

amdkfd: don't map SVM ranges to a GPU without a VM

PATCH In review Zhu Lingshan 2 participants 3 messages Nov 20 – Nov 23

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

PATCH 1/1 amdkfd: don't map SVM ranges to a GPU without a VM

If a kfd process does not perform ACQUIRE VM for its kfd_process_device, the VM of the pdd is NULL.

svm_range_validate_and_map does not check whether pdd->drm_priv is NULL before accessing it, and may cause kernel panic.

This commit fixes this issue by skipping any GPUs
that haven't acquired VM in svm map.

This commit does not return an error code when
pdd->drm_priv is NULL to avoid endless
rescheduling of restore_work.

---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +8 -0
index 7401b7fdcb57..b5175f346351 100644
@@ -1818,6 +1818,14 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
 			  prange->bitmap_aip, MAX_GPU_INSTANCE);
 	}
 
+	for (idx = 0; idx < ctx->process->n_pdds; idx++) {
+		if (!ctx->process->pdds[idx]->drm_priv) {
+			pr_debug("GPU %d has no VM acquired, skip SVM mapping for it, please consider acquiring VM for it and perform SVM unmap and map again\n",
+				 ctx->process->pdds[idx]->user_gpu_id);
+			clear_bit(idx, ctx->bitmap);
+		}
+	}
+
 	if (bitmap_empty(ctx->bitmap, MAX_GPU_INSTANCE)) {
 		r = 0;
 		goto free_ctx;
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 24 lines · Zhu Lingshan

If a kfd process does not perform ACQUIRE VM for its kfd_process_device, the VM of the pdd is NULL.

svm_range_validate_and_map does not check whether pdd->drm_priv is NULL before accessing it, and may cause kernel panic.

This commit fixes this issue by skipping any GPUs
that haven't acquired VM in svm map.

This commit does not return an error code when
pdd->drm_priv is NULL to avoid endless
rescheduling of restore_work.

---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 8 ++++++++
  1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
index 7401b7fdcb57..b5175f346351 100644
@@ -1818,6 +1818,14 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
  			  prange->bitmap_aip, MAX_GPU_INSTANCE);

drivers/gpu/drm/amd/amdkfd/kfd_svm.c static int svm_range_validate_and_map(struct mm_struct *mm, · line 1828

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +8 -0
  	}
 
+	for (idx = 0; idx < ctx->process->n_pdds; idx++) {
+		if (!ctx->process->pdds[idx]->drm_priv) {
+			pr_debug("GPU %d has no VM acquired, skip SVM mapping for it, please consider acquiring VM for it and perform SVM unmap and map again\n",
+				 ctx->process->pdds[idx]->user_gpu_id);
+			clear_bit(idx, ctx->bitmap);
+		}
+	}
+

I'd put this check in svm_range_check_attr and svm_range_new (where prange->bitmap_access is initialized for the XNACK-enabled case). svm_range_check_attr gives user mode feedback when they're doing something wrong rather than just silently failing to map memory.

Regards,
  Felix

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
  	if (bitmap_empty(ctx->bitmap, MAX_GPU_INSTANCE)) {
  		r = 0;
  		goto free_ctx;
#2 lore raw
Quoted 35 lines · Felix Kuehling
Quoted 34 lines · Zhu Lingshan

If a kfd process does not perform ACQUIRE VM for its kfd_process_device, the VM of the pdd is NULL.

svm_range_validate_and_map does not check whether pdd->drm_priv is NULL before accessing it, and may cause kernel panic.

This commit fixes this issue by skipping any GPUs
that haven't acquired VM in svm map.

This commit does not return an error code when
pdd->drm_priv is NULL to avoid endless
rescheduling of restore_work.

---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 8 ++++++++

  1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -0
index 7401b7fdcb57..b5175f346351 100644
@@ -1818,6 +1818,14 @@ static int svm_range_validate_and_map(struct
 mm_struct *mm,
                 prange->bitmap_aip, MAX_GPU_INSTANCE);
       }
   +    for (idx = 0; idx < ctx->process->n_pdds; idx++) {
+        if (!ctx->process->pdds[idx]->drm_priv) {
+            pr_debug("GPU %d has no VM acquired, skip SVM mapping

for it, please consider acquiring VM for it and perform SVM unmap and map again\n",
+                 ctx->process->pdds[idx]->user_gpu_id);
+            clear_bit(idx, ctx->bitmap);

Quoted 8 lines
Quoted 3 lines

+        }
+    }
+

I'd put this check in svm_range_check_attr and svm_range_new (where prange->bitmap_access is initialized for the XNACK-enabled case). svm_range_check_attr gives user mode feedback when they're doing something wrong rather than just silently failing to map memory.

Thanks and the new patch has been sent out with title "[PATCH] amdkfd: don't give a GPU access to SVM ranges when no VM"

Thanks
Lingshan

Quoted 8 lines

Regards,
  Felix

Quoted 3 lines

      if (bitmap_empty(ctx->bitmap, MAX_GPU_INSTANCE)) { r = 0;
          goto free_ctx;