From: sashiko-bot@kernel.org
To: "Damien Le Moal" <dlemoal@kernel.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v4 5/9] zloop: add storage element emulation
Date: Fri, 09 Oct 2026 09:21:56 +0000 [thread overview]
Message-ID: <sashiko-outbox-165156@kernel.org> (raw)
In-Reply-To: <20261009090945.1504194-6-dlemoal@kernel.org>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] block: IDR and module leak on zloop_ctl_add error path
- [High] block: zone reset vfs_truncate races with in-flight IO
- [Medium] block/zloop: elements left in RESTORE_IN_PROGRESS on error
--
commit 2aa446d71ddca7634ded310055adccb68fd83788
Author: Damien Le Moal <dlemoal@kernel.org>
Subject: zloop: add storage element emulation
Emulate the storage element depopulation feature of SMR disks in the
zloop driver. This emulation is controlled using the new stor_elements
option.
> diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
> --- a/drivers/block/zloop.c
> +++ b/drivers/block/zloop.c
> @@ -420,7 +486,22 @@ static int zloop_close_zone(struct zloop_device *zlo, unsigned int zone_no)
> return ret;
> }
>
> -static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no)
> +static int zloop_do_reset_zone(struct zloop_device *zlo,
> + struct zloop_zone *zone)
> +{
> + if (vfs_truncate(&zone->file->f_path, 0))
> + return -EIO;
> +
[Severity: High]
Is there a potential race between this background truncation and active I/O?
When zloop_restore_elements() sets zlo->restore_in_progress = true and
schedules the background restore work, it rejects new I/O but doesn't
appear to drain in-flight I/O (for example, by using blk_mq_freeze_queue()).
If an in-flight REQ_OP_WRITE in zloop_cmd_workfn() executes
zloop_seq_write_prep() (which acquires zone->wp_lock, but not zone->lock)
at the same time this worker calls vfs_truncate(), could the worker
truncate the file to 0 just before the write completes at the old write
pointer? This might desync zone->wp and create a massive sparse file.
[ ... ]
> +static void zloop_restore_elements_work(struct work_struct *work)
> +{
> + struct zloop_device *zlo = container_of(work, struct zloop_device,
> + restore_elements_work.work);
> + struct zloop_zone *zone;
> + struct blk_se *se;
> + unsigned int i;
> + int ret;
> +
> + mutex_lock(&zlo->stor_elements_lock);
> +
> + /* Reset all zones. */
> + for (i = 0, zone = zlo->zones; i < zlo->nr_zones; i++, zone++) {
> + if (test_bit(ZLOOP_ZONE_CONV, &zone->flags)) {
> + zloop_restore_conv_zone(zlo, zone);
> + continue;
> + }
> + ret = zloop_restore_seq_zone(zlo, zone);
> + if (ret)
> + goto out_unlock;
[Severity: Medium]
If a zone file truncation fails here, are the storage elements left
indefinitely in the BLK_SE_STS_RESTORE_IN_PROGRESS state?
The error path jumps to out_unlock, which clears zlo->restore_in_progress
but skips updating the se->status for individual elements. Should this error
path transition the elements to BLK_SE_STS_RESTORE_ERROR instead, so that
userspace queries (like zloop_report_elements()) return an accurate status?
> + }
> +
> + /* Restore all removed elements. */
> + for (i = 0, se = zlo->elements; i < zlo->nr_elements; i++, se++) {
> + if (READ_ONCE(se->status) == BLK_SE_STS_RESTORE_IN_PROGRESS)
> + WRITE_ONCE(se->status, BLK_SE_STS_OK);
> + }
> +
> + zlo->nr_removed_elements = 0;
> +
> +out_unlock:
> + WRITE_ONCE(zlo->restore_in_progress, false);
> + mutex_unlock(&zlo->stor_elements_lock);
> +}
[ ... ]
> @@ -1361,6 +1870,10 @@ static int zloop_ctl_add(struct zloop_options *opts)
> zlo->id, zlo->nr_zones,
> ((sector_t)zlo->zone_size << SECTOR_SHIFT) >> 20,
> zlo->block_size);
> + if (zlo->nr_elements)
> + pr_info("zloop%d: %d storage elements\n",
> + zlo->id, zlo->nr_elements);
> +
> pr_info("zloop%d: using %s%s zone append\n",
> zlo->id,
> zlo->ordered_zone_append ? "ordered " : "",
> @@ -1370,6 +1883,8 @@ static int zloop_ctl_add(struct zloop_options *opts)
>
> out_cleanup_disk:
> put_disk(zlo->disk);
> + return ret;
> +
[Severity: High]
Does this early return bypass the IDR removal and module reference put?
If we return here, the out_free_idr label (which calls idr_remove()) and
the final out label (which calls module_put(THIS_MODULE)) are completely
skipped.
Since put_disk() ultimately triggers zloop_free_disk() which frees the
zlo structure via kvfree(zlo), does leaving the freed pointer in
zloop_index_idr create a dangling pointer for subsequent lookups? It also
appears the module reference would be leaked permanently.
> out_cleanup_tags:
> blk_mq_free_tag_set(&zlo->tag_set);
> out_close_files:
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261009090945.1504194-1-dlemoal@kernel.org?part=5
next prev parent reply other threads:[~2026-10-09 9:21 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 [this message]
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
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-165156@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.