Skip to contentSkip to conversation

drm/amdgpu: move notifier_seq read back inside retry loop

PATCH In review Honglei Huang 3 participants 5 messages May 28

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

PATCH 1/1 drm/amdgpu: move notifier_seq read back inside retry loop

Align with drm_gpusvm_get_pages() (drm_gpusvm.c line 1416, 1440) which refreshes notifier_seq via mmu_interval_read_begin() on each retry iteration. Without this, a stale sequence number causes hmm_range_fault() to perpetually return -EBUSY, leading to an infinite retry loop at the caller level.

Fixes 144ba981783f ("drm/amdgpu: fix amdgpu_hmm_range_get_pages")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1 -1
index 5d72878c8..ec0fe9044 100644
@@ -192,7 +192,6 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,
 	end = start + npages * PAGE_SIZE;
 	hmm_range->dev_private_owner = owner;
 
-	hmm_range->notifier_seq = mmu_interval_read_begin(notifier);
 	do {
 		hmm_range->end = min(hmm_range->start + max_bytes, end);
 
@@ -202,6 +201,7 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,
 		timeout = jiffies + msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT);
 
 retry:
+		hmm_range->notifier_seq = mmu_interval_read_begin(notifier);
 		r = hmm_range_fault(hmm_range);
 		if (unlikely(r)) {
 			if (r == -EBUSY && !time_after(jiffies, timeout))
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 5 lines · Honglei Huang

Align with drm_gpusvm_get_pages() (drm_gpusvm.c line 1416, 1440) which refreshes notifier_seq via mmu_interval_read_begin() on each retry iteration. Without this, a stale sequence number causes hmm_range_fault() to perpetually return -EBUSY, leading to an infinite retry loop at the caller level.

Absolutely clear NAK.

This is exactly the bug 144ba981783f ("drm/amdgpu: fix amdgpu_hmm_range_get_pages") tries to fix.

The sequence *must* be grabbed before the loop because it protects all pages and not just the one from the current grabbed chunk.

What probably needs to happen is that we need to move the retry label or just completely stop retrying at all.

Regards,
Christian.

Quoted 27 lines
Fixes 144ba981783f ("drm/amdgpu: fix amdgpu_hmm_range_get_pages")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1 -1
index 5d72878c8..ec0fe9044 100644
@@ -192,7 +192,6 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,
 	end = start + npages * PAGE_SIZE;
 	hmm_range->dev_private_owner = owner;
 
-	hmm_range->notifier_seq = mmu_interval_read_begin(notifier);
 	do {
 		hmm_range->end = min(hmm_range->start + max_bytes, end);
 
@@ -202,6 +201,7 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,
 		timeout = jiffies + msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT);
 
 retry:
+		hmm_range->notifier_seq = mmu_interval_read_begin(notifier);
 		r = hmm_range_fault(hmm_range);
 		if (unlikely(r)) {
 			if (r == -EBUSY && !time_after(jiffies, timeout))
#2 lore raw

AMD General

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, May 28, 2026 2:54 PM
To: Huang, Honglei1 <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Huang, Ray <[email protected]>; Prosyak, Vitaly <[email protected]>; Liu, Jenny (Jing) <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: move notifier_seq read back inside retry loop

Quoted 5 lines · Honglei Huang

Align with drm_gpusvm_get_pages() (drm_gpusvm.c line 1416, 1440) which refreshes notifier_seq via mmu_interval_read_begin() on each retry iteration. Without this, a stale sequence number causes hmm_range_fault() to perpetually return -EBUSY, leading to an infinite retry loop at the caller level.

Absolutely clear NAK.

This is exactly the bug 144ba981783f ("drm/amdgpu: fix amdgpu_hmm_range_get_pages") tries to fix.

The sequence *must* be grabbed before the loop because it protects all pages and not just the one from the current grabbed chunk.

What probably needs to happen is that we need to move the retry label or just completely stop retrying at all.

Got it.
But in my local test, the test KFDMemoryTest.LargestSysBufferTest always fail. It can pass before. This case needs RAM size big enough to reproduce, for some large RAM size CI platform, it can reproduce easily. Maybe someone can else can double check.

And I understand your concern about the seq scope.

Would it be acceptable to just remove the internal retry entirely and propagate -EBUSY to the caller? The caller already handles retry at a higher level. Something like:

hmm_range->notifier_seq = mmu_interval_read_begin(notifier); r = hmm_range_fault(hmm_range);
if (unlikely(r))

    goto out_free_pfns;

This keeps your seq placement while eliminating the infinite loop on -EBUSY.

Regards,
Christian.

Quoted 28 lines
Fixes 144ba981783f ("drm/amdgpu: fix amdgpu_hmm_range_get_pages")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1 -1
index 5d72878c8..ec0fe9044 100644
@@ -192,7 +192,6 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,
      end = start + npages * PAGE_SIZE;
      hmm_range->dev_private_owner = owner;
 
-     hmm_range->notifier_seq = mmu_interval_read_begin(notifier);
      do {
              hmm_range->end = min(hmm_range->start + max_bytes, end);
 
@@ -202,6 +201,7 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,
              timeout = jiffies + msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT);
 
 retry:
+             hmm_range->notifier_seq = mmu_interval_read_begin(notifier);
              r = hmm_range_fault(hmm_range);
              if (unlikely(r)) {
                      if (r == -EBUSY && !time_after(jiffies, timeout))
maintainer
#3 lore raw
Quoted 18 lines · On 5/28/26 09:22, Huang, Honglei1 wrote:

AMD General

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, May 28, 2026 2:54 PM
To: Huang, Honglei1 <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Huang, Ray <[email protected]>; Prosyak, Vitaly <[email protected]>; Liu, Jenny (Jing) <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: move notifier_seq read back inside retry loop

Quoted 5 lines · Honglei Huang

Align with drm_gpusvm_get_pages() (drm_gpusvm.c line 1416, 1440) which refreshes notifier_seq via mmu_interval_read_begin() on each retry iteration. Without this, a stale sequence number causes hmm_range_fault() to perpetually return -EBUSY, leading to an infinite retry loop at the caller level.

Absolutely clear NAK.

Quoted 8 lines

This is exactly the bug 144ba981783f ("drm/amdgpu: fix amdgpu_hmm_range_get_pages") tries to fix.

The sequence *must* be grabbed before the loop because it protects all pages and not just the one from the current grabbed chunk.

What probably needs to happen is that we need to move the retry label or just completely stop retrying at all.

Got it.
But in my local test, the test KFDMemoryTest.LargestSysBufferTest always fail.

I mean that's pretty much intentional. Testing is for falsification and not validation.

Either the use case is not valid in the first place or the test is not valid.

Quoted 8 lines

It can pass before. This case needs RAM size big enough to reproduce, for some large RAM size CI platform, it can reproduce easily. Maybe someone can else can double check.

And I understand your concern about the seq scope.

Would it be acceptable to just remove the internal retry entirely and propagate -EBUSY to the caller?

Yeah I had a similar thought. I don't think the code should retry at all.

-EBUSY means userspace did something in parallel which resulting in the operation to not be able to complete.

So the only good reaction I can see is to abort and let user space or higher level retry.

Regards,
Christian.

Quoted 43 lines

The caller already handles retry at a
higher level. Something like:

hmm_range->notifier_seq = mmu_interval_read_begin(notifier); r = hmm_range_fault(hmm_range);
if (unlikely(r))

    goto out_free_pfns;

This keeps your seq placement while eliminating the infinite loop on -EBUSY.

Regards,
Christian.

Quoted 28 lines
Fixes 144ba981783f ("drm/amdgpu: fix amdgpu_hmm_range_get_pages")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1 -1
index 5d72878c8..ec0fe9044 100644
@@ -192,7 +192,6 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,
      end = start + npages * PAGE_SIZE;
      hmm_range->dev_private_owner = owner;
 
-     hmm_range->notifier_seq = mmu_interval_read_begin(notifier);
      do {
              hmm_range->end = min(hmm_range->start + max_bytes, end);
 
@@ -202,6 +201,7 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,
              timeout = jiffies + msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT);
 
 retry:
+             hmm_range->notifier_seq = mmu_interval_read_begin(notifier);
              r = hmm_range_fault(hmm_range);
              if (unlikely(r)) {
                      if (r == -EBUSY && !time_after(jiffies, timeout))
#4 lore raw
Quoted 23 lines · Christian König
Quoted 22 lines · On 5/28/26 09:22, Huang, Honglei1 wrote:

AMD General

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, May 28, 2026 2:54 PM
To: Huang, Honglei1 <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Huang, Ray <[email protected]>; Prosyak, Vitaly <[email protected]>; Liu, Jenny (Jing) <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: move notifier_seq read back inside retry loop

Quoted 5 lines · Honglei Huang

Align with drm_gpusvm_get_pages() (drm_gpusvm.c line 1416, 1440) which refreshes notifier_seq via mmu_interval_read_begin() on each retry iteration. Without this, a stale sequence number causes hmm_range_fault() to perpetually return -EBUSY, leading to an infinite retry loop at the caller level.

Absolutely clear NAK.

This is exactly the bug 144ba981783f ("drm/amdgpu: fix amdgpu_hmm_range_get_pages") tries to fix.

The sequence *must* be grabbed before the loop because it protects all pages and not just the one from the current grabbed chunk.

Quoted 9 lines
Quoted 4 lines

What probably needs to happen is that we need to move the retry label or just completely stop retrying at all.

Got it.
But in my local test, the test KFDMemoryTest.LargestSysBufferTest always fail.

I mean that's pretty much intentional. Testing is for falsification and not validation.

Either the use case is not valid in the first place or the test is not valid.

Yes, under the current pattern this case is hard to pass for large system memory platform.

Quoted 6 lines
Quoted 6 lines

It can pass before. This case needs RAM size big enough to reproduce, for some large RAM size CI platform, it can reproduce easily. Maybe someone can else can double check.

And I understand your concern about the seq scope.

Quoted 8 lines
Quoted 2 lines

Would it be acceptable to just remove the internal retry entirely and propagate -EBUSY to the caller?

Yeah I had a similar thought. I don't think the code should retry at all.

-EBUSY means userspace did something in parallel which resulting in the operation to not be able to complete.

So the only good reaction I can see is to abort and let user space or higher level retry.

Yes, and actually I think maybe there are two points need to be changed.
If we want to keep the retry tag, the retry need to be moved to the start of do while loop, the entire fault path need to be done again, the previous 2G size chunks should not be skipped. The retry tag in the middle of the loop is meaningless. The whole range should be retry again.

And the latest seq number should be get when restart the retry. Or there will be a -EBUSY infinite loop when a retry is needed, cause the seq number never get updated.

This can be done in inside a function or outside a function.
If a retry is needed at a high level calling, modifications will also be required at other call points, and there are many places need to be modified.

However, even with the above fixes, faults in large intervals may still get stuck in endless retries. I got a the pages from a system with 60G of memory, memory changes are inevitable in my local tests.

Perhaps the better approach is to split the huge range into smaller chunks, like drm_gpusvm does with 2 MiB ranges, and get the pages and insert each one into the MMU notifier individually. In this way, registration for a large area can be completed, although it will be time consuming.
But it's better than the situation of constantly trying again and again.

Regards,
Honglei

Quoted 48 lines

Regards,
Christian.

Quoted 43 lines

The caller already handles retry at a
higher level. Something like:

hmm_range->notifier_seq = mmu_interval_read_begin(notifier); r = hmm_range_fault(hmm_range);
if (unlikely(r))

     goto out_free_pfns;

This keeps your seq placement while eliminating the infinite loop on -EBUSY.

Regards,
Christian.

Quoted 28 lines
Fixes 144ba981783f ("drm/amdgpu: fix amdgpu_hmm_range_get_pages")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c +1 -1
index 5d72878c8..ec0fe9044 100644
@@ -192,7 +192,6 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,
       end = start + npages * PAGE_SIZE;
       hmm_range->dev_private_owner = owner;
 
-     hmm_range->notifier_seq = mmu_interval_read_begin(notifier);
       do {
               hmm_range->end = min(hmm_range->start + max_bytes, end);
 
@@ -202,6 +201,7 @@ int amdgpu_hmm_range_get_pages(struct mmu_interval_notifier *notifier,
               timeout = jiffies + msecs_to_jiffies(HMM_RANGE_DEFAULT_TIMEOUT);
 
  retry:
+             hmm_range->notifier_seq = mmu_interval_read_begin(notifier);
               r = hmm_range_fault(hmm_range);
               if (unlikely(r)) {
                       if (r == -EBUSY && !time_after(jiffies, timeout))