* [PATCH] virtio_blk: set the zone write granularity
@ 2026-09-18 14:06 Niklas Cassel
2026-09-22 19:24 ` Stefan Hajnoczi
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Niklas Cassel @ 2026-09-18 14:06 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
Paolo Bonzini, Stefan Hajnoczi, Jens Axboe, Dmitry Fomichev
Cc: Damien Le Moal, Niklas Cassel, virtualization, linux-block
virtblk_read_zoned_limits() reads the write granularity that the device
reports in virtio_blk_zoned_characteristics and assigns it to the
physical block size and to io_min, but never to the limit that is named
after it. queue_limits.zone_write_granularity is left at zero, so
blk_validate_zoned_limits() raises it to the logical block size:
if (lim->zone_write_granularity < lim->logical_block_size)
lim->zone_write_granularity = lim->logical_block_size;
A device that reports a granularity coarser than its logical block size,
which is what the field exists to express, therefore has it silently
reduced. A 512e host managed disk passed through to a guest reports a
logical block size of 512 and a write granularity of 4096, and the guest
ends up with a zone write granularity of 512.
bio_split_alignment() returns lim->zone_write_granularity if it is non-zero
and bio_split_io_at() may split a bio with as per bio_split_alignment().
This can real to the write getting rejected by the host drive, as the write
is not aligned to the physical block size.
zonefs also takes its block size from bdev_zone_write_granularity(), so it
would incorrectly use 512 on a disk that requires 4096.
sd_zbc_read_zones() sets the limit from the physical block size for the
same reason. NVMe ZNS and null_blk leave it unset, but the fallback
gives the right answer for them, as their write granularity is the
logical block size. virtio carries a separate value that may exceed it.
Set the zone write granularity from the value that the device reports.
Fixes: 95bfec41bd3d ("virtio-blk: add support for zoned block devices")
Signed-off-by: Niklas Cassel <cassel@kernel.org>
---
drivers/block/virtio_blk.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 32bf3ba07a9d..c8bfbf8435ac 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -743,6 +743,7 @@ static int virtblk_read_zoned_limits(struct virtio_blk *vblk,
dev_warn(&vdev->dev, "zero write granularity reported\n");
return -ENODEV;
}
+ lim->zone_write_granularity = wg;
lim->physical_block_size = wg;
lim->io_min = wg;
base-commit: 5dd1818b15d98d4a20806cd00b1b40320b06004f
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] virtio_blk: set the zone write granularity
2026-09-18 14:06 [PATCH] virtio_blk: set the zone write granularity Niklas Cassel
@ 2026-09-22 19:24 ` Stefan Hajnoczi
2026-09-29 11:50 ` Niklas Cassel
2026-09-29 18:55 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2026-09-22 19:24 UTC (permalink / raw)
To: Niklas Cassel
Cc: Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
Paolo Bonzini, Jens Axboe, Dmitry Fomichev, Damien Le Moal,
virtualization, linux-block
[-- Attachment #1: Type: text/plain, Size: 1959 bytes --]
On Fri, Sep 18, 2026 at 04:06:42PM +0200, Niklas Cassel wrote:
> virtblk_read_zoned_limits() reads the write granularity that the device
> reports in virtio_blk_zoned_characteristics and assigns it to the
> physical block size and to io_min, but never to the limit that is named
> after it. queue_limits.zone_write_granularity is left at zero, so
> blk_validate_zoned_limits() raises it to the logical block size:
>
> if (lim->zone_write_granularity < lim->logical_block_size)
> lim->zone_write_granularity = lim->logical_block_size;
>
> A device that reports a granularity coarser than its logical block size,
> which is what the field exists to express, therefore has it silently
> reduced. A 512e host managed disk passed through to a guest reports a
> logical block size of 512 and a write granularity of 4096, and the guest
> ends up with a zone write granularity of 512.
>
> bio_split_alignment() returns lim->zone_write_granularity if it is non-zero
> and bio_split_io_at() may split a bio with as per bio_split_alignment().
> This can real to the write getting rejected by the host drive, as the write
> is not aligned to the physical block size.
>
> zonefs also takes its block size from bdev_zone_write_granularity(), so it
> would incorrectly use 512 on a disk that requires 4096.
>
> sd_zbc_read_zones() sets the limit from the physical block size for the
> same reason. NVMe ZNS and null_blk leave it unset, but the fallback
> gives the right answer for them, as their write granularity is the
> logical block size. virtio carries a separate value that may exceed it.
>
> Set the zone write granularity from the value that the device reports.
>
> Fixes: 95bfec41bd3d ("virtio-blk: add support for zoned block devices")
> Signed-off-by: Niklas Cassel <cassel@kernel.org>
> ---
> drivers/block/virtio_blk.c | 1 +
> 1 file changed, 1 insertion(+)
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] virtio_blk: set the zone write granularity
2026-09-18 14:06 [PATCH] virtio_blk: set the zone write granularity Niklas Cassel
2026-09-22 19:24 ` Stefan Hajnoczi
@ 2026-09-29 11:50 ` Niklas Cassel
2026-09-29 18:55 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Niklas Cassel @ 2026-09-29 11:50 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
Paolo Bonzini, Stefan Hajnoczi, Jens Axboe, Dmitry Fomichev
Cc: Damien Le Moal, virtualization, linux-block
On Fri, Sep 18, 2026 at 04:06:42PM +0200, Niklas Cassel wrote:
> virtblk_read_zoned_limits() reads the write granularity that the device
> reports in virtio_blk_zoned_characteristics and assigns it to the
> physical block size and to io_min, but never to the limit that is named
> after it. queue_limits.zone_write_granularity is left at zero, so
> blk_validate_zoned_limits() raises it to the logical block size:
>
> if (lim->zone_write_granularity < lim->logical_block_size)
> lim->zone_write_granularity = lim->logical_block_size;
>
> A device that reports a granularity coarser than its logical block size,
> which is what the field exists to express, therefore has it silently
> reduced. A 512e host managed disk passed through to a guest reports a
> logical block size of 512 and a write granularity of 4096, and the guest
> ends up with a zone write granularity of 512.
>
> bio_split_alignment() returns lim->zone_write_granularity if it is non-zero
> and bio_split_io_at() may split a bio with as per bio_split_alignment().
> This can real to the write getting rejected by the host drive, as the write
> is not aligned to the physical block size.
>
> zonefs also takes its block size from bdev_zone_write_granularity(), so it
> would incorrectly use 512 on a disk that requires 4096.
>
> sd_zbc_read_zones() sets the limit from the physical block size for the
> same reason. NVMe ZNS and null_blk leave it unset, but the fallback
> gives the right answer for them, as their write granularity is the
> logical block size. virtio carries a separate value that may exceed it.
>
> Set the zone write granularity from the value that the device reports.
>
> Fixes: 95bfec41bd3d ("virtio-blk: add support for zoned block devices")
> Signed-off-by: Niklas Cassel <cassel@kernel.org>
> ---
> drivers/block/virtio_blk.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
> index 32bf3ba07a9d..c8bfbf8435ac 100644
> --- a/drivers/block/virtio_blk.c
> +++ b/drivers/block/virtio_blk.c
> @@ -743,6 +743,7 @@ static int virtblk_read_zoned_limits(struct virtio_blk *vblk,
> dev_warn(&vdev->dev, "zero write granularity reported\n");
> return -ENODEV;
> }
> + lim->zone_write_granularity = wg;
> lim->physical_block_size = wg;
> lim->io_min = wg;
>
>
> base-commit: 5dd1818b15d98d4a20806cd00b1b40320b06004f
> --
> 2.55.0
>
Gentle ping
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] virtio_blk: set the zone write granularity
2026-09-18 14:06 [PATCH] virtio_blk: set the zone write granularity Niklas Cassel
2026-09-22 19:24 ` Stefan Hajnoczi
2026-09-29 11:50 ` Niklas Cassel
@ 2026-09-29 18:55 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2026-09-29 18:55 UTC (permalink / raw)
To: Michael S. Tsirkin, Jason Wang, Eugenio Pérez, Xuan Zhuo,
Paolo Bonzini, Stefan Hajnoczi, Dmitry Fomichev, Niklas Cassel
Cc: Damien Le Moal, virtualization, linux-block
On Fri, 18 Sep 2026 16:06:42 +0200, Niklas Cassel wrote:
> virtblk_read_zoned_limits() reads the write granularity that the device
> reports in virtio_blk_zoned_characteristics and assigns it to the
> physical block size and to io_min, but never to the limit that is named
> after it. queue_limits.zone_write_granularity is left at zero, so
> blk_validate_zoned_limits() raises it to the logical block size:
>
> if (lim->zone_write_granularity < lim->logical_block_size)
> lim->zone_write_granularity = lim->logical_block_size;
>
> [...]
Applied, thanks!
[1/1] virtio_blk: set the zone write granularity
commit: 684b413b5483f57c890c171b9400076a0143b918
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-29 18:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-18 14:06 [PATCH] virtio_blk: set the zone write granularity Niklas Cassel
2026-09-22 19:24 ` Stefan Hajnoczi
2026-09-29 11:50 ` Niklas Cassel
2026-09-29 18:55 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox