Skip to content

Commit

Permalink
blk-mq: fix a memory ordering bug in blk_mq_queue_enter()
Browse files Browse the repository at this point in the history
blk-mq uses a percpu_counter to keep track of how many usages are in
flight.  The percpu_counter is drained while freezing to ensure that
no usage is left in-flight after freezing is complete.

blk_mq_queue_enter/exit() and blk_mq_[un]freeze_queue() implement this
per-cpu gating mechanism; unfortunately, it contains a subtle bug -
smp_wmb() in blk_mq_queue_enter() doesn't prevent prevent the cpu from
fetching @q->bypass_depth before incrementing @q->mq_usage_counter and
if freezing happens inbetween the caller can slip through and freezing
can be complete while there are active users.

Use smp_mb() instead so that bypass_depth and mq_usage_counter
modifications and tests are properly interlocked.

Signed-off-by: Tejun Heo <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Nicholas A. Bellinger <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
htejun authored and axboe committed Jul 1, 2014
1 parent 17737d3 commit 531ed62
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static int blk_mq_queue_enter(struct request_queue *q)
int ret;

__percpu_counter_add(&q->mq_usage_counter, 1, 1000000);
smp_wmb();
smp_mb();

/* we have problems freezing the queue if it's initializing */
if (!blk_queue_dying(q) &&
Expand Down

0 comments on commit 531ed62

Please sign in to comment.