From: Guixin Liu <kanie@linux.alibaba.com>
To: Jens Axboe <axboe@kernel.dk>, Christoph Hellwig <hch@lst.de>,
Tejun Heo <tj@kernel.org>, Josef Bacik <josef@toxicpanda.com>,
Nilay Shroff <nilay@linux.ibm.com>,
Ming Lei <ming.lei@redhat.com>, Hannes Reinecke <hare@suse.de>
Cc: linux-block@vger.kernel.org
Subject: [PATCH 1/7] blk-mq: free the rqs arrays of tags in the SRCU callback
Date: Thu, 19 Nov 2026 15:05:42 +0800 [thread overview]
Message-ID: <20261119070548.3125491-2-kanie@linux.alibaba.com> (raw)
In-Reply-To: <20261119070548.3125491-1-kanie@linux.alibaba.com>
struct blk_mq_tags and the requests are kept alive until the iterators
under tags_srcu are gone, and the bitmaps were recently moved into that
SRCU callback as well, but the tags->rqs[] and tags->static_rqs[] arrays
are still freed right away by blk_mq_free_rq_map(). An iterator holding
a tags pointer dereferences both arrays per set bit, e.g.
blk_mq_find_and_get_req(), so when the number of hardware queues shrinks
the arrays can be freed while blk_mq_tagset_busy_iter() is about to walk
them.
Free both arrays in the SRCU callback together with the bitmaps. With
that blk_mq_free_rq_map() is a trivial wrapper of blk_mq_free_tags(),
so drop it and call blk_mq_free_tags() directly.
Fixes: 995412e23bb2 ("blk-mq: Replace tags->lock with SRCU for tag iterators")
Fixes: ad0d05dbddc1 ("blk-mq: Defer freeing of tags page_list to SRCU callback")
Cc: stable@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
block/blk-mq-tag.c | 2 ++
block/blk-mq.c | 18 +++---------------
block/blk-mq.h | 1 -
3 files changed, 5 insertions(+), 16 deletions(-)
diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index 3515031b3226..ee5413ebab01 100644
--- a/block/blk-mq-tag.c
+++ b/block/blk-mq-tag.c
@@ -611,6 +611,8 @@ static void blk_mq_free_tags_callback(struct rcu_head *head)
kmemleak_free(page_address(page));
__free_pages(page, page->private);
}
+ kfree(tags->rqs);
+ kfree(tags->static_rqs);
/* An iterator may walk the bitmaps for as long as it may see the tags */
sbitmap_queue_free(&tags->bitmap_tags);
sbitmap_queue_free(&tags->breserved_tags);
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 5ae22d556540..ae12f2a52cc9 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -3532,16 +3532,6 @@ void blk_mq_free_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags,
*/
}
-void blk_mq_free_rq_map(struct blk_mq_tags *tags)
-{
- kfree(tags->rqs);
- tags->rqs = NULL;
- kfree(tags->static_rqs);
- tags->static_rqs = NULL;
-
- blk_mq_free_tags(tags);
-}
-
static enum hctx_type hctx_idx_to_type(struct blk_mq_tag_set *set,
unsigned int hctx_idx)
{
@@ -3594,12 +3584,10 @@ static struct blk_mq_tags *blk_mq_alloc_rq_map(struct blk_mq_tag_set *set,
GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY,
node);
if (!tags->static_rqs)
- goto err_free_rqs;
+ goto err_free_tags;
return tags;
-err_free_rqs:
- kfree(tags->rqs);
err_free_tags:
blk_mq_free_tags(tags);
return NULL;
@@ -4155,7 +4143,7 @@ struct blk_mq_tags *blk_mq_alloc_map_and_rqs(struct blk_mq_tag_set *set,
ret = blk_mq_alloc_rqs(set, tags, hctx_idx, depth);
if (ret) {
- blk_mq_free_rq_map(tags);
+ blk_mq_free_tags(tags);
return NULL;
}
@@ -4183,7 +4171,7 @@ void blk_mq_free_map_and_rqs(struct blk_mq_tag_set *set,
{
if (tags) {
blk_mq_free_rqs(set, tags, hctx_idx);
- blk_mq_free_rq_map(tags);
+ blk_mq_free_tags(tags);
}
}
diff --git a/block/blk-mq.h b/block/blk-mq.h
index 1e64236d34d4..ba7bd917c361 100644
--- a/block/blk-mq.h
+++ b/block/blk-mq.h
@@ -62,7 +62,6 @@ void blk_mq_put_rq_ref(struct request *rq);
*/
void blk_mq_free_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags,
unsigned int hctx_idx);
-void blk_mq_free_rq_map(struct blk_mq_tags *tags);
struct blk_mq_tags *blk_mq_alloc_map_and_rqs(struct blk_mq_tag_set *set,
unsigned int hctx_idx, unsigned int depth);
void blk_mq_free_map_and_rqs(struct blk_mq_tag_set *set,
--
2.43.7
next prev parent reply other threads:[~2026-11-19 7:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 7:05 [PATCH 0/7] block fixes found by code inspection Guixin Liu
2026-11-19 7:05 ` Guixin Liu [this message]
2026-11-19 7:05 ` [PATCH 2/7] blk-mq: clear stale stopped flag on hctx reuse Guixin Liu
2026-11-19 7:05 ` [PATCH 3/7] blk-iocost: don't take rq_qos_mutex before the queue is frozen in cost model write Guixin Liu
2026-11-19 7:05 ` [PATCH 4/7] blk-iocost: unfreeze the queue before dropping the bdev reference in qos write Guixin Liu
2026-11-19 7:05 ` [PATCH 5/7] blk-stat: account for the mean of the source in blk_rq_stat_sum() Guixin Liu
2026-11-19 7:05 ` [PATCH 6/7] blk-cgroup: don't attach a qos policy to a dead disk Guixin Liu
2026-11-19 7:05 ` [PATCH 7/7] blk-mq: unpublish the tags before deferring their free to SRCU Guixin Liu
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=20261119070548.3125491-2-kanie@linux.alibaba.com \
--to=kanie@linux.alibaba.com \
--cc=axboe@kernel.dk \
--cc=hare@suse.de \
--cc=hch@lst.de \
--cc=josef@toxicpanda.com \
--cc=linux-block@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=nilay@linux.ibm.com \
--cc=tj@kernel.org \
/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