From: Bart Van Assche <bvanassche@acm.org>
To: Chris Down <chris@chrisdown.name>,
"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
Subject: Re: [PATCH v2 5/5] scsi: sd: Fix unsplit discards when the granularity exceeds the limit
Date: Sat, 28 Nov 2026 18:41:54 -0800 [thread overview]
Message-ID: <73aefcc3-319d-42a0-afae-7b88ac6594dc@acm.org> (raw)
In-Reply-To: <6e833f169d0c31a3a7da7581c68d4aee5d348ca1.1795842371.git.chris@chrisdown.name>
On 11/28/26 1:26 AM, Chris Down wrote:
> @@ -206,6 +206,17 @@ static void sd_config_discard(struct scsi_disk
*sdkp, struct queue_limits *lim,
>
> lim->max_hw_discard_sectors = max_blocks *
> (logical_block_size >> SECTOR_SHIFT);
> +
> + /*
> + * The block layer doesn't split a discard if the limit is below the
> + * granularity, so we'd get discards of any size.
> + */
> + if (lim->max_hw_discard_sectors &&
> + lim->max_hw_discard_sectors <
> + lim->discard_granularity >> SECTOR_SHIFT) {
> + sdkp->provisioning_mode = SD_LBP_DISABLE;
> + lim->max_hw_discard_sectors = 0;
> + }
> }
My concerns about the above changes are as follows:
1. This only checks lim->max_hw_discard_sectors, whereas
blk_validate_limits() sets:
lim->max_discard_sectors =
min(lim->max_hw_discard_sectors,
lim->max_user_discard_sectors);
and __bio_split_discard() splits against lim->max_discard_sectors.
There are still multiple ways to hit `max_discard_sectors < granularity`
(or 0) with sdkp->provisioning_mode still set to SD_LBP_WS10 /
SD_LBP_ZERO:
- If userspace previously lowered discard_max_bytes and a revalidate
later raises unmap_granularity above max_user_discard_sectors (but
still <= max_hw_discard_sectors), Patch 5 doesn't trigger,
max_discard_sectors remains non-zero, and __bio_split_discard()
returns every discard unsplit.
- SCSI VPD 0xb0 unmap_granularity does not have to be a power of 2,
while queue_max_discard_sectors_store() checks alignment with
`max_discard_bytes & (discard_granularity - 1)`. For example, with
discard_granularity = 0x5000 (40 sectors), writing 0x2000 (16
sectors) passes `0x2000 & 0x4fff == 0`, leaving
0 < max_discard_sectors < granularity and unsplit discards.
- Writing 0 to discard_max_bytes while a large discard is in flight
or being split leaves sdkp->provisioning_mode unchanged while
__bio_split_discard() returns the remaining bio unsplit.
Since this is a block-layer invariant (already worked around in mmc
and drbd as well), shouldn't blk_validate_limits() and/or
__bio_split_discard() handle it centrally?
2. In provisioning_mode_store(), if the user explicitly writes
"writesame_10" or "writesame_zero" and this check overrides
sdkp->provisioning_mode to SD_LBP_DISABLE, the sysfs store still
returns success (`count`) instead of -EINVAL (inconsistent with
patch 3).
3. Pre-existing, but right above this hunk,
`sdkp->unmap_granularity * logical_block_size` is computed in 32-bit
unsigned int from a raw u32 VPD field. A large unmap_granularity
(e.g. >= 0x800000 for 512-byte blocks) overflows and wraps
lim->discard_granularity to a small value, defeating this check.
Thanks,
Bart.
prev parent reply other threads:[~2026-11-29 2:41 UTC|newest]
Thread overview: 10+ 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-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-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-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 [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=73aefcc3-319d-42a0-afae-7b88ac6594dc@acm.org \
--to=bvanassche@acm.org \
--cc=James.Bottomley@hansenpartnership.com \
--cc=chris@chrisdown.name \
--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®