Skip to content

Commit a3996d1

Browse files
shroffniaxboe
authored andcommitted
block: protect debugfs attrs using elevator_lock instead of sysfs_lock
Currently, the block debugfs attributes (tags, tags_bitmap, sched_tags, and sched_tags_bitmap) are protected using q->sysfs_lock. However, these attributes are updated in multiple scenarios: - During driver probe method - During an elevator switch/update - During an nr_hw_queues update - When writing to the sysfs attribute nr_requests All these update paths (except driver probe method, which doesn't require any protection) are already protected using q->elevator_lock. To ensure consistency and proper synchronization, replace q->sysfs_lock with q->elevator_lock for protecting these debugfs attributes. Signed-off-by: Nilay Shroff <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] [axboe: some commit message rewording/fixes] Signed-off-by: Jens Axboe <[email protected]>
1 parent 75618ac commit a3996d1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

block/blk-mq-debugfs.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,12 @@ static int hctx_tags_show(void *data, struct seq_file *m)
400400
struct request_queue *q = hctx->queue;
401401
int res;
402402

403-
res = mutex_lock_interruptible(&q->sysfs_lock);
403+
res = mutex_lock_interruptible(&q->elevator_lock);
404404
if (res)
405405
goto out;
406406
if (hctx->tags)
407407
blk_mq_debugfs_tags_show(m, hctx->tags);
408-
mutex_unlock(&q->sysfs_lock);
408+
mutex_unlock(&q->elevator_lock);
409409

410410
out:
411411
return res;
@@ -417,12 +417,12 @@ static int hctx_tags_bitmap_show(void *data, struct seq_file *m)
417417
struct request_queue *q = hctx->queue;
418418
int res;
419419

420-
res = mutex_lock_interruptible(&q->sysfs_lock);
420+
res = mutex_lock_interruptible(&q->elevator_lock);
421421
if (res)
422422
goto out;
423423
if (hctx->tags)
424424
sbitmap_bitmap_show(&hctx->tags->bitmap_tags.sb, m);
425-
mutex_unlock(&q->sysfs_lock);
425+
mutex_unlock(&q->elevator_lock);
426426

427427
out:
428428
return res;
@@ -434,12 +434,12 @@ static int hctx_sched_tags_show(void *data, struct seq_file *m)
434434
struct request_queue *q = hctx->queue;
435435
int res;
436436

437-
res = mutex_lock_interruptible(&q->sysfs_lock);
437+
res = mutex_lock_interruptible(&q->elevator_lock);
438438
if (res)
439439
goto out;
440440
if (hctx->sched_tags)
441441
blk_mq_debugfs_tags_show(m, hctx->sched_tags);
442-
mutex_unlock(&q->sysfs_lock);
442+
mutex_unlock(&q->elevator_lock);
443443

444444
out:
445445
return res;
@@ -451,12 +451,12 @@ static int hctx_sched_tags_bitmap_show(void *data, struct seq_file *m)
451451
struct request_queue *q = hctx->queue;
452452
int res;
453453

454-
res = mutex_lock_interruptible(&q->sysfs_lock);
454+
res = mutex_lock_interruptible(&q->elevator_lock);
455455
if (res)
456456
goto out;
457457
if (hctx->sched_tags)
458458
sbitmap_bitmap_show(&hctx->sched_tags->bitmap_tags.sb, m);
459-
mutex_unlock(&q->sysfs_lock);
459+
mutex_unlock(&q->elevator_lock);
460460

461461
out:
462462
return res;

include/linux/blkdev.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,9 @@ struct request_queue {
566566
* nr_requests and wbt latency, this lock also protects the sysfs attrs
567567
* nr_requests and wbt_lat_usec. Additionally the nr_hw_queues update
568568
* may modify hctx tags, reserved-tags and cpumask, so this lock also
569-
* helps protect the hctx attrs. To ensure proper locking order during
570-
* an elevator or nr_hw_queue update, first freeze the queue, then
571-
* acquire ->elevator_lock.
569+
* helps protect the hctx sysfs/debugfs attrs. To ensure proper locking
570+
* order during an elevator or nr_hw_queue update, first freeze the
571+
* queue, then acquire ->elevator_lock.
572572
*/
573573
struct mutex elevator_lock;
574574

0 commit comments

Comments
 (0)