From: sashiko-bot@kernel.org
To: "Chris Down" <chris@chrisdown.name>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v2 4/5] scsi: sd: Fix WRITE SAME(10) count truncation when the mode changes
Date: Sat, 28 Nov 2026 09:46:30 +0000 [thread overview]
Message-ID: <sashiko-outbox-238601@kernel.org> (raw)
In-Reply-To: <a1acc1de43d8ee89d64e345da817f7ac3585e86d.1795842371.git.chris@chrisdown.name>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] scsi: sd: unlocked set_capacity_and_notify() in
sd_revalidate_disk()
--
commit c8bf97f59b4ffaebd830de4ab08208e4fd13924d
Author: Chris Down <chris@chrisdown.name>
scsi: sd: Fix WRITE SAME(10) count truncation when the mode changes
This commit updates provisioning_mode and zeroing_mode only while the
request queue is frozen, and defers increasing the gendisk capacity in
sd_revalidate_disk() until after the modes and queue limits are updated.
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index d995650bc8a10..792058f52f65e 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
[ ... ]
> @@ -3901,10 +3906,27 @@ static void sd_revalidate_disk(struct gendisk *disk)
>
> sdkp->first_scan = 0;
>
> - set_capacity_and_notify(disk, logical_to_sectors(sdp, sdkp->capacity));
> - sd_config_write_same(sdkp, lim);
> + /*
> + * The WRITE SAME(10) modes can't address all of a disk with more than
> + * 2^32 blocks, so don't show a bigger capacity until they are gone.
> + */
> + sectors = logical_to_sectors(sdp, sdkp->capacity);
> + grown = sectors > get_capacity(disk);
> + if (!grown)
> + set_capacity_and_notify(disk, sectors);
>
> - err = queue_limits_commit_update_frozen(sdkp->disk->queue, lim);
> + /*
> + * Queued requests are sized for the old modes, so only change the
> + * modes once the queue is frozen.
> + */
> + memflags = blk_mq_freeze_queue(sdkp->disk->queue);
> + if (sdkp->media_present)
> + sd_config_discard(sdkp, lim, sd_discard_mode(sdkp));
> + sd_config_write_same(sdkp, lim);
> + err = queue_limits_commit_update(sdkp->disk->queue, lim);
> + blk_mq_unfreeze_queue(sdkp->disk->queue, memflags);
> + if (grown)
> + set_capacity_and_notify(disk, sectors);
> if (err)
> goto out;
[Severity: Medium]
Can calling set_capacity_and_notify() in the grown path after
queue_limits_commit_update() unlocks q->limits_lock race with a
concurrent sd_revalidate_disk() or update the capacity after a failed
limits commit?
sd_revalidate_disk() can be entered concurrently from sd_rescan(),
sd_open(), and cache_type_store(), relying on q->limits_lock to serialize
updates. When the disk grows past 2^32 blocks and then shrinks back:
CPU0 CPU1
sd_revalidate_disk()
queue_limits_start_update()
sd_read_capacity() (> 2^32)
grown = true
queue_limits_commit_update()
mutex_unlock(&q->limits_lock)
sd_revalidate_disk()
queue_limits_start_update()
sd_read_capacity() (<= 2^32)
grown = false
set_capacity_and_notify()
sd_config_discard() (SD_LBP_WS10)
queue_limits_commit_update()
set_capacity_and_notify()
<-- overwrites capacity with > 2^32 while in WRITE SAME(10) mode
In addition, because err is checked after set_capacity_and_notify(), a
failed queue_limits_commit_update() still publishes the new capacity while
leaving the old queue limits in place and skipping
sd_zbc_revalidate_zones().
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795842371.git.chris@chrisdown.name?part=4
next prev parent reply other threads:[~2026-11-28 9:46 UTC|newest]
Thread overview: 7+ 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-28 9:26 ` [PATCH v2 3/5] scsi: sd: Fix data corruption in WRITE SAME(10) discards 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-28 9:46 ` sashiko-bot [this message]
2026-11-28 9:26 ` [PATCH v2 5/5] scsi: sd: Fix unsplit discards when the granularity exceeds the limit 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=sashiko-outbox-238601@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=chris@chrisdown.name \
--cc=linux-scsi@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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