Skip to content

Commit

Permalink
block: remove deadlock in disk_clear_events
Browse files Browse the repository at this point in the history
In disk_clear_events, do not put work on system_nrt_freezable_wq.
Instead, put it on system_nrt_wq.

There is a race between probing a usb and suspending the device.  Since
probing a usb calls disk_clear_events, which puts work on a frozen
workqueue, probing cannot finish after the workqueue is frozen.  However,
suspending cannot finish until the usb probe is finished, so we get a
deadlock, causing the system to reboot.

The way to reproduce this bug is to wake up from suspend with a usb
storage device plugged in, or plugging in a usb storage device right
before suspend.  The window of time is on the order of time it takes to
probe the usb device.  As long as the workqueues are frozen before the
call to add_disk within sd_probe_async finishes, there will be a deadlock
(which calls blkdev_get, sd_open, check_disk_change, then
disk_clear_events).  This is not difficult to reproduce after figuring out
the timings.

[[email protected]: fix up comment]
Signed-off-by: Derek Basehore <[email protected]>
Reviewed-by: Mandeep Singh Baines <[email protected]>
Cc: Jens Axboe <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
dbasehore authored and axboe committed Dec 19, 2012
1 parent 74779e2 commit aea24a8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,14 @@ unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask)

/* uncondtionally schedule event check and wait for it to finish */
disk_block_events(disk);
queue_delayed_work(system_freezable_wq, &ev->dwork, 0);
/*
* We need to put the work on system_nrt_wq here since there is a
* deadlock that happens while probing a usb device while suspending. If
* we put work on a freezable workqueue here, a usb probe will wait here
* until the workqueue is unfrozen during suspend. Since suspend waits
* on all probes to complete, we have a deadlock
*/
queue_delayed_work(system_nrt_wq, &ev->dwork, 0);
flush_delayed_work(&ev->dwork);
__disk_unblock_events(disk, false);

Expand Down

0 comments on commit aea24a8

Please sign in to comment.