From: sashiko-bot@kernel.org
To: "Damien Le Moal" <dlemoal@kernel.org>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH v3 4/7] zloop: add storage element emulation
Date: Wed, 07 Oct 2026 08:35:58 +0000 [thread overview]
Message-ID: <sashiko-outbox-162750@kernel.org> (raw)
In-Reply-To: <20261007082344.1049179-5-dlemoal@kernel.org>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] block: permanent device bricking due to uncleared restore_in_progress flag
- [High] block: restored storage elements' zones are permanently left offline or read-only
- [Medium] block: TOCTOU race allows I/O on OFFLINE/READONLY zones during removal
--
commit 20ddc2153af7f05d1115bfa8b2509e5c9f65e4f8
Author: Damien Le Moal <dlemoal@kernel.org>
Subject: zloop: add storage element emulation
This commit adds storage element emulation to the zloop driver,
allowing simulation of SMR disk fractional access storage elements.
> diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
> index 394dc2408ed73..e113ecd63c0b2 100644
> --- a/drivers/block/zloop.c
> +++ b/drivers/block/zloop.c
[ ... ]
> @@ -430,20 +511,19 @@ static int zloop_reset_zone(struct zloop_device *zlo, unsigned int zone_no)
>
> mutex_lock(&zone->lock);
>
> + if (zloop_zone_is_offline_or_readonly(zlo, zone)) {
> + if (!all_zones)
> + ret = -EIO;
> + goto unlock;
> + }
> +
> if (!test_bit(ZLOOP_ZONE_SEQ_ERROR, &zone->flags) &&
> zone->cond == BLK_ZONE_COND_EMPTY)
> goto unlock;
[Severity: High]
In zloop_restore_elements_work(), the code calls zloop_reset_all_zones()
to reset the zones of restored elements, which in turn calls this function
as zloop_reset_zone(..., all_zones=true).
Since zloop_zone_is_offline_or_readonly() evaluates to true for these
removed elements' zones, the function jumps to unlock and skips
zloop_do_reset_zone().
Does this permanently leave the restored elements' zones offline or
read-only, preventing the restoration from completing successfully?
[ ... ]
> +static bool zloop_prep_rq(struct zloop_device *zlo, struct request *rq)
> +{
> + struct zloop_zone *zone = &zlo->zones[rq_zone_no(rq)];
> + bool is_write = op_is_write(req_op(rq));
> + bool ret = true;
> +
> + spin_lock(&zone->wp_lock);
> +
> + if (zlo->nr_elements) {
> + if (zone->cond == BLK_ZONE_COND_OFFLINE ||
> + (zone->cond == BLK_ZONE_COND_READONLY && is_write)) {
> + ret = false;
> + goto unlock;
> + }
> + }
[Severity: Medium]
Is there a time-of-check to time-of-use race condition here?
This validates the zone condition against offline and read-only states
before adding the I/O request to the workqueue. If a concurrently
executing zloop_remove_element_work() transitions the zone condition to
offline while the request is pending in the queue, the request could still
be processed.
Once popped from the queue, zloop_handle_cmd() calls zloop_rw(), which
executes reads and conventional zone writes without re-acquiring the zone
lock or re-validating the zone condition. Could this allow reads and writes
to execute against offlined zones?
[ ... ]
> +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 blk_storage_element *se;
> + unsigned int i;
> + int ret;
> +
> + mutex_lock(&zlo->stor_elements_lock);
> +
> + /* Reset all zones. */
> + ret = zloop_reset_all_zones(zlo);
> + if (ret)
> + goto out_unlock;
> +
> + /* Restore all removed elements. */
> + for (i = 0, se = zlo->elements; i < zlo->nr_elements; i++, se++) {
> + if (se->status == BLK_SE_STS_RESTORE_IN_PROGRESS)
> + se->status = BLK_SE_STS_OK;
> + }
> +
> + zlo->nr_removed_elements = 0;
> + WRITE_ONCE(zlo->restore_in_progress, false);
> +
> +out_unlock:
> + mutex_unlock(&zlo->stor_elements_lock);
> +}
[Severity: High]
If zloop_reset_all_zones() fails (for example, if vfs_truncate encounters
an I/O error), this code branches to out_unlock and skips clearing the
restore_in_progress flag.
Since zlo->restore_in_progress would remain true, zloop_queue_rq() appears
to unconditionally reject all incoming block I/O with BLK_STS_IOERR
afterward. Does this leave the device permanently bricked on a reset
failure?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261007082344.1049179-1-dlemoal@kernel.org?part=4
next prev parent reply other threads:[~2026-10-07 8:35 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 [this message]
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
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-162750@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