public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Yu Kuai <yukuai@fnnas.com>
Cc: axboe@kernel.dk, linux-block@vger.kernel.org, tj@kernel.org,
	nilay@linux.ibm.com
Subject: Re: [PATCH v7 04/16] blk-rq-qos: fix possible debugfs_mutex deadlock
Date: Wed, 7 Jan 2026 17:41:39 +0800	[thread overview]
Message-ID: <aV4qU9mRZFt_NHKK@fedora> (raw)
In-Reply-To: <20251231085126.205310-5-yukuai@fnnas.com>

On Wed, Dec 31, 2025 at 04:51:14PM +0800, Yu Kuai wrote:
> 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 <yukuai@fnnas.com>
> Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
> ---
>  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 *disk, enum rq_qos_id id,
>  	blk_queue_flag_set(QUEUE_FLAG_QOS_ENABLED, q);
>  
>  	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 9bef71ec645d..de3528236545 100644
> --- a/block/blk-wbt.c
> +++ b/block/blk-wbt.c
> @@ -774,6 +774,7 @@ EXPORT_SYMBOL_GPL(wbt_enable_default);
>  
>  void wbt_init_enable_default(struct gendisk *disk)
>  {
> +	struct request_queue *q = disk->queue;
>  	struct rq_wb *rwb;
>  
>  	if (!__wbt_enable_default(disk))
> @@ -783,8 +784,14 @@ void wbt_init_enable_default(struct gendisk *disk)
>  	if (WARN_ON_ONCE(!rwb))
>  		return;
>  
> -	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);
>  }
>  
>  static u64 wbt_default_latency_nsec(struct request_queue *q)
> @@ -1009,5 +1016,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);
> +

You may add one helper for avoiding the code duplication, but not a big
deal:

Reviewed-by: Ming Lei <ming.lei@redhat.com>


Thanks,
Ming


  reply	other threads:[~2026-01-07  9:41 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-31  8:51 [PATCH v7 00/16] blk-mq: fix possible deadlocks Yu Kuai
2025-12-31  8:51 ` [PATCH v7 01/16] blk-wbt: factor out a helper wbt_set_lat() Yu Kuai
2025-12-31  8:51 ` [PATCH v7 02/16] blk-wbt: fix possible deadlock to nest pcpu_alloc_mutex under q_usage_counter Yu Kuai
2026-01-07  9:30   ` Ming Lei
2025-12-31  8:51 ` [PATCH v7 03/16] blk-mq-debugfs: factor out a helper to register debugfs for all rq_qos Yu Kuai
2025-12-31  8:51 ` [PATCH v7 04/16] blk-rq-qos: fix possible debugfs_mutex deadlock Yu Kuai
2026-01-07  9:41   ` Ming Lei [this message]
2025-12-31  8:51 ` [PATCH v7 05/16] blk-mq-debugfs: make blk_mq_debugfs_register_rqos() static Yu Kuai
2026-01-07  9:42   ` Ming Lei
2025-12-31  8:51 ` [PATCH v7 06/16] blk-mq-debugfs: remove blk_mq_debugfs_unregister_rqos() Yu Kuai
2026-01-04 16:37   ` Nilay Shroff
2026-01-07  9:48   ` Ming Lei
2025-12-31  8:51 ` [PATCH v7 07/16] blk-mq-debugfs: add missing debugfs_mutex in blk_mq_debugfs_register_hctxs() Yu Kuai
2026-01-04 16:37   ` Nilay Shroff
2026-01-07  9:51   ` Ming Lei
2025-12-31  8:51 ` [PATCH v7 08/16] blk-mq-debugfs: warn about possible deadlock Yu Kuai
2026-01-04 16:38   ` Nilay Shroff
2026-01-07  9:56   ` Ming Lei
2025-12-31  8:51 ` [PATCH v7 09/16] blk-throttle: fix possible deadlock for fs reclaim under rq_qos_mutex Yu Kuai
2026-01-04 16:38   ` Nilay Shroff
2026-01-07 12:04   ` Ming Lei
2026-01-08 16:56     ` Yu Kuai
2026-01-09  2:18       ` Ming Lei
2026-01-09  2:22         ` Yu Kuai
2026-01-09  2:26           ` Ming Lei
2026-01-09  9:09       ` Nilay Shroff
2026-02-11  2:07         ` Yu Kuai
2025-12-31  8:51 ` [PATCH v7 10/16] block/blk-rq-qos: add a new helper rq_qos_add_frozen() Yu Kuai
2026-01-04 16:39   ` Nilay Shroff
2026-01-07 12:14   ` Ming Lei
2025-12-31  8:51 ` [PATCH v7 11/16] blk-wbt: fix incorrect lock order for rq_qos_mutex and freeze queue Yu Kuai
2026-01-04 16:39   ` Nilay Shroff
2026-01-07 12:14   ` Ming Lei
2025-12-31  8:51 ` [PATCH v7 12/16] blk-iocost: " Yu Kuai
2026-01-04 16:39   ` Nilay Shroff
2026-01-07 12:17   ` Ming Lei
2025-12-31  8:51 ` [PATCH v7 13/16] blk-iolatency: " Yu Kuai
2026-01-04 16:40   ` Nilay Shroff
2026-01-07 12:20   ` Ming Lei
2025-12-31  8:51 ` [PATCH v7 14/16] block/blk-rq-qos: cleanup rq_qos_add() Yu Kuai
2026-01-04 16:40   ` Nilay Shroff
2025-12-31  8:51 ` [PATCH v7 15/16] blk-rq-qos: remove queue frozen from rq_qos_del() Yu Kuai
2026-01-04 16:40   ` Nilay Shroff
2025-12-31  8:51 ` [PATCH v7 16/16] blk-cgroup: remove queue frozen from blkcg_activate_policy() Yu Kuai
2026-01-04 16:41   ` Nilay Shroff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aV4qU9mRZFt_NHKK@fedora \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=nilay@linux.ibm.com \
    --cc=tj@kernel.org \
    --cc=yukuai@fnnas.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox