From: Chris Down <chris@chrisdown.name>
To: Christoph Hellwig <hch@lst.de>
Cc: "Martin K. Petersen" <mkp@kernel.org>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@meta.com
Subject: Re: [PATCH 2/2] scsi: sd: Fix data corruption in WRITE SAME(10) discards
Date: Sat, 28 Nov 2026 01:26:44 -0800 [thread overview]
Message-ID: <awqeVFzX-t35Vvs4@chrisdown.name> (raw)
In-Reply-To: <20261111164705.GC18355@lst.de>
Hi Christoph,
Christoph Hellwig writes:
>Nah, that's not really how things work. See my reply to patch 1
>for the suggested proper fix.
Sure, I'll do the same for writesame_10 and writesame_zero in v2.
Even with that, a discard can still reach sd_setup_write_same10_cmnd()
with a count that doesn't fit, though.
One case is a discard that is already queued when the mode changes. sd
sets provisioning_mode before it freezes the queue to commit the new
limits, so that request is still sized for the old mode. For that one
I'll set the mode with the queue frozen instead, as
nvme_update_ns_info_block() does for its own state.
The other is that __bio_split_discard() doesn't split a discard at all
when max_discard_sectors is zero or below the discard granularity. With
scsi_debug, 512-byte blocks and an unmap granularity of 0x10000 blocks,
a 64 MiB discard in writesame_10 mode goes out as a single WRITE
SAME(10) with a count of zero. sd can avoid that one by disabling
discard when the granularity is above its limit, as drbd does. But
writing 0 to discard_max_bytes while a large discard is running also
sends the rest of the bio to sd unsplit, and I don't see how sd can
prevent that with its limits.
An LBA that doesn't fit can still get there as well. bio_check_eod()
only checks a bio against the partition it was submitted to. If a disk
shrinks to 2^32 blocks or fewer while a partition on it still ends
above that, a discard to the end of that partition is sent as WRITE
SAME(10) with its LBA truncated. sd_setup_read_write_cmnd() fails reads
and writes there with "access beyond end of device", but discards and
write zeroes have no such check.
Would you rather I fix those in the block layer, or have sd check the
LBA and count before it builds the command?
Chris
prev parent reply other threads:[~2026-11-28 9:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-07 16:35 [PATCH 0/2] scsi: sd: Fix WRITE SAME(10) data corruption Chris Down
2026-11-07 16:35 ` [PATCH 1/2] scsi: sd: Fix data corruption in WRITE SAME(10) write zeroes Chris Down
2026-11-11 16:46 ` Christoph Hellwig
2026-11-28 9:26 ` Chris Down
2026-11-07 16:35 ` [PATCH 2/2] scsi: sd: Fix data corruption in WRITE SAME(10) discards Chris Down
2026-11-11 16:47 ` Christoph Hellwig
2026-11-28 9:26 ` Chris Down [this message]
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=awqeVFzX-t35Vvs4@chrisdown.name \
--to=chris@chrisdown.name \
--cc=James.Bottomley@hansenpartnership.com \
--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 \
/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