From: Changyul Lee <lcy8047@gmail.com>
To: Damien Le Moal <dlemoal@kernel.org>, Jens Axboe <axboe@kernel.dk>
Cc: Christoph Hellwig <hch@lst.de>,
Johannes Thumshirn <johannes.thumshirn@wdc.com>,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
Changyul Lee <lcy8047@gmail.com>
Subject: [PATCH] zloop: remove the device ID after del_gendisk()
Date: Fri, 6 Nov 2026 11:06:38 -0500 [thread overview]
Message-ID: <20261106160638.2385495-1-lcy8047@gmail.com> (raw)
zloop_ctl_remove() removes the device ID from zloop_index_idr before
del_gendisk() removes the "zloop<N>" disk from sysfs. An "add" request
issued in between can get the same ID, and its add_disk() fails:
sysfs: cannot create duplicate filename '/devices/virtual/block/zloop0'
...
zloop: add_disk failed (err=-17)
Remove the ID after del_gendisk() and before put_disk() frees the
device. Until then, an "add" requesting the same ID fails with -EEXIST,
and another "remove" fails with -EINVAL from the existing Zlo_deleting
check.
Fixes: eb0570c7df23 ("block: new zoned loop block device driver")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
Notes:
Found with a static analysis tool we are developing.
Reproduced in QEMU (x86_64) with two threads that each write
"add id=0,..." and then "remove id=0" to /dev/zloop-control in a loop
for 20 seconds, with the zone files on tmpfs. Without this patch,
add_disk() failed 2126 times with the error above. With it, add_disk()
never failed, and the requests that overlapped a deletion got -EEXIST
("add") or -EINVAL ("remove").
drivers/block/zloop.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
index 65634a39b0bf..8fb1f7fad286 100644
--- a/drivers/block/zloop.c
+++ b/drivers/block/zloop.c
@@ -1467,7 +1467,6 @@ static int zloop_ctl_remove(struct zloop_options *opts)
} else if (zlo->state == Zlo_deleting) {
ret = -EINVAL;
} else {
- idr_remove(&zloop_index_idr, zlo->id);
WRITE_ONCE(zlo->state, Zlo_deleting);
}
@@ -1477,6 +1476,10 @@ static int zloop_ctl_remove(struct zloop_options *opts)
del_gendisk(zlo->disk);
+ mutex_lock(&zloop_ctl_mutex);
+ idr_remove(&zloop_index_idr, zlo->id);
+ mutex_unlock(&zloop_ctl_mutex);
+
if (zlo->discard_write_cache)
zloop_forget_cache(zlo);
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.43.0
next reply other threads:[~2026-11-06 16:06 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-06 16:06 Changyul Lee [this message]
2026-11-06 16:10 ` Christoph Hellwig
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=20261106160638.2385495-1-lcy8047@gmail.com \
--to=lcy8047@gmail.com \
--cc=axboe@kernel.dk \
--cc=dlemoal@kernel.org \
--cc=hch@lst.de \
--cc=johannes.thumshirn@wdc.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®