Skip to content

Commit 7569354

Browse files
author
Ming Lei
committed
block: protect wbt_lat_usec using q->elevator_lock
JIRA: https://issues.redhat.com/browse/RHEL-112997 commit 245618f Author: Nilay Shroff <nilay@linux.ibm.com> Date: Tue Mar 4 15:52:35 2025 +0530 block: protect wbt_lat_usec using q->elevator_lock The wbt latency and state could be updated while initializing the elevator or exiting the elevator. It could be also updated while configuring IO latency QoS parameters using cgroup. The elevator code path is now protected with q->elevator_lock. So we should protect the access to sysfs attribute wbt_lat_usec using q->elevator _lock instead of q->sysfs_lock. White we're at it, also protect ioc_qos_write(), which configures wbt parameters via cgroup, using q->elevator_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-7-nilay@linux.ibm.com Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Ming Lei <ming.lei@redhat.com>
1 parent 3c70398 commit 7569354

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

block/blk-iocost.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3248,6 +3248,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input,
32483248
}
32493249

32503250
memflags = blk_mq_freeze_queue(disk->queue);
3251+
mutex_lock(&disk->queue->elevator_lock);
32513252
blk_mq_quiesce_queue(disk->queue);
32523253

32533254
spin_lock_irq(&ioc->lock);
@@ -3355,6 +3356,7 @@ static ssize_t ioc_qos_write(struct kernfs_open_file *of, char *input,
33553356
spin_unlock_irq(&ioc->lock);
33563357

33573358
blk_mq_unquiesce_queue(disk->queue);
3359+
mutex_unlock(&disk->queue->elevator_lock);
33583360
blk_mq_unfreeze_queue(disk->queue, memflags);
33593361

33603362
ret = -EINVAL;

block/blk-sysfs.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ static ssize_t queue_wb_lat_show(struct gendisk *disk, char *page)
563563
ssize_t ret;
564564
struct request_queue *q = disk->queue;
565565

566-
mutex_lock(&q->sysfs_lock);
566+
mutex_lock(&q->elevator_lock);
567567
if (!wbt_rq_qos(q)) {
568568
ret = -EINVAL;
569569
goto out;
@@ -576,7 +576,7 @@ static ssize_t queue_wb_lat_show(struct gendisk *disk, char *page)
576576

577577
ret = sysfs_emit(page, "%llu\n", div_u64(wbt_get_min_lat(q), 1000));
578578
out:
579-
mutex_unlock(&q->sysfs_lock);
579+
mutex_unlock(&q->elevator_lock);
580580
return ret;
581581
}
582582

@@ -595,8 +595,8 @@ static ssize_t queue_wb_lat_store(struct gendisk *disk, const char *page,
595595
if (val < -1)
596596
return -EINVAL;
597597

598-
mutex_lock(&q->sysfs_lock);
599598
memflags = blk_mq_freeze_queue(q);
599+
mutex_lock(&q->elevator_lock);
600600

601601
rqos = wbt_rq_qos(q);
602602
if (!rqos) {
@@ -625,8 +625,8 @@ static ssize_t queue_wb_lat_store(struct gendisk *disk, const char *page,
625625

626626
blk_mq_unquiesce_queue(q);
627627
out:
628+
mutex_unlock(&q->elevator_lock);
628629
blk_mq_unfreeze_queue(q, memflags);
629-
mutex_unlock(&q->sysfs_lock);
630630

631631
return ret;
632632
}
@@ -695,19 +695,15 @@ static struct attribute *queue_attrs[] = {
695695

696696
/* Request-based queue attributes that are not relevant for bio-based queues. */
697697
static struct attribute *blk_mq_queue_attrs[] = {
698-
/*
699-
* Attributes which are protected with q->sysfs_lock.
700-
*/
701-
#ifdef CONFIG_BLK_WBT
702-
&queue_wb_lat_entry.attr,
703-
#endif
704698
/*
705699
* Attributes which require some form of locking other than
706700
* q->sysfs_lock.
707701
*/
708702
&elv_iosched_entry.attr,
709703
&queue_requests_entry.attr,
710-
704+
#ifdef CONFIG_BLK_WBT
705+
&queue_wb_lat_entry.attr,
706+
#endif
711707
/*
712708
* Attributes which don't require locking.
713709
*/
@@ -888,10 +884,10 @@ int blk_register_queue(struct gendisk *disk)
888884
goto out_crypto_sysfs_unregister;
889885
}
890886
}
887+
wbt_enable_default(disk);
891888
mutex_unlock(&q->elevator_lock);
892889

893890
blk_queue_flag_set(QUEUE_FLAG_REGISTERED, q);
894-
wbt_enable_default(disk);
895891

896892
/* Now everything is ready and send out KOBJ_ADD uevent */
897893
kobject_uevent(&disk->queue_kobj, KOBJ_ADD);

include/linux/blkdev.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,8 @@ struct request_queue {
582582
/*
583583
* Protects against I/O scheduler switching, particularly when
584584
* updating q->elevator. Since the elevator update code path may
585-
* also modify q->nr_requests, this lock also protects the sysfs
586-
* attribute nr_requests.
585+
* also modify q->nr_requests and wbt latency, this lock also
586+
* protects the sysfs attributes nr_requests and wbt_lat_usec.
587587
* To ensure proper locking order during an elevator update, first
588588
* freeze the queue, then acquire ->elevator_lock.
589589
*/

0 commit comments

Comments
 (0)