Skip to contentSkip to conversation

drm/amdgpu: drop retry loop in amdgpu_hmm_range_get_pages

PATCH In review Alex Deucher 3 participants 5 messages Jun 16 – Jun 18

Subsystems (4)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu: drop retry loop in amdgpu_hmm_range_get_pages

From: Honglei Huang <[email protected]>

Since commit c08972f55594 ("drm/amdgpu: fix amdgpu_hmm_range_get_pages") moved mmu_interval_read_begin() out of the per-chunk loop, the captured notifier_seq is no longer refreshed across retries. As a result, the existing -EBUSY retry path can never make progress:

hmm_range_fault() returns -EBUSY only when mmu_interval_check_retry(notifier, notifier_seq) reports that the sequence is stale. Once the sequence has advanced, the stored seq will never match again, so every subsequent call within the same invocation returns -EBUSY immediately.

The "goto retry" therefore degenerates into a busy spin that simply burns CPU for the full HMM_RANGE_DEFAULT_TIMEOUT (~1s) window before finally bailing out with -EAGAIN. This is pure latency with no chance of recovery, and it actively hurts the KFD userptr stack: the caller ends up blocked for a second while holding mmap_lock, only to return -EAGAIN to the restore worker (or to userspace) which would have re-driven the operation immediately anyway.

Drop the retry/timeout entirely and let -EBUSY propagate straight to out_free_pfns, where it is already translated to -EAGAIN. Recovery is handled at a higher level: the KFD restore_userptr_worker reschedules itself, and the userptr ioctl path returns -EAGAIN to userspace.

No functional regression: the previous behaviour on -EBUSY was already to fail with -EAGAIN after a 1s stall; we just skip the stall.

Fixes c08972f55594 ("drm/amdgpu: fix amdgpu_hmm_range_get_pages")
(cherry picked from commit 342981fff32802a819d6fc7cf3c9fedf9f3d9d60)

---

This patch is from drm-next and fixes a regression in a patch that went to stable.

 drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1 -8
index e452444b33b0..99bc9ad67d5b 100644
@@ -174,7 +174,6 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,
 	const u64 max_bytes = SZ_2G;
 
 	struct hmm_range *hmm_range = &range->hmm_range;
-	unsigned long timeout;
 	unsigned long *pfns;
 	unsigned long end;
 	int r;
@@ -201,15 +200,9 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,
 		pr_debug("hmm range: start = 0x%lx, end = 0x%lx",
 			hmm_range->start, hmm_range->end);
 
-		timeout = jiffies + msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT);
-
-retry:
 		r = hmm_range_fault(hmm_range);
-		if (unlikely(r)) {
-			if (r == -EBUSY && !time_after(jiffies, timeout))
-				goto retry;
+		if (unlikely(r))
 			goto out_free_pfns;
-		}
 
 		if (hmm_range->end == end)
 			break;
Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 36 lines · Alex Deucher

From: Honglei Huang <[email protected]>

Since commit c08972f55594 ("drm/amdgpu: fix amdgpu_hmm_range_get_pages") moved mmu_interval_read_begin() out of the per-chunk loop, the captured notifier_seq is no longer refreshed across retries. As a result, the existing -EBUSY retry path can never make progress:

hmm_range_fault() returns -EBUSY only when mmu_interval_check_retry(notifier, notifier_seq) reports that the sequence is stale. Once the sequence has advanced, the stored seq will never match again, so every subsequent call within the same invocation returns -EBUSY immediately.

The "goto retry" therefore degenerates into a busy spin that simply burns CPU for the full HMM_RANGE_DEFAULT_TIMEOUT (~1s) window before finally bailing out with -EAGAIN. This is pure latency with no chance of recovery, and it actively hurts the KFD userptr stack: the caller ends up blocked for a second while holding mmap_lock, only to return -EAGAIN to the restore worker (or to userspace) which would have re-driven the operation immediately anyway.

Drop the retry/timeout entirely and let -EBUSY propagate straight to out_free_pfns, where it is already translated to -EAGAIN. Recovery is handled at a higher level: the KFD restore_userptr_worker reschedules itself, and the userptr ioctl path returns -EAGAIN to userspace.

No functional regression: the previous behaviour on -EBUSY was already to fail with -EAGAIN after a 1s stall; we just skip the stall.

Fixes c08972f55594 ("drm/amdgpu: fix amdgpu_hmm_range_get_pages")
(cherry picked from commit 342981fff32802a819d6fc7cf3c9fedf9f3d9d60)
Quoted 4 lines

---

This patch is from drm-next and fixes a regression in a patch that went to stable.

But this commit isn't in Linus's tree yet so we can't take it, right?

confused,

greg k-h

author maintainer
#2 lore raw

Public

Quoted 51 lines

-----Original Message-----
From: Greg KH <[email protected]>
Sent: Tuesday, June 16, 2026 9:21 AM
To: Deucher, Alexander <[email protected]>
Cc: [email protected]; Koenig, Christian <[email protected]>; Huang, Honglei1 <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: drop retry loop in amdgpu_hmm_range_get_pages

Quoted 4 lines · Alex Deucher

From: Honglei Huang <[email protected]>

Since commit c08972f55594 ("drm/amdgpu: fix amdgpu_hmm_range_get_pages") moved mmu_interval_read_begin() out

of

Quoted 2 lines

the per-chunk loop, the captured notifier_seq is no longer refreshed across retries. As a result, the existing -EBUSY retry path can never make

progress:

Quoted 9 lines

hmm_range_fault() returns -EBUSY only when mmu_interval_check_retry(notifier, notifier_seq) reports that the sequence is stale. Once the sequence has advanced, the stored seq will never match again, so every subsequent call within the same invocation returns -EBUSY immediately.

The "goto retry" therefore degenerates into a busy spin that simply burns CPU for the full HMM_RANGE_DEFAULT_TIMEOUT (~1s) window

before

Quoted 23 lines

finally bailing out with -EAGAIN. This is pure latency with no chance of recovery, and it actively hurts the KFD userptr stack: the caller ends up blocked for a second while holding mmap_lock, only to return -EAGAIN to the restore worker (or to userspace) which would have re-driven the operation immediately anyway.

Drop the retry/timeout entirely and let -EBUSY propagate straight to out_free_pfns, where it is already translated to -EAGAIN. Recovery is handled at a higher level: the KFD restore_userptr_worker reschedules itself, and the userptr ioctl path returns -EAGAIN to userspace.

No functional regression: the previous behaviour on -EBUSY was already to fail with -EAGAIN after a 1s stall; we just skip the stall.

from commit 342981fff32802a819d6fc7cf3c9fedf9f3d9d60)
Cc: [email protected]
---

Quoted 4 lines
Quoted 2 lines

This patch is from drm-next and fixes a regression in a patch that went to stable.

But this commit isn't in Linus's tree yet so we can't take it, right?

It was only in drm-next when I sent this email, but it has since landed in Linux tree now that he has pulled the drm tree.

Alex

Quoted 4 lines

confused,

greg k-h

maintainer
#3 lore raw
In reply to Alex Deucher
Quoted 26 lines · Alex Deucher

From: Honglei Huang <[email protected]>

Since commit c08972f55594 ("drm/amdgpu: fix amdgpu_hmm_range_get_pages") moved mmu_interval_read_begin() out of the per-chunk loop, the captured notifier_seq is no longer refreshed across retries. As a result, the existing -EBUSY retry path can never make progress:

hmm_range_fault() returns -EBUSY only when mmu_interval_check_retry(notifier, notifier_seq) reports that the sequence is stale. Once the sequence has advanced, the stored seq will never match again, so every subsequent call within the same invocation returns -EBUSY immediately.

The "goto retry" therefore degenerates into a busy spin that simply burns CPU for the full HMM_RANGE_DEFAULT_TIMEOUT (~1s) window before finally bailing out with -EAGAIN. This is pure latency with no chance of recovery, and it actively hurts the KFD userptr stack: the caller ends up blocked for a second while holding mmap_lock, only to return -EAGAIN to the restore worker (or to userspace) which would have re-driven the operation immediately anyway.

Drop the retry/timeout entirely and let -EBUSY propagate straight to out_free_pfns, where it is already translated to -EAGAIN. Recovery is handled at a higher level: the KFD restore_userptr_worker reschedules itself, and the userptr ioctl path returns -EAGAIN to userspace.

Quoted 4 lines

No functional regression: the previous behaviour on -EBUSY was already to fail with -EAGAIN after a 1s stall; we just skip the stall.

Fixes c08972f55594 ("drm/amdgpu: fix amdgpu_hmm_range_get_pages")

This commit is not anywhere...

#4 lore raw
Quoted 2 lines · Greg KH
Quoted 1 line · Alex Deucher

From: Honglei Huang <[email protected]>

FWIW, that change in between landed in mainline as 342981fff32802 ("drm/amdgpu: drop retry loop in amdgpu_hmm_range_get_pages"), so might be a good idea to add this while applying:

commit 342981fff32802a819d6fc7cf3c9fedf9f3d9d60 upstream.

Quoted 10 lines
Quoted 8 lines

Since commit c08972f55594 ("drm/amdgpu: fix amdgpu_hmm_range_get_pages") moved mmu_interval_read_begin() out of the per-chunk loop, the captured notifier_seq is no longer refreshed across retries. As a result, the existing -EBUSY retry path can never make progress:
[...]
No functional regression: the previous behaviour on -EBUSY was already to fail with -EAGAIN after a 1s stall; we just skip the stall.>>

Fixes c08972f55594 ("drm/amdgpu: fix amdgpu_hmm_range_get_pages")

This commit is not anywhere...

This is 962d684b5dc074 ("drm/amdgpu: fix amdgpu_hmm_range_get_pages") [v7.1-rc6, v7.0.12], which recently landed in mainline a second time as c08972f555945c.

Hope this gets things rolling (I just stumbled on a second report about a regression which should be fixed by this, which is why I thought it might be worth adding these details to the thread in the hope to get this into 7.1.y and 7.0.y soon).

Ciao, Thorsten