Skip to content

Commit 530ca2c

Browse files
Keith Buschaxboe
authored andcommitted
blk-mq: Allow blocking queue tag iter callbacks
A recent commit runs tag iterator callbacks under the rcu read lock, but existing callbacks do not satisfy the non-blocking requirement. The commit intended to prevent an iterator from accessing a queue that's being modified. This patch fixes the original issue by taking a queue reference instead of reading it, which allows callbacks to make blocking calls. Fixes: f5bbbbe ("blk-mq: sync the update nr_hw_queues with blk_mq_queue_tag_busy_iter") Acked-by: Jianchao Wang <jianchao.w.wang@oracle.com> Signed-off-by: Keith Busch <keith.busch@intel.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b57e99b commit 530ca2c

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

block/blk-mq-tag.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,11 @@ void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn,
322322

323323
/*
324324
* __blk_mq_update_nr_hw_queues will update the nr_hw_queues and
325-
* queue_hw_ctx after freeze the queue. So we could use q_usage_counter
326-
* to avoid race with it. __blk_mq_update_nr_hw_queues will users
327-
* synchronize_rcu to ensure all of the users go out of the critical
328-
* section below and see zeroed q_usage_counter.
325+
* queue_hw_ctx after freeze the queue, so we use q_usage_counter
326+
* to avoid race with it.
329327
*/
330-
rcu_read_lock();
331-
if (percpu_ref_is_zero(&q->q_usage_counter)) {
332-
rcu_read_unlock();
328+
if (!percpu_ref_tryget(&q->q_usage_counter))
333329
return;
334-
}
335330

336331
queue_for_each_hw_ctx(q, hctx, i) {
337332
struct blk_mq_tags *tags = hctx->tags;
@@ -347,7 +342,7 @@ void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn,
347342
bt_for_each(hctx, &tags->breserved_tags, fn, priv, true);
348343
bt_for_each(hctx, &tags->bitmap_tags, fn, priv, false);
349344
}
350-
rcu_read_unlock();
345+
blk_queue_exit(q);
351346
}
352347

353348
static int bt_alloc(struct sbitmap_queue *bt, unsigned int depth,

0 commit comments

Comments
 (0)