Skip to contentSkip to conversation

drm/amdkfd: fix the clean up when amdgpu_hmm_range_alloc fails

PATCH Superseded Sunil Khatri 2 participants 2 messages Oct 24, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -1
index 7f0ab73e2396..76e36201742a 100644
@@ -1740,7 +1740,7 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
 			range = amdgpu_hmm_range_alloc(NULL);
 			if (unlikely(!range)) {
 				r = -ENOMEM;
-				goto free_ctx;
+				break;
 			}
 
 			r = amdgpu_hmm_range_get_pages(&prange->notifier, addr, npages,
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 14 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 | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
index 7f0ab73e2396..76e36201742a 100644

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

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +1 -1
@@ -1740,7 +1740,7 @@ static int svm_range_validate_and_map(struct mm_struct *mm,
  			range = amdgpu_hmm_range_alloc(NULL);
  			if (unlikely(!range)) {
  				r = -ENOMEM;
-				goto free_ctx;
+				break;

Sorry, looking at the latest code, it's even more complicated because of p->svms.faulting_task, which also needs to be reset.

			WRITE_ONCE(p->svms.faulting_task, current);
 			range = amdgpu_hmm_range_alloc(NULL);
			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);
				pr_debug("failed %d to get svm range pages\n", r);
			}

Regards,
  Felix

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_svm.c +0 -0
  			}
 
  			r = amdgpu_hmm_range_get_pages(&prange->notifier, addr, npages,