From: Ming Lei Date: Mon, 5 May 2025 14:17:47 +0000 (+0800) Subject: block: don't allow to switch elevator if updating nr_hw_queues is in-progress X-Git-Tag: v6.16-rc1~216^2~86 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b126d9d7475e3a35155f31418e54d9221b971ca1;p=thirdparty%2Flinux.git 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 Link: https://lore.kernel.org/linux-block/aAWv3NPtNIKKvJZc@fedora/ [1] Reported-by: Shinichiro Kawasaki Closes: https://lore.kernel.org/linux-block/mz4t4tlwiqjijw3zvqnjb7ovvvaegkqganegmmlc567tt5xj67@xal5ro544cnc/ Signed-off-by: Ming Lei Reviewed-by: Nilay Shroff Reviewed-by: Christoph Hellwig Link: https://lore.kernel.org/r/20250505141805.2751237-10-ming.lei@redhat.com Signed-off-by: Jens Axboe --- diff --git a/block/elevator.c b/block/elevator.c index 4400eb8fe54f1..2e18513dcd739 100644 --- a/block/elevator.c +++ b/block/elevator.c @@ -723,6 +723,7 @@ ssize_t elv_iosched_store(struct gendisk *disk, const char *buf, int ret; unsigned int memflags; struct request_queue *q = disk->queue; + struct blk_mq_tag_set *set = q->tag_set; /* * If the attribute needs to load a module, do it before freezing the @@ -734,6 +735,7 @@ ssize_t elv_iosched_store(struct gendisk *disk, const char *buf, elv_iosched_load_module(name); + down_read(&set->update_nr_hwq_lock); memflags = blk_mq_freeze_queue(q); mutex_lock(&q->elevator_lock); ret = elevator_change(q, name); @@ -741,6 +743,7 @@ ssize_t elv_iosched_store(struct gendisk *disk, const char *buf, ret = count; mutex_unlock(&q->elevator_lock); blk_mq_unfreeze_queue(q, memflags); + up_read(&set->update_nr_hwq_lock); return ret; }