From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Ming Lei <ming.lei@redhat.com>, Richard Jones <rjones@redhat.com>,
Jeff Moyer <jmoyer@redhat.com>,
Jiri Jaburek <jjaburek@redhat.com>
Subject: [PATCH] block: elevator: avoid to load iosched module from this disk
Date: Sat, 7 Sep 2024 09:43:31 +0800 [thread overview]
Message-ID: <20240907014331.176152-1-ming.lei@redhat.com> (raw)
When switching io scheduler via sysfs, 'request_module' may be called
if the specified scheduler doesn't exist.
This was has deadlock risk because the module may be stored on FS behind
our disk since request queue is frozen before switching its elevator.
Fix it by returning -EDEADLK in case that the disk is claimed, which
can be thought as one signal that the disk is mounted.
Some distributions(Fedora) simulates the original kernel command line of
'elevator=foo' via 'echo foo > /sys/block/$DISK/queue/scheduler', and boot
hang is triggered.
Cc: Richard Jones <rjones@redhat.com>
Cc: Jeff Moyer <jmoyer@redhat.com>
Cc: Jiri Jaburek <jjaburek@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
block/elevator.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/block/elevator.c b/block/elevator.c
index f13d552a32c8..2b0432f4ac33 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -676,6 +676,13 @@ void elevator_disable(struct request_queue *q)
blk_mq_unfreeze_queue(q);
}
+static bool disk_is_claimed(struct gendisk *disk)
+{
+ if (disk->part0->bd_holder)
+ return true;
+ return false;
+}
+
/*
* Switch this queue to the given IO scheduler.
*/
@@ -699,6 +706,13 @@ static int elevator_change(struct request_queue *q, const char *elevator_name)
e = elevator_find_get(q, elevator_name);
if (!e) {
+ /*
+ * Try to avoid to load iosched module from FS behind our
+ * disk, otherwise deadlock may be triggered
+ */
+ if (disk_is_claimed(q->disk))
+ return -EDEADLK;
+
request_module("%s-iosched", elevator_name);
e = elevator_find_get(q, elevator_name);
if (!e)
--
2.46.0
next reply other threads:[~2024-09-07 1:43 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-07 1:43 Ming Lei [this message]
2024-09-07 7:35 ` [PATCH] block: elevator: avoid to load iosched module from this disk Richard W.M. Jones
2024-09-07 7:58 ` Ming Lei
2024-09-07 9:04 ` Damien Le Moal
2024-09-07 9:48 ` Ming Lei
2024-09-07 10:02 ` Richard W.M. Jones
2024-09-07 10:07 ` Ming Lei
2024-09-07 10:36 ` Richard W.M. Jones
2024-09-07 11:01 ` Richard W.M. Jones
2024-09-07 11:02 ` Ming Lei
2024-09-07 11:14 ` Richard W.M. Jones
2024-09-08 0:02 ` Damien Le Moal
2024-09-09 1:00 ` Ming Lei
2024-09-09 1:01 ` Ming Lei
2024-09-07 9:53 ` Richard W.M. Jones
2024-09-07 13:50 ` Jens Axboe
2024-09-09 1:24 ` Ming Lei
2024-09-09 1:56 ` Damien Le Moal
2024-09-09 1:59 ` Damien Le Moal
2024-09-09 2:16 ` Ming Lei
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=20240907014331.176152-1-ming.lei@redhat.com \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=jjaburek@redhat.com \
--cc=jmoyer@redhat.com \
--cc=linux-block@vger.kernel.org \
--cc=rjones@redhat.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;
as well as URLs for NNTP newsgroup(s).