All of lore.kernel.org
 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 v5 4/9] block: add storage element management ioctls
Date: Mon, 12 Oct 2026 13:40:08 +0000	[thread overview]
Message-ID: <sashiko-outbox-168194@kernel.org> (raw)
In-Reply-To: <20261012130121.1902634-5-dlemoal@kernel.org>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] block: concurrent I/O race in storage element removal/restoration
- [High] block: silent data loss in conventional zones on storage element ioctls
- [High] block: cross-partition data destruction via storage element ioctls
- [Medium] block: zone state permanently desynchronized if SE ioctl is interrupted
--

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

block: add storage element management ioctls

This commit introduces new ioctl commands for storage element management on
zoned block devices. The new commands allow userspace to query, report,
remove, and restore storage elements.

> diff --git a/block/blk-zoned.c b/block/blk-zoned.c
> index 46822c7a05ecc..8736e80b4080d 100644
> --- a/block/blk-zoned.c
> +++ b/block/blk-zoned.c

[ ... ]

> @@ -2917,6 +2968,52 @@ int bdev_remove_storage_element(struct block_device *bdev,
>  }
>  EXPORT_SYMBOL_GPL(bdev_remove_storage_element);
>  
> +static int blkdev_flush_and_truncate(struct block_device *bdev,
> +				     blk_mode_t mode)
> +{
> +	int ret;
> +
> +	inode_lock(bdev->bd_mapping->host);
> +	filemap_invalidate_lock(bdev->bd_mapping);
> +	ret = blkdev_issue_flush(bdev->bd_disk->part0);
> +	if (!ret)
> +		ret = truncate_bdev_range(bdev, mode, 0,
> +					  bdev_nr_bytes(bdev) - 1);

[Severity: High]
Will this discard unwritten buffered data in conventional zones?

While users might typically use direct I/O for zoned devices, zoned devices
can contain conventional zones which fully support and commonly use buffered
I/O. truncate_bdev_range() delegates to truncate_inode_pages_range() which
forcefully drops all pages in the mapping. Could dirty pages be silently
destroyed here? Should this code call filemap_write_and_wait() before
truncating the cache?

[Severity: High]
Does this only invalidate the page cache for the opened partition?

When a user invokes these ioctls on a partition (e.g., /dev/sda1),
bdev->bd_mapping is the page cache for that partition. Since the underlying
hardware operation modifies the entire physical device, the page caches for
the whole disk and other partitions are not invalidated, which could lead to
stale reads and silent data corruption across the system.

> +	filemap_invalidate_unlock(bdev->bd_mapping);
> +	inode_unlock(bdev->bd_mapping->host);
> +
> +	return ret;
> +}

[Severity: High]
Are we safely dropping the VFS locks before the storage element removal
starts?

The locks preventing concurrent I/O and page cache repopulation are released
here. When the ioctl handler later delegates to
bdev_remove_storage_element(), there is no barrier preventing concurrent
processes from opening the device and issuing buffered or direct I/Os during
a destructive hardware operation.

> +
> +static int blkdev_remove_storage_element_ioctl(struct block_device *bdev,
> +					blk_mode_t mode, void __user *argp)
> +{
> +	unsigned int element_id;
> +	int ret;
> +
> +	if (!(mode & BLK_OPEN_WRITE))
> +		return -EBADF;
> +	if (bdev_read_only(bdev))
> +		return -EPERM;

[Severity: High]
Is a user with write access to a single partition able to destroy data on
other partitions?

The storage element ioctls issue a disk-wide destructive hardware command
that can alter the physical geometry of the drive. Without checking if the
block device is a partition (e.g., via bdev_is_partition()) or requiring
capable(CAP_SYS_ADMIN), these operations might destroy zones belonging to
other partitions.

[ ... ]

> +	/*
> +	 * Flush the device volatile write cache and invalidate all cached data
> +	 * so that reads do not return old data for zones that went offline.
> +	 * Since a user can only write to zoned devices using direct IOs, we
> +	 * should never have any dirty page invalidated and so no data loss as
> +	 * long as the device cache flush succeeds, that is, as long as the
> +	 * flush does not use degraded storage elements.
> +	 */
> +	ret = blkdev_flush_and_truncate(bdev, mode);
> +	if (ret)
> +		return ret;
> +
> +	return bdev_remove_storage_element(bdev, element_id);
> +}

[Severity: High]
Is it safe to rely on the caller to prevent new I/Os here?

bdev_remove_storage_element() freezes the queue but immediately unfreezes
it before executing the long-running remove_element callback. Since the VFS
locks were already dropped in blkdev_flush_and_truncate(), the device is
left unprotected from concurrent I/Os during a destructive hardware
operation.

[Severity: Medium]
Could the zone state become permanently desynchronized if this ioctl is
interrupted?

When this ioctl is interrupted by a fatal signal, the underlying loop in
disk_wait_for_se_mgmt_completion() returns -EINTR and
bdev_remove_storage_element() immediately revalidates the zones while the
hardware operation is still in progress.

Because the polling loop was the only tracking mechanism, the kernel's
zones_state array is never updated to reflect the final state of the
depopulated zones once the hardware finishes. This leaves the kernel
permanently desynchronized, potentially leading to unexpected I/O errors.

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

  reply	other threads:[~2026-10-12 13:40 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 13:01 [PATCH v5 0/9] Add support for storage element depopulation Damien Le Moal
2026-10-12 13:01 ` [PATCH v5 1/9] block: introduce disk_zone_is_offline() Damien Le Moal
2026-10-12 13:01 ` [PATCH v5 2/9] block: refactor blk_revalidate_disk_zones() Damien Le Moal
2026-10-12 13:01 ` [PATCH v5 3/9] block: introduce storage element management Damien Le Moal
2026-10-12 13:23   ` sashiko-bot
2026-10-12 13:27     ` Damien Le Moal
2026-10-12 14:23   ` Christoph Hellwig
2026-10-12 13:01 ` [PATCH v5 4/9] block: add storage element management ioctls Damien Le Moal
2026-10-12 13:40   ` sashiko-bot [this message]
2026-10-12 13:49     ` Damien Le Moal
2026-10-12 14:31   ` Christoph Hellwig
2026-10-12 14:56     ` Damien Le Moal
2026-10-12 14:57       ` Christoph Hellwig
2026-10-12 14:59         ` Damien Le Moal
2026-10-12 13:01 ` [PATCH v5 5/9] zloop: add storage element emulation Damien Le Moal
2026-10-12 13:52   ` sashiko-bot
2026-10-12 13:01 ` [PATCH v5 6/9] zloop: add degrade_element control command Damien Le Moal
2026-10-12 14:02   ` sashiko-bot
2026-10-12 14:43   ` Christoph Hellwig
2026-10-12 13:01 ` [PATCH v5 7/9] scsi: sd: fail read commands to offline zones early Damien Le Moal
2026-10-12 14:36   ` Christoph Hellwig
2026-10-12 13:01 ` [PATCH v5 8/9] scsi: sd_zbc: always revalidate zones for disks supporting head depopulation Damien Le Moal
2026-10-12 14:19   ` sashiko-bot
2026-10-12 14:37   ` Christoph Hellwig
2026-10-12 14:57     ` Damien Le Moal
2026-10-12 13:01 ` [PATCH v5 9/9] scsi: sd_zbc: define storage element management operations Damien Le Moal
2026-10-12 14:38   ` Christoph Hellwig

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-168194@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.