drm/amdgpu: save VKMS modeset state from the system PM path only
Subsystems (2)
PATCH 1/9 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/9 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
PATCH 3/9 drm/amdgpu/mes: skip unmap queue notification during GPU reset
In reply to Prike Liangamdgpu_mes_userq_notify_unmap_work_handler() submits a MES misc op without holding reset_domain->sem, so it can ring the MES doorbell while the GPU is being reset:
WARNING: amdgpu_device.c:928 at amdgpu_device_skip_hw_access+0x73/0x90 [amdgpu] Workqueue: events amdgpu_mes_userq_notify_unmap_work_handler [amdgpu] Call Trace: amdgpu_mm_wdoorbell64+0x20/0x70 [amdgpu] mes_v11_0_ring_set_wptr+0x71/0x80 [amdgpu] amdgpu_ring_commit+0x5b/0xa0 [amdgpu] mes_v11_0_submit_pkt_and_poll_completion.constprop.0+0x207/0x520 [amdgpu] mes_v11_0_misc_op+0x8b/0x240 [amdgpu] amdgpu_mes_notify_unmap_queue+0xa3/0x110 [amdgpu] amdgpu_mes_userq_notify_unmap_work_handler+0x24/0x70 [amdgpu]
Only send the notification when reset_domain->sem can be trylocked. The work re-arms itself while the HW queues are oversubscribed, so the notification is retried once the reset has finished.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +5 -1
@@ -1191,7 +1191,11 @@ static void amdgpu_mes_userq_notify_unmap_work_handler(struct work_struct *work) userq_notify_unmap_work.work);struct amdgpu_device *adev = mes->adev; -amdgpu_mes_notify_unmap_queue (adev); +/* MES is unusable during GPU recovery; the re-arm below retries later */ +if (down_read_trylock (&adev->reset_domain->sem)) { +amdgpu_mes_notify_unmap_queue (adev); +up_read (&adev->reset_domain->sem); + }/* Re-arm if still oversubscribed */ if (atomic_read(&mes->userq_hw_queue_count) >
Signature · 1 line
2.34.1
Re: [PATCH 3/9] drm/amdgpu/mes: skip unmap queue notification during GPU reset
Quoted 15 lines · Prike Liang
amdgpu_mes_userq_notify_unmap_work_handler()submits a MES misc op without holdingreset_domain->sem, so it can ring the MES doorbell while the GPU is being reset:WARNING: amdgpu_device.c:928 at amdgpu_device_skip_hw_access+0x73/0x90 [amdgpu] Workqueue: events amdgpu_mes_userq_notify_unmap_work_handler [amdgpu] Call Trace: amdgpu_mm_wdoorbell64+0x20/0x70 [amdgpu] mes_v11_0_ring_set_wptr+0x71/0x80 [amdgpu] amdgpu_ring_commit+0x5b/0xa0 [amdgpu] mes_v11_0_submit_pkt_and_poll_completion.constprop.0+0x207/0x520 [amdgpu] mes_v11_0_misc_op+0x8b/0x240 [amdgpu] amdgpu_mes_notify_unmap_queue+0xa3/0x110 [amdgpu] amdgpu_mes_userq_notify_unmap_work_handler+0x24/0x70 [amdgpu]
Quoted 6 lines
Only send the notification when
reset_domain->semcan be trylocked. The work re-arms itself while the HW queues are oversubscribed, so the notification is retried once the reset has finished.Fixes a3e112968588 ("drm/amdgpu/userq: create the same workaround of oversubscription timer")Signed-off-by Prike Liang <[email protected]>
Quoted 22 lines
Cc Eric Huang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +5
-1@@ -1191,7 +1191,11 @@ static void amdgpu_mes_userq_notify_unmap_work_handler(struct work_struct *work) userq_notify_unmap_work.work);struct amdgpu_device *adev = mes->adev; -amdgpu_mes_notify_unmap_queue (adev); +/* MES is unusable during GPU recovery; the re-arm below retries later */ +if (down_read_trylock (&adev->reset_domain->sem)) { +amdgpu_mes_notify_unmap_queue (adev); +up_read (&adev->reset_domain->sem); + }/* Re-arm if still oversubscribed */ if (atomic_read(&mes->userq_hw_queue_count) >
PATCH 4/9 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
PATCH 5/9 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 6/9 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 run from GPU recovery as well as from system suspend and unload, 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, so no worker touches a block that has been shut down.
begin_use also runs in recovery for the IB tests, so it never waits. The worker now checks the submission count and gates the block under the power gating lock, so it can't gate the block behind a concurrent begin_use. sw_fini still 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 | 32 +++++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 35 +++++++++++++++++++----- 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, 76 insertions(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +25 -7
@@ -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 ;
@@ -97,7 +99,11 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev)int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +/* The 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);return 0 ; }
@@ -114,6 +120,14 @@ 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); + +mutex_lock (&adev->jpeg.jpeg_pg_lock); +/* Check submissions before fences so a concurrent end_use isn't missed */ +if (atomic_read_acquire (&adev->jpeg.total_submission_cnt)) + goto reschedule; +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;
@@ -122,13 +136,17 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work) fences +=amdgpu_fence_count_emitted (&adev->jpeg.inst[i].ring_dec[j]); } -if (!fences && !atomic_read (&adev->jpeg.total_submission_cnt)) { -mutex_lock (&adev->jpeg.jpeg_pg_lock); +if (!fences) {amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_JPEG ,AMD_PG_STATE_GATE ); -mutex_unlock (&adev->jpeg.jpeg_pg_lock); - }else -schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); + goto unlock; + } + +reschedule: +schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); +unlock: +mutex_unlock (&adev->jpeg.jpeg_pg_lock); +up_read (&adev->reset_domain->sem); }void amdgpu_jpeg_ring_begin_use (struct amdgpu_ring *ring)
@@ -136,7 +154,7 @@ void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)struct amdgpu_device *adev = ring->adev;if (!atomic_fetch_inc (&adev->jpeg.total_submission_cnt)) -cancel_delayed_work_sync (&adev->jpeg.idle_work); +cancel_delayed_work (&adev->jpeg.idle_work);mutex_lock (&adev->jpeg.jpeg_pg_lock); amdgpu_device_ip_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_JPEG,
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +28 -7
@@ -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,14 @@ 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); + +mutex_lock (&vcn_inst->vcn_pg_lock); +/* Check submissions before fences so a concurrent end_use isn't missed */ +if (atomic_read_acquire (&vcn_inst->total_submission_cnt)) + goto reschedule; +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] +=amdgpu_fence_count_emitted (&vcn_inst->ring_enc[j]);
@@ -490,15 +509,17 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) fence[i] +=amdgpu_fence_count_emitted (&vcn_inst->ring_dec); fences += fence[i]; -if (!fences && !atomic_read (&vcn_inst->total_submission_cnt)) { -mutex_lock (&vcn_inst->vcn_pg_lock); +if (!fences) { vcn_inst->set_pg_state (vcn_inst,AMD_PG_STATE_GATE ); -mutex_unlock (&vcn_inst->vcn_pg_lock);amdgpu_vcn_put_profile (adev); - - }else { -schedule_delayed_work (&vcn_inst->idle_work,VCN_IDLE_TIMEOUT ); + goto unlock; } + +reschedule: +schedule_delayed_work (&vcn_inst->idle_work,VCN_IDLE_TIMEOUT ); +unlock: +mutex_unlock (&vcn_inst->vcn_pg_lock); +up_read (&adev->reset_domain->sem); }void amdgpu_vcn_ring_begin_use (struct amdgpu_ring *ring)
@@ -507,7 +528,7 @@ void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)struct amdgpu_vcn_inst *vcn_inst = &adev->vcn.inst[ring->me];if (!atomic_fetch_inc (&vcn_inst->total_submission_cnt)) -cancel_delayed_work_sync (&vcn_inst->idle_work); +cancel_delayed_work (&vcn_inst->idle_work);mutex_lock (&vcn_inst->vcn_pg_lock); vcn_inst->set_pg_state (vcn_inst,AMD_PG_STATE_UNGATE );
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1 -0
@@ -526,6 +526,7 @@ int amdgpu_vcn_suspend(struct amdgpu_device *adev, int i);int amdgpu_vcn_resume (struct amdgpu_device *adev,int i);void amdgpu_vcn_ring_begin_use (struct amdgpu_ring *ring);void amdgpu_vcn_ring_end_use (struct amdgpu_ring *ring); +void amdgpu_vcn_cancel_idle_work (struct amdgpu_vcn_inst *vcn_inst);bool amdgpu_vcn_is_disabled_vcn (struct amdgpu_device *adev,enum vcn_ring_type type,uint32_t vcn_instance);
drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +1 -1
@@ -177,7 +177,7 @@ static int jpeg_v2_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE &&RREG32_SOC15 (JPEG ,0 , mmUVD_JRBC_STATUS))
drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +1 -1
@@ -239,7 +239,7 @@ static int jpeg_v2_5_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int i; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1 << i))
drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +1 -1
@@ -192,7 +192,7 @@ static int jpeg_v3_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE &&RREG32_SOC15 (JPEG ,0 , mmUVD_JRBC_STATUS))
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +1 -1
@@ -221,7 +221,7 @@ static int jpeg_v4_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (!amdgpu_sriov_vf (adev)) {if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE &&RREG32_SOC15 (JPEG ,0 , regUVD_JRBC_STATUS))
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +1 -1
@@ -455,7 +455,7 @@ static int jpeg_v4_0_3_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int ret =0 ; -cancel_delayed_work_sync (&adev->jpeg.idle_work); +amdgpu_jpeg_suspend (adev);if (!amdgpu_sriov_vf (adev)) {if (adev->jpeg.cur_state !=AMD_PG_STATE_GATE )
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +1 -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 6/9] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
Quoted 191 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 run from GPU recovery as well as from system suspend and unload, 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, so no worker touches a block that has been shut down.
begin_usealso runs in recovery for the IB tests, so it never waits. The worker now checks the submission count and gates the block under the power gating lock, so it can't gate the block behind a concurrentbegin_use.sw_finistill 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 | 32 +++++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 35 +++++++++++++++++++----- 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, 76 insertions(+), 36 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +25
-7@@ -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 ;@@ -97,7 +99,11 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev)int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +/* The 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);return 0 ; }@@ -114,6 +120,14 @@ 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); + +mutex_lock (&adev->jpeg.jpeg_pg_lock); +/* Check submissions before fences so a concurrent end_use isn't missed */ +if (atomic_read_acquire (&adev->jpeg.total_submission_cnt)) + goto reschedule; +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -122,13 +136,17 @@ static void amdgpu_jpeg_idle_work_handler(struct work_struct *work) fences +=amdgpu_fence_count_emitted (&adev->jpeg.inst[i].ring_dec[j]); } -if (!fences && !atomic_read (&adev->jpeg.total_submission_cnt)) { -mutex_lock (&adev->jpeg.jpeg_pg_lock); +if (!fences) {amdgpu_device_ip_set_powergating_state (adev,AMD_IP_BLOCK_TYPE_JPEG ,AMD_PG_STATE_GATE ); -mutex_unlock (&adev->jpeg.jpeg_pg_lock); - }else -schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); + goto unlock; + } + +reschedule: +schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); +unlock: +mutex_unlock (&adev->jpeg.jpeg_pg_lock); +up_read (&adev->reset_domain->sem); }void amdgpu_jpeg_ring_begin_use (struct amdgpu_ring *ring)@@ -136,7 +154,7 @@ void amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)struct amdgpu_device *adev = ring->adev;if (!atomic_fetch_inc (&adev->jpeg.total_submission_cnt)) -cancel_delayed_work_sync (&adev->jpeg.idle_work); +cancel_delayed_work (&adev->jpeg.idle_work);mutex_lock (&adev->jpeg.jpeg_pg_lock); amdgpu_device_ip_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_JPEG,drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +27
-6@@ -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,14 @@ 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); + +mutex_lock (&vcn_inst->vcn_pg_lock); +/* Check submissions before fences so a concurrent end_use isn't missed */ +if (atomic_read_acquire (&vcn_inst->total_submission_cnt)) + goto reschedule; +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] +=amdgpu_fence_count_emitted (&vcn_inst->ring_enc[j]);@@ -490,15 +509,17 @@ static void amdgpu_vcn_idle_work_handler(struct work_struct *work) fence[i] +=amdgpu_fence_count_emitted (&vcn_inst->ring_dec); fences += fence[i]; -if (!fences && !atomic_read (&vcn_inst->total_submission_cnt)) { -mutex_lock (&vcn_inst->vcn_pg_lock); +if (!fences) { vcn_inst->set_pg_state (vcn_inst,AMD_PG_STATE_GATE ); -mutex_unlock (&vcn_inst->vcn_pg_lock);amdgpu_vcn_put_profile (adev); - - }else { -schedule_delayed_work (&vcn_inst->idle_work,VCN_IDLE_TIMEOUT ); + goto unlock; } + +reschedule: +schedule_delayed_work (&vcn_inst->idle_work,VCN_IDLE_TIMEOUT ); +unlock: +mutex_unlock (&vcn_inst->vcn_pg_lock); +up_read (&adev->reset_domain->sem); }void amdgpu_vcn_ring_begin_use (struct amdgpu_ring *ring)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring) · line 531
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +1
-1@@ -507,7 +528,7 @@ void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring)struct amdgpu_vcn_inst *vcn_inst = &adev->vcn.inst[ring->me];if (!atomic_fetch_inc (&vcn_inst->total_submission_cnt)) -cancel_delayed_work_sync (&vcn_inst->idle_work); +cancel_delayed_work (&vcn_inst->idle_work);
I think calling amdgpu_vcn_cancel_idle_work is sufficient here. Other changes to idle worker other than down_read are not required.
Thanks,
Lijo
Quoted 279 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0mutex_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 6/9] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle work
AMD General
Regards,
Prike
Quoted 219 lines
-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Friday, October 23, 2026 2:46 PM
To: Liang, Prike <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Prosyak, Vitaly <[email protected]>
Subject: Re: [PATCH 6/9] drm/amdgpu: stop GPU recovery wait for the JPEG/VCN idle workQuoted 13 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 run from GPU recovery as well as from system suspend and unload, 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, so no worker touches a block that has been shut down.Quoted 8 lines
begin_usealso runs in recovery for the IB tests, so it never waits. The worker now checks the submission count and gates the block under the power gating lock, so it can't gate the block behind a concurrentbegin_use.sw_finistill cancels synchronously, it never runs with the reset semaphore held.Update versions:
https://lore.kernel.org/amd-gfx/PH7PR12MB6000698A62D208E47BB358D7FB662
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c static void amdgpu_jpeg_idle_work_handler(struct
Quoted 57 lines
@ PH7PR12MB6000.namprd12.prod.outlook.com/
Signed-off-by Prike Liang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 32 +++++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 35 +++++++++++++++++++----- 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, 76 insertions(+), 36 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +7
-1@@ -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 ;@@ -97,7 +99,11 @@ int amdgpu_jpeg_sw_fini(struct amdgpu_device *adev)int amdgpu_jpeg_suspend (struct amdgpu_device *adev) { -cancel_delayed_work_sync (&adev->jpeg.idle_work); +/* The 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);return 0 ; }@@ -114,6 +120,14 @@ static void amdgpu_jpeg_idle_work_handler(struct
work_struct*work)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c static void amdgpu_jpeg_idle_work_handler(struct
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +8
-0unsigned int fences =0 ;unsigned int i, j; +/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); + +mutex_lock (&adev->jpeg.jpeg_pg_lock); +/* Check submissions before fences so a concurrent end_use isn't missed */ +if (atomic_read_acquire (&adev->jpeg.total_submission_cnt)) + goto reschedule; +for (i =0 ; i < adev->jpeg.num_jpeg_inst; ++i) {if (adev->jpeg.harvest_config & (1U << i))continue ;@@ -122,13 +136,17 @@ static void amdgpu_jpeg_idle_work_handler(struct
work_struct*work)drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1
-2fences +=amdgpu_fence_count_emitted (&adev- jpeg.inst[i].ring_dec[j]); } -if (!fences && !atomic_read (&adev->jpeg.total_submission_cnt)) { -mutex_lock (&adev->jpeg.jpeg_pg_lock); +if (!fences) { amdgpu_device_ip_set_powergating_state(adev,
AMD_IP_BLOCK_TYPE_JPEG,drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c static void amdgpu_jpeg_idle_work_handler(struct work_struct *work)
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +0
-3AMD_PG_STATE_GATE); -mutex_unlock (&adev->jpeg.jpeg_pg_lock); - }else - schedule_delayed_work(&adev->jpeg.idle_work,
JPEG_IDLE_TIMEOUT);drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c void amdgpu_vcn_sw_fini(struct amdgpu_device *adev,
Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +8
-0+ goto unlock; + } + +reschedule: +schedule_delayed_work (&adev->jpeg.idle_work,JPEG_IDLE_TIMEOUT ); +unlock: +mutex_unlock (&adev->jpeg.jpeg_pg_lock); +up_read (&adev->reset_domain->sem); }void
amdgpu_jpeg_ring_begin_use(struct amdgpu_ring *ring)@@ -136,7
+154,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); +cancel_delayed_work (&adev->jpeg.idle_work);mutex_lock (&adev->jpeg.jpeg_pg_lock); amdgpu_device_ip_set_powergating_state(adev,
AMD_IP_BLOCK_TYPE_JPEG, diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c
index34e1242d66ea..fee6bea52e5e100644drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +0
-0@@ -269,6 +269,8 @@ void amdgpu_vcn_sw_fini(struct amdgpu_device *adev,int i)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c void amdgpu_vcn_put_profile(struct amdgpu_device
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +2
-0if (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)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c static void amdgpu_vcn_idle_work_handler(struct
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +8
-0mutex_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,14 @@ static void amdgpu_vcn_idle_work_handler(struct
work_struct*work)drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c static void amdgpu_vcn_idle_work_handler(struct
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +8
-0if (adev->vcn.harvest_config & (1 << i))return ; +/* Nothing holding the reset semaphore waits for this work */ +down_read (&adev->reset_domain->sem); + +mutex_lock (&vcn_inst->vcn_pg_lock); +/* Check submissions before fences so a concurrent end_use isn't missed */ +if (atomic_read_acquire (&vcn_inst->total_submission_cnt)) + goto reschedule; +for (j =0 ; j < adev->vcn.inst[i].num_enc_rings; ++j) fence[i] +=amdgpu_fence_count_emitted (&vcn_inst->ring_enc[j]);@@ -490,15 +509,17 @@ static void amdgpu_vcn_idle_work_handler(struct
work_struct*work)drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c static void amdgpu_vcn_idle_work_handler(struct work_struct *work)
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +1
-6fence[i] +=amdgpu_fence_count_emitted (&vcn_inst->ring_dec); fences += fence[i]; -if (!fences && !atomic_read (&vcn_inst->total_submission_cnt)) { -mutex_lock (&vcn_inst->vcn_pg_lock); +if (!fences) { vcn_inst->set_pg_state (vcn_inst,AMD_PG_STATE_GATE ); -mutex_unlock (&vcn_inst->vcn_pg_lock);amdgpu_vcn_put_profile (adev); - - }else { - schedule_delayed_work(&vcn_inst->idle_work,
VCN_IDLE_TIMEOUT);Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +8
-0+ goto unlock; } + +reschedule: +schedule_delayed_work (&vcn_inst->idle_work,VCN_IDLE_TIMEOUT ); +unlock: +mutex_unlock (&vcn_inst->vcn_pg_lock); +up_read (&adev->reset_domain->sem); } void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring) @@ -507,7 +528,7 @@ void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring) struct amdgpu_vcn_inst *vcn_inst = &adev->vcn.inst[ring->me];
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c void amdgpu_vcn_ring_begin_use(struct amdgpu_ring *ring) · line 531
Quoted 3 lines
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); +cancel_delayed_work (&vcn_inst->idle_work);I think calling
amdgpu_vcn_cancel_idle_workis sufficient here. Other changes to idle worker other thandown_readare not required.
Yeah, it's simpler and clearer and will address it in the following version.
Thanks,
Prike
Quoted 333 lines
Thanks,
Lijodrivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h int amdgpu_vcn_suspend(struct amdgpu_device *adev,
Quoted 9 lines
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.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);
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h int amdgpu_vcn_suspend(struct amdgpu_device *adev, int i);
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h +1
-0int 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 --git
drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c static int jpeg_v2_0_hw_fini(struct amdgpu_ip_block
Quoted 6 lines
a/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)drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c static int jpeg_v2_5_hw_fini(struct amdgpu_ip_block
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v2_0.c +1
-1{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)) 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)drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c static int jpeg_v3_0_hw_fini(struct amdgpu_ip_block
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v2_5.c +1
-1struct 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)) 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)drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c static int jpeg_v4_0_hw_fini(struct amdgpu_ip_block
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +1
-1{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)) 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)drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c static int jpeg_v4_0_hw_fini(struct amdgpu_ip_block *ip_block)
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0.c +1
-1{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)) diff --git
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c static int jpeg_v4_0_3_hw_fini(struct amdgpu_ip_block
Quoted 6 lines
a/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)drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c static int jpeg_v4_0_5_hw_fini(struct amdgpu_ip_block
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +1
-1struct 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) diff --git
a/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)drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c static int jpeg_v5_0_0_hw_fini(struct amdgpu_ip_block
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +1
-1struct 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)) 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)drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c static int jpeg_v5_0_1_hw_fini(struct amdgpu_ip_block
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +1
-1{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)) 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)drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c static int jpeg_v5_0_2_hw_fini(struct amdgpu_ip_block
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1
-1struct 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) diff --git
a/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)drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c static int jpeg_v5_3_0_hw_fini(struct amdgpu_ip_block
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_2.c +1
-1struct 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) diff --git
a/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)drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c static int jpeg_v5_3_0_hw_fini(struct amdgpu_ip_block *ip_block) · line 178
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/jpeg_v5_3_0.c +1
-1{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))diff
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c static int vcn_v1_0_sw_init(struct amdgpu_ip_block
Quoted 6 lines
--git
a/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)drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c static int vcn_v2_0_hw_fini(struct amdgpu_ip_block
Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/vcn_v1_0.c +3
-2if (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 +0
-0@@ -322,7 +322,7 @@ static int vcn_v2_0_hw_fini(struct amdgpu_ip_block
*ip_block)drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c static int vcn_v2_5_sw_init(struct amdgpu_ip_block
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +1
-1struct 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 && 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)drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c static int vcn_v3_0_hw_fini(struct amdgpu_ip_block
Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +3
-2if (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 +0
-0@@ -449,7 +449,7 @@ static int vcn_v3_0_hw_fini(struct amdgpu_ip_block
*ip_block)drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c static int vcn_v3_0_hw_fini(struct amdgpu_ip_block *ip_block)
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1
-1if (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) || diff--git
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c static int vcn_v4_0_hw_fini(struct amdgpu_ip_block
Quoted 6 lines
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)drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c static int vcn_v4_0_hw_fini(struct amdgpu_ip_block · line 380
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1
-1if (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) || diff--git
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c static int vcn_v4_0_3_hw_fini(struct amdgpu_ip_block
Quoted 6 lines
a/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.cb/drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c
index3f39aa83c319..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)drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c static int vcn_v4_0_5_hw_fini(struct amdgpu_ip_block
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1
-1for (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); diff --git
a/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)drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c static int vcn_v4_0_5_hw_fini(struct amdgpu_ip_block · line 333
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1
-1if (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) || diff--git
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c static int vcn_v5_0_0_hw_fini(struct amdgpu_ip_block
Quoted 6 lines
a/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c
index7b7c3bc9f046..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)drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c static int vcn_v5_0_0_hw_fini(struct amdgpu_ip_block · line 297
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1
-1if (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) || diff--git
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c static int vcn_v5_0_1_hw_fini(struct amdgpu_ip_block
Quoted 6 lines
a/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.cb/drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c
indexc9e990ab297d..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)drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c static int vcn_v5_0_2_hw_fini(struct amdgpu_ip_block
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +1
-1for (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 +0
-0@@ -279,7 +279,7 @@ static int vcn_v5_0_2_hw_fini(struct amdgpu_ip_block
*ip_block)Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_2.c +1
-1for (i =0 ; i < adev->vcn.num_vcn_inst; ++i) {struct amdgpu_vcn_inst *vinst = &adev->vcn.inst[i]; -cancel_delayed_work_sync (&adev->vcn.inst[i].idle_work); +amdgpu_vcn_cancel_idle_work (&adev->vcn.inst[i]);if (vinst->cur_state !=AMD_PG_STATE_GATE ) vinst->set_pg_state (vinst,AMD_PG_STATE_GATE ); }
PATCH 7/9 drm/amdgpu/userq: 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
PATCH 8/9 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
PATCH 9/9 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