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 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 <nilay@linux.ibm.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20250313115235.3707600-2-nilay@linux.ibm.com
[axboe: some commit message rewording/fixes]
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Nilay Shroff and committed by
Jens Axboe
a3996d11 75618ac6

+11 -11
+8 -8
block/blk-mq-debugfs.c
··· 400 400 struct request_queue *q = hctx->queue; 401 401 int res; 402 402 403 - res = mutex_lock_interruptible(&q->sysfs_lock); 403 + res = mutex_lock_interruptible(&q->elevator_lock); 404 404 if (res) 405 405 goto out; 406 406 if (hctx->tags) 407 407 blk_mq_debugfs_tags_show(m, hctx->tags); 408 - mutex_unlock(&q->sysfs_lock); 408 + mutex_unlock(&q->elevator_lock); 409 409 410 410 out: 411 411 return res; ··· 417 417 struct request_queue *q = hctx->queue; 418 418 int res; 419 419 420 - res = mutex_lock_interruptible(&q->sysfs_lock); 420 + res = mutex_lock_interruptible(&q->elevator_lock); 421 421 if (res) 422 422 goto out; 423 423 if (hctx->tags) 424 424 sbitmap_bitmap_show(&hctx->tags->bitmap_tags.sb, m); 425 - mutex_unlock(&q->sysfs_lock); 425 + mutex_unlock(&q->elevator_lock); 426 426 427 427 out: 428 428 return res; ··· 434 434 struct request_queue *q = hctx->queue; 435 435 int res; 436 436 437 - res = mutex_lock_interruptible(&q->sysfs_lock); 437 + res = mutex_lock_interruptible(&q->elevator_lock); 438 438 if (res) 439 439 goto out; 440 440 if (hctx->sched_tags) 441 441 blk_mq_debugfs_tags_show(m, hctx->sched_tags); 442 - mutex_unlock(&q->sysfs_lock); 442 + mutex_unlock(&q->elevator_lock); 443 443 444 444 out: 445 445 return res; ··· 451 451 struct request_queue *q = hctx->queue; 452 452 int res; 453 453 454 - res = mutex_lock_interruptible(&q->sysfs_lock); 454 + res = mutex_lock_interruptible(&q->elevator_lock); 455 455 if (res) 456 456 goto out; 457 457 if (hctx->sched_tags) 458 458 sbitmap_bitmap_show(&hctx->sched_tags->bitmap_tags.sb, m); 459 - mutex_unlock(&q->sysfs_lock); 459 + mutex_unlock(&q->elevator_lock); 460 460 461 461 out: 462 462 return res;
+3 -3
include/linux/blkdev.h
··· 566 566 * nr_requests and wbt latency, this lock also protects the sysfs attrs 567 567 * nr_requests and wbt_lat_usec. Additionally the nr_hw_queues update 568 568 * 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. 572 572 */ 573 573 struct mutex elevator_lock; 574 574