[PATCH 2/2] scsi: scsi_debug: reset protection information on zone reset

From: Tal Zussman

Date: Tue Nov 10 2026 - 16:25:04 EST


zbc_rwp_zone() zeroes the data of a zone that is reset, but leaves the
protection information of its previous contents in place. Reads of a
zoned device are not limited to the blocks below the write pointer, so
with DIX enabled reading those blocks back fails the guard check.

Write to a zone, reset it and read it back:

# modprobe scsi_debug zbc=managed sector_size=4096 dev_size_mb=64 \
zone_size_mb=4 dif=1 dix=1
# dd if=/dev/urandom of=/dev/sda bs=1M count=1 seek=8 oflag=direct
# blkzone reset -o 16384 -c 1 /dev/sda
# dd if=/dev/sda of=/dev/null bs=1M count=1 skip=8 iflag=direct
dd: error reading '/dev/sda': Invalid or incomplete multibyte or wide character

The read fails with EILSEQ, and the guard tag that the device reports
is still that of the data that was written, while the block now holds
zeroes:

scsi_debug:dif_verify: GUARD check failed on sector 2048 rcvd 0x288f, data 0x0000
protection error, dev sda, sector 16384 op 0x0:(READ) flags 0x10800 phys_seg 256 prio class 2

Reset the protection information of the zeroed blocks to 0xff, as
unmap_region() does, so that they are not checked until they are
written again.

Fixes: f0d1cf9378bd ("scsi: scsi_debug: Add ZBC zone commands")
Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
drivers/scsi/scsi_debug.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 1c27ea0f9b69..9eb64caebdf9 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -6613,8 +6613,9 @@ static int resp_finish_zone(struct scsi_cmnd *scp,
}

/*
- * Zero the blocks of a zone that is being reset. The store can be smaller
- * than the device, so wrap around at its end like do_device_access() does.
+ * Zero the blocks of a zone that is being reset, and reset their protection
+ * information. The store can be smaller than the device, so wrap around at
+ * its end like do_device_access() does.
*/
static void zbc_zero_blocks(struct sdeb_store_info *sip, sector_t lba,
sector_t num)
@@ -6630,6 +6631,9 @@ static void zbc_zero_blocks(struct sdeb_store_info *sip, sector_t lba,
n = min_t(sector_t, num, sdebug_store_sectors - block);
memset(sip->storep + block * sdebug_sector_size, 0,
(size_t)n * sdebug_sector_size);
+ if (sip->dif_storep)
+ memset(sip->dif_storep + block, 0xff,
+ n * sizeof(*sip->dif_storep));
lba += n;
num -= n;
}

--
2.39.5