Skip to content

Commit 5e40f44

Browse files
shroffniaxboe
authored andcommitted
block: protect read_ahead_kb using q->limits_lock
The bdi->ra_pages could be updated under q->limits_lock because it's usually calculated from the queue limits by queue_limits_commit_update. So protect reading/writing the sysfs attribute read_ahead_kb using q->limits_lock instead of q->sysfs_lock. Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Ming Lei <[email protected]> Signed-off-by: Nilay Shroff <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 245618f commit 5e40f44

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

block/blk-sysfs.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ static ssize_t queue_ra_show(struct gendisk *disk, char *page)
9393
{
9494
ssize_t ret;
9595

96-
mutex_lock(&disk->queue->sysfs_lock);
96+
mutex_lock(&disk->queue->limits_lock);
9797
ret = queue_var_show(disk->bdi->ra_pages << (PAGE_SHIFT - 10), page);
98-
mutex_unlock(&disk->queue->sysfs_lock);
98+
mutex_unlock(&disk->queue->limits_lock);
9999

100100
return ret;
101101
}
@@ -111,12 +111,15 @@ queue_ra_store(struct gendisk *disk, const char *page, size_t count)
111111
ret = queue_var_store(&ra_kb, page, count);
112112
if (ret < 0)
113113
return ret;
114-
115-
mutex_lock(&q->sysfs_lock);
114+
/*
115+
* ->ra_pages is protected by ->limits_lock because it is usually
116+
* calculated from the queue limits by queue_limits_commit_update.
117+
*/
118+
mutex_lock(&q->limits_lock);
116119
memflags = blk_mq_freeze_queue(q);
117120
disk->bdi->ra_pages = ra_kb >> (PAGE_SHIFT - 10);
121+
mutex_unlock(&q->limits_lock);
118122
blk_mq_unfreeze_queue(q, memflags);
119-
mutex_unlock(&q->sysfs_lock);
120123

121124
return ret;
122125
}
@@ -670,7 +673,8 @@ static struct attribute *queue_attrs[] = {
670673
&queue_dma_alignment_entry.attr,
671674

672675
/*
673-
* Attributes which are protected with q->sysfs_lock.
676+
* Attributes which require some form of locking other than
677+
* q->sysfs_lock.
674678
*/
675679
&queue_ra_entry.attr,
676680

include/linux/blkdev.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,9 @@ struct request_queue {
571571
struct mutex elevator_lock;
572572

573573
struct mutex sysfs_lock;
574+
/*
575+
* Protects queue limits and also sysfs attribute read_ahead_kb.
576+
*/
574577
struct mutex limits_lock;
575578

576579
/*

0 commit comments

Comments
 (0)