I won't apply this version, please send v2 with the changes below.

On Mon, 02 Nov 2026 12:30:51 +0100, Alexander Ivanov 
<[email protected]> wrote:
> QEMU virtio-blk advertises WRITE_ZEROES, so a guest switched to
> vhost-blk may issue such requests and gets VIRTIO_BLK_S_UNSUPP.

- Reword this paragraph: no guest of our vhost-blk device can get
  WRITE_ZEROES today, and a QEMU change has to follow this patch.
- Say in the message what the VMM must advertise: the backend logical
  block size, max_write_zeroes_sectors aligned to it, and
  max_write_zeroes_seg = 1. Drop "as QEMU does" for the alignment
  check.
- Use a much smaller chunk when the range is written with zero pages.
- Make the commit message much shorter: what the patch does, what the
  VMM must advertise and the errors the guest gets, in a few lines.
  Move the rest to the cover text: the comparisons with QEMU, the
  BLKROSET race, why a submit error would hang the guest, the wait in
  vhost_blk_flush(), the WRITE SAME retry. For a single patch b4 puts
  the cover text below the "---" line, so it stays in the mail and
  the list archive but not in git.

The scenario cannot happen with our QEMU. The "write-zeroes" property
of vhost-blk is off by default ("not yet implemented in kernel
module"). Even when it is on, vhost_get_features() clears the bit,
because the kernel did not report it. A guest moved from virtio-blk
to vhost-blk renegotiates features on the new device. The real reason
is parity with virtio-blk.

> part of the chain, where the virtio spec places it.
>
> Complete a range not aligned to the logical block size and a request
> to a read-only backend with VIRTIO_BLK_S_IOERR, as QEMU does. The

bs_mask comes from the backend, but our QEMU always tells the guest
blk_size 512 and leaves max_write_zeroes_sectors at 0. A Linux guest
reads 0 as no limit and splits a large zeroout at 8388607 sectors. On a
4Kn backend, e.g. dm-qcow2 on a 4K disk, such a request is not aligned
and gets IOERR. The guest does not fall back to zero pages, so
blkdiscard -z or BLKZEROOUT of 4 GiB or more fails with -EIO, where
before the patch the guest wrote the zeroes itself. QEMU checks
alignment against the block size it advertised, so it never hits this.

> +#define VHOST_BLK_MAX_WRITE_ZEROES_SECTORS   (SZ_1G >> SECTOR_SHIFT)

dm-ploop, dm-qcow2 and most SATA disks have no WRITE ZEROES, so on them
every chunk goes through the zero-page fallback: about a thousand 1 MiB
bios, all submitted from the vhost worker with vq->mutex held. On a disk
with a shallow queue submit_bio() sleeps on tags until most of that GiB
is written, and with the default single worker the completions of all
queues of the device wait behind it. A Linux guest never sends a data
request that large, and a guest zeroing on its own sends 1 MiB requests
that do not block the worker. 1 GiB is fine for real WRITE ZEROES bios;
for the zero-page case a chunk of a few MiB keeps the worker responsive.

-- 
Konstantin Khorenko,
Virtuozzo Linux Kernel Team

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to