drm/amdgpu: save VKMS modeset state from the system PM path only
Subsystems (2)
PATCH 1/8 drm/amdgpu: save VKMS modeset state from the system PM path only
amdgpu_vkms_suspend()/resume() are IP block callbacks shared by system suspend/resume and GPU recovery. Calling drm_mode_config_helper_suspend() and drm_mode_config_helper_resume() from them makes GPU recovery take clientlist_mutex and the modeset locks and duplicate the atomic state while holding reset_domain->sem. Lockdep reports:
Chain exists of:
&dev->clientlist_mutex --> &userq_mgr->userq_mutex --> &reset_domain->semVKMS has no hardware state that a reset can lose, so the reset path never needs these helpers. Call them from amdgpu_device_suspend()/resume() instead and leave the IP callbacks with only the hardware init.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 14 +------------- 2 files changed, 19 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +18 -1
@@ -4568,9 +4568,16 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)amdgpu_ras_suspend (adev); +/* VKMS modeset state is saved here, never from the reset path */ +if (adev->enable_virtual_display) { + r =drm_mode_config_helper_suspend (dev); +if (r) + goto unwind_smartshift; + } + r =amdgpu_device_ip_suspend_phase1 (adev);if (r) - goto unwind_smartshift; + goto unwind_vkms;amdgpu_amdkfd_suspend (adev, !amdgpu_sriov_vf (adev) && !adev->in_runpm); r =amdgpu_userq_suspend (adev);
@@ -4618,6 +4625,10 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)return r; } +unwind_vkms: +if (adev->enable_virtual_display) +drm_mode_config_helper_resume (dev); + unwind_smartshift: rec =amdgpu_acpi_smart_shift_update (adev,AMDGPU_SS_DEV_D0 );if (rec) {
@@ -4717,6 +4728,12 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients) goto exit; } +if (adev->enable_virtual_display) { + r =drm_mode_config_helper_resume (dev); +if (r) + goto exit; + } + r =amdgpu_amdkfd_resume (adev, !amdgpu_sriov_vf (adev) && !adev->in_runpm);if (r) goto exit;
drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +1 -13
@@ -488,24 +488,12 @@ static int amdgpu_vkms_hw_fini(struct amdgpu_ip_block *ip_block)static int amdgpu_vkms_suspend (struct amdgpu_ip_block *ip_block) { -struct amdgpu_device *adev = ip_block->adev; -int r; - - r =drm_mode_config_helper_suspend (adev_to_drm (adev)); -if (r) -return r; -return 0 ; }static int amdgpu_vkms_resume (struct amdgpu_ip_block *ip_block) { -int r; - - r =amdgpu_vkms_hw_init (ip_block); -if (r) -return r; -return drm_mode_config_helper_resume (adev_to_drm (ip_block->adev)); +return amdgpu_vkms_hw_init (ip_block); } static int amdgpu_vkms_set_clockgating_state(struct amdgpu_ip_block *ip_block,
Signature · 1 line
2.34.1
PATCH 2/8 drm/amdgpu: finish GPU recovery callbacks before restarting schedulers
Run 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
@@ -5816,8 +5816,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.
@@ -5827,18 +5829,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
Re: [PATCH 2/8] drm/amdgpu: finish GPU recovery callbacks before restarting schedulers
Quoted 16 lines · Prike Liang
Run 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,
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 5822
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-2@@ -5816,8 +5816,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; + }
Does this reordering indirectly affect any ttm memory management funcs (sdma) that may be required during KFD resume sequence?
Thanks,
Lijo
Quoted 25 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +3
-4/* * Must check guilty signal here since after this point all old * HW fences are force signaled. @@ -5827,18 +5829,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);
RE: [PATCH 2/8] drm/amdgpu: finish GPU recovery callbacks before restarting schedulers
AMD General
Regards,
Prike
Quoted 39 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 23, 2026 5:14 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH 2/8] drm/amdgpu: finish GPU recovery callbacks before restarting schedulersQuoted 18 lines · Prike Liang
Run 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,
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct · line 5821
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-2@@ -5816,8 +5816,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);
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 5822
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0+ goto reset_unlock; + }Does this reordering indirectly affect any ttm memory management funcs (sdma) that may be required during KFD resume sequence?
amdgpu_device_gpu_resume() doesn't submit or wait for any TTM or other DRM scheduler job. This change keeps the DRM schedulers stopped until all the hardware has fully resumed, since jobs running earlier could access hardware blocks that aren't ready yet and fault.
Thanks,
Prike
Quoted 32 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0/* * Must check guilty signal here since after this point all old * HW fences are force signaled.
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -5827,18 +5829,17 @@ int amdgpu_device_gpu_recover(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0if (job && (dma_fence_get_status (&job->hw_fence->base) >0 )) { job_signaled = true; dev_info(adev->dev, "Guilty job already signaled, skipping HWreset");
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-2- 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);Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-2if (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);
Lazar, Lijo
Acked-byRe: [PATCH 2/8] drm/amdgpu: finish GPU recovery callbacks before restarting schedulers
Quoted 50 lines · Prike
AMD General
Regards,
PrikeQuoted 39 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 23, 2026 5:14 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH 2/8] drm/amdgpu: finish GPU recovery callbacks before restarting schedulersQuoted 18 lines · Prike Liang
Run 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,
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct · line 5821
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-2@@ -5816,8 +5816,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);Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 5822
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2
-0+ goto reset_unlock; + }Does this reordering indirectly affect any ttm memory management funcs (sdma) that may be required during KFD resume sequence?
Quoted 8 lines
amdgpu_device_gpu_resume()doesn't submit or wait for any TTM or other DRM scheduler job. This change keeps the DRM schedulers stopped until all the hardware has fully resumed, since jobs running earlier could access hardware blocks that aren't ready yet and fault.Thanks,
Prike
Thanks Prike. As ttm mman jobs could get canceled for vram lost reset cases, it looks fine.
Thanks,
Lijo
Quoted 33 lines
Quoted 32 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0/* * Must check guilty signal here since after this point all old * HW fences are force signaled.
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -5827,18 +5829,17 @@ int amdgpu_device_gpu_recover(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0if (job && (dma_fence_get_status (&job->hw_fence->base) >0 )) { job_signaled = true; dev_info(adev->dev, "Guilty job already signaled, skipping HWreset");
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-2- 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);Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-2if (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);
PATCH 3/8 drm/amdgpu/uvd: don't allocate or lock BOs in the direct IB test
In reply to Prike LiangThe IB tests run inside GPU recovery, which must not allocate memory with reclaim, take BO reservation locks or depend on eviction. The direct IB pool and the job allocation use GFP_ATOMIC for this reason.
amdgpu_uvd_send_msg() still passes the UVD scheduler entity for direct submissions, so drm_sched_job_init() allocates a scheduler fence with GFP_KERNEL that the direct submission never uses. It also reserves the message BO and adds the fence to it, which takes the reservation lock, can allocate a fence slot with GFP_KERNEL and falls back to a blocking dma_fence_wait().
Only pass the entity for scheduled submissions. The direct message BO is only used by the IB test, which waits for each fence itself, so only fence the BO for scheduled submissions.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +6 -5
@@ -1114,7 +1114,8 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,uint64_t addr;int i, r; - r = amdgpu_job_alloc_with_ib(ring->adev, &adev->uvd.entity, + r = amdgpu_job_alloc_with_ib(ring->adev, + direct ? NULL : &adev->uvd.entity, AMDGPU_FENCE_OWNER_UNDEFINED, 64, direct ? AMDGPU_IB_POOL_DIRECT : AMDGPU_IB_POOL_DELAYED,
@@ -1159,11 +1160,11 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo, goto err_free; f =amdgpu_job_submit (job); - } -amdgpu_bo_reserve (bo, true); -amdgpu_bo_fence (bo, f, false); -amdgpu_bo_unreserve (bo); +amdgpu_bo_reserve (bo, true); +amdgpu_bo_fence (bo, f, false); +amdgpu_bo_unreserve (bo); + }if (fence) *fence =dma_fence_get (f);
Signature · 1 line
2.34.1
Re: [PATCH 3/8] drm/amdgpu/uvd: don't allocate or lock BOs in the direct IB test
Quoted 11 lines · Prike Liang
The IB tests run inside GPU recovery, which must not allocate memory with reclaim, take BO reservation locks or depend on eviction. The direct IB pool and the job allocation use
GFP_ATOMICfor this reason.
amdgpu_uvd_send_msg()still passes the UVD scheduler entity for direct submissions, sodrm_sched_job_init()allocates a scheduler fence withGFP_KERNELthat the direct submission never uses. It also reserves the message BO and adds the fence to it, which takes the reservation lock, can allocate a fence slot withGFP_KERNELand falls back to a blockingdma_fence_wait().
Quoted 5 lines
Only pass the entity for scheduled submissions. The direct message BO is only used by the IB test, which waits for each fence itself, so only fence the BO for scheduled submissions.
Signed-off-by Prike Liang <[email protected]>
Quoted 34 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +6
-5@@ -1114,7 +1114,8 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,uint64_t addr;int i, r; - r = amdgpu_job_alloc_with_ib(ring->adev, &adev->uvd.entity, + r = amdgpu_job_alloc_with_ib(ring->adev, + direct ? NULL : &adev->uvd.entity, AMDGPU_FENCE_OWNER_UNDEFINED, 64, direct ? AMDGPU_IB_POOL_DIRECT : AMDGPU_IB_POOL_DELAYED,@@ -1159,11 +1160,11 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo, goto err_free; f =amdgpu_job_submit (job); - } -amdgpu_bo_reserve (bo, true); -amdgpu_bo_fence (bo, f, false); -amdgpu_bo_unreserve (bo); +amdgpu_bo_reserve (bo, true); +amdgpu_bo_fence (bo, f, false); +amdgpu_bo_unreserve (bo); + }if (fence) *fence =dma_fence_get (f);
PATCH 4/8 drm/amdgpu/vce: don't allocate a scheduler fence in the direct IB test
In reply to Prike LiangThe IB tests run inside GPU recovery, which must not allocate memory with reclaim. The direct IB pool and the job allocation use GFP_ATOMIC for this reason.
amdgpu_vce_get_create_msg() and amdgpu_vce_get_destroy_msg() still pass the VCE scheduler entity for direct submissions, so drm_sched_job_init() allocates a scheduler fence with GFP_KERNEL that the direct submission never uses.
The create message is always submitted directly, so don't pass the entity there. The destroy message also goes through the scheduler when the handles of a closed file are freed, so only pass the entity for those scheduled submissions.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +3 -2
@@ -470,7 +470,7 @@ static int amdgpu_vce_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,uint64_t addr;int i, r; - r = amdgpu_job_alloc_with_ib(ring->adev, &ring->adev->vce.entity, + r = amdgpu_job_alloc_with_ib(ring->adev, NULL, AMDGPU_FENCE_OWNER_UNDEFINED, ib_size_dw * 4, AMDGPU_IB_POOL_DIRECT, AMDGPU_KERNEL_JOB_ID_VCN_RING_TEST,
@@ -561,7 +561,8 @@ static int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,struct dma_fence *f =NULL ;int i, r; - r = amdgpu_job_alloc_with_ib(ring->adev, &ring->adev->vce.entity, + r = amdgpu_job_alloc_with_ib(ring->adev, + direct ? NULL : &ring->adev->vce.entity, AMDGPU_FENCE_OWNER_UNDEFINED, ib_size_dw * 4, direct ? AMDGPU_IB_POOL_DIRECT :
Signature · 1 line
2.34.1
PATCH 5/8 drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
In reply to Prike LiangThe common JPEG and VCN idle workers program power gating and DPG pause, so they must not run while a GPU reset is in progress. Recovery must not wait for them either, since everything the workers depend on then becomes a dependency of GPU recovery.
Make the workers take reset_domain->sem for read, so they wait for a running reset instead of touching the hardware. hw_fini/suspend and begin_use, the latter for the IB tests, run from GPU recovery as well, so only skip waiting for the idle work when the reset itself calls them. The reset holds the semaphore for write and would otherwise deadlock on a worker blocked on it. Outside a reset the cancel stays synchronous as before. sw_fini always cancels synchronously, it never runs with the reset semaphore held.
Update versions: https://lore.kernel.org/amd-gfx/PH7PR12MB6000698A62D208E47BB358D7FB662@
PH7PR12MB6000.namprd12.prod.outlook.com/
--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 20 ++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 18 +++++++++++++++++- 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 | 2 +- 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_v1_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 4 ++-- 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 +- 23 files changed, 58 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +18 -2
@@ -74,6 +74,8 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev) {int i, j; +cancel_delayed_work_sync (&adev->jpeg.idle_work); +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;
@@ -95,9 +97,18 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev)return 0 ; } +static void amdgpu_jpeg_cancel_idle_work (struct amdgpu_device *adev) +{ +/* The reset mustn't wait for the idle work, which waits for the reset */ +if (amdgpu_in_reset (adev)) +cancel_delayed_work (&adev->jpeg.idle_work); +else +cancel_delayed_work_sync (&adev->jpeg.idle_work); +} +int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);return 0 ; }
@@ -114,6 +125,9 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)unsigned int fences =0 ;unsigned int i, j; +/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;
@@ -129,6 +143,8 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)mutex_unlock (&adev->jpeg.jpeg_pg_lock); }else schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); + +up_read (&adev->reset_domain->sem); }void amdgpu_jpeg_ring_begin_use (struct amdgpu_ring *ring)
@@ -136,7 +152,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); +amdgpu_jpeg_cancel_idle_work (adev);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 +17 -1
@@ -269,6 +269,8 @@ void amdgpu_vcn_sw_fini(struct amdgpu_device *adev, int i)if (adev->vcn.harvest_config & (1 << i))return ; +cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); + amdgpu_bo_free_kernel( &adev->vcn.inst[i].dpg_sram_bo, &adev->vcn.inst[i].dpg_sram_gpu_addr,
@@ -459,6 +461,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 reset mustn't wait for the idle work, which waits for the reset */ +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 =
@@ -470,6 +481,9 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work)if (adev->vcn.harvest_config & (1 << i))return ; +/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] +=amdgpu_fence_count_emitted (&vcn_inst->ring_enc[j]);
@@ -499,6 +513,8 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) }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 +523,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); +amdgpu_vcn_cancel_idle_work (vcn_inst);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 -1
@@ -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))
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_v1_0.c +2 -2
@@ -150,8 +150,8 @@ static int vcn_v1_0_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r; -/* Override the work func */ - adev->vcn.inst[0 ].idle_work.work.func = vcn_v1_0_idle_work_handler; +/* Own lockdep class, this work is still cancelled synchronously */ +INIT_DELAYED_WORK (&adev->vcn.inst[0 ].idle_work, vcn_v1_0_idle_work_handler);amdgpu_vcn_setup_ucode (adev,0 );
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_v2_5.c +2 -2
@@ -304,8 +304,8 @@ static int vcn_v2_5_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r; -/* Override the work func */ - adev->vcn.inst[j].idle_work.work.func = vcn_v2_5_idle_work_handler; +/* Own lockdep class, this work is still cancelled synchronously */ +INIT_DELAYED_WORK (&adev->vcn.inst[j].idle_work, vcn_v2_5_idle_work_handler);amdgpu_vcn_setup_ucode (adev, j);
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
Re: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
Quoted 14 lines · Prike Liang
The common JPEG and VCN idle workers program power gating and DPG pause, so they must not run while a GPU reset is in progress. Recovery must not wait for them either, since everything the workers depend on then becomes a dependency of GPU recovery.
Make the workers take
reset_domain->semfor read, so they wait for a running reset instead of touching the hardware. hw_fini/suspend andbegin_use, the latter for the IB tests, run from GPU recovery as well, so only skip waiting for the idle work when the reset itself calls them. The reset holds the semaphore for write and would otherwise deadlock on a worker blocked on it. Outside a reset the cancel stays synchronous as before.sw_finialways cancels synchronously, it never runs with the reset semaphore held.
Quoted 4 lines
Update versions: https://lore.kernel.org/amd-gfx/PH7PR12MB6000698A62D208E47BB358D7FB662@
PH7PR12MB6000.namprd12.prod.outlook.com/Signed-off-by Prike Liang <[email protected]>
Thanks,
Lijo
Quoted 420 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 20 ++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 18 +++++++++++++++++- 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 | 2 +- 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_v1_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 4 ++-- 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 +- 23 files changed, 58 insertions(+), 25 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +18
-2@@ -74,6 +74,8 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev) {int i, j; +cancel_delayed_work_sync (&adev->jpeg.idle_work); +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -95,9 +97,18 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev)return 0 ; } +static void amdgpu_jpeg_cancel_idle_work (struct amdgpu_device *adev) +{ +/* The reset mustn't wait for the idle work, which waits for the reset */ +if (amdgpu_in_reset (adev)) +cancel_delayed_work (&adev->jpeg.idle_work); +else +cancel_delayed_work_sync (&adev->jpeg.idle_work); +} +int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);return 0 ; }@@ -114,6 +125,9 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)unsigned int fences =0 ;unsigned int i, j; +/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -129,6 +143,8 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)mutex_unlock (&adev->jpeg.jpeg_pg_lock); }else schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); + +up_read (&adev->reset_domain->sem); }void amdgpu_jpeg_ring_begin_use (struct amdgpu_ring *ring)@@ -136,7 +152,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); +amdgpu_jpeg_cancel_idle_work (adev);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 +17
-1@@ -269,6 +269,8 @@ void amdgpu_vcn_sw_fini(struct amdgpu_device *adev, int i)if (adev->vcn.harvest_config & (1 << i))return ; +cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); + amdgpu_bo_free_kernel( &adev->vcn.inst[i].dpg_sram_bo, &adev->vcn.inst[i].dpg_sram_gpu_addr,@@ -459,6 +461,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 reset mustn't wait for the idle work, which waits for the reset */ +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 =@@ -470,6 +481,9 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work)if (adev->vcn.harvest_config & (1 << i))return ; +/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] +=amdgpu_fence_count_emitted (&vcn_inst->ring_enc[j]);@@ -499,6 +513,8 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) }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 +523,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); +amdgpu_vcn_cancel_idle_work (vcn_inst);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
-1@@ -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))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_v1_0.c +2
-2@@ -150,8 +150,8 @@ static int vcn_v1_0_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r; -/* Override the work func */ - adev->vcn.inst[0 ].idle_work.work.func = vcn_v1_0_idle_work_handler; +/* Own lockdep class, this work is still cancelled synchronously */ +INIT_DELAYED_WORK (&adev->vcn.inst[0 ].idle_work, vcn_v1_0_idle_work_handler);amdgpu_vcn_setup_ucode (adev,0 );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_v2_5.c +2
-2@@ -304,8 +304,8 @@ static int vcn_v2_5_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r; -/* Override the work func */ - adev->vcn.inst[j].idle_work.work.func = vcn_v2_5_idle_work_handler; +/* Own lockdep class, this work is still cancelled synchronously */ +INIT_DELAYED_WORK (&adev->vcn.inst[j].idle_work, vcn_v2_5_idle_work_handler);amdgpu_vcn_setup_ucode (adev, j);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 ); }
RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
In reply to Prike LiangAMD General
Quoted 62 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Prike Liang
Sent: Friday, October 23, 2026 4:34 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workThe common JPEG and VCN idle workers program power gating and DPG pause, so they must not run while a GPU reset is in progress. Recovery must not wait for them either, since everything the workers depend on then becomes a dependency of GPU recovery.
Make the workers take
reset_domain->semfor read, so they wait for a running reset instead of touching the hardware. hw_fini/suspend andbegin_use, the latter for the IB tests, run from GPU recovery as well, so only skip waiting for the idle work when the reset itself calls them. The reset holds the semaphore for write and would otherwise deadlock on a worker blocked on it. Outside a reset the cancel stays synchronous as before.sw_finialways cancels synchronously, it never runs with the reset semaphore held.Update versions: https://lore.kernel.org/amd-
gfx/PH7PR12MB6000698A62D208E47BB358D7FB662@
PH7PR12MB6000.namprd12.prod.outlook.com/Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 20 ++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 18 +++++++++++++++++- 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 | 2 +- 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_v1_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 4 ++-- 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 +- 23 files changed, 58 insertions(+), 25 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 78
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0@@ -74,6 +74,8 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev) {int i, j; +cancel_delayed_work_sync (&adev->jpeg.idle_work); +
I think this is redundant when hw_fini() ran normally, they are only needed when hw_fini() was skipped - i.e. when hw_init() failed and status.hw was never set. Also, UVD and VCE should be covered as well.
Thanks,
Leo
Quoted 446 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +13
-1for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -95,9 +97,18 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev)return 0 ; } +static void amdgpu_jpeg_cancel_idle_work (struct amdgpu_device *adev) +{ +/* The reset mustn't wait for the idle work, which waits for the reset */ +if (amdgpu_in_reset (adev)) +cancel_delayed_work (&adev->jpeg.idle_work); +else +cancel_delayed_work_sync (&adev->jpeg.idle_work); +} +int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);return 0 ; }@@ -114,6 +125,9 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)unsigned int fences =0 ;unsigned int i, j; +/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue;drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0@@ -129,6 +143,8 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work) mutex_unlock(&adev->jpeg.jpeg_pg_lock); }else schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); + +up_read (&adev->reset_domain->sem); }void
amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1
-1@@ -136,7 +152,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); +amdgpu_jpeg_cancel_idle_work (adev);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 +2
-0@@ -269,6 +269,8 @@ void amdgpu_vcn_sw_fini(struct amdgpu_device *adev, int i)if (adev->vcn.harvest_config & (1 << i))return ; +cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); + amdgpu_bo_free_kernel( &adev->vcn.inst[i].dpg_sram_bo,&adev->vcn.inst[i].dpg_sram_gpu_addr,drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +9
-0@@ -459,6 +461,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 reset mustn't wait for the idle work, which waits for the reset */ +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=drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-0@@ -470,6 +481,9 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work)if (adev->vcn.harvest_config & (1 << i))return ; +/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] += amdgpu_fence_count_emitted(&vcn_inst-Quoted 1 line
ring_enc[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +2
-0@@ -499,6 +513,8 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) }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)drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +1
-1@@ -507,7 +523,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); +amdgpu_vcn_cancel_idle_work (vcn_inst);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_typetype,uint32_tvcn_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
-1@@ -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))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_v1_0.c +2
-2@@ -150,8 +150,8 @@ static int vcn_v1_0_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r; -/* Override the work func */ - adev->vcn.inst[0 ].idle_work.work.func = vcn_v1_0_idle_work_handler; +/* Own lockdep class, this work is still cancelled synchronously */ +INIT_DELAYED_WORK (&adev->vcn.inst[0 ].idle_work, vcn_v1_0_idle_work_handler);amdgpu_vcn_setup_ucode(adev, 0);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_v2_5.c +2
-2@@ -304,8 +304,8 @@ static int vcn_v2_5_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r; -/* Override the work func */ - adev->vcn.inst[j].idle_work.work.func = vcn_v2_5_idle_work_handler; +/* Own lockdep class, this work is still cancelled synchronously */ + INIT_DELAYED_WORK(&adev->vcn.inst[j].idle_work,
vcn_v2_5_idle_work_handler);amdgpu_vcn_setup_ucode(adev, j);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 );}--
2.34.1
RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
AMD General
Regards,
Prike
Quoted 77 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Saturday, October 24, 2026 6:47 AM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Quoted 65 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Prike Liang
Sent: Friday, October 23, 2026 4:34 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workThe common JPEG and VCN idle workers program power gating and DPG pause, so they must not run while a GPU reset is in progress. Recovery must not wait for them either, since everything the workers depend on then becomes a dependency of GPU recovery.
Make the workers take
reset_domain->semfor read, so they wait for a running reset instead of touching the hardware. hw_fini/suspend andbegin_use, the latter for the IB tests, run from GPU recovery as well, so only skip waiting for the idle work when the reset itself calls them. The reset holds the semaphore for write and would otherwise deadlock on a worker blocked on it. Outside a reset the cancel stays synchronous as before.sw_finialways cancels synchronously, it never runs with the reset semaphore held.Update versions: https://lore.kernel.org/amd-
gfx/PH7PR12MB6000698A62D208E47BB358D7FB662@
PH7PR12MB6000.namprd12.prod.outlook.com/Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 20 ++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 18 +++++++++++++++++- 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 | 2 +- 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_v1_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 4 ++-- 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 +- 23 files changed, 58 insertions(+), 25 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0@@ -74,6 +74,8 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev) {int i, j;
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev) · line 78
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0+cancel_delayed_work_sync (&adev->jpeg.idle_work); +I think this is redundant when
hw_fini()ran normally, they are only needed whenhw_fini()was skipped - i.e. whenhw_init()failed and status.hw was never set. Also, UVD and VCE should be covered as well.
Yeah, this change is aimed at the cases where the idle work isn't cancelled synchronously before sw_fini(): hw_fini() was skipped (e.g. hw_init() failed), or the suspend/hw_fini path only did the non-waiting cancel because it ran during a reset. If the idle work was already cancelled synchronously before sw_fini(), the extra cancel_delayed_work_sync() is harmless and just returns.
If there are no other objections, I'll submit this fix upstream later.
Meanwhile, could someone help review patches 3 and 4? They remove the VCN/JPEG memory allocations, which can trigger reclaim, from the GPU recovery path.
Thanks,
Prike
Quoted 449 lines
Thanks,
LeoQuoted 445 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +13
-1for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -95,9 +97,18 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev)return 0 ; } +static void amdgpu_jpeg_cancel_idle_work (struct amdgpu_device *adev) +{ +/* The reset mustn't wait for the idle work, which waits for the reset */ +if (amdgpu_in_reset (adev)) +cancel_delayed_work (&adev->jpeg.idle_work); +else +cancel_delayed_work_sync (&adev->jpeg.idle_work); +} +int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);return 0 ; }@@ -114,6 +125,9 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)unsigned int fences =0 ;unsigned int i, j; +/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue;drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0@@ -129,6 +143,8 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work) mutex_unlock(&adev->jpeg.jpeg_pg_lock); }else schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); + +up_read (&adev->reset_domain->sem); }void
amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1
-1@@ -136,7 +152,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); +amdgpu_jpeg_cancel_idle_work (adev);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 +2
-0@@ -269,6 +269,8 @@ void amdgpu_vcn_sw_fini(struct amdgpu_device *adev, int i)if (adev->vcn.harvest_config & (1 << i))return ; +cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); + amdgpu_bo_free_kernel( &adev->vcn.inst[i].dpg_sram_bo,&adev->vcn.inst[i].dpg_sram_gpu_addr,drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +9
-0@@ -459,6 +461,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 reset mustn't wait for the idle work, which waits for the reset */ +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=drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-0@@ -470,6 +481,9 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work)if (adev->vcn.harvest_config & (1 << i))return ; +/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] += amdgpu_fence_count_emitted(&vcn_inst-Quoted 1 line
ring_enc[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +2
-0@@ -499,6 +513,8 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) }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)drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +1
-1@@ -507,7 +523,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); +amdgpu_vcn_cancel_idle_work (vcn_inst);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_typetype,uint32_tvcn_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
-1@@ -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))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_v1_0.c +2
-2@@ -150,8 +150,8 @@ static int vcn_v1_0_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r; -/* Override the work func */ - adev->vcn.inst[0 ].idle_work.work.func = vcn_v1_0_idle_work_handler; +/* Own lockdep class, this work is still cancelled synchronously */ +INIT_DELAYED_WORK (&adev->vcn.inst[0 ].idle_work, vcn_v1_0_idle_work_handler);amdgpu_vcn_setup_ucode(adev, 0);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_v2_5.c +2
-2@@ -304,8 +304,8 @@ static int vcn_v2_5_sw_init(struct amdgpu_ip_block *ip_block)if (r)return r; -/* Override the work func */ - adev->vcn.inst[j].idle_work.work.func = vcn_v2_5_idle_work_handler; +/* Own lockdep class, this work is still cancelled synchronously */ + INIT_DELAYED_WORK(&adev->vcn.inst[j].idle_work,
vcn_v2_5_idle_work_handler);amdgpu_vcn_setup_ucode(adev, j);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 );}--
2.34.1
RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
AMD General
Quoted 101 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Monday, October 26, 2026 5:04 AM
To: Liu, Leo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Regards,
PrikeQuoted 78 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Saturday, October 24, 2026 6:47 AM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Quoted 66 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Prike Liang
Sent: Friday, October 23, 2026 4:34 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workThe common JPEG and VCN idle workers program power gating and DPG pause, so they must not run while a GPU reset is in progress. Recovery must not wait for them either, since everything the workers depend on then becomes a dependency of GPU recovery.
Make the workers take
reset_domain->semfor read, so they wait for a running reset instead of touching the hardware. hw_fini/suspend andbegin_use, the latter for the IB tests, run from GPU recovery as well, so only skip waiting for the idle work when the reset itself calls them. The reset holds the semaphore for write and would otherwise deadlock on a worker blocked on it. Outside a reset the cancel stays synchronous as before.sw_finialways cancels synchronously, it never runs with the reset semaphore held.Update versions: https://lore.kernel.org/amd-
gfx/PH7PR12MB6000698A62D208E47BB358D7FB662@
PH7PR12MB6000.namprd12.prod.outlook.com/Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 20 ++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 18 +++++++++++++++++- 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 | 2 +- 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_v1_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 4 ++-- 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 +- 23 files changed, 58 insertions(+), 25 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0@@ -74,6 +74,8 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev) {int i, j;Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c int amdgpu_jpeg_sw_fini(struct amdgpu_device · line 78
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0+cancel_delayed_work_sync (&adev->jpeg.idle_work); +I think this is redundant when
hw_fini()ran normally, they are only needed whenhw_fini()was skipped - i.e. whenhw_init()failed and status.hw was never set. Also, UVD and VCE should be covered as well.
Quoted 6 lines
Yeah, this change is aimed at the cases where the idle work isn't cancelled synchronously before
sw_fini():hw_fini()was skipped (e.g.hw_init()failed), or the suspend/hw_fini path only did the non-waiting cancel because it ran during a reset. If the idle work was already cancelled synchronously beforesw_fini(), the extracancel_delayed_work_sync()is harmless and just returns.
The problem is that calling cancel worker in sw_fini arrives too late, the idle work is scheduled ~1 second into the future. The fini_early/fini teardown sequence runs in that same window, tearing down other IP blocks that VCN depends on
(MMHUB, SMU). The right place to cancel is in hw_init()'s error path, immediately before returning the error, while other IPs is still alive, and close time window which could lead to problems.
Thanks,
Leo
Quoted 480 lines
If there are no other objections, I'll submit this fix upstream later.
Meanwhile, could someone help review patches 3 and 4? They remove the VCN/JPEG memory allocations, which can trigger reclaim, from the GPU recovery path.
Thanks,
PrikeQuoted 7 lines
Thanks,
Leodrivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c int amdgpu_jpeg_sw_fini(struct amdgpu_device
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -95,9 +97,18 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device*adev)
Quoted 462 lines
Quoted 461 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +13
-1return 0 ; } +static void amdgpu_jpeg_cancel_idle_work (struct amdgpu_device +*adev) { +/* The reset mustn't wait for the idle work, which waits for the reset */ +if (amdgpu_in_reset (adev)) +cancel_delayed_work (&adev->jpeg.idle_work); +else +cancel_delayed_work_sync (&adev->jpeg.idle_work); +} +int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);return 0 ; }@@ -114,6 +125,9 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)unsigned int fences =0 ;unsigned int i, j; +/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue;drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0@@ -129,6 +143,8 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work) mutex_unlock(&adev->jpeg.jpeg_pg_lock); }else schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); + +up_read (&adev->reset_domain->sem); }void
amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)@@ -136,7
+152,7 @@ voidamdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)struct amdgpu_device *adev = ring->adev; if (!atomic_fetch_inc(&adev->jpeg.total_submission_cnt))drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1
-1-cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);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 +2
-0@@ -269,6 +269,8 @@ void amdgpu_vcn_sw_fini(struct amdgpu_device *adev, int i)if (adev->vcn.harvest_config & (1 << i))return ; +cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); + amdgpu_bo_free_kernel( &adev->vcn.inst[i].dpg_sram_bo,&adev->vcn.inst[i].dpg_sram_gpu_addr,drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0@@ -459,6 +461,15 @@ void amdgpu_vcn_put_profile(struct
amdgpu_device
*adev)mutex_unlock(&adev->vcn.workload_profile_mutex);}
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +9
-0+void amdgpu_vcn_cancel_idle_work (struct amdgpu_vcn_inst *vcn_inst) +{ +/* The reset mustn't wait for the idle work, which waits for the reset */ +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 = @@ -470,6 +481,9 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) if (adev->vcn.harvest_config & (1 << i)) return;drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-0+/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] += amdgpu_fence_count_emitted(&vcn_inst-Quoted 1 line
ring_enc[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +2
-0@@ -499,6 +513,8 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) }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
+523,7 @@ voidamdgpu_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))drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +1
-2-cancel_delayed_work_sync (&vcn_inst->idle_work); +amdgpu_vcn_cancel_idle_work (vcn_inst);mutex_lock (&vcn_inst->vcn_pg_lock); vcn_inst->set_pg_state (vcn_inst,AMD_PG_STATE_UNGATE ); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
indexbea95307fd42..a6438950854e100644drivers/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); diff --gita/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c
index72069b77f6f1..b048fd4b8b59100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +0
-0@@ -177,7 +177,7 @@ static int jpeg_v2_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
index2968256d4cd7..f6a9258ae3ca100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c
index564e40899df2..922711aa06a3100644drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +0
-0@@ -192,7 +192,7 @@ static int jpeg_v3_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c
indexb29ca3a49939..fe7ab9cb35bb100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +0
-0@@ -221,7 +221,7 @@ static int jpeg_v4_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +1
-2-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 ) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c
index4da3f9c995c1..87efc3c2b9e0100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c
indexdcdb089b4308..91968ad26f17100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c
indexf2debf6b6bd0..27116d1e9e64100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1
-2-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 ) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c
indexdd0abce73687..7e068c2d4d6d100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +1
-2-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 ) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c
index8ddd12740a04..16daeb61114c100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +1
-1-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_v1_0.c +0
-0@@ -150,8 +150,8 @@ static int vcn_v1_0_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +2
-2-/* Override the work func */ - adev->vcn.inst[0 ].idle_work.work.func = vcn_v1_0_idle_work_handler; +/* Own lockdep class, this work is still cancelled synchronously */ + INIT_DELAYED_WORK(&adev->vcn.inst[0].idle_work,
vcn_v1_0_idle_work_handler);amdgpu_vcn_setup_ucode(adev, 0);drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +1
-1-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 && diff --git
a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.cb/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
index10ef5616b2f5..9dd4c313cbe7100644drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-0@@ -304,8 +304,8 @@ static int vcn_v2_5_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-2-/* Override the work func */ - adev->vcn.inst[j].idle_work.work.func =
vcn_v2_5_idle_work_handler;
+ /* Own lockdep class, this work is still cancelled
+ synchronously
*/
+ INIT_DELAYED_WORK(&adev->vcn.inst[j].idle_work,vcn_v2_5_idle_work_handler);amdgpu_vcn_setup_ucode(adev, j);drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1
-1-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)|| diff --git
a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c
index4b7f7bbe18da..5b47a643d725100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1
-1-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)|| diff --git
a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cindex3f39aa83c319..5aa09c3bd79b100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +0
-0@@ -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];drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1
-1-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)|| diff --git
a/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cindex7b7c3bc9f046..0c189063a6ab100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1
-1-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)|| diff --git
a/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cindexc9e990ab297d..3fa553fb41d3100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +0
-0@@ -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];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +1
-1-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 +0
-0@@ -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];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c +1
-2-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 ); } --2.34.1
RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
AMD General
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Liu, Leo
Sent: Monday, October 26, 2026 9:32 AM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
AMD General
Quoted 103 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Monday, October 26, 2026 5:04 AM
To: Liu, Leo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Regards,
PrikeQuoted 80 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Saturday, October 24, 2026 6:47 AM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Quoted 66 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Prike Liang
Sent: Friday, October 23, 2026 4:34 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workThe common JPEG and VCN idle workers program power gating and DPG pause, so they must not run while a GPU reset is in progress. Recovery must not wait for them either, since everything the workers depend on then becomes a dependency of GPU recovery.
Make the workers take
reset_domain->semfor read, so they wait for
a running reset instead of touching the hardware. hw_fini/suspend andbegin_use, the latter for the IB tests, run from GPU recovery
as well, so only skip waiting for the idle work when the reset itself calls them. The reset holds the semaphore for write and would otherwise
deadlock on a worker blocked on it. Outside a reset the cancel
stays synchronous as before.sw_finialways cancels synchronously, it never runs with the reset semaphore held.Update versions: https://lore.kernel.org/amd-
gfx/PH7PR12MB6000698A62D208E47BB358D7FB662@
PH7PR12MB6000.namprd12.prod.outlook.com/Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 20 ++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 18 +++++++++++++++++- 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 | 2 +- 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_v1_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 4 ++-- 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 +- 23 files changed, 58 insertions(+), 25 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0@@ -74,6 +74,8 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev) {int i, j;Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c int amdgpu_jpeg_sw_fini(struct amdgpu_device · line 78
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0+cancel_delayed_work_sync (&adev->jpeg.idle_work); +I think this is redundant when
hw_fini()ran normally, they are only needed whenhw_fini()was skipped - i.e. whenhw_init()failed and status.hw was never set. Also, UVD and VCE should be covered as well.
Quoted 6 lines
Yeah, this change is aimed at the cases where the idle work isn't
cancelled synchronously beforesw_fini():hw_fini()was skipped (e.g.hw_init()failed), or the suspend/hw_fini path only did the
non-waiting cancel because it ran during a reset. If the idle work was
already cancelled synchronously beforesw_fini(), the extracancel_delayed_work_sync()is harmless and just returns.
The problem is that calling cancel worker in sw_fini arrives too late, the idle work is scheduled ~1 second into the future.
The fini_early/fini teardown sequence runs in that same window, tearing down other IP blocks that VCN depends on (MMHUB, SMU). The right place to cancel is in hw_init()'s error path, immediately before returning the error, while other IPs is still alive, and close time window which could lead to problems.
Thanks,
Leo
Quoted 492 lines
If there are no other objections, I'll submit this fix upstream later.
Meanwhile, could someone help review patches 3 and 4? They remove the VCN/JPEG memory allocations, which can trigger reclaim, from the GPU recovery path.
Thanks,
PrikeQuoted 7 lines
Thanks,
Leodrivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c int amdgpu_jpeg_sw_fini(struct amdgpu_device
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -95,9 +97,18 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device*adev)
Quoted 474 lines
Quoted 473 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +10
-1return 0 ; } +static void amdgpu_jpeg_cancel_idle_work (struct amdgpu_device +*adev) { +/* The reset mustn't wait for the idle work, which waits for the reset */ +if (amdgpu_in_reset (adev)) +cancel_delayed_work (&adev->jpeg.idle_work); +else +cancel_delayed_work_sync (&adev->jpeg.idle_work); +} +int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);return 0 ; }@@ -114,6 +125,9 @@ static voidamdgpu_jpeg_idle_work_handler(struct
work_struct*work)unsigned int fences = 0; unsigned int i, j;drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3
-0+/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -129,6 +143,8 @@ static voidamdgpu_jpeg_idle_work_handler(struct
work_struct*work)mutex_unlock(&adev->jpeg.jpeg_pg_lock); } else schedule_delayed_work(&adev->jpeg.idle_work,
JPEG_IDLE_TIMEOUT);drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3
-1+ +up_read (&adev->reset_domain->sem); } void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring) @@ -136 ,7 +152,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))drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1
-1-cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);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 +2
-0@@ -269,6 +269,8 @@ void amdgpu_vcn_sw_fini(struct amdgpu_device *adev, int i)if (adev->vcn.harvest_config & (1 << i))return ; +cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); + amdgpu_bo_free_kernel( &adev->vcn.inst[i].dpg_sram_bo,&adev->vcn.inst[i].dpg_sram_gpu_addr,drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0@@ -459,6 +461,15 @@ void amdgpu_vcn_put_profile(struct
amdgpu_device
*adev)mutex_unlock(&adev->vcn.workload_profile_mutex);}
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +9
-0+void amdgpu_vcn_cancel_idle_work (struct amdgpu_vcn_inst +*vcn_inst) { +/* The reset mustn't wait for the idle work, which waits for the reset */ +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 = @@ -470,6 +481,9 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) if (adev->vcn.harvest_config & (1 << i)) return;drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-0+/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] += amdgpu_fence_count_emitted(&vcn_inst-Quoted 1 line
ring_enc[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0@@ -499,6 +513,8 @@ static voidamdgpu_vcn_idle_work_handler(struct
work_struct*work)} else { schedule_delayed_work(&vcn_inst->idle_work, VCN_IDLE_TIMEOUT); }drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-1+ +up_read (&adev->reset_domain->sem); } void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring) @@ -507 ,7 +523,7 @@ void amdgpu_vcn_ring_begin_use(struct amdgpu_ring*ring)
structamdgpu_vcn_inst*vcn_inst=
&adev->vcn.inst[ring->me];if (!atomic_fetch_inc(&vcn_inst->total_submission_cnt))drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +1
-2-cancel_delayed_work_sync (&vcn_inst->idle_work); +amdgpu_vcn_cancel_idle_work (vcn_inst);mutex_lock (&vcn_inst->vcn_pg_lock); vcn_inst->set_pg_state (vcn_inst,AMD_PG_STATE_UNGATE ); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
indexbea95307fd42..a6438950854e100644drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +2
-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); diff --gita/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c
index72069b77f6f1..b048fd4b8b59100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +0
-0@@ -177,7 +177,7 @@ static int jpeg_v2_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
index2968256d4cd7..f6a9258ae3ca100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c
index564e40899df2..922711aa06a3100644drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +0
-0@@ -192,7 +192,7 @@ static int jpeg_v3_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c
indexb29ca3a49939..fe7ab9cb35bb100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +0
-0@@ -221,7 +221,7 @@ static int jpeg_v4_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +1
-2-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 ) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c
index4da3f9c995c1..87efc3c2b9e0100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c
indexdcdb089b4308..91968ad26f17100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c
indexf2debf6b6bd0..27116d1e9e64100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1
-2-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 ) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c
indexdd0abce73687..7e068c2d4d6d100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +1
-2-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 ) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c
index8ddd12740a04..16daeb61114c100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +1
-1-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_v1_0.c +0
-0@@ -150,8 +150,8 @@ static int vcn_v1_0_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +2
-2-/* Override the work func */ - adev->vcn.inst[0 ].idle_work.work.func = vcn_v1_0_idle_work_handler; +/* Own lockdep class, this work is still cancelled synchronously */ + INIT_DELAYED_WORK(&adev->vcn.inst[0].idle_work,
vcn_v1_0_idle_work_handler);amdgpu_vcn_setup_ucode(adev, 0);drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +1
-1-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 && diff --git
a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.cb/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
index10ef5616b2f5..9dd4c313cbe7100644drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-0@@ -304,8 +304,8 @@ static int vcn_v2_5_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-2-/* Override the work func */ - adev->vcn.inst[j].idle_work.work.func =
vcn_v2_5_idle_work_handler;
+ /* Own lockdep class, this work is still cancelled
+ synchronously
*/
+ INIT_DELAYED_WORK(&adev->vcn.inst[j].idle_work,vcn_v2_5_idle_work_handler);amdgpu_vcn_setup_ucode(adev, j);drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c
index4b7f7bbe18da..5b47a643d725100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cindex3f39aa83c319..5aa09c3bd79b100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +0
-0@@ -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];drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1
-1-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); diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c
indexf30f80c1b07f..9693950cd16d100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cindex7b7c3bc9f046..0c189063a6ab100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cindexc9e990ab297d..3fa553fb41d3100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +0
-0@@ -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];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +1
-1-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 +0
-0@@ -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];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c +1
-2-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 ); } --2.34.1
RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
In reply to Liu, LeoAMD General
Regards,
Prike
Quoted 123 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Monday, October 26, 2026 10:32 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Quoted 103 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Monday, October 26, 2026 5:04 AM
To: Liu, Leo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Regards,
PrikeQuoted 80 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Saturday, October 24, 2026 6:47 AM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Quoted 66 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Prike Liang
Sent: Friday, October 23, 2026 4:34 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workThe common JPEG and VCN idle workers program power gating and DPG pause, so they must not run while a GPU reset is in progress. Recovery must not wait for them either, since everything the workers depend on then becomes a dependency of GPU recovery.
Make the workers take
reset_domain->semfor read, so they wait for
a running reset instead of touching the hardware. hw_fini/suspend andbegin_use, the latter for the IB tests, run from GPU recovery
as well, so only skip waiting for the idle work when the reset itself calls them. The reset holds the semaphore for write and would otherwise
deadlock on a worker blocked on it. Outside a reset the cancel
stays synchronous as before.sw_finialways cancels synchronously, it never runs with the reset semaphore held.Update versions: https://lore.kernel.org/amd-
gfx/PH7PR12MB6000698A62D208E47BB358D7FB662@
PH7PR12MB6000.namprd12.prod.outlook.com/Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 20 ++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 18 +++++++++++++++++- 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 | 2 +- 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_v1_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 4 ++-- 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 +- 23 files changed, 58 insertions(+), 25 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0@@ -74,6 +74,8 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev) {int i, j;Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c int amdgpu_jpeg_sw_fini(struct amdgpu_device · line 78
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0+cancel_delayed_work_sync (&adev->jpeg.idle_work); +I think this is redundant when
hw_fini()ran normally, they are only needed whenhw_fini()was skipped - i.e. whenhw_init()failed and status.hw was never set. Also, UVD and VCE should be covered as well.Quoted 5 lines
Yeah, this change is aimed at the cases where the idle work isn't cancelled synchronously before
sw_fini():hw_fini()was skipped (e.g.hw_init()failed), or the suspend/hw_fini path only did the non-waiting cancel because it ran during a reset. If the idle work was already cancelled synchronously beforesw_fini(), the extra
cancel_delayed_work_sync()is harmless and just returns.Quoted 1 line
Quoted 6 lines
The problem is that calling cancel worker in
sw_finiarrives too late, the idle work is scheduled ~1 second into the future.
The fini_early/fini teardown sequence runs in that same window, tearing down other IP blocks that VCN depends on (MMHUB, SMU). The right place to cancel is in hw_init()'s error path, immediately before returning the error, while other IPs is still alive, and close time window which could lead to problems.
Yes, I'll add a separate patch that cancels synchronously the idle work in the hw_init error paths, so the worker can't run after a failed hw_init.
I'd like to keep the synchronous cancel in sw_fini, though. It covers the case where hw_fini doesn't wait for a worker that's already running, which happens when a peer in the same XGMI hive is resetting. The cancel makes sure that worker finishes before its state is freed.
There's still a related timing issue in the hive reset case: the worker can run after VCN and SMU have been torn down. I'll handle that separately, I want to keep this series focused on GPU recovery first.
Regards,
Prike
Quoted 496 lines
Thanks,
LeoQuoted 492 lines
If there are no other objections, I'll submit this fix upstream later.
Meanwhile, could someone help review patches 3 and 4? They remove the VCN/JPEG memory allocations, which can trigger reclaim, from the GPU recovery path.
Thanks,
PrikeQuoted 7 lines
Thanks,
Leodrivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c int amdgpu_jpeg_sw_fini(struct amdgpu_device
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -95,9 +97,18 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device*adev)
Quoted 474 lines
Quoted 473 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +10
-1return 0 ; } +static void amdgpu_jpeg_cancel_idle_work (struct amdgpu_device +*adev) { +/* The reset mustn't wait for the idle work, which waits for the reset */ +if (amdgpu_in_reset (adev)) +cancel_delayed_work (&adev->jpeg.idle_work); +else +cancel_delayed_work_sync (&adev->jpeg.idle_work); +} +int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);return 0 ; }@@ -114,6 +125,9 @@ static voidamdgpu_jpeg_idle_work_handler(struct
work_struct*work)unsigned int fences = 0; unsigned int i, j;drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3
-0+/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -129,6 +143,8 @@ static voidamdgpu_jpeg_idle_work_handler(struct
work_struct*work)mutex_unlock(&adev->jpeg.jpeg_pg_lock); } else schedule_delayed_work(&adev->jpeg.idle_work,
JPEG_IDLE_TIMEOUT);drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3
-1+ +up_read (&adev->reset_domain->sem); } void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring) @@ -136 ,7 +152,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))drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1
-1-cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);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 +2
-0@@ -269,6 +269,8 @@ void amdgpu_vcn_sw_fini(struct amdgpu_device *adev, int i)if (adev->vcn.harvest_config & (1 << i))return ; +cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); + amdgpu_bo_free_kernel( &adev->vcn.inst[i].dpg_sram_bo,&adev->vcn.inst[i].dpg_sram_gpu_addr,drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0@@ -459,6 +461,15 @@ void amdgpu_vcn_put_profile(struct
amdgpu_device
*adev)mutex_unlock(&adev->vcn.workload_profile_mutex);}
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +9
-0+void amdgpu_vcn_cancel_idle_work (struct amdgpu_vcn_inst +*vcn_inst) { +/* The reset mustn't wait for the idle work, which waits for the reset */ +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 = @@ -470,6 +481,9 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) if (adev->vcn.harvest_config & (1 << i)) return;drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-0+/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] += amdgpu_fence_count_emitted(&vcn_inst-Quoted 1 line
ring_enc[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0@@ -499,6 +513,8 @@ static voidamdgpu_vcn_idle_work_handler(struct
work_struct*work)} else { schedule_delayed_work(&vcn_inst->idle_work, VCN_IDLE_TIMEOUT); }drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-1+ +up_read (&adev->reset_domain->sem); } void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring) @@ -507 ,7 +523,7 @@ void amdgpu_vcn_ring_begin_use(struct amdgpu_ring*ring)
structamdgpu_vcn_inst*vcn_inst=
&adev->vcn.inst[ring->me];if (!atomic_fetch_inc(&vcn_inst->total_submission_cnt))drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +1
-2-cancel_delayed_work_sync (&vcn_inst->idle_work); +amdgpu_vcn_cancel_idle_work (vcn_inst);mutex_lock (&vcn_inst->vcn_pg_lock); vcn_inst->set_pg_state (vcn_inst,AMD_PG_STATE_UNGATE ); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
indexbea95307fd42..a6438950854e100644drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +2
-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); diff --gita/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c
index72069b77f6f1..b048fd4b8b59100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +0
-0@@ -177,7 +177,7 @@ static int jpeg_v2_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
index2968256d4cd7..f6a9258ae3ca100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c
index564e40899df2..922711aa06a3100644drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +0
-0@@ -192,7 +192,7 @@ static int jpeg_v3_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c
indexb29ca3a49939..fe7ab9cb35bb100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +0
-0@@ -221,7 +221,7 @@ static int jpeg_v4_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +1
-2-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 ) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c
index4da3f9c995c1..87efc3c2b9e0100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c
indexdcdb089b4308..91968ad26f17100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c
indexf2debf6b6bd0..27116d1e9e64100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1
-2-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 ) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c
indexdd0abce73687..7e068c2d4d6d100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +1
-2-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 ) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c
index8ddd12740a04..16daeb61114c100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +1
-1-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_v1_0.c +0
-0@@ -150,8 +150,8 @@ static int vcn_v1_0_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +2
-2-/* Override the work func */ - adev->vcn.inst[0 ].idle_work.work.func = vcn_v1_0_idle_work_handler; +/* Own lockdep class, this work is still cancelled synchronously */ + INIT_DELAYED_WORK(&adev->vcn.inst[0].idle_work,
vcn_v1_0_idle_work_handler);amdgpu_vcn_setup_ucode(adev, 0);drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +1
-1-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 && diff --git
a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.cb/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
index10ef5616b2f5..9dd4c313cbe7100644drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-0@@ -304,8 +304,8 @@ static int vcn_v2_5_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-2-/* Override the work func */ - adev->vcn.inst[j].idle_work.work.func =
vcn_v2_5_idle_work_handler;
+ /* Own lockdep class, this work is still cancelled
+ synchronously
*/
+ INIT_DELAYED_WORK(&adev->vcn.inst[j].idle_work,vcn_v2_5_idle_work_handler);amdgpu_vcn_setup_ucode(adev, j);drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c
index4b7f7bbe18da..5b47a643d725100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cindex3f39aa83c319..5aa09c3bd79b100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +0
-0@@ -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];drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1
-1-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); diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c
indexf30f80c1b07f..9693950cd16d100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cindex7b7c3bc9f046..0c189063a6ab100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cindexc9e990ab297d..3fa553fb41d3100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +0
-0@@ -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];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +1
-1-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 +0
-0@@ -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];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c +1
-2-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 ); } --2.34.1
RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
AMD General
Quoted 150 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Tuesday, October 27, 2026 9:20 AM
To: Liu, Leo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Regards,
PrikeQuoted 10 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Monday, October 26, 2026 10:32 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workQuoted 52 lines
AMD General
Quoted 50 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Monday, October 26, 2026 5:04 AM
To: Liu, Leo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Regards,
PrikeQuoted 35 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Saturday, October 24, 2026 6:47 AM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Quoted 21 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Prike Liang
Sent: Friday, October 23, 2026 4:34 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workThe common JPEG and VCN idle workers program power gating and DPG pause, so they must not run while a GPU reset is in progress. Recovery must not wait for them either, since everything the workers depend on then becomes a dependency of GPU recovery.
Make the workers take
reset_domain->semfor read, so they wait for a running reset instead of touching the hardware. hw_fini/suspend andbegin_use, the latter for the IB tests, run from GPU recovery as well, so only skip waiting for the idle work when thereset itself calls them.
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
Quoted 47 lines
The reset holds the semaphore for write and would otherwise deadlock on a worker blocked on it. Outside a reset the cancel stays synchronous as before.
sw_finialways cancels synchronously, it never runs with the reset semaphore held.Update versions: https://lore.kernel.org/amd-
gfx/PH7PR12MB6000698A62D208E47BB358D7FB662@
PH7PR12MB6000.namprd12.prod.outlook.com/Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 20++++++++++++++++++--
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c| ++++++++++++++++++18
+++++++++++++++++-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 | 2 +- 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_v1_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 4 ++-- 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 +- 23 files changed, 58 insertions(+), 25 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0@@ -74,6 +74,8 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev) {int i, j;Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c int amdgpu_jpeg_sw_fini(struct amdgpu_device · line 78
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0+cancel_delayed_work_sync (&adev->jpeg.idle_work); +I think this is redundant when
hw_fini()ran normally, they are only needed whenhw_fini()was skipped - i.e. whenhw_init()failed and status.hw was neverset.
Quoted 10 lines
Quoted 7 lines
Quoted 1 line
Also, UVD and VCE should be covered as well.
Yeah, this change is aimed at the cases where the idle work isn't cancelled synchronously before
sw_fini():hw_fini()was skipped (e.g.hw_init()failed), or the suspend/hw_fini path only did the non-waiting cancel because it ran during a reset. If the idle work was already cancelled synchronously beforesw_fini(), the extra
cancel_delayed_work_sync()is harmless and just returns.Quoted 1 line
Quoted 6 lines
The problem is that calling cancel worker in
sw_finiarrives too late, the idle work is scheduled ~1 second into the future.
The fini_early/fini teardown sequence runs in that same window, tearing down other IP blocks that VCN depends on (MMHUB, SMU). The right place to cancel is in hw_init()'s error path, immediately before returning the error, while other IPs is still alive, and close time window whichcould lead to problems.
Quoted 7 lines
Yes, I'll add a separate patch that cancels synchronously the idle work in the
hw_initerror paths, so the worker can't run after a failedhw_init.I'd like to keep the synchronous cancel in
sw_fini, though. It covers the case wherehw_finidoesn't wait for a worker that's already running, which happens when a peer in the same XGMI hive is resetting. The cancel makes sure that worker finishes before its state is freed.
That is a race condition, and the cancel doesn't fix the root cause,
The preferred fix should make hw_fini properly so it always guarantees the handler is done, removing the need for anything in sw_fini. At least, if keeping something in sw_fini, you need to make it conditional - only when hw_fini actually left a handler running.
Thanks,
Leo
Quoted 514 lines
There's still a related timing issue in the hive reset case: the worker can run after VCN and SMU have been torn down. I'll handle that separately, I want to keep this series focused on GPU recovery first.
Regards,
PrikeQuoted 20 lines
Thanks,
LeoQuoted 17 lines
If there are no other objections, I'll submit this fix upstream later.
Meanwhile, could someone help review patches 3 and 4? They remove the VCN/JPEG memory allocations, which can trigger reclaim, from the GPU recovery path.
Thanks,
PrikeQuoted 7 lines
Thanks,
Leodrivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c int amdgpu_jpeg_sw_fini(struct amdgpu_device
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -95,9 +97,18 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device*adev)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev)
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3
-0return 0 ; } +static void amdgpu_jpeg_cancel_idle_work (struct amdgpu_device +*adev) { +/* The reset mustn't wait for the idle work, which waits for the reset */
Quoted 69 lines
Quoted 69 lines
Quoted 69 lines
Quoted 69 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +7
-1+if (amdgpu_in_reset (adev)) +cancel_delayed_work (&adev->jpeg.idle_work); +else +cancel_delayed_work_sync (&adev->jpeg.idle_work); +} +int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);return 0 ; }@@ -114,6 +125,9 @@ static voidamdgpu_jpeg_idle_work_handler(struct
work_struct*work)unsigned int fences = 0; unsigned int i, j;drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3
-0+/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -129,6 +143,8 @@ static voidamdgpu_jpeg_idle_work_handler(struct
work_struct*work)mutex_unlock(&adev->jpeg.jpeg_pg_lock); } else schedule_delayed_work(&adev->jpeg.idle_work,
JPEG_IDLE_TIMEOUT);drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3
-1+ +up_read (&adev->reset_domain->sem); } void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring) @@ -136 ,7 +152,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))drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1
-1-cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);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 +2
-0@@ -269,6 +269,8 @@ void amdgpu_vcn_sw_fini(struct amdgpu_device *adev, int i)if (adev->vcn.harvest_config & (1 << i))return ; +cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); + amdgpu_bo_free_kernel( &adev->vcn.inst[i].dpg_sram_bo,&adev->vcn.inst[i].dpg_sram_gpu_addr,drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0@@ -459,6 +461,15 @@ void amdgpu_vcn_put_profile(struct
amdgpu_device
*adev)mutex_unlock(&adev->vcn.workload_profile_mutex);}
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-0+void amdgpu_vcn_cancel_idle_work (struct amdgpu_vcn_inst +*vcn_inst) { +/* The reset mustn't wait for the idle work, which waits for the reset */
Quoted 232 lines
Quoted 232 lines
Quoted 232 lines
Quoted 232 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +6
-0+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 = @@ -470,6 +481,9 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) if (adev->vcn.harvest_config & (1 << i)) return;drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-0+/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] += amdgpu_fence_count_emitted(&vcn_inst-Quoted 1 line
ring_enc[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0@@ -499,6 +513,8 @@ static voidamdgpu_vcn_idle_work_handler(struct
work_struct*work)} else { schedule_delayed_work(&vcn_inst->idle_work, VCN_IDLE_TIMEOUT); }drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-1+ +up_read (&adev->reset_domain->sem); } void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring) @@ -507 ,7 +523,7 @@ void amdgpu_vcn_ring_begin_use(struct amdgpu_ring*ring)
structamdgpu_vcn_inst*vcn_inst=
&adev->vcn.inst[ring->me];if (!atomic_fetch_inc(&vcn_inst->total_submission_cnt))drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +1
-1-cancel_delayed_work_sync (&vcn_inst->idle_work); +amdgpu_vcn_cancel_idle_work (vcn_inst);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 +0
-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); voidamdgpu_vcn_ring_end_use(struct amdgpu_ring *ring);drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +2
-0+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); diff --gita/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c
index72069b77f6f1..b048fd4b8b59100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +0
-0@@ -177,7 +177,7 @@ static int jpeg_v2_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
index2968256d4cd7..f6a9258ae3ca100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c
index564e40899df2..922711aa06a3100644drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +0
-0@@ -192,7 +192,7 @@ static int jpeg_v3_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +1
-1-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)) diff --git
a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c
indexb29ca3a49939..fe7ab9cb35bb100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +0
-0@@ -221,7 +221,7 @@ static int jpeg_v4_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c
indexdcdb089b4308..91968ad26f17100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c
indexf2debf6b6bd0..27116d1e9e64100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +1
-1-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_v1_0.c +0
-0@@ -150,8 +150,8 @@ static int vcn_v1_0_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +0
-2-/* Override the work func */ - adev->vcn.inst[0].idle_work.work.func =
vcn_v1_0_idle_work_handler;Quoted 169 lines
Quoted 168 lines
Quoted 167 lines
Quoted 166 lines
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +2
-0+/* Own lockdep class, this work is still cancelled synchronously */ + INIT_DELAYED_WORK(&adev->vcn.inst[0].idle_work,
vcn_v1_0_idle_work_handler);amdgpu_vcn_setup_ucode(adev, 0);drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +1
-1-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 && diff --git
a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.cb/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
index10ef5616b2f5..9dd4c313cbe7100644drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-0@@ -304,8 +304,8 @@ static int vcn_v2_5_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-2-/* Override the work func */ - adev->vcn.inst[j].idle_work.work.func =
vcn_v2_5_idle_work_handler;
+ /* Own lockdep class, this work is still cancelled
+ synchronously
*/
+ INIT_DELAYED_WORK(&adev->vcn.inst[j].idle_work,vcn_v2_5_idle_work_handler);amdgpu_vcn_setup_ucode(adev, j);drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c
index4b7f7bbe18da..5b47a643d725100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cindex3f39aa83c319..5aa09c3bd79b100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +0
-0@@ -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) {
structamdgpu_vcn_inst*vinst =
&adev->vcn.inst[i];drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1
-1-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); diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c
indexf30f80c1b07f..9693950cd16d100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cindex7b7c3bc9f046..0c189063a6ab100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cindexc9e990ab297d..3fa553fb41d3100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +0
-0@@ -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) {
structamdgpu_vcn_inst*vinst =
&adev->vcn.inst[i];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +1
-1-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 +0
-0@@ -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) {
structamdgpu_vcn_inst*vinst =
&adev->vcn.inst[i];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c +1
-2-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 ); } --2.34.1
RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
AMD General
Regards,
Prike
Quoted 171 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Tuesday, October 27, 2026 11:23 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Quoted 159 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Tuesday, October 27, 2026 9:20 AM
To: Liu, Leo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Regards,
PrikeQuoted 11 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Monday, October 26, 2026 10:32 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workQuoted 53 lines
AMD General
Quoted 51 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Monday, October 26, 2026 5:04 AM
To: Liu, Leo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Regards,
PrikeQuoted 36 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Saturday, October 24, 2026 6:47 AM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Quoted 22 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Prike Liang
Sent: Friday, October 23, 2026 4:34 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workThe common JPEG and VCN idle workers program power gating and DPG pause, so they must not run while a GPU reset is in progress. Recovery must not wait for them either, since everything the workers depend on then becomes a dependency of GPU recovery.
Make the workers take
reset_domain->semfor read, so they wait for a running reset instead of touching the hardware. hw_fini/suspend andbegin_use, the latter for the IB tests, run from GPU recovery as well, so only skip waiting for the idle work when thereset itself calls them.
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
Quoted 49 lines
The reset holds the semaphore for write and would otherwise deadlock on a worker blocked on it. Outside a reset the cancel stays synchronous as before.
sw_finialways cancels synchronously, it never runs with the reset semaphore held.Update versions: https://lore.kernel.org/amd-
gfx/PH7PR12MB6000698A62D208E47BB358D7FB662@
PH7PR12MB6000.namprd12.prod.outlook.com/Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 20++++++++++++++++++--
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c++++++++++++++++++|
++++++++++++++++++18
+++++++++++++++++-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 | 2 +- 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_v1_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 4 ++-- 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 +- 23 files changed, 58 insertions(+), 25 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0@@ -74,6 +74,8 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev) {int i, j;Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c int amdgpu_jpeg_sw_fini(struct amdgpu_device · line 78
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0+cancel_delayed_work_sync (&adev->jpeg.idle_work); +I think this is redundant when
hw_fini()ran normally, they are only needed whenhw_fini()was skipped - i.e. whenhw_init()failed and status.hw was neverset.
Quoted 10 lines
Quoted 7 lines
Quoted 1 line
Also, UVD and VCE should be covered as well.
Yeah, this change is aimed at the cases where the idle work isn't cancelled synchronously before
sw_fini():hw_fini()was skipped (e.g.hw_init()failed), or the suspend/hw_fini path only did the non-waiting cancel because it ran during a reset. If the idle work was already cancelled synchronously beforesw_fini(), the extra
cancel_delayed_work_sync()is harmless and just returns.Quoted 1 line
Quoted 7 lines
The problem is that calling cancel worker in
sw_finiarrives too late, the idle work is scheduled ~1 second into the future. The fini_early/fini teardown sequence runs in that same window, tearing down other IP blocks that VCN depends on (MMHUB, SMU). The right place to cancel is in hw_init()'s error path, immediately before returning the error, while other IPs is still alive, and close time window whichcould lead to problems.
Yes, I'll add a separate patch that cancels synchronously the idle work in the
hw_initerror paths, so the worker can't run after a failedhw_init.
Quoted 8 lines
Quoted 4 lines
I'd like to keep the synchronous cancel in
sw_fini, though. It covers the case wherehw_finidoesn't wait for a worker that's already running, which happens when a peer in the same XGMI hive is resetting. The cancel makes sure that worker finishes before its state is freed.That is a race condition, and the cancel doesn't fix the root cause, The preferred fix should make
hw_finiproperly so it always guarantees the handler is done, removing the need for anything insw_fini.
OK, got it. For the XGMI hive case, where hw_fini doesn't wait for the idle work while a peer is resetting, I'll move the synchronous cancel to early_fini(). It runs only on teardown, before any hw_fini. I'll also drop the cancel from sw_fini.
Quoted 2 lines
At least, if keeping something in
sw_fini, you need to make it conditional - only whenhw_finiactually left a handler running.
Yes, a flag set when hw_fini skips waiting would let sw_fini cancel only in that case. But the worker could still run while the hardware is being torn down. So I'll move the synchronous cancel to early_fini(), before any hw_fini, and drop it from sw_fini.
Thanks,
Prike
Quoted 522 lines
Thanks,
LeoQuoted 518 lines
There's still a related timing issue in the hive reset case: the worker can run after VCN and SMU have been torn down. I'll handle that separately, I want to keep this series focused on GPU recovery first.
Regards,
PrikeQuoted 19 lines
Thanks,
LeoQuoted 16 lines
If there are no other objections, I'll submit this fix upstream later.
Meanwhile, could someone help review patches 3 and 4? They remove the VCN/JPEG memory allocations, which can trigger reclaim, from the GPU recovery path.
Thanks,
PrikeQuoted 7 lines
Thanks,
LeoQuoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i)) continue; @@ -95,9 +97,18 @@ intamdgpu_jpeg_sw_fini(struct
amdgpu_deviceQuoted 8 lines
Quoted 8 lines
*adev)
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c
Quoted 7 lines
return 0;}
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +4
-0+static void amdgpu_jpeg_cancel_idle_work (struct amdgpu_device +*adev) { +/* The reset mustn't wait for the idle work, which waits +for the reset */
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
Quoted 68 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +7
-1+if (amdgpu_in_reset (adev)) +cancel_delayed_work (&adev->jpeg.idle_work); +else +cancel_delayed_work_sync (&adev->jpeg.idle_work); +} +int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);return 0 ; }@@ -114,6 +125,9 @@ static voidamdgpu_jpeg_idle_work_handler(struct
work_struct*work)unsigned int fences = 0; unsigned int i, j;drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3
-0+/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i)) continue; @@ -129,6 +143,8 @@ staticvoid amdgpu_jpeg_idle_work_handler(struct
work_struct*work)mutex_unlock(&adev->jpeg.jpeg_pg_lock); } else schedule_delayed_work(&adev->jpeg.idle_work,
JPEG_IDLE_TIMEOUT);drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3
-1+ +up_read (&adev->reset_domain->sem); } void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring) @@ -136 ,7 +152,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))drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1
-1-cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);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 +2
-0@@ -269,6 +269,8 @@ void amdgpu_vcn_sw_fini(struct amdgpu_device *adev, int i) if (adev->vcn.harvest_config & (1 << i))return ; +cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); + amdgpu_bo_free_kernel( &adev->vcn.inst[i].dpg_sram_bo,&adev->vcn.inst[i].dpg_sram_gpu_addr,drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0@@ -459,6 +461,15 @@ void amdgpu_vcn_put_profile(struct
amdgpu_device
*adev)mutex_unlock(&adev->vcn.workload_profile_mutex);}
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +4
-0+void amdgpu_vcn_cancel_idle_work (struct amdgpu_vcn_inst +*vcn_inst) { +/* The reset mustn't wait for the idle work, which waits +for the reset */
Quoted 235 lines
Quoted 235 lines
Quoted 235 lines
Quoted 235 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +6
-0+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 = @@ -470,6 +481,9 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) if (adev->vcn.harvest_config & (1 << i)) return;drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-0+/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] +=amdgpu_fence_count_emitted(&vcn_inst-
Quoted 1 line
ring_enc[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0@@ -499,6 +513,8 @@ static voidamdgpu_vcn_idle_work_handler(struct
work_struct*work)} else { schedule_delayed_work(&vcn_inst->idle_work, VCN_IDLE_TIMEOUT); }drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-1+ +up_read (&adev->reset_domain->sem); } void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring) @@ -507 ,7 +523,7 @@ void amdgpu_vcn_ring_begin_use(struct amdgpu_ring*ring)
structamdgpu_vcn_inst*vcn_inst=
&adev->vcn.inst[ring->me];if (!atomic_fetch_inc(&vcn_inst->total_submission_cnt))drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +1
-1-cancel_delayed_work_sync (&vcn_inst->idle_work); +amdgpu_vcn_cancel_idle_work (vcn_inst);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 +0
-0@@ -526,6 +526,7 @@ int amdgpu_vcn_suspend(struct
amdgpu_device*adev, int i); intamdgpu_vcn_resume(struct amdgpu_device *adev, int i); voidamdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring); voidamdgpu_vcn_ring_end_use(struct amdgpu_ring *ring);drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +2
-0+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_tvcn_instance); diff --gita/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c
index72069b77f6f1..b048fd4b8b59100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +0
-0@@ -177,7 +177,7 @@ static int jpeg_v2_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
index2968256d4cd7..f6a9258ae3ca100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c
index564e40899df2..922711aa06a3100644drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +0
-0@@ -192,7 +192,7 @@ static int jpeg_v3_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c
indexb29ca3a49939..fe7ab9cb35bb100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +0
-0@@ -221,7 +221,7 @@ static int jpeg_v4_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +1
-1-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)) diff --gita/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c
index0343a64595f2..f4896ad9d1de100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c
indexdcdb089b4308..91968ad26f17100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c
indexf2debf6b6bd0..27116d1e9e64100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +1
-1-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)) diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
index76793a5caa70..470d8f110799100644drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +0
-0@@ -150,8 +150,8 @@ static int vcn_v1_0_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +0
-2-/* Override the work func */ - adev->vcn.inst[0].idle_work.work.func =
vcn_v1_0_idle_work_handler;Quoted 169 lines
Quoted 168 lines
Quoted 167 lines
Quoted 166 lines
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +2
-0+/* Own lockdep class, this work is still cancelled synchronously */ + INIT_DELAYED_WORK(&adev->vcn.inst[0].idle_work,
vcn_v1_0_idle_work_handler);amdgpu_vcn_setup_ucode(adev, 0);drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +1
-1-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 && diff --git
a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.cb/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
index10ef5616b2f5..9dd4c313cbe7100644drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-0@@ -304,8 +304,8 @@ static int vcn_v2_5_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-2-/* Override the work func */ - adev->vcn.inst[j].idle_work.work.func =
vcn_v2_5_idle_work_handler;
+ /* Own lockdep class, this work is still
+ cancelled synchronously
*/
+ INIT_DELAYED_WORK(&adev->vcn.inst[j].idle_work,vcn_v2_5_idle_work_handler);amdgpu_vcn_setup_ucode(adev, j);drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c
index4b7f7bbe18da..5b47a643d725100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cindex3f39aa83c319..5aa09c3bd79b100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +0
-0@@ -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) {
structamdgpu_vcn_inst*vinst =
&adev->vcn.inst[i];drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1
-1-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); diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c
indexf30f80c1b07f..9693950cd16d100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cindex7b7c3bc9f046..0c189063a6ab100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cindexc9e990ab297d..3fa553fb41d3100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +0
-0@@ -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) {
structamdgpu_vcn_inst*vinst =
&adev->vcn.inst[i];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +1
-1-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 +0
-0@@ -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) {
structamdgpu_vcn_inst*vinst =
&adev->vcn.inst[i];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c +1
-2-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 ); } --2.34.1
RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
AMD General
Quoted 196 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Tuesday, October 27, 2026 11:28 PM
To: Liu, Leo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Regards,
PrikeQuoted 10 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Tuesday, October 27, 2026 11:23 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workQuoted 95 lines
AMD General
Quoted 93 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Tuesday, October 27, 2026 9:20 AM
To: Liu, Leo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Regards,
PrikeQuoted 11 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Monday, October 26, 2026 10:32 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workQuoted 53 lines
AMD General
Quoted 51 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Monday, October 26, 2026 5:04 AM
To: Liu, Leo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Regards,
PrikeQuoted 36 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Saturday, October 24, 2026 6:47 AM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Quoted 22 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Prike Liang
Sent: Friday, October 23, 2026 4:34 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workThe common JPEG and VCN idle workers program power gating and DPG pause, so they must not run while a GPU reset is in progress. Recovery must not wait for them either, since everything the workers depend on then becomes a dependency of GPU recovery.
Make the workers take
reset_domain->semfor read, so they wait for a running reset instead of touching the hardware. hw_fini/suspend andbegin_use, the latter for the IB tests, run from GPU recovery as well, so only skip waiting for the idle work when thereset itself calls them.
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
The reset holds the semaphore for write and would otherwise deadlock on a worker blocked on it. Outside a reset the cancel stays synchronous as before.
sw_finialways cancels synchronously, it never runs with the reset semaphore held.Update versions: https://lore.kernel.org/amd-
gfx/PH7PR12MB6000698A62D208E47BB358D7FB662@
PH7PR12MB6000.namprd12.prod.outlook.com/Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 20++++++++++++++++++--
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.cQuoted 64 lines
Quoted 64 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
++++++++++++++++++|
++++++++++++++++++18
+++++++++++++++++-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 | 2 +- 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_v1_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 4 ++-- 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 +- 23 files changed, 58 insertions(+), 25 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0@@ -74,6 +74,8 @@ int amdgpu_jpeg_sw_fini(struct
amdgpu_device*adev) { int i, j;Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0+cancel_delayed_work_sync (&adev->jpeg.idle_work); +I think this is redundant when
hw_fini()ran normally, they are only needed whenhw_fini()was skipped - i.e. whenhw_init()failed and status.hw was neverset.
Quoted 18 lines
Quoted 8 lines
Quoted 1 line
Also, UVD and VCE should be covered as well.
Yeah, this change is aimed at the cases where the idle work isn't cancelled synchronously before
sw_fini():hw_fini()was skipped (e.g.hw_init()failed), or the suspend/hw_fini path only did the non-waiting cancel because it ran during a reset. If the idle work was already cancelled synchronously beforesw_fini(), the extra
cancel_delayed_work_sync()is harmless and just returns.Quoted 1 line
The problem is that calling cancel worker in
sw_finiarrives too late, the idle work is scheduled ~1 second into the future. The fini_early/fini teardown sequence runs in that same window, tearing down other IP blocks that VCN depends on (MMHUB, SMU). The right place to cancel is in hw_init()'s error path, immediately before returning the error, while other IPs is still alive, and close time window whichQuoted 8 lines
Quoted 8 lines
could lead to problems.
Yes, I'll add a separate patch that cancels synchronously the idle work in the
hw_initerror paths, so the worker can't run after a failedhw_init.I'd like to keep the synchronous cancel in
sw_fini, though. It covers the case wherehw_finidoesn't wait for a worker that's already running, which happens when a peer in the same XGMI hive isresetting.
Quoted 2 lines
Quoted 1 line
The cancel makes sure that worker finishes before its state is freed.
Quoted 8 lines
Quoted 3 lines
That is a race condition, and the cancel doesn't fix the root cause, The preferred fix should make
hw_finiproperly so it always guarantees the handler is done, removing the need for anything insw_fini.OK, got it. For the XGMI hive case, where
hw_finidoesn't wait for the idle work while a peer is resetting, I'll move the synchronous cancel toearly_fini(). It runs only on teardown, before anyhw_fini. I'll also drop the cancel fromsw_fini.
However it still leaves a time window between the ring test failure and when early_fini is eventually reached, during which the idle workers can fire on broken hardware or race with other
IP blocks in transitional states. The only place that eliminates the window entirely is hw_init()'s error path itself.
More importantly, it seems to me that early_fini is only called from amdgpu_device_fini_hw() - the driver unload path. It has no presence in amdgpu_device_gpu_recover(), if that is true, does it affect your case?
Thanks,
Leo
Quoted 542 lines
Quoted 2 lines
At least, if keeping something in
sw_fini, you need to make it conditional - only whenhw_finiactually left a handler running.Yes, a flag set when
hw_finiskips waiting would letsw_finicancel only in that case. But the worker could still run while the hardware is being torn down. So I'll move the synchronous cancel toearly_fini(), before anyhw_fini, and drop it fromsw_fini.Thanks,
PrikeQuoted 530 lines
Thanks,
LeoQuoted 526 lines
There's still a related timing issue in the hive reset case: the worker can run after VCN and SMU have been torn down. I'll handle that separately, I want to keep this series focused on GPU recovery first.
Regards,
PrikeQuoted 20 lines
Thanks,
LeoQuoted 17 lines
If there are no other objections, I'll submit this fix upstream later.
Meanwhile, could someone help review patches 3 and 4? They remove the VCN/JPEG memory allocations, which can trigger reclaim, from the GPU recovery path.
Thanks,
PrikeQuoted 7 lines
Thanks,
LeoQuoted 4 lines
for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) { if (adev->jpeg.harvest_config & (1U << i)) continue; @@ -95,9 +97,18 @@ intamdgpu_jpeg_sw_fini(struct
amdgpu_device*adev)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c
Quoted 8 lines
return 0;}
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +5
-0+static void amdgpu_jpeg_cancel_idle_work (struct +amdgpu_device +*adev) { +/* The reset mustn't wait for the idle work, which +waits for the reset */
Quoted 71 lines
Quoted 71 lines
Quoted 71 lines
Quoted 71 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +8
-1+if (amdgpu_in_reset (adev)) +cancel_delayed_work (&adev->jpeg.idle_work); +else + +cancel_delayed_work_sync (&adev->jpeg.idle_work); +} +int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);return 0 ; }@@ -114,6 +125,9 @@ static voidamdgpu_jpeg_idle_work_handler(struct
work_struct*work)unsigned int fences = 0; unsigned int i, j;drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3
-0+/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i)) continue; @@ -129,6 +143,8 @@ staticvoid amdgpu_jpeg_idle_work_handler(struct
work_struct*work)mutex_unlock(&adev->jpeg.jpeg_pg_lock); } else schedule_delayed_work(&adev->jpeg.idle_work,
JPEG_IDLE_TIMEOUT);drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0+ +up_read (&adev->reset_domain->sem); }void amdgpu_jpeg_ring_begin_use (struct amdgpu_ring *ring)@@
-136,7
+152,7 @@ voidamdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)struct amdgpu_device *adev = ring->adev; if (!atomic_fetch_inc(&adev->jpeg.total_submission_cnt))drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1
-1-cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);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 +3
-0@@ -269,6 +269,8 @@ void amdgpu_vcn_sw_fini(struct amdgpu_device *adev, int i) if (adev->vcn.harvest_config & (1 << i))return ; + +cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); + amdgpu_bo_free_kernel( &adev->vcn.inst[i].dpg_sram_bo, &adev->vcn.inst[i].dpg_sram_gpu_addr,@@ -459,6 +461,15 @@ void amdgpu_vcn_put_profile(struct
amdgpu_device
*adev)mutex_unlock(&adev->vcn.workload_profile_mutex);}
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +4
-0+void amdgpu_vcn_cancel_idle_work (struct amdgpu_vcn_inst +*vcn_inst) { +/* The reset mustn't wait for the idle work, which +waits for the reset */
Quoted 236 lines
Quoted 236 lines
Quoted 236 lines
Quoted 236 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +7
-0+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 = @@ -470,6 +481,9 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) if (adev->vcn.harvest_config & (1 << i)) return;drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-0+/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] +=amdgpu_fence_count_emitted(&vcn_inst-
Quoted 1 line
ring_enc[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0@@ -499,6 +513,8 @@ static voidamdgpu_vcn_idle_work_handler(struct
work_struct*work)} else { schedule_delayed_work(&vcn_inst->idle_work, VCN_IDLE_TIMEOUT); }drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-1+ +up_read (&adev->reset_domain->sem); } void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring) @@ -507 ,7 +523,7 @@ void amdgpu_vcn_ring_begin_use(struct amdgpu_ring*ring)
structamdgpu_vcn_inst*vcn_inst=
&adev->vcn.inst[ring->me];if (!atomic_fetch_inc(&vcn_inst->total_submission_cnt))drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +1
-1-cancel_delayed_work_sync (&vcn_inst->idle_work); +amdgpu_vcn_cancel_idle_work (vcn_inst);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 +0
-0@@ -526,6 +526,7 @@ int amdgpu_vcn_suspend(struct
amdgpu_device*adev, int i); intamdgpu_vcn_resume(struct amdgpu_device *adev, int i); voidamdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring); voidamdgpu_vcn_ring_end_use(struct amdgpu_ring *ring);drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +2
-0+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_tvcn_instance); diff --gita/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c
index72069b77f6f1..b048fd4b8b59100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +0
-0@@ -177,7 +177,7 @@ static int jpeg_v2_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
index2968256d4cd7..f6a9258ae3ca100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c
index564e40899df2..922711aa06a3100644drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +0
-0@@ -192,7 +192,7 @@ static int jpeg_v3_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c
indexb29ca3a49939..fe7ab9cb35bb100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +0
-0@@ -221,7 +221,7 @@ static int jpeg_v4_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +1
-1-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)) diff --gita/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c
index0343a64595f2..f4896ad9d1de100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c
indexdcdb089b4308..91968ad26f17100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c
indexf2debf6b6bd0..27116d1e9e64100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +1
-1-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)) diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
index76793a5caa70..470d8f110799100644drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +0
-0@@ -150,8 +150,8 @@ static int vcn_v1_0_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +0
-2-/* Override the work func */ - adev->vcn.inst[0].idle_work.work.func =
vcn_v1_0_idle_work_handler;Quoted 172 lines
Quoted 171 lines
Quoted 170 lines
Quoted 169 lines
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +2
-0+/* Own lockdep class, this work is still cancelled synchronously */ + INIT_DELAYED_WORK(&adev->vcn.inst[0].idle_work,
vcn_v1_0_idle_work_handler);amdgpu_vcn_setup_ucode(adev, 0);drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +1
-2-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 && diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
index10ef5616b2f5..9dd4c313cbe7100644drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-0@@ -304,8 +304,8 @@ static int vcn_v2_5_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-2-/* Override the work func */ - adev->vcn.inst[j].idle_work.work.func =
vcn_v2_5_idle_work_handler;
+ /* Own lockdep class, this work is still
+ cancelled synchronously
*/
+
+INIT_DELAYED_WORK(&adev->vcn.inst[j].idle_work, vcn_v2_5_idle_work_handler);amdgpu_vcn_setup_ucode(adev, j);drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c
index4b7f7bbe18da..5b47a643d725100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cindex3f39aa83c319..5aa09c3bd79b100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +0
-0@@ -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) {
structamdgpu_vcn_inst*vinst =
&adev->vcn.inst[i];drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1
-1-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); diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c
indexf30f80c1b07f..9693950cd16d100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cindex7b7c3bc9f046..0c189063a6ab100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cindexc9e990ab297d..3fa553fb41d3100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +0
-0@@ -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) {
structamdgpu_vcn_inst*vinst =
&adev->vcn.inst[i];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +2
-1-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 +0
-0@@ -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) {
structamdgpu_vcn_inst*vinst =
&adev->vcn.inst[i];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c +2
-2-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 ); } --2.34.1
RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
AMD General
Regards,
Prike
Quoted 222 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Wednesday, October 28, 2026 11:40 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Quoted 10 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Tuesday, October 27, 2026 11:28 PM
To: Liu, Leo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workQuoted 90 lines
AMD General
Regards,
PrikeQuoted 85 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Tuesday, October 27, 2026 11:23 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Quoted 72 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Tuesday, October 27, 2026 9:20 AM
To: Liu, Leo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Regards,
PrikeQuoted 57 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Monday, October 26, 2026 10:32 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Quoted 44 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Monday, October 26, 2026 5:04 AM
To: Liu, Leo <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Regards,
PrikeQuoted 29 lines
-----Original Message-----
From: Liu, Leo <[email protected]>
Sent: Saturday, October 24, 2026 6:47 AM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: RE: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workAMD General
Quoted 15 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Prike Liang
Sent: Friday, October 23, 2026 4:34 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>
Subject: [PATCH 5/8] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workThe common JPEG and VCN idle workers program power gating and DPG pause, so they must not run while a GPU reset is in
progress.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Recovery must not wait for them either, since everything the workers depend on then becomes a dependency of GPU recovery.
Make the workers take
reset_domain->semfor read, so they wait for a running reset instead of touching the hardware. hw_fini/suspend andbegin_use, the latter for the IB tests, run from GPU recovery as well, so only skip waiting for the idle work when theQuoted 5 lines
Quoted 5 lines
Quoted 5 lines
reset itself calls them.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
The reset holds the semaphore for write and would otherwise deadlock on a worker blocked on it. Outside a reset the cancel stays synchronous as before.
sw_finialways cancels synchronously, it never runs with the reset semaphoreheld.
Quoted 86 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Update versions: https://lore.kernel.org/amd-
gfx/PH7PR12MB6000698A62D208E47BB358D7FB662@
PH7PR12MB6000.namprd12.prod.outlook.com/Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 20++++++++++++++++++--
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.cQuoted 66 lines
Quoted 66 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
++++++++++++++++++|
++++++++++++++++++18
+++++++++++++++++-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 | 2 +- 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_v1_0.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 2 +- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 4 ++-- 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 +- 23 files changed, 58 insertions(+), 25 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-0@@ -74,6 +74,8 @@ int amdgpu_jpeg_sw_fini(struct
amdgpu_device*adev) { int i, j;Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0+cancel_delayed_work_sync (&adev->jpeg.idle_work); +I think this is redundant when
hw_fini()ran normally, they are only needed whenhw_fini()was skipped - i.e. whenhw_init()failed and status.hw was neverset.
Quoted 11 lines
Quoted 8 lines
Quoted 1 line
Also, UVD and VCE should be covered as well.
Yeah, this change is aimed at the cases where the idle work isn't cancelled synchronously before
sw_fini():hw_fini()was skipped (e.g.hw_init()failed), or the suspend/hw_fini path only did the non-waiting cancel because it ran during a reset. If the idle work was already cancelled synchronously beforesw_fini(), the extra
cancel_delayed_work_sync()is harmless and just returns.Quoted 1 line
Quoted 7 lines
The problem is that calling cancel worker in
sw_finiarrives too late, the idle work is scheduled ~1 second into the future. The fini_early/fini teardown sequence runs in that same window, tearing down other IP blocks that VCN depends on (MMHUB, SMU). The right place to cancel is in hw_init()'s error path, immediately before returning the error, while other IPs is still alive, and close time window whichcould lead to problems.
Quoted 7 lines
Quoted 7 lines
Yes, I'll add a separate patch that cancels synchronously the idle work in the
hw_initerror paths, so the worker can't run after a failedhw_init.I'd like to keep the synchronous cancel in
sw_fini, though. It covers the case wherehw_finidoesn't wait for a worker that's already running, which happens when a peer in the same XGMI hive isresetting.
Quoted 2 lines
Quoted 1 line
The cancel makes sure that worker finishes before its state is freed.
Quoted 7 lines
Quoted 3 lines
That is a race condition, and the cancel doesn't fix the root cause, The preferred fix should make
hw_finiproperly so it always guarantees the handler is done, removing the need for anything insw_fini.OK, got it. For the XGMI hive case, where
hw_finidoesn't wait for the idle work while a peer is resetting, I'll move the synchronous cancel
toearly_fini(). It runs only on teardown, before anyhw_fini. I'll also drop the cancelfrom
sw_fini.Quoted 1 line
Quoted 8 lines
However it still leaves a time window between the ring test failure and when
early_finiis eventually reached, during which the idle workers can fire on broken hardware or race with other IP blocks in transitional states. The only place that eliminates the window entirely is hw_init()'s error path itself.More importantly, it seems to me that
early_finiis only called fromamdgpu_device_fini_hw()- the driver unload path. It has no presence inamdgpu_device_gpu_recover(), if that is true, does it affect your case?
Yes, most of those cases are covered by cancelling synchronously the idle work in the hw_init error path. The one left is a device being unloaded while a peer in its XGMI hive is being reset. The hive shares one reset domain, so in that case hw_fini doesn't wait for the idle work. hw_fini is skipped entirely if the peer's reset has already suspended the device. Cancelling the idle work synchronously in early_fini covers this, since early_fini only runs on teardown and before any hw_fini. That cancel only holds up the unload, at most until the peer's reset finishes, so recovery still never waits for the worker.
Meanwhile, I see you've already handled the hw_init error path, so I'll drop my local fix for it and focus on the GPU recovery side. I'll update the patch as follows:
1) Don't cancel the idle work synchronously on the GPU reset path.
2) Cancel the idle work synchronously in early_fini, to cover a device being unloaded while a peer in its XGMI hive is being reset.
Thanks,
Prike
Quoted 555 lines
Thanks,
LeoQuoted 550 lines
Quoted 2 lines
At least, if keeping something in
sw_fini, you need to make it conditional - only whenhw_finiactually left a handler running.Yes, a flag set when
hw_finiskips waiting would letsw_finicancel only in that case. But the worker could still run while the hardware is being torn down. So I'll move the synchronous cancel toearly_fini(), before anyhw_fini, and drop it fromsw_fini.Thanks,
PrikeQuoted 538 lines
Thanks,
LeoQuoted 534 lines
There's still a related timing issue in the hive reset case: the worker can run after VCN and SMU have been torn down. I'll handle that separately, I want to keep this series focused on GPU recovery first.
Regards,
PrikeQuoted 20 lines
Thanks,
LeoQuoted 17 lines
If there are no other objections, I'll submit this fix upstream later.
Meanwhile, could someone help review patches 3 and 4? They remove the VCN/JPEG memory allocations, which can trigger reclaim, from the GPU recovery path.
Thanks,
PrikeQuoted 7 lines
Thanks,
LeoQuoted 4 lines
for (i = 0; i < adev->jpeg.num_jpeg_inst; ++i) { if (adev->jpeg.harvest_config & (1U << i)) continue; @@ -95,9 +97,18 @@ intamdgpu_jpeg_sw_fini(struct
amdgpu_device*adev)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c
Quoted 8 lines
return 0;}
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +5
-0+static void amdgpu_jpeg_cancel_idle_work (struct +amdgpu_device +*adev) { +/* The reset mustn't wait for the idle work, which +waits for the reset */
Quoted 72 lines
Quoted 72 lines
Quoted 72 lines
Quoted 72 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +8
-1+if (amdgpu_in_reset (adev)) +cancel_delayed_work (&adev->jpeg.idle_work); +else + +cancel_delayed_work_sync (&adev->jpeg.idle_work); +} +int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);return 0 ; }@@ -114,6 +125,9 @@ static voidamdgpu_jpeg_idle_work_handler(struct
work_struct*work)unsigned int fences = 0; unsigned int i, j;drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +3
-0+/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i)) continue; @@ -129,6 +143,8 @@ staticvoid amdgpu_jpeg_idle_work_handler(struct
work_struct*work)mutex_unlock(&adev->jpeg.jpeg_pg_lock); } else schedule_delayed_work(&adev->jpeg.idle_work,
JPEG_IDLE_TIMEOUT);drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +2
-0+ +up_read (&adev->reset_domain->sem); }void amdgpu_jpeg_ring_begin_use (struct amdgpu_ring *ring)@@
-136,7
+152,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))drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1
-1-cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_cancel_idle_work (adev);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 +3
-0@@ -269,6 +269,8 @@ void amdgpu_vcn_sw_fini(struct amdgpu_device *adev, int i) if (adev->vcn.harvest_config & (1 << i))return ; + +cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); + amdgpu_bo_free_kernel( &adev->vcn.inst[i].dpg_sram_bo, &adev->vcn.inst[i].dpg_sram_gpu_addr,@@ -459,6 +461,15 @@ void amdgpu_vcn_put_profile(struct
amdgpu_device
*adev)mutex_unlock(&adev->vcn.workload_profile_mutex);}
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +4
-0+void amdgpu_vcn_cancel_idle_work (struct amdgpu_vcn_inst +*vcn_inst) { +/* The reset mustn't wait for the idle work, which +waits for the reset */
Quoted 243 lines
Quoted 243 lines
Quoted 243 lines
Quoted 243 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +7
-0+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 = @@ -470,6 +481,9 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) if (adev->vcn.harvest_config & (1 << i)) return;drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3
-0+/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] +=amdgpu_fence_count_emitted(&vcn_inst-
Quoted 1 line
ring_enc[j]);
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0@@ -499,6 +513,8 @@ static voidamdgpu_vcn_idle_work_handler(struct
work_struct*work)} else { schedule_delayed_work(&vcn_inst->idle_work, VCN_IDLE_TIMEOUT); }drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +2
-0+ +up_read (&adev->reset_domain->sem); }void amdgpu_vcn_ring_begin_use (struct amdgpu_ring *ring)@@
-507,7
+523,7 @@ void amdgpu_vcn_ring_begin_use(struct +amdgpu_ring
*ring)
structamdgpu_vcn_inst*vcn_inst=
&adev->vcn.inst[ring->me];if (!atomic_fetch_inc(&vcn_inst->total_submission_cnt))drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +1
-1-cancel_delayed_work_sync (&vcn_inst->idle_work); +amdgpu_vcn_cancel_idle_work (vcn_inst);mutex_lock (&vcn_inst->vcn_pg_lock); vcn_inst->set_pg_state(vcn_inst,
AMD_PG_STATE_UNGATE); diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.hb/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
indexbea95307fd42..a6438950854e100644drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +0
-0@@ -526,6 +526,7 @@ int amdgpu_vcn_suspend(struct
amdgpu_device*adev, int i); intamdgpu_vcn_resume(struct amdgpu_device *adev, int i); voidamdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring); voidamdgpu_vcn_ring_end_use(struct amdgpu_ring *ring);drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +2
-0+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_tvcn_instance); diff --gita/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c
index72069b77f6f1..b048fd4b8b59100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +0
-0@@ -177,7 +177,7 @@ static int jpeg_v2_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c
index2968256d4cd7..f6a9258ae3ca100644drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +1
-1-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 +0
-0@@ -192,7 +192,7 @@ static int jpeg_v3_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +1
-2-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)) diff --git a/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c
b/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c
indexb29ca3a49939..fe7ab9cb35bb100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +0
-0@@ -221,7 +221,7 @@ static int jpeg_v4_0_hw_fini(struct
amdgpu_ip_block*ip_block){ struct amdgpu_device *adev = ip_block->adev;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +1
-1-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)) diff --gita/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c
index0343a64595f2..f4896ad9d1de100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +1
-1-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) diff --gita/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c
index4da3f9c995c1..87efc3c2b9e0100644drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +1
-1-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_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +1
-1-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 +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1
-1-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) diff --gita/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c
indexdd0abce73687..7e068c2d4d6d100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +1
-1-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) diff --gita/drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.cb/drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c
index8ddd12740a04..16daeb61114c100644drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +1
-1-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)) diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
index76793a5caa70..470d8f110799100644drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +0
-0@@ -150,8 +150,8 @@ static int vcn_v1_0_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +0
-2-/* Override the work func */ - adev->vcn.inst[0].idle_work.work.func =
vcn_v1_0_idle_work_handler;Quoted 172 lines
Quoted 171 lines
Quoted 170 lines
Quoted 169 lines
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +2
-0+/* Own lockdep class, this work is still cancelled synchronously */ + INIT_DELAYED_WORK(&adev->vcn.inst[0].idle_work,
vcn_v1_0_idle_work_handler);amdgpu_vcn_setup_ucode(adev, 0);drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +1
-2-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 && diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
index10ef5616b2f5..9dd4c313cbe7100644drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-0@@ -304,8 +304,8 @@ static int vcn_v2_5_sw_init(struct
amdgpu_ip_block*ip_block)if (r) return r;drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +0
-2-/* Override the work func */ - adev->vcn.inst[j].idle_work.work.func =
vcn_v2_5_idle_work_handler;
+ /* Own lockdep class, this work is still
+ cancelled synchronously
*/
+
+INIT_DELAYED_WORK(&adev->vcn.inst[j].idle_work, vcn_v2_5_idle_work_handler);amdgpu_vcn_setup_ucode(adev, j);drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c
index4b7f7bbe18da..5b47a643d725100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cindex3f39aa83c319..5aa09c3bd79b100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +0
-0@@ -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) {
structamdgpu_vcn_inst*vinst =
&adev->vcn.inst[i];drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1
-1-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); diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c
indexf30f80c1b07f..9693950cd16d100644drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cindex7b7c3bc9f046..0c189063a6ab100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +0
-0@@ -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;drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1
-1-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)
|| diff --gita/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cindexc9e990ab297d..3fa553fb41d3100644drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +0
-0@@ -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) {
structamdgpu_vcn_inst*vinst =
&adev->vcn.inst[i];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +2
-1-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 +0
-0@@ -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) {
structamdgpu_vcn_inst*vinst =
&adev->vcn.inst[i];drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c +2
-2-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 ); } --2.34.1
PATCH 6/8 drm/amdgpu/userq: wait for GPU reset before mapping or unmapping queues
In reply to Prike LiangThe user queue map and unmap helpers talk to the MES, but only the create path holds reset_domain->sem around them. The eviction, restore, destroy and suspend paths can submit to the MES while a GPU reset is in progress:
WARNING: amdgpu_device.c:928 at amdgpu_device_skip_hw_access+0x73/0x90 [amdgpu] Workqueue: events amdgpu_eviction_fence_suspend_worker [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_remove_hw_queue+0xd9/0x100 [amdgpu] mes_userq_unmap+0xc3/0x140 [amdgpu] amdgpu_userq_unmap_helper+0x67/0x280 [amdgpu] amdgpu_userq_evict+0x52/0xf0 [amdgpu] amdgpu_eviction_fence_suspend_worker+0x55/0xe0 [amdgpu]
Take the semaphore for read in the helpers instead, around both the MES call and the queue state check and update. The reset changes the queue state from amdgpu_userq_pre_reset()/post_reset(), so every caller now waits for a running reset and acts on the state it left behind.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4 -5
@@ -362,6 +362,8 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue) adev->userq_funcs[queue->queue_type];int r; +/* The reset changes the queue state and the MES is unusable meanwhile */ +guard (rwsem_read)(&adev->reset_domain->sem);if ((queue->state ==AMDGPU_USERQ_STATE_MAPPED ) || (queue->state ==AMDGPU_USERQ_STATE_PREEMPTED )) {trace_amdgpu_userq_state_start (queue);
@@ -388,6 +390,8 @@ static int amdgpu_userq_map_helper(struct amdgpu_usermode_queue *queue) adev->userq_funcs[queue->queue_type];int r; +/* The reset changes the queue state and the MES is unusable meanwhile */ +guard (rwsem_read)(&adev->reset_domain->sem);if (queue->state ==AMDGPU_USERQ_STATE_UNMAPPED ) {trace_amdgpu_userq_state_start (queue);
@@ -769,12 +773,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)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);
Signature · 1 line
2.34.1
Re: [PATCH 6/8] drm/amdgpu/userq: wait for GPU reset before mapping or unmapping queues
Personally, I am not a big fan of C++ style constructor/destructor patterns in C because they execute hidden code under the hood and can mask what is actually happening during a return path. But i found already in many places in amdgpu usage of this macro ... The fix is solid and handles the race condition properly.
Quoted 63 lines · Prike Liang
The user queue map and unmap helpers talk to the MES, but only the create path holds
reset_domain->semaround them. The eviction, restore, destroy and suspend paths can submit to the MES while a GPU reset is in progress:WARNING: amdgpu_device.c:928 at amdgpu_device_skip_hw_access+0x73/0x90 [amdgpu] Workqueue: events amdgpu_eviction_fence_suspend_worker [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_remove_hw_queue+0xd9/0x100 [amdgpu] mes_userq_unmap+0xc3/0x140 [amdgpu] amdgpu_userq_unmap_helper+0x67/0x280 [amdgpu] amdgpu_userq_evict+0x52/0xf0 [amdgpu] amdgpu_eviction_fence_suspend_worker+0x55/0xe0 [amdgpu]Take the semaphore for read in the helpers instead, around both the MES call and the queue state check and update. The reset changes the queue state from amdgpu_userq_pre_reset()/post_reset(), so every caller now waits for a running reset and acts on the state it left behind.
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4
-5@@ -362,6 +362,8 @@ static int amdgpu_userq_unmap_helper(struct amdgpu_usermode_queue *queue) adev->userq_funcs[queue->queue_type];int r; +/* The reset changes the queue state and the MES is unusable meanwhile */ +guard (rwsem_read)(&adev->reset_domain->sem);if ((queue->state ==AMDGPU_USERQ_STATE_MAPPED ) || (queue->state ==AMDGPU_USERQ_STATE_PREEMPTED )) {trace_amdgpu_userq_state_start (queue);@@ -388,6 +390,8 @@ static int amdgpu_userq_map_helper(struct amdgpu_usermode_queue *queue) adev->userq_funcs[queue->queue_type];int r; +/* The reset changes the queue state and the MES is unusable meanwhile */ +guard (rwsem_read)(&adev->reset_domain->sem);if (queue->state ==AMDGPU_USERQ_STATE_UNMAPPED ) {trace_amdgpu_userq_state_start (queue);@@ -769,12 +773,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)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);
PATCH 7/8 drm/amdgpu: stop the schedulers before preparing the GPU reset
In reply to Prike Liangamdgpu_device_halt_activities() only stops the ring schedulers after amdgpu_amdkfd_pre_reset() and amdgpu_userq_pre_reset(). With a hung MES every REMOVE_QUEUE in amdgpu_userq_pre_reset() waits for its timeout, so the schedulers keep pushing jobs to the hardware for seconds after the reset has started:
GPU reset begin!. Source: 6
MES failed to respond to msg=REMOVE_QUEUE fence_wait_ret=528494 status=0x0
WARNING: amdgpu_device.c:928 at amdgpu_device_skip_hw_access+0x73/0x90 [amdgpu] Workqueue: sdma0 drm_sched_run_job_work [gpu_sched] Call Trace: amdgpu_mm_wdoorbell64+0x20/0x70 [amdgpu] sdma_v6_0_ring_set_wptr+0xa6/0x180 [amdgpu] amdgpu_ring_commit+0x5b/0xa0 [amdgpu] amdgpu_ib_schedule+0x64a/0x8f0 [amdgpu] amdgpu_job_run+0xa2/0x220 [amdgpu] drm_sched_run_job_work+0x10c/0x300 [gpu_sched]
Stop the schedulers of all devices in the reset list first. None of the preparation steps needs them, and jobs submitted meanwhile simply wait until amdgpu_device_sched_resume().
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +15 -13
@@ -5534,7 +5534,21 @@ static void amdgpu_device_halt_activities(struct amdgpu_device *adev,struct amdgpu_device *tmp_adev =NULL ;int i; -/* block all schedulers and reset given job's ring */ +/* Stop job submission first, the preparation below can take seconds */ +list_for_each_entry (tmp_adev, device_list, reset_list) { +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { +struct amdgpu_ring *ring = tmp_adev->rings[i]; + +if (!amdgpu_ring_sched_ready (ring)) +continue ; + +drm_sched_wqueue_stop (&ring->sched); + +if (need_emergency_restart) +amdgpu_job_stop_all_jobs_on_sched (&ring->sched); + } + } +list_for_each_entry (tmp_adev, device_list, reset_list) {amdgpu_device_set_mp1_state (tmp_adev);
@@ -5570,18 +5584,6 @@ static void amdgpu_device_halt_activities(struct amdgpu_device *adev,amdgpu_ras_suspend (tmp_adev);amdgpu_userq_pre_reset (tmp_adev); - -for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { -struct amdgpu_ring *ring = tmp_adev->rings[i]; - -if (!amdgpu_ring_sched_ready (ring)) -continue ; - -drm_sched_wqueue_stop (&ring->sched); - -if (need_emergency_restart) -amdgpu_job_stop_all_jobs_on_sched (&ring->sched); - }atomic_inc (&tmp_adev->gpu_reset_counter); } }
Signature · 1 line
2.34.1
Re: [PATCH 7/8] drm/amdgpu: stop the schedulers before preparing the GPU reset
Quoted 18 lines · Prike Liang
amdgpu_device_halt_activities()only stops the ring schedulers afteramdgpu_amdkfd_pre_reset()andamdgpu_userq_pre_reset(). With a hung MES everyREMOVE_QUEUEinamdgpu_userq_pre_reset()waits for its timeout, so the schedulers keep pushing jobs to the hardware for seconds after the reset has started:GPU reset begin!. Source: 6 MES failed to respond to msg=REMOVE_QUEUE fence_wait_ret=528494 status=0x0 WARNING: amdgpu_device.c:928 at amdgpu_device_skip_hw_access+0x73/0x90 [amdgpu] Workqueue: sdma0 drm_sched_run_job_work [gpu_sched] Call Trace: amdgpu_mm_wdoorbell64+0x20/0x70 [amdgpu] sdma_v6_0_ring_set_wptr+0xa6/0x180 [amdgpu] amdgpu_ring_commit+0x5b/0xa0 [amdgpu] amdgpu_ib_schedule+0x64a/0x8f0 [amdgpu] amdgpu_job_run+0xa2/0x220 [amdgpu] drm_sched_run_job_work+0x10c/0x300 [gpu_sched]
Quoted 6 lines
Stop the schedulers of all devices in the reset list first. None of the preparation steps needs them, and jobs submitted meanwhile simply wait until
amdgpu_device_sched_resume().Fixes 290f46cf5726 ("drm/amdgpu: Implement user queue reset functionality")Signed-off-by Prike Liang <[email protected]>
Same question as before - should we keep memory management related rings running till user queues are stopped?
Thanks,
Lijo
Quoted 50 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +15
-13@@ -5534,7 +5534,21 @@ static void amdgpu_device_halt_activities(struct amdgpu_device *adev,struct amdgpu_device *tmp_adev =NULL ;int i; -/* block all schedulers and reset given job's ring */ +/* Stop job submission first, the preparation below can take seconds */ +list_for_each_entry (tmp_adev, device_list, reset_list) { +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { +struct amdgpu_ring *ring = tmp_adev->rings[i]; + +if (!amdgpu_ring_sched_ready (ring)) +continue ; + +drm_sched_wqueue_stop (&ring->sched); + +if (need_emergency_restart) +amdgpu_job_stop_all_jobs_on_sched (&ring->sched); + } + } +list_for_each_entry (tmp_adev, device_list, reset_list) {amdgpu_device_set_mp1_state (tmp_adev);@@ -5570,18 +5584,6 @@ static void amdgpu_device_halt_activities(struct amdgpu_device *adev,amdgpu_ras_suspend (tmp_adev);amdgpu_userq_pre_reset (tmp_adev); - -for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { -struct amdgpu_ring *ring = tmp_adev->rings[i]; - -if (!amdgpu_ring_sched_ready (ring)) -continue ; - -drm_sched_wqueue_stop (&ring->sched); - -if (need_emergency_restart) -amdgpu_job_stop_all_jobs_on_sched (&ring->sched); - }atomic_inc (&tmp_adev->gpu_reset_counter); } }
RE: [PATCH 7/8] drm/amdgpu: stop the schedulers before preparing the GPU reset
AMD General
Regards,
Prike
Quoted 36 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 23, 2026 5:30 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH 7/8] drm/amdgpu: stop the schedulers before preparing the GPU resetQuoted 8 lines · Prike Liang
amdgpu_device_halt_activities()only stops the ring schedulers afteramdgpu_amdkfd_pre_reset()andamdgpu_userq_pre_reset(). With a hung MES everyREMOVE_QUEUEinamdgpu_userq_pre_reset()waits for its timeout, so the schedulers keep pushing jobs to the hardware for seconds after the reset has started:GPU reset begin!. Source: 6
MES failed to respond to msg=REMOVE_QUEUE fence_wait_ret=528494status=0x0
Quoted 1 line
WARNING: amdgpu_device.c:928 at
amdgpu_device_skip_hw_access+0x73/0x90[amdgpu]Quoted 13 lines
Workqueue: sdma0 drm_sched_run_job_work [gpu_sched] Call Trace: amdgpu_mm_wdoorbell64+0x20/0x70 [amdgpu] sdma_v6_0_ring_set_wptr+0xa6/0x180 [amdgpu] amdgpu_ring_commit+0x5b/0xa0 [amdgpu] amdgpu_ib_schedule+0x64a/0x8f0 [amdgpu] amdgpu_job_run+0xa2/0x220 [amdgpu] drm_sched_run_job_work+0x10c/0x300 [gpu_sched]Stop the schedulers of all devices in the reset list first. None of the preparation steps needs them, and jobs submitted meanwhile simply wait until
amdgpu_device_sched_resume().
Quoted 6 lines
Quoted 3 lines
Fixes 290f46cf5726 ("drm/amdgpu: Implement user queue resetfunctionality")
Signed-off-by Prike Liang <[email protected]>Same question as before - should we keep memory management related rings running till user queues are stopped?
As to the gfx userq + kernel sdma then if keeping the drm scheduler and related ring keep running until stopping userq, then there will have a register accessing fault caused by the inflight submission during gpu recovery period.
Quoted 56 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_device_halt_activities(struct
Quoted 10 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -5534,7 +5534,21 @@ static void amdgpu_device_halt_activities(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_device_halt_activities(struct
Quoted 23 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +15
-1struct amdgpu_device *tmp_adev =NULL ;int i; -/* block all schedulers and reset given job's ring */ +/* Stop job submission first, the preparation below can take seconds */ +list_for_each_entry (tmp_adev, device_list, reset_list) { +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { +struct amdgpu_ring *ring = tmp_adev->rings[i]; + +if (!amdgpu_ring_sched_ready (ring)) +continue ; + +drm_sched_wqueue_stop (&ring->sched); + +if (need_emergency_restart) +amdgpu_job_stop_all_jobs_on_sched (&ring->sched); + } + } +list_for_each_entry (tmp_adev, device_list, reset_list) {amdgpu_device_set_mp1_state (tmp_adev);@@ -5570,18 +5584,6 @@ static void amdgpu_device_halt_activities(struct
amdgpu_device*adev,Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-12amdgpu_ras_suspend (tmp_adev);amdgpu_userq_pre_reset (tmp_adev); - -for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { -struct amdgpu_ring *ring = tmp_adev->rings[i]; - -if (!amdgpu_ring_sched_ready (ring)) -continue ; - -drm_sched_wqueue_stop (&ring->sched); - -if (need_emergency_restart) -amdgpu_job_stop_all_jobs_on_sched (&ring->sched); - }atomic_inc (&tmp_adev->gpu_reset_counter); } }
Lazar, Lijo
Acked-byRe: [PATCH 7/8] drm/amdgpu: stop the schedulers before preparing the GPU reset
Quoted 41 lines · Prike
AMD General
Regards,
PrikeQuoted 36 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 23, 2026 5:30 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH 7/8] drm/amdgpu: stop the schedulers before preparing the GPU resetQuoted 8 lines · Prike Liang
amdgpu_device_halt_activities()only stops the ring schedulers afteramdgpu_amdkfd_pre_reset()andamdgpu_userq_pre_reset(). With a hung MES everyREMOVE_QUEUEinamdgpu_userq_pre_reset()waits for its timeout, so the schedulers keep pushing jobs to the hardware for seconds after the reset has started:GPU reset begin!. Source: 6
MES failed to respond to msg=REMOVE_QUEUE fence_wait_ret=528494status=0x0
Quoted 1 line
WARNING: amdgpu_device.c:928 at
amdgpu_device_skip_hw_access+0x73/0x90[amdgpu]Quoted 13 lines
Workqueue: sdma0 drm_sched_run_job_work [gpu_sched] Call Trace: amdgpu_mm_wdoorbell64+0x20/0x70 [amdgpu] sdma_v6_0_ring_set_wptr+0xa6/0x180 [amdgpu] amdgpu_ring_commit+0x5b/0xa0 [amdgpu] amdgpu_ib_schedule+0x64a/0x8f0 [amdgpu] amdgpu_job_run+0xa2/0x220 [amdgpu] drm_sched_run_job_work+0x10c/0x300 [gpu_sched]Stop the schedulers of all devices in the reset list first. None of the preparation steps needs them, and jobs submitted meanwhile simply wait until
amdgpu_device_sched_resume().
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Fixes 290f46cf5726 ("drm/amdgpu: Implement user queue resetfunctionality")
Signed-off-by Prike Liang <[email protected]>Same question as before - should we keep memory management related rings running till user queues are stopped?
As to the gfx userq + kernel sdma then if keeping the drm scheduler and related ring keep running until stopping userq, then there will have a register accessing fault caused by the inflight submission during gpu recovery period.
Thanks,
Lijo
Quoted 57 lines
Quoted 56 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_device_halt_activities(struct
Quoted 10 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -5534,7 +5534,21 @@ static void amdgpu_device_halt_activities(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_device.c static void amdgpu_device_halt_activities(struct
Quoted 23 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +15
-1struct amdgpu_device *tmp_adev =NULL ;int i; -/* block all schedulers and reset given job's ring */ +/* Stop job submission first, the preparation below can take seconds */ +list_for_each_entry (tmp_adev, device_list, reset_list) { +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { +struct amdgpu_ring *ring = tmp_adev->rings[i]; + +if (!amdgpu_ring_sched_ready (ring)) +continue ; + +drm_sched_wqueue_stop (&ring->sched); + +if (need_emergency_restart) +amdgpu_job_stop_all_jobs_on_sched (&ring->sched); + } + } +list_for_each_entry (tmp_adev, device_list, reset_list) {amdgpu_device_set_mp1_state (tmp_adev);@@ -5570,18 +5584,6 @@ static void amdgpu_device_halt_activities(struct
amdgpu_device*adev,Quoted 18 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-12amdgpu_ras_suspend (tmp_adev);amdgpu_userq_pre_reset (tmp_adev); - -for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { -struct amdgpu_ring *ring = tmp_adev->rings[i]; - -if (!amdgpu_ring_sched_ready (ring)) -continue ; - -drm_sched_wqueue_stop (&ring->sched); - -if (need_emergency_restart) -amdgpu_job_stop_all_jobs_on_sched (&ring->sched); - }atomic_inc (&tmp_adev->gpu_reset_counter); } }
PATCH 8/8 drm/amdgpu/gmc11: don't access the fault registers during GPU reset
In reply to Prike LiangIH1 and IH2 are processed from a work item, so a VM fault delivered there can read and write the VM L2 fault registers while a GPU reset is running:
WARNING: amdgpu_device.c:928 at amdgpu_device_skip_hw_access+0x73/0x90 [amdgpu] Workqueue: events amdgpu_irq_handle_ih1 [amdgpu] Call Trace: amdgpu_device_rreg+0x21/0x50 [amdgpu] gmc_v11_0_process_interrupt+0x241/0x250 [amdgpu] amdgpu_irq_dispatch+0x12d/0x2f0 [amdgpu] amdgpu_ih_process+0x70/0x190 [amdgpu] amdgpu_irq_handle_ih1+0x23/0x30 [amdgpu]
Trylock reset_domain->sem around the register access when running in task context instead, and only print the fault when that fails. The semaphore is held just for the register access, so the reset never waits for the fault handling. The hard IRQ path for IH0 is unchanged, the IH is disabled before the ASIC reset.
--- drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +13 -1
@@ -108,6 +108,7 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev, AMDGPU_GMC9_FAULT_SOURCE_DATA_RETRY);bool write_fault = !!(entry->src_data[1 ] &AMDGPU_GMC9_FAULT_SOURCE_DATA_WRITE ); +bool read_status = !amdgpu_sriov_vf (adev);uint32_t status =0 ;uint32_t cam_index;u64 addr;
@@ -125,7 +126,15 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev,return 1 ; } -if (!amdgpu_sriov_vf (adev)) { +/* +* IH1/IH2 are processed from a work item, don't touch the registers +* while a GPU reset is running there. +*/ +if (read_status &&in_task () && + !down_read_trylock (&adev->reset_domain->sem)) + read_status = false; + +if (read_status) {/* * Issue a dummy read to wait for the status register to * be updated to avoid reading an incorrect value due to
@@ -137,6 +146,9 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev, status =RREG32 (hub->vm_l2_pro_fault_status);WREG32_P (hub->vm_l2_pro_fault_cntl,1 , ~1 ); +if (in_task ()) +up_read (&adev->reset_domain->sem); +amdgpu_vm_update_fault_cache (adev, entry->pasid, addr, status, entry->vmid_src ?AMDGPU_MMHUB0 (0 ) :AMDGPU_GFXHUB (0 )); }
Signature · 1 line
2.34.1
Re: [PATCH 8/8] drm/amdgpu/gmc11: don't access the fault registers during GPU reset
Preventing register access during a GPU reset via |down_read_trylock()| within the |in_task()| is a clean way to avoid the hardware access warnings.
Quoted 63 lines · Prike Liang
IH1 and IH2 are processed from a work item, so a VM fault delivered there can read and write the VM L2 fault registers while a GPU reset is running:
WARNING: amdgpu_device.c:928 at amdgpu_device_skip_hw_access+0x73/0x90 [amdgpu] Workqueue: events amdgpu_irq_handle_ih1 [amdgpu] Call Trace: amdgpu_device_rreg+0x21/0x50 [amdgpu] gmc_v11_0_process_interrupt+0x241/0x250 [amdgpu] amdgpu_irq_dispatch+0x12d/0x2f0 [amdgpu] amdgpu_ih_process+0x70/0x190 [amdgpu] amdgpu_irq_handle_ih1+0x23/0x30 [amdgpu]Trylock
reset_domain->semaround the register access when running in task context instead, and only print the fault when that fails. The semaphore is held just for the register access, so the reset never waits for the fault handling. The hard IRQ path for IH0 is unchanged, the IH is disabled before the ASIC reset.Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +13
-1@@ -108,6 +108,7 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev, AMDGPU_GMC9_FAULT_SOURCE_DATA_RETRY);bool write_fault = !!(entry->src_data[1 ] &AMDGPU_GMC9_FAULT_SOURCE_DATA_WRITE ); +bool read_status = !amdgpu_sriov_vf (adev);uint32_t status =0 ;uint32_t cam_index;u64 addr;@@ -125,7 +126,15 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev,return 1 ; } -if (!amdgpu_sriov_vf (adev)) { +/* +* IH1/IH2 are processed from a work item, don't touch the registers +* while a GPU reset is running there. +*/ +if (read_status &&in_task () && + !down_read_trylock (&adev->reset_domain->sem)) + read_status = false; + +if (read_status) {/* * Issue a dummy read to wait for the status register to * be updated to avoid reading an incorrect value due to @@ -137,6 +146,9 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev, status =RREG32 (hub->vm_l2_pro_fault_status);WREG32_P (hub->vm_l2_pro_fault_cntl,1 , ~1 ); +if (in_task ()) +up_read (&adev->reset_domain->sem); +amdgpu_vm_update_fault_cache (adev, entry->pasid, addr, status, entry->vmid_src ?AMDGPU_MMHUB0 (0 ) :AMDGPU_GFXHUB (0 )); }
Christian König
maintainerRe: [PATCH 8/8] drm/amdgpu/gmc11: don't access the fault registers during GPU reset
I think we need to take a step further and prevent interrupt processing from the workers while in the GPU reset.
So in amdgpu_irq_handle_ih1(), amdgpu_irq_handle_ih2() and amdgpu_irq_handle_ih_soft() we should do a down_read()/up_read() while calling the amdgpu_ih_process() function.
That should also cover this case here as well since in_task() is only true through one of those call paths.
Regards,
Christian.
Quoted 68 lines · vitaly prosyak
Preventing register access during a GPU reset via |down_read_trylock()| within the |in_task()| is a clean way to avoid the hardware access warnings.
Reviewed-by [email protected]Quoted 63 lines · Prike Liang
IH1 and IH2 are processed from a work item, so a VM fault delivered there can read and write the VM L2 fault registers while a GPU reset is running:
WARNING: amdgpu_device.c:928 at amdgpu_device_skip_hw_access+0x73/0x90 [amdgpu] Workqueue: events amdgpu_irq_handle_ih1 [amdgpu] Call Trace: amdgpu_device_rreg+0x21/0x50 [amdgpu] gmc_v11_0_process_interrupt+0x241/0x250 [amdgpu] amdgpu_irq_dispatch+0x12d/0x2f0 [amdgpu] amdgpu_ih_process+0x70/0x190 [amdgpu] amdgpu_irq_handle_ih1+0x23/0x30 [amdgpu]Trylock
reset_domain->semaround the register access when running in task context instead, and only print the fault when that fails. The semaphore is held just for the register access, so the reset never waits for the fault handling. The hard IRQ path for IH0 is unchanged, the IH is disabled before the ASIC reset.Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +13
-1@@ -108,6 +108,7 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev, AMDGPU_GMC9_FAULT_SOURCE_DATA_RETRY);bool write_fault = !!(entry->src_data[1 ] &AMDGPU_GMC9_FAULT_SOURCE_DATA_WRITE ); +bool read_status = !amdgpu_sriov_vf (adev);uint32_t status =0 ;uint32_t cam_index;u64 addr;@@ -125,7 +126,15 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev,return 1 ; } -if (!amdgpu_sriov_vf (adev)) { +/* +* IH1/IH2 are processed from a work item, don't touch the registers +* while a GPU reset is running there. +*/ +if (read_status &&in_task () && + !down_read_trylock (&adev->reset_domain->sem)) + read_status = false; + +if (read_status) {/* * Issue a dummy read to wait for the status register to * be updated to avoid reading an incorrect value due to @@ -137,6 +146,9 @@ static int gmc_v11_0_process_interrupt(struct amdgpu_device *adev, status =RREG32 (hub->vm_l2_pro_fault_status);WREG32_P (hub->vm_l2_pro_fault_cntl,1 , ~1 ); +if (in_task ()) +up_read (&adev->reset_domain->sem); +amdgpu_vm_update_fault_cache (adev, entry->pasid, addr, status, entry->vmid_src ?AMDGPU_MMHUB0 (0 ) :AMDGPU_GFXHUB (0 )); }
AMD General
Adding Mario for his insight on moving drm_mode_config_helper_suspend()/ resume() out of GPU recovery, where they block waiting and allocate reclaim under reset_domain->sem and can deadlock with userq_mutex.
Regards,
Prike
Quoted 115 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Friday, October 23, 2026 4:34 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>; Li, Sun peng (Leo) <[email protected]>
Subject: [PATCH 1/8] drm/amdgpu: save VKMS modeset state from the system PM path onlyamdgpu_vkms_suspend()/resume() are IP block callbacks shared by system suspend/resume and GPU recovery. Calling
drm_mode_config_helper_suspend()anddrm_mode_config_helper_resume()from them makes GPU recovery takeclientlist_mutexand the modeset locks and duplicate the atomic state while holdingreset_domain->sem. Lockdep reports:Chain exists of: &dev->clientlist_mutex --> &userq_mgr->userq_mutex --> &reset_domain->semVKMS has no hardware state that a reset can lose, so the reset path never needs these helpers. Call them from amdgpu_device_suspend()/resume() instead and leave the IP callbacks with only the hardware init.
Signed-off-by Prike Liang <[email protected]>Cc Sun peng Li (Leo) <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 14 +------------- 2 files changed, 19 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8
-1@@ -4568,9 +4568,16 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)amdgpu_ras_suspend (adev ); +/* VKMS modeset state is saved here, never from the reset path */ +if (adev->enable_virtual_display) { + r =drm_mode_config_helper_suspend (dev); +if (r) + goto unwind_smartshift; + } + r =amdgpu_device_ip_suspend_phase1 (adev);if (r) - goto unwind_smartshift; + goto unwind_vkms; amdgpu_amdkfd_suspend(adev, !amdgpu_sriov_vf(adev) && !adev-Quoted 1 line
in_runpm);r = amdgpu_userq_suspend(adev);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0@@ -4618,6 +4625,10 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)return r; } +unwind_vkms: +if (adev->enable_virtual_display) +drm_mode_config_helper_resume (dev); + unwind_smartshift: rec =amdgpu_acpi_smart_shift_update (adev,AMDGPU_SS_DEV_D0 );if (rec) {drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6
-0@@ -4717,6 +4728,12 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients) goto exit; } +if (adev->enable_virtual_display) { + r =drm_mode_config_helper_resume (dev); +if (r) + goto exit; + } + r =amdgpu_amdkfd_resume (adev, !amdgpu_sriov_vf (adev) && !adev- >in_runpm);if (r) goto exit;drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +1
-14@@ -488,24 +488,12 @@ static int amdgpu_vkms_hw_fini(struct amdgpu_ip_block *ip_block)static int amdgpu_vkms_suspend (struct amdgpu_ip_block *ip_block) { -struct amdgpu_device *adev = ip_block->adev; -int r; - - r =drm_mode_config_helper_suspend (adev_to_drm (adev)); -if (r) -return r; -return 0 ; }static int amdgpu_vkms_resume (struct amdgpu_ip_block *ip_block) { -int r; - - r =amdgpu_vkms_hw_init (ip_block); -if (r) -return r; -return drm_mode_config_helper_resume (adev_to_drm (ip_block->adev)); +return amdgpu_vkms_hw_init (ip_block); } static int amdgpu_vkms_set_clockgating_state(struct amdgpu_ip_block *ip_block, --2.34.1
Mario Limonciello
Reviewed-byQuoted 32 lines · Prike
AMD General
Adding Mario for his insight on moving drm_mode_config_helper_suspend()/
resume()out of GPU recovery, where they block waiting and allocate reclaim underreset_domain->semand can deadlock withuserq_mutex.Regards,
PrikeQuoted 23 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Friday, October 23, 2026 4:34 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>; Li, Sun peng (Leo) <[email protected]>
Subject: [PATCH 1/8] drm/amdgpu: save VKMS modeset state from the system PM path onlyamdgpu_vkms_suspend()/resume() are IP block callbacks shared by system suspend/resume and GPU recovery. Calling
drm_mode_config_helper_suspend()anddrm_mode_config_helper_resume()from them makes GPU recovery takeclientlist_mutexand the modeset locks and duplicate the atomic state while holdingreset_domain->sem. Lockdep reports:Chain exists of: &dev->clientlist_mutex --> &userq_mgr->userq_mutex --> &reset_domain->semVKMS has no hardware state that a reset can lose, so the reset path never needs these helpers. Call them from amdgpu_device_suspend()/resume() instead and leave the IP callbacks with only the hardware init.
As you mentioned when pinging me there is the reclaim/fence reasoning too. It would be good to include both in the commit message as well.
I definitely don't think we need all those blocking helpers in the GPU recovery path at all.
From me this patch looks good.
I do have a small nit below (feel free to fix while committing).
Quoted 67 lines
Quoted 67 lines
Signed-off-by Prike Liang <[email protected]>Cc Sun peng Li (Leo) <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 14 +------------- 2 files changed, 19 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8
-1@@ -4568,9 +4568,16 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)amdgpu_ras_suspend (adev ); +/* VKMS modeset state is saved here, never from the reset path */ +if (adev->enable_virtual_display) { + r =drm_mode_config_helper_suspend (dev); +if (r) + goto unwind_smartshift; + } + r =amdgpu_device_ip_suspend_phase1 (adev);if (r) - goto unwind_smartshift; + goto unwind_vkms;Quoted 2 lines
Quoted 1 line
amdgpu_amdkfd_suspend(adev, !amdgpu_sriov_vf(adev) && !adev-
in_runpm);r = amdgpu_userq_suspend(adev);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0@@ -4618,6 +4625,10 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)return r; } +unwind_vkms: +if (adev->enable_virtual_display) +drm_mode_config_helper_resume (dev); + unwind_smartshift: rec =amdgpu_acpi_smart_shift_update (adev,AMDGPU_SS_DEV_D0 );if (rec) {drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6
-0@@ -4717,6 +4728,12 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients) goto exit; } +if (adev->enable_virtual_display) { + r =drm_mode_config_helper_resume (dev); +if (r) + goto exit; + } + r =amdgpu_amdkfd_resume (adev, !amdgpu_sriov_vf (adev) && !adev- > in_runpm);if (r) goto exit;drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +0
-0@@ -488,24 +488,12 @@ static int amdgpu_vkms_hw_fini(struct amdgpu_ip_block *ip_block)
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c static int amdgpu_vkms_hw_fini(struct amdgpu_ip_block *ip_block) · line 492
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +0
-7static int amdgpu_vkms_suspend (struct amdgpu_ip_block *ip_block) { -struct amdgpu_device *adev = ip_block->adev; -int r; - - r =drm_mode_config_helper_suspend (adev_to_drm (adev)); -if (r) -return r; -return 0 ; }
With these changes I would suggest you just drop the callback/function entirely from amdgpu_vkms_ip_funcs since the function just returns 0 now.
.suspend = amdgpu_vkms_suspend,
Quoted 15 lines
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +1
-7static int amdgpu_vkms_resume (struct amdgpu_ip_block *ip_block) { -int r; - - r =amdgpu_vkms_hw_init (ip_block); -if (r) -return r; -return drm_mode_config_helper_resume (adev_to_drm (ip_block->adev)); +return amdgpu_vkms_hw_init (ip_block); } static int amdgpu_vkms_set_clockgating_state(struct amdgpu_ip_block *ip_block, --2.34.1
AMD General
Regards,
Prike
Quoted 46 lines
-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Friday, October 30, 2026 3:28 AM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Li, Sun peng (Leo) <[email protected]>
Subject: Re: [PATCH 1/8] drm/amdgpu: save VKMS modeset state from the system PM path onlyQuoted 27 lines · Prike
AMD General
Adding Mario for his insight on moving drm_mode_config_helper_suspend()/
resume()out of GPU recovery, where they block waiting and allocate reclaim underreset_domain->semand can deadlock withuserq_mutex.Regards,
PrikeQuoted 17 lines
-----Original Message-----
From: Liang, Prike <[email protected]>
Sent: Friday, October 23, 2026 4:34 PM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Lazar, Lijo <[email protected]>; Prosyak, Vitaly <[email protected]>; Liang, Prike <[email protected]>; Li, Sun peng
(Leo) <[email protected]>
Subject: [PATCH 1/8] drm/amdgpu: save VKMS modeset state from the system PM path onlyamdgpu_vkms_suspend()/resume() are IP block callbacks shared by system suspend/resume and GPU recovery. Calling
drm_mode_config_helper_suspend()anddrm_mode_config_helper_resume()from them makes GPU recovery takeclientlist_mutexand the modeset locks and duplicate the atomic state while holdingreset_domain->sem. Lockdepreports:
Quoted 5 lines
Quoted 5 lines
Chain exists of: &dev->clientlist_mutex --> &userq_mgr->userq_mutex -->
&reset_domain->sem
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
VKMS has no hardware state that a reset can lose, so the reset path never needs these helpers. Call them from amdgpu_device_suspend()/resume() instead and leave the IP callbacks with only
the hardware init.
As you mentioned when pinging me there is the reclaim/fence reasoning too. It would be good to include both in the commit message as well.
Yeah, will include that analysis in the commit log.
Quoted 77 lines
I definitely don't think we need all those blocking helpers in the GPU recovery path at all.
From me this patch looks good.
Reviewed-by Mario Limonciello <[email protected]>I do have a small nit below (feel free to fix while committing).
Quoted 68 lines
Quoted 68 lines
Signed-off-by Prike Liang <[email protected]>Cc Sun peng Li (Leo) <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 19 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c | 14 +------------- 2 files changed, 19 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8
-1@@ -4568,9 +4568,16 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)amdgpu_ras_suspend (adev); +/* VKMS modeset state is saved here, never from the reset path */ +if (adev->enable_virtual_display) { + r =drm_mode_config_helper_suspend (dev); +if (r) + goto unwind_smartshift; + } + r =amdgpu_device_ip_suspend_phase1 (adev);if (r) - goto unwind_smartshift; + goto unwind_vkms;Quoted 2 lines
Quoted 1 line
amdgpu_amdkfd_suspend(adev, !amdgpu_sriov_vf(adev) && !adev-
in_runpm);r = amdgpu_userq_suspend(adev); @@ -4618,6 +4625,10 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients) return r; }drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10
-0+unwind_vkms: +if (adev->enable_virtual_display) +drm_mode_config_helper_resume (dev); + unwind_smartshift: rec =amdgpu_acpi_smart_shift_update (adev,AMDGPU_SS_DEV_D0 );if (rec) {@@ -4717,6 +4728,12 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients) goto exit; } +if (adev->enable_virtual_display) { + r =drm_mode_config_helper_resume (dev); +if (r) + goto exit; + } + r = amdgpu_amdkfd_resume(adev, !amdgpu_sriov_vf(adev) &&!adev-
Quoted 1 line
in_runpm);if (r) goto exit;drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +0
-0@@ -488,24 +488,12 @@ static int amdgpu_vkms_hw_fini(struct
amdgpu_ip_block*ip_block)
Quoted 13 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c static int amdgpu_vkms_hw_fini(struct amdgpu_ip_block *ip_block) · line 492
Quoted 10 lines
static int amdgpu_vkms_suspend(struct amdgpu_ip_block *ip_block) {drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +0
-7-struct amdgpu_device *adev = ip_block->adev; -int r; - - r =drm_mode_config_helper_suspend (adev_to_drm (adev)); -if (r) -return r; -return 0 ; }With these changes I would suggest you just drop the callback/function entirely from
amdgpu_vkms_ip_funcssince the function just returns 0 now.
OK, will clean it up and before wants to keep it for paring the resume funcs.
Quoted 19 lines
.suspend =
amdgpu_vkms_suspend,Quoted 16 lines
Quoted 15 lines
static int amdgpu_vkms_resume(struct amdgpu_ip_block *ip_block) {drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c +1
-6-int r; - - r =amdgpu_vkms_hw_init (ip_block); -if (r) -return r; -return drm_mode_config_helper_resume (adev_to_drm (ip_block->adev)); +return amdgpu_vkms_hw_init (ip_block); } static int amdgpu_vkms_set_clockgating_state(struct amdgpu_ip_block
*ip_block,
--
2.34.1