From nobody Sun Feb 8 11:16:47 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 2B1062E266C; Mon, 2 Feb 2026 08:05:29 +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=1770019530; cv=none; b=Oy0FqO6cIBWAtsvWr+yMbwJbNOm/htSvXRZnwGKdtUvbd9HI8ElogK9LR3j8eNh4ED5ETf1S3yQS4Ni3mKn6Q1FXBlnnRofufsxZD5emeM5affzlDS1ZC9uQWQbOrCDRk5zCGcT2s47ebdbr6krw9wzRtwivaLSVSTTaDdVhSho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770019530; c=relaxed/simple; bh=gQFordqoJbhdZJvAzqTlCZcPa30IHDKadRzhmeEhy7o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rxnZYL3v0HatjA91GKr+JkJEYF5SST9iXJrQIx0H7u9g4RjKo967gcDWTJ3tqVFSRNdMo3ItXyzrJtNDxf7lXPzcwlIGKeCMHgh/hlfTVdw1PXB6r9jwyLf8gbGdBetaRJ07FdakkytBh5haCewqlxhbS9TgP3jSPC1Pm8ZaCos= 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 2074FC116C6; Mon, 2 Feb 2026 08:05:27 +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 1/8] blk-wbt: factor out a helper wbt_set_lat() Date: Mon, 2 Feb 2026 16:05:16 +0800 Message-ID: <20260202080523.3947504-2-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" To move implementation details inside blk-wbt.c, prepare to fix possible deadlock to call wbt_init() while queue is frozen in the next patch. Reviewed-by: Ming Lei Reviewed-by: Nilay Shroff Signed-off-by: Yu Kuai Reviewed-by: Hannes Reinecke --- block/blk-sysfs.c | 39 ++---------------------------------- block/blk-wbt.c | 50 ++++++++++++++++++++++++++++++++++++++++++++--- block/blk-wbt.h | 7 ++----- 3 files changed, 51 insertions(+), 45 deletions(-) diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index e0a70d26972b..a580688c3ad5 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -636,11 +636,8 @@ static ssize_t queue_wb_lat_show(struct gendisk *disk,= char *page) static ssize_t queue_wb_lat_store(struct gendisk *disk, const char *page, size_t count) { - struct request_queue *q =3D disk->queue; - struct rq_qos *rqos; ssize_t ret; s64 val; - unsigned int memflags; =20 ret =3D queue_var_store64(&val, page); if (ret < 0) @@ -648,40 +645,8 @@ static ssize_t queue_wb_lat_store(struct gendisk *disk= , const char *page, if (val < -1) return -EINVAL; =20 - /* - * Ensure that the queue is idled, in case the latency update - * ends up either enabling or disabling wbt completely. We can't - * have IO inflight if that happens. - */ - memflags =3D blk_mq_freeze_queue(q); - - rqos =3D wbt_rq_qos(q); - if (!rqos) { - ret =3D wbt_init(disk); - if (ret) - goto out; - } - - ret =3D count; - if (val =3D=3D -1) - val =3D wbt_default_latency_nsec(q); - else if (val >=3D 0) - val *=3D 1000ULL; - - if (wbt_get_min_lat(q) =3D=3D val) - goto out; - - blk_mq_quiesce_queue(q); - - mutex_lock(&disk->rqos_state_mutex); - wbt_set_min_lat(q, val); - mutex_unlock(&disk->rqos_state_mutex); - - blk_mq_unquiesce_queue(q); -out: - blk_mq_unfreeze_queue(q, memflags); - - return ret; + ret =3D wbt_set_lat(disk, val); + return ret ? ret : count; } =20 QUEUE_RW_ENTRY(queue_wb_lat, "wbt_lat_usec"); diff --git a/block/blk-wbt.c b/block/blk-wbt.c index 8e025834f2fb..0a37d97bda75 100644 --- a/block/blk-wbt.c +++ b/block/blk-wbt.c @@ -93,6 +93,8 @@ struct rq_wb { struct rq_depth rq_depth; }; =20 +static int wbt_init(struct gendisk *disk); + static inline struct rq_wb *RQWB(struct rq_qos *rqos) { return container_of(rqos, struct rq_wb, rqos); @@ -506,7 +508,7 @@ u64 wbt_get_min_lat(struct request_queue *q) return RQWB(rqos)->min_lat_nsec; } =20 -void wbt_set_min_lat(struct request_queue *q, u64 val) +static void wbt_set_min_lat(struct request_queue *q, u64 val) { struct rq_qos *rqos =3D wbt_rq_qos(q); if (!rqos) @@ -741,7 +743,7 @@ void wbt_init_enable_default(struct gendisk *disk) WARN_ON_ONCE(wbt_init(disk)); } =20 -u64 wbt_default_latency_nsec(struct request_queue *q) +static u64 wbt_default_latency_nsec(struct request_queue *q) { /* * We default to 2msec for non-rotational storage, and 75msec @@ -901,7 +903,7 @@ static const struct rq_qos_ops wbt_rqos_ops =3D { #endif }; =20 -int wbt_init(struct gendisk *disk) +static int wbt_init(struct gendisk *disk) { struct request_queue *q =3D disk->queue; struct rq_wb *rwb; @@ -948,3 +950,45 @@ int wbt_init(struct gendisk *disk) return ret; =20 } + +int wbt_set_lat(struct gendisk *disk, s64 val) +{ + struct request_queue *q =3D disk->queue; + unsigned int memflags; + struct rq_qos *rqos; + int ret =3D 0; + + /* + * Ensure that the queue is idled, in case the latency update + * ends up either enabling or disabling wbt completely. We can't + * have IO inflight if that happens. + */ + memflags =3D blk_mq_freeze_queue(q); + + rqos =3D wbt_rq_qos(q); + if (!rqos) { + ret =3D wbt_init(disk); + if (ret) + goto out; + } + + if (val =3D=3D -1) + val =3D wbt_default_latency_nsec(q); + else if (val >=3D 0) + val *=3D 1000ULL; + + if (wbt_get_min_lat(q) =3D=3D val) + goto out; + + blk_mq_quiesce_queue(q); + + mutex_lock(&disk->rqos_state_mutex); + wbt_set_min_lat(q, val); + mutex_unlock(&disk->rqos_state_mutex); + + blk_mq_unquiesce_queue(q); +out: + blk_mq_unfreeze_queue(q, memflags); + + return ret; +} diff --git a/block/blk-wbt.h b/block/blk-wbt.h index 925f22475738..6e39da17218b 100644 --- a/block/blk-wbt.h +++ b/block/blk-wbt.h @@ -4,16 +4,13 @@ =20 #ifdef CONFIG_BLK_WBT =20 -int wbt_init(struct gendisk *disk); void wbt_init_enable_default(struct gendisk *disk); void wbt_disable_default(struct gendisk *disk); void wbt_enable_default(struct gendisk *disk); =20 u64 wbt_get_min_lat(struct request_queue *q); -void wbt_set_min_lat(struct request_queue *q, u64 val); -bool wbt_disabled(struct request_queue *); - -u64 wbt_default_latency_nsec(struct request_queue *); +bool wbt_disabled(struct request_queue *q); +int wbt_set_lat(struct gendisk *disk, s64 val); =20 #else =20 --=20 2.51.0 From nobody Sun Feb 8 11:16:47 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 64CA831076D; Mon, 2 Feb 2026 08:05:32 +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=1770019532; cv=none; b=l6lOr8toBLr5++VIhtdlOEPWuiRfI2V+rUbaeSibe3fgxXl9w8NAQ6avBGlahe8lC2a8K0shuLmjXq6XFkvSsRaEt6sDjL0pFjDgJaTYMutypJdvT/HKb8x9GliR5hS5Tjt48DNS+vm1ZqyUwk7yXG1Xoe44KCgEMe8xuH8BBPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770019532; c=relaxed/simple; bh=3AZcyUVL5hbvTRPlY6JGfimIl0dbowc32m5wWsZDtaE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XcfQa0YUZTJk3A5TDAxnXubZfZC+7SVKlGZWFd1ri99alwK15A79gQ/M8j9pgBY/QhZsBcNwHZAn6zS8FgHXMzVm+B8K/oV739GTW7e/+iEdBhepLCeIxGVNvTfIw1AZJgYciZd0qJguHr3ABZDYHKY6JE/gxggPNIrfGledPcI= 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 4D125C116C6; Mon, 2 Feb 2026 08:05:30 +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 2/8] blk-wbt: fix possible deadlock to nest pcpu_alloc_mutex under q_usage_counter Date: Mon, 2 Feb 2026 16:05:17 +0800 Message-ID: <20260202080523.3947504-3-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" If wbt is disabled by default and user configures wbt by sysfs, queue will be frozen first and then pcpu_alloc_mutex will be held in blk_stat_alloc_callback(). Fix this problem by allocating memory first before queue frozen. Signed-off-by: Yu Kuai Reviewed-by: Nilay Shroff Reviewed-by: Ming Lei --- block/blk-wbt.c | 108 ++++++++++++++++++++++++++++-------------------- 1 file changed, 63 insertions(+), 45 deletions(-) diff --git a/block/blk-wbt.c b/block/blk-wbt.c index 0a37d97bda75..665760274e60 100644 --- a/block/blk-wbt.c +++ b/block/blk-wbt.c @@ -93,7 +93,7 @@ struct rq_wb { struct rq_depth rq_depth; }; =20 -static int wbt_init(struct gendisk *disk); +static int wbt_init(struct gendisk *disk, struct rq_wb *rwb); =20 static inline struct rq_wb *RQWB(struct rq_qos *rqos) { @@ -698,6 +698,41 @@ static void wbt_requeue(struct rq_qos *rqos, struct re= quest *rq) } } =20 +static int wbt_data_dir(const struct request *rq) +{ + const enum req_op op =3D req_op(rq); + + if (op =3D=3D REQ_OP_READ) + return READ; + else if (op_is_write(op)) + return WRITE; + + /* don't account */ + return -1; +} + +static struct rq_wb *wbt_alloc(void) +{ + struct rq_wb *rwb =3D kzalloc(sizeof(*rwb), GFP_KERNEL); + + if (!rwb) + return NULL; + + rwb->cb =3D blk_stat_alloc_callback(wb_timer_fn, wbt_data_dir, 2, rwb); + if (!rwb->cb) { + kfree(rwb); + return NULL; + } + + return rwb; +} + +static void wbt_free(struct rq_wb *rwb) +{ + blk_stat_free_callback(rwb->cb); + kfree(rwb); +} + /* * Enable wbt if defaults are configured that way */ @@ -739,8 +774,17 @@ EXPORT_SYMBOL_GPL(wbt_enable_default); =20 void wbt_init_enable_default(struct gendisk *disk) { - if (__wbt_enable_default(disk)) - WARN_ON_ONCE(wbt_init(disk)); + struct rq_wb *rwb; + + if (!__wbt_enable_default(disk)) + return; + + rwb =3D wbt_alloc(); + if (WARN_ON_ONCE(!rwb)) + return; + + if (WARN_ON_ONCE(wbt_init(disk, rwb))) + wbt_free(rwb); } =20 static u64 wbt_default_latency_nsec(struct request_queue *q) @@ -754,19 +798,6 @@ static u64 wbt_default_latency_nsec(struct request_que= ue *q) return 2000000ULL; } =20 -static int wbt_data_dir(const struct request *rq) -{ - const enum req_op op =3D req_op(rq); - - if (op =3D=3D REQ_OP_READ) - return READ; - else if (op_is_write(op)) - return WRITE; - - /* don't account */ - return -1; -} - static void wbt_queue_depth_changed(struct rq_qos *rqos) { RQWB(rqos)->rq_depth.queue_depth =3D blk_queue_depth(rqos->disk->queue); @@ -778,8 +809,7 @@ static void wbt_exit(struct rq_qos *rqos) struct rq_wb *rwb =3D RQWB(rqos); =20 blk_stat_remove_callback(rqos->disk->queue, rwb->cb); - blk_stat_free_callback(rwb->cb); - kfree(rwb); + wbt_free(rwb); } =20 /* @@ -903,22 +933,11 @@ static const struct rq_qos_ops wbt_rqos_ops =3D { #endif }; =20 -static int wbt_init(struct gendisk *disk) +static int wbt_init(struct gendisk *disk, struct rq_wb *rwb) { struct request_queue *q =3D disk->queue; - struct rq_wb *rwb; - int i; int ret; - - rwb =3D kzalloc(sizeof(*rwb), GFP_KERNEL); - if (!rwb) - return -ENOMEM; - - rwb->cb =3D blk_stat_alloc_callback(wb_timer_fn, wbt_data_dir, 2, rwb); - if (!rwb->cb) { - kfree(rwb); - return -ENOMEM; - } + int i; =20 for (i =3D 0; i < WBT_NUM_RWQ; i++) rq_wait_init(&rwb->rq_wait[i]); @@ -938,38 +957,38 @@ static int wbt_init(struct gendisk *disk) ret =3D rq_qos_add(&rwb->rqos, disk, RQ_QOS_WBT, &wbt_rqos_ops); mutex_unlock(&q->rq_qos_mutex); if (ret) - goto err_free; + return ret; =20 blk_stat_add_callback(q, rwb->cb); - return 0; - -err_free: - blk_stat_free_callback(rwb->cb); - kfree(rwb); - return ret; - } =20 int wbt_set_lat(struct gendisk *disk, s64 val) { struct request_queue *q =3D disk->queue; + struct rq_qos *rqos =3D wbt_rq_qos(q); + struct rq_wb *rwb =3D NULL; unsigned int memflags; - struct rq_qos *rqos; int ret =3D 0; =20 + if (!rqos) { + rwb =3D wbt_alloc(); + if (!rwb) + return -ENOMEM; + } + /* * Ensure that the queue is idled, in case the latency update * ends up either enabling or disabling wbt completely. We can't * have IO inflight if that happens. */ memflags =3D blk_mq_freeze_queue(q); - - rqos =3D wbt_rq_qos(q); if (!rqos) { - ret =3D wbt_init(disk); - if (ret) + ret =3D wbt_init(disk, rwb); + if (ret) { + wbt_free(rwb); goto out; + } } =20 if (val =3D=3D -1) @@ -989,6 +1008,5 @@ int wbt_set_lat(struct gendisk *disk, s64 val) blk_mq_unquiesce_queue(q); out: blk_mq_unfreeze_queue(q, memflags); - return ret; } --=20 2.51.0 From nobody Sun Feb 8 11:16:47 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 95FAE31076D; Mon, 2 Feb 2026 08:05:34 +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=1770019534; cv=none; b=M9wDQbVkNoQaFioQrgWT8jPr7nLSjW+l2D2vbobJ08ks4y1OA/ecyVyCCYNtuScU1+ySiDEB2kSsHYvXTzgZmG75uIcFaS16qNP/hKYkIwf2ov/MCTbRP1zv2NT/puXkyGEUAY4WMrArkNiaTWpEgMoaENdCpIUYyb8rfrRMDmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770019534; c=relaxed/simple; bh=ZQxUzyRdpBdLCJgMHRWkVytDFox1oIHQ8WUnbIjEuHk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g6kGUn/7LV8ADEh7Sf07zVR2jDuSoaeA4JQEu1YskEz+c8nqZUHl1TEg2qKfKouRQL3/kGS2UxCIGGP7FS9ic8pdq5j9nRJux8lx9ZNp60Jm9jhvitAv5BdQXCobh33RNtoTzlcatpE75xm1J5pY9vBv/7kEQi3Rpc8SoZyZTcw= 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 79D43C116C6; Mon, 2 Feb 2026 08:05:32 +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 3/8] blk-mq-debugfs: factor out a helper to register debugfs for all rq_qos Date: Mon, 2 Feb 2026 16:05:18 +0800 Message-ID: <20260202080523.3947504-4-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" There is already a helper blk_mq_debugfs_register_rqos() to register one rqos, however this helper is called synchronously when the rqos is created with queue frozen. Prepare to fix possible deadlock to create blk-mq debugfs entries while queue is still frozen. Reviewed-by: Ming Lei Reviewed-by: Nilay Shroff Signed-off-by: Yu Kuai Reviewed-by: Hannes Reinecke --- block/blk-mq-debugfs.c | 23 +++++++++++++++-------- block/blk-mq-debugfs.h | 5 +++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index 4896525b1c05..4fe164b6d648 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -631,14 +631,7 @@ void blk_mq_debugfs_register(struct request_queue *q) blk_mq_debugfs_register_hctx(q, hctx); } =20 - if (q->rq_qos) { - struct rq_qos *rqos =3D q->rq_qos; - - while (rqos) { - blk_mq_debugfs_register_rqos(rqos); - rqos =3D rqos->next; - } - } + blk_mq_debugfs_register_rq_qos(q); } =20 static void blk_mq_debugfs_register_ctx(struct blk_mq_hw_ctx *hctx, @@ -769,6 +762,20 @@ void blk_mq_debugfs_register_rqos(struct rq_qos *rqos) debugfs_create_files(rqos->debugfs_dir, rqos, rqos->ops->debugfs_attrs); } =20 +void blk_mq_debugfs_register_rq_qos(struct request_queue *q) +{ + lockdep_assert_held(&q->debugfs_mutex); + + if (q->rq_qos) { + struct rq_qos *rqos =3D q->rq_qos; + + while (rqos) { + blk_mq_debugfs_register_rqos(rqos); + rqos =3D rqos->next; + } + } +} + void blk_mq_debugfs_register_sched_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx) { diff --git a/block/blk-mq-debugfs.h b/block/blk-mq-debugfs.h index c80e453e3014..54948a266889 100644 --- a/block/blk-mq-debugfs.h +++ b/block/blk-mq-debugfs.h @@ -33,6 +33,7 @@ void blk_mq_debugfs_register_sched_hctx(struct request_qu= eue *q, struct blk_mq_hw_ctx *hctx); void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx); =20 +void blk_mq_debugfs_register_rq_qos(struct request_queue *q); void blk_mq_debugfs_register_rqos(struct rq_qos *rqos); void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos); #else @@ -78,6 +79,10 @@ static inline void blk_mq_debugfs_register_rqos(struct r= q_qos *rqos) { } =20 +static inline void blk_mq_debugfs_register_rq_qos(struct request_queue *q) +{ +} + static inline void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos) { } --=20 2.51.0 From nobody Sun Feb 8 11:16:47 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 B6F8F311975; Mon, 2 Feb 2026 08:05:36 +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=1770019536; cv=none; b=SFxyks0MSkOBoDoJwk4wj2kL7vDcFAKZsNcNgGS9wstPZJXhJQquZw8nbdqTRec1Ftbk3tylXcN8q4OTjJNvdfeX+BZCo3pbpPqomxDbzZwtCbzNPSULT0t7rIyonwnmYwf/xqqqJthxHK+Mf6JyWWDIDWCiMvZoDPIz8n1J9FA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770019536; c=relaxed/simple; bh=WgAZHah0jtN76dcJY5zFLPK/BQJtvQwBkHW+vLk2c3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DFAJo7w8me9ttiJFIoTSwnZ9v2EoAzyx0OBxTOTDAQDEk4WV64Mw4KO+RzHXZA6yV2pOCx1k9lFZd+WB9g2ojEVegwAHFaFMimEqliAVvJXKZKc+xtgloSE9wlAshoLyxar1d45om0UHw4hFBrEV+zNQIBLRDfpl4pOkahL+hT8= 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 A65C2C116D0; Mon, 2 Feb 2026 08:05:34 +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 4/8] blk-rq-qos: fix possible debugfs_mutex deadlock Date: Mon, 2 Feb 2026 16:05:19 +0800 Message-ID: <20260202080523.3947504-5-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" Currently rq-qos debugfs entries are created from rq_qos_add(), while rq_qos_add() can be called while queue is still frozen. This can deadlock because creating new entries can trigger fs reclaim. Fix this problem by delaying creating rq-qos debugfs entries after queue is unfrozen. - For wbt, 1) it can be initialized by default, fix it by calling new helper after wbt_init() from wbt_init_enable_default(); 2) it can be initialized by sysfs, fix it by calling new helper after queue is unfrozen from wbt_set_lat(). - For iocost and iolatency, they can only be initialized by blkcg configuration, however, they don't have debugfs entries for now, hence they are not handled yet. Signed-off-by: Yu Kuai Reviewed-by: Nilay Shroff Reviewed-by: Ming Lei Reviewed-by: Hannes Reinecke --- block/blk-rq-qos.c | 7 ------- block/blk-wbt.c | 13 ++++++++++++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/block/blk-rq-qos.c b/block/blk-rq-qos.c index 654478dfbc20..d7ce99ce2e80 100644 --- a/block/blk-rq-qos.c +++ b/block/blk-rq-qos.c @@ -347,13 +347,6 @@ int rq_qos_add(struct rq_qos *rqos, struct gendisk *di= sk, enum rq_qos_id id, blk_queue_flag_set(QUEUE_FLAG_QOS_ENABLED, q); =20 blk_mq_unfreeze_queue(q, memflags); - - if (rqos->ops->debugfs_attrs) { - mutex_lock(&q->debugfs_mutex); - blk_mq_debugfs_register_rqos(rqos); - mutex_unlock(&q->debugfs_mutex); - } - return 0; ebusy: blk_mq_unfreeze_queue(q, memflags); diff --git a/block/blk-wbt.c b/block/blk-wbt.c index 665760274e60..1415f2bf8611 100644 --- a/block/blk-wbt.c +++ b/block/blk-wbt.c @@ -774,6 +774,7 @@ EXPORT_SYMBOL_GPL(wbt_enable_default); =20 void wbt_init_enable_default(struct gendisk *disk) { + struct request_queue *q =3D disk->queue; struct rq_wb *rwb; =20 if (!__wbt_enable_default(disk)) @@ -783,8 +784,14 @@ void wbt_init_enable_default(struct gendisk *disk) if (WARN_ON_ONCE(!rwb)) return; =20 - if (WARN_ON_ONCE(wbt_init(disk, rwb))) + if (WARN_ON_ONCE(wbt_init(disk, rwb))) { wbt_free(rwb); + return; + } + + mutex_lock(&q->debugfs_mutex); + blk_mq_debugfs_register_rq_qos(q); + mutex_unlock(&q->debugfs_mutex); } =20 static u64 wbt_default_latency_nsec(struct request_queue *q) @@ -1008,5 +1015,9 @@ int wbt_set_lat(struct gendisk *disk, s64 val) blk_mq_unquiesce_queue(q); out: blk_mq_unfreeze_queue(q, memflags); + mutex_lock(&q->debugfs_mutex); + blk_mq_debugfs_register_rq_qos(q); + mutex_unlock(&q->debugfs_mutex); + return ret; } --=20 2.51.0 From nobody Sun Feb 8 11:16:47 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 F1B982E266C; Mon, 2 Feb 2026 08:05:38 +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=1770019539; cv=none; b=k+zgCrnNDgKS1UB164+bZkzfI8EleOUsw8FdgJ41XN0XfYITWae0GCsERKBHCbg38XiOMohje1ogQytI84RVzs9JoMa2ztGt/YTTutNy1Lkn974bkSD9rCnVeS5lfwVIsyAu27675iLHKfOn4113jqqSaE9vV7Fcg8Cp9qSvLGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770019539; c=relaxed/simple; bh=DPagL1gIOlB/G6hvEmxknILuk0nDjlpNMTJ4pChBGmc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qj6fQqoxj5d+5Ex2YGbryt6r86mfaOKRVrr0RqP/+uFBnCPMVWDko6SZjaf+ptvP5HGklmlr5JqfhF3pJZL2dWB1+XODwUY//rVmdgFGyszSi8XjlqoHMKiKT63jsY6AE2rCZVrwnjerdIwpjd8/W+V9w5FPu0VAFmxpdx9PeS8= 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 D2B9CC116C6; Mon, 2 Feb 2026 08:05:36 +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 5/8] blk-mq-debugfs: make blk_mq_debugfs_register_rqos() static Date: Mon, 2 Feb 2026 16:05:20 +0800 Message-ID: <20260202080523.3947504-6-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" Because it's only used inside blk-mq-debugfs.c now. Reviewed-by: Nilay Shroff Signed-off-by: Yu Kuai Reviewed-by: Ming Lei Reviewed-by: Hannes Reinecke --- block/blk-mq-debugfs.c | 2 +- block/blk-mq-debugfs.h | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index 4fe164b6d648..11f00a868541 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -744,7 +744,7 @@ void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos) rqos->debugfs_dir =3D NULL; } =20 -void blk_mq_debugfs_register_rqos(struct rq_qos *rqos) +static void blk_mq_debugfs_register_rqos(struct rq_qos *rqos) { struct request_queue *q =3D rqos->disk->queue; const char *dir_name =3D rq_qos_id_to_name(rqos->id); diff --git a/block/blk-mq-debugfs.h b/block/blk-mq-debugfs.h index 54948a266889..d94daa66556b 100644 --- a/block/blk-mq-debugfs.h +++ b/block/blk-mq-debugfs.h @@ -34,7 +34,6 @@ void blk_mq_debugfs_register_sched_hctx(struct request_qu= eue *q, void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx); =20 void blk_mq_debugfs_register_rq_qos(struct request_queue *q); -void blk_mq_debugfs_register_rqos(struct rq_qos *rqos); void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos); #else static inline void blk_mq_debugfs_register(struct request_queue *q) @@ -75,10 +74,6 @@ static inline void blk_mq_debugfs_unregister_sched_hctx(= struct blk_mq_hw_ctx *hc { } =20 -static inline void blk_mq_debugfs_register_rqos(struct rq_qos *rqos) -{ -} - static inline void blk_mq_debugfs_register_rq_qos(struct request_queue *q) { } --=20 2.51.0 From nobody Sun Feb 8 11:16:47 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 363B82E266C; Mon, 2 Feb 2026 08:05:40 +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=1770019541; cv=none; b=ILDsdZV0GqVfPo5FBUY/IAeuNUzyFt8VyNJ/lig8lQjxsef0TNgUnC5oupT1+d4Kup+nkwCKaF3qGGalbsPyqDVtt+wATKx6ReKpz6vLA+87tp/oOC6scG0mn13S6PVXpd1pOdbLvZfIfHqK6//8wh0v47Gfoz5Qd3FOmQtlngg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770019541; c=relaxed/simple; bh=71dJ0wHPodFp3HMbfG6GxWJmkGY5vzMEvhmKs2UQ40E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=odh/TZ1jDri7DlNmSpUnbUPKQACZw+xT62rUXgUA72PTu0FHu4EO1KEKoiUdb3rSLp5O/EbU7NX3BKyJwFOiIc9ASUECjzaKr9gzclaCbJ6qUgjk4MubWqwX0hTUjucMXaH2kU1jxauJ3kITTt0nAbVbnR9Ce4fyid5wrmZNlNc= 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 0AB68C19421; Mon, 2 Feb 2026 08:05:38 +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 6/8] blk-mq-debugfs: remove blk_mq_debugfs_unregister_rqos() Date: Mon, 2 Feb 2026 16:05:21 +0800 Message-ID: <20260202080523.3947504-7-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" Because this helper is only used by iocost and iolatency, while they don't have debugfs entries. Signed-off-by: Yu Kuai Reviewed-by: Nilay Shroff Reviewed-by: Ming Lei Reviewed-by: Hannes Reinecke --- block/blk-mq-debugfs.c | 10 ---------- block/blk-mq-debugfs.h | 4 ---- block/blk-rq-qos.c | 4 ---- 3 files changed, 18 deletions(-) diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index 11f00a868541..22c182b40bc3 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -734,16 +734,6 @@ static const char *rq_qos_id_to_name(enum rq_qos_id id) return "unknown"; } =20 -void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos) -{ - lockdep_assert_held(&rqos->disk->queue->debugfs_mutex); - - if (!rqos->disk->queue->debugfs_dir) - return; - debugfs_remove_recursive(rqos->debugfs_dir); - rqos->debugfs_dir =3D NULL; -} - static void blk_mq_debugfs_register_rqos(struct rq_qos *rqos) { struct request_queue *q =3D rqos->disk->queue; diff --git a/block/blk-mq-debugfs.h b/block/blk-mq-debugfs.h index d94daa66556b..49bb1aaa83dc 100644 --- a/block/blk-mq-debugfs.h +++ b/block/blk-mq-debugfs.h @@ -34,7 +34,6 @@ void blk_mq_debugfs_register_sched_hctx(struct request_qu= eue *q, void blk_mq_debugfs_unregister_sched_hctx(struct blk_mq_hw_ctx *hctx); =20 void blk_mq_debugfs_register_rq_qos(struct request_queue *q); -void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos); #else static inline void blk_mq_debugfs_register(struct request_queue *q) { @@ -78,9 +77,6 @@ static inline void blk_mq_debugfs_register_rq_qos(struct = request_queue *q) { } =20 -static inline void blk_mq_debugfs_unregister_rqos(struct rq_qos *rqos) -{ -} #endif =20 #if defined(CONFIG_BLK_DEV_ZONED) && defined(CONFIG_BLK_DEBUG_FS) diff --git a/block/blk-rq-qos.c b/block/blk-rq-qos.c index d7ce99ce2e80..85cf74402a09 100644 --- a/block/blk-rq-qos.c +++ b/block/blk-rq-qos.c @@ -371,8 +371,4 @@ void rq_qos_del(struct rq_qos *rqos) if (!q->rq_qos) blk_queue_flag_clear(QUEUE_FLAG_QOS_ENABLED, q); blk_mq_unfreeze_queue(q, memflags); - - mutex_lock(&q->debugfs_mutex); - blk_mq_debugfs_unregister_rqos(rqos); - mutex_unlock(&q->debugfs_mutex); } --=20 2.51.0 From nobody Sun Feb 8 11:16:47 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 46AAD2E266C; Mon, 2 Feb 2026 08:05:43 +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=1770019543; cv=none; b=VxhW7W7TdL7AT0mNsI/85V9XCnC3I3K/UxCjmt+WPfGQ7d+xs4NRAC6RYSbZzP5Z/qkAi6CmaW5j+PhcDAuvlRXL5WFRPkRUi6CEEl9n28XEWCJV47AVu3ctUAYvy0PGt1+B9gk1STys3o+Lj8yqjtxkTTdt5q09L5zYnZ1Mj+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770019543; c=relaxed/simple; bh=dIyfkG4jYJUUKVfMapTtdGMGgtz+ZeVnkS58TLNdc7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i572kmEDenoZN18XJzT7s4GeHuRSOn8pCzWv18MDSefne3uibsiWHRmXYyPbEkC7Re9hNqc38f5xlcbs97r50FjfLF7yKRFUp2HthYKjLimmxDRhx4QeZN4Ajcta99ZTYcjclamFR7gY06Mme7lt0BRV9Xd7U5Iu1MaWpyJqNX8= 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 37545C116D0; Mon, 2 Feb 2026 08:05:41 +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 7/8] blk-mq-debugfs: add missing debugfs_mutex in blk_mq_debugfs_register_hctxs() Date: Mon, 2 Feb 2026 16:05:22 +0800 Message-ID: <20260202080523.3947504-8-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" In blk_mq_update_nr_hw_queues(), debugfs_mutex is not held while creating debugfs entries for hctxs. Hence add debugfs_mutex there, it's safe because queue is not frozen. Signed-off-by: Yu Kuai Reviewed-by: Nilay Shroff Reviewed-by: Ming Lei Reviewed-by: Hannes Reinecke --- block/blk-mq-debugfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c index 22c182b40bc3..5c7cadf51a88 100644 --- a/block/blk-mq-debugfs.c +++ b/block/blk-mq-debugfs.c @@ -679,8 +679,10 @@ void blk_mq_debugfs_register_hctxs(struct request_queu= e *q) struct blk_mq_hw_ctx *hctx; unsigned long i; =20 + 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); } =20 void blk_mq_debugfs_unregister_hctxs(struct request_queue *q) --=20 2.51.0 From nobody Sun Feb 8 11:16:47 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