Skip to contentSkip to conversation

drm/amdkfd: fix the clean up when amdgpu_hmm_range_alloc fails

PATCH In review Sunil Khatri 2 participants 2 messages Oct 24, 2025

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

PATCH v3 1/1 drm/amdkfd: fix the clean up when amdgpu_hmm_range_alloc fails

we need to unreserve the bo's too during clean up along with freeing the memory of context.

Fixes c549912cd8 (drm/amdkfd: add missing return value check for range)
---
 drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +4 -6
index 7f0ab73e2396..35c592024a01 100644
@@ -1738,14 +1738,12 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
 
 			WRITE_ONCE(p->svms.faulting_task, current);
 			range = amdgpu_hmm_range_alloc(NULL);
-			if (unlikely(!range)) {
-				r = -ENOMEM;
-				goto free_ctx;
-			}
-
-			r = amdgpu_hmm_range_get_pages(&prange->notifier, addr, npages,
+			if (likely(range))
+				r = amdgpu_hmm_range_get_pages(&prange->notifier, addr, npages,
 						       readonly, owner,
 						       range);
+			else
+				r = -ENOMEM;
 			WRITE_ONCE(p->svms.faulting_task, NULL);
 			if (r) {
 				amdgpu_hmm_range_free(range);
Signature · 1 line
2.34.1
maintainer Reviewed-by on v3 1/1
#1 lore raw
Quoted 17 lines · Sunil Khatri

we need to unreserve the bo's too during clean up along with freeing the memory of context.

Fixes c549912cd8 (drm/amdkfd: add missing return value check for range)
---
  drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 10 ++++------
  1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
index 7f0ab73e2396..35c592024a01 100644
@@ -1738,14 +1738,12 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
 
  			WRITE_ONCE(p->svms.faulting_task, current);
  			range = amdgpu_hmm_range_alloc(NULL);

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

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -6
-			if (unlikely(!range)) {
-				r = -ENOMEM;
-				goto free_ctx;
-			}
-
-			r = amdgpu_hmm_range_get_pages(&prange->notifier, addr, npages,
+			if (likely(range))
+				r = amdgpu_hmm_range_get_pages(&prange->notifier, addr, npages,
  						       readonly, owner,
  						       range);

Please fix the indentation here so the parameters line up with the open parenthesis. With that fixed, the patch is

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +2 -0
+			else
+				r = -ENOMEM;
  			WRITE_ONCE(p->svms.faulting_task, NULL);
  			if (r) {
  				amdgpu_hmm_range_free(range);