Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

block: protect nr_requests update using q->elevator_lock

The sysfs attribute nr_requests could be simultaneously updated from
elevator switch/update or nr_hw_queue update code path. The update to
nr_requests for each of those code paths runs holding q->elevator_lock.
So we should protect access to sysfs attribute nr_requests using q->
elevator_lock instead of q->sysfs_lock.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
Link: https://lore.kernel.org/r/20250304102551.2533767-6-nilay@linux.ibm.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Nilay Shroff and committed by
Jens Axboe
3efe7571 1bf70d08

+11 -9
+5 -5
block/blk-sysfs.c
··· 55 55 { 56 56 ssize_t ret; 57 57 58 - mutex_lock(&disk->queue->sysfs_lock); 58 + mutex_lock(&disk->queue->elevator_lock); 59 59 ret = queue_var_show(disk->queue->nr_requests, page); 60 - mutex_unlock(&disk->queue->sysfs_lock); 60 + mutex_unlock(&disk->queue->elevator_lock); 61 61 return ret; 62 62 } 63 63 ··· 76 76 if (ret < 0) 77 77 return ret; 78 78 79 - mutex_lock(&q->sysfs_lock); 80 79 memflags = blk_mq_freeze_queue(q); 80 + mutex_lock(&q->elevator_lock); 81 81 if (nr < BLKDEV_MIN_RQ) 82 82 nr = BLKDEV_MIN_RQ; 83 83 84 84 err = blk_mq_update_nr_requests(disk->queue, nr); 85 85 if (err) 86 86 ret = err; 87 + mutex_unlock(&q->elevator_lock); 87 88 blk_mq_unfreeze_queue(q, memflags); 88 - mutex_unlock(&q->sysfs_lock); 89 89 return ret; 90 90 } 91 91 ··· 692 692 /* 693 693 * Attributes which are protected with q->sysfs_lock. 694 694 */ 695 - &queue_requests_entry.attr, 696 695 #ifdef CONFIG_BLK_WBT 697 696 &queue_wb_lat_entry.attr, 698 697 #endif ··· 700 701 * q->sysfs_lock. 701 702 */ 702 703 &elv_iosched_entry.attr, 704 + &queue_requests_entry.attr, 703 705 704 706 /* 705 707 * Attributes which don't require locking.
+6 -4
include/linux/blkdev.h
··· 561 561 struct list_head flush_list; 562 562 563 563 /* 564 - * Protects against I/O scheduler switching, specifically when 565 - * updating q->elevator. To ensure proper locking order during 566 - * an elevator update, first freeze the queue, then acquire 567 - * ->elevator_lock. 564 + * Protects against I/O scheduler switching, particularly when 565 + * updating q->elevator. Since the elevator update code path may 566 + * also modify q->nr_requests, this lock also protects the sysfs 567 + * attribute nr_requests. 568 + * To ensure proper locking order during an elevator update, first 569 + * freeze the queue, then acquire ->elevator_lock. 568 570 */ 569 571 struct mutex elevator_lock; 570 572