Prevent CPU deadlock with fbdev based consoles while printing scheduler warnings
Subsystems (2)
PATCH 1/1 Prevent CPU deadlock with fbdev based consoles while printing scheduler warnings
From: Mika Penttilä <[email protected]>
With some fbdev based consoles, using the deferred_io mechanism and drm_fb_helper, there can be a call chain like:
Backtrack:
try_to_wake_up <-- rq_lock taken__queue_workqueue_work_onsoft_cursorhide_cursorvt_console_printconsole_unlockvprintk_emit
printk__warn_printk
(cfs_rq_is_decayed -> SCHED_WARN_ON)__update_blocked_fairupdate_blocked_averages <-- rq_lock taken
Example producer is with qemu bochs virtio device (qemu stdvga), and drm bochs support in the guest.
This can fixed be used using schedule_delayed_work() to get out of scheduler context, if needed, while queueing the damage_work.
--- drivers/gpu/drm/drm_fb_helper.c | 8 ++++---- include/drm/drm_fb_helper.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/drm_fb_helper.c +4 -4
@@ -429,7 +429,7 @@ static int drm_fb_helper_damage_blit(struct drm_fb_helper *fb_helper,static void drm_fb_helper_damage_work (struct work_struct *work) { struct drm_fb_helper *helper = container_of(work, struct drm_fb_helper, - damage_work); + damage_work.work);struct drm_device *dev = helper->dev;struct drm_clip_rect *clip = &helper->damage_clip;struct drm_clip_rect clip_copy;
@@ -488,7 +488,7 @@ void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,INIT_LIST_HEAD (&helper->kernel_fb_list);spin_lock_init (&helper->damage_lock);INIT_WORK (&helper->resume_work, drm_fb_helper_resume_worker); -INIT_WORK (&helper->damage_work, drm_fb_helper_damage_work); +INIT_DELAYED_WORK (&helper->damage_work, drm_fb_helper_damage_work); helper->damage_clip.x1 = helper->damage_clip.y1 = ~0 ;mutex_init (&helper->lock); helper->funcs = funcs;
@@ -625,7 +625,7 @@ void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)return ;cancel_work_sync (&fb_helper->resume_work); -cancel_work_sync (&fb_helper->damage_work); +cancel_delayed_work_sync (&fb_helper->damage_work); info = fb_helper->fbdev;if (info) {
@@ -677,7 +677,7 @@ static void drm_fb_helper_damage(struct fb_info *info, u32 x, u32 y, clip->y2 =max_t (u32, clip->y2, y + height);spin_unlock_irqrestore (&helper->damage_lock, flags); -schedule_work (&helper->damage_work); +schedule_delayed_work (&helper->damage_work,in_atomic () ?1 :0 ); }/* Convert memory region into area of scanlines and pixels per scanline */
include/drm/drm_fb_helper.h +1 -1
@@ -132,7 +132,7 @@ struct drm_fb_helper {u32 pseudo_palette[17 ];struct drm_clip_rect damage_clip;spinlock_t damage_lock; -struct work_struct damage_work; +struct delayed_work damage_work;struct work_struct resume_work;/**
Signature · 1 line
2.17.1
Gentle ping, any concerns or suggestions on this topic or solution in general?
Thanks,
Mika
Quoted 87 lines · On 2.8.2022 6.31, [email protected] wrote:
From: Mika Penttilä<[email protected]>
With some fbdev based consoles, using the
deferred_iomechanism anddrm_fb_helper, there can be a call chain like:Backtrack:
try_to_wake_up<--rq_locktaken__queue_workqueue_work_onsoft_cursorhide_cursorvt_console_printconsole_unlockvprintk_emit
printk__warn_printk
(cfs_rq_is_decayed->SCHED_WARN_ON)__update_blocked_fairupdate_blocked_averages<--rq_locktakenExample producer is with qemu bochs virtio device (qemu stdvga), and drm bochs support in the guest.
This can fixed be used using
schedule_delayed_work()to get out of scheduler context, if needed, while queueing thedamage_work.Signed-off-by Mika Penttilä<[email protected]>Cc David Airlie<[email protected]>--- drivers/gpu/drm/drm_fb_helper.c | 8 ++++---- include/drm/drm_fb_helper.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)drivers/gpu/drm/drm_fb_helper.c +4
-4@@ -429,7 +429,7 @@ static int drm_fb_helper_damage_blit(struct drm_fb_helper *fb_helper,static void drm_fb_helper_damage_work (struct work_struct *work) { struct drm_fb_helper *helper = container_of(work, struct drm_fb_helper, - damage_work); + damage_work.work);struct drm_device *dev = helper->dev;struct drm_clip_rect *clip = &helper->damage_clip;struct drm_clip_rect clip_copy;@@ -488,7 +488,7 @@ void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,INIT_LIST_HEAD (&helper->kernel_fb_list);spin_lock_init (&helper->damage_lock);INIT_WORK (&helper->resume_work, drm_fb_helper_resume_worker); -INIT_WORK (&helper->damage_work, drm_fb_helper_damage_work); +INIT_DELAYED_WORK (&helper->damage_work, drm_fb_helper_damage_work); helper->damage_clip.x1 = helper->damage_clip.y1 = ~0 ;mutex_init (&helper->lock); helper->funcs = funcs;@@ -625,7 +625,7 @@ void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)return ;cancel_work_sync (&fb_helper->resume_work); -cancel_work_sync (&fb_helper->damage_work); +cancel_delayed_work_sync (&fb_helper->damage_work); info = fb_helper->fbdev;if (info) {@@ -677,7 +677,7 @@ static void drm_fb_helper_damage(struct fb_info *info, u32 x, u32 y, clip->y2 =max_t (u32, clip->y2, y + height);spin_unlock_irqrestore (&helper->damage_lock, flags); -schedule_work (&helper->damage_work); +schedule_delayed_work (&helper->damage_work,in_atomic () ?1 :0 ); }/* Convert memory region into area of scanlines and pixels per scanline */ include/drm/drm_fb_helper.h +1
-1@@ -132,7 +132,7 @@ struct drm_fb_helper {u32 pseudo_palette[17 ];struct drm_clip_rect damage_clip;spinlock_t damage_lock; -struct work_struct damage_work; +struct delayed_work damage_work;struct work_struct resume_work;/**
Dave Airlie
maintainerJust adding Thomas in case he missed it.
Dave.
Quoted 98 lines · Mika Penttilä
Gentle ping, any concerns or suggestions on this topic or solution in general?
Thanks,
MikaOn 2.8.2022 6.31, [email protected] wrote:
From: Mika Penttilä <[email protected]>
With some fbdev based consoles, using the
deferred_iomechanism anddrm_fb_helper, there can be a call chain like:Backtrack:
try_to_wake_up<--rq_locktaken__queue_workqueue_work_onsoft_cursorhide_cursorvt_console_printconsole_unlockvprintk_emit
printk__warn_printk
(cfs_rq_is_decayed->SCHED_WARN_ON)__update_blocked_fairupdate_blocked_averages<--rq_locktakenExample producer is with qemu bochs virtio device (qemu stdvga), and drm bochs support in the guest.
This can fixed be used using
schedule_delayed_work()to get out of scheduler context, if needed, while queueing thedamage_work.Signed-off-by Mika Penttilä <[email protected]>Cc David Airlie <[email protected]>--- drivers/gpu/drm/drm_fb_helper.c | 8 ++++---- include/drm/drm_fb_helper.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)drivers/gpu/drm/drm_fb_helper.c +4
-4@@ -429,7 +429,7 @@ static int drm_fb_helper_damage_blit(struct drm_fb_helper *fb_helper,static void drm_fb_helper_damage_work (struct work_struct *work) { struct drm_fb_helper *helper = container_of(work, struct drm_fb_helper, - damage_work); + damage_work.work);struct drm_device *dev = helper->dev;struct drm_clip_rect *clip = &helper->damage_clip;struct drm_clip_rect clip_copy;@@ -488,7 +488,7 @@ void drm_fb_helper_prepare(struct drm_device *dev, struct drm_fb_helper *helper,INIT_LIST_HEAD (&helper->kernel_fb_list);spin_lock_init (&helper->damage_lock);INIT_WORK (&helper->resume_work, drm_fb_helper_resume_worker); -INIT_WORK (&helper->damage_work, drm_fb_helper_damage_work); +INIT_DELAYED_WORK (&helper->damage_work, drm_fb_helper_damage_work); helper->damage_clip.x1 = helper->damage_clip.y1 = ~0 ;mutex_init (&helper->lock); helper->funcs = funcs;@@ -625,7 +625,7 @@ void drm_fb_helper_fini(struct drm_fb_helper *fb_helper)return ;cancel_work_sync (&fb_helper->resume_work); -cancel_work_sync (&fb_helper->damage_work); +cancel_delayed_work_sync (&fb_helper->damage_work); info = fb_helper->fbdev;if (info) {@@ -677,7 +677,7 @@ static void drm_fb_helper_damage(struct fb_info *info, u32 x, u32 y, clip->y2 =max_t (u32, clip->y2, y + height);spin_unlock_irqrestore (&helper->damage_lock, flags); -schedule_work (&helper->damage_work); +schedule_delayed_work (&helper->damage_work,in_atomic () ?1 :0 ); }/* Convert memory region into area of scanlines and pixels per scanline */ include/drm/drm_fb_helper.h +1
-1@@ -132,7 +132,7 @@ struct drm_fb_helper {u32 pseudo_palette[17 ];struct drm_clip_rect damage_clip;spinlock_t damage_lock; -struct work_struct damage_work; +struct delayed_work damage_work;struct work_struct resume_work;/**