From: Jason Wang <jasowang@redhat.com>
To: Laurent Vivier <lvivier@redhat.com>
Cc: qemu-devel@nongnu.org,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Stefan Weil" <sw@weilnetz.de>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Dr. David Alan Gilbert" <dave@treblig.org>,
"Eric Blake" <eblake@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [PATCH v2 05/10] net: Consolidate vhost feature bits into NetClientInfo
Date: Tue, 1 Jul 2025 09:39:03 +0800 [thread overview]
Message-ID: <CACGkMEven2FG294GRJ_PHc_xvE3DkNtEokk+sW=Sss7izJO8rA@mail.gmail.com> (raw)
In-Reply-To: <20250618155718.550968-6-lvivier@redhat.com>
On Wed, Jun 18, 2025 at 11:57 PM Laurent Vivier <lvivier@redhat.com> wrote:
>
> Previously, the vhost_net_get_feature_bits() function in
> hw/net/vhost_net.c used a large switch statement to determine
> the appropriate feature bits based on the NetClientDriver type.
>
> This created unnecessary coupling between the generic vhost layer
> and specific network backends (like TAP, vhost-user, and
> vhost-vdpa).
>
> This patch moves the definition of vhost feature bits directly into the
> NetClientInfo structure for each relevant network client.
>
> This refactoring centralizes feature bit definitions where they're
> needed, making code easier to add new vhost-enabled network backends
> in the future without modifying core vhost logic.
>
> Signed-off-by: Laurent Vivier <lvivier@redhat.com>
> ---
> hw/net/vhost_net.c | 80 ++--------------------------------------
> include/net/net.h | 1 +
> include/net/vhost-vdpa.h | 2 -
> net/tap.c | 19 ++++++++++
> net/vhost-user.c | 43 +++++++++++++++++++++
> net/vhost-vdpa.c | 4 +-
> 6 files changed, 70 insertions(+), 79 deletions(-)
>
> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> index 16dadd022e75..3dff819d2dbd 100644
> --- a/hw/net/vhost_net.c
> +++ b/hw/net/vhost_net.c
> @@ -36,86 +36,14 @@
> #include "hw/virtio/virtio-bus.h"
> #include "linux-headers/linux/vhost.h"
>
> -
> -/* Features supported by host kernel. */
> -static const int kernel_feature_bits[] = {
> - VIRTIO_F_NOTIFY_ON_EMPTY,
> - VIRTIO_RING_F_INDIRECT_DESC,
> - VIRTIO_RING_F_EVENT_IDX,
> - VIRTIO_NET_F_MRG_RXBUF,
> - VIRTIO_F_VERSION_1,
> - VIRTIO_NET_F_MTU,
> - VIRTIO_F_IOMMU_PLATFORM,
> - VIRTIO_F_RING_PACKED,
> - VIRTIO_F_RING_RESET,
> - VIRTIO_F_IN_ORDER,
> - VIRTIO_F_NOTIFICATION_DATA,
> - VIRTIO_NET_F_RSC_EXT,
> - VIRTIO_NET_F_HASH_REPORT,
> - VHOST_INVALID_FEATURE_BIT
> -};
> -
> -/* Features supported by others. */
> -static const int user_feature_bits[] = {
> - VIRTIO_F_NOTIFY_ON_EMPTY,
> - VIRTIO_F_NOTIFICATION_DATA,
> - VIRTIO_RING_F_INDIRECT_DESC,
> - VIRTIO_RING_F_EVENT_IDX,
> -
> - VIRTIO_F_ANY_LAYOUT,
> - VIRTIO_F_VERSION_1,
> - VIRTIO_NET_F_CSUM,
> - VIRTIO_NET_F_GUEST_CSUM,
> - VIRTIO_NET_F_GSO,
> - VIRTIO_NET_F_GUEST_TSO4,
> - VIRTIO_NET_F_GUEST_TSO6,
> - VIRTIO_NET_F_GUEST_ECN,
> - VIRTIO_NET_F_GUEST_UFO,
> - VIRTIO_NET_F_HOST_TSO4,
> - VIRTIO_NET_F_HOST_TSO6,
> - VIRTIO_NET_F_HOST_ECN,
> - VIRTIO_NET_F_HOST_UFO,
> - VIRTIO_NET_F_MRG_RXBUF,
> - VIRTIO_NET_F_MTU,
> - VIRTIO_F_IOMMU_PLATFORM,
> - VIRTIO_F_RING_PACKED,
> - VIRTIO_F_RING_RESET,
> - VIRTIO_F_IN_ORDER,
> - VIRTIO_NET_F_RSS,
> - VIRTIO_NET_F_RSC_EXT,
> - VIRTIO_NET_F_HASH_REPORT,
> - VIRTIO_NET_F_GUEST_USO4,
> - VIRTIO_NET_F_GUEST_USO6,
> - VIRTIO_NET_F_HOST_USO,
> -
> - /* This bit implies RARP isn't sent by QEMU out of band */
> - VIRTIO_NET_F_GUEST_ANNOUNCE,
> -
> - VIRTIO_NET_F_MQ,
> -
> - VHOST_INVALID_FEATURE_BIT
> -};
> -
> static const int *vhost_net_get_feature_bits(struct vhost_net *net)
> {
> - if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
> - return kernel_feature_bits;
> - }
> -
> - if (qemu_is_vhost_user(net->nc)) {
> - return user_feature_bits;
> + if (net->nc->info->vhost_feature_bits == NULL) {
> + error_report("Feature bits not defined for this type: %d",
> + net->nc->info->type);
> }
>
> -#ifdef CONFIG_VHOST_NET_VDPA
> - if (net->nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA) {
> - return vdpa_feature_bits;
> - }
> -#endif
> -
> - error_report("Feature bits not defined for this type: %d",
> - net->nc->info->type);
> -
> - return 0;
> + return net->nc->info->vhost_feature_bits;
> }
>
> uint64_t vhost_net_get_features(struct vhost_net *net, uint64_t features)
> diff --git a/include/net/net.h b/include/net/net.h
> index 8a62cd6e8aab..dd11be11a39f 100644
> --- a/include/net/net.h
> +++ b/include/net/net.h
> @@ -94,6 +94,7 @@ typedef struct NetClientInfo {
> NetAnnounce *announce;
> SetSteeringEBPF *set_steering_ebpf;
> NetCheckPeerType *check_peer_type;
> + const int *vhost_feature_bits;
> IsVHostUser *is_vhost_user;
> GetVHostNet *get_vhost_net;
Assuming we had already had get_vhost_net, it looks to me it's better
to move/reuse the vhost_feature_bits there?
Thanks
next prev parent reply other threads:[~2025-07-01 1:40 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-18 15:57 [PATCH v2 00/10] net: Add passt netdev backend Laurent Vivier
2025-06-18 15:57 ` [PATCH v2 01/10] net: Refactor stream logic for reuse in '-net passt' Laurent Vivier
2025-06-18 15:57 ` [PATCH v2 02/10] net: Define net_client_set_link() Laurent Vivier
2025-06-18 15:57 ` [PATCH v2 03/10] net: Introduce helper to identify vhost-user clients Laurent Vivier
2025-07-01 1:36 ` Jason Wang
2025-06-18 15:57 ` [PATCH v2 04/10] net: Add get_vhost_net callback to NetClientInfo Laurent Vivier
2025-06-18 15:57 ` [PATCH v2 05/10] net: Consolidate vhost feature bits into NetClientInfo Laurent Vivier
2025-07-01 1:39 ` Jason Wang [this message]
2025-06-18 15:57 ` [PATCH v2 06/10] net: Add get_acked_features callback to NetClientInfo Laurent Vivier
2025-06-18 15:57 ` [PATCH v2 07/10] net: Add save_acked_features " Laurent Vivier
2025-06-18 15:57 ` [PATCH v2 08/10] net: Allow network backends to advertise max TX queue size Laurent Vivier
2025-06-18 15:57 ` [PATCH v2 09/10] net: Add passt network backend Laurent Vivier
2025-06-24 8:16 ` Markus Armbruster
2025-06-24 8:37 ` Laurent Vivier
2025-06-24 11:55 ` Markus Armbruster
2025-06-24 12:03 ` Daniel P. Berrangé
2025-06-24 12:47 ` Laurent Vivier
2025-06-25 6:57 ` Markus Armbruster
2025-06-30 14:22 ` Stefano Brivio
2025-07-01 1:46 ` Jason Wang
2025-07-01 13:00 ` Laurent Vivier
2025-07-03 10:27 ` Stefano Brivio
2025-06-18 15:57 ` [PATCH v2 10/10] net/passt: Implement vhost-user backend support Laurent Vivier
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='CACGkMEven2FG294GRJ_PHc_xvE3DkNtEokk+sW=Sss7izJO8rA@mail.gmail.com' \
--to=jasowang@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dave@treblig.org \
--cc=eblake@redhat.com \
--cc=lvivier@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.com \
--cc=sw@weilnetz.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).