mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] virtio-blk: Fix zone append sector reporting in batched completion
@ 2026-10-26 11:55 shao.mingyin
  2026-10-27 15:06 ` Christoph Hellwig
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: shao.mingyin @ 2026-10-26 11:55 UTC (permalink / raw)
  To: mst, jasowangio, virtualization
  Cc: pbonzini, stefanha, eperezma, hch, dlemoal, linux-block, linux-kernel

From: Shao Mingyin <shao.mingyin@zte.com.cn>

For zone append, the block layer copies req->__sector back into the
bio in blk_zone_append_update_request_bio(), so the driver must update
req->__sector with the sector reported by the device.
virtblk_request_done() does that, but the batched completion path used
by virtblk_poll() only unmaps and cleans up the requests before calling
blk_mq_end_request_batch().

A zone append completed through polling therefore keeps the sector that
was assigned at submission time, and the file system or application sees
the wrong LBA for the written data.

Move the sector update into a helper and call it from both completion
paths.

Fixes: 95bfec41bd3d ("virtio-blk: add support for zoned block devices")
Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>
---
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index c8bfbf8435ac..cc29b8238a4d 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -331,18 +331,25 @@ static inline u8 virtblk_vbr_status(struct virtblk_req *vbr)
 	return *((u8 *)&vbr->in_hdr + vbr->in_hdr_len - 1);
 }

+static inline void virtblk_update_zone_append_sector(struct request *req,
+						     struct virtblk_req *vbr)
+{
+	struct virtio_blk *vblk = req->mq_hctx->queue->queuedata;
+
+	if (req_op(req) == REQ_OP_ZONE_APPEND)
+		req->__sector = virtio64_to_cpu(vblk->vdev,
+						vbr->in_hdr.zone_append.sector);
+}
+
 static inline void virtblk_request_done(struct request *req)
 {
 	struct virtblk_req *vbr = blk_mq_rq_to_pdu(req);
 	blk_status_t status = virtblk_result(virtblk_vbr_status(vbr));
-	struct virtio_blk *vblk = req->mq_hctx->queue->queuedata;

 	virtblk_unmap_data(req, vbr);
 	virtblk_cleanup_cmd(req);

-	if (req_op(req) == REQ_OP_ZONE_APPEND)
-		req->__sector = virtio64_to_cpu(vblk->vdev,
-						vbr->in_hdr.zone_append.sector);
+	virtblk_update_zone_append_sector(req, vbr);

 	blk_mq_end_request(req, status);
 }
@@ -1196,8 +1203,11 @@ static void virtblk_complete_batch(struct io_comp_batch *iob)
 	struct request *req;

 	rq_list_for_each(&iob->req_list, req) {
-		virtblk_unmap_data(req, blk_mq_rq_to_pdu(req));
+		struct virtblk_req *vbr = blk_mq_rq_to_pdu(req);
+
+		virtblk_unmap_data(req, vbr);
 		virtblk_cleanup_cmd(req);
+		virtblk_update_zone_append_sector(req, vbr);
 	}
 	blk_mq_end_request_batch(iob);
 }

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] virtio-blk: Fix zone append sector reporting in batched completion
  2026-10-26 11:55 [PATCH] virtio-blk: Fix zone append sector reporting in batched completion shao.mingyin
@ 2026-10-27 15:06 ` Christoph Hellwig
       [not found]   ` <2026102810270846959TfFOThssBqrSo1PlP9X@zte.com.cn>
  2026-10-27 19:17 ` Stefan Hajnoczi
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2026-10-27 15:06 UTC (permalink / raw)
  To: shao.mingyin
  Cc: mst, jasowangio, virtualization, pbonzini, stefanha, eperezma,
	hch, dlemoal, linux-block, linux-kernel

On Mon, Oct 26, 2026 at 07:55:19PM +0800, shao.mingyin@zte.com.cn wrote:
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
> 
> For zone append, the block layer copies req->__sector back into the
> bio in blk_zone_append_update_request_bio(), so the driver must update
> req->__sector with the sector reported by the device.
> virtblk_request_done() does that, but the batched completion path used
> by virtblk_poll() only unmaps and cleans up the requests before calling
> blk_mq_end_request_batch().
> 
> A zone append completed through polling therefore keeps the sector that
> was assigned at submission time, and the file system or application sees
> the wrong LBA for the written data.
> 
> Move the sector update into a helper and call it from both completion
> paths.

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>

Can you add something to blktests to exercises this?


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] virtio-blk: Fix zone append sector reporting in batched completion
  2026-10-26 11:55 [PATCH] virtio-blk: Fix zone append sector reporting in batched completion shao.mingyin
  2026-10-27 15:06 ` Christoph Hellwig
@ 2026-10-27 19:17 ` Stefan Hajnoczi
  2026-10-27 19:19 ` Michael S. Tsirkin
  2026-11-03 14:31 ` Jens Axboe
  3 siblings, 0 replies; 7+ messages in thread
From: Stefan Hajnoczi @ 2026-10-27 19:17 UTC (permalink / raw)
  To: shao.mingyin
  Cc: mst, jasowangio, virtualization, pbonzini, eperezma, hch,
	dlemoal, linux-block, linux-kernel

On Mon, Oct 26, 2026 at 07:55:19PM +0800, shao.mingyin@zte.com.cn wrote:
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
> 
> For zone append, the block layer copies req->__sector back into the
> bio in blk_zone_append_update_request_bio(), so the driver must update
> req->__sector with the sector reported by the device.
> virtblk_request_done() does that, but the batched completion path used
> by virtblk_poll() only unmaps and cleans up the requests before calling
> blk_mq_end_request_batch().
> 
> A zone append completed through polling therefore keeps the sector that
> was assigned at submission time, and the file system or application sees
> the wrong LBA for the written data.
> 
> Move the sector update into a helper and call it from both completion
> paths.
> 
> Fixes: 95bfec41bd3d ("virtio-blk: add support for zoned block devices")
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>

Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] virtio-blk: Fix zone append sector reporting in batched completion
  2026-10-26 11:55 [PATCH] virtio-blk: Fix zone append sector reporting in batched completion shao.mingyin
  2026-10-27 15:06 ` Christoph Hellwig
  2026-10-27 19:17 ` Stefan Hajnoczi
@ 2026-10-27 19:19 ` Michael S. Tsirkin
  2026-11-03 14:31 ` Jens Axboe
  3 siblings, 0 replies; 7+ messages in thread
From: Michael S. Tsirkin @ 2026-10-27 19:19 UTC (permalink / raw)
  To: shao.mingyin
  Cc: jasowangio, virtualization, pbonzini, stefanha, eperezma, hch,
	dlemoal, linux-block, linux-kernel

On Mon, Oct 26, 2026 at 07:55:19PM +0800, shao.mingyin@zte.com.cn wrote:
> From: Shao Mingyin <shao.mingyin@zte.com.cn>
> 
> For zone append, the block layer copies req->__sector back into the
> bio in blk_zone_append_update_request_bio(), so the driver must update
> req->__sector with the sector reported by the device.
> virtblk_request_done() does that, but the batched completion path used
> by virtblk_poll() only unmaps and cleans up the requests before calling
> blk_mq_end_request_batch().
> 
> A zone append completed through polling therefore keeps the sector that
> was assigned at submission time, and the file system or application sees
> the wrong LBA for the written data.
> 
> Move the sector update into a helper and call it from both completion
> paths.
> 
> Fixes: 95bfec41bd3d ("virtio-blk: add support for zoned block devices")
> Signed-off-by: Shao Mingyin <shao.mingyin@zte.com.cn>

Acked-by: Michael S. Tsirkin <mst@redhat.com>

> ---
> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index c8bfbf8435ac..cc29b8238a4d 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -331,18 +331,25 @@ static inline u8 virtblk_vbr_status(struct virtblk_req *vbr)
>  	return *((u8 *)&vbr->in_hdr + vbr->in_hdr_len - 1);
>  }
> 
> +static inline void virtblk_update_zone_append_sector(struct request *req,
> +						     struct virtblk_req *vbr)
> +{
> +	struct virtio_blk *vblk = req->mq_hctx->queue->queuedata;
> +
> +	if (req_op(req) == REQ_OP_ZONE_APPEND)
> +		req->__sector = virtio64_to_cpu(vblk->vdev,
> +						vbr->in_hdr.zone_append.sector);
> +}
> +
>  static inline void virtblk_request_done(struct request *req)
>  {
>  	struct virtblk_req *vbr = blk_mq_rq_to_pdu(req);
>  	blk_status_t status = virtblk_result(virtblk_vbr_status(vbr));
> -	struct virtio_blk *vblk = req->mq_hctx->queue->queuedata;
> 
>  	virtblk_unmap_data(req, vbr);
>  	virtblk_cleanup_cmd(req);
> 
> -	if (req_op(req) == REQ_OP_ZONE_APPEND)
> -		req->__sector = virtio64_to_cpu(vblk->vdev,
> -						vbr->in_hdr.zone_append.sector);
> +	virtblk_update_zone_append_sector(req, vbr);
> 
>  	blk_mq_end_request(req, status);
>  }
> @@ -1196,8 +1203,11 @@ static void virtblk_complete_batch(struct io_comp_batch *iob)
>  	struct request *req;
> 
>  	rq_list_for_each(&iob->req_list, req) {
> -		virtblk_unmap_data(req, blk_mq_rq_to_pdu(req));
> +		struct virtblk_req *vbr = blk_mq_rq_to_pdu(req);
> +
> +		virtblk_unmap_data(req, vbr);
>  		virtblk_cleanup_cmd(req);
> +		virtblk_update_zone_append_sector(req, vbr);
>  	}
>  	blk_mq_end_request_batch(iob);
>  }


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] virtio-blk: Fix zone append sector reporting in batched completion
       [not found]   ` <2026102810270846959TfFOThssBqrSo1PlP9X@zte.com.cn>
@ 2026-11-03  8:02     ` Christoph Hellwig
  2026-11-03  8:02       ` Christoph Hellwig
  0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2026-11-03  8:02 UTC (permalink / raw)
  To: shao.mingyin
  Cc: hch, mst, jasowangio, virtualization, pbonzini, stefanha,
	eperezma, dlemoal, linux-block, linux-kernel

On Wed, Oct 28, 2026 at 10:27:08AM +0800, shao.mingyin@zte.com.cn wrote:
> I looked into adding blktests coverage, and there is a structural
> problem. blktests cannot issue REQ_OP_ZONE_APPEND from userspace: fio's
> --zone_append goes through the io_uring_cmd NVMe passthrough path, so it
> never reaches the driver's zone-append completion, and zbdioctl has no
> append operation. blktests has no zone-append test today for the same
> reason.

Right.

> That does not fit blktests, which is a block-layer test suite driven
> from userspace. Two options as I see it:
> 
>   1. an XFS reproducer (e.g. xfstests) - the one that actually
>      exercises the append completion path, or
>   2. a blktests zbd test that covers a zoned virtio-blk with poll
>      queues, which would not reach the append part itself.
> 
> I am happy to write either, or to leave it if you think the coverage
> is not worth the churn. Which do you prefer?

We do have some blktests test that use a file system in the zbd
category (zbd/009, zbd/010, zbd/014) so I think we could do this in
blktests.  I.e. do a blktest that tests zoned polled I/O if we're
on a zoned device that support polling.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] virtio-blk: Fix zone append sector reporting in batched completion
  2026-11-03  8:02     ` Christoph Hellwig
@ 2026-11-03  8:02       ` Christoph Hellwig
  0 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2026-11-03  8:02 UTC (permalink / raw)
  To: shao.mingyin
  Cc: hch, mst, jasowangio, virtualization, pbonzini, stefanha,
	eperezma, dlemoal, linux-block, linux-kernel

On Tue, Nov 03, 2026 at 09:02:23AM +0100, Christoph Hellwig wrote:
> On Wed, Oct 28, 2026 at 10:27:08AM +0800, shao.mingyin@zte.com.cn wrote:
> > I looked into adding blktests coverage, and there is a structural
> > problem. blktests cannot issue REQ_OP_ZONE_APPEND from userspace: fio's
> > --zone_append goes through the io_uring_cmd NVMe passthrough path, so it
> > never reaches the driver's zone-append completion, and zbdioctl has no
> > append operation. blktests has no zone-append test today for the same
> > reason.
> 
> Right.
> 
> > That does not fit blktests, which is a block-layer test suite driven
> > from userspace. Two options as I see it:
> > 
> >   1. an XFS reproducer (e.g. xfstests) - the one that actually
> >      exercises the append completion path, or
> >   2. a blktests zbd test that covers a zoned virtio-blk with poll
> >      queues, which would not reach the append part itself.
> > 
> > I am happy to write either, or to leave it if you think the coverage
> > is not worth the churn. Which do you prefer?
> 
> We do have some blktests test that use a file system in the zbd
> category (zbd/009, zbd/010, zbd/014) so I think we could do this in
> blktests.  I.e. do a blktest that tests zoned polled I/O if we're
> on a zoned device that support polling.

OTOH xfstests might actually still fit better for this.  I guess
eiter way will work..

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] virtio-blk: Fix zone append sector reporting in batched completion
  2026-10-26 11:55 [PATCH] virtio-blk: Fix zone append sector reporting in batched completion shao.mingyin
                   ` (2 preceding siblings ...)
  2026-10-27 19:19 ` Michael S. Tsirkin
@ 2026-11-03 14:31 ` Jens Axboe
  3 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2026-11-03 14:31 UTC (permalink / raw)
  To: mst, jasowangio, virtualization, shao.mingyin
  Cc: pbonzini, stefanha, eperezma, hch, dlemoal, linux-block, linux-kernel


On Mon, 26 Oct 2026 19:55:19 +0800, shao.mingyin@zte.com.cn wrote:
> For zone append, the block layer copies req->__sector back into the
> bio in blk_zone_append_update_request_bio(), so the driver must update
> req->__sector with the sector reported by the device.
> virtblk_request_done() does that, but the batched completion path used
> by virtblk_poll() only unmaps and cleans up the requests before calling
> blk_mq_end_request_batch().
> 
> [...]

Applied, thanks!

[1/1] virtio-blk: Fix zone append sector reporting in batched completion
      commit: 08a6572441a4e646c96c2b8d8ead9eea0e458332

Best regards,
-- 
Jens Axboe




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-03 14:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-26 11:55 [PATCH] virtio-blk: Fix zone append sector reporting in batched completion shao.mingyin
2026-10-27 15:06 ` Christoph Hellwig
     [not found]   ` <2026102810270846959TfFOThssBqrSo1PlP9X@zte.com.cn>
2026-11-03  8:02     ` Christoph Hellwig
2026-11-03  8:02       ` Christoph Hellwig
2026-10-27 19:17 ` Stefan Hajnoczi
2026-10-27 19:19 ` Michael S. Tsirkin
2026-11-03 14:31 ` Jens Axboe

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®