Commit c268ffdd authored by Yu Kuai's avatar Yu Kuai
Browse files

block: protect blk_mq_debugfs_register/unregister_hctx() with 'debugfs_mutex'

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IAGRKP


CVE: NA

----------------------------------------

All operations to create and remove files under 'q->debugfs_dir' should
be protected by 'q->debugfs_mutex'.

Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
parent f60ba77c
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -881,6 +881,8 @@ void blk_mq_debugfs_register_hctx(struct request_queue *q,
	char name[20];
	int i;

	lockdep_assert_held(&q->debugfs_mutex);

	if (!q->debugfs_dir)
		return;

@@ -895,6 +897,8 @@ void blk_mq_debugfs_register_hctx(struct request_queue *q,

void blk_mq_debugfs_unregister_hctx(struct blk_mq_hw_ctx *hctx)
{
	lockdep_assert_held(&hctx->queue->debugfs_mutex);

	if (!hctx->queue->debugfs_dir)
		return;
	debugfs_remove_recursive(hctx->debugfs_dir);
@@ -907,8 +911,10 @@ void blk_mq_debugfs_register_hctxs(struct request_queue *q)
	struct blk_mq_hw_ctx *hctx;
	int i;

	mutex_lock(&q->debugfs_mutex);
	queue_for_each_hw_ctx(q, hctx, i)
		blk_mq_debugfs_register_hctx(q, hctx);
	mutex_unlock(&q->debugfs_mutex);
}

void blk_mq_debugfs_unregister_hctxs(struct request_queue *q)
@@ -916,8 +922,10 @@ void blk_mq_debugfs_unregister_hctxs(struct request_queue *q)
	struct blk_mq_hw_ctx *hctx;
	int i;

	mutex_lock(&q->debugfs_mutex);
	queue_for_each_hw_ctx(q, hctx, i)
		blk_mq_debugfs_unregister_hctx(hctx);
	mutex_unlock(&q->debugfs_mutex);
}

void blk_mq_debugfs_register_sched(struct request_queue *q)
+2 −0
Original line number Diff line number Diff line
@@ -2428,7 +2428,9 @@ static void blk_mq_exit_hw_queues(struct request_queue *q,
	queue_for_each_hw_ctx(q, hctx, i) {
		if (i == nr_queue)
			break;
		mutex_lock(&q->debugfs_mutex);
		blk_mq_debugfs_unregister_hctx(hctx);
		mutex_unlock(&q->debugfs_mutex);
		blk_mq_exit_hctx(q, set, hctx, i);
	}
}