Skip to content

Commit

Permalink
swap_readpage(): avoid blk_wake_io_task() if !synchronous
Browse files Browse the repository at this point in the history
swap_readpage() sets waiter = bio->bi_private even if synchronous = F,
this means that the caller can get the spurious wakeup after return.

This can be fatal if blk_wake_io_task() does
set_current_state(TASK_RUNNING) after the caller does
set_special_state(), in the worst case the kernel can crash in
do_task_dead().

Link: http://lkml.kernel.org/r/[email protected]
Fixes: 0619317 ("block: add polled wakeup task helper")
Signed-off-by: Oleg Nesterov <[email protected]>
Reported-by: Qian Cai <[email protected]>
Acked-by: Hugh Dickins <[email protected]>
Reviewed-by: Jens Axboe <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
oleg-nesterov authored and torvalds committed Jul 5, 2019
1 parent eef778c commit 8751853
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions mm/page_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ 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);
put_task_struct(waiter);
if (waiter) {
blk_wake_io_task(waiter);
put_task_struct(waiter);
}
}

int generic_swapfile_activate(struct swap_info_struct *sis,
Expand Down Expand Up @@ -395,11 +397,12 @@ int swap_readpage(struct page *page, bool synchronous)
* Keep this task valid during swap readpage because the oom killer may
* attempt to access it in the page fault retry time check.
*/
get_task_struct(current);
bio->bi_private = current;
bio_set_op_attrs(bio, REQ_OP_READ, 0);
if (synchronous)
if (synchronous) {
bio->bi_opf |= REQ_HIPRI;
get_task_struct(current);
bio->bi_private = current;
}
count_vm_event(PSWPIN);
bio_get(bio);
qc = submit_bio(bio);
Expand Down

0 comments on commit 8751853

Please sign in to comment.