On Mon, Sep 07, 2026 at 01:07:35PM +0200, Niklas Cassel wrote:
> Hello Stefan, Kevin, and everyone else,
> 
> This series fixes how QEMU reports and enforces the two constraints a zoned
> device places on a write to a sequential zone: the write granularity, and
> the largest zone append it accepts. It also fixes two bugs in the zone
> append emulation in file-posix, one of which a guest can reach.
> 
> Many of these patches are in preparation for Sam Li's zoned qcow2 series.
> The first two patches in the series are taken directly from there, as they
> are unrelated to qcow2.
> 
> Patch 3 is preparation with no functional change: deriving the zone that an
> offset belongs to was open coded in five places, so it becomes a helper.
> 
> Patches 4 to 6 concern the write granularity. virtio-blk reported the
> logical block size while the driver enforced the backend value, so on a
> 512e SMR disk a guest could be told that a request was valid and get an
> I/O error for it. Writes to sequential zones were not checked against the
> granularity at all, and zone appends had only their offset checked, not
> their length. Patch 6 then refuses at realize a device whose write
> pointers the configured logical block size cannot address, which needs no
> emulated backend to provoke: write 512 bytes to a zone of a null_blk
> device and attach it with logical_block_size=4096.
> 
> Patches 7 to 10 concern the append limit. The sector invariant moves to
> bdrv_co_zone_append(), since a write pointer is tracked in sectors and
> cannot represent anything finer, and file-posix drops its own check which
> conflated that with the coarser granularity of the medium. file-posix then
> stops reporting zone_append_max_bytes, which bounds REQ_OP_ZONE_APPEND, an
> operation it never issues: it appends with an ordinary pwritev(), so
> max_hw_transfer is the limit that applies. Finally virtio-blk derives what
> it advertises rather than passing BlockLimits.max_append_sectors through,
> which made an unset field mean "zone append unsupported" rather than "no
> limit of its own", and Linux refuses to attach a zoned device that reports
> zero.
> 
> Patches 11 and 12 fix the write pointer that raw_co_prw() substitutes for
> the offset of an append. An offset that is never bounded against the
> device derives an out of range zone index and reads past the write pointer
> array, which qemu-io can reach. An append to a full zone uses a pointer
> recorded at the end of the zone, so the data is written into the next zone
> and success is returned; a guest can reach that one, because nothing in
> virtio-blk checks whether a zone is full.
> 
> 
> Changes since v3:
> -Picked up tags from Damien.
> -Replaced ctz64() with a zone_size_bits in struct BlockLimits.

Hi Niklas,
Thank you for your patience. QEMU block layer code reviews are slow at
the moment and it took me a while to get to your series.

Overall it looks good. The only concern I have is exposing BlockBackend
BlockLimits fields directly in the emulated device. This breaks live
migration because guest drivers are not prepared for limits to change
suddenly at runtime. More about this in my replies.

Thanks,
Stefan

> 
> 
> Niklas Cassel (10):
>   block: add a helper for the index of the zone an offset falls in
>   virtio-blk: report the effective zone write granularity
>   virtio-blk: check the write granularity of writes to sequential zones
>   hw/block: reject a zoned device whose write pointers are unaddressable
>   block: reject zone appends that are not a multiple of the sector size
>   file-posix: remove the zone append write granularity check
>   file-posix: base the zone append limit on the transfer limit
>   virtio-blk: derive the maximum zone append size
>   file-posix: reject a zone append past the device capacity
>   file-posix: reject a zone append to a full or conventional zone
> 
> Sam Li (2):
>   block: widen BlockLimits.zone_size to uint64_t
>   virtio-blk: do not merge requests across a zone boundary
> 
>  block/block-backend.c             |  11 +++
>  block/file-posix.c                |  71 +++++++++++++-------
>  block/io.c                        |  31 +++++++++
>  hw/block/block.c                  |  53 +++++++++++++++
>  hw/block/virtio-blk.c             | 108 +++++++++++++++++++++++++-----
>  include/block/block-io.h          |   8 +++
>  include/block/block_int-common.h  |   9 ++-
>  include/hw/block/block.h          |   9 +++
>  include/system/block-backend-io.h |   1 +
>  9 files changed, 260 insertions(+), 41 deletions(-)
> 
> -- 
> 2.55.0
> 

Attachment: signature.asc
Description: PGP signature

Reply via email to