* [PATCH V2] blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues
@ 2025-08-15 13:17 Ming Lei
2025-08-15 14:05 ` Nilay Shroff
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Ming Lei @ 2025-08-15 13:17 UTC (permalink / raw)
To: Jens Axboe, linux-block; +Cc: Ming Lei, Nilay Shroff, Yu Kuai
Commit 5989bfe6ac6b ("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 <nilay@linux.ibm.com>
Cc: Yu Kuai <yukuai3@huawei.com>
Fixes: 5989bfe6ac6b ("block: restore two stage elevator switch while running nr_hw_queue update")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
V2:
- fix the issue locally, so patch is simplified
block/blk-mq.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/block/blk-mq.c b/block/blk-mq.c
index b67d6c02eceb..ba3a4b77f578 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -5033,6 +5033,7 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
unsigned int memflags;
int i;
struct xarray elv_tbl, et_tbl;
+ bool queues_frozen = false;
lockdep_assert_held(&set->tag_list_lock);
@@ -5056,9 +5057,6 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
blk_mq_sysfs_unregister_hctxs(q);
}
- list_for_each_entry(q, &set->tag_list, tag_set_list)
- blk_mq_freeze_queue_nomemsave(q);
-
/*
* Switch IO scheduler to 'none', cleaning up the data associated
* 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,
if (blk_mq_elv_switch_none(q, &elv_tbl))
goto switch_back;
+ list_for_each_entry(q, &set->tag_list, tag_set_list)
+ blk_mq_freeze_queue_nomemsave(q);
+ queues_frozen = true;
if (blk_mq_realloc_tag_set_tags(set, nr_hw_queues) < 0)
goto switch_back;
@@ -5091,8 +5092,12 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set,
}
switch_back:
/* The blk_mq_elv_switch_back unfreezes queue for us. */
- list_for_each_entry(q, &set->tag_list, tag_set_list)
+ list_for_each_entry(q, &set->tag_list, tag_set_list) {
+ /* switch_back expects queue to be frozen */
+ if (!queues_frozen)
+ blk_mq_freeze_queue_nomemsave(q);
blk_mq_elv_switch_back(q, &elv_tbl, &et_tbl);
+ }
list_for_each_entry(q, &set->tag_list, tag_set_list) {
blk_mq_sysfs_register_hctxs(q);
--
2.50.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH V2] blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues
2025-08-15 13:17 [PATCH V2] blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues Ming Lei
@ 2025-08-15 14:05 ` Nilay Shroff
2025-08-16 1:02 ` Yu Kuai
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Nilay Shroff @ 2025-08-15 14:05 UTC (permalink / raw)
To: Ming Lei, Jens Axboe, linux-block; +Cc: Yu Kuai
On 8/15/25 6:47 PM, Ming Lei wrote:
> Commit 5989bfe6ac6b ("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 <nilay@linux.ibm.com>
> Cc: Yu Kuai <yukuai3@huawei.com>
> Fixes: 5989bfe6ac6b ("block: restore two stage elevator switch while running nr_hw_queue update")
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
Looks good to me:
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH V2] blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues
2025-08-15 13:17 [PATCH V2] blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues Ming Lei
2025-08-15 14:05 ` Nilay Shroff
@ 2025-08-16 1:02 ` Yu Kuai
2025-08-21 4:29 ` Ming Lei
2025-08-21 11:35 ` Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Yu Kuai @ 2025-08-16 1:02 UTC (permalink / raw)
To: Ming Lei, Jens Axboe, linux-block; +Cc: Nilay Shroff, Yu Kuai
在 2025/8/15 21:17, Ming Lei 写道:
> Commit 5989bfe6ac6b ("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<nilay@linux.ibm.com>
> Cc: Yu Kuai<yukuai3@huawei.com>
> Fixes: 5989bfe6ac6b ("block: restore two stage elevator switch while running nr_hw_queue update")
> Signed-off-by: Ming Lei<ming.lei@redhat.com>
> ---
> V2:
> - fix the issue locally, so patch is simplified
>
> block/blk-mq.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
LGTM
Reviewed-by: Yu Kuai <yukuai3@huawei.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH V2] blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues
2025-08-15 13:17 [PATCH V2] blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues Ming Lei
2025-08-15 14:05 ` Nilay Shroff
2025-08-16 1:02 ` Yu Kuai
@ 2025-08-21 4:29 ` Ming Lei
2025-08-21 11:35 ` Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Ming Lei @ 2025-08-21 4:29 UTC (permalink / raw)
To: Jens Axboe, linux-block; +Cc: Nilay Shroff, Yu Kuai
On Fri, Aug 15, 2025 at 9:17 PM Ming Lei <ming.lei@redhat.com> wrote:
>
> Commit 5989bfe6ac6b ("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 <nilay@linux.ibm.com>
> Cc: Yu Kuai <yukuai3@huawei.com>
> Fixes: 5989bfe6ac6b ("block: restore two stage elevator switch while running nr_hw_queue update")
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> V2:
> - fix the issue locally, so patch is simplified
Hi Jens,
Ping...
Thanks,
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH V2] blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues
2025-08-15 13:17 [PATCH V2] blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues Ming Lei
` (2 preceding siblings ...)
2025-08-21 4:29 ` Ming Lei
@ 2025-08-21 11:35 ` Jens Axboe
3 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2025-08-21 11:35 UTC (permalink / raw)
To: linux-block, Ming Lei; +Cc: Nilay Shroff, Yu Kuai
On Fri, 15 Aug 2025 21:17:37 +0800, Ming Lei wrote:
> Commit 5989bfe6ac6b ("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.
>
> [...]
Applied, thanks!
[1/1] blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues
commit: 2d82f3bd8910eb65e30bb2a3c9b945bfb3b6d661
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-21 11:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-15 13:17 [PATCH V2] blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues Ming Lei
2025-08-15 14:05 ` Nilay Shroff
2025-08-16 1:02 ` Yu Kuai
2025-08-21 4:29 ` Ming Lei
2025-08-21 11:35 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).