public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chris Mason <clm@meta.com>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: Chris Mason <clm@meta.com>, <axboe@kernel.dk>,
	<nilay@linux.ibm.com>, <ming.lei@redhat.com>,
	<linux-block@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<yukuai3@huawei.com>, <yi.zhang@huawei.com>,
	<yangerkun@huawei.com>, <johnny.chenyi@huawei.com>
Subject: Re: [PATCH v2 for-6.18/block 05/10] blk-mq: cleanup shared tags case in blk_mq_update_nr_requests()
Date: Tue, 14 Oct 2025 06:05:01 -0700	[thread overview]
Message-ID: <20251014130507.4187235-2-clm@meta.com> (raw)
In-Reply-To: <20250910080445.239096-6-yukuai1@huaweicloud.com>

Hi everyone,

My review automation flagged this one in linux-next, and it looks like a
valid bug to me:

On Wed, 10 Sep 2025 16:04:40 +0800 Yu Kuai <yukuai1@huaweicloud.com> wrote:

> From: Yu Kuai <yukuai3@huawei.com>
> 
> For shared tags case, all hctx->sched_tags/tags are the same, it doesn't
> make sense to call into blk_mq_tag_update_depth() multiple times for the
> same tags.
> 

[ ... ]

> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index 9b97f2f3f2c9..80c20700bce8 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -4935,34 +4935,35 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)
>
>  	blk_mq_quiesce_queue(q);
>
> -	queue_for_each_hw_ctx(q, hctx, i) {
> -		if (!hctx->tags)
> -			continue;
> -		/*
> -		 * If we're using an MQ scheduler, just update the scheduler
> -		 * queue depth. This is similar to what the old code would do.
> -		 */
> -		if (hctx->sched_tags) {
> -			ret = blk_mq_tag_update_depth(hctx, &hctx->sched_tags,
> -						      nr);
> -		} else {
> -			ret = blk_mq_tag_update_depth(hctx, &hctx->tags, nr);
> -		}
> -		if (ret)
> -			goto out;
> -	}
> -
> -	q->nr_requests = nr;
> -	if (q->elevator && q->elevator->type->ops.depth_updated)
> -		q->elevator->type->ops.depth_updated(q);
> -
>  	if (blk_mq_is_shared_tags(set->flags)) {
>  		if (q->elevator)
>  			blk_mq_tag_update_sched_shared_tags(q);
                        ^^^^

Does blk_mq_tag_update_sched_shared_tags() use the wrong value here?

In the old code, q->nr_requests was updated to nr before calling
blk_mq_tag_update_sched_shared_tags(). But in the new code, this
function is called while q->nr_requests still contains the old value.

Looking at blk_mq_tag_update_sched_shared_tags():

    void blk_mq_tag_update_sched_shared_tags(struct request_queue *q)
    {
        sbitmap_queue_resize(&q->sched_shared_tags->bitmap_tags,
                             q->nr_requests - q->tag_set->reserved_tags);
    }

It reads q->nr_requests to calculate the new sbitmap size. With the
reordering, this will resize the sbitmap to the old depth instead of
the new depth passed in nr.

-chris

  reply	other threads:[~2025-10-14 13:06 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-10  8:04 [PATCH v2 for-6.18/block 00/10] blk-mq: cleanup and fixes for updating nr_requests Yu Kuai
2025-09-10  8:04 ` [PATCH v2 for-6.18/block 01/10] blk-mq: remove useless checking in queue_requests_store() Yu Kuai
2025-09-10  8:04 ` [PATCH v2 for-6.18/block 02/10] blk-mq: remove useless checkings in blk_mq_update_nr_requests() Yu Kuai
2025-09-10  8:04 ` [PATCH v2 for-6.18/block 03/10] blk-mq: check invalid nr_requests in queue_requests_store() Yu Kuai
2025-09-10  8:04 ` [PATCH v2 for-6.18/block 04/10] blk-mq: convert to serialize updating nr_requests with update_nr_hwq_lock Yu Kuai
2025-09-10 10:05   ` Nilay Shroff
2025-09-10  8:04 ` [PATCH v2 for-6.18/block 05/10] blk-mq: cleanup shared tags case in blk_mq_update_nr_requests() Yu Kuai
2025-10-14 13:05   ` Chris Mason [this message]
2025-10-14 18:04     ` Nilay Shroff
2025-10-15  0:56       ` Yu Kuai
2025-09-10  8:04 ` [PATCH v2 for-6.18/block 06/10] blk-mq: split bitmap grow and resize " Yu Kuai
2025-09-10 10:08   ` Nilay Shroff
2025-09-10  8:04 ` [PATCH v2 for-6.18/block 07/10] blk-mq-sched: add new parameter nr_requests in blk_mq_alloc_sched_tags() Yu Kuai
2025-09-10  8:04 ` [PATCH v2 for-6.18/block 08/10] blk-mq: fix potential deadlock while nr_requests grown Yu Kuai
2025-09-10 10:11   ` Nilay Shroff
2025-09-10  8:04 ` [PATCH v2 for-6.18/block 09/10] blk-mq: remove blk_mq_tag_update_depth() Yu Kuai
2025-09-10  8:04 ` [PATCH v2 for-6.18/block 10/10] blk-mq: fix stale nr_requests documentation Yu Kuai
2025-09-10 11:30 ` [PATCH v2 for-6.18/block 00/10] blk-mq: cleanup and fixes for updating nr_requests Jens Axboe

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=20251014130507.4187235-2-clm@meta.com \
    --to=clm@meta.com \
    --cc=axboe@kernel.dk \
    --cc=johnny.chenyi@huawei.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=nilay@linux.ibm.com \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.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