diff mbox series

[PATCHv2,4/6] blk-sysfs: protect nr_requests update using q->elevator_lock

Message ID 20250218082908.265283-5-nilay@linux.ibm.com (mailing list archive)
State New
Headers show
Series block: fix lock order and remove redundant locking | expand

Commit Message

Nilay Shroff Feb. 18, 2025, 8:28 a.m. UTC
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 path now runs holding q->elevator_
lock. So we should now protect access to sysfs attribute nr_requests
using q->elevator_lock instead of q->sysfs_lock.

Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
 block/blk-sysfs.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 355dfb514712..37ac73468d4e 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -59,10 +59,11 @@  queue_var_store(unsigned long *var, const char *page, size_t count)
 static ssize_t queue_requests_show(struct gendisk *disk, char *page)
 {
 	int ret;
+	struct request_queue *q = disk->queue;
 
-	mutex_lock(&disk->queue->sysfs_lock);
-	ret = queue_var_show(disk->queue->nr_requests, page);
-	mutex_unlock(&disk->queue->sysfs_lock);
+	mutex_lock(&q->elevator_lock);
+	ret = queue_var_show(q->nr_requests, page);
+	mutex_unlock(&q->elevator_lock);
 
 	return ret;
 }
@@ -75,8 +76,8 @@  queue_requests_store(struct gendisk *disk, const char *page, size_t count)
 	unsigned int memflags;
 	struct request_queue *q = disk->queue;
 
-	mutex_lock(&q->sysfs_lock);
 	memflags = blk_mq_freeze_queue(q);
+	mutex_lock(&q->elevator_lock);
 
 	if (!queue_is_mq(disk->queue)) {
 		ret = -EINVAL;
@@ -94,8 +95,9 @@  queue_requests_store(struct gendisk *disk, const char *page, size_t count)
 	if (err)
 		ret = err;
 out:
+	mutex_unlock(&q->elevator_lock);
 	blk_mq_unfreeze_queue(q, memflags);
-	mutex_unlock(&q->sysfs_lock);
+
 	return ret;
 }