Skip to content

Commit

Permalink
block: add a read barrier in blk_queue_enter()
Browse files Browse the repository at this point in the history
Without the barrier, reading DEAD flag of .q_usage_counter
and reading .mq_freeze_depth may be reordered, then the
following wait_event_interruptible() may never return.

Reviewed-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
  • Loading branch information
Ming Lei authored and Jens Axboe committed Mar 29, 2017
1 parent d9d149a commit 5ed61d3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions block/blk-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,15 @@ int blk_queue_enter(struct request_queue *q, bool nowait)
if (nowait)
return -EBUSY;

/*
* read pair of barrier in blk_mq_freeze_queue_start(),
* we need to order reading __PERCPU_REF_DEAD flag of
* .q_usage_counter and reading .mq_freeze_depth,
* otherwise the following wait may never return if the
* two reads are reordered.
*/
smp_rmb();

ret = wait_event_interruptible(q->mq_freeze_wq,
!atomic_read(&q->mq_freeze_depth) ||
blk_queue_dying(q));
Expand Down

0 comments on commit 5ed61d3

Please sign in to comment.