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 v9 06/13] zloop: keep zone write pointer and condition consistent
Date: Sun, 15 Nov 2026 15:07:15 +0000	[thread overview]
Message-ID: <sashiko-outbox-215607@kernel.org> (raw)
In-Reply-To: <20261115145015.938426-7-dlemoal@kernel.org>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] zloop: static ret in zloop_set_zone_append_sector() causes
  sticky errors
- [High] zloop: redundant zloop_do_open_zone() in zloop_seq_write_prep()
  fails I/O
- [Medium] zloop: race on zone->cond between
  zloop_set_zone_append_sector() and open
--

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

zloop: keep zone write pointer and condition consistent

This commit calls zloop_do_open_zone() in zloop_set_zone_append_sector()
and changes its return type to blk_status_t so ordered zone append commands
implicitly open the target zone when the write pointer is updated.

> diff --git a/drivers/block/zloop.c b/drivers/block/zloop.c
> index 65634a39b0bfc..7aba65d43b250 100644
> --- a/drivers/block/zloop.c
> +++ b/drivers/block/zloop.c
> @@ -885,20 +885,26 @@ static void zloop_complete_rq(struct request *rq)
>  	blk_mq_end_request(rq, sts);
>  }
>  
> -static bool zloop_set_zone_append_sector(struct request *rq)
> +static blk_status_t zloop_set_zone_append_sector(struct request *rq)
>  {
>  	struct zloop_device *zlo = rq->q->queuedata;
>  	unsigned int zone_no = rq_zone_no(rq);
>  	struct zloop_zone *zone = &zlo->zones[zone_no];
>  	sector_t zone_end = zone->start + zlo->zone_capacity;
>  	sector_t nr_sectors = blk_rq_sectors(rq);
> +	static blk_status_t ret = BLK_STS_OK;

[Severity: High]
Should ret be a non-static local variable?

Because ret is declared static and is never reset to BLK_STS_OK on the
success path, once any call fails, every subsequent ordered zone append
opens the target zone, advances zone->wp, and still returns the stale error
to zloop_queue_rq(), aborting the request and leaving zone->wp out of sync
with the backing file.  Concurrent callers on different zones also race on
reading and writing ret.

A later patch in the series, commit "zloop: add storage element emulation",
refactors zloop_set_zone_append_sector() and removes this static variable,
but this commit carries a Fixes: tag and introduces the regression for
bisection and backports.

>  
>  	spin_lock(&zone->wp_lock);
>  
>  	if (zone->cond == BLK_ZONE_COND_FULL ||
>  	    zone->wp + nr_sectors > zone_end) {
> -		spin_unlock(&zone->wp_lock);
> -		return false;
> +		ret = BLK_STS_IOERR;
> +		goto unlock;
> +	}
> +
> +	if (!zloop_do_open_zone(zlo, zone, false)) {
> +		ret = BLK_STS_ZONE_OPEN_RESOURCE;
> +		goto unlock;
>  	}

[Severity: Medium]
Can calling zloop_do_open_zone() under only zone->wp_lock race with
zloop_open_zone() on the same zone?

zloop_open_zone() calls zloop_do_open_zone() while holding only zone->lock,
without taking zone->wp_lock:

drivers/block/zloop.c:zloop_open_zone() {
	...
	mutex_lock(&zone->lock);
	...
	if (!zloop_do_open_zone(zlo, zone, true))
		ret = -EIO;
	...
}

When a zone is in BLK_ZONE_COND_EMPTY or BLK_ZONE_COND_CLOSED, an ordered
zone append and an explicit zone open can enter zloop_do_open_zone()
concurrently:

CPU0                                  CPU1
zloop_queue_rq()                      zloop_open_zone()
  zloop_set_zone_append_sector()        mutex_lock(&zone->lock)
    spin_lock(&zone->wp_lock)           zloop_do_open_zone()
    zloop_do_open_zone()                  switch (zone->cond)
      switch (zone->cond)                 zloop_open_closed_or_empty_zone()
      zloop_open_closed_or_empty_zone()     spin_lock(&zlo->open_zones_lock)
                                            zlo->nr_open_zones++;
                                            list_add_tail(&zone->open_zone_entry, ...)
                                            spin_unlock(&zlo->open_zones_lock)
        spin_lock(&zlo->open_zones_lock)
        zlo->nr_open_zones++;
        list_add_tail(&zone->open_zone_entry, ...)  <-- list corruption

Both paths add zone->open_zone_entry to zlo->open_zones_lru_list and
increment zlo->nr_open_zones, corrupting the LRU list and open zone
accounting.

>  
>  	rq->__sector = zone->wp;
> @@ -906,9 +912,10 @@ static bool zloop_set_zone_append_sector(struct request *rq)
>  	if (zone->wp >= zone_end)
>  		zloop_mark_full(zlo, zone);

[Severity: High]
Does calling zloop_do_open_zone() again in zloop_seq_write_prep() fail
ordered zone appends that fill a zone?

When an ordered zone append reaches zone_end here, zloop_mark_full() sets
zone->cond to BLK_ZONE_COND_FULL before the command work item runs.  When
the work item later executes zloop_rw() -> zloop_seq_write_prep(), it
skips the capacity check and write pointer update for ordered_zone_append,
but still calls zloop_do_open_zone() unconditionally:

drivers/block/zloop.c:zloop_seq_write_prep() {
	...
	/* Implicitly open the target zone. */
	if (!zloop_do_open_zone(zlo, zone, false)) {
		ret = -EIO;
		goto out_unlock;
	}

	if (!is_append || !zlo->ordered_zone_append) {
		zone->wp += nr_sectors;
		if (zone->wp == zone_end)
			zloop_mark_full(zlo, zone);
	}
	...
}

Because zloop_do_open_zone() returns false when zone->cond is
BLK_ZONE_COND_FULL, the zone-filling append (and any earlier in-flight
ordered append to that zone whose work item runs after zloop_mark_full())
fails with -EIO and sets ZLOOP_ZONE_SEQ_ERROR.  Skipping
zloop_do_open_zone() in zloop_seq_write_prep() when is_append and
zlo->ordered_zone_append are set would avoid reopening a zone that was
already opened and possibly marked full at submission time.

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

  reply	other threads:[~2026-11-15 15:07 UTC|newest]

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