From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Nilay Shroff <nilay@linux.ibm.com>,
Christoph Hellwig <hch@lst.de>, Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 1/2] block: move queue quiesce into elevator_change()
Date: Wed, 7 May 2025 20:04:02 +0800 [thread overview]
Message-ID: <20250507120406.3028670-2-ming.lei@redhat.com> (raw)
In-Reply-To: <20250507120406.3028670-1-ming.lei@redhat.com>
blk_mq_freeze_queue() can't be called on quiesced queue, otherwise it may
never return if there is any queued requests.
Fix it by moving queue quiesce int elevator_change() by adding one flag to
'struct elv_change_ctx' for controlling this behavior.
Fixes: 1e44bedbc921 ("block: unifying elevator change")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/blk-sysfs.c | 5 +----
block/elevator.c | 9 +++++++++
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 386374ff655b..8be2390c3c19 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -948,11 +948,8 @@ void blk_unregister_queue(struct gendisk *disk)
blk_mq_sysfs_unregister(disk);
blk_crypto_sysfs_unregister(disk);
- if (queue_is_mq(q)) {
- blk_mq_quiesce_queue(q);
+ if (queue_is_mq(q))
elevator_set_none(q);
- blk_mq_unquiesce_queue(q);
- }
mutex_lock(&q->sysfs_lock);
disk_unregister_independent_access_ranges(disk);
diff --git a/block/elevator.c b/block/elevator.c
index f8d72bd20610..e1386b84a415 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -49,6 +49,7 @@
struct elv_change_ctx {
const char *name;
bool no_uevent;
+ bool quiesce_queue;
/* for unregistering old elevator */
struct elevator_queue *old;
@@ -658,12 +659,17 @@ static int elevator_change_done(struct request_queue *q,
*/
static int elevator_change(struct request_queue *q, struct elv_change_ctx *ctx)
{
+ bool quiesce_queue = ctx->quiesce_queue;
unsigned int memflags;
int ret = 0;
lockdep_assert_held(&q->tag_set->update_nr_hwq_lock);
+ WARN_ON_ONCE(blk_queue_quiesced(q));
+
memflags = blk_mq_freeze_queue(q);
+ if (quiesce_queue)
+ blk_mq_quiesce_queue(q);
/*
* May be called before adding disk, when there isn't any FS I/O,
* so freezing queue plus canceling dispatch work is enough to
@@ -678,6 +684,8 @@ static int elevator_change(struct request_queue *q, struct elv_change_ctx *ctx)
if (!(q->elevator && elevator_match(q->elevator->type, ctx->name)))
ret = elevator_switch(q, ctx);
mutex_unlock(&q->elevator_lock);
+ if (quiesce_queue)
+ blk_mq_unquiesce_queue(q);
blk_mq_unfreeze_queue(q, memflags);
if (!ret)
ret = elevator_change_done(q, ctx);
@@ -744,6 +752,7 @@ void elevator_set_none(struct request_queue *q)
{
struct elv_change_ctx ctx = {
.name = "none",
+ .quiesce_queue = true,
};
int err;
--
2.47.0
next prev parent reply other threads:[~2025-05-07 12:04 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 12:04 [PATCH 0/2] block: fix hang in elevator_change() and improve elevator_set_none Ming Lei
2025-05-07 12:04 ` Ming Lei [this message]
2025-05-07 13:53 ` [PATCH 1/2] block: move queue quiesce into elevator_change() Christoph Hellwig
2025-05-07 14:28 ` Ming Lei
2025-05-07 14:48 ` Ming Lei
2025-05-07 19:05 ` Nilay Shroff
2025-05-08 3:02 ` Ming Lei
2025-05-08 5:03 ` Christoph Hellwig
2025-05-08 8:03 ` Ming Lei
2025-05-07 12:04 ` [PATCH 2/2] block: avoid unnecessary queue freeze in elevator_set_none() Ming Lei
2025-05-07 13:54 ` Christoph Hellwig
2025-05-08 3:57 ` Ming Lei
2025-05-08 5:04 ` Christoph Hellwig
2025-05-08 8:16 ` Ming Lei
2025-05-07 19:20 ` Nilay Shroff
2025-05-08 4:31 ` [PATCH 0/2] block: fix hang in elevator_change() and improve elevator_set_none Shinichiro Kawasaki
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=20250507120406.3028670-2-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--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