From: Yu Kuai <yukuai@fnnas.com>
To: Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
Ming Lei <ming.lei@redhat.com>,
Nilay Shroff <nilay@linux.ibm.com>,
Hannes Reinecke <hare@suse.de>,
yukuai@fnnas.com
Subject: [PATCH v9 1/8] blk-wbt: factor out a helper wbt_set_lat()
Date: Mon, 2 Feb 2026 16:05:16 +0800 [thread overview]
Message-ID: <20260202080523.3947504-2-yukuai@fnnas.com> (raw)
In-Reply-To: <20260202080523.3947504-1-yukuai@fnnas.com>
To move implementation details inside blk-wbt.c, prepare to fix possible
deadlock to call wbt_init() while queue is frozen in the next patch.
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
Signed-off-by: Yu Kuai <yukuai@fnnas.com>
Reviewed-by: Hannes Reinecke <hare@suse.de>
---
block/blk-sysfs.c | 39 ++----------------------------------
block/blk-wbt.c | 50 ++++++++++++++++++++++++++++++++++++++++++++---
block/blk-wbt.h | 7 ++-----
3 files changed, 51 insertions(+), 45 deletions(-)
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index e0a70d26972b..a580688c3ad5 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -636,11 +636,8 @@ static ssize_t queue_wb_lat_show(struct gendisk *disk, char *page)
static ssize_t queue_wb_lat_store(struct gendisk *disk, const char *page,
size_t count)
{
- struct request_queue *q = disk->queue;
- struct rq_qos *rqos;
ssize_t ret;
s64 val;
- unsigned int memflags;
ret = queue_var_store64(&val, page);
if (ret < 0)
@@ -648,40 +645,8 @@ static ssize_t queue_wb_lat_store(struct gendisk *disk, const char *page,
if (val < -1)
return -EINVAL;
- /*
- * Ensure that the queue is idled, in case the latency update
- * ends up either enabling or disabling wbt completely. We can't
- * have IO inflight if that happens.
- */
- memflags = blk_mq_freeze_queue(q);
-
- rqos = wbt_rq_qos(q);
- if (!rqos) {
- ret = wbt_init(disk);
- if (ret)
- goto out;
- }
-
- ret = count;
- if (val == -1)
- val = wbt_default_latency_nsec(q);
- else if (val >= 0)
- val *= 1000ULL;
-
- if (wbt_get_min_lat(q) == val)
- goto out;
-
- blk_mq_quiesce_queue(q);
-
- mutex_lock(&disk->rqos_state_mutex);
- wbt_set_min_lat(q, val);
- mutex_unlock(&disk->rqos_state_mutex);
-
- blk_mq_unquiesce_queue(q);
-out:
- blk_mq_unfreeze_queue(q, memflags);
-
- return ret;
+ ret = wbt_set_lat(disk, val);
+ return ret ? ret : count;
}
QUEUE_RW_ENTRY(queue_wb_lat, "wbt_lat_usec");
diff --git a/block/blk-wbt.c b/block/blk-wbt.c
index 8e025834f2fb..0a37d97bda75 100644
--- a/block/blk-wbt.c
+++ b/block/blk-wbt.c
@@ -93,6 +93,8 @@ struct rq_wb {
struct rq_depth rq_depth;
};
+static int wbt_init(struct gendisk *disk);
+
static inline struct rq_wb *RQWB(struct rq_qos *rqos)
{
return container_of(rqos, struct rq_wb, rqos);
@@ -506,7 +508,7 @@ u64 wbt_get_min_lat(struct request_queue *q)
return RQWB(rqos)->min_lat_nsec;
}
-void wbt_set_min_lat(struct request_queue *q, u64 val)
+static void wbt_set_min_lat(struct request_queue *q, u64 val)
{
struct rq_qos *rqos = wbt_rq_qos(q);
if (!rqos)
@@ -741,7 +743,7 @@ void wbt_init_enable_default(struct gendisk *disk)
WARN_ON_ONCE(wbt_init(disk));
}
-u64 wbt_default_latency_nsec(struct request_queue *q)
+static u64 wbt_default_latency_nsec(struct request_queue *q)
{
/*
* We default to 2msec for non-rotational storage, and 75msec
@@ -901,7 +903,7 @@ static const struct rq_qos_ops wbt_rqos_ops = {
#endif
};
-int wbt_init(struct gendisk *disk)
+static int wbt_init(struct gendisk *disk)
{
struct request_queue *q = disk->queue;
struct rq_wb *rwb;
@@ -948,3 +950,45 @@ int wbt_init(struct gendisk *disk)
return ret;
}
+
+int wbt_set_lat(struct gendisk *disk, s64 val)
+{
+ struct request_queue *q = disk->queue;
+ unsigned int memflags;
+ struct rq_qos *rqos;
+ int ret = 0;
+
+ /*
+ * Ensure that the queue is idled, in case the latency update
+ * ends up either enabling or disabling wbt completely. We can't
+ * have IO inflight if that happens.
+ */
+ memflags = blk_mq_freeze_queue(q);
+
+ rqos = wbt_rq_qos(q);
+ if (!rqos) {
+ ret = wbt_init(disk);
+ if (ret)
+ goto out;
+ }
+
+ if (val == -1)
+ val = wbt_default_latency_nsec(q);
+ else if (val >= 0)
+ val *= 1000ULL;
+
+ if (wbt_get_min_lat(q) == val)
+ goto out;
+
+ blk_mq_quiesce_queue(q);
+
+ mutex_lock(&disk->rqos_state_mutex);
+ wbt_set_min_lat(q, val);
+ mutex_unlock(&disk->rqos_state_mutex);
+
+ blk_mq_unquiesce_queue(q);
+out:
+ blk_mq_unfreeze_queue(q, memflags);
+
+ return ret;
+}
diff --git a/block/blk-wbt.h b/block/blk-wbt.h
index 925f22475738..6e39da17218b 100644
--- a/block/blk-wbt.h
+++ b/block/blk-wbt.h
@@ -4,16 +4,13 @@
#ifdef CONFIG_BLK_WBT
-int wbt_init(struct gendisk *disk);
void wbt_init_enable_default(struct gendisk *disk);
void wbt_disable_default(struct gendisk *disk);
void wbt_enable_default(struct gendisk *disk);
u64 wbt_get_min_lat(struct request_queue *q);
-void wbt_set_min_lat(struct request_queue *q, u64 val);
-bool wbt_disabled(struct request_queue *);
-
-u64 wbt_default_latency_nsec(struct request_queue *);
+bool wbt_disabled(struct request_queue *q);
+int wbt_set_lat(struct gendisk *disk, s64 val);
#else
--
2.51.0
next prev parent reply other threads:[~2026-02-02 8:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-02 8:05 [PATCH v9 0/8] blk-mq: fix possible deadlocks Yu Kuai
2026-02-02 8:05 ` Yu Kuai [this message]
2026-02-02 8:05 ` [PATCH v9 2/8] blk-wbt: fix possible deadlock to nest pcpu_alloc_mutex under q_usage_counter Yu Kuai
2026-02-02 8:05 ` [PATCH v9 3/8] blk-mq-debugfs: factor out a helper to register debugfs for all rq_qos Yu Kuai
2026-02-02 8:05 ` [PATCH v9 4/8] blk-rq-qos: fix possible debugfs_mutex deadlock Yu Kuai
2026-02-02 8:05 ` [PATCH v9 5/8] blk-mq-debugfs: make blk_mq_debugfs_register_rqos() static Yu Kuai
2026-02-02 8:05 ` [PATCH v9 6/8] blk-mq-debugfs: remove blk_mq_debugfs_unregister_rqos() Yu Kuai
2026-02-02 8:05 ` [PATCH v9 7/8] blk-mq-debugfs: add missing debugfs_mutex in blk_mq_debugfs_register_hctxs() Yu Kuai
2026-02-02 8:05 ` [PATCH v9 8/8] blk-mq-debugfs: warn about possible deadlock Yu Kuai
2026-02-06 9:26 ` kernel test robot
2026-02-02 15:21 ` [PATCH v9 0/8] blk-mq: fix possible deadlocks 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=20260202080523.3947504-2-yukuai@fnnas.com \
--to=yukuai@fnnas.com \
--cc=axboe@kernel.dk \
--cc=hare@suse.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=nilay@linux.ibm.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®