Skip to content

Commit 2d82f3b

Browse files
Ming Leiaxboe
authored andcommitted
blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues
Commit 5989bfe ("block: restore two stage elevator switch while running nr_hw_queue update") reintroduced a lockdep warning by calling blk_mq_freeze_queue_nomemsave() before switching the I/O scheduler. The function blk_mq_elv_switch_none() calls elevator_change_done(). Running this while the queue is frozen causes a lockdep warning. Fix this by reordering the operations: first, switch the I/O scheduler to 'none', and then freeze the queue. This ensures that elevator_change_done() is not called on an already frozen queue. And this way is safe because elevator_set_none() does freeze queue before switching to none. Also we still have to rely on blk_mq_elv_switch_back() for switching back, and it has to cover unfrozen queue case. Cc: Nilay Shroff <[email protected]> Cc: Yu Kuai <[email protected]> Fixes: 5989bfe ("block: restore two stage elevator switch while running nr_hw_queue update") Signed-off-by: Ming Lei <[email protected]> Reviewed-by: Yu Kuai <[email protected]> Reviewed-by: Nilay Shroff <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent d0a2b52 commit 2d82f3b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

block/blk-mq.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5033,6 +5033,7 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
50335033
unsigned int memflags;
50345034
int i;
50355035
struct xarray elv_tbl, et_tbl;
5036+
bool queues_frozen = false;
50365037

50375038
lockdep_assert_held(&set->tag_list_lock);
50385039

@@ -5056,9 +5057,6 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
50565057
blk_mq_sysfs_unregister_hctxs(q);
50575058
}
50585059

5059-
list_for_each_entry(q, &set->tag_list, tag_set_list)
5060-
blk_mq_freeze_queue_nomemsave(q);
5061-
50625060
/*
50635061
* Switch IO scheduler to 'none', cleaning up the data associated
50645062
* with the previous scheduler. We will switch back once we are done
@@ -5068,6 +5066,9 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
50685066
if (blk_mq_elv_switch_none(q, &elv_tbl))
50695067
goto switch_back;
50705068

5069+
list_for_each_entry(q, &set->tag_list, tag_set_list)
5070+
blk_mq_freeze_queue_nomemsave(q);
5071+
queues_frozen = true;
50715072
if (blk_mq_realloc_tag_set_tags(set, nr_hw_queues) < 0)
50725073
goto switch_back;
50735074

@@ -5091,8 +5092,12 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
50915092
}
50925093
switch_back:
50935094
/* The blk_mq_elv_switch_back unfreezes queue for us. */
5094-
list_for_each_entry(q, &set->tag_list, tag_set_list)
5095+
list_for_each_entry(q, &set->tag_list, tag_set_list) {
5096+
/* switch_back expects queue to be frozen */
5097+
if (!queues_frozen)
5098+
blk_mq_freeze_queue_nomemsave(q);
50955099
blk_mq_elv_switch_back(q, &elv_tbl, &et_tbl);
5100+
}
50965101

50975102
list_for_each_entry(q, &set->tag_list, tag_set_list) {
50985103
blk_mq_sysfs_register_hctxs(q);

0 commit comments

Comments
 (0)