Message ID | 1559156813-30681-1-git-send-email-cai@lca.pw (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | mm/page_io: fix a crash in do_task_dead() | expand |
On Wed, 29 May 2019 15:06:53 -0400 Qian Cai <cai@lca.pw> wrote: > The commit 0619317ff8ba ("block: add polled wakeup task helper") > replaced wake_up_process() with blk_wake_io_task() in > end_swap_bio_read() which triggers a crash when running heavy swapping > workloads. > > [T114538] kernel BUG at kernel/sched/core.c:3462! > [T114538] Process oom01 (pid: 114538, stack limit = 0x000000004f40e0c1) > [T114538] Call trace: > [T114538] do_task_dead+0xf0/0xf8 > [T114538] do_exit+0xd5c/0x10fc > [T114538] do_group_exit+0xf4/0x110 > [T114538] get_signal+0x280/0xdd8 > [T114538] do_notify_resume+0x720/0x968 > [T114538] work_pending+0x8/0x10 > > This is because shortly after set_special_state(TASK_DEAD), > end_swap_bio_read() is called from an interrupt handler that revive the > task state to TASK_RUNNING causes __schedule() to return and trip the > BUG() later. > > [ C206] Call trace: > [ C206] dump_backtrace+0x0/0x268 > [ C206] show_stack+0x20/0x2c > [ C206] dump_stack+0xb4/0x108 > [ C206] blk_wake_io_task+0x7c/0x80 > [ C206] end_swap_bio_read+0x22c/0x31c > [ C206] bio_endio+0x3d8/0x414 > [ C206] dec_pending+0x280/0x378 [dm_mod] > [ C206] clone_endio+0x128/0x2ac [dm_mod] > [ C206] bio_endio+0x3d8/0x414 > [ C206] blk_update_request+0x3ac/0x924 > [ C206] scsi_end_request+0x54/0x350 > [ C206] scsi_io_completion+0xf0/0x6f4 > [ C206] scsi_finish_command+0x214/0x228 > [ C206] scsi_softirq_done+0x170/0x1a4 > [ C206] blk_done_softirq+0x100/0x194 > [ C206] __do_softirq+0x350/0x790 > [ C206] irq_exit+0x200/0x26c > [ C206] handle_IPI+0x2e8/0x514 > [ C206] gic_handle_irq+0x224/0x228 > [ C206] el1_irq+0xb8/0x140 > [ C206] _raw_spin_unlock_irqrestore+0x3c/0x74 > [ C206] do_task_dead+0x88/0xf8 > [ C206] do_exit+0xd5c/0x10fc > [ C206] do_group_exit+0xf4/0x110 > [ C206] get_signal+0x280/0xdd8 > [ C206] do_notify_resume+0x720/0x968 > [ C206] work_pending+0x8/0x10 > > Before the offensive commit, wake_up_process() will prevent this from > happening by taking the pi_lock and bail out immediately if TASK_DEAD is > set. > > if (!(p->state & TASK_NORMAL)) > goto out; Nice description, thanks. And... ouch. blk_wake_io_task() is a scary thing - changing a task to TASK_RUNNING state from interrupt context. I wonder whether the assumptions which that is making hold true in all situations even after this change. Is polled block IO important enough for doing this stuff? > Fixes: 0619317ff8ba ("block: add polled wakeup task helper") That will be needing a cc:stable, no? > ... > > --- a/mm/page_io.c > +++ b/mm/page_io.c > @@ -140,7 +140,8 @@ static void end_swap_bio_read(struct bio *bio) > unlock_page(page); > WRITE_ONCE(bio->bi_private, NULL); > bio_put(bio); > - blk_wake_io_task(waiter); > + /* end_swap_bio_read() could be called from an interrupt handler. */ > + wake_up_process(waiter); > put_task_struct(waiter); > }
On 5/29/19 4:44 PM, Andrew Morton wrote: > On Wed, 29 May 2019 15:06:53 -0400 Qian Cai <cai@lca.pw> wrote: > >> The commit 0619317ff8ba ("block: add polled wakeup task helper") >> replaced wake_up_process() with blk_wake_io_task() in >> end_swap_bio_read() which triggers a crash when running heavy swapping >> workloads. >> >> [T114538] kernel BUG at kernel/sched/core.c:3462! >> [T114538] Process oom01 (pid: 114538, stack limit = 0x000000004f40e0c1) >> [T114538] Call trace: >> [T114538] do_task_dead+0xf0/0xf8 >> [T114538] do_exit+0xd5c/0x10fc >> [T114538] do_group_exit+0xf4/0x110 >> [T114538] get_signal+0x280/0xdd8 >> [T114538] do_notify_resume+0x720/0x968 >> [T114538] work_pending+0x8/0x10 >> >> This is because shortly after set_special_state(TASK_DEAD), >> end_swap_bio_read() is called from an interrupt handler that revive the >> task state to TASK_RUNNING causes __schedule() to return and trip the >> BUG() later. >> >> [ C206] Call trace: >> [ C206] dump_backtrace+0x0/0x268 >> [ C206] show_stack+0x20/0x2c >> [ C206] dump_stack+0xb4/0x108 >> [ C206] blk_wake_io_task+0x7c/0x80 >> [ C206] end_swap_bio_read+0x22c/0x31c >> [ C206] bio_endio+0x3d8/0x414 >> [ C206] dec_pending+0x280/0x378 [dm_mod] >> [ C206] clone_endio+0x128/0x2ac [dm_mod] >> [ C206] bio_endio+0x3d8/0x414 >> [ C206] blk_update_request+0x3ac/0x924 >> [ C206] scsi_end_request+0x54/0x350 >> [ C206] scsi_io_completion+0xf0/0x6f4 >> [ C206] scsi_finish_command+0x214/0x228 >> [ C206] scsi_softirq_done+0x170/0x1a4 >> [ C206] blk_done_softirq+0x100/0x194 >> [ C206] __do_softirq+0x350/0x790 >> [ C206] irq_exit+0x200/0x26c >> [ C206] handle_IPI+0x2e8/0x514 >> [ C206] gic_handle_irq+0x224/0x228 >> [ C206] el1_irq+0xb8/0x140 >> [ C206] _raw_spin_unlock_irqrestore+0x3c/0x74 >> [ C206] do_task_dead+0x88/0xf8 >> [ C206] do_exit+0xd5c/0x10fc >> [ C206] do_group_exit+0xf4/0x110 >> [ C206] get_signal+0x280/0xdd8 >> [ C206] do_notify_resume+0x720/0x968 >> [ C206] work_pending+0x8/0x10 >> >> Before the offensive commit, wake_up_process() will prevent this from >> happening by taking the pi_lock and bail out immediately if TASK_DEAD is >> set. >> >> if (!(p->state & TASK_NORMAL)) >> goto out; > > Nice description, thanks. > > And... ouch. blk_wake_io_task() is a scary thing - changing a task to > TASK_RUNNING state from interrupt context. I wonder whether the > assumptions which that is making hold true in all situations even after > this change. > > Is polled block IO important enough for doing this stuff? Andrew, you missed the improved patch, you were CC'ed on that one too and I queued it up a few hours ago: http://git.kernel.dk/cgit/linux-block/commit/?h=for-linus&id=6f3ead091fe2a8fb57a5996fe8b94237a896c6e9 Please drop this one. >> Fixes: 0619317ff8ba ("block: add polled wakeup task helper") > > That will be needing a cc:stable, no? Also added that when I did.
diff --git a/mm/page_io.c b/mm/page_io.c index 2e8019d0e048..dc2d3e037ccf 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -140,7 +140,8 @@ static void end_swap_bio_read(struct bio *bio) unlock_page(page); WRITE_ONCE(bio->bi_private, NULL); bio_put(bio); - blk_wake_io_task(waiter); + /* end_swap_bio_read() could be called from an interrupt handler. */ + wake_up_process(waiter); put_task_struct(waiter); }
The commit 0619317ff8ba ("block: add polled wakeup task helper") replaced wake_up_process() with blk_wake_io_task() in end_swap_bio_read() which triggers a crash when running heavy swapping workloads. [T114538] kernel BUG at kernel/sched/core.c:3462! [T114538] Process oom01 (pid: 114538, stack limit = 0x000000004f40e0c1) [T114538] Call trace: [T114538] do_task_dead+0xf0/0xf8 [T114538] do_exit+0xd5c/0x10fc [T114538] do_group_exit+0xf4/0x110 [T114538] get_signal+0x280/0xdd8 [T114538] do_notify_resume+0x720/0x968 [T114538] work_pending+0x8/0x10 This is because shortly after set_special_state(TASK_DEAD), end_swap_bio_read() is called from an interrupt handler that revive the task state to TASK_RUNNING causes __schedule() to return and trip the BUG() later. [ C206] Call trace: [ C206] dump_backtrace+0x0/0x268 [ C206] show_stack+0x20/0x2c [ C206] dump_stack+0xb4/0x108 [ C206] blk_wake_io_task+0x7c/0x80 [ C206] end_swap_bio_read+0x22c/0x31c [ C206] bio_endio+0x3d8/0x414 [ C206] dec_pending+0x280/0x378 [dm_mod] [ C206] clone_endio+0x128/0x2ac [dm_mod] [ C206] bio_endio+0x3d8/0x414 [ C206] blk_update_request+0x3ac/0x924 [ C206] scsi_end_request+0x54/0x350 [ C206] scsi_io_completion+0xf0/0x6f4 [ C206] scsi_finish_command+0x214/0x228 [ C206] scsi_softirq_done+0x170/0x1a4 [ C206] blk_done_softirq+0x100/0x194 [ C206] __do_softirq+0x350/0x790 [ C206] irq_exit+0x200/0x26c [ C206] handle_IPI+0x2e8/0x514 [ C206] gic_handle_irq+0x224/0x228 [ C206] el1_irq+0xb8/0x140 [ C206] _raw_spin_unlock_irqrestore+0x3c/0x74 [ C206] do_task_dead+0x88/0xf8 [ C206] do_exit+0xd5c/0x10fc [ C206] do_group_exit+0xf4/0x110 [ C206] get_signal+0x280/0xdd8 [ C206] do_notify_resume+0x720/0x968 [ C206] work_pending+0x8/0x10 Before the offensive commit, wake_up_process() will prevent this from happening by taking the pi_lock and bail out immediately if TASK_DEAD is set. if (!(p->state & TASK_NORMAL)) goto out; Fixes: 0619317ff8ba ("block: add polled wakeup task helper") Signed-off-by: Qian Cai <cai@lca.pw> --- mm/page_io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)