From: Chris Down <chris@chrisdown.name>
To: "Martin K. Petersen" <mkp@kernel.org>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>
Cc: Christoph Hellwig <hch@lst.de>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@meta.com, sashiko-bot@kernel.org,
Bart Van Assche <bvanassche@acm.org>
Subject: [PATCH v3 0/5] scsi: sd: Fix WRITE SAME(10) data corruption
Date: Sun, 29 Nov 2026 11:25:21 -0800 [thread overview]
Message-ID: <cover.1795967558.git.chris@chrisdown.name> (raw)
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. scsi_debug doesn't unmap
anything when the count is zero, but in SBC it is intended to imply that
every block from the LBA to the end of the disk should be unmapped
unless the device sets WSNZ.
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. A request that still doesn't fit is failed
instead of being truncated.
v3:
- Update the unmap write zeroes limit in zeroing_mode_store(), and
check and change the mode there under the limits lock with the queue
frozen (Bart)
- Change max_write_same_blocks with the queue frozen as well (Bart)
- Set a grown capacity under the limits lock, so that a revalidate
running at the same time can't leave the disk bigger than its modes
can address (Sashiko, Bart)
- Fail requests that don't fit in WRITE SAME(10) in
sd_setup_write_same10_cmnd(), for the ones that the modes and the
limits can't stop (Bart)
- Drop the patch that disabled discard when the granularity is above
the discard limit. That belongs in the block layer, and the new check
stops the truncation in the meantime (Bart)
- Check the gendisk capacity as well in sd_can_use_ws10(), since
sdkp->capacity is zero while a removable disk has no medium (Bart)
- Use U32_MAX in sd_can_use_ws10(), and fix the comment about the
capacity in provisioning_mode_store() (Bart)
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
v2: https://lore.kernel.org/r/cover.1795842371.git.chris@chrisdown.name
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 truncation of WRITE SAME(10) requests that don't fit
drivers/scsi/sd.c | 124 +++++++++++++++++++++++++++++++++++++++-------
1 file changed, 106 insertions(+), 18 deletions(-)
base-commit: efd68f17acca65f581b9f2fa9ba50c8643ab544d
--
2.56.1
next reply other threads:[~2026-11-29 19:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 19:25 Chris Down [this message]
2026-11-29 19:25 ` [PATCH v3 1/5] scsi: sd: Fix stale max_hw_wzeroes_unmap_sectors after a mode change Chris Down
2026-11-29 19:25 ` [PATCH v3 2/5] scsi: sd: Fix data corruption in WRITE SAME(10) write zeroes Chris Down
2026-11-29 19:25 ` [PATCH v3 3/5] scsi: sd: Fix data corruption in WRITE SAME(10) discards Chris Down
2026-11-29 19:25 ` [PATCH v3 4/5] scsi: sd: Fix WRITE SAME(10) count truncation when the mode changes Chris Down
2026-11-29 19:25 ` [PATCH v3 5/5] scsi: sd: Fix truncation of WRITE SAME(10) requests that don't fit Chris Down
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cover.1795967558.git.chris@chrisdown.name \
--to=chris@chrisdown.name \
--cc=James.Bottomley@hansenpartnership.com \
--cc=bvanassche@acm.org \
--cc=hch@lst.de \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=sashiko-bot@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®