All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
To: Alexander Ivanov <alexander.ivanov@virtuozzo.com>,
	andrey.zhadchenko@virtuozzo.com
Cc: svt-core@virtuozzo.com
Subject: Re: [PATCH hci-8.2 v3] vhost-blk: implement the write-zeroes property
Date: Tue, 24 Nov 2026 17:34:17 +0200	[thread overview]
Message-ID: <7db31ef0-81d7-4128-b969-105a349b90ba@virtuozzo.com> (raw)
In-Reply-To: <20261124134005.508103-1-alexander.ivanov@virtuozzo.com>

On 11/24/26 3:40 PM, Alexander Ivanov wrote:
> vhost-blk in the kernel now handles VIRTIO_BLK_T_WRITE_ZEROES. It sends
> each request to the backend as a single WRITE ZEROES bio and answers
> VIRTIO_BLK_S_UNSUPP when the backend does not support WRITE ZEROES at
> the time of the request, so the guest falls back to writing zeroes.
> 
> With the write-zeroes property on, offer VIRTIO_BLK_F_WRITE_ZEROES and
> set max_write_zeroes_sectors to the largest range one bio can carry,
> rounded down to 64 KiB. The kernel fails a range not aligned to the
> logical block size of the backend, and a constant keeps the guest-visible
> limit the same on every host. Do not offer the feature for a read-only
> device.
> 
> Do not derive the feature or the limit from the WRITE ZEROES limit of
> the backend. It changes while QEMU has the device open, e.g. when a dm
> table is reloaded with a target that does not pass WRITE ZEROES through,
> while the guest reads the config only at probe and the destination of a
> migration or qemu-update must offer the features the guest has
> negotiated.
> 
> Fail realize if the property is on and the kernel does not offer the
> feature. Masking it silently would make the guest ABI depend on the
> host: a migration to a node with an older kernel would start the
> destination without the feature and fail only in virtio_load(), after
> RAM has been transferred.
> 
> The property stays off by default. The first kernel version with the
> support answered VIRTIO_BLK_S_IOERR for a backend without WRITE ZEROES:
> do not turn the property on with it.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-141684
> 
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
> [...]

I think this version is not good enough as well.  Here we
unconditionally advertise the WRITE_ZEROES feature bit - without any
check whether actual backend (dm-qcow2) support the operation.  We just
rely on the s->dev.features having this bit - and it's always set.

Proposal: what if we keep the sysfs check from v2 patch, but only use it
as confirmation that backend supports the op, not as the value to advertise?

Smth like:
>   if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_WRITE_ZEROES)) {
>       uint64_t bytes;
> 
>       if (!vhost_blk_get_write_zeroes_max_bytes(s->backend_rdev, &bytes, errp)) {
>           goto fail;
>       }
>       if (!bytes) {
>           error_setg(errp, "vhost-blk: '%s' does not support write zeroes",
>                      s->conf.devpath);
>           goto fail;
>       }
>   }

I.e. read value from sysfs but treat it as zero/non-zero (yes/no) value,
because IIUC if WRITE_ZEROES is unsupported by the backend (as it's now
with dm-qcow2) we'll read 0 from there.  And then in
blkcfg.max_write_zeroes_sectors we write the constant value as we do
here in v3.

There's of course still the issue of value dropping to 0 in runtime.  If
this ever happens, qemu-update will be broken.  So we have to guarantee
somehow our backend doesn't change this value on the fly.

What do you think?
Andrey


      reply	other threads:[~2026-11-24 15:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 13:40 Alexander Ivanov
2026-11-24 15:34 ` Andrey Drobyshev [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7db31ef0-81d7-4128-b969-105a349b90ba@virtuozzo.com \
    --to=andrey.drobyshev@virtuozzo.com \
    --cc=alexander.ivanov@virtuozzo.com \
    --cc=andrey.zhadchenko@virtuozzo.com \
    --cc=svt-core@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.