Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Damien Le Moal" <dlemoal@kernel.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v4 9/9] scsi: sd_zbc: define storage element management operations
Date: Fri, 09 Oct 2026 09:28:49 +0000	[thread overview]
Message-ID: <sashiko-outbox-165166@kernel.org> (raw)
In-Reply-To: <20261009090945.1504194-10-dlemoal@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] scsi: sd_zbc: concurrent I/O races with storage element modification due to unfrozen queue
- [Medium] scsi: sd_zbc: nr_zones calculation for ALL_ACCESS_STORAGE omits runt zone
--

commit f862e7a8a5445f6170e01d1055958c0159fb3b36
Author: Damien Le Moal <dlemoal@kernel.org>

scsi: sd_zbc: define storage element management operations

This commit defines storage element management operations (report, remove,
restore) via struct blk_se_ops. These operations are intended for SMR disks
supporting the storage element depopulation feature.

> diff --git a/drivers/scsi/sd_zbc.c b/drivers/scsi/sd_zbc.c
> index 1bf5f7ea0d9c5..2f79a8d7b9d93 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_se *element)
> +{
> +	struct scsi_device *sdp = sdkp->device;
> +	sector_t zone_sectors = sd_zbc_zone_sectors(sdkp);
> +	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]
For devices with a "runt" zone at the end, the total capacity is not a
perfect multiple of the zone size. Since the bitwise right shift performs
integer division that rounds down, could this silently truncate the
remainder blocks?

If so, does this cause the element to under-report the total number of zones
by one, creating a mismatch with the core block layer's zone count (which
properly rounds up)?

> +		break;
> +	case SCSI_PHYS_ELEM_TYPE_FRAC_ACCESS_STORAGE:
[ ... ]
> +static int sd_zbc_remove_storage_element(struct gendisk *disk,
> +					 unsigned int element_id)
> +{
> +	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;
> +	const struct scsi_exec_args exec_args = {
> +		.sshdr = &sshdr,
> +	};
> +	unsigned char cmd[16];
> +	int result;
> +
> +	if (!sdkp->modify_zones_supported)
> +		return -EOPNOTSUPP;
> +
> +	memset(cmd, 0, 16);
> +	cmd[0] = SERVICE_ACTION_IN_16;
> +	cmd[1] = SAI_REMOVE_ELEMENT_AND_MODIFY_ZONES;
> +	put_unaligned_be32(element_id, &cmd[10]);
> +
> +	result = scsi_execute_cmd(sdp, cmd, REQ_OP_DRV_IN, NULL, 0,
> +				  timeout, 1, &exec_args);

[Severity: High]
The block layer explicitly unfreezes the queue before invoking the se_ops
callback. For example, in 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);

Because the queue is unfrozen when sd_zbc_remove_storage_element() is
called, another process could issue direct I/Os (e.g. via io_uring) to the
queue. Can the hardware zone topology modification sent via this SCSI
command race with concurrent I/O operations and lead to I/O failures or
data corruption?

> +	if (result) {
> +		sd_printk(KERN_ERR, sdkp,
> +			  "REMOVE ELEMENT AND MODIFY ZONES failed\n");

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261009090945.1504194-1-dlemoal@kernel.org?part=9

      reply	other threads:[~2026-10-09  9:28 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09  9:09 [PATCH v4 0/9] Add support for storage element depopulation Damien Le Moal
2026-10-09  9:09 ` [PATCH v4 1/9] block: introduce disk_zone_is_offline() Damien Le Moal
2026-10-12 12:04   ` Christoph Hellwig
2026-10-09  9:09 ` [PATCH v4 2/9] block: refactor blk_revalidate_disk_zones() Damien Le Moal
2026-10-12 12:04   ` Christoph Hellwig
2026-10-09  9:09 ` [PATCH v4 3/9] block: introduce storage element management Damien Le Moal
2026-10-09  9:24   ` sashiko-bot
2026-10-09  9:09 ` [PATCH v4 4/9] block: add storage element management ioctls Damien Le Moal
2026-10-09  9:28   ` sashiko-bot
2026-10-09  9:09 ` [PATCH v4 5/9] zloop: add storage element emulation Damien Le Moal
2026-10-09  9:21   ` sashiko-bot
2026-10-09  9:09 ` [PATCH v4 6/9] zloop: add degrade_element control command Damien Le Moal
2026-10-09  9:09 ` [PATCH v4 7/9] scsi: sd: fail read commands to offline zones early Damien Le Moal
2026-10-09  9:09 ` [PATCH v4 8/9] scsi: sd_zbc: always revalidate zones for disks supporting head depopulation Damien Le Moal
2026-10-09  9:32   ` sashiko-bot
2026-10-09  9:34     ` Damien Le Moal
2026-10-09  9:09 ` [PATCH v4 9/9] scsi: sd_zbc: define storage element management operations Damien Le Moal
2026-10-09  9:28   ` 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-165166@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