All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>
To: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
Cc: andrey.drobyshev@virtuozzo.com, svt-core@virtuozzo.com
Subject: Re: [PATCH hci-8.2] vhost-blk: advertise discard limits in the config space
Date: Mon, 23 Nov 2026 14:20:21 +0100	[thread overview]
Message-ID: <85321d14-bf6d-431f-838e-e50e43713fb9@virtuozzo.com> (raw)
In-Reply-To: <20261123084134.177261-1-alexander.ivanov@virtuozzo.com>

LGTM

Reviewed-by: Andrey Zhadchenko <andrey.zhadchenko@virtuozzo.com>

On 11/23/26 09:41, Alexander Ivanov wrote:
> vhost-blk in the kernel now handles VIRTIO_BLK_T_DISCARD, but with the
> discard property on, the config space reports zero for max_discard_seg,
> max_discard_sectors and discard_sector_alignment. A Linux guest reads a
> zero max_discard_seg as seg_max and merges adjacent discards into one
> multi-segment request, which the kernel rejects with
> VIRTIO_BLK_S_UNSUPP.
> 
> Advertise one segment per request, as virtio-blk does, a range that
> fits in the single bio the kernel issues, and the logical block size as
> the alignment. Unlike write zeroes, the backend discard limit is not
> read: the kernel splits the bio by it and completes a discard with
> VIRTIO_BLK_S_OK when the backend cannot do one.
> 
> The property stays off by default. A kernel without discard support in
> vhost-blk does not offer the feature, so it is not negotiated there.
> 
> https://virtuozzo.atlassian.net/browse/VSTOR-141683
> 
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
>   hw/block/vhost-blk.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/block/vhost-blk.c b/hw/block/vhost-blk.c
> index 153cc7604d0..3f940e965ad 100644
> --- a/hw/block/vhost-blk.c
> +++ b/hw/block/vhost-blk.c
> @@ -812,6 +812,13 @@ static void vhost_blk_update_config(VirtIODevice *vdev, uint8_t *config)
>       blkcfg.physical_block_exp = get_physical_block_exp(conf);
>       blkcfg.alignment_offset = 0;
>       virtio_stw_p(vdev, &blkcfg.num_queues, s->conf.num_queues);
> +    if (virtio_has_feature(s->host_features, VIRTIO_BLK_F_DISCARD)) {
> +        virtio_stl_p(vdev, &blkcfg.max_discard_sectors,
> +                     UINT32_MAX >> BDRV_SECTOR_BITS);
> +        virtio_stl_p(vdev, &blkcfg.discard_sector_alignment,
> +                     blk_size >> BDRV_SECTOR_BITS);
> +        virtio_stl_p(vdev, &blkcfg.max_discard_seg, 1);
> +    }
>       if (s->max_write_zeroes_sectors) {
>           virtio_stl_p(vdev, &blkcfg.max_write_zeroes_sectors,
>                        s->max_write_zeroes_sectors);
> @@ -832,7 +839,6 @@ static const Property vhost_blk_properties[] = {
>       DEFINE_PROP_UINT16("num-threads", VHostBlk, conf.num_threads, 1),
>       DEFINE_PROP_BIT64("flush", VHostBlk, host_features,
>                         VIRTIO_BLK_F_FLUSH, true),
> -/* Discard not yet implemented in kernel module */
>       DEFINE_PROP_BIT64("discard", VHostBlk, host_features,
>                         VIRTIO_BLK_F_DISCARD, false),
>       DEFINE_PROP_BIT64("write-zeroes", VHostBlk, host_features,


  reply	other threads:[~2026-11-23 13:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  8:41 Alexander Ivanov
2026-11-23 13:20 ` Andrey Zhadchenko [this message]
2026-11-23 17:35 ` Andrey Drobyshev
2026-11-26  9:35   ` Alexander Ivanov

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=85321d14-bf6d-431f-838e-e50e43713fb9@virtuozzo.com \
    --to=andrey.zhadchenko@virtuozzo.com \
    --cc=alexander.ivanov@virtuozzo.com \
    --cc=andrey.drobyshev@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.