All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Yi Zhang <yi.zhang@redhat.com>
Cc: linux-block <linux-block@vger.kernel.org>,
	Jens Axboe <axboe@kernel.dk>,
	Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Subject: Re: [bug report] blktests block/022 failed with possible circular locking dependency detected at: __kernfs_remove+0x275/0x710 and del_gendisk+0xfd/0x190
Date: Wed, 4 Mar 2026 18:16:25 +0800	[thread overview]
Message-ID: <aagGeXqeHnCugRyr@fedora> (raw)
In-Reply-To: <CAHj4cs-em-4acsHabMdT=jJhXkCzjnprD-aQH1OgrZo4nTnmMw@mail.gmail.com>

On Wed, Mar 04, 2026 at 03:10:06PM +0800, Yi Zhang wrote:
> Hi
> 
> I found blktests block/022 failed on the latest
> linux-block/for-next[1], please help check it and let me know if you
> need any info/testing for it, thanks.
> 
> [1]
> commit b82c5e4f1bcb3fa78ba3c95a0d198f55553c0fc1
> Merge: 187d9a5a18b4 d47f7c173262
> Author: Jens Axboe <axboe@kernel.dk>
> Date:   Mon Mar 2 14:04:16 2026 -0700
> 
>     Merge branch 'for-7.1/block' into for-next
> 
> dmesg:
> [ 1329.227229] run blktests block/022 at 2026-03-03 13:51:07
> [ 1329.838331] null_blk: module loaded
> --snip--

...

> [ 1349.822314]  Possible unsafe locking scenario:
> 
> [ 1349.828232]        CPU0                    CPU1
> [ 1349.832766]        ----                    ----
> [ 1349.837296]   rlock(&set->update_nr_hwq_lock);
> [ 1349.841752]                                lock(kn->active#104);
> [ 1349.847767]                                lock(&set->update_nr_hwq_lock);
> [ 1349.854647]   lock(kn->active#104);
> [ 1349.858148]
>                 *** DEADLOCK ***

Looks one real deadlock risk, can you try the following patch?


diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index f3b1968c80ce..55a1bbfef7d4 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -78,8 +78,14 @@ queue_requests_store(struct gendisk *disk, const char *page, size_t count)
 	/*
 	 * Serialize updating nr_requests with concurrent queue_requests_store()
 	 * and switching elevator.
+	 *
+	 * Use trylock to avoid circular lock dependency with kernfs active
+	 * reference during concurrent disk deletion:
+	 *   update_nr_hwq_lock -> kn->active (via del_gendisk -> kobject_del)
+	 *   kn->active -> update_nr_hwq_lock (via this sysfs write path)
 	 */
-	down_write(&set->update_nr_hwq_lock);
+	if (!down_write_trylock(&set->update_nr_hwq_lock))
+		return -EBUSY;
 
 	if (nr == q->nr_requests)
 		goto unlock;
diff --git a/block/elevator.c b/block/elevator.c
index ebe2a1fcf011..3bcd37c2aa34 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -807,7 +807,16 @@ ssize_t elv_iosched_store(struct gendisk *disk, const char *buf,
 	elv_iosched_load_module(ctx.name);
 	ctx.type = elevator_find_get(ctx.name);
 
-	down_read(&set->update_nr_hwq_lock);
+	/*
+	 * Use trylock to avoid circular lock dependency with kernfs active
+	 * reference during concurrent disk deletion:
+	 *   update_nr_hwq_lock -> kn->active (via del_gendisk -> kobject_del)
+	 *   kn->active -> update_nr_hwq_lock (via this sysfs write path)
+	 */
+	if (!down_read_trylock(&set->update_nr_hwq_lock)) {
+		ret = -EBUSY;
+		goto out;
+	}
 	if (!blk_queue_no_elv_switch(q)) {
 		ret = elevator_change(q, &ctx);
 		if (!ret)
@@ -817,6 +826,7 @@ ssize_t elv_iosched_store(struct gendisk *disk, const char *buf,
 	}
 	up_read(&set->update_nr_hwq_lock);
 
+out:
 	if (ctx.type)
 		elevator_put(ctx.type);
 	return ret;


Thanks,
Ming


  reply	other threads:[~2026-03-04 10:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-04  7:10 [bug report] blktests block/022 failed with possible circular locking dependency detected at: __kernfs_remove+0x275/0x710 and del_gendisk+0xfd/0x190 Yi Zhang
2026-03-04 10:16 ` Ming Lei [this message]
2026-03-05  1:51   ` Yi Zhang

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=aagGeXqeHnCugRyr@fedora \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=shinichiro.kawasaki@wdc.com \
    --cc=yi.zhang@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.