[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CACGkMEsw7mgQdJieHz6CT3p5Pew=vH1qp5H2BSag_55w+q9Vnw@mail.gmail.com>
Date: Fri, 28 Nov 2025 10:39:57 +0800
From: Jason Wang <jasowang@...hat.com>
To: "Michael S. Tsirkin" <mst@...hat.com>
Cc: linux-kernel@...r.kernel.org, Andrew Lunn <andrew@...n.ch>,
Paolo Abeni <pabeni@...hat.com>, Eugenio Pérez <eperezma@...hat.com>,
Xuan Zhuo <xuanzhuo@...ux.alibaba.com>, Jonathan Corbet <corbet@....net>, kvm@...r.kernel.org,
virtualization@...ts.linux.dev, netdev@...r.kernel.org,
linux-doc@...r.kernel.org, Mike Christie <michael.christie@...cle.com>,
Paolo Bonzini <pbonzini@...hat.com>, Stefan Hajnoczi <stefanha@...hat.com>,
Stefano Garzarella <sgarzare@...hat.com>
Subject: Re: [PATCH v6 3/3] vhost: switch to arrays of feature bits
On Thu, Nov 27, 2025 at 2:40 PM Michael S. Tsirkin <mst@...hat.com> wrote:
>
> The current interface where caller has to know in which 64 bit chunk
> each bit is, is inelegant and fragile.
> Let's simply use arrays of bits.
> By using unroll macros text size grows only slightly.
>
> Signed-off-by: Michael S. Tsirkin <mst@...hat.com>
> ---
> drivers/vhost/net.c | 19 ++++++++++---------
> drivers/vhost/scsi.c | 9 ++++++---
> drivers/vhost/test.c | 6 +++++-
> drivers/vhost/vhost.h | 42 ++++++++++++++++++++++++++++++++++--------
> drivers/vhost/vsock.c | 10 ++++++----
> 5 files changed, 61 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
> index d057ea55f5ad..f8ed39337f56 100644
> --- a/drivers/vhost/net.c
> +++ b/drivers/vhost/net.c
> @@ -69,15 +69,15 @@ MODULE_PARM_DESC(experimental_zcopytx, "Enable Zero Copy TX;"
>
> #define VHOST_DMA_IS_DONE(len) ((__force u32)(len) >= (__force u32)VHOST_DMA_DONE_LEN)
>
> -static const u64 vhost_net_features[VIRTIO_FEATURES_U64S] = {
> - VHOST_FEATURES |
> - (1ULL << VHOST_NET_F_VIRTIO_NET_HDR) |
> - (1ULL << VIRTIO_NET_F_MRG_RXBUF) |
> - (1ULL << VIRTIO_F_ACCESS_PLATFORM) |
> - (1ULL << VIRTIO_F_RING_RESET) |
> - (1ULL << VIRTIO_F_IN_ORDER),
> - VIRTIO_BIT(VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO) |
> - VIRTIO_BIT(VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO),
> +static const int vhost_net_bits[] = {
> + VHOST_FEATURES,
> + VHOST_NET_F_VIRTIO_NET_HDR,
> + VIRTIO_NET_F_MRG_RXBUF,
> + VIRTIO_F_ACCESS_PLATFORM,
> + VIRTIO_F_RING_RESET,
> + VIRTIO_F_IN_ORDER,
> + VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO,
> + VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO
> };
>
> enum {
> @@ -1720,6 +1720,7 @@ static long vhost_net_set_owner(struct vhost_net *n)
> static long vhost_net_ioctl(struct file *f, unsigned int ioctl,
> unsigned long arg)
> {
> + const DEFINE_VHOST_FEATURES_ARRAY(vhost_net_features, vhost_net_bits);
> u64 all_features[VIRTIO_FEATURES_U64S];
> struct vhost_net *n = f->private_data;
> void __user *argp = (void __user *)arg;
> diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
> index 98e4f68f4e3c..f43c1fe9fad9 100644
> --- a/drivers/vhost/scsi.c
> +++ b/drivers/vhost/scsi.c
> @@ -197,11 +197,14 @@ enum {
> };
>
> /* Note: can't set VIRTIO_F_VERSION_1 yet, since that implies ANY_LAYOUT. */
> -enum {
> - VHOST_SCSI_FEATURES = VHOST_FEATURES | (1ULL << VIRTIO_SCSI_F_HOTPLUG) |
> - (1ULL << VIRTIO_SCSI_F_T10_PI)
> +static const int vhost_scsi_bits[] = {
> + VHOST_FEATURES,
> + VIRTIO_SCSI_F_HOTPLUG,
> + VIRTIO_SCSI_F_T10_PI
> };
>
> +#define VHOST_SCSI_FEATURES VHOST_FEATURES_U64(vhost_scsi_bits, 0)
> +
> #define VHOST_SCSI_MAX_TARGET 256
> #define VHOST_SCSI_MAX_IO_VQ 1024
> #define VHOST_SCSI_MAX_EVENT 128
> diff --git a/drivers/vhost/test.c b/drivers/vhost/test.c
> index 94cd09f36f59..f592b2f548e8 100644
> --- a/drivers/vhost/test.c
> +++ b/drivers/vhost/test.c
> @@ -28,7 +28,11 @@
> */
> #define VHOST_TEST_PKT_WEIGHT 256
>
> -#define VHOST_TEST_FEATURES VHOST_FEATURES
> +static const int vhost_test_bits[] = {
> + VHOST_FEATURES
> +};
> +
> +#define VHOST_TEST_FEATURES VHOST_FEATURES_U64(vhost_test_features, 0)
Did you mean vhost_test_bits actually?
Thanks
Powered by blists - more mailing lists