Linux block layer
 help / color / mirror / Atom feed
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 7/7] blk-mq: unpublish the tags before deferring their free to SRCU
Date: Thu, 19 Nov 2026 15:05:48 +0800	[thread overview]
Message-ID: <20261119070548.3125491-8-kanie@linux.alibaba.com> (raw)
In-Reply-To: <20261119070548.3125491-1-kanie@linux.alibaba.com>

__blk_mq_free_map_and_rqs() frees set->tags[hctx_idx] first, which
starts the tags_srcu grace period, and only then stores NULL into the
slot. The store is a plain store, unordered against the plain load in
blk_mq_tagset_busy_iter(), which reads set->tags[i] to find the tags to
walk. A reader that enters the SRCU read side after the grace period
snapshot, but still loads the old, non-NULL pointer, is not waited for
by that grace period, so blk_mq_free_tags_callback() can free the tags
and everything they point to while the iterator is about to walk them.

blk_mq_tagset_busy_iter() is reachable from the nvme and scsi timeout
and error recovery paths without any queue freeze gating the free, so
nothing else serializes the two.

Clear set->tags[hctx_idx] before blk_mq_free_map_and_rqs(), so a reader
either sees NULL and skips the tags, or loads the pointer before
entering the SRCU read side, in which case the grace period waits for
it.

Fixes: 995412e23bb25 ("blk-mq: Replace tags->lock with SRCU for tag iterators")
Cc: stable@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
 block/blk-mq.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 87c1ccdf66ab..b58f73256202 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -4179,10 +4179,11 @@ void blk_mq_free_map_and_rqs(struct blk_mq_tag_set *set,
 static void __blk_mq_free_map_and_rqs(struct blk_mq_tag_set *set,
 				      unsigned int hctx_idx)
 {
-	if (!blk_mq_is_shared_tags(set->flags))
-		blk_mq_free_map_and_rqs(set, set->tags[hctx_idx], hctx_idx);
+	struct blk_mq_tags *tags = set->tags[hctx_idx];
 
 	set->tags[hctx_idx] = NULL;
+	if (!blk_mq_is_shared_tags(set->flags))
+		blk_mq_free_map_and_rqs(set, tags, hctx_idx);
 }
 
 static void blk_mq_map_swqueue(struct request_queue *q)
-- 
2.43.7


      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 ` [PATCH 1/7] blk-mq: free the rqs arrays of tags in the SRCU callback Guixin Liu
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 ` Guixin Liu [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=20261119070548.3125491-8-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