The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v2 0/5] scsi: sd: Fix WRITE SAME(10) data corruption
@ 2026-11-28  9:26 Chris Down
  2026-11-28  9:26 ` [PATCH v2 1/5] scsi: sd: Fix stale max_hw_wzeroes_unmap_sectors after a mode change Chris Down
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Chris Down @ 2026-11-28  9:26 UTC (permalink / raw)
  To: Martin K. Petersen, James E.J. Bottomley
  Cc: Christoph Hellwig, linux-scsi, linux-kernel, kernel-team

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@chrisdown.name

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-28  9:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28  9:26 [PATCH v2 0/5] scsi: sd: Fix WRITE SAME(10) data corruption Chris Down
2026-11-28  9:26 ` [PATCH v2 1/5] scsi: sd: Fix stale max_hw_wzeroes_unmap_sectors after a mode change Chris Down
2026-11-28  9:26 ` [PATCH v2 2/5] scsi: sd: Fix data corruption in WRITE SAME(10) write zeroes Chris Down
2026-11-28  9:26 ` [PATCH v2 3/5] scsi: sd: Fix data corruption in WRITE SAME(10) discards Chris Down
2026-11-28  9:26 ` [PATCH v2 4/5] scsi: sd: Fix WRITE SAME(10) count truncation when the mode changes Chris Down
2026-11-28  9:26 ` [PATCH v2 5/5] scsi: sd: Fix unsplit discards when the granularity exceeds the limit Chris Down

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox