mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ming Lei <tom.leiming@gmail.com>
To: shao.mingyin@zte.com.cn
Cc: linux-block@vger.kernel.org, axboe@kernel.dk,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] ublk: stop reporting zones on an empty response
Date: Mon, 9 Nov 2026 19:27:52 -0600	[thread overview]
Message-ID: <avJzGIqp5ZUehCGx@fedora-laptop> (raw)
In-Reply-To: <20261109225110056QQJAEflTHzwYHzwXlMBb_@zte.com.cn>

On Mon, Nov 09, 2026 at 10:51:10PM +0800, shao.mingyin@zte.com.cn wrote:
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
> 
> ublk_report_zones() treats a zero-length zone as the end of a server
> response, but only breaks out of the inner loop.  If the server returns
> an empty report, done_zones and sector do not advance, so the driver
> keeps issuing REPORT ZONES requests at the same sector indefinitely.
> 
> Finish the report when the zero-length marker is encountered and return
> the number of zones already reported.  Use the existing exit path to
> release the report buffer, including when the first response is empty.

The issue is real, I can reproduce it with one ublk server which
completes UBLK_IO_OP_REPORT_ZONES without filling any zone: both
BLKREPORTZONE and START_DEV(blk_revalidate_disk_zones()) loop forever,
and the task can't be killed.

> 
> Fixes: 29802d7ca33b ("ublk: enable zoned storage support")
> Cc: stable@vger.kernel.org
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
> ---
>  drivers/block/ublk_drv.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 3d322fa1bc83..5c14daeaebbf 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -693,8 +693,10 @@ static int ublk_report_zones(struct gendisk *disk, sector_t sector,
>  			struct blk_zone *zone = buffer + i;
>  
>  			/* A zero length zone means no more zones in this response */
> -			if (!zone->len)
> -				break;
> +			if (!zone->len) {
> +				ret = done_zones;
> +				goto out;
> +			}

But this terminates the whole report on any zero-length zone, not only
on an empty response.

A zero-length zone means "no more zones in this response", and so far
the driver continues from the advanced sector and asks for the remaining
zones. With this patch, a server returning fewer zones than requested
gets a truncated report. For example, when the server fills half of
the requested zones each time:

- BLKREPORTZONE for 256 zones returns 128 zones

- START_DEV fails:

	ublkb0: last zone and capacity mismatch (1048576 != 2097152)
	ublkb0: failed to revalidate zones

Both work fine before this patch.

How about stopping only if the response doesn't carry any zone? That is
what sd_zbc and virtio_blk do too. Something like:

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -661,6 +661,7 @@ static int ublk_report_zones(struct gendisk *disk, sector_t sector,
 		struct request *req;
 		struct ublk_zoned_report_desc desc;
 		blk_status_t status;
+		unsigned int i;
 
 		memset(buffer, 0, buffer_length);
 
@@ -689,7 +690,7 @@ static int ublk_report_zones(struct gendisk *disk, sector_t sector,
 		if (ret)
 			goto out;
 
-		for (unsigned int i = 0; i < zones_in_request; i++) {
+		for (i = 0; i < zones_in_request; i++) {
 			struct blk_zone *zone = buffer + i;
 
 			/* A zero length zone means no more zones in this response */
@@ -704,6 +705,10 @@ static int ublk_report_zones(struct gendisk *disk, sector_t sector,
 			sector += zone_size_sectors;
 
 		}
+
+		/* empty response: no progress, don't ask again */
+		if (!i)
+			break;
 	}
 
 	ret = done_zones;

With the above, empty response is handled as in your patch
(BLKREPORTZONE returns 0 zones, START_DEV fails with "No zones
reported"), and partial response still works.


Thanks,
Ming

      reply	other threads:[~2026-11-10  1:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 14:51 shao.mingyin
2026-11-10  1:27 ` Ming Lei [this message]

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=avJzGIqp5ZUehCGx@fedora-laptop \
    --to=tom.leiming@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shao.mingyin@zte.com.cn \
    /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

all inboxes | Powered by JetHome®