amdkfd: don't map SVM ranges to a GPU without a VM
Subsystems (3)
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 whenpdd->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
@@ -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
Felix Kuehling
maintainerQuoted 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_mapdoes not check whetherpdd->drm_privis 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_privis NULL to avoid endless
rescheduling ofrestore_work.Signed-off-by Zhu Lingshan <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0
-0@@ -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
-0if (bitmap_empty (ctx->bitmap,MAX_GPU_INSTANCE )) { r =0 ; goto free_ctx;
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_mapdoes not check whetherpdd->drm_privis 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_privis NULL to avoid endless
rescheduling ofrestore_work.Signed-off-by Zhu Lingshan <[email protected]>---
drivers/gpu/drm/amd/amdkfd/kfd_svm.c| 8 ++++++++1 file changed, 8 insertions(+)drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2
-0@@ -1818,6 +1818,14 @@ static int svm_range_validate_and_map(structmm_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 mappingfor 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_attrandsvm_range_new(whereprange->bitmap_accessis initialized for the XNACK-enabled case).svm_range_check_attrgives 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,
FelixQuoted 3 lines
if (
bitmap_empty(ctx->bitmap, MAX_GPU_INSTANCE)) { r = 0;
gotofree_ctx;