Skip to content

Commit

Permalink
block: protect debugfs attribute method hctx_busy_show
Browse files Browse the repository at this point in the history
The hctx_busy_show method in debugfs is currently unprotected. This
method iterates over all started requests in a tagset and prints them.
However, the tags can be updated concurrently via the sysfs attributes
'nr_requests' or 'scheduler' (elevator switch), leading to potential
race conditions.

Since sysfs attributes 'nr_requests' and 'scheduler' are already
protected using q->elevator_lock, extend this protection to the debugfs
'busy' attribute as well to ensure consistency.

Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20250313115235.3707600-4-nilay@linux.ibm.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Nilay Shroff authored and Jens Axboe committed Mar 13, 2025
1 parent 78800f5 commit 0e94ed3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions block/blk-mq-debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,14 @@ static int hctx_busy_show(void *data, struct seq_file *m)
{
struct blk_mq_hw_ctx *hctx = data;
struct show_busy_params params = { .m = m, .hctx = hctx };
int res;

res = mutex_lock_interruptible(&hctx->queue->elevator_lock);
if (res)
return res;
blk_mq_tagset_busy_iter(hctx->queue->tag_set, hctx_show_busy_rq,
&params);
mutex_unlock(&hctx->queue->elevator_lock);

return 0;
}
Expand Down

0 comments on commit 0e94ed3

Please sign in to comment.