From: sashiko-bot@kernel.org
To: "Damien Le Moal" <dlemoal@kernel.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 7/7] scsi: sd_zbc: define storage element management operations
Date: Wed, 07 Oct 2026 08:40:47 +0000 [thread overview]
Message-ID: <sashiko-outbox-162754@kernel.org> (raw)
In-Reply-To: <20261007082344.1049179-8-dlemoal@kernel.org>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] block: race in bdev_remove_storage_element allows DIO during zone removal
- [Medium] scsi: sd_zbc: runt zone omitted from element->nr_zones calculation
- [Medium] scsi: sd_zbc: data race on sdkp->zone_info in sd_zbc_parse_storage_element()
--
commit 944c56308f45deb202a2ccbb04113e14aa6d2842
Author: Damien Le Moal <dlemoal@kernel.org>
scsi: sd_zbc: define storage element management operations
Define the storage element management operations using struct
blk_storage_elements_ops. These operations are valid only on SMR disks
supporting the storage element depopulation feature.
> diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
> index 1bf5f7ea0d9c5..80ed7a8e09a40 100644
> --- a/drivers/scsi/sd_zbc.c
> +++ b/drivers/scsi/sd_zbc.c
> @@ -548,6 +548,239 @@ static void sd_zbc_print_zones(struct scsi_disk *sdkp)
> sdkp->zone_info.zone_blocks);
> }
>
> +static void sd_zbc_parse_storage_element(struct scsi_disk *sdkp, u8 *desc,
> + struct blk_storage_element *element)
> +{
> + struct scsi_device *sdp = sdkp->device;
> + sector_t zone_sectors = sd_zbc_zone_sectors(sdkp);
[Severity: Medium]
Could this read of sdkp->zone_info.zone_blocks (via sd_zbc_zone_sectors) race
with concurrent disk revalidation?
It appears that sd_zbc_parse_storage_element() accesses zone_blocks without
acquiring disk->zone_revalidate_mutex or freezing the request queue via
blk_queue_enter(). Concurrently, disk revalidation (e.g., via the partition
scan ioctl or uevent rescan) can call sd_zbc_revalidate_zones() which modifies
sdkp->zone_info before acquiring zone_revalidate_mutex:
drivers/scsi/sd_zbc.c:sd_zbc_revalidate_zones() {
...
sdkp->zone_info.zone_blocks = zone_blocks;
sdkp->zone_info.nr_zones = nr_zones;
...
}
Can this lead to torn reads, or an ilog2(0) evaluation if the variable is
zeroed concurrently?
> + u64 capacity;
> +
> + memset(element, 0, sizeof(*element));
> +
> + element->id = get_unaligned_be32(&desc[4]);
> +
> + switch (desc[14]) {
> + case SCSI_PHYS_ELEM_TYPE_ALL_ACCESS_STORAGE:
> + element->type = BLK_SE_TYPE_RDWR;
> + capacity = get_unaligned_be64(&desc[16]);
> + if (!zone_sectors || capacity == ULLONG_MAX)
> + element->nr_zones = 0;
> + else
> + element->nr_zones =
> + logical_to_sectors(sdp, capacity) >>
> + ilog2(zone_sectors);
[Severity: Medium]
Does this floor division drop the remainder of the capacity, improperly
omitting the runt zone from the element's zone count?
When the driver parses a BLK_SE_TYPE_RDWR storage element descriptor spanning
a capacity that does not divide perfectly by the zone size (e.g., reaching
the end of the disk where a runt zone resides), the bitwise right shift
silently truncates the remainder.
For comparison, sd_zbc_read_zones() calculates the total disk zones using
round_up(sdkp->capacity, zone_blocks) >> ilog2(zone_blocks) to correctly
account for the runt zone.
[ ... ]
> +static int sd_zbc_remove_storage_element(struct gendisk *disk,
> + unsigned int element_id)
> +{
[Severity: High]
Is it safe to rely on the caller for synchronization here when the block
layer queue freeze has been dropped?
The caller in the block layer actively drops the queue freeze before executing
the removal:
block/blk-zoned.c:bdev_remove_storage_element() {
...
memflags = blk_mq_freeze_queue(disk->queue);
blk_mq_unfreeze_queue(disk->queue, memflags);
ret = disk->fops->se_ops->remove_element(disk, element_id);
...
}
And the ioctl only holds inode_lock:
block/blk-zoned.c:blkdev_remove_storage_element_ioctl() {
...
filemap_invalidate_unlock(bdev->bd_mapping);
if (!ret)
ret = bdev_remove_storage_element(bdev, element_id);
inode_unlock(bdev->bd_mapping->host);
...
}
Since direct I/O (via blkdev_write_iter) explicitly bypasses inode_lock for
block devices, this seems to allow direct I/O to be issued while the element
is actively being removed. Could this cause torn state between the hardware
and the block layer's in-memory zone write plug tracking?
> + struct scsi_disk *sdkp = scsi_disk(disk);
> + struct scsi_device *sdp = sdkp->device;
> + const int timeout = sdp->request_queue->rq_timeout;
> + struct scsi_sense_hdr sshdr;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261007082344.1049179-1-dlemoal@kernel.org?part=7
prev parent reply other threads:[~2026-10-07 8:40 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 8:23 [PATCH v3 0/7] Add support for storage element depopulation Damien Le Moal
2026-10-07 8:23 ` [PATCH v3 1/7] block: fail reads to offline zones early Damien Le Moal
2026-10-07 8:41 ` sashiko-bot
2026-10-07 13:29 ` Christoph Hellwig
2026-10-07 14:31 ` Damien Le Moal
2026-10-07 8:23 ` [PATCH v3 2/7] block: introduce storage element management Damien Le Moal
2026-10-07 8:34 ` sashiko-bot
2026-10-07 13:35 ` Christoph Hellwig
2026-10-07 14:35 ` Damien Le Moal
2026-10-07 8:23 ` [PATCH v3 3/7] block: add storage element management ioctls Damien Le Moal
2026-10-07 8:39 ` sashiko-bot
2026-10-07 13:39 ` Christoph Hellwig
2026-10-07 14:37 ` Damien Le Moal
2026-10-07 15:28 ` Christoph Hellwig
2026-10-07 8:23 ` [PATCH v3 4/7] zloop: add storage element emulation Damien Le Moal
2026-10-07 8:35 ` sashiko-bot
2026-10-07 13:40 ` Christoph Hellwig
2026-10-07 8:23 ` [PATCH v3 5/7] zloop: add degrade_element control command Damien Le Moal
2026-10-07 8:39 ` sashiko-bot
2026-10-07 8:23 ` [PATCH v3 6/7] scsi: sd_zbc: always revalidate zones for disks supporting head depopulation Damien Le Moal
2026-10-07 8:35 ` sashiko-bot
2026-10-07 8:23 ` [PATCH v3 7/7] scsi: sd_zbc: define storage element management operations Damien Le Moal
2026-10-07 8:40 ` sashiko-bot [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=sashiko-outbox-162754@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dlemoal@kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).