linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block: elevator: avoid to load iosched module from this disk
@ 2024-09-07  1:43 Ming Lei
  2024-09-07  7:35 ` Richard W.M. Jones
  0 siblings, 1 reply; 20+ messages in thread
From: Ming Lei @ 2024-09-07  1:43 UTC (permalink / raw)
  To: Jens Axboe, linux-block; +Cc: Ming Lei, Richard Jones, Jeff Moyer, Jiri Jaburek

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


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2024-09-09  2:17 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-07  1:43 [PATCH] block: elevator: avoid to load iosched module from this disk Ming Lei
2024-09-07  7:35 ` 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

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).