virtio_blk: set the zone write granularity
Subsystems (3)
PATCH 1/1 virtio_blk: set the zone write granularity
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.
--- drivers/block/virtio_blk.c | 1 + 1 file changed, 1 insertion(+)
drivers/block/virtio_blk.c +1 -0
@@ -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
Signature · 1 line
2.55.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines
virtblk_read_zoned_limits()reads the write granularity that the device reports invirtio_blk_zoned_characteristicsand assigns it to the physical block size and toio_min, but never to the limit that is named after it. queue_limits.zone_write_granularity is left at zero, soblk_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.
Quoted 6 lines
[ ... ]
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 <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 28 lines · Niklas Cassel
virtblk_read_zoned_limits()reads the write granularity that the device reports invirtio_blk_zoned_characteristicsand assigns it to the physical block size and toio_min, but never to the limit that is named after it. queue_limits.zone_write_granularity is left at zero, soblk_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()returnslim->zone_write_granularityif it is non-zero andbio_split_io_at()may split a bio with as perbio_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 andnull_blkleave 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.
Quoted 7 lines
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 <[email protected]>--- drivers/block/virtio_blk.c | 1 + 1 file changed, 1 insertion(+)
Quoted 49 lines · Niklas Cassel
virtblk_read_zoned_limits()reads the write granularity that the device reports invirtio_blk_zoned_characteristicsand assigns it to the physical block size and toio_min, but never to the limit that is named after it. queue_limits.zone_write_granularity is left at zero, soblk_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()returnslim->zone_write_granularityif it is non-zero andbio_split_io_at()may split a bio with as perbio_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 andnull_blkleave 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 <[email protected]>--- drivers/block/virtio_blk.c | 1 + 1 file changed, 1 insertion(+)drivers/block/virtio_blk.c +1
-0@@ -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;
Quoted 4 lines
base-commit:
5dd1818b15d98d4a20806cd00b1b40320b06004fSignature · 1 line
2.55.0
Gentle ping
Quoted 10 lines · Niklas Cassel
virtblk_read_zoned_limits()reads the write granularity that the device reports invirtio_blk_zoned_characteristicsand assigns it to the physical block size and toio_min, but never to the limit that is named after it. queue_limits.zone_write_granularity is left at zero, soblk_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,
Signature · 1 line
Jens Axboe