diff options
author | Damien Le Moal <dlemoal@kernel.org> | 2024-09-08 03:07:04 +0300 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2024-09-10 22:43:42 +0300 |
commit | 734e1a8603128ac31526c477a39456be5f4092b6 (patch) | |
tree | ea68a92fd5f2fe2fcd2d0e03756c0bf6e5b7f0c6 /block/elevator.h | |
parent | 4ba032bc71dad8d604d308afffaa16b81816c751 (diff) | |
download | linux-734e1a8603128ac31526c477a39456be5f4092b6.tar.xz |
block: Prevent deadlocks when switching elevators
Commit af2814149883 ("block: freeze the queue in queue_attr_store")
changed queue_attr_store() to always freeze a sysfs attribute queue
before calling the attribute store() method, to ensure that no IOs are
in-flight when an attribute value is being updated.
However, this change created a potential deadlock situation for the
scheduler queue attribute as changing the queue elevator with
elv_iosched_store() can result in a call to request_module() if the user
requested module is not already registered. If the file of the requested
module is stored on the block device of the frozen queue, a deadlock
will happen as the read operations triggered by request_module() will
wait for the queue freeze to end.
Solve this issue by introducing the load_module method in struct
queue_sysfs_entry, and to calling this method function in
queue_attr_store() before freezing the attribute queue.
The macro definition QUEUE_RW_LOAD_MODULE_ENTRY() is added to define a
queue sysfs attribute that needs loading a module.
The definition of the scheduler atrribute is changed to using
QUEUE_RW_LOAD_MODULE_ENTRY(), with the function
elv_iosched_load_module() defined as the load_module method.
elv_iosched_store() can then be simplified to remove the call to
request_module().
Reported-by: Richard W.M. Jones <rjones@redhat.com>
Reported-by: Jiri Jaburek <jjaburek@redhat.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219166
Fixes: af2814149883 ("block: freeze the queue in queue_attr_store")
Cc: stable@vger.kernel.org
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Tested-by: Richard W.M. Jones <rjones@redhat.com>
Link: https://lore.kernel.org/r/20240908000704.414538-1-dlemoal@kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/elevator.h')
-rw-r--r-- | block/elevator.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/block/elevator.h b/block/elevator.h index 3fe18e1a8692..2a78544bf201 100644 --- a/block/elevator.h +++ b/block/elevator.h @@ -148,6 +148,8 @@ extern void elv_unregister(struct elevator_type *); * io scheduler sysfs switching */ ssize_t elv_iosched_show(struct gendisk *disk, char *page); +int elv_iosched_load_module(struct gendisk *disk, const char *page, + size_t count); ssize_t elv_iosched_store(struct gendisk *disk, const char *page, size_t count); extern bool elv_bio_merge_ok(struct request *, struct bio *); |