[PATCH v2 0/5] scsi: sd: Fix WRITE SAME(10) data corruption
From: Chris Down
Date: Sat Nov 28 2026 - 04:26:41 EST
With scsi_debug and 512-byte logical blocks, a 1 MiB discard at 2 TiB
succeeds, but it's the first MiB of the disk that gets discarded. This
happens because the starting LBA wraps to zero, because it doesn't fit
in WRITE SAME(10).
Write zeroes can also run out of bits for the block count. With a
0x20000-block WRITE SAME limit, a 64 MiB hole punch sends a count of
zero and leaves the whole range as it was.
Let's only use the WRITE SAME(10) modes when a 32-bit LBA can address
the whole disk, and keep the queue limits and the modes in step so that
requests fit in the count.
v2:
- Don't select or accept the WRITE SAME(10) modes when a 32-bit LBA
can't address the whole disk, instead of checking each request
(Christoph)
- Clear max_hw_wzeroes_unmap_sectors when the zeroing mode doesn't
unmap, since the zeroing mode can now change on a resize
- Change the modes with the queue frozen, so that queued requests are
not sent in a mode they were not sized for
- Disable discard when the granularity is above the discard limit,
since the block layer doesn't split discards in that case
v1: https://lore.kernel.org/r/cover.1794069087.git.chris@xxxxxxxxxxxxxx
Chris Down (5):
scsi: sd: Fix stale max_hw_wzeroes_unmap_sectors after a mode change
scsi: sd: Fix data corruption in WRITE SAME(10) write zeroes
scsi: sd: Fix data corruption in WRITE SAME(10) discards
scsi: sd: Fix WRITE SAME(10) count truncation when the mode changes
scsi: sd: Fix unsplit discards when the granularity exceeds the limit
drivers/scsi/sd.c | 75 +++++++++++++++++++++++++++++++++++++++++------
1 file changed, 66 insertions(+), 9 deletions(-)
base-commit: efd68f17acca65f581b9f2fa9ba50c8643ab544d
--
2.56.1