From nobody Mon Feb 9 12:24:30 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 878B9318B8C; Mon, 2 Feb 2026 08:05:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770019545; cv=none; b=h/JeWRynaE3pC+vkKKdAMd1C2petz3V8LO2QQ19EIcVrm9pgh9aTH6ISbpmy7f6hNXKwxPvHrb8NDRJf03O5hbdElL4I2nunMpbecIfXjFXOitYh0SlEv2fWmY1gUHDL/t7ztz1xtTmLSyIpU9O55ZMqa0SEwTfbNTamJe5Gx1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770019545; c=relaxed/simple; bh=FMStoCEce7vJ5MfJqC0YqrAsq1RuPnDC4HKWZkUGDBk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A83PWeDjnomPpdNIXc3G4edmaUw7K3cQNG+02oPm/8Nc3PQRaSF8yLETt8WwaG7TjGHSo8d2ExNUSCMKhmzG7dajtvncpYerE+jkAHVxVPhMKY4np2Hi0NEh4d0JsqulVk7QerLHIL8bQyrBh6BIHKTtPjoUIGB4WHWV/teGSEw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 63D00C116C6; Mon, 2 Feb 2026 08:05:43 +0000 (UTC) From: Yu Kuai To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Ming Lei , Nilay Shroff , Hannes Reinecke , yukuai@fnnas.com Subject: [PATCH v9 8/8] blk-mq-debugfs: warn about possible deadlock Date: Mon, 2 Feb 2026 16:05:23 +0800 Message-ID: <20260202080523.3947504-9-yukuai@fnnas.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260202080523.3947504-1-yukuai@fnnas.com> References: <20260202080523.3947504-1-yukuai@fnnas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Creating new debugfs entries can trigger fs reclaim, hence we can't do this with queue frozen, meanwhile, other locks that can be held while queue is frozen should not be held as well. Signed-off-by: Yu Kuai Reviewed-by: Nilay Shroff Reviewed-by: Ming Lei Reviewed-by: Hannes Reinecke --- block/blk-mq-debugfs.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index 5c7cadf51a88..faeaa1fc86a7 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -608,9 +608,23 @@ static const struct blk_mq_debugfs_attr blk_mq_debugfs= _ctx_attrs[] =3D { {}, }; =20 -static void debugfs_create_files(struct dentry *parent, void *data, +static void debugfs_create_files(struct request_queue *q, struct dentry *p= arent, + void *data, const struct blk_mq_debugfs_attr *attr) { + lockdep_assert_held(&q->debugfs_mutex); + /* + * Creating new debugfs entries with queue freezed has the risk of + * deadlock. + */ + WARN_ON_ONCE(q->mq_freeze_depth !=3D 0); + /* + * debugfs_mutex should not be nested under other locks that can be + * grabbed while queue is frozen. + */ + lockdep_assert_not_held(&q->elevator_lock); + lockdep_assert_not_held(&q->rq_qos_mutex); + if (IS_ERR_OR_NULL(parent)) return; =20 @@ -624,7 +638,7 @@ void blk_mq_debugfs_register(struct request_queue *q) struct blk_mq_hw_ctx *hctx; unsigned long i; =20 - debugfs_create_files(q->debugfs_dir, q, blk_mq_debugfs_queue_attrs); + debugfs_create_files(q, q->debugfs_dir, q, blk_mq_debugfs_queue_attrs); =20 queue_for_each_hw_ctx(q, hctx, i) { if (!hctx->debugfs_dir) @@ -643,7 +657,8 @@ static void blk_mq_debugfs_register_ctx(struct blk_mq_h= w_ctx *hctx, snprintf(name, sizeof(name), "cpu%u", ctx->cpu); ctx_dir =3D debugfs_create_dir(name, hctx->debugfs_dir); =20 - debugfs_create_files(ctx_dir, ctx, blk_mq_debugfs_ctx_attrs); + debugfs_create_files(hctx->queue, ctx_dir, ctx, + blk_mq_debugfs_ctx_attrs); } =20 void blk_mq_debugfs_register_hctx(struct request_queue *q, @@ -659,7 +674,8 @@ void blk_mq_debugfs_register_hctx(struct request_queue = *q, snprintf(name, sizeof(name), "hctx%u", hctx->queue_num); hctx->debugfs_dir =3D debugfs_create_dir(name, q->debugfs_dir); =20 - debugfs_create_files(hctx->debugfs_dir, hctx, blk_mq_debugfs_hctx_attrs); + debugfs_create_files(q, hctx->debugfs_dir, hctx, + blk_mq_debugfs_hctx_attrs); =20 hctx_for_each_ctx(hctx, ctx, i) blk_mq_debugfs_register_ctx(hctx, ctx); @@ -712,7 +728,7 @@ void blk_mq_debugfs_register_sched(struct request_queue= *q) =20 q->sched_debugfs_dir =3D debugfs_create_dir("sched", q->debugfs_dir); =20 - debugfs_create_files(q->sched_debugfs_dir, q, e->queue_debugfs_attrs); + debugfs_create_files(q, q->sched_debugfs_dir, q, e->queue_debugfs_attrs); } =20 void blk_mq_debugfs_unregister_sched(struct request_queue *q) @@ -751,7 +767,8 @@ static void blk_mq_debugfs_register_rqos(struct rq_qos = *rqos) q->debugfs_dir); =20 rqos->debugfs_dir =3D debugfs_create_dir(dir_name, q->rqos_debugfs_dir); - debugfs_create_files(rqos->debugfs_dir, rqos, rqos->ops->debugfs_attrs); + debugfs_create_files(q, rqos->debugfs_dir, rqos, + rqos->ops->debugfs_attrs); } =20 void blk_mq_debugfs_register_rq_qos(struct request_queue *q) @@ -788,7 +805,7 @@ void blk_mq_debugfs_register_sched_hctx(struct request_= queue *q, =20 hctx->sched_debugfs_dir =3D debugfs_create_dir("sched", hctx->debugfs_dir); - debugfs_create_files(hctx->sched_debugfs_dir, hctx, + debugfs_create_files(q, hctx->sched_debugfs_dir, hctx, e->hctx_debugfs_attrs); } =20 --=20 2.51.0