From: Chris Down <chris@chrisdown.name>
To: Bart Van Assche <bvanassche@acm.org>
Cc: "Martin K. Petersen" <mkp@kernel.org>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
Christoph Hellwig <hch@lst.de>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@meta.com
Subject: Re: [PATCH v2 4/5] scsi: sd: Fix WRITE SAME(10) count truncation when the mode changes
Date: Sun, 29 Nov 2026 11:25:35 -0800 [thread overview]
Message-ID: <awx8Lz3iR7fNAK5K@chrisdown.name> (raw)
In-Reply-To: <faa1aec5-8630-4c0a-b5b8-480447ad1fa2@acm.org>
Hi Bart,
Bart Van Assche writes:
>1. max_write_same_blocks_store() was missed. It still modifies
> sdp->no_write_same and sdkp->max_ws_blocks before
> queue_limits_start_update(), and calls sd_config_write_same() before
> queue_limits_commit_update_frozen() freezes the queue.
Yep, I'll move all of that under the lock and the freeze in v3.
>2. Both here and in sd_revalidate_disk(), sd_config_discard() and
> sd_config_write_same() mutate sdkp->provisioning_mode,
> sdkp->zeroing_mode, and sdkp->max_ws_blocks before
> queue_limits_commit_update() validates lim. If
> queue_limits_commit_update() returns an error, q->limits keeps the
> old (potentially larger) limits while sdkp has already switched to
> the new mode.
That's how it is before this series as well, since sd_config_discard()
and sd_config_write_same() have always run before the commit. With the
check from your point 4, a request that was sized for the old limits is
failed instead of being truncated, so I'd rather not add unwinding to
this series on top of that.
>3. As sashiko-bot also pointed out, in the `grown` path:
> - `if (err) goto out;` is checked after `set_capacity_and_notify()`,
> so a failed limits commit still publishes the larger capacity and
> skips sd_zbc_revalidate_zones().
This one isn't new either. sd_revalidate_disk() already set the
capacity before the commit and only looked at err afterwards. The modes
have changed by then even if the commit failed, so the bigger capacity
is still one that they can address.
> - queue_limits_commit_update() unlocks q->limits_lock, so
> `if (grown) set_capacity_and_notify(disk, sectors);` runs unlocked
> and can race with a concurrent sd_revalidate_disk() (from
> sd_rescan(), sd_open(), or cache_type_store()) that shrinks the
> disk back <= 2^32 and re-enables WRITE SAME(10) modes.
Yes, that race is there. In v3 I'll set a grown capacity under the
limits lock, so that it's always the one the current modes were picked
for.
> That's another strong reason to also enforce the LBA/count bounds in
> sd_setup_write_same10_cmnd().
Agreed. I asked Christoph in [1] whether he'd rather have that or a fix
in the block layer, but I can reproduce the partition case on v2 with
scsi_debug. A discard through a partition that still ends above 2^32
blocks after the shrink goes out with LBA 0 and unmaps the start of the
disk. So I'll add the check in v3 on top of the mode changes. It also
takes care of the unsplit discards from your review of patch 5.
Thanks!
Chris
[1] https://lore.kernel.org/r/awqeVFzX-t35Vvs4@chrisdown.name
next prev parent reply other threads:[~2026-11-29 19:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
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-29 2:38 ` Bart Van Assche
2026-11-29 19:25 ` 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-29 2:39 ` Bart Van Assche
2026-11-29 19:25 ` 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-29 2:40 ` Bart Van Assche
2026-11-29 19:25 ` Chris Down [this message]
2026-11-28 9:26 ` [PATCH v2 5/5] scsi: sd: Fix unsplit discards when the granularity exceeds the limit Chris Down
2026-11-29 2:41 ` Bart Van Assche
2026-11-29 19:25 ` 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=awx8Lz3iR7fNAK5K@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 \
/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®