drm/amdgpu: Wait for eviction fence before scheduling resume work
Subsystems (2)
PATCH 1/1 drm/amdgpu: Wait for eviction fence before scheduling resume work
In the amdgpu_userq_evict function, after signaling the eviction fence, we need to ensure it's processed before scheduling the resume work. This prevents potential race conditions where the resume work might start before the eviction fence has been fully handled, leading to inconsistent state in user queues.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4 -0
@@ -1238,6 +1238,10 @@ amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr,return ; } +/* Wait for eviction fence to be processed before schedule a resume work */ +if (dma_fence_wait_timeout (&ev_fence->base, false,msecs_to_jiffies (100 )) <=0 ) { +dev_warn (adev->dev,"Eviction fence wait timed out\n" ); + }/* Schedule a resume work */ schedule_delayed_work (&uq_mgr->resume_work,0 ); }
Signature · 1 line
2.49.0
Christian König
maintainerQuoted 5 lines · Jesse.Zhang
In the
amdgpu_userq_evictfunction, after signaling the eviction fence, we need to ensure it's processed before scheduling the resume work. This prevents potential race conditions where the resume work might start before the eviction fence has been fully handled, leading to inconsistent state in user queues.
Well signaling the fence means it is fully processed. So this change here is just bluntly nonsense.
What exactly is happening?
Regards,
Christian.
Quoted 21 lines
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4
-0@@ -1238,6 +1238,10 @@ amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr,return ; } +/* Wait for eviction fence to be processed before schedule a resume work */ +if (dma_fence_wait_timeout (&ev_fence->base, false,msecs_to_jiffies (100 )) <=0 ) { +dev_warn (adev->dev,"Eviction fence wait timed out\n" ); + }/* Schedule a resume work */ schedule_delayed_work (&uq_mgr->resume_work,0 ); }
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 15 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, December 9, 2025 5:42 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Wait for eviction fence before scheduling resume workQuoted 5 lines · Jesse.Zhang
In the
amdgpu_userq_evictfunction, after signaling the eviction fence, we need to ensure it's processed before scheduling the resume work. This prevents potential race conditions where the resume work might start before the eviction fence has been fully handled, leading to inconsistent state in user queues.
Quoted 4 lines
Well signaling the fence means it is fully processed. So this change here is just bluntly nonsense.
What exactly is happening?
[Zhang, Jesse(Jie)] Hi Christian,
Let me clarify the issue we're observing with the SDMA user queues under stress.
**The Problem:**
During stress testing of SDMA user queues, we intermittently see stale doorbell values persisting after the CPU writes to cpu_wptr. Specifically, after updating cpu_wptr (which should update the doorbell), the doorbell register sometimes retains its previous value, causing inconsistent queue behavior. This happens randomly under heavy load but is reproducible in stress scenarios.
**Root Cause Analysis:**
After signaling the eviction fence, the resume work is scheduled immediately without ensuring that all internal driver state updates (queue state transitions, MES state cleanup, etc.) are fully visible and consistent.
How about changing it this way?
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1 -1
@@ -1130,8 +1130,27 @@ static void amdgpu_userq_restore_worker(struct work_struct *work) {/* Schedule a resume work */ -schedule_delayed_work (&uq_mgr->resume_work,0 ); +schedule_delayed_work (&uq_mgr->resume_work,usecs_to_jiffies (1000 ));
Thanks
Jesse
Quoted 27 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_evict(struct amdgpu_userq_mgr
Quoted 12 lines
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0@@ -1238,6 +1238,10 @@ amdgpu_userq_evict(struct amdgpu_userq_mgr
*uq_mgr,drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_evict(struct amdgpu_userq_mgr · line 1242
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-0return ; } +/* Wait for eviction fence to be processed before schedule a resume work */ + if (dma_fence_wait_timeout(&ev_fence->base, false, msecs_to_jiffies(100))<= 0) {
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-0+dev_warn (adev->dev,"Eviction fence wait timed out\n" ); + }/* Schedule a resume work */ schedule_delayed_work (&uq_mgr->resume_work,0 ); }
Christian König
maintainerQuoted 31 lines · Jesse(Jie)
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 15 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, December 9, 2025 5:42 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Wait for eviction fence before scheduling resume workQuoted 5 lines · Jesse.Zhang
In the
amdgpu_userq_evictfunction, after signaling the eviction fence, we need to ensure it's processed before scheduling the resume work. This prevents potential race conditions where the resume work might start before the eviction fence has been fully handled, leading to inconsistent state in user queues.Quoted 4 lines
Well signaling the fence means it is fully processed. So this change here is just bluntly nonsense.
What exactly is happening?
[Zhang, Jesse(Jie)] Hi Christian,
Let me clarify the issue we're observing with the SDMA user queues under stress.
**The Problem:**
During stress testing of SDMA user queues, we intermittently see stale doorbell values persisting after the CPU writes tocpu_wptr. Specifically, after updatingcpu_wptr(which should update the doorbell), the doorbell register sometimes retains its previous value, causing inconsistent queue behavior. This happens randomly under heavy load but is reproducible in stress scenarios.
Quoted 3 lines
**Root Cause Analysis:**
After signaling the eviction fence, the resume work is scheduled immediately without ensuring that all internal driver state updates (queue state transitions, MES state cleanup, etc.) are fully visible and consistent.
That is a massive bug and the root cause of this issue.
The eviction fence can only be signaled *after* all queue state transitions and the MES state is clean.
What the heck is going on here? What state are we talking about?
Quoted 1 line
How about changing it this way?
Stuff like that is an absolutely clear NAK as well.
Regards,
Christian.
Quoted 39 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-1@@ -1130,8 +1130,27 @@ static void amdgpu_userq_restore_worker(struct work_struct *work) {/* Schedule a resume work */ -schedule_delayed_work (&uq_mgr->resume_work,0 ); +schedule_delayed_work (&uq_mgr->resume_work,usecs_to_jiffies (1000 ));Thanks
JesseQuoted 27 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_evict(struct amdgpu_userq_mgr
Quoted 12 lines
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0@@ -1238,6 +1238,10 @@ amdgpu_userq_evict(struct amdgpu_userq_mgr
*uq_mgr,drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_evict(struct amdgpu_userq_mgr · line 1242
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-0return ; } +/* Wait for eviction fence to be processed before schedule a resume work */ + if (dma_fence_wait_timeout(&ev_fence->base, false, msecs_to_jiffies(100))<= 0) {
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-0+dev_warn (adev->dev,"Eviction fence wait timed out\n" ); + }/* Schedule a resume work */ schedule_delayed_work (&uq_mgr->resume_work,0 ); }
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 48 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Wednesday, December 10, 2025 5:53 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Wait for eviction fence before scheduling resume workQuoted 18 lines · Jesse(Jie)
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 16 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, December 9, 2025 5:42 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Wait for eviction fence before scheduling resume workQuoted 5 lines · Jesse.Zhang
In the
amdgpu_userq_evictfunction, after signaling the eviction fence, we need to ensure it's processed before scheduling the resume work. This prevents potential race conditions where the resume work might start before the eviction fence has been fully handled, leading to inconsistent state in user queues.Quoted 7 lines
Quoted 4 lines
Well signaling the fence means it is fully processed. So this change here is just bluntly nonsense.
What exactly is happening?
[Zhang, Jesse(Jie)] Hi Christian,
Let me clarify the issue we're observing with the SDMA user queues under
stress.
Quoted 3 lines
**The Problem:**
During stress testing of SDMA user queues, we intermittently see stale doorbellvalues persisting after the CPU writes to
cpu_wptr.Quoted 2 lines
Specifically, after updating
cpu_wptr(which should update the doorbell), the doorbell register sometimes retains its previous value, causinginconsistent queue behavior. This happens randomly under heavy load but is reproducible in stress scenarios.
Quoted 5 lines
**Root Cause Analysis:**
After signaling the eviction fence, the resume work is scheduled immediately without ensuring that all internal driver state updates (queue state
Quoted 8 lines
transitions, MES state cleanup, etc.) are fully visible and consistent.
That is a massive bug and the root cause of this issue.
The eviction fence can only be signaled *after* all queue state transitions and the MES state is clean.
What the heck is going on here? What state are we talking about?
[Zhang, Jesse(Jie)] This issue was discovered during SDMA user queue testing in the IGT. After updating wptr_cpu and the doorbell from CPU side, the doorbell register sometimes randomly retains its previous value. We suspect this is related to the memory synchronization. Do you have any guidance on this?
Here is the internal ticket : https://ontrack-internal.amd.com/browse/SWDEV-565880>
Thanks
Jesse
Quoted 49 lines
Quoted 1 line
How about changing it this way?
Stuff like that is an absolutely clear NAK as well.
Regards,
Christian.Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-1@@ -1130,8 +1130,27 @@ static void amdgpu_userq_restore_worker(struct work_struct *work) {/* Schedule a resume work */ -schedule_delayed_work (&uq_mgr->resume_work,0 ); +schedule_delayed_work (&uq_mgr->resume_work, +usecs_to_jiffies (1000 ));Quoted 24 lines
Thanks
JesseQuoted 21 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_evict(struct amdgpu_userq_mgr
Quoted 12 lines
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0@@ -1238,6 +1238,10 @@ amdgpu_userq_evict(struct amdgpu_userq_mgr
*uq_mgr,Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-0return ; } +/* Wait for eviction fence to be processed before schedule a resume work */
Quoted 8 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_evict(struct amdgpu_userq_mgr · line 1243
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-0+if (dma_fence_wait_timeout (&ev_fence->base, false, + msecs_to_jiffies(100))<= 0) {
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-0+dev_warn (adev->dev,"Eviction fence wait timed out\n" ); + }/* Schedule a resume work */ schedule_delayed_work (&uq_mgr->resume_work,0 ); }