drm/amd/display: Fix DM IRQ teardown races
Subsystems (3)
v2 cover drm/amd/display: Fix DM IRQ teardown races
Changes since v1:
- Remove irq_fini_in_progress flag; the spinlock serialization and empty-list check are sufficient (Leo Li)
- Remove redundant irq_wq != NULL check in amdgpu_dm_irq_schedule_work; amdgpu_dm_irq_init() already guarantees it is valid (Leo Li)
Geoffrey McRae (2):
drm/amd/display: Fix DM IRQ teardown races drm/amd/display: Use unbound workqueues for deferred DM work
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 8 +- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 4 + .../drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c | 172 ++++++++++-------- 3 files changed, 102 insertions(+), 82 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/2 drm/amd/display: Fix DM IRQ teardown races
DM IRQ teardown can race with interrupt handling and low-context work. The IRQ handler can still walk the DM IRQ handler tables while the teardown path removes and frees entries. Low-context work can also remain queued after its handler has been removed, leading to a possible use-after-free when the work item later runs.
Rework amdgpu_dm_irq_fini() to detach all low and high context handlers from the IRQ tables under the table lock, then cancel pending low-context work outside the lock before freeing the handlers. Also cancel low-context work in remove_irq_handler() before freeing an individual handler.
Fix the suspend path by disabling HPD and HPD RX hardware interrupts under the IRQ table lock before flushing pending low-context work, avoiding a TOCTOU window where new work could be queued after the list check.
Finally, call amdgpu_dm_irq_fini() from amdgpu_dm_fini() before DC is destroyed, so IRQ teardown happens while the display core state is still valid.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 8 +- .../drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c | 141 +++++++++--------- 2 files changed, 70 insertions(+), 79 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -6
@@ -1010,14 +1010,11 @@ static void amdgpu_dm_fini(struct amdgpu_device *adev) adev->dm.hpd_rx_offload_wq =NULL ; } +amdgpu_dm_irq_fini (adev); +/* DC Destroy TODO: Replace destroy DAL */ if (adev->dm.dc)dc_destroy (&adev->dm.dc); -/* -* TODO: pageflip, vlank interrupt -* -* amdgpu_dm_irq_fini(adev); -*/ if (adev->dm.cgs_device) {amdgpu_cgs_destroy_device (adev->dm.cgs_device);
@@ -1523,7 +1520,6 @@ static int dm_hw_fini(struct amdgpu_ip_block *ip_block)amdgpu_dm_hpd_fini (adev); -amdgpu_dm_irq_fini (adev);amdgpu_dm_fini (adev);return 0 ; }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c +68 -73
217 lines not on this page · raw message
Signature · 1 line
2.43.0
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c static int amdgpu_dm_irq_handler(struct amdgpu_device *adev, · line 681
Quoted 12 lines · Geoffrey McRae
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c +2
-2@@ -678,9 +673,9 @@ static int amdgpu_dm_irq_handler(struct amdgpu_device *adev,struct amdgpu_irq_src *source, struct amdgpu_iv_entry *entry) { + enum dc_irq_source src; - enum dc_irq_source src = -dc_interrupt_to_irq_source ( + src =dc_interrupt_to_irq_source ( adev->dm.dc, entry->src_id, entry->src_data[0 ]);
With irq_fini_in_progress removed, this hunk does nothing and can be dropped as well. With that:
PATCH v2 2/2 drm/amd/display: Use unbound workqueues for deferred DM work
In reply to Geoffrey McRaeDM currently queues some deferred display work on system workqueues. Low-context IRQ handlers are queued on system_highpri_wq, while deferred vmin/vmax updates are queued on system_percpu_wq.
Both paths can execute long-running display work. HPD and HPD RX handling may involve link detection, AUX transactions, connector state updates, and hotplug notification. The vmin/vmax update path calls into DC under dc_lock to adjust stream timing. These paths can therefore trigger the workqueue CPU hog detector when run from per-CPU workers:
workqueue: dm_irq_work_func [amdgpu] hogged CPU for >10000us
workqueue: dm_handle_vmin_vmax_update [amdgpu] hogged CPU for >10000us
Move the deferred low-context IRQ work to a dedicated high-priority unbound workqueue, preserving the priority of the previous system_highpri_wq usage while avoiding long-running work on per-CPU workers.
Move deferred vmin/vmax updates to a separate normal-priority unbound workqueue.
High-context IRQ handlers remain unchanged and continue to run directly from the IRQ path.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 4 +++ .../drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c | 31 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +4 -0
@@ -324,6 +324,8 @@ struct hpd_rx_irq_offload_work {* @ddev: DRM base driver structure * @display_indexes_num: Max number of display streams supported * @irq_handler_list_table_lock: Synchronizes access to IRQ tables +* @irq_wq: Dedicated high-priority unbound workqueue for deferred IRQ work +* @vmin_vmax_wq: Dedicated unbound workqueue for deferred vmin/vmax updates * @backlight_dev: Backlight control device * @backlight_link: Link on which to control backlight * @backlight_caps: Capabilities of the backlight device
@@ -563,6 +565,8 @@ struct amdgpu_display_manager { dmub_outbox_params[1 ];spinlock_t irq_handler_list_table_lock; +struct workqueue_struct *irq_wq; +struct workqueue_struct *vmin_vmax_wq;struct backlight_device *backlight_dev[AMDGPU_DM_MAX_NUM_EDP ];
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c +28 -3
@@ -397,6 +397,21 @@ int amdgpu_dm_irq_init(struct amdgpu_device *adev)spin_lock_init (&adev->dm.irq_handler_list_table_lock); + adev->dm.irq_wq =alloc_workqueue ("amdgpu_dm_irq" , +WQ_UNBOUND |WQ_HIGHPRI ,0 ); + +if (!adev->dm.irq_wq) +return -ENOMEM ; + + adev->dm.vmin_vmax_wq =alloc_workqueue ("amdgpu_dm_vmin_vmax" , +WQ_UNBOUND ,0 ); + +if (!adev->dm.vmin_vmax_wq) { +destroy_workqueue (adev->dm.irq_wq); + adev->dm.irq_wq =NULL ; +return -ENOMEM ; + } +for (src =0 ; src <DAL_IRQ_SOURCES_NUMBER ; src++) {/* low context handler list init */ lh = &adev->dm.irq_handler_list_low_tab[src];
@@ -478,6 +493,16 @@ void amdgpu_dm_irq_fini(struct amdgpu_device *adev)list_del (&handler->list);kfree (handler); } + +if (adev->dm.vmin_vmax_wq) { +destroy_workqueue (adev->dm.vmin_vmax_wq); + adev->dm.vmin_vmax_wq =NULL ; + } + +if (adev->dm.irq_wq) { +destroy_workqueue (adev->dm.irq_wq); + adev->dm.irq_wq =NULL ; + } }EXPORT_IF_KUNIT (amdgpu_dm_irq_fini);
@@ -594,7 +619,7 @@ static void amdgpu_dm_irq_schedule_work(struct amdgpu_device *adev, goto out_unlock;list_for_each_entry (handler_data, handler_list, list) { -if (queue_work (system_highpri_wq, &handler_data->work)) { +if (queue_work (adev->dm.irq_wq, &handler_data->work)) { work_queued = true;break ; }
@@ -622,7 +647,7 @@ static void amdgpu_dm_irq_schedule_work(struct amdgpu_device *adev,INIT_WORK (&handler_data_add->work, dm_irq_work_func); -if (queue_work (system_highpri_wq, &handler_data_add->work)) +if (queue_work (adev->dm.irq_wq, &handler_data_add->work))DRM_DEBUG ("Queued work for handling interrupt from " "display for IRQ source %d\n" , irq_source);
@@ -1882,7 +1907,7 @@ static void schedule_dc_vmin_vmax(struct amdgpu_device *adev, offload_work->stream = stream; offload_work->adjust = adjust_copy; -queue_work (system_percpu_wq, &offload_work->work); +queue_work (adev->dm.vmin_vmax_wq, &offload_work->work); }static void dm_vupdate_high_irq (void *interrupt_params)
Signature · 1 line
2.43.0
Re: [PATCH v2 2/2] drm/amd/display: Use unbound workqueues for deferred DM work
Quoted 18 lines · Geoffrey McRae
DM currently queues some deferred display work on system workqueues. Low-context IRQ handlers are queued on
system_highpri_wq, while deferred vmin/vmax updates are queued onsystem_percpu_wq.Both paths can execute long-running display work. HPD and HPD RX handling may involve link detection, AUX transactions, connector state updates, and hotplug notification. The vmin/vmax update path calls into DC under
dc_lockto adjust stream timing. These paths can therefore trigger the workqueue CPU hog detector when run from per-CPU workers:workqueue:
dm_irq_work_func[amdgpu] hogged CPU for >10000us
workqueue:dm_handle_vmin_vmax_update[amdgpu] hogged CPU for >10000usMove the deferred low-context IRQ work to a dedicated high-priority unbound workqueue, preserving the priority of the previous
system_highpri_wqusage while avoiding long-running work on per-CPU workers.
Quoted 6 lines
Move deferred vmin/vmax updates to a separate normal-priority unbound workqueue.
High-context IRQ handlers remain unchanged and continue to run directly from the IRQ path.
Thanks!
Quoted 102 lines
Signed-off-by Geoffrey McRae <[email protected]>Cc Harry Wentland <[email protected]>Cc Leo Li <[email protected]>Cc Alex Deucher <[email protected]>Cc Christian König <[email protected]>--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 4 +++ .../drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c | 31 +++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +4
-0@@ -324,6 +324,8 @@ struct hpd_rx_irq_offload_work {* @ddev: DRM base driver structure * @display_indexes_num: Max number of display streams supported * @irq_handler_list_table_lock: Synchronizes access to IRQ tables +* @irq_wq: Dedicated high-priority unbound workqueue for deferred IRQ work +* @vmin_vmax_wq: Dedicated unbound workqueue for deferred vmin/vmax updates * @backlight_dev: Backlight control device * @backlight_link: Link on which to control backlight * @backlight_caps: Capabilities of the backlight device @@ -563,6 +565,8 @@ struct amdgpu_display_manager { dmub_outbox_params[1 ];spinlock_t irq_handler_list_table_lock; +struct workqueue_struct *irq_wq; +struct workqueue_struct *vmin_vmax_wq;struct backlight_device *backlight_dev[AMDGPU_DM_MAX_NUM_EDP ];drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c +28
-3@@ -397,6 +397,21 @@ int amdgpu_dm_irq_init(struct amdgpu_device *adev)spin_lock_init (&adev->dm.irq_handler_list_table_lock); + adev->dm.irq_wq =alloc_workqueue ("amdgpu_dm_irq" , +WQ_UNBOUND |WQ_HIGHPRI ,0 ); + +if (!adev->dm.irq_wq) +return -ENOMEM ; + + adev->dm.vmin_vmax_wq =alloc_workqueue ("amdgpu_dm_vmin_vmax" , +WQ_UNBOUND ,0 ); + +if (!adev->dm.vmin_vmax_wq) { +destroy_workqueue (adev->dm.irq_wq); + adev->dm.irq_wq =NULL ; +return -ENOMEM ; + } +for (src =0 ; src <DAL_IRQ_SOURCES_NUMBER ; src++) {/* low context handler list init */ lh = &adev->dm.irq_handler_list_low_tab[src];@@ -478,6 +493,16 @@ void amdgpu_dm_irq_fini(struct amdgpu_device *adev)list_del (&handler->list);kfree (handler); } + +if (adev->dm.vmin_vmax_wq) { +destroy_workqueue (adev->dm.vmin_vmax_wq); + adev->dm.vmin_vmax_wq =NULL ; + } + +if (adev->dm.irq_wq) { +destroy_workqueue (adev->dm.irq_wq); + adev->dm.irq_wq =NULL ; + } }EXPORT_IF_KUNIT (amdgpu_dm_irq_fini);@@ -594,7 +619,7 @@ static void amdgpu_dm_irq_schedule_work(struct amdgpu_device *adev, goto out_unlock;list_for_each_entry (handler_data, handler_list, list) { -if (queue_work (system_highpri_wq, &handler_data->work)) { +if (queue_work (adev->dm.irq_wq, &handler_data->work)) { work_queued = true;break ; }@@ -622,7 +647,7 @@ static void amdgpu_dm_irq_schedule_work(struct amdgpu_device *adev,INIT_WORK (&handler_data_add->work, dm_irq_work_func); -if (queue_work (system_highpri_wq, &handler_data_add->work)) +if (queue_work (adev->dm.irq_wq, &handler_data_add->work))DRM_DEBUG ("Queued work for handling interrupt from " "display for IRQ source %d\n" , irq_source);@@ -1882,7 +1907,7 @@ static void schedule_dc_vmin_vmax(struct amdgpu_device *adev, offload_work->stream = stream; offload_work->adjust = adjust_copy; -queue_work (system_percpu_wq, &offload_work->work); +queue_work (adev->dm.vmin_vmax_wq, &offload_work->work); }static void dm_vupdate_high_irq (void *interrupt_params)