Skip to content

Commit b126d9d

Browse files
Ming Leiaxboe
authored andcommitted
block: don't allow to switch elevator if updating nr_hw_queues is in-progress
Elevator switch code is another `nr_hw_queue` reader in non-fast-IO code path, so it can't be done if updating `nr_hw_queues` is in-progress. Take same approach with not allowing add/del disk when updating nr_hw_queues is in-progress, by grabbing read lock of set->update_nr_hwq_sema. Reviewed-by: Hannes Reinecke <hare@suse.de> Link: https://lore.kernel.org/linux-block/aAWv3NPtNIKKvJZc@fedora/ [1] Reported-by: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com> Closes: https://lore.kernel.org/linux-block/mz4t4tlwiqjijw3zvqnjb7ovvvaegkqganegmmlc567tt5xj67@xal5ro544cnc/ Signed-off-by: Ming Lei <ming.lei@redhat.com> Reviewed-by: Nilay Shroff <nilay@linux.ibm.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20250505141805.2751237-10-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 98e68f6 commit b126d9d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

block/elevator.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ ssize_t elv_iosched_store(struct gendisk *disk, const char *buf,
723723
int ret;
724724
unsigned int memflags;
725725
struct request_queue *q = disk->queue;
726+
struct blk_mq_tag_set *set = q->tag_set;
726727

727728
/*
728729
* If the attribute needs to load a module, do it before freezing the
@@ -734,13 +735,15 @@ ssize_t elv_iosched_store(struct gendisk *disk, const char *buf,
734735

735736
elv_iosched_load_module(name);
736737

738+
down_read(&set->update_nr_hwq_lock);
737739
memflags = blk_mq_freeze_queue(q);
738740
mutex_lock(&q->elevator_lock);
739741
ret = elevator_change(q, name);
740742
if (!ret)
741743
ret = count;
742744
mutex_unlock(&q->elevator_lock);
743745
blk_mq_unfreeze_queue(q, memflags);
746+
up_read(&set->update_nr_hwq_lock);
744747
return ret;
745748
}
746749

0 commit comments

Comments
 (0)