Re: [PATCH v2 3/5] scsi: sd: Fix data corruption in WRITE SAME(10) discards
From: Bart Van Assche
Date: Sat Nov 28 2026 - 21:39:56 EST
On 11/28/26 1:26 AM, Chris Down wrote:
> lim = queue_limits_start_update(sdkp->disk->queue);
> + /* A revalidate updates the capacity under the limits lock. */
> + if ((mode == SD_LBP_WS10 || mode == SD_LBP_ZERO) &&
> + !sd_can_use_ws10(sdkp)) {
> + queue_limits_cancel_update(sdkp->disk->queue);
> + return -EINVAL;
> + }
That comment isn't correct for removable devices:
set_media_not_present() sets sdkp->capacity = 0 without holding
q->limits_lock and without updating get_capacity(sdkp->disk). It is
called from sd_check_events() and from sd_spinup_disk() (which runs in
sd_revalidate_disk() before queue_limits_start_update()).
So on a removable disk with capacity > 2^32 blocks, sd_can_use_ws10()
can see sdkp->capacity == 0 and allow SD_LBP_WS10 / SD_LBP_ZERO while
get_capacity(sdkp->disk) is still > 2^32.
Thanks,
Bart.