Skip to content

Commit

Permalink
Merge tag 'block-6.11-20240912' of git://git.kernel.dk/linux
Browse files Browse the repository at this point in the history
Pull block fix from Jens Axboe:
 "Just a single fix for a deadlock issue that can happen if someone
  attempts to change the root disk IO scheduler with a module that
  requires loading from disk.

  Changing the scheduler freezes the queue while that operation is
  happening, hence causing a deadlock"

* tag 'block-6.11-20240912' of git://git.kernel.dk/linux:
  block: Prevent deadlocks when switching elevators
  • Loading branch information
Linus Torvalds committed Sep 12, 2024
2 parents fdf042d + 734e1a8 commit b8e7cd0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
22 changes: 21 additions & 1 deletion block/blk-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
struct queue_sysfs_entry {
struct attribute attr;
ssize_t (*show)(struct gendisk *disk, char *page);
int (*load_module)(struct gendisk *disk, const char *page, size_t count);
ssize_t (*store)(struct gendisk *disk, const char *page, size_t count);
};

Expand Down Expand Up @@ -413,14 +414,22 @@ static struct queue_sysfs_entry _prefix##_entry = { \
.store = _prefix##_store, \
};

#define QUEUE_RW_LOAD_MODULE_ENTRY(_prefix, _name) \
static struct queue_sysfs_entry _prefix##_entry = { \
.attr = { .name = _name, .mode = 0644 }, \
.show = _prefix##_show, \
.load_module = _prefix##_load_module, \
.store = _prefix##_store, \
}

QUEUE_RW_ENTRY(queue_requests, "nr_requests");
QUEUE_RW_ENTRY(queue_ra, "read_ahead_kb");
QUEUE_RW_ENTRY(queue_max_sectors, "max_sectors_kb");
QUEUE_RO_ENTRY(queue_max_hw_sectors, "max_hw_sectors_kb");
QUEUE_RO_ENTRY(queue_max_segments, "max_segments");
QUEUE_RO_ENTRY(queue_max_integrity_segments, "max_integrity_segments");
QUEUE_RO_ENTRY(queue_max_segment_size, "max_segment_size");
QUEUE_RW_ENTRY(elv_iosched, "scheduler");
QUEUE_RW_LOAD_MODULE_ENTRY(elv_iosched, "scheduler");

QUEUE_RO_ENTRY(queue_logical_block_size, "logical_block_size");
QUEUE_RO_ENTRY(queue_physical_block_size, "physical_block_size");
Expand Down Expand Up @@ -670,6 +679,17 @@ queue_attr_store(struct kobject *kobj, struct attribute *attr,
if (!entry->store)
return -EIO;

/*
* If the attribute needs to load a module, do it before freezing the
* queue to ensure that the module file can be read when the request
* queue is the one for the device storing the module file.
*/
if (entry->load_module) {
res = entry->load_module(disk, page, length);
if (res)
return res;
}

blk_mq_freeze_queue(q);
mutex_lock(&q->sysfs_lock);
res = entry->store(disk, page, length);
Expand Down
21 changes: 15 additions & 6 deletions block/elevator.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,17 +698,26 @@ static int elevator_change(struct request_queue *q, const char *elevator_name)
return 0;

e = elevator_find_get(q, elevator_name);
if (!e) {
request_module("%s-iosched", elevator_name);
e = elevator_find_get(q, elevator_name);
if (!e)
return -EINVAL;
}
if (!e)
return -EINVAL;
ret = elevator_switch(q, e);
elevator_put(e);
return ret;
}

int elv_iosched_load_module(struct gendisk *disk, const char *buf,
size_t count)
{
char elevator_name[ELV_NAME_MAX];

if (!elv_support_iosched(disk->queue))
return -EOPNOTSUPP;

strscpy(elevator_name, buf, sizeof(elevator_name));

return request_module("%s-iosched", strstrip(elevator_name));
}

ssize_t elv_iosched_store(struct gendisk *disk, const char *buf,
size_t count)
{
Expand Down
2 changes: 2 additions & 0 deletions block/elevator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *);
Expand Down

0 comments on commit b8e7cd0

Please sign in to comment.