Re: [PATCH v2 5/5] scsi: sd: Fix unsplit discards when the granularity exceeds the limit

From: Chris Down

Date: Sun Nov 29 2026 - 14:26:11 EST


Hi Bart,

Bart Van Assche writes:
> 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?

Yeah, I think that's the right place for it. sd isn't told when the
user limit changes, so it can only ever cover the case where the
device's own granularity is above its limit. I'll drop this patch from
v3 and look at fixing it in the block layer separately. With the check
in sd_setup_write_same10_cmnd() from your review of patch 4, a discard
that reaches sd unsplit in the meantime is failed instead of being sent
with a truncated count.

>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).

That goes away with the patch.

>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.

Good catch. That one isn't specific to WRITE SAME(10), so I'll look at
it separately as well.

Thanks!

Chris