On Mon, Sep 07, 2026 at 01:07:41PM +0200, Niklas Cassel wrote: > The write pointers of a zoned device outlive any particular use of it, > whether the device keeps them itself or a backend records them, while the > logical block size is a property of the frontend and is chosen afresh > every time the device is attached. Nothing ties the two together. A zone > written while the device was configured with logical_block_size=512 > leaves a write pointer that is a multiple of 512, and attaching the same > device with logical_block_size=4096 makes that pointer unaddressable. > > Such a pointer is not merely misaligned. The guest addresses the device > in logical blocks, and a zone report expresses the write pointer in 512 > byte sectors, so the guest is told about a position that does not fall on > a logical block boundary. It can neither read nor write there, and the > zone can only be recovered by resetting it. The reverse direction is > harmless: a pointer laid down with a larger logical block size is still a > multiple of a smaller one. > > On a zoned null_blk device with a logical block size of 512, a 512 byte > append to a sequential zone leaves the write pointer half a logical block > into it: > > $ qemu-io --image-opts -n driver=host_device,filename=/dev/nullb0 \ > -c "zap -p 0x20000000 0x200" -c "zrp 0x20000000 1" > start: 0x100000, len 0x80000, cap 0x80000, wptr 0x100001, zcond:2 > > Attaching that disk with logical_block_size=4096 handed the guest a zone > it could not write to. > > Check at realize time that the zone size and every write pointer of a > sequential zone are multiples of the write granularity that the device is > about to report, and refuse to start otherwise. The write pointers are > already held in memory by the driver, so this costs no I/O. > > The check uses blkconf_zone_write_granularity(), the same value that a > frontend reports to its guest and validates requests against, so the > three cannot disagree. > > Reviewed-by: Damien Le Moal <[email protected]> > Signed-off-by: Niklas Cassel <[email protected]> > --- > hw/block/block.c | 46 ++++++++++++++++++++++++++++++++++++++++ > hw/block/virtio-blk.c | 4 ++++ > include/hw/block/block.h | 1 + > 3 files changed, 51 insertions(+)
Reviewed-by: Stefan Hajnoczi <[email protected]>
signature.asc
Description: PGP signature
