All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Damien Le Moal" <dlemoal@kernel.org>, linux-scsi@vger.kernel.org
Subject: Re: [PATCH v12 08/13] zloop: add storage element emulation
Date: Tue, 17 Nov 2026 16:20:45 +0000	[thread overview]
Message-ID: <sashiko-outbox-219155@kernel.org> (raw)
In-Reply-To: <20261117155739.304506-9-dlemoal@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] zloop: serialize zloop_ctl_remove() with storage element ops
--

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

zloop: add storage element emulation

This commit adds storage element depopulation and restoration emulation to the
zloop driver, controlled via a new stor_elements option and exposed through
zloop_se_ops.

> diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
> index 6bb68022ab30e..a4536e6240c0b 100644
> --- a/drivers/block/zloop.c
> +++ b/drivers/block/zloop.c

[ ... ]

> @@ -1388,6 +2022,12 @@ static void zloop_forget_cache(struct zloop_device *zlo)
>  
>  	pr_info("%pg: discarding volatile write cache\n", zlo->disk->part0);
>  
> +	/*
> +	 * Serialize with storage element removal or restoration that may be
> +	 * finishing running during device removal.
> +	 */
> +	mutex_lock(&zlo->stor_elements_lock);
> +
>  	for (i = 0; i < zlo->nr_zones; i++) {
>  		struct zloop_zone *zone = &zlo->zones[i];
>  		struct file *file = zone->file;
> @@ -1418,6 +2058,8 @@ static void zloop_forget_cache(struct zloop_device *zlo)
>  		vfs_truncate(&file->f_path,
>  			(old_wp - zone->start) << SECTOR_SHIFT);
>  	}
> +
> +	mutex_unlock(&zlo->stor_elements_lock);
>  }

[Severity: Medium]
Can zloop_ctl_remove() finish and return to userspace while
zloop_execute_restore_elements() is still truncating zone backing files when
discard_write_cache is disabled?

zloop_forget_cache() is only called from zloop_ctl_remove() when
zlo->discard_write_cache is set:

drivers/block/zloop.c:zloop_ctl_remove() {
    ...
	del_gendisk(zlo->disk);

	if (zlo->discard_write_cache)
		zloop_forget_cache(zlo);

	put_disk(zlo->disk);
    ...
}

When discard_write_cache is false (the default), nothing in zloop_ctl_remove()
acquires zlo->stor_elements_lock to wait for an in-flight storage element
operation that passed the Zlo_deleting check just before removal started:

CPU0                                    CPU1
zloop_restore_elements()
  msleep(5000)
  mutex_lock(&zlo->stor_elements_lock)
  /* zlo->state != Zlo_deleting */
                                        zloop_ctl_remove()
                                          idr_remove(&zloop_index_idr, ...)
                                          WRITE_ONCE(zlo->state, Zlo_deleting)
                                          del_gendisk(zlo->disk)
                                          put_disk(zlo->disk)
                                          return 0;
  zloop_execute_restore_elements()
    zloop_restore_zone()
      vfs_truncate(...)  <-- runs after device removal completed

If userspace re-adds the device with the same ID or accesses base_dir after
remove returns, the ongoing truncations from the old instance race with the
new accesses and corrupt the zone files.  Acquiring zlo->stor_elements_lock in
zloop_ctl_remove() after del_gendisk() would serialize removal regardless of
discard_write_cache.

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

  reply	other threads:[~2026-11-17 16:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 15:57 [PATCH v12 00/13] Add support for storage element depopulation Damien Le Moal
2026-11-17 15:57 ` [PATCH v12 01/13] block: introduce disk_zone_is_offline() Damien Le Moal
2026-11-17 15:57 ` [PATCH v12 02/13] block: refactor blk_revalidate_disk_zones() Damien Le Moal
2026-11-17 15:57 ` [PATCH v12 03/13] block: allow dropping all zone write plugs on revalidation Damien Le Moal
2026-11-17 15:57 ` [PATCH v12 04/13] block: introduce storage element management Damien Le Moal
2026-11-17 15:57 ` [PATCH v12 05/13] block: add storage element management ioctls Damien Le Moal
2026-11-17 15:57 ` [PATCH v12 06/13] zloop: fix ordered zone append handling Damien Le Moal
2026-11-17 15:57 ` [PATCH v12 07/13] zloop: fix zone reporting consistency Damien Le Moal
2026-11-17 15:57 ` [PATCH v12 08/13] zloop: add storage element emulation Damien Le Moal
2026-11-17 16:20   ` sashiko-bot [this message]
2026-11-17 15:57 ` [PATCH v12 09/13] zloop: add degrade_element control command Damien Le Moal
2026-11-17 15:57 ` [PATCH v12 10/13] scsi: scsi_proto: refine the definition of storage element health Damien Le Moal
2026-11-17 15:57 ` [PATCH v12 11/13] scsi: sd_zbc: always revalidate zones for disks supporting head depopulation Damien Le Moal
2026-11-17 15:57 ` [PATCH v12 12/13] scsi: sd_zbc: define storage element management operations Damien Le Moal
2026-11-17 15:57 ` [PATCH v12 13/13] scsi: sd: fail read commands to offline zones early Damien Le Moal

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-219155@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.