drm/amdgpu: defer GPU recovery after userq eviction failure
Subsystems (2)
PATCH 1/9 drm/amdgpu: defer GPU recovery after userq eviction failure
On userq eviction failure, the suspend worker waits for reset_work while holding userq_mutex and inside a DMA-fence signaling section. This makes eviction-fence completion depend on GPU recovery finishing, although recovery can itself require memory allocation and eviction.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 12 +++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 10 +++------- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +9 -3
@@ -65,6 +65,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;struct dma_fence *ev_fence;bool cookie; +int r;mutex_lock (&uq_mgr->userq_mutex);
@@ -79,21 +80,26 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work) cookie =dma_fence_begin_signalling (); ev_fence =amdgpu_evf_mgr_get_fence (evf_mgr); -amdgpu_userq_evict (uq_mgr); + r =amdgpu_userq_evict (uq_mgr);/* * Signaling the eviction fence must be done while holding the * userq_mutex. Otherwise we won't resume the queues before issuing the * next fence. */ -dma_fence_signal (ev_fence); +if (!r) +dma_fence_signal (ev_fence);dma_fence_end_signalling (cookie);dma_fence_put (ev_fence); -if (!evf_mgr->shutdown) +if (!r && !evf_mgr->shutdown)schedule_delayed_work (&uq_mgr->resume_work,0 );mutex_unlock (&uq_mgr->userq_mutex); + +if (r) +amdgpu_reset_domain_schedule (uq_mgr->adev->reset_domain, + &uq_mgr->reset_work); } int amdgpu_evf_mgr_attach_fence(struct amdgpu_eviction_fence_mgr *evf_mgr,
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3 -7
@@ -1308,13 +1308,9 @@ amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr) ret = r; } -if (ret) { +if (ret)drm_file_err (uq_mgr->file,"Couldn't unmap all the queues, eviction failed ret=%d\n" , ret); -amdgpu_reset_domain_schedule (uq_mgr->adev->reset_domain, - &uq_mgr->reset_work); -flush_work (&uq_mgr->reset_work); - }return ret; }
@@ -1334,10 +1330,10 @@ amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr) } } -void +int amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr) { -amdgpu_userq_evict_all (uq_mgr); +return amdgpu_userq_evict_all (uq_mgr); } int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv,
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1 -1
@@ -163,7 +163,7 @@ void amdgpu_userq_mgr_cancel_resume(struct amdgpu_userq_mgr *userq_mgr);void amdgpu_userq_mgr_fini (struct amdgpu_userq_mgr *userq_mgr);void amdgpu_userq_wait_for_signal (struct amdgpu_userq_mgr *uq_mgr); -void amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr); +int amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr);void amdgpu_userq_ensure_ev_fence (struct amdgpu_userq_mgr *userq_mgr,struct amdgpu_eviction_fence_mgr *evf_mgr);
Signature · 1 line
2.34.1
PATCH 2/9 drm/amdgpu: skip VKMS mode-config helpers during GPU reset
GPU recovery already notifies DRM clients. Skip the VKMS mode-config suspend/resume helpers during that internal reset to avoid duplicate client notification and atomic-state handling under the reset lock. Keep ordinary system suspend and resume unchanged.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +6 -0
@@ -491,6 +491,9 @@ static int amdgpu_vkms_suspend(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int r; +if (amdgpu_in_reset (adev)) +return 0 ; + r =drm_mode_config_helper_suspend (adev_to_drm (adev));if (r)return r;
@@ -505,6 +508,9 @@ static int amdgpu_vkms_resume(struct amdgpu_ip_block *ip_block) r =amdgpu_vkms_hw_init (ip_block);if (r)return r; +if (amdgpu_in_reset (ip_block->adev)) +return 0 ; +return drm_mode_config_helper_resume (adev_to_drm (ip_block->adev)); }
Signature · 1 line
2.34.1
Christian König
maintainerRe: [PATCH 2/9] drm/amdgpu: skip VKMS mode-config helpers during GPU reset
Quoted 4 lines · Prike Liang
GPU recovery already notifies DRM clients. Skip the VKMS mode-config suspend/resume helpers during that internal reset to avoid duplicate client notification and atomic-state handling under the reset lock. Keep ordinary system suspend and resume unchanged.
Clear NAK to that as well.
The amdgpu_in_reset() function can only be called from inside the GPU reset itself!
It is *NOT* allowed to skip any operation outside the reset depending on this.
Regards,
Christian.
Quoted 30 lines
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +6
-0@@ -491,6 +491,9 @@ static int amdgpu_vkms_suspend(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int r; +if (amdgpu_in_reset (adev)) +return 0 ; + r =drm_mode_config_helper_suspend (adev_to_drm (adev));if (r)return r;@@ -505,6 +508,9 @@ static int amdgpu_vkms_resume(struct amdgpu_ip_block *ip_block) r =amdgpu_vkms_hw_init (ip_block);if (r)return r; +if (amdgpu_in_reset (ip_block->adev)) +return 0 ; +return drm_mode_config_helper_resume (adev_to_drm (ip_block->adev)); }
RE: [PATCH 2/9] drm/amdgpu: skip VKMS mode-config helpers during GPU reset
AMD General
Regards,
Prike
Quoted 15 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, October 13, 2026 5:28 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH 2/9] drm/amdgpu: skip VKMS mode-config helpers during GPU resetQuoted 4 lines · Prike Liang
GPU recovery already notifies DRM clients. Skip the VKMS mode-config suspend/resume helpers during that internal reset to avoid duplicate client notification and atomic-state handling under the reset lock. Keep ordinary system suspend and resume unchanged.
Quoted 5 lines
Clear NAK to that as well.
The
amdgpu_in_reset()function can only be called from inside the GPU reset itself!It is *NOT* allowed to skip any operation outside the reset depending on this.
How about moving the drm_mode_config_helper_suspend()/resume() calls for VKMS into the system suspend/resume path (amdgpu_device_suspend/resume())? VKMS has no hardware state a reset can lose, so recovery doesn't need them, and that can drop the amdgpu_in_reset() check entirely.
Regards,
Prike
Quoted 36 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c static int amdgpu_vkms_suspend(struct
Quoted 12 lines
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +0
-0@@ -491,6 +491,9 @@ static int amdgpu_vkms_suspend(struct
amdgpu_ip_block*ip_block)drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c static int amdgpu_vkms_resume(struct amdgpu_ip_block
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +3
-0struct amdgpu_device *adev = ip_block->adev;int r; +if (amdgpu_in_reset (adev)) +return 0 ; + r =drm_mode_config_helper_suspend (adev_to_drm (adev));if (r)return r;@@ -505,6 +508,9 @@ static int amdgpu_vkms_resume(struct amdgpu_ip_block
*ip_block)Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +3
-0r =amdgpu_vkms_hw_init (ip_block);if (r)return r; +if (amdgpu_in_reset (ip_block->adev)) +return 0 ; +return drm_mode_config_helper_resume (adev_to_drm (ip_block->adev)); }
Christian König
maintainerRe: [PATCH 2/9] drm/amdgpu: skip VKMS mode-config helpers during GPU reset
Quoted 22 lines · Prike
AMD General
Regards,
PrikeQuoted 17 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, October 13, 2026 5:28 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH 2/9] drm/amdgpu: skip VKMS mode-config helpers during GPU resetQuoted 4 lines · Prike Liang
GPU recovery already notifies DRM clients. Skip the VKMS mode-config suspend/resume helpers during that internal reset to avoid duplicate client notification and atomic-state handling under the reset lock. Keep ordinary system suspend and resume unchanged.
Clear NAK to that as well.
Quoted 8 lines
Quoted 3 lines
The
amdgpu_in_reset()function can only be called from inside the GPU reset itself!It is *NOT* allowed to skip any operation outside the reset depending on this.
How about moving the drm_mode_config_helper_suspend()/resume() calls for VKMS into the system suspend/resume path (amdgpu_device_suspend/resume())? VKMS has no hardware state a reset can lose, so recovery doesn't need them, and that can drop the
amdgpu_in_reset()check entirely.
I'm not an expert for the VKMS stuff but that sounds like it makes sense to me.
Regards,
Christian.
Quoted 40 lines
Regards,
PrikeQuoted 36 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c static int amdgpu_vkms_suspend(struct
Quoted 12 lines
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +0
-0@@ -491,6 +491,9 @@ static int amdgpu_vkms_suspend(struct
amdgpu_ip_block*ip_block)drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c static int amdgpu_vkms_resume(struct amdgpu_ip_block
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +3
-0struct amdgpu_device *adev = ip_block->adev;int r; +if (amdgpu_in_reset (adev)) +return 0 ; + r =drm_mode_config_helper_suspend (adev_to_drm (adev));if (r)return r;@@ -505,6 +508,9 @@ static int amdgpu_vkms_resume(struct amdgpu_ip_block
*ip_block)Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +3
-0r =amdgpu_vkms_hw_init (ip_block);if (r)return r; +if (amdgpu_in_reset (ip_block->adev)) +return 0 ; +return drm_mode_config_helper_resume (adev_to_drm (ip_block->adev)); }
PATCH 3/9 drm/amdgpu: skip VMHUB fault handling while the device is inaccessible
In reply to Prike LiangSkip GFX11 retry-fault processing and VMHUB status MMIO when reset is in progress or hardware access has been disabled. Retain a rate-limited diagnostic containing the fault address and client.
--- drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +7 -0
@@ -115,6 +115,13 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev, addr = (u64 )entry->src_data[0 ] <<12 ; addr |= ((u64 )entry->src_data[1 ] &0xf ) <<44 ; +if (amdgpu_in_reset (adev) || adev->no_hw_access) { +dev_err_ratelimited (adev->dev, +"[inaccessible device] page fault address 0x%016llx from client %d\n" , + addr, entry->client_id); +return 0 ; + } +if (retry_fault) { cam_index = entry->src_data[2 ] &0x3ff ;
Signature · 1 line
2.34.1
PATCH 4/9 drm/amdgpu/userq: complete hung queue fences after successful removal
In reply to Prike LiangOnly mark an additional MES queue as hung and complete its fences after both hardware reset and removal succeed. A failed operation leaves its dependencies pending for device recovery; it does not prove DMA stopped.
--- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +3 -2
@@ -282,7 +282,6 @@ int mes_userq_reset_queue(struct amdgpu_device *adev,if (uq == guilty_uq)continue ;if (uq->doorbell_index == db) { - uq->state =AMDGPU_USERQ_STATE_HUNG ;if (use_mmio) r =amdgpu_mes_reset_queue_mmio (adev, queue_type,0 ,1 , pipe, queue,0 );else
@@ -292,8 +291,10 @@ int mes_userq_reset_queue(struct amdgpu_device *adev, r =mes_userq_unmap (uq);if (r)return r; +trace_amdgpu_userq_state_changed (uq,AMDGPU_USERQ_STATE_HUNG ); + uq->state =AMDGPU_USERQ_STATE_HUNG ;amdgpu_userq_fence_driver_force_completion (uq); -break ; +return 0 ; } } }
Signature · 1 line
2.34.1
PATCH 5/9 drm/amdgpu: finish GPU recovery callbacks before restarting schedulers
In reply to Prike LiangRun GPU post-reset callbacks, including KFD and display-audio resume, before restarting DRM scheduler workqueues. IP hardware initialization already happens inside ASIC recovery; this change orders the remaining callbacks before new scheduler submissions. Preserve the emergency-stop and guity job completition path's callbacks without starting schedulers,
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7 -6
@@ -5783,8 +5783,10 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,amdgpu_device_halt_activities (adev, job, reset_context, &device_list, hive, need_emergency_restart); -if (need_emergency_restart) - goto skip_sched_resume; +if (need_emergency_restart) { +amdgpu_device_gpu_resume (adev, &device_list, need_emergency_restart); + goto reset_unlock; + }/* * Must check guilty signal here since after this point all old * HW fences are force signaled.
@@ -5794,18 +5796,17 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,if (job && (dma_fence_get_status (&job->hw_fence->base) >0 )) { job_signaled = true;dev_info (adev->dev,"Guilty job already signaled, skipping HW reset" ); - goto skip_hw_reset; + goto post_resume; } r =amdgpu_device_asic_reset (adev, &device_list, reset_context);if (r) goto reset_unlock; -skip_hw_reset: +post_resume: +amdgpu_device_gpu_resume (adev, &device_list, need_emergency_restart); r =amdgpu_device_sched_resume (&device_list, reset_context, job_signaled);if (r) goto reset_unlock; -skip_sched_resume: -amdgpu_device_gpu_resume (adev, &device_list, need_emergency_restart); reset_unlock:amdgpu_device_recovery_put_reset_lock (adev, &device_list);amdgpu_ras_post_reset (adev, &device_list);
Signature · 1 line
2.34.1
PATCH 6/9 drm/amdgpu: serialize JPEG and VCN idle work with GPU reset
In reply to Prike LiangTake the reset-domain read semaphore in the common JPEG and VCN idle workers so their hardware accesses wait for GPU recovery to finish. Keep end-use scheduling, including from recovery ring tests, so idle engines can power down even if no further jobs arrive.
Do not synchronously cancel these workers from recovery while holding the reset write semaphore. Use nonblocking cancellation in the common ring begin-use paths and during reset-time hardware finalization, while retaining synchronous draining for normal suspend and teardown.
Serialize the idle decision and VCN DPG pause updates with begin-use under the power-gating mutex. Check the submission count before reading fences, with acquire ordering against end-use, so a running worker cannot miss a submission that completes between the two checks.
VCN 1.0 and 2.5 override the common idle worker and retain their existing worker and cancellation behavior.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 28 +++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 32 ++++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 1 + drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c | 3 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c | 2 +- 21 files changed, 65 insertions(+), 33 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +21 -7
@@ -97,7 +97,11 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev)int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +/* The idle worker may be waiting for the reset writer to release sem. */ +if (amdgpu_in_reset (adev)) +cancel_delayed_work (&adev->jpeg.idle_work); +else +cancel_delayed_work_sync (&adev->jpeg.idle_work);return 0 ; }
@@ -114,6 +118,12 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)unsigned int fences =0 ;unsigned int i, j; +down_read (&adev->reset_domain->sem); +mutex_lock (&adev->jpeg.jpeg_pg_lock); +/* Check submissions before fences, while excluding a new begin_use. */ +if (atomic_read_acquire (&adev->jpeg.total_submission_cnt)) + goto reschedule; +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;
@@ -122,13 +132,17 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work) fences +=amdgpu_fence_count_emitted (&adev->jpeg.inst[i].ring_dec[j]); } -if (!fences && !atomic_read (&adev->jpeg.total_submission_cnt)) { -mutex_lock (&adev->jpeg.jpeg_pg_lock); +if (!fences) {amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_JPEG ,AMD_PG_STATE_GATE ); -mutex_unlock (&adev->jpeg.jpeg_pg_lock); - }else -schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); + goto unlock; + } + +reschedule: +schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); +unlock: +mutex_unlock (&adev->jpeg.jpeg_pg_lock); +up_read (&adev->reset_domain->sem); }void amdgpu_jpeg_ring_begin_use (struct amdgpu_ring *ring)
@@ -136,7 +150,7 @@ void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)struct amdgpu_device *adev = ring->adev;if (!atomic_fetch_inc (&adev->jpeg.total_submission_cnt)) -cancel_delayed_work_sync (&adev->jpeg.idle_work); +cancel_delayed_work (&adev->jpeg.idle_work);mutex_lock (&adev->jpeg.jpeg_pg_lock); amdgpu_device_ip_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_JPEG,
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +25 -7
@@ -459,6 +459,15 @@ void amdgpu_vcn_put_profile(struct amdgpu_device *adev)mutex_unlock (&adev->vcn.workload_profile_mutex); } +void amdgpu_vcn_cancel_idle_work (struct amdgpu_vcn_inst *vcn_inst) +{ +/* The idle worker may be waiting for the reset writer to release sem. */ +if (amdgpu_in_reset (vcn_inst->adev)) +cancel_delayed_work (&vcn_inst->idle_work); +else +cancel_delayed_work_sync (&vcn_inst->idle_work); +} +static void amdgpu_vcn_idle_work_handler (struct work_struct *work) { struct amdgpu_vcn_inst *vcn_inst =
@@ -466,10 +475,17 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work)struct amdgpu_device *adev = vcn_inst->adev;unsigned int fences =0 , fence[AMDGPU_MAX_VCN_INSTANCES ] = {0 };unsigned int i = vcn_inst->inst, j; +bool idle = false;if (adev->vcn.harvest_config & (1 << i))return ; +down_read (&adev->reset_domain->sem); +mutex_lock (&vcn_inst->vcn_pg_lock); +/* Check submissions before fences, while excluding a new begin_use. */ +if (atomic_read_acquire (&vcn_inst->total_submission_cnt)) + goto unlock; +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] +=amdgpu_fence_count_emitted (&vcn_inst->ring_enc[j]);
@@ -490,15 +506,17 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) fence[i] +=amdgpu_fence_count_emitted (&vcn_inst->ring_dec); fences += fence[i]; -if (!fences && !atomic_read (&vcn_inst->total_submission_cnt)) { -mutex_lock (&vcn_inst->vcn_pg_lock); + idle = !fences; +if (idle) vcn_inst->set_pg_state (vcn_inst,AMD_PG_STATE_GATE ); -mutex_unlock (&vcn_inst->vcn_pg_lock); -amdgpu_vcn_put_profile (adev); - }else { +unlock: +mutex_unlock (&vcn_inst->vcn_pg_lock); +if (idle) +amdgpu_vcn_put_profile (adev); +else schedule_delayed_work (&vcn_inst->idle_work,VCN_IDLE_TIMEOUT ); - } +up_read (&adev->reset_domain->sem); }void amdgpu_vcn_ring_begin_use (struct amdgpu_ring *ring)
@@ -507,7 +525,7 @@ void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)struct amdgpu_vcn_inst *vcn_inst = &adev->vcn.inst[ring->me];if (!atomic_fetch_inc (&vcn_inst->total_submission_cnt)) -cancel_delayed_work_sync (&vcn_inst->idle_work); +cancel_delayed_work (&vcn_inst->idle_work);mutex_lock (&vcn_inst->vcn_pg_lock); vcn_inst->set_pg_state (vcn_inst,AMD_PG_STATE_UNGATE );
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1 -0
@@ -526,6 +526,7 @@ int amdgpu_vcn_suspend(struct amdgpu_device *adev, int i);int amdgpu_vcn_resume (struct amdgpu_device *adev,int i);void amdgpu_vcn_ring_begin_use (struct amdgpu_ring *ring);void amdgpu_vcn_ring_end_use (struct amdgpu_ring *ring); +void amdgpu_vcn_cancel_idle_work (struct amdgpu_vcn_inst *vcn_inst);bool amdgpu_vcn_is_disabled_vcn (struct amdgpu_device *adev,enum vcn_ring_type type,uint32_t vcn_instance);
drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +1 -1
@@ -177,7 +177,7 @@ static int jpeg_v2_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE &&RREG32_SOC15 (JPEG ,0 , mmUVD_JRBC_STATUS))
drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +1 -1
@@ -239,7 +239,7 @@ static int jpeg_v2_5_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int i; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1 << i))
drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +1 -1
@@ -192,7 +192,7 @@ static int jpeg_v3_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE &&RREG32_SOC15 (JPEG ,0 , mmUVD_JRBC_STATUS))
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +1 -1
@@ -221,7 +221,7 @@ static int jpeg_v4_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (!amdgpu_sriov_vf (adev)) {if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE &&RREG32_SOC15 (JPEG ,0 , regUVD_JRBC_STATUS))
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +1 -1
@@ -455,7 +455,7 @@ static int jpeg_v4_0_3_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int ret =0 ; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (!amdgpu_sriov_vf (adev)) {if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE )
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +1 -2
@@ -250,7 +250,7 @@ static int jpeg_v4_0_5_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int i; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1 << i))
@@ -883,4 +883,3 @@ const struct amdgpu_ip_block_version jpeg_v4_0_5_ip_block = { .rev = 5, .funcs = &jpeg_v4_0_5_ip_funcs, }; -
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +1 -1
@@ -189,7 +189,7 @@ static int jpeg_v5_0_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE &&RREG32_SOC15 (JPEG ,0 , regUVD_JRBC_STATUS))
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1 -1
@@ -326,7 +326,7 @@ static int jpeg_v5_0_1_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int ret =0 ; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (!amdgpu_sriov_vf (adev)) {if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE )
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +1 -1
@@ -299,7 +299,7 @@ static int jpeg_v5_0_2_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int ret =0 ; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (!amdgpu_sriov_vf (adev)) {if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE )
drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +1 -1
@@ -172,7 +172,7 @@ static int jpeg_v5_3_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE &&RREG32_SOC15 (JPEG ,0 , regUVD_JRBC0_UVD_JRBC_STATUS))
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +1 -1
@@ -322,7 +322,7 @@ static int vcn_v2_0_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;struct amdgpu_vcn_inst *vinst = adev->vcn.inst; -cancel_delayed_work_sync (&vinst->idle_work); +amdgpu_vcn_cancel_idle_work (vinst); if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) || (vinst->cur_state != AMD_PG_STATE_GATE &&
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1 -1
@@ -449,7 +449,7 @@ static int vcn_v3_0_hw_fini(struct amdgpu_ip_block *ip_block)if (adev->vcn.harvest_config & (1 << i))continue ; -cancel_delayed_work_sync (&vinst->idle_work); +amdgpu_vcn_cancel_idle_work (vinst);if (!amdgpu_sriov_vf (adev)) { if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) ||
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1 -1
@@ -374,7 +374,7 @@ static int vcn_v4_0_hw_fini(struct amdgpu_ip_block *ip_block)if (adev->vcn.harvest_config & (1 << i))continue ; -cancel_delayed_work_sync (&vinst->idle_work); +amdgpu_vcn_cancel_idle_work (vinst);if (!amdgpu_sriov_vf (adev)) { if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) ||
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1 -1
@@ -417,7 +417,7 @@ static int vcn_v4_0_3_hw_fini(struct amdgpu_ip_block *ip_block)for (i =0 ; i < adev->vcn.num_vcn_inst; ++i) {struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[i]; -cancel_delayed_work_sync (&vinst->idle_work); +amdgpu_vcn_cancel_idle_work (vinst);if (vinst->cur_state !=AMD_PG_STATE_GATE ) vinst->set_pg_state (vinst,AMD_PG_STATE_GATE );
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1 -1
@@ -327,7 +327,7 @@ static int vcn_v4_0_5_hw_fini(struct amdgpu_ip_block *ip_block)if (adev->vcn.harvest_config & (1 << i))continue ; -cancel_delayed_work_sync (&vinst->idle_work); +amdgpu_vcn_cancel_idle_work (vinst);if (!amdgpu_sriov_vf (adev)) { if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) ||
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1 -1
@@ -291,7 +291,7 @@ static int vcn_v5_0_0_hw_fini(struct amdgpu_ip_block *ip_block)if (adev->vcn.harvest_config & (1 << i))continue ; -cancel_delayed_work_sync (&vinst->idle_work); +amdgpu_vcn_cancel_idle_work (vinst);if (!amdgpu_sriov_vf (adev)) { if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) ||
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +1 -1
@@ -364,7 +364,7 @@ static int vcn_v5_0_1_hw_fini(struct amdgpu_ip_block *ip_block)for (i =0 ; i < adev->vcn.num_vcn_inst; ++i) {struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[i]; -cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); +amdgpu_vcn_cancel_idle_work (&adev->vcn.inst[i]);if (vinst->cur_state !=AMD_PG_STATE_GATE ) vinst->set_pg_state (vinst,AMD_PG_STATE_GATE ); }
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c +1 -1
@@ -279,7 +279,7 @@ static int vcn_v5_0_2_hw_fini(struct amdgpu_ip_block *ip_block)for (i =0 ; i < adev->vcn.num_vcn_inst; ++i) {struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[i]; -cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); +amdgpu_vcn_cancel_idle_work (&adev->vcn.inst[i]);if (vinst->cur_state !=AMD_PG_STATE_GATE ) vinst->set_pg_state (vinst,AMD_PG_STATE_GATE ); }
Signature · 1 line
2.34.1
Christian König
maintainerRe: [PATCH 6/9] drm/amdgpu: serialize JPEG and VCN idle work with GPU reset
Quoted 48 lines · Prike Liang
Take the reset-domain read semaphore in the common JPEG and VCN idle workers so their hardware accesses wait for GPU recovery to finish. Keep end-use scheduling, including from recovery ring tests, so idle engines can power down even if no further jobs arrive.
Do not synchronously cancel these workers from recovery while holding the reset write semaphore. Use nonblocking cancellation in the common ring begin-use paths and during reset-time hardware finalization, while retaining synchronous draining for normal suspend and teardown.
Serialize the idle decision and VCN DPG pause updates with begin-use under the power-gating mutex. Check the submission count before reading fences, with acquire ordering against end-use, so a running worker cannot miss a submission that completes between the two checks.
VCN 1.0 and 2.5 override the common idle worker and retain their existing worker and cancellation behavior.
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 28 +++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 32 ++++++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 1 + drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c | 3 +-- drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c | 2 +- drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c | 2 +- 21 files changed, 65 insertions(+), 33 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev) · line 101
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-1@@ -97,7 +97,11 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev)int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +/* The idle worker may be waiting for the reset writer to release sem. */ +if (amdgpu_in_reset (adev))
Again, complete NAK to that!
Christian.
Quoted 373 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +19
-6+cancel_delayed_work (&adev->jpeg.idle_work); + else + cancel_delayed_work_sync(&adev->jpeg.idle_work);return 0 ; }@@ -114,6 +118,12 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)unsigned int fences =0 ;unsigned int i, j; +down_read (&adev->reset_domain->sem); +mutex_lock (&adev->jpeg.jpeg_pg_lock); +/* Check submissions before fences, while excluding a new begin_use. */ +if (atomic_read_acquire (&adev->jpeg.total_submission_cnt)) + goto reschedule; +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -122,13 +132,17 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work) fences +=amdgpu_fence_count_emitted (&adev->jpeg.inst[i].ring_dec[j]); } -if (!fences && !atomic_read (&adev->jpeg.total_submission_cnt)) { -mutex_lock (&adev->jpeg.jpeg_pg_lock); +if (!fences) {amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_JPEG ,AMD_PG_STATE_GATE ); -mutex_unlock (&adev->jpeg.jpeg_pg_lock); - }else -schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); + goto unlock; + } + +reschedule: +schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); +unlock: +mutex_unlock (&adev->jpeg.jpeg_pg_lock); +up_read (&adev->reset_domain->sem); }void amdgpu_jpeg_ring_begin_use (struct amdgpu_ring *ring)@@ -136,7 +150,7 @@ void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)struct amdgpu_device *adev = ring->adev;if (!atomic_fetch_inc (&adev->jpeg.total_submission_cnt)) -cancel_delayed_work_sync (&adev->jpeg.idle_work); +cancel_delayed_work (&adev->jpeg.idle_work);mutex_lock (&adev->jpeg.jpeg_pg_lock); amdgpu_device_ip_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_JPEG,drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +25
-7@@ -459,6 +459,15 @@ void amdgpu_vcn_put_profile(struct amdgpu_device *adev)mutex_unlock (&adev->vcn.workload_profile_mutex); } +void amdgpu_vcn_cancel_idle_work (struct amdgpu_vcn_inst *vcn_inst) +{ +/* The idle worker may be waiting for the reset writer to release sem. */ +if (amdgpu_in_reset (vcn_inst->adev)) +cancel_delayed_work (&vcn_inst->idle_work); +else +cancel_delayed_work_sync (&vcn_inst->idle_work); +} +static void amdgpu_vcn_idle_work_handler (struct work_struct *work) { struct amdgpu_vcn_inst *vcn_inst =@@ -466,10 +475,17 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work)struct amdgpu_device *adev = vcn_inst->adev;unsigned int fences =0 , fence[AMDGPU_MAX_VCN_INSTANCES ] = {0 };unsigned int i = vcn_inst->inst, j; +bool idle = false;if (adev->vcn.harvest_config & (1 << i))return ; +down_read (&adev->reset_domain->sem); +mutex_lock (&vcn_inst->vcn_pg_lock); +/* Check submissions before fences, while excluding a new begin_use. */ +if (atomic_read_acquire (&vcn_inst->total_submission_cnt)) + goto unlock; +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] +=amdgpu_fence_count_emitted (&vcn_inst->ring_enc[j]);@@ -490,15 +506,17 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) fence[i] +=amdgpu_fence_count_emitted (&vcn_inst->ring_dec); fences += fence[i]; -if (!fences && !atomic_read (&vcn_inst->total_submission_cnt)) { -mutex_lock (&vcn_inst->vcn_pg_lock); + idle = !fences; +if (idle) vcn_inst->set_pg_state (vcn_inst,AMD_PG_STATE_GATE ); -mutex_unlock (&vcn_inst->vcn_pg_lock); -amdgpu_vcn_put_profile (adev); - }else { +unlock: +mutex_unlock (&vcn_inst->vcn_pg_lock); +if (idle) +amdgpu_vcn_put_profile (adev); +else schedule_delayed_work (&vcn_inst->idle_work,VCN_IDLE_TIMEOUT ); - } +up_read (&adev->reset_domain->sem); }void amdgpu_vcn_ring_begin_use (struct amdgpu_ring *ring)@@ -507,7 +525,7 @@ void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)struct amdgpu_vcn_inst *vcn_inst = &adev->vcn.inst[ring->me];if (!atomic_fetch_inc (&vcn_inst->total_submission_cnt)) -cancel_delayed_work_sync (&vcn_inst->idle_work); +cancel_delayed_work (&vcn_inst->idle_work);mutex_lock (&vcn_inst->vcn_pg_lock); vcn_inst->set_pg_state (vcn_inst,AMD_PG_STATE_UNGATE );drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1
-0@@ -526,6 +526,7 @@ int amdgpu_vcn_suspend(struct amdgpu_device *adev, int i);int amdgpu_vcn_resume (struct amdgpu_device *adev,int i);void amdgpu_vcn_ring_begin_use (struct amdgpu_ring *ring);void amdgpu_vcn_ring_end_use (struct amdgpu_ring *ring); +void amdgpu_vcn_cancel_idle_work (struct amdgpu_vcn_inst *vcn_inst);bool amdgpu_vcn_is_disabled_vcn (struct amdgpu_device *adev,enum vcn_ring_type type,uint32_t vcn_instance);drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +1
-1@@ -177,7 +177,7 @@ static int jpeg_v2_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE &&RREG32_SOC15 (JPEG ,0 , mmUVD_JRBC_STATUS))drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +1
-1@@ -239,7 +239,7 @@ static int jpeg_v2_5_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int i; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1 << i))drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +1
-1@@ -192,7 +192,7 @@ static int jpeg_v3_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE &&RREG32_SOC15 (JPEG ,0 , mmUVD_JRBC_STATUS))drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +1
-1@@ -221,7 +221,7 @@ static int jpeg_v4_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (!amdgpu_sriov_vf (adev)) {if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE &&RREG32_SOC15 (JPEG ,0 , regUVD_JRBC_STATUS))drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +1
-1@@ -455,7 +455,7 @@ static int jpeg_v4_0_3_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int ret =0 ; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (!amdgpu_sriov_vf (adev)) {if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE )drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +1
-2@@ -250,7 +250,7 @@ static int jpeg_v4_0_5_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int i; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1 << i))@@ -883,4 +883,3 @@ const struct amdgpu_ip_block_version jpeg_v4_0_5_ip_block = { .rev = 5, .funcs = &jpeg_v4_0_5_ip_funcs, }; -drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +1
-1@@ -189,7 +189,7 @@ static int jpeg_v5_0_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE &&RREG32_SOC15 (JPEG ,0 , regUVD_JRBC_STATUS))drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1
-1@@ -326,7 +326,7 @@ static int jpeg_v5_0_1_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int ret =0 ; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (!amdgpu_sriov_vf (adev)) {if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE )drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +1
-1@@ -299,7 +299,7 @@ static int jpeg_v5_0_2_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int ret =0 ; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (!amdgpu_sriov_vf (adev)) {if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE )drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +1
-1@@ -172,7 +172,7 @@ static int jpeg_v5_3_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE &&RREG32_SOC15 (JPEG ,0 , regUVD_JRBC0_UVD_JRBC_STATUS))drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +1
-1@@ -322,7 +322,7 @@ static int vcn_v2_0_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;struct amdgpu_vcn_inst *vinst = adev->vcn.inst; -cancel_delayed_work_sync (&vinst->idle_work); +amdgpu_vcn_cancel_idle_work (vinst); if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) || (vinst->cur_state != AMD_PG_STATE_GATE &&drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1
-1@@ -449,7 +449,7 @@ static int vcn_v3_0_hw_fini(struct amdgpu_ip_block *ip_block)if (adev->vcn.harvest_config & (1 << i))continue ; -cancel_delayed_work_sync (&vinst->idle_work); +amdgpu_vcn_cancel_idle_work (vinst);if (!amdgpu_sriov_vf (adev)) { if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) ||drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1
-1@@ -374,7 +374,7 @@ static int vcn_v4_0_hw_fini(struct amdgpu_ip_block *ip_block)if (adev->vcn.harvest_config & (1 << i))continue ; -cancel_delayed_work_sync (&vinst->idle_work); +amdgpu_vcn_cancel_idle_work (vinst);if (!amdgpu_sriov_vf (adev)) { if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) ||drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1
-1@@ -417,7 +417,7 @@ static int vcn_v4_0_3_hw_fini(struct amdgpu_ip_block *ip_block)for (i =0 ; i < adev->vcn.num_vcn_inst; ++i) {struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[i]; -cancel_delayed_work_sync (&vinst->idle_work); +amdgpu_vcn_cancel_idle_work (vinst);if (vinst->cur_state !=AMD_PG_STATE_GATE ) vinst->set_pg_state (vinst,AMD_PG_STATE_GATE );drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1
-1@@ -327,7 +327,7 @@ static int vcn_v4_0_5_hw_fini(struct amdgpu_ip_block *ip_block)if (adev->vcn.harvest_config & (1 << i))continue ; -cancel_delayed_work_sync (&vinst->idle_work); +amdgpu_vcn_cancel_idle_work (vinst);if (!amdgpu_sriov_vf (adev)) { if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) ||drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1
-1@@ -291,7 +291,7 @@ static int vcn_v5_0_0_hw_fini(struct amdgpu_ip_block *ip_block)if (adev->vcn.harvest_config & (1 << i))continue ; -cancel_delayed_work_sync (&vinst->idle_work); +amdgpu_vcn_cancel_idle_work (vinst);if (!amdgpu_sriov_vf (adev)) { if ((adev->pg_flags & AMD_PG_SUPPORT_VCN_DPG) ||drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +1
-1@@ -364,7 +364,7 @@ static int vcn_v5_0_1_hw_fini(struct amdgpu_ip_block *ip_block)for (i =0 ; i < adev->vcn.num_vcn_inst; ++i) {struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[i]; -cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); +amdgpu_vcn_cancel_idle_work (&adev->vcn.inst[i]);if (vinst->cur_state !=AMD_PG_STATE_GATE ) vinst->set_pg_state (vinst,AMD_PG_STATE_GATE ); }drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c +1
-1@@ -279,7 +279,7 @@ static int vcn_v5_0_2_hw_fini(struct amdgpu_ip_block *ip_block)for (i =0 ; i < adev->vcn.num_vcn_inst; ++i) {struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[i]; -cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); +amdgpu_vcn_cancel_idle_work (&adev->vcn.inst[i]);if (vinst->cur_state !=AMD_PG_STATE_GATE ) vinst->set_pg_state (vinst,AMD_PG_STATE_GATE ); }
PATCH 7/9 drm/amdgpu/userq: take reset_domain->sem before userq_mutex in destroy
In reply to Prike Liangamdgpu_userq_destroy() takes reset_domain->sem for read in amdgpu_userq_detach_doorbell() while holding userq_mutex. GPU recovery holds reset_domain->sem for write and then takes clientlist_mutex in drm_client_dev_suspend(), which already depends on userq_mutex through the fbdev reservation and userq restore paths. Lockdep reports:
Chain exists of:
&dev->clientlist_mutex --> &userq_mgr->userq_mutex --> &reset_domain->semKeep waiting for the last fence under userq_mutex only, as the fence of a hung queue is only force-completed by the reset, then take reset_domain->sem before re-acquiring userq_mutex for the doorbell detach, unmap and fence driver teardown. This also keeps the MES unmap from racing with an in-progress GPU reset.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6 -10
@@ -415,15 +415,6 @@ static void amdgpu_userq_wait_for_last_fence(struct amdgpu_usermode_queue *queuedma_fence_wait (f, false); } -static void amdgpu_userq_detach_doorbell (struct amdgpu_usermode_queue *queue) -{ -struct amdgpu_device *adev = queue->userq_mgr->adev; - -down_read (&adev->reset_domain->sem); -xa_erase_irq (&adev->userq_doorbell_xa, queue->doorbell_index); -up_read (&adev->reset_domain->sem); -} -/** * amdgpu_userq_ensure_ev_fence - ensure a valid, unsignaled eviction fence exists * @uq_mgr: the usermode queue manager for this process
@@ -547,8 +538,12 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_quemutex_lock (&uq_mgr->userq_mutex);amdgpu_userq_wait_for_last_fence (queue); +mutex_unlock (&uq_mgr->userq_mutex); -amdgpu_userq_detach_doorbell (queue); +/* GPU recovery takes userq_mutex under reset_domain->sem, keep that order */ +down_read (&adev->reset_domain->sem); +mutex_lock (&uq_mgr->userq_mutex); +xa_erase_irq (&adev->userq_doorbell_xa, queue->doorbell_index);#if defined(CONFIG_DEBUG_FS )debugfs_remove_recursive (queue->debugfs_queue);
@@ -558,6 +553,7 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queamdgpu_userq_fence_driver_free (queue); queue->fence_drv =NULL ;mutex_unlock (&uq_mgr->userq_mutex); +up_read (&adev->reset_domain->sem);/* * A failed unmap means MES could not remove the hung queue and is now
Signature · 1 line
2.34.1
Christian König
maintainerRe: [PATCH 7/9] drm/amdgpu/userq: take reset_domain->sem before userq_mutex in destroy
Quoted 2 lines · Prike Liang
amdgpu_userq_destroy()takesreset_domain->semfor read inamdgpu_userq_detach_doorbell()while holdinguserq_mutex.
Yeah that is correct behavior.
Quoted 3 lines
GPU recovery
holdsreset_domain->semfor write and then takesclientlist_mutexindrm_client_dev_suspend(),
That is completely broken behavior and need to be fixed.
The GPU reset can *NEVER* call drm_client_dev_suspend(), who came up with that nonsense?
Regards,
Christian.
Quoted 60 lines
which already depends on
userq_mutexthrough
the fbdev reservation and userq restore paths. Lockdep reports:Chain exists of: &dev->clientlist_mutex --> &userq_mgr->userq_mutex --> &reset_domain->semKeep waiting for the last fence under
userq_mutexonly, as the fence of a hung queue is only force-completed by the reset, then takereset_domain->sembefore re-acquiringuserq_mutexfor the doorbell detach, unmap and fence driver teardown. This also keeps the MES unmap from racing with an in-progress GPU reset.Fixes f18719ef4bb7 ("drm/amdgpu: Convert amdgpu userqueue management from IDR to XArray")Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +6
-10@@ -415,15 +415,6 @@ static void amdgpu_userq_wait_for_last_fence(struct amdgpu_usermode_queue *queuedma_fence_wait (f, false); } -static void amdgpu_userq_detach_doorbell (struct amdgpu_usermode_queue *queue) -{ -struct amdgpu_device *adev = queue->userq_mgr->adev; - -down_read (&adev->reset_domain->sem); -xa_erase_irq (&adev->userq_doorbell_xa, queue->doorbell_index); -up_read (&adev->reset_domain->sem); -} -/** * amdgpu_userq_ensure_ev_fence - ensure a valid, unsignaled eviction fence exists * @uq_mgr: the usermode queue manager for this process @@ -547,8 +538,12 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_quemutex_lock (&uq_mgr->userq_mutex);amdgpu_userq_wait_for_last_fence (queue); +mutex_unlock (&uq_mgr->userq_mutex); -amdgpu_userq_detach_doorbell (queue); +/* GPU recovery takes userq_mutex under reset_domain->sem, keep that order */ +down_read (&adev->reset_domain->sem); +mutex_lock (&uq_mgr->userq_mutex); +xa_erase_irq (&adev->userq_doorbell_xa, queue->doorbell_index);#if defined(CONFIG_DEBUG_FS )debugfs_remove_recursive (queue->debugfs_queue);@@ -558,6 +553,7 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queamdgpu_userq_fence_driver_free (queue); queue->fence_drv =NULL ;mutex_unlock (&uq_mgr->userq_mutex); +up_read (&adev->reset_domain->sem);/* * A failed unmap means MES could not remove the hung queue and is now
RE: [PATCH 7/9] drm/amdgpu/userq: take reset_domain->sem before userq_mutex in destroy
AMD General
Regards,
Prike
Quoted 15 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, October 13, 2026 5:31 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH 7/9] drm/amdgpu/userq: takereset_domain->sembeforeuserq_mutexin destroyQuoted 2 lines · Prike Liang
amdgpu_userq_destroy()takesreset_domain->semfor read inamdgpu_userq_detach_doorbell()while holdinguserq_mutex.Yeah that is correct behavior.
Quoted 8 lines
Quoted 3 lines
GPU recovery
holdsreset_domain->semfor write and then takesclientlist_mutexindrm_client_dev_suspend(),That is completely broken behavior and need to be fixed.
The GPU reset can *NEVER* call
drm_client_dev_suspend(), who came up with that nonsense?
The call to drm_client_dev_suspend() have been in the GPU recovery path for some time, possibly leveraged incorrectly from the system suspend path. I’ll clean it up in the GPU recovery path.
Regards,
Prike
Quoted 72 lines
Regards,
Christian.drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static void amdgpu_userq_wait_for_last_fence(struct
Quoted 26 lines
which already depends on
userq_mutexthrough the fbdev reservation and userq restore paths. Lockdep reports:Chain exists of: &dev->clientlist_mutex --> &userq_mgr->userq_mutex -->
&reset_domain->semKeep waiting for the last fence under
userq_mutexonly, as the fence of a hung queue is only force-completed by the reset, then takereset_domain->sembefore re-acquiringuserq_mutexfor the doorbell detach, unmap and fence driver teardown. This also keeps the MES unmap from racing with an in-progress GPU reset.Fixes f18719ef4bb7 ("drm/amdgpu: Convert amdgpu userqueue managementfrom IDR to XArray")
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0@@ -415,15 +415,6 @@ static void amdgpu_userq_wait_for_last_fence(struct
amdgpu_usermode_queue*queueQuoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-1dma_fence_wait (f, false); } -static void amdgpu_userq_detach_doorbell(struct amdgpu_usermode_queuedrivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static void amdgpu_userq_wait_for_last_fence(struct amdgpu_usermode_queue *queue
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-7*queue) -{ -struct amdgpu_device *adev = queue->userq_mgr->adev; - -down_read (&adev->reset_domain->sem); -xa_erase_irq (&adev->userq_doorbell_xa, queue->doorbell_index); -up_read (&adev->reset_domain->sem); -} -/** * amdgpu_userq_ensure_ev_fence - ensure a valid, unsignaled eviction fence exists
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que
Quoted 10 lines
* @uq_mgr: the usermode queue manager for this process @@ -547,8
+538,12 @@ amdgpu_userq_destroy(structamdgpu_userq_mgr*uq_mgr, structamdgpu_usermode_quemutex_lock(&uq_mgr->userq_mutex); amdgpu_userq_wait_for_last_fence(queue);drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-1+mutex_unlock (&uq_mgr->userq_mutex); -amdgpu_userq_detach_doorbell (queue); +/* GPU recovery takes userq_mutex under reset_domain->sem, keep that order */
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_destroy(struct amdgpu_userq_mgr
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3
-0+down_read (&adev->reset_domain->sem); +mutex_lock (&uq_mgr->userq_mutex); +xa_erase_irq (&adev->userq_doorbell_xa, queue->doorbell_index);#if defined(CONFIG_DEBUG_FS )debugfs_remove_recursive (queue->debugfs_queue);@@ -558,6 +553,7 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr
*uq_mgr, structamdgpu_usermode_queQuoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-0amdgpu_userq_fence_driver_free (queue); queue->fence_drv =NULL ;mutex_unlock (&uq_mgr->userq_mutex); +up_read (&adev->reset_domain->sem);/* * A failed unmap means MES could not remove the hung queue and is now
PATCH 8/9 drm/amdgpu/userq: take reset_domain->sem before userq_mutex in create
In reply to Prike Liangamdgpu_userq_create() maps the queue under reset_domain->sem, but amdgpu_userq_ensure_ev_fence() returns with userq_mutex held, so the semaphore nests inside userq_mutex. That is the inverse of the order used by GPU recovery and lockdep reports a circular dependency:
Chain exists of:
&dev->clientlist_mutex --> &userq_mgr->userq_mutex --> &reset_domain->semuserq_mutex has to stay held from amdgpu_userq_ensure_ev_fence() until the queue is mapped to keep the eviction fence valid, so only trylock reset_domain->sem under it. If a reset is in progress, drop userq_mutex, wait for the reset to finish and retry. Hold the semaphore until the queue is mapped or its doorbell is erased again on failure.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +11 -6
@@ -748,18 +748,21 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)if (r) goto clean_mqd; -amdgpu_userq_ensure_ev_fence (&fpriv->userq_mgr, &fpriv->evf_mgr); +for (;;) { +amdgpu_userq_ensure_ev_fence (&fpriv->userq_mgr, &fpriv->evf_mgr); +/* reset_domain->sem nests outside userq_mutex, so only trylock here */ +if (down_read_trylock (&adev->reset_domain->sem)) +break ; +mutex_unlock (&uq_mgr->userq_mutex); +down_read (&adev->reset_domain->sem); +up_read (&adev->reset_domain->sem); + }/* don't map the queue if scheduling is halted */ if (!adev->userq_halt_for_enforce_isolation || ((queue->queue_type !=AMDGPU_HW_IP_GFX ) && (queue->queue_type !=AMDGPU_HW_IP_COMPUTE ))) { -/* Serialize the map against an in-progress GPU reset (MES is -* unresponsive during recovery), matching amdgpu_userq_detach_doorbell(). -*/ -down_read (&adev->reset_domain->sem); r =amdgpu_userq_map_helper (queue); -up_read (&adev->reset_domain->sem);if (r) {drm_file_err (uq_mgr->file,"Failed to map Queue\n" );trace_amdgpu_userq_create_end (queue, r);
@@ -770,6 +773,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)atomic_inc (&uq_mgr->userq_count[queue->queue_type]);mutex_unlock (&uq_mgr->userq_mutex); +up_read (&adev->reset_domain->sem); r = xa_alloc(&uq_mgr->userq_xa, &qid, queue, XA_LIMIT(1, AMDGPU_MAX_USERQ_COUNT),
@@ -791,6 +795,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) erase_doorbell:xa_erase_irq (&adev->userq_doorbell_xa, index); +up_read (&adev->reset_domain->sem); clean_mqd: uq_funcs->mqd_destroy (queue); clean_doorbell_bo:
Signature · 1 line
2.34.1
PATCH 9/9 drm/amdgpu/mes: skip unmap queue notification during GPU reset
In reply to Prike Liangamdgpu_mes_userq_notify_unmap_work_handler() submits a MES misc op without holding reset_domain->sem, so it can ring the MES doorbell while the GPU is being reset:
WARNING: amdgpu_device.c:928 at amdgpu_device_skip_hw_access+0x73/0x90 [amdgpu] Workqueue: events amdgpu_mes_userq_notify_unmap_work_handler [amdgpu] Call Trace: amdgpu_mm_wdoorbell64+0x20/0x70 [amdgpu] mes_v11_0_ring_set_wptr+0x71/0x80 [amdgpu] amdgpu_ring_commit+0x5b/0xa0 [amdgpu] mes_v11_0_submit_pkt_and_poll_completion.constprop.0+0x207/0x520 [amdgpu] mes_v11_0_misc_op+0x8b/0x240 [amdgpu] amdgpu_mes_notify_unmap_queue+0xa3/0x110 [amdgpu] amdgpu_mes_userq_notify_unmap_work_handler+0x24/0x70 [amdgpu]
Only send the notification when reset_domain->sem can be trylocked. The work re-arms itself while the HW queues are oversubscribed, so the notification is retried once the reset has finished.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +5 -1
@@ -1192,7 +1192,11 @@ static void amdgpu_mes_userq_notify_unmap_work_handler(struct work_struct *work) userq_notify_unmap_work.work);struct amdgpu_device *adev = mes->adev; -amdgpu_mes_notify_unmap_queue (adev); +/* MES is unusable during GPU recovery; the re-arm below retries later */ +if (down_read_trylock (&adev->reset_domain->sem)) { +amdgpu_mes_notify_unmap_queue (adev); +up_read (&adev->reset_domain->sem); + }/* Re-arm if still oversubscribed */ if (atomic_read(&mes->userq_hw_queue_count) >
Signature · 1 line
2.34.1
Christian König
maintainerQuoted 4 lines · Prike Liang
On userq eviction failure, the suspend worker waits for
reset_workwhile holdinguserq_mutexand inside a DMA-fence signaling section. This makes eviction-fence completion depend on GPU recovery finishing, although recovery can itself require memory allocation and eviction.
Absolutely clear NAK to that!
GPU recovery is to unlock memory allocation and eviction, so it can *NEVER* allocate memory nor depend on eviction to complete.
This patch here is just utterly nonsense. What we need to avoid is to touch the userq mutex and/or any eviction fence from the GPU recovery.
Regards,
Christian.
Quoted 96 lines
Fixes c8ed2de0f2ee ("drm/amdgpu: rework userq reset work handling")Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 12 +++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 10 +++------- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +9
-3@@ -65,6 +65,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work)struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;struct dma_fence *ev_fence;bool cookie; +int r;mutex_lock (&uq_mgr->userq_mutex);@@ -79,21 +80,26 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct *work) cookie =dma_fence_begin_signalling (); ev_fence =amdgpu_evf_mgr_get_fence (evf_mgr); -amdgpu_userq_evict (uq_mgr); + r =amdgpu_userq_evict (uq_mgr);/* * Signaling the eviction fence must be done while holding the * userq_mutex. Otherwise we won't resume the queues before issuing the * next fence. */ -dma_fence_signal (ev_fence); +if (!r) +dma_fence_signal (ev_fence);dma_fence_end_signalling (cookie);dma_fence_put (ev_fence); -if (!evf_mgr->shutdown) +if (!r && !evf_mgr->shutdown)schedule_delayed_work (&uq_mgr->resume_work,0 );mutex_unlock (&uq_mgr->userq_mutex); + +if (r) +amdgpu_reset_domain_schedule (uq_mgr->adev->reset_domain, + &uq_mgr->reset_work); } int amdgpu_evf_mgr_attach_fence(struct amdgpu_eviction_fence_mgr *evf_mgr,drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +3
-7@@ -1308,13 +1308,9 @@ amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr) ret = r; } -if (ret) { +if (ret)drm_file_err (uq_mgr->file,"Couldn't unmap all the queues, eviction failed ret=%d\n" , ret); -amdgpu_reset_domain_schedule (uq_mgr->adev->reset_domain, - &uq_mgr->reset_work); -flush_work (&uq_mgr->reset_work); - }return ret; }@@ -1334,10 +1330,10 @@ amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr) } } -void +int amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr) { -amdgpu_userq_evict_all (uq_mgr); +return amdgpu_userq_evict_all (uq_mgr); } int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv,drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1
-1@@ -163,7 +163,7 @@ void amdgpu_userq_mgr_cancel_resume(struct amdgpu_userq_mgr *userq_mgr);void amdgpu_userq_mgr_fini (struct amdgpu_userq_mgr *userq_mgr);void amdgpu_userq_wait_for_signal (struct amdgpu_userq_mgr *uq_mgr); -void amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr); +int amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr);void amdgpu_userq_ensure_ev_fence (struct amdgpu_userq_mgr *userq_mgr,struct amdgpu_eviction_fence_mgr *evf_mgr);
AMD General
Regards,
Prike
Quoted 15 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, October 13, 2026 5:26 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH 1/9] drm/amdgpu: defer GPU recovery after userq eviction failureQuoted 4 lines · Prike Liang
On userq eviction failure, the suspend worker waits for
reset_workwhile holdinguserq_mutexand inside a DMA-fence signaling section. This makes eviction-fence completion depend on GPU recovery finishing, although recovery can itself require memory allocation and eviction.
Quoted 7 lines
Absolutely clear NAK to that!
GPU recovery is to unlock memory allocation and eviction, so it can *NEVER* allocate memory nor depend on eviction to complete.
This patch here is just utterly nonsense. What we need to avoid is to touch the userq mutex and/or any eviction fence from the GPU recovery.
You're right, the current lock ordering userq mutex-> reset semaphore in the userq eviction signaling path does not need to change, as it matches the order declared in amdgpu_lockdep_init(). On further check, the VCN/UVD IB test may perform a memory allocation with GFP_KERNEL that triggers reclaim during GPU recovery. We may need a follow-up patch to address the resulting potential deadlock.
Regards,
Prike
Regards,
Quoted 107 lines
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c amdgpu_eviction_fence_suspend_worker(struct work_struct
Quoted 15 lines
Fixes c8ed2de0f2ee ("drm/amdgpu: rework userq reset work handling")Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 12 +++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 10 +++------- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +0
-0@@ -65,6 +65,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct*work)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c amdgpu_eviction_fence_suspend_worker(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +1
-0struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;struct dma_fence *ev_fence;bool cookie; +int r;mutex_lock (&uq_mgr->userq_mutex);@@ -79,21 +80,26 @@ amdgpu_eviction_fence_suspend_worker(struct
work_struct*work)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_evict_all(struct amdgpu_userq_mgr
Quoted 35 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +8
-3cookie =dma_fence_begin_signalling (); ev_fence =amdgpu_evf_mgr_get_fence (evf_mgr); -amdgpu_userq_evict (uq_mgr); + r =amdgpu_userq_evict (uq_mgr);/* * Signaling the eviction fence must be done while holding the * userq_mutex. Otherwise we won't resume the queues before issuing the * next fence. */ -dma_fence_signal (ev_fence); +if (!r) +dma_fence_signal (ev_fence);dma_fence_end_signalling (cookie);dma_fence_put (ev_fence); -if (!evf_mgr->shutdown) +if (!r && !evf_mgr->shutdown)schedule_delayed_work (&uq_mgr->resume_work,0 );mutex_unlock (&uq_mgr->userq_mutex); + +if (r) +amdgpu_reset_domain_schedule (uq_mgr->adev->reset_domain, + &uq_mgr->reset_work); } int amdgpu_evf_mgr_attach_fence(struct amdgpu_eviction_fence_mgr
*evf_mgr, diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index3fe91fdafe55..5fef0cc7703c100644drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0@@ -1308,13 +1308,9 @@ amdgpu_userq_evict_all(struct amdgpu_userq_mgr
*uq_mgr)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr)
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-1ret = r; } -if (ret) { +if (ret) drm_file_err(uq_mgr->file, "Couldn't unmap all the queues, eviction failed ret=%d\n",ret);
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_wait_for_signal(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-4-amdgpu_reset_domain_schedule (uq_mgr->adev->reset_domain, - &uq_mgr->reset_work); -flush_work (&uq_mgr->reset_work); - }return ret; }@@ -1334,10 +1330,10 @@ amdgpu_userq_wait_for_signal(struct
amdgpu_userq_mgr*uq_mgr)Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-2} } -void +int amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr) { -amdgpu_userq_evict_all (uq_mgr); +return amdgpu_userq_evict_all (uq_mgr); } int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct
drm_file*file_priv, diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.hb/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
index488dc21d7c81..4dcf6151de6a100644drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +0
-0@@ -163,7 +163,7 @@ void amdgpu_userq_mgr_cancel_resume(struct
amdgpu_userq_mgr*userq_mgr); voidamdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr);void
amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr);drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1
-1-void amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr); +int amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr);void amdgpu_userq_ensure_ev_fence (struct amdgpu_userq_mgr *userq_mgr,struct amdgpu_eviction_fence_mgr *evf_mgr);
Christian König
maintainerQuoted 25 lines · Prike
AMD General
Regards,
PrikeQuoted 20 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Tuesday, October 13, 2026 5:26 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH 1/9] drm/amdgpu: defer GPU recovery after userq eviction failureQuoted 4 lines · Prike Liang
On userq eviction failure, the suspend worker waits for
reset_workwhile holdinguserq_mutexand inside a DMA-fence signaling section. This makes eviction-fence completion depend on GPU recovery finishing, although recovery can itself require memory allocation and eviction.Absolutely clear NAK to that!
GPU recovery is to unlock memory allocation and eviction, so it can *NEVER* allocate memory nor depend on eviction to complete.
Quoted 6 lines
Quoted 2 lines
This patch here is just utterly nonsense. What we need to avoid is to touch the userq mutex and/or any eviction fence from the GPU recovery.
You're right, the current lock ordering userq mutex-> reset semaphore in the userq eviction signaling path does not need to change, as it matches the order declared in
amdgpu_lockdep_init(). On further check, the VCN/UVD IB test may perform a memory allocation withGFP_KERNELthat triggers reclaim during GPU recovery. We may need a follow-up patch to address the resulting potential deadlock.
Yeah that is a really good catch. That needs to use GFP_ATOMIC so that we can use the emergency reserves.
That should probably be ok since the memory is immediately freed up again.
Regards,
Christian.
Quoted 113 lines
Regards,
PrikeRegards,
Quoted 107 lines
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c amdgpu_eviction_fence_suspend_worker(struct work_struct
Quoted 15 lines
Fixes c8ed2de0f2ee ("drm/amdgpu: rework userq reset work handling")Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c | 12 +++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 10 +++------- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +0
-0@@ -65,6 +65,7 @@ amdgpu_eviction_fence_suspend_worker(struct work_struct*work)
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c amdgpu_eviction_fence_suspend_worker(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +1
-0struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;struct dma_fence *ev_fence;bool cookie; +int r;mutex_lock (&uq_mgr->userq_mutex);@@ -79,21 +80,26 @@ amdgpu_eviction_fence_suspend_worker(struct
work_struct*work)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_evict_all(struct amdgpu_userq_mgr
Quoted 35 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c +8
-3cookie =dma_fence_begin_signalling (); ev_fence =amdgpu_evf_mgr_get_fence (evf_mgr); -amdgpu_userq_evict (uq_mgr); + r =amdgpu_userq_evict (uq_mgr);/* * Signaling the eviction fence must be done while holding the * userq_mutex. Otherwise we won't resume the queues before issuing the * next fence. */ -dma_fence_signal (ev_fence); +if (!r) +dma_fence_signal (ev_fence);dma_fence_end_signalling (cookie);dma_fence_put (ev_fence); -if (!evf_mgr->shutdown) +if (!r && !evf_mgr->shutdown)schedule_delayed_work (&uq_mgr->resume_work,0 );mutex_unlock (&uq_mgr->userq_mutex); + +if (r) +amdgpu_reset_domain_schedule (uq_mgr->adev->reset_domain, + &uq_mgr->reset_work); } int amdgpu_evf_mgr_attach_fence(struct amdgpu_eviction_fence_mgr
*evf_mgr, diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index3fe91fdafe55..5fef0cc7703c100644drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-0@@ -1308,13 +1308,9 @@ amdgpu_userq_evict_all(struct amdgpu_userq_mgr
*uq_mgr)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr)
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-1ret = r; } -if (ret) { +if (ret) drm_file_err(uq_mgr->file, "Couldn't unmap all the queues, eviction failed ret=%d\n",ret);
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c amdgpu_userq_wait_for_signal(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-4-amdgpu_reset_domain_schedule (uq_mgr->adev->reset_domain, - &uq_mgr->reset_work); -flush_work (&uq_mgr->reset_work); - }return ret; }@@ -1334,10 +1330,10 @@ amdgpu_userq_wait_for_signal(struct
amdgpu_userq_mgr*uq_mgr)Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-2} } -void +int amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr) { -amdgpu_userq_evict_all (uq_mgr); +return amdgpu_userq_evict_all (uq_mgr); } int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct
drm_file*file_priv, diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.hb/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
index488dc21d7c81..4dcf6151de6a100644drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +0
-0@@ -163,7 +163,7 @@ void amdgpu_userq_mgr_cancel_resume(struct
amdgpu_userq_mgr*userq_mgr); voidamdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr);void
amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr);drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1
-1-void amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr); +int amdgpu_userq_evict (struct amdgpu_userq_mgr *uq_mgr);void amdgpu_userq_ensure_ev_fence (struct amdgpu_userq_mgr *userq_mgr,struct amdgpu_eviction_fence_mgr *evf_mgr);