Linux block layer
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, Nilay Shroff <nilay@linux.ibm.com>,
	"yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH] blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues
Date: Fri, 15 Aug 2025 17:38:10 +0800	[thread overview]
Message-ID: <aJ8AAiINKj-3c1Xw@fedora> (raw)
In-Reply-To: <b4183646-a5cf-1f29-5451-c63fdda7c490@huaweicloud.com>

On Fri, Aug 15, 2025 at 05:34:23PM +0800, Yu Kuai wrote:
> Hi,
> 
> 在 2025/08/15 17:15, Yu Kuai 写道:
> > Will it be simpler if we move blk_mq_freeze_queue_nomemsave() into
> > blk_mq_elv_switch_none(), after elevator is succeed switching to none
> > then freeze the queue.
> > 
> > Later in blk_mq_elv_switch_back we'll know if xa_load() return valid
> > elevator_type, related queue is already freezed.
> 
> Like following:
> 
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index e9f037a25fe3..3640fae5707b 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -5010,7 +5010,13 @@ static int blk_mq_elv_switch_none(struct
> request_queue *q,
>                 __elevator_get(q->elevator->type);
> 
>                 elevator_set_none(q);
> +       } else {
> +               ret = xa_insert(elv_tbl, q->id, xa_mk_value(1), GFP_KERNEL);
> +               if (WARN_ON_ONCE(ret))
> +                       return ret;
>         }
> +
> +       blk_mq_freeze_queue_nomemsave(q);
>         return ret;
>  }
> 
> @@ -5045,9 +5051,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
> diff --git a/block/elevator.c b/block/elevator.c
> index e2ebfbf107b3..9400ea9ec024 100644
> --- a/block/elevator.c
> +++ b/block/elevator.c
> @@ -715,16 +715,21 @@ void elv_update_nr_hw_queues(struct request_queue *q,
> struct elevator_type *e,
> 
>         WARN_ON_ONCE(q->mq_freeze_depth == 0);
> 
> -       if (e && !blk_queue_dying(q) && blk_queue_registered(q)) {
> -               ctx.name = e->elevator_name;
> -               ctx.et = t;
> -
> -               mutex_lock(&q->elevator_lock);
> -               /* force to reattach elevator after nr_hw_queue is updated
> */
> -               ret = elevator_switch(q, &ctx);
> -               mutex_unlock(&q->elevator_lock);
> +       if (e) {
> +               if (!xa_is_value(e) && !blk_queue_dying(q) &&
> +                   blk_queue_registered(q)) {
> +                       ctx.name = e->elevator_name;
> +                       ctx.et = t;
> +
> +                       mutex_lock(&q->elevator_lock);
> +                       /* force to reattach elevator after nr_hw_queue is
> updated */
> +                       ret = elevator_switch(q, &ctx);
> +                       mutex_unlock(&q->elevator_lock);
> +               }
> +
> +               blk_mq_unfreeze_queue_nomemrestore(q);
>         }
> -       blk_mq_unfreeze_queue_nomemrestore(q);
> +

I feel it doesn't become simpler, :-(

However we still can avoid the change in elv_update_nr_hw_queues() by moving
freeze/unfree queue to blk_mq_elv_switch_back(), which looks more readable.



Thanks, 
Ming


  reply	other threads:[~2025-08-15  9:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-15  7:56 [PATCH] blk-mq: fix lockdep warning in __blk_mq_update_nr_hw_queues Ming Lei
2025-08-15  9:15 ` Yu Kuai
2025-08-15  9:34   ` Yu Kuai
2025-08-15  9:38     ` Ming Lei [this message]
2025-08-15 10:06       ` Nilay Shroff
2025-08-15 12:58         ` Ming Lei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aJ8AAiINKj-3c1Xw@fedora \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=nilay@linux.ibm.com \
    --cc=yukuai1@huaweicloud.com \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox