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 6/7] blk-cgroup: don't attach a qos policy to a dead disk
Date: Thu, 19 Nov 2026 15:05:47 +0800 [thread overview]
Message-ID: <20261119070548.3125491-7-kanie@linux.alibaba.com> (raw)
In-Reply-To: <20261119070548.3125491-1-kanie@linux.alibaba.com>
blkg_conf_open_bdev() validates disk_live() once under rq_qos_mutex.
ioc_qos_write() and ioc_cost_model_write() then release that mutex,
freeze the queue and re-acquire it, so __del_gendisk() can run
rq_qos_exit() to completion in the window and detach the existing
policy. After the re-acquire, q_to_ioc() returning NULL now also means
"the policy was torn down", not just "never enabled", and the writer
calls blk_iocost_init() to attach a fresh ioc to the dead disk.
Nothing tears that ioc down again: rq_qos_exit() already ran, and for
disks on a shared queue, e.g. sd/sr, blk_mq_destroy_queue() does not
call it either. The ioc with its timer and per-cpu stats is leaked, and
QUEUE_FLAG_QOS_ENABLED is resurrected on the dead queue. The same
lazy-init pattern in blk_throtl_init() and blk_iolatency_init() is
reachable the same way once their respective config writers get the
release-freeze-reacquire treatment.
Reject a dead disk in all three init helpers.
Fixes: 7caa47151ab2 ("blkcg: implement blk-iocost")
Fixes: a3166c51702b ("blk-throttle: delay initialization until configuration")
Fixes: a13696b83da4 ("blk-iolatency: Make initialization lazy")
Cc: stable@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
block/blk-iocost.c | 3 +++
block/blk-iolatency.c | 3 +++
block/blk-throttle.c | 3 +++
3 files changed, 9 insertions(+)
diff --git a/block/blk-iocost.c b/block/blk-iocost.c
index b251ecc66d8a..f71d997f232c 100644
--- a/block/blk-iocost.c
+++ b/block/blk-iocost.c
@@ -3009,6 +3009,9 @@ static int blk_iocost_init(struct gendisk *disk)
struct ioc *ioc;
int i, cpu, ret;
+ if (test_bit(GD_DEAD, &disk->state))
+ return -ENODEV;
+
/* The caller holds rq_qos_mutex, which is taken with the queue frozen */
ioc = kzalloc_obj(*ioc, GFP_NOIO);
if (!ioc)
diff --git a/block/blk-iolatency.c b/block/blk-iolatency.c
index a3bd153c67be..553f2091730f 100644
--- a/block/blk-iolatency.c
+++ b/block/blk-iolatency.c
@@ -761,6 +761,9 @@ static int blk_iolatency_init(struct gendisk *disk)
struct blk_iolatency *blkiolat;
int ret;
+ if (test_bit(GD_DEAD, &disk->state))
+ return -ENODEV;
+
/* The caller holds rq_qos_mutex, which is taken with the queue frozen */
blkiolat = kzalloc_obj(*blkiolat, GFP_NOIO);
if (!blkiolat)
diff --git a/block/blk-throttle.c b/block/blk-throttle.c
index c5e26551956a..374ac75832ea 100644
--- a/block/blk-throttle.c
+++ b/block/blk-throttle.c
@@ -1322,6 +1322,9 @@ static int blk_throtl_init(struct gendisk *disk)
unsigned int memflags;
int ret;
+ if (test_bit(GD_DEAD, &disk->state))
+ return -ENODEV;
+
/* The caller holds rq_qos_mutex, which is taken with the queue frozen */
td = kzalloc_node(sizeof(*td), GFP_NOIO, q->node);
if (!td)
--
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 ` [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 ` Guixin Liu [this message]
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-7-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