* [PATCH] block: fix handling of dead zone write plugs
@ 2026-05-13 11:11 Damien Le Moal
2026-05-13 11:22 ` Shin'ichiro Kawasaki
2026-05-13 13:56 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Damien Le Moal @ 2026-05-13 11:11 UTC (permalink / raw)
To: Jens Axboe, linux-block; +Cc: Christoph Hellwig, Shin'ichiro Kawasaki
Shin'ichiro reported hard to reproduce unaligned write errors with zoned
block devices. Under normal operation conditions (e.g. running XFS on an
SMR disk), these errors are nearly impossible to trigger. But using a
"slow" kernel with many debug options enables and some specific use cases
(e.g. fio zbd test case 46), the errors can be reproduced fairly easily.
The unaligned write errors come from mishandling a valid reference
counting pattern of zone write plugs. Such pattern triggers for instance
if a process A writes a zone (not necessarilly to the full state), another
process B immediately resets the zone and immediately following the
completion of the zone reset, starts issuing writes to the zone. With such
pattern, in some cases, the zone write plugs worker thread of the device
may still be holding a reference to the zone write plug of the zone taken
when process A was writing to the zone. The following zone reset from
process B marks the zone as dead but does not remove the zone write plug
from the device hash table as a reference to the plug still exist. Once
process B starts issuing new writes, the zone write plug is seen as dead
and the writes from process B are immediately failed, despite this write
pattern being perfectly legal.
Fix this by allowing restoring a dead zone write plug to a live state if a
write is issued to the zone when the zone is: marked as dead, empty and
the write sector corresponds to the first sector of the zone (that is, the
write is aligned to the zone write pointer). This is done with the new
helper function disk_check_zone_wplug_dead(), which restores a dead zone
write plug to a live state by clearing the BLK_ZONE_WPLUG_DEAD flag and
restoring the initial reference to the zone write plug taken when the plug
was added to the device hash table.
Reported-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Fixes: b7d4ffb51037 ("block: fix zone write plug removal")
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
---
block/blk-zoned.c | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 30cad2bb9291..42ef830054dc 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -623,6 +623,28 @@ static void disk_mark_zone_wplug_dead(struct blk_zone_wplug *zwplug)
}
}
+static inline bool disk_check_zone_wplug_dead(struct blk_zone_wplug *zwplug)
+{
+ if (!(zwplug->flags & BLK_ZONE_WPLUG_DEAD))
+ return false;
+
+ /*
+ * If a new write is received right after a zone reset completes and
+ * while the disk_zone_wplugs_worker() thread has not yet released the
+ * reference on the zone write plug after processing the last write to
+ * the zone, then the new write BIO will see the zone write plug marked
+ * as dead. This case is however a false positive and a perfectly valid
+ * pattern. In such case, restore the zone write plug to a live one.
+ */
+ if (!zwplug->wp_offset && bio_list_empty(&zwplug->bio_list)) {
+ zwplug->flags &= ~BLK_ZONE_WPLUG_DEAD;
+ refcount_inc(&zwplug->ref);
+ return false;
+ }
+
+ return true;
+}
+
static bool disk_zone_wplug_submit_bio(struct gendisk *disk,
struct blk_zone_wplug *zwplug);
@@ -1444,12 +1466,12 @@ static bool blk_zone_wplug_handle_write(struct bio *bio, unsigned int nr_segs)
spin_lock_irqsave(&zwplug->lock, flags);
/*
- * If we got a zone write plug marked as dead, then the user is issuing
- * writes to a full zone, or without synchronizing with zone reset or
- * zone finish operations. In such case, fail the BIO to signal this
- * invalid usage.
+ * Check if we got a zone write plug marked as dead. If yes, then the
+ * user is likely issuing writes to a full zone, or without
+ * synchronizing with zone reset or zone finish operations. In such
+ * case, fail the BIO to signal this invalid usage.
*/
- if (zwplug->flags & BLK_ZONE_WPLUG_DEAD) {
+ if (disk_check_zone_wplug_dead(zwplug)) {
spin_unlock_irqrestore(&zwplug->lock, flags);
disk_put_zone_wplug(zwplug);
bio_io_error(bio);
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] block: fix handling of dead zone write plugs
2026-05-13 11:11 [PATCH] block: fix handling of dead zone write plugs Damien Le Moal
@ 2026-05-13 11:22 ` Shin'ichiro Kawasaki
2026-05-13 13:56 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Shin'ichiro Kawasaki @ 2026-05-13 11:22 UTC (permalink / raw)
To: Damien Le Moal; +Cc: Jens Axboe, linux-block, Christoph Hellwig
On May 13, 2026 / 20:11, Damien Le Moal wrote:
> Shin'ichiro reported hard to reproduce unaligned write errors with zoned
> block devices. Under normal operation conditions (e.g. running XFS on an
> SMR disk), these errors are nearly impossible to trigger. But using a
> "slow" kernel with many debug options enables and some specific use cases
> (e.g. fio zbd test case 46), the errors can be reproduced fairly easily.
...
> Reported-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
> Fixes: b7d4ffb51037 ("block: fix zone write plug removal")
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Thanks for the fix. I applied this patch on top of the v7.1-rc3 kernel and
confirmed that the fio zbd test case 46 failure goes away.
Tested-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] block: fix handling of dead zone write plugs
2026-05-13 11:11 [PATCH] block: fix handling of dead zone write plugs Damien Le Moal
2026-05-13 11:22 ` Shin'ichiro Kawasaki
@ 2026-05-13 13:56 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2026-05-13 13:56 UTC (permalink / raw)
To: linux-block, Damien Le Moal; +Cc: Christoph Hellwig, Shin'ichiro Kawasaki
On Wed, 13 May 2026 20:11:29 +0900, Damien Le Moal wrote:
> Shin'ichiro reported hard to reproduce unaligned write errors with zoned
> block devices. Under normal operation conditions (e.g. running XFS on an
> SMR disk), these errors are nearly impossible to trigger. But using a
> "slow" kernel with many debug options enables and some specific use cases
> (e.g. fio zbd test case 46), the errors can be reproduced fairly easily.
>
> The unaligned write errors come from mishandling a valid reference
> counting pattern of zone write plugs. Such pattern triggers for instance
> if a process A writes a zone (not necessarilly to the full state), another
> process B immediately resets the zone and immediately following the
> completion of the zone reset, starts issuing writes to the zone. With such
> pattern, in some cases, the zone write plugs worker thread of the device
> may still be holding a reference to the zone write plug of the zone taken
> when process A was writing to the zone. The following zone reset from
> process B marks the zone as dead but does not remove the zone write plug
> from the device hash table as a reference to the plug still exist. Once
> process B starts issuing new writes, the zone write plug is seen as dead
> and the writes from process B are immediately failed, despite this write
> pattern being perfectly legal.
>
> [...]
Applied, thanks!
[1/1] block: fix handling of dead zone write plugs
commit: 836efd35c472d89c838d7b17ef339ddb3286ffc5
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-13 13:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-13 11:11 [PATCH] block: fix handling of dead zone write plugs Damien Le Moal
2026-05-13 11:22 ` Shin'ichiro Kawasaki
2026-05-13 13:56 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox