[PATCH 0/2] scsi: sd: Fix WRITE SAME(10) data corruption

From: Chris Down

Date: Sat Nov 07 2026 - 13:06:02 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 use plain WRITE SAME(16) for write zeroes when the LBA or count
won't fit in WRITE SAME(10). For discard, we can just refuse the request
and leave the data alone.

Chris Down (2):
scsi: sd: Fix data corruption in WRITE SAME(10) write zeroes
scsi: sd: Fix data corruption in WRITE SAME(10) discards

drivers/scsi/sd.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)


base-commit: 04feb5fd2c23894ebc2cdaf4a4cc38b8667b17ac
--
2.54.0