From: "Zqiang" <qiang.zhang@linux.dev>
To: axboe@kernel.dk, tom.leiming@gmail.com
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] blk-mq: Fix missed srcu_barrier() calls before cleanup_srcu_struct()
Date: Sun, 11 Oct 2026 09:01:33 +0000 [thread overview]
Message-ID: <92f5338ea2715d7a863002f1244151c6ff9efe5f@linux.dev> (raw)
In-Reply-To: <20260820095716.21528-1-qiang.zhang@linux.dev>
Friendly ping :)
Thanks
Zqiang
>
> In blk_mq_alloc_tag_set(), if blk_mq_alloc_set_map_and_rqs() fails
> after some hardware queues have already been allocated, its unwind
> path frees the partially allocated maps and tags through invoke the
> blk_mq_free_map_and_rqs()->blk_mq_free_tags(), which issues call_srcu()
> against set->tags_srcu. control then returns to blk_mq_alloc_tag_set()
> and falls through to the out_cleanup_tags_srcu label, which calls
> cleanup_srcu_struct() directly.
>
> Calling cleanup_srcu_struct() while call_srcu() callbacks are still
> outstanding is illegal, it triggers a WARN and tears down the
> srcu_struct while the pending blk_mq_free_tags_callback() still
> references it, leading to a use-after-free.
>
> The normal teardown path in blk_mq_free_tag_set() already guards
> against this by calling srcu_barrier() before cleanup_srcu_struct(),
> but the error path in blk_mq_alloc_tag_set() was missing the same
> barrier. this commit therefore also add srcu_barrier(&set->tags_srcu)
> call so that all outstanding SRCU callbacks complete before the
> srcu_struct is destroyed.
>
> Fixes: ad0d05dbddc1 ("blk-mq: Defer freeing of tags page_list to SRCU callback")
> Signed-off-by: Zqiang <qiang.zhang@linux.dev>
> ---
> block/blk-mq.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index 2c850330a32b..59cd629b37d5 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -4924,6 +4924,7 @@ int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)
> }
> kfree(set->tags);
> set->tags = NULL;
> + srcu_barrier(&set->tags_srcu);
> out_cleanup_tags_srcu:
> cleanup_srcu_struct(&set->tags_srcu);
> out_cleanup_srcu:
> --
> 2.17.1
>
prev parent reply other threads:[~2026-10-11 9:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 9:57 Zqiang
2026-10-11 9:01 ` Zqiang [this message]
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=92f5338ea2715d7a863002f1244151c6ff9efe5f@linux.dev \
--to=qiang.zhang@linux.dev \
--cc=axboe@kernel.dk \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tom.leiming@gmail.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
all inboxes | Powered by JetHome®