From nobody Sat Nov 15 08:50:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752829028; cv=none; d=zohomail.com; s=zohoarc; b=j41iYbykLc4yfdgyq+DUrjQSQVekCVZeel0LLfPexgVT6g2dgJJwS3xScFTwfBk+7kjB9YB9DEYQg1hdCWruBrc+zMIbSiBmk96zgdIU42/Xh7LH45AE7lbfn6bfh8copDACXLTuRhZWgh6Hfsat5Tr2uGfGfnoxm4EvIvm4mQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752829028; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=AD5R4ia70RcTDA7QN0mMJQQfFKJkg2c51z0pD2mDpU4=; b=c6Ug6EEuN5Fcin+XaZC/jopFinH0F+jv+ST4X8fVOd5sFngu0QoSy4du1lq+RIpOQZi88Q/cb1fI2P90wTd/vuASPXuybI+8/Ag7YBu+FePMF0AGizaUVJbeSmxW/GW22mhSK4WVWGMxo0bESUD40rcamrNmh+dWn0pkq9Zs1rA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752829028766166.78893317230802; Fri, 18 Jul 2025 01:57:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucgqO-0000sG-J1; Fri, 18 Jul 2025 04:53:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqL-0000jj-CY for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqJ-000160-4q for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:25 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-62-EOv0CQyrNrCuZ5xshiF6uQ-1; Fri, 18 Jul 2025 04:53:18 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0F68E1956080; Fri, 18 Jul 2025 08:53:17 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.19]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1F68019560A1; Fri, 18 Jul 2025 08:53:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752828802; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AD5R4ia70RcTDA7QN0mMJQQfFKJkg2c51z0pD2mDpU4=; b=KL81lVurxRTAUGIv8T3WJNTdvqZFGikWiLvGBNxptbV+2AJCEtrSa8dxylAFVUglN65XK4 XetbLn8O6FoEU8ZST+O1oF9uoRj1SY8Yo7tBN624HgLp704iJDJu6SDR2ogG4NDsnRTbVI Y4FzzM5/bjO0ad+fE4WYBZVzeJAtdh0= X-MC-Unique: EOv0CQyrNrCuZ5xshiF6uQ-1 X-Mimecast-MFC-AGG-ID: EOv0CQyrNrCuZ5xshiF6uQ_1752828797 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC v3 01/13] net: bundle all offloads in a single struct Date: Fri, 18 Jul 2025 10:52:27 +0200 Message-ID: <0670f6ee1fe10d3c9468e7d75f30262c6c84b160.1752828082.git.pabeni@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752829029453116600 Content-Type: text/plain; charset="utf-8" The set_offload() argument list is already pretty long and we are going to introduce soon a bunch of additional offloads. Replace the offload arguments with a single struct and update all the relevant call-sites. No functional changes intended. Signed-off-by: Paolo Abeni --- Note: I maintained the struct usage as opposed to uint64_t bitmask usage as suggested by Akihiko, because the latter feel a bit more invasive. v1 -> v2: - drop unneeded 'struct' keywords - moved to series start --- hw/net/e1000e_core.c | 5 +++-- hw/net/igb_core.c | 5 +++-- hw/net/virtio-net.c | 19 +++++++++++-------- hw/net/vmxnet3.c | 13 +++++-------- include/net/net.h | 15 ++++++++++++--- net/net.c | 5 ++--- net/netmap.c | 3 +-- net/tap-bsd.c | 3 +-- net/tap-linux.c | 21 ++++++++++++--------- net/tap-solaris.c | 4 ++-- net/tap-stub.c | 3 +-- net/tap.c | 8 ++++---- net/tap_int.h | 4 ++-- 13 files changed, 59 insertions(+), 49 deletions(-) diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c index 2413858790..27599a0dc2 100644 --- a/hw/net/e1000e_core.c +++ b/hw/net/e1000e_core.c @@ -2827,8 +2827,9 @@ e1000e_update_rx_offloads(E1000ECore *core) trace_e1000e_rx_set_cso(cso_state); =20 if (core->has_vnet) { - qemu_set_offload(qemu_get_queue(core->owner_nic)->peer, - cso_state, 0, 0, 0, 0, 0, 0); + NetOffloads ol =3D {.csum =3D cso_state }; + + qemu_set_offload(qemu_get_queue(core->owner_nic)->peer, &ol); } } =20 diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c index 39e3ce1c8f..45d8fd795b 100644 --- a/hw/net/igb_core.c +++ b/hw/net/igb_core.c @@ -3058,8 +3058,9 @@ igb_update_rx_offloads(IGBCore *core) trace_e1000e_rx_set_cso(cso_state); =20 if (core->has_vnet) { - qemu_set_offload(qemu_get_queue(core->owner_nic)->peer, - cso_state, 0, 0, 0, 0, 0, 0); + NetOffloads ol =3D {.csum =3D cso_state }; + + qemu_set_offload(qemu_get_queue(core->owner_nic)->peer, &ol); } } =20 diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index c4c49b0f9c..8953c329e7 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -773,14 +773,17 @@ static uint64_t virtio_net_bad_features(VirtIODevice = *vdev) =20 static void virtio_net_apply_guest_offloads(VirtIONet *n) { - qemu_set_offload(qemu_get_queue(n->nic)->peer, - !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_CSUM)), - !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO4)), - !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO6)), - !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_ECN)), - !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_UFO)), - !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO4)), - !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO6))= ); + NetOffloads ol =3D { + .csum =3D !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_C= SUM)), + .tso4 =3D !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_T= SO4)), + .tso6 =3D !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_T= SO6)), + .ecn =3D !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_E= CN)), + .ufo =3D !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_U= FO)), + .uso4 =3D !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_U= SO4)), + .uso6 =3D !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_U= SO6)), + }; + + qemu_set_offload(qemu_get_queue(n->nic)->peer, &ol); } =20 static uint64_t virtio_net_guest_offloads_by_features(uint64_t features) diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index af73aa8ef2..03732375a7 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -1322,14 +1322,11 @@ static void vmxnet3_update_features(VMXNET3State *s) s->lro_supported, rxcso_supported, s->rx_vlan_stripping); if (s->peer_has_vhdr) { - qemu_set_offload(qemu_get_queue(s->nic)->peer, - rxcso_supported, - s->lro_supported, - s->lro_supported, - 0, - 0, - 0, - 0); + NetOffloads ol =3D { .csum =3D rxcso_supported, + .tso4 =3D s->lro_supported, + .tso6 =3D s->lro_supported }; + + qemu_set_offload(qemu_get_queue(s->nic)->peer, &ol); } } =20 diff --git a/include/net/net.h b/include/net/net.h index 84ee18e0f9..48ba333d02 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -35,6 +35,16 @@ typedef struct NICConf { int32_t bootindex; } NICConf; =20 +typedef struct NetOffloads { + bool csum; + bool tso4; + bool tso6; + bool ecn; + bool ufo; + bool uso4; + bool uso6; +} NetOffloads; + #define DEFINE_NIC_PROPERTIES(_state, _conf) \ DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ DEFINE_PROP_NETDEV("netdev", _state, _conf.peers) @@ -57,7 +67,7 @@ typedef bool (HasUfo)(NetClientState *); typedef bool (HasUso)(NetClientState *); typedef bool (HasVnetHdr)(NetClientState *); typedef bool (HasVnetHdrLen)(NetClientState *, int); -typedef void (SetOffload)(NetClientState *, int, int, int, int, int, int, = int); +typedef void (SetOffload)(NetClientState *, const NetOffloads *); typedef int (GetVnetHdrLen)(NetClientState *); typedef void (SetVnetHdrLen)(NetClientState *, int); typedef bool (GetVnetHashSupportedTypes)(NetClientState *, uint32_t *); @@ -189,8 +199,7 @@ bool qemu_has_ufo(NetClientState *nc); bool qemu_has_uso(NetClientState *nc); bool qemu_has_vnet_hdr(NetClientState *nc); bool qemu_has_vnet_hdr_len(NetClientState *nc, int len); -void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6, - int ecn, int ufo, int uso4, int uso6); +void qemu_set_offload(NetClientState *nc, const NetOffloads *ol); int qemu_get_vnet_hdr_len(NetClientState *nc); void qemu_set_vnet_hdr_len(NetClientState *nc, int len); bool qemu_get_vnet_hash_supported_types(NetClientState *nc, uint32_t *type= s); diff --git a/net/net.c b/net/net.c index da275db86e..63872b6855 100644 --- a/net/net.c +++ b/net/net.c @@ -540,14 +540,13 @@ bool qemu_has_vnet_hdr_len(NetClientState *nc, int le= n) return nc->info->has_vnet_hdr_len(nc, len); } =20 -void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6, - int ecn, int ufo, int uso4, int uso6) +void qemu_set_offload(NetClientState *nc, const NetOffloads *ol) { if (!nc || !nc->info->set_offload) { return; } =20 - nc->info->set_offload(nc, csum, tso4, tso6, ecn, ufo, uso4, uso6); + nc->info->set_offload(nc, ol); } =20 int qemu_get_vnet_hdr_len(NetClientState *nc) diff --git a/net/netmap.c b/net/netmap.c index 297510e190..6cd8f2bdc5 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -366,8 +366,7 @@ static void netmap_set_vnet_hdr_len(NetClientState *nc,= int len) } } =20 -static void netmap_set_offload(NetClientState *nc, int csum, int tso4, int= tso6, - int ecn, int ufo, int uso4, int uso6) +static void netmap_set_offload(NetClientState *nc, const NetOffloads *ol) { NetmapState *s =3D DO_UPCAST(NetmapState, nc, nc); =20 diff --git a/net/tap-bsd.c b/net/tap-bsd.c index b4c84441ba..86b6edee94 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -231,8 +231,7 @@ int tap_fd_set_vnet_be(int fd, int is_be) return -EINVAL; } =20 -void tap_fd_set_offload(int fd, int csum, int tso4, - int tso6, int ecn, int ufo, int uso4, int uso6) +void tap_fd_set_offload(int fd, const NetOffloads *ol) { } =20 diff --git a/net/tap-linux.c b/net/tap-linux.c index 22ec2f45d2..a1c58f74f5 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -239,8 +239,7 @@ int tap_fd_set_vnet_be(int fd, int is_be) abort(); } =20 -void tap_fd_set_offload(int fd, int csum, int tso4, - int tso6, int ecn, int ufo, int uso4, int uso6) +void tap_fd_set_offload(int fd, const NetOffloads *ol) { unsigned int offload =3D 0; =20 @@ -249,20 +248,24 @@ void tap_fd_set_offload(int fd, int csum, int tso4, return; } =20 - if (csum) { + if (ol->csum) { offload |=3D TUN_F_CSUM; - if (tso4) + if (ol->tso4) { offload |=3D TUN_F_TSO4; - if (tso6) + } + if (ol->tso6) { offload |=3D TUN_F_TSO6; - if ((tso4 || tso6) && ecn) + } + if ((ol->tso4 || ol->tso6) && ol->ecn) { offload |=3D TUN_F_TSO_ECN; - if (ufo) + } + if (ol->ufo) { offload |=3D TUN_F_UFO; - if (uso4) { + } + if (ol->uso4) { offload |=3D TUN_F_USO4; } - if (uso6) { + if (ol->uso6) { offload |=3D TUN_F_USO6; } } diff --git a/net/tap-solaris.c b/net/tap-solaris.c index 51b7830bef..833c066bee 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -27,6 +27,7 @@ #include "tap_int.h" #include "qemu/ctype.h" #include "qemu/cutils.h" +#include "net/net.h" =20 #include #include @@ -235,8 +236,7 @@ int tap_fd_set_vnet_be(int fd, int is_be) return -EINVAL; } =20 -void tap_fd_set_offload(int fd, int csum, int tso4, - int tso6, int ecn, int ufo, int uso4, int uso6) +void tap_fd_set_offload(int fd, const NetOffloads *ol) { } =20 diff --git a/net/tap-stub.c b/net/tap-stub.c index 38673434cb..67d14ad4d5 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -66,8 +66,7 @@ int tap_fd_set_vnet_be(int fd, int is_be) return -EINVAL; } =20 -void tap_fd_set_offload(int fd, int csum, int tso4, - int tso6, int ecn, int ufo, int uso4, int uso6) +void tap_fd_set_offload(int fd, const NetOffloads *ol) { } =20 diff --git a/net/tap.c b/net/tap.c index 23536c09b4..b49db19f83 100644 --- a/net/tap.c +++ b/net/tap.c @@ -280,15 +280,14 @@ static int tap_set_vnet_be(NetClientState *nc, bool i= s_be) return tap_fd_set_vnet_be(s->fd, is_be); } =20 -static void tap_set_offload(NetClientState *nc, int csum, int tso4, - int tso6, int ecn, int ufo, int uso4, int uso6) +static void tap_set_offload(NetClientState *nc, const NetOffloads *ol) { TAPState *s =3D DO_UPCAST(TAPState, nc, nc); if (s->fd < 0) { return; } =20 - tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo, uso4, uso6); + tap_fd_set_offload(s->fd, ol); } =20 static void tap_exit_notify(Notifier *notifier, void *data) @@ -386,6 +385,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer, int fd, int vnet_hdr) { + NetOffloads ol =3D {}; NetClientState *nc; TAPState *s; =20 @@ -399,7 +399,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer, s->has_ufo =3D tap_probe_has_ufo(s->fd); s->has_uso =3D tap_probe_has_uso(s->fd); s->enabled =3D true; - tap_set_offload(&s->nc, 0, 0, 0, 0, 0, 0, 0); + tap_set_offload(&s->nc, &ol); /* * Make sure host header length is set correctly in tap: * it might have been modified by another instance of qemu. diff --git a/net/tap_int.h b/net/tap_int.h index 8857ff299d..f8bbe1cb0c 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -27,6 +27,7 @@ #define NET_TAP_INT_H =20 #include "qapi/qapi-types-net.h" +#include "net/net.h" =20 int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required, int mq_required, Error **errp); @@ -37,8 +38,7 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, = Error **errp); int tap_probe_vnet_hdr(int fd, Error **errp); int tap_probe_has_ufo(int fd); int tap_probe_has_uso(int fd); -void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int= ufo, - int uso4, int uso6); +void tap_fd_set_offload(int fd, const NetOffloads *ol); void tap_fd_set_vnet_hdr_len(int fd, int len); int tap_fd_set_vnet_le(int fd, int vnet_is_le); int tap_fd_set_vnet_be(int fd, int vnet_is_be); --=20 2.50.0 From nobody Sat Nov 15 08:50:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752828837; cv=none; d=zohomail.com; s=zohoarc; b=HC3k9GlQsnBKw0Oqqzd8dErkrqKbjaJY5XggCY6w4QU0iNHJi6hXDrnGiiabmao8w7etZzuWxZXxofm8mOT/FATA5zRzqKBmGQgFyhLbzs7dGDutZVmXXNSvT5ffOmbNpcvaE49zdz5BYVLeM573girX0GRdbufMUuARvgPDstg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752828837; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=q19wn6ISCizGdXR5AvCwHZareuBWeQKslzPjVdnIOGU=; b=HpdqA2Ggzevk1VLIJnphgHN2LLDoy5xzq2pUoZLPbyxfDsEsKXk8lpMSD+XUQsMu8tuE96xyzA9YGkLrV+gTbqTFavNy3KR+TY10pwox66ikacbCHob9MOiyUPQkfE6cpnQpSj+j5qwo4pxKAOtXdA8bwoUWx85toaOBxN00hyk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752828837848245.76385722953148; Fri, 18 Jul 2025 01:53:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucgqU-00012o-CU; Fri, 18 Jul 2025 04:53:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqQ-0000xz-E0 for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqO-00017L-G8 for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:30 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-691-UrgQ7njDPjiKJEir_9AVNg-1; Fri, 18 Jul 2025 04:53:24 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 684C41800286; Fri, 18 Jul 2025 08:53:22 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.19]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8EAAF1956089; Fri, 18 Jul 2025 08:53:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752828807; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q19wn6ISCizGdXR5AvCwHZareuBWeQKslzPjVdnIOGU=; b=Im453In+RlK8W9SFSJrNR1EzPbHnmsIAVoXpCteaMroAXseKaj/QSDl1DCCFxYEo/dHF9L GuImUXp1mqHsvZt3oQ0iaPF3g9/46/vO6o3/Bdw/uPvCBTkdsS+w1e5JHE9dtKPt0s57/s WqkCL7JHI+B/InWar058NwXX72rIZV4= X-MC-Unique: UrgQ7njDPjiKJEir_9AVNg-1 X-Mimecast-MFC-AGG-ID: UrgQ7njDPjiKJEir_9AVNg_1752828802 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC v3 02/13] linux-headers: Update to Linux ~v6.16-rc5 net-next Date: Fri, 18 Jul 2025 10:52:28 +0200 Message-ID: <0bc9ef41193838559c8f4bf138cf4faf192849bc.1752828082.git.pabeni@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752828839512116600 Content-Type: text/plain; charset="utf-8" Update headers to include the virtio GSO over UDP tunnel features Signed-off-by: Paolo Abeni -- Note: while the relevant change are not into Linus's tree yet, they have been merged in the net-next tree and they should land into the vanilla tree during the next merge window. --- include/standard-headers/linux/ethtool.h | 4 +-- include/standard-headers/linux/vhost_types.h | 5 +++ include/standard-headers/linux/virtio_net.h | 33 ++++++++++++++++++++ linux-headers/linux/vhost.h | 7 +++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/include/standard-headers/linux/ethtool.h b/include/standard-he= aders/linux/ethtool.h index cef0d207a6..eb80314028 100644 --- a/include/standard-headers/linux/ethtool.h +++ b/include/standard-headers/linux/ethtool.h @@ -2314,7 +2314,7 @@ enum { IPV6_USER_FLOW =3D 0x0e, /* spec only (usr_ip6_spec; nfc only) */ IPV4_FLOW =3D 0x10, /* hash only */ IPV6_FLOW =3D 0x11, /* hash only */ - ETHER_FLOW =3D 0x12, /* spec only (ether_spec) */ + ETHER_FLOW =3D 0x12, /* hash or spec (ether_spec) */ =20 /* Used for GTP-U IPv4 and IPv6. * The format of GTP packets only includes @@ -2371,7 +2371,7 @@ enum { /* Flag to enable RSS spreading of traffic matching rule (nfc only) */ #define FLOW_RSS 0x20000000 =20 -/* L3-L4 network traffic flow hash options */ +/* L2-L4 network traffic flow hash options */ #define RXH_L2DA (1 << 1) #define RXH_VLAN (1 << 2) #define RXH_L3_PROTO (1 << 3) diff --git a/include/standard-headers/linux/vhost_types.h b/include/standar= d-headers/linux/vhost_types.h index fd54044936..4a3aacc39e 100644 --- a/include/standard-headers/linux/vhost_types.h +++ b/include/standard-headers/linux/vhost_types.h @@ -110,6 +110,11 @@ struct vhost_msg_v2 { }; }; =20 +struct vhost_features_array { + uint64_t count; /* number of entries present in features array */ + uint64_t features[] __counted_by(count); +}; + struct vhost_memory_region { uint64_t guest_phys_addr; uint64_t memory_size; /* bytes */ diff --git a/include/standard-headers/linux/virtio_net.h b/include/standard= -headers/linux/virtio_net.h index 982e854f14..93abaae0b9 100644 --- a/include/standard-headers/linux/virtio_net.h +++ b/include/standard-headers/linux/virtio_net.h @@ -70,6 +70,28 @@ * with the same MAC. */ #define VIRTIO_NET_F_SPEED_DUPLEX 63 /* Device set linkspeed and duplex */ +#define VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO 65 /* Driver can receive + * GSO-over-UDP-tunnel packets + */ +#define VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_CSUM 66 /* Driver handles + * GSO-over-UDP-tunnel + * packets with partial csum + * for the outer header + */ +#define VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO 67 /* Device can receive + * GSO-over-UDP-tunnel packets + */ +#define VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO_CSUM 68 /* Device handles + * GSO-over-UDP-tunnel + * packets with partial csum + * for the outer header + */ + +/* Offloads bits corresponding to VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO{,_CSUM} + * features + */ +#define VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_MAPPED 46 +#define VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_CSUM_MAPPED 47 =20 #ifndef VIRTIO_NET_NO_LEGACY #define VIRTIO_NET_F_GSO 6 /* Host handles pkts w/ any GSO type */ @@ -131,12 +153,17 @@ struct virtio_net_hdr_v1 { #define VIRTIO_NET_HDR_F_NEEDS_CSUM 1 /* Use csum_start, csum_offset */ #define VIRTIO_NET_HDR_F_DATA_VALID 2 /* Csum is valid */ #define VIRTIO_NET_HDR_F_RSC_INFO 4 /* rsc info in csum_ fields */ +#define VIRTIO_NET_HDR_F_UDP_TUNNEL_CSUM 8 /* UDP tunnel csum offload */ uint8_t flags; #define VIRTIO_NET_HDR_GSO_NONE 0 /* Not a GSO frame */ #define VIRTIO_NET_HDR_GSO_TCPV4 1 /* GSO frame, IPv4 TCP (TSO) */ #define VIRTIO_NET_HDR_GSO_UDP 3 /* GSO frame, IPv4 UDP (UFO) */ #define VIRTIO_NET_HDR_GSO_TCPV6 4 /* GSO frame, IPv6 TCP */ #define VIRTIO_NET_HDR_GSO_UDP_L4 5 /* GSO frame, IPv4& IPv6 UDP (USO) */ +#define VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV4 0x20 /* UDPv4 tunnel present */ +#define VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV6 0x40 /* UDPv6 tunnel present */ +#define VIRTIO_NET_HDR_GSO_UDP_TUNNEL (VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV4 = | \ + VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV6) #define VIRTIO_NET_HDR_GSO_ECN 0x80 /* TCP has ECN set */ uint8_t gso_type; __virtio16 hdr_len; /* Ethernet + IP + tcp/udp hdrs */ @@ -181,6 +208,12 @@ struct virtio_net_hdr_v1_hash { uint16_t padding; }; =20 +struct virtio_net_hdr_v1_hash_tunnel { + struct virtio_net_hdr_v1_hash hash_hdr; + uint16_t outer_th_offset; + uint16_t inner_nh_offset; +}; + #ifndef VIRTIO_NET_NO_LEGACY /* This header comes first in the scatter-gather list. * For legacy virtio, if VIRTIO_F_ANY_LAYOUT is not negotiated, it must diff --git a/linux-headers/linux/vhost.h b/linux-headers/linux/vhost.h index d4b3e2ae13..d6ad01fbb8 100644 --- a/linux-headers/linux/vhost.h +++ b/linux-headers/linux/vhost.h @@ -235,4 +235,11 @@ */ #define VHOST_VDPA_GET_VRING_SIZE _IOWR(VHOST_VIRTIO, 0x82, \ struct vhost_vring_state) + +/* Extended features manipulation */ +#define VHOST_GET_FEATURES_ARRAY _IOR(VHOST_VIRTIO, 0x83, \ + struct vhost_features_array) +#define VHOST_SET_FEATURES_ARRAY _IOW(VHOST_VIRTIO, 0x83, \ + struct vhost_features_array) + #endif --=20 2.50.0 From nobody Sat Nov 15 08:50:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752828907; cv=none; d=zohomail.com; s=zohoarc; b=i4ohG9eeVCdWAdSnjIr1ALb/gfRapxDoAbM9aGgXUs9qFPvAXjDCR/PqG+S2nmXLi98VOiy1a5OhSjbTUEucTPKlsOKoYVeEV5yGzIgtRA16WUoobKEfXO+co419ehKkTXAklQBDXOO6BFKtsKX5SN6voXGrB6IDKIBkFD626tU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752828907; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Q3TQfhpyStXbt0pfAiVguwtvMOM41Sx4QrHJWtkUaKM=; b=B26sjMO9LSZdQrh0LKS/CoiOkf+qO1wdt+ryYgGbtNh5dWt0YTMjQes3raH8f/GcQL7Ap/FgrY8+LzZhgPGwRuG/UafTmEbJBAEtanNWfAFLExHwJ339zELLhXPS5OZe2uMbM6kz/T09koOiIMcL3eLiZDqoM9PhW5DskSHHY4A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752828907589664.5356527069961; Fri, 18 Jul 2025 01:55:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucgqZ-0001Gi-KY; Fri, 18 Jul 2025 04:53:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqW-0001CG-PN for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqU-00018p-UQ for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:36 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-467-SdNu9AuyPyKxe6cM2wQOkw-1; Fri, 18 Jul 2025 04:53:30 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3F503180028C; Fri, 18 Jul 2025 08:53:28 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.19]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EB37B1956089; Fri, 18 Jul 2025 08:53:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752828814; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q3TQfhpyStXbt0pfAiVguwtvMOM41Sx4QrHJWtkUaKM=; b=SyjricbQnkrqGrmdxc6b/UyRDybNky1FZAvXD61reezu0j+Ojhy4t6/Vzkp0sAY5k+kYJ7 vSzh6MDvfy2+wyy5x6wNOEKcvB6MNcZCSf6l2eSy4BXyLCsEXvqs9uExM4p1aBHEfCAEcu ZKfONd1J7wUd7nWeVn1IDDfilJQOAlQ= X-MC-Unique: SdNu9AuyPyKxe6cM2wQOkw-1 X-Mimecast-MFC-AGG-ID: SdNu9AuyPyKxe6cM2wQOkw_1752828808 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC v3 03/13] virtio: introduce extended features type Date: Fri, 18 Jul 2025 10:52:29 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752828910176116600 Content-Type: text/plain; charset="utf-8" The virtio specifications allows for up to 128 bits for the device features. Soon we are going to use some of the 'extended' bits features (bit 64 and above) for the virtio net driver. Represent the virtio features bitmask with a fixes size array, and introduce a few helpers to help manipulate them. Most drivers will keep using only 64 bits features space: use union to allow them access the lower part of the extended space without any per driver change. Signed-off-by: Paolo Abeni --- v2 -> v3: - fix preprocessor guard name - use BIT_ULL - add missing parentheses - use memcmp() - _is_empty() -> _empty() - _andnot() returns a bool, true if dst has any non zero bits - _array -> _ex v1 -> v2: - use a fixed size array for features instead of uint128 - use union with u64 to reduce the needed code churn --- include/hw/virtio/virtio-features.h | 123 ++++++++++++++++++++++++++++ include/hw/virtio/virtio.h | 7 +- 2 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 include/hw/virtio/virtio-features.h diff --git a/include/hw/virtio/virtio-features.h b/include/hw/virtio/virtio= -features.h new file mode 100644 index 0000000000..68e326e3e8 --- /dev/null +++ b/include/hw/virtio/virtio-features.h @@ -0,0 +1,123 @@ +/* + * Virtio features helpers + * + * Copyright 2025 Red Hat, Inc. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef QEMU_VIRTIO_FEATURES_H +#define QEMU_VIRTIO_FEATURES_H + +#include "qemu/bitops.h" + +#define VIRTIO_FEATURES_FMT "%016"PRIx64"%016"PRIx64 +#define VIRTIO_FEATURES_PR(f) (f)[1], (f)[0] + +#define VIRTIO_FEATURES_MAX 128 +#define VIRTIO_BIT(b) BIT_ULL((b) % 64) +#define VIRTIO_DWORD(b) ((b) >> 6) +#define VIRTIO_FEATURES_WORDS (VIRTIO_FEATURES_MAX >> 5) +#define VIRTIO_FEATURES_DWORDS (VIRTIO_FEATURES_WORDS >> 1) + +#define VIRTIO_DECLARE_FEATURES(name) \ + union { \ + uint64_t name; \ + uint64_t name##_ex[VIRTIO_FEATURES_DWORDS]; \ + } + +static inline void virtio_features_clear(uint64_t *features) +{ + memset(features, 0, sizeof(features[0]) * VIRTIO_FEATURES_DWORDS); +} + +static inline void virtio_features_from_u64(uint64_t *features, uint64_t f= rom) +{ + virtio_features_clear(features); + features[0] =3D from; +} + +static inline bool virtio_has_feature_ex(const uint64_t *features, + unsigned int fbit) +{ + assert(fbit < VIRTIO_FEATURES_MAX); + return features[VIRTIO_DWORD(fbit)] & VIRTIO_BIT(fbit); +} + +static inline void virtio_add_feature_ex(uint64_t *features, + unsigned int fbit) +{ + assert(fbit < VIRTIO_FEATURES_MAX); + features[VIRTIO_DWORD(fbit)] |=3D VIRTIO_BIT(fbit); +} + +static inline void virtio_clear_feature_ex(uint64_t *features, + unsigned int fbit) +{ + assert(fbit < VIRTIO_FEATURES_MAX); + features[VIRTIO_DWORD(fbit)] &=3D ~VIRTIO_BIT(fbit); +} + +static inline bool virtio_features_equal(const uint64_t *f1, + const uint64_t *f2) +{ + return !memcmp(f1, f2, sizeof(uint64_t) * VIRTIO_FEATURES_DWORDS); +} + +static inline bool virtio_features_use_extended(const uint64_t *features) +{ + int i; + + for (i =3D 1; i < VIRTIO_FEATURES_DWORDS; ++i) { + if (features[i]) { + return true; + } + } + return false; +} + +static inline bool virtio_features_empty(const uint64_t *features) +{ + return !virtio_features_use_extended(features) && !features[0]; +} + +static inline void virtio_features_copy(uint64_t *to, const uint64_t *from) +{ + memcpy(to, from, sizeof(to[0]) * VIRTIO_FEATURES_DWORDS); +} + +static inline bool virtio_features_andnot(uint64_t *to, const uint64_t *f1, + const uint64_t *f2) +{ + uint64_t diff =3D 0; + int i; + + for (i =3D 0; i < VIRTIO_FEATURES_DWORDS; i++) { + to[i] =3D f1[i] & ~f2[i]; + diff |=3D to[i]; + } + return diff; +} + +static inline void virtio_features_and(uint64_t *to, const uint64_t *f1, + const uint64_t *f2) +{ + int i; + + for (i =3D 0; i < VIRTIO_FEATURES_DWORDS; i++) { + to[i] =3D f1[i] & f2[i]; + } +} + +static inline void virtio_features_or(uint64_t *to, const uint64_t *f1, + const uint64_t *f2) +{ + int i; + + for (i =3D 0; i < VIRTIO_FEATURES_DWORDS; i++) { + to[i] =3D f1[i] | f2[i]; + } +} + +#endif + diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index c594764f23..39e4059a66 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -16,6 +16,7 @@ =20 #include "system/memory.h" #include "hw/qdev-core.h" +#include "hw/virtio/virtio-features.h" #include "net/net.h" #include "migration/vmstate.h" #include "qemu/event_notifier.h" @@ -121,9 +122,9 @@ struct VirtIODevice * backend (e.g. vhost) and could potentially be a subset of the * total feature set offered by QEMU. */ - uint64_t host_features; - uint64_t guest_features; - uint64_t backend_features; + VIRTIO_DECLARE_FEATURES(host_features); + VIRTIO_DECLARE_FEATURES(guest_features); + VIRTIO_DECLARE_FEATURES(backend_features); =20 size_t config_len; void *config; --=20 2.50.0 From nobody Sat Nov 15 08:50:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752828916; cv=none; d=zohomail.com; s=zohoarc; b=lbtInL/EtMJrP1EFlVR+fJGY1bMe9CRmGPZ3VDAu9zLP98fCn0yrIeXSvyk23oMzXrsCWvtUpgKT8QxpzVbgv2fYQHLswUnPgZxvyBQ8thCtpaulKlvK7qF8i/gVzZK/6bWQiKHDmYd8CBq82ZM7gaw9wOk9bzNFczEdUpfRosI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752828916; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JTfQZjUV4wVtS/Z0swl737oNnNKTWMly/RkEX4hAeuA=; b=O203Na9MpsKw4fzYEr6Gzk06LDR8B0NqCZW+cfphYdWazoMHCSiU7sdLTsmU1oK6IGhvyxsnptjr/eUpVgwWM5NdgxTAkYjF9wMSog3ZL/5uGDvhQnEutfXcjnyYIDy7FiKCKCChMvnv56KlbdFUfGEkn0h4ODDcaVT9anQRpgw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752828916805685.2158046054296; Fri, 18 Jul 2025 01:55:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucgqc-0001ST-TX; Fri, 18 Jul 2025 04:53:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqb-0001LN-9M for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqY-0001AD-Va for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:40 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-177-YYynmkIzMP6h75XrUrHtHw-1; Fri, 18 Jul 2025 04:53:35 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 65F591956087; Fri, 18 Jul 2025 08:53:33 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.19]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BFFB31956089; Fri, 18 Jul 2025 08:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752828818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JTfQZjUV4wVtS/Z0swl737oNnNKTWMly/RkEX4hAeuA=; b=fc9jdUQdZnwE7fJkvih2XmOO2WF4AmyCeQ2YZu417tLPZ6kM5yFafu7kgh+KkzZnMXXehl HWeFIkYGc9MwwiRuskpE2oOwomVvwNcpYujLaU5+Mtij3QV1b4QyjYRhnTTVMx1V113G0I Fq0VDbJik3gof/OfdiFBBBBDOgN1ik0= X-MC-Unique: YYynmkIzMP6h75XrUrHtHw-1 X-Mimecast-MFC-AGG-ID: YYynmkIzMP6h75XrUrHtHw_1752828813 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC v3 04/13] virtio: serialize extended features state Date: Fri, 18 Jul 2025 10:52:30 +0200 Message-ID: <88978e62d3eb7a58d7d647c7ee29f074ccc99bc0.1752828082.git.pabeni@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752828918391116600 Content-Type: text/plain; charset="utf-8" If the driver uses any of the extended features (i.e. 64 or above), store the extended features range (64-127 bits). At load time, let legacy features initialize the full features range and pass it to the set helper; sub-states loading will have filled-up the extended part as needed. This is one of the few spots that need explicitly to know and set in stone the extended features array size; add a build bug to prevent breaking the migration should such size change again in the future: more serialization plumbing will be needed. Signed-off-by: Paolo Abeni --- v2 -> v3: - 128bit_features state load/stores only the high bits - consolidate the load implementation to use a single set helper for 128/64/32 bits features - _array -> _ex v1 -> v2: - uint128_t -> u64[2] --- hw/virtio/virtio.c | 88 ++++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 31 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 2ab1d20769..2817d3a893 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2954,6 +2954,24 @@ static const VMStateDescription vmstate_virtio_disab= led =3D { } }; =20 +static bool virtio_128bit_features_needed(void *opaque) +{ + VirtIODevice *vdev =3D opaque; + + return virtio_features_use_extended(vdev->host_features_ex); +} + +static const VMStateDescription vmstate_virtio_128bit_features =3D { + .name =3D "virtio/128bit_features", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D &virtio_128bit_features_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT64(guest_features_ex[1], VirtIODevice), + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_virtio =3D { .name =3D "virtio", .version_id =3D 1, @@ -2963,6 +2981,7 @@ static const VMStateDescription vmstate_virtio =3D { }, .subsections =3D (const VMStateDescription * const []) { &vmstate_virtio_device_endian, + &vmstate_virtio_128bit_features, &vmstate_virtio_64bit_features, &vmstate_virtio_virtqueues, &vmstate_virtio_ringsize, @@ -3059,23 +3078,28 @@ const VMStateInfo virtio_vmstate_info =3D { .put =3D virtio_device_put, }; =20 -static int virtio_set_features_nocheck(VirtIODevice *vdev, uint64_t val) +static int virtio_set_features_nocheck(VirtIODevice *vdev, const uint64_t = *val) { VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); - bool bad =3D (val & ~(vdev->host_features)) !=3D 0; + uint64_t tmp[VIRTIO_FEATURES_DWORDS]; + bool bad; + + bad =3D virtio_features_andnot(tmp, val, vdev->host_features_ex); + virtio_features_and(tmp, val, vdev->host_features_ex); =20 - val &=3D vdev->host_features; if (k->set_features) { - k->set_features(vdev, val); + bad =3D bad || virtio_features_use_extended(tmp); + k->set_features(vdev, tmp[0]); } - vdev->guest_features =3D val; + + virtio_features_copy(vdev->guest_features_ex, tmp); return bad ? -1 : 0; } =20 typedef struct VirtioSetFeaturesNocheckData { Coroutine *co; VirtIODevice *vdev; - uint64_t val; + uint64_t val[VIRTIO_FEATURES_DWORDS]; int ret; } VirtioSetFeaturesNocheckData; =20 @@ -3088,14 +3112,15 @@ static void virtio_set_features_nocheck_bh(void *op= aque) } =20 static int coroutine_mixed_fn -virtio_set_features_nocheck_maybe_co(VirtIODevice *vdev, uint64_t val) +virtio_set_features_nocheck_maybe_co(VirtIODevice *vdev, + const uint64_t *val) { if (qemu_in_coroutine()) { VirtioSetFeaturesNocheckData data =3D { .co =3D qemu_coroutine_self(), .vdev =3D vdev, - .val =3D val, }; + virtio_features_copy(data.val, val); aio_bh_schedule_oneshot(qemu_get_current_aio_context(), virtio_set_features_nocheck_bh, &data); qemu_coroutine_yield(); @@ -3107,6 +3132,7 @@ virtio_set_features_nocheck_maybe_co(VirtIODevice *vd= ev, uint64_t val) =20 int virtio_set_features(VirtIODevice *vdev, uint64_t val) { + uint64_t features[VIRTIO_FEATURES_DWORDS]; int ret; /* * The driver must not attempt to set features after feature negotiati= on @@ -3122,7 +3148,8 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t = val) __func__, vdev->name); } =20 - ret =3D virtio_set_features_nocheck(vdev, val); + virtio_features_from_u64(features, val); + ret =3D virtio_set_features_nocheck(vdev, features); if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) { /* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ int i; @@ -3145,6 +3172,7 @@ void virtio_reset(void *opaque) { VirtIODevice *vdev =3D opaque; VirtioDeviceClass *k =3D VIRTIO_DEVICE_GET_CLASS(vdev); + uint64_t features[VIRTIO_FEATURES_DWORDS]; int i; =20 virtio_set_status(vdev, 0); @@ -3171,7 +3199,8 @@ void virtio_reset(void *opaque) vdev->start_on_kick =3D false; vdev->started =3D false; vdev->broken =3D false; - virtio_set_features_nocheck(vdev, 0); + virtio_features_clear(features); + virtio_set_features_nocheck(vdev, features); vdev->queue_sel =3D 0; vdev->status =3D 0; vdev->disabled =3D false; @@ -3254,7 +3283,7 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int vers= ion_id) * Note: devices should always test host features in future - don't cr= eate * new dependencies like this. */ - vdev->guest_features =3D features; + virtio_features_from_u64(vdev->guest_features_ex, features); =20 config_len =3D qemu_get_be32(f); =20 @@ -3333,26 +3362,23 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int ve= rsion_id) vdev->device_endian =3D virtio_default_endian(); } =20 - if (virtio_64bit_features_needed(vdev)) { - /* - * Subsection load filled vdev->guest_features. Run them - * through virtio_set_features to sanity-check them against - * host_features. - */ - uint64_t features64 =3D vdev->guest_features; - if (virtio_set_features_nocheck_maybe_co(vdev, features64) < 0) { - error_report("Features 0x%" PRIx64 " unsupported. " - "Allowed features: 0x%" PRIx64, - features64, vdev->host_features); - return -1; - } - } else { - if (virtio_set_features_nocheck_maybe_co(vdev, features) < 0) { - error_report("Features 0x%x unsupported. " - "Allowed features: 0x%" PRIx64, - features, vdev->host_features); - return -1; - } + /* + * Avoid silently breaking migration should the feature space increase + * even more in the (far away) future + */ + QEMU_BUILD_BUG_ON(VIRTIO_FEATURES_DWORDS !=3D 2); + + /* + * guest_features_ex is fully initialized with u32 features and upper + * bits have been filled as needed by the later load. + */ + if (virtio_set_features_nocheck_maybe_co(vdev, + vdev->guest_features_ex) < 0)= { + error_report("Features 0x" VIRTIO_FEATURES_FMT " unsupported. " + "Allowed features: 0x" VIRTIO_FEATURES_FMT, + VIRTIO_FEATURES_PR(vdev->guest_features_ex), + VIRTIO_FEATURES_PR(vdev->host_features_ex)); + return -1; } =20 if (!virtio_device_started(vdev, vdev->status) && --=20 2.50.0 From nobody Sat Nov 15 08:50:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752828907; cv=none; d=zohomail.com; s=zohoarc; b=JY9BaPy2J9udWW/0dYHgRsAC26JnG75Yga0Rve697mfslxz5LPZl70BKOo9zPU4KqhpnTHGXNTof8mc5flvvBhdokIuMUlL9HDWPHRXW2lkfv8B0Ua649BVxKddscXvqwTcQ+49Muoaf2mWtoXcfea0A+IWMCVKw4f+EvwK2RFM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752828907; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vG49PnliW3cNEtWWNfrKYkcxJt02WcjRiHMrTnlNddI=; b=jgIGMIp/UiW7CO6tGmm5xSWPxztorLISqQVbinzgckWaisbaYjNQHS4MocqqkPQry3ssm40BcsG7SS51ZMYW8l8cPgYcll20BdrVBVCyslC2SppLtB3L7f/TSxfJV4UE+AQ++676VV+uzhq0xdJ1Mwt3RjJk1XcAbaS95UzMRUQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752828907788807.2343261766822; Fri, 18 Jul 2025 01:55:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucgqx-0001m6-5M; Fri, 18 Jul 2025 04:54:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqg-0001YK-5h for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqe-0001CB-9h for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:45 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-AFjn3_75OOWXEwqjFt-cQQ-1; Fri, 18 Jul 2025 04:53:39 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5D1AC195608B; Fri, 18 Jul 2025 08:53:38 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.19]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E8D5B1956089; Fri, 18 Jul 2025 08:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752828823; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vG49PnliW3cNEtWWNfrKYkcxJt02WcjRiHMrTnlNddI=; b=SQr6mYDWJRTMi/FtNDIQKpTup04fx3sEMFueZ8uOMGB9AzROjqibgYC9gs3i9JJ4bNKpjq EYLrtvEOsW2/p002dJ2nSWKnZ7wml7Ktzq9LvEiKwbFcOBfuUO0bfcqPzinSYemmFpqY7B nWFaG73sTgTaoslUulX+ELBHgo0k1VA= X-MC-Unique: AFjn3_75OOWXEwqjFt-cQQ-1 X-Mimecast-MFC-AGG-ID: AFjn3_75OOWXEwqjFt-cQQ_1752828818 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC v3 05/13] virtio: add support for negotiating extended features Date: Fri, 18 Jul 2025 10:52:31 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752828910035116600 Content-Type: text/plain; charset="utf-8" The virtio specifications allows for up to 128 bits for the device features. Soon we are going to use some of the 'extended' bits features for the virtio net driver. Add support to allow extended features negotiation on a per devices basis. Devices willing to negotiated extended features need to implemented a new pair of features getter/setter, the core will conditionally use them instead of the basic one. Note that 'bad_features' don't need to be extended, as they are bound to the 64 bits limit. Signed-off-by: Paolo Abeni --- v2 -> v3: - _array -> _ex v1 -> v2: - uint128_t -> uint64_t[] --- hw/virtio/virtio-bus.c | 11 ++++++++--- hw/virtio/virtio.c | 18 +++++++++++++----- include/hw/virtio/virtio.h | 4 ++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index 11adfbf3ab..cef944e015 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -62,9 +62,14 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error= **errp) } =20 /* Get the features of the plugged device. */ - assert(vdc->get_features !=3D NULL); - vdev->host_features =3D vdc->get_features(vdev, vdev->host_features, - &local_err); + if (vdc->get_features_ex) { + vdc->get_features_ex(vdev, vdev->host_features_ex, &local_err); + } else { + assert(vdc->get_features !=3D NULL); + virtio_features_from_u64(vdev->host_features_ex, + vdc->get_features(vdev, vdev->host_featur= es, + &local_err)); + } if (local_err) { error_propagate(errp, local_err); return; diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 2817d3a893..5b60617d33 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3087,7 +3087,9 @@ static int virtio_set_features_nocheck(VirtIODevice *= vdev, const uint64_t *val) bad =3D virtio_features_andnot(tmp, val, vdev->host_features_ex); virtio_features_and(tmp, val, vdev->host_features_ex); =20 - if (k->set_features) { + if (k->set_features_ex) { + k->set_features_ex(vdev, val); + } else if (k->set_features) { bad =3D bad || virtio_features_use_extended(tmp); k->set_features(vdev, tmp[0]); } @@ -3130,9 +3132,8 @@ virtio_set_features_nocheck_maybe_co(VirtIODevice *vd= ev, } } =20 -int virtio_set_features(VirtIODevice *vdev, uint64_t val) +int virtio_set_features_ex(VirtIODevice *vdev, const uint64_t *features) { - uint64_t features[VIRTIO_FEATURES_DWORDS]; int ret; /* * The driver must not attempt to set features after feature negotiati= on @@ -3142,13 +3143,12 @@ int virtio_set_features(VirtIODevice *vdev, uint64_= t val) return -EINVAL; } =20 - if (val & (1ull << VIRTIO_F_BAD_FEATURE)) { + if (features[0] & (1ull << VIRTIO_F_BAD_FEATURE)) { qemu_log_mask(LOG_GUEST_ERROR, "%s: guest driver for %s has enabled UNUSED(30) feat= ure bit!\n", __func__, vdev->name); } =20 - virtio_features_from_u64(features, val); ret =3D virtio_set_features_nocheck(vdev, features); if (virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) { /* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */ @@ -3168,6 +3168,14 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t= val) return ret; } =20 +int virtio_set_features(VirtIODevice *vdev, uint64_t val) +{ + uint64_t features[VIRTIO_FEATURES_DWORDS]; + + virtio_features_from_u64(features, val); + return virtio_set_features_ex(vdev, features); +} + void virtio_reset(void *opaque) { VirtIODevice *vdev =3D opaque; diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 39e4059a66..2aeb021fb3 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -178,6 +178,9 @@ struct VirtioDeviceClass { /* This is what a VirtioDevice must implement */ DeviceRealize realize; DeviceUnrealize unrealize; + void (*get_features_ex)(VirtIODevice *vdev, uint64_t *requested_featur= es, + Error **errp); + void (*set_features_ex)(VirtIODevice *vdev, const uint64_t *val); uint64_t (*get_features)(VirtIODevice *vdev, uint64_t requested_features, Error **errp); @@ -373,6 +376,7 @@ void virtio_queue_reset(VirtIODevice *vdev, uint32_t qu= eue_index); void virtio_queue_enable(VirtIODevice *vdev, uint32_t queue_index); void virtio_update_irq(VirtIODevice *vdev); int virtio_set_features(VirtIODevice *vdev, uint64_t val); +int virtio_set_features_ex(VirtIODevice *vdev, const uint64_t *val); =20 /* Base devices. */ typedef struct VirtIOBlkConf VirtIOBlkConf; --=20 2.50.0 From nobody Sat Nov 15 08:50:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752828981; cv=none; d=zohomail.com; s=zohoarc; b=MujQlerScBNSjKb/Jljao8P9nEZk/mrI8xW1HtlMp03QcmzULIFbS6/bw81urR+/Qog7yeGyoz+wqN0g0uqfVurwi59gCGZvFRuuCZgHcqDsJGgHbkYkJNNTJstTUM6oKh5ikPq02As+HymimCqEwinrH2zt0ddxvV8xhOwbGrg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752828981; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Zxl+R1bU66zl6qyIHsJovHkttLLv0JKawCyNJCbVijI=; b=HljYr2pxIQj/AMI8SwV/KoC52YnEkKQJ0v7Bbfdg+887GPXcbhGfPdwuFztygb8mT8K6eNEO+ppJR/4lTLHUCYUrw1CV6Au21R6pgKW0P7QTASKLiD8sLOxnUfWDIy15AX+u2XylGuciWrDvFKzw+rDByuXkDFEKPz8VTXIFl1Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752828981606890.2535871652314; Fri, 18 Jul 2025 01:56:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucgr1-00024h-Iz; Fri, 18 Jul 2025 04:54:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqk-0001bt-Ul for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqj-0001E3-9c for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:50 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-591-_VpHsfd0P_yrBeTGCjpvzQ-1; Fri, 18 Jul 2025 04:53:45 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CB7E5180048E; Fri, 18 Jul 2025 08:53:43 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.19]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 12D5F1956089; Fri, 18 Jul 2025 08:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752828828; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zxl+R1bU66zl6qyIHsJovHkttLLv0JKawCyNJCbVijI=; b=ggq8Fug8wi7jdlsKca6zh5C+OB0fBBzfpttEyuI2gkxlCInE2CVW1Xg6cvxbl6LcgXv/Ii xDPBaG5jrXIsIryLZssDybW9mYImJuHUBBaUuFT/6PrscByZ87bRlE0a3A3cG+RnghEZar rQ5iz9b0oLfiu5SuClFNI64IdmQOor4= X-MC-Unique: _VpHsfd0P_yrBeTGCjpvzQ-1 X-Mimecast-MFC-AGG-ID: _VpHsfd0P_yrBeTGCjpvzQ_1752828823 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC v3 06/13] virtio-pci: implement support for extended features Date: Fri, 18 Jul 2025 10:52:32 +0200 Message-ID: <253cd85bc76ded8259fc9d12ed3764e2507bcb75.1752828082.git.pabeni@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752828982978116600 Content-Type: text/plain; charset="utf-8" Extend the features configuration space to 128 bits, and allow the common read/write operation to access all of it. On migration, save the 128 bit version of the features only if the upper bits are non zero. Relay reset to clear all the feature space before load. Signed-off-by: Paolo Abeni --- v2 -> v3: - drop the pre_load/post_load trickery and relay on reset zeroing the features instead. - avoid union usage, just increase guest_features size and use SUB_ARRAY. - drop unneeded '!!' - _array -> _ex v1 -> v2: - use separate VMStateDescription and pre/post load to avoid breaking migration - clear proxy features on device reset --- hw/virtio/virtio-pci.c | 54 +++++++++++++++++++++++++++++----- include/hw/virtio/virtio-pci.h | 2 +- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 767216d795..6800c80eed 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -109,6 +109,29 @@ static const VMStateDescription vmstate_virtio_pci_mod= ern_queue_state =3D { } }; =20 +static bool virtio_pci_modern_state_features128_needed(void *opaque) +{ + VirtIOPCIProxy *proxy =3D opaque; + uint32_t features =3D 0; + int i; + + for (i =3D 2; i < ARRAY_SIZE(proxy->guest_features); ++i) { + features |=3D proxy->guest_features[i]; + } + return features; +} + +static const VMStateDescription vmstate_virtio_pci_modern_state_features12= 8 =3D { + .name =3D "virtio_pci/modern_state/features128", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D &virtio_pci_modern_state_features128_needed, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32_SUB_ARRAY(guest_features, VirtIOPCIProxy, 2, 2), + VMSTATE_END_OF_LIST() + } +}; + static bool virtio_pci_modern_state_needed(void *opaque) { VirtIOPCIProxy *proxy =3D opaque; @@ -124,11 +147,15 @@ static const VMStateDescription vmstate_virtio_pci_mo= dern_state_sub =3D { .fields =3D (const VMStateField[]) { VMSTATE_UINT32(dfselect, VirtIOPCIProxy), VMSTATE_UINT32(gfselect, VirtIOPCIProxy), - VMSTATE_UINT32_ARRAY(guest_features, VirtIOPCIProxy, 2), + VMSTATE_UINT32_SUB_ARRAY(guest_features, VirtIOPCIProxy, 0, 2), VMSTATE_STRUCT_ARRAY(vqs, VirtIOPCIProxy, VIRTIO_QUEUE_MAX, 0, vmstate_virtio_pci_modern_queue_state, VirtIOPCIQueue), VMSTATE_END_OF_LIST() + }, + .subsections =3D (const VMStateDescription * const []) { + &vmstate_virtio_pci_modern_state_features128, + NULL } }; =20 @@ -1494,11 +1521,14 @@ static uint64_t virtio_pci_common_read(void *opaque= , hwaddr addr, val =3D proxy->dfselect; break; case VIRTIO_PCI_COMMON_DF: - if (proxy->dfselect <=3D 1) { + if (proxy->dfselect < VIRTIO_FEATURES_WORDS) { VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); =20 - val =3D (vdev->host_features & ~vdc->legacy_features) >> - (32 * proxy->dfselect); + val =3D vdev->host_features_ex[proxy->dfselect >> 1] >> + (32 * (proxy->dfselect & 1)); + if (proxy->dfselect <=3D 1) { + val &=3D (~vdc->legacy_features) >> (32 * proxy->dfselect); + } } break; case VIRTIO_PCI_COMMON_GFSELECT: @@ -1589,10 +1619,17 @@ static void virtio_pci_common_write(void *opaque, h= waddr addr, break; case VIRTIO_PCI_COMMON_GF: if (proxy->gfselect < ARRAY_SIZE(proxy->guest_features)) { + uint64_t features[VIRTIO_FEATURES_DWORDS]; + int i; + proxy->guest_features[proxy->gfselect] =3D val; - virtio_set_features(vdev, - (((uint64_t)proxy->guest_features[1]) << 3= 2) | - proxy->guest_features[0]); + virtio_features_clear(features); + for (i =3D 0; i < ARRAY_SIZE(proxy->guest_features); ++i) { + uint64_t cur =3D proxy->guest_features[i]; + + features[i >> 1] |=3D cur << ((i & 1) * 32); + } + virtio_set_features_ex(vdev, features); } break; case VIRTIO_PCI_COMMON_MSIX: @@ -2311,6 +2348,9 @@ static void virtio_pci_reset(DeviceState *qdev) virtio_bus_reset(bus); msix_unuse_all_vectors(&proxy->pci_dev); =20 + QEMU_BUILD_BUG_ON(ARRAY_SIZE(proxy->guest_features) !=3D 4); + memset(proxy->guest_features, 0, sizeof(proxy->guest_features)); + for (i =3D 0; i < VIRTIO_QUEUE_MAX; i++) { proxy->vqs[i].enabled =3D 0; proxy->vqs[i].reset =3D 0; diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h index eab5394898..eae0fcdec3 100644 --- a/include/hw/virtio/virtio-pci.h +++ b/include/hw/virtio/virtio-pci.h @@ -158,7 +158,7 @@ struct VirtIOPCIProxy { uint32_t nvectors; uint32_t dfselect; uint32_t gfselect; - uint32_t guest_features[2]; + uint32_t guest_features[4]; VirtIOPCIQueue vqs[VIRTIO_QUEUE_MAX]; =20 VirtIOIRQFD *vector_irqfd; --=20 2.50.0 From nobody Sat Nov 15 08:50:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752828915; cv=none; d=zohomail.com; s=zohoarc; b=inYLm5wGqUXG0ROgl6GCYJag5uMvVIldBtY5K5++8M56W6G7drFwbZZ59KLVTc8vVcpGiH0w3g5Nhfek/RB/nwn6Lj3WFjakjGS902ovlpC04SeAGi8EmgDYJec9ZEwWj5AjqZ/VIkKxLHY60nw4jRH9JPJXL+lGO0RJFCqZ3cU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752828915; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HRCP4zzbXWKwS+Vej6PIvTWGPDj6CHagt4gnNJxMPMo=; b=KZ7CrXLcnDBtAUbgzudhjOEywe/6mSoRq2iumdksbROL7a7S1yM1a7HOK+4SQ0cHHYSJN+0pFfnSZBks/aSA5vNzn8cGfK1+mRrzsYPBroc2e45MKfRA82JaXwXfsLXlp6yKxIDSlmji7Tl9pHkyqJcym2rc9R3OaybU3Z7ObQs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752828915982167.71485369064692; Fri, 18 Jul 2025 01:55:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucgqx-0001pm-TH; Fri, 18 Jul 2025 04:54:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqp-0001iN-Jb for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqn-0001FC-Mt for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:53:55 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-669-zTfx1jNwNxaaOIjyCZUtQA-1; Fri, 18 Jul 2025 04:53:50 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1A6BD180029E; Fri, 18 Jul 2025 08:53:49 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.19]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 557CF1956089; Fri, 18 Jul 2025 08:53:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752828833; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HRCP4zzbXWKwS+Vej6PIvTWGPDj6CHagt4gnNJxMPMo=; b=UhZFg+igk6MGcXrAiTjJv5jDeMs2pLJMgocus8ytt9yye8hEOJRHCEPdgVTQwgEe4Wt8Al czOoEqhdwGJug+iGokCMYBh6W5CA1dM4q4GnE4jknRF/GXNNXJvns9W82Qh/JqKTcj3xwq MKWyxajl2Aay0I5ZbWoxH2Dl6zgSVWg= X-MC-Unique: zTfx1jNwNxaaOIjyCZUtQA-1 X-Mimecast-MFC-AGG-ID: zTfx1jNwNxaaOIjyCZUtQA_1752828829 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC v3 07/13] vhost: add support for negotiating extended features Date: Fri, 18 Jul 2025 10:52:33 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752828918450116600 Content-Type: text/plain; charset="utf-8" Similar to virtio infra, vhost core maintains the features status in the full extended format and allows the devices to implement extended version of the getter/setter. Note that 'protocol_features' are not extended: they are only used by vhost-user, and the latter device is not going to implement extended features soon. Signed-off-by: Paolo Abeni --- v2 -> v3: - fix compile warning - _array -> _ex v1 -> v2: - uint128_t -> uint64_t[] - add _ex() variant of features manipulation helpers --- hw/virtio/vhost.c | 73 +++++++++++++++++++++++++++---- include/hw/virtio/vhost-backend.h | 6 +++ include/hw/virtio/vhost.h | 33 ++++++++++++-- 3 files changed, 100 insertions(+), 12 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index c30ea1156e..85ae1e4d4c 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -972,20 +972,34 @@ static int vhost_virtqueue_set_addr(struct vhost_dev = *dev, static int vhost_dev_set_features(struct vhost_dev *dev, bool enable_log) { - uint64_t features =3D dev->acked_features; + uint64_t features[VIRTIO_FEATURES_DWORDS]; int r; + + virtio_features_copy(features, dev->acked_features_ex); if (enable_log) { - features |=3D 0x1ULL << VHOST_F_LOG_ALL; + virtio_add_feature_ex(features, VHOST_F_LOG_ALL); } if (!vhost_dev_has_iommu(dev)) { - features &=3D ~(0x1ULL << VIRTIO_F_IOMMU_PLATFORM); + virtio_clear_feature_ex(features, VIRTIO_F_IOMMU_PLATFORM); } if (dev->vhost_ops->vhost_force_iommu) { if (dev->vhost_ops->vhost_force_iommu(dev) =3D=3D true) { - features |=3D 0x1ULL << VIRTIO_F_IOMMU_PLATFORM; + virtio_add_feature_ex(features, VIRTIO_F_IOMMU_PLATFORM); } } - r =3D dev->vhost_ops->vhost_set_features(dev, features); + + if (virtio_features_use_extended(features) && + !dev->vhost_ops->vhost_set_features_ex) { + VHOST_OPS_DEBUG(r, "extended features without device support"); + r =3D -EINVAL; + goto out; + } + + if (dev->vhost_ops->vhost_set_features_ex) { + r =3D dev->vhost_ops->vhost_set_features_ex(dev, features); + } else { + r =3D dev->vhost_ops->vhost_set_features(dev, features[0]); + } if (r < 0) { VHOST_OPS_DEBUG(r, "vhost_set_features failed"); goto out; @@ -1506,12 +1520,27 @@ static void vhost_virtqueue_cleanup(struct vhost_vi= rtqueue *vq) } } =20 +static int vhost_dev_get_features(struct vhost_dev *hdev, + uint64_t *features) +{ + uint64_t features64; + int r; + + if (hdev->vhost_ops->vhost_get_features_ex) { + return hdev->vhost_ops->vhost_get_features_ex(hdev, features); + } + + r =3D hdev->vhost_ops->vhost_get_features(hdev, &features64); + virtio_features_from_u64(features, features64); + return r; +} + int vhost_dev_init(struct vhost_dev *hdev, void *opaque, VhostBackendType backend_type, uint32_t busyloop_timeou= t, Error **errp) { + uint64_t features[VIRTIO_FEATURES_DWORDS]; unsigned int used, reserved, limit; - uint64_t features; int i, r, n_initialized_vqs =3D 0; =20 hdev->vdev =3D NULL; @@ -1531,7 +1560,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, goto fail; } =20 - r =3D hdev->vhost_ops->vhost_get_features(hdev, &features); + r =3D vhost_dev_get_features(hdev, features); if (r < 0) { error_setg_errno(errp, -r, "vhost_get_features failed"); goto fail; @@ -1569,7 +1598,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, } } =20 - hdev->features =3D features; + virtio_features_copy(hdev->features_ex, features); =20 hdev->memory_listener =3D (MemoryListener) { .name =3D "vhost", @@ -1592,7 +1621,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *opaq= ue, }; =20 if (hdev->migration_blocker =3D=3D NULL) { - if (!(hdev->features & (0x1ULL << VHOST_F_LOG_ALL))) { + if (!virtio_has_feature_ex(hdev->features_ex, VHOST_F_LOG_ALL)) { error_setg(&hdev->migration_blocker, "Migration disabled: vhost lacks VHOST_F_LOG_ALL fe= ature."); } else if (vhost_dev_log_is_shared(hdev) && !qemu_memfd_alloc_chec= k()) { @@ -1871,6 +1900,20 @@ uint64_t vhost_get_features(struct vhost_dev *hdev, = const int *feature_bits, return features; } =20 +void vhost_get_features_ex(struct vhost_dev *hdev, + const int *feature_bits, + uint64_t *features) +{ + const int *bit =3D feature_bits; + + while (*bit !=3D VHOST_INVALID_FEATURE_BIT) { + if (!virtio_has_feature_ex(hdev->features_ex, *bit)) { + virtio_clear_feature_ex(features, *bit); + } + bit++; + } +} + void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits, uint64_t features) { @@ -1884,6 +1927,18 @@ void vhost_ack_features(struct vhost_dev *hdev, cons= t int *feature_bits, } } =20 +void vhost_ack_features_ex(struct vhost_dev *hdev, const int *feature_bits, + const uint64_t *features) +{ + const int *bit =3D feature_bits; + while (*bit !=3D VHOST_INVALID_FEATURE_BIT) { + if (virtio_has_feature_ex(features, *bit)) { + virtio_add_feature_ex(hdev->acked_features_ex, *bit); + } + bit++; + } +} + int vhost_dev_get_config(struct vhost_dev *hdev, uint8_t *config, uint32_t config_len, Error **errp) { diff --git a/include/hw/virtio/vhost-backend.h b/include/hw/virtio/vhost-ba= ckend.h index d6df209a2f..ff94fa1734 100644 --- a/include/hw/virtio/vhost-backend.h +++ b/include/hw/virtio/vhost-backend.h @@ -95,6 +95,10 @@ typedef int (*vhost_new_worker_op)(struct vhost_dev *dev, struct vhost_worker_state *worker); typedef int (*vhost_free_worker_op)(struct vhost_dev *dev, struct vhost_worker_state *worker); +typedef int (*vhost_set_features_ex_op)(struct vhost_dev *dev, + const uint64_t *features); +typedef int (*vhost_get_features_ex_op)(struct vhost_dev *dev, + uint64_t *features); typedef int (*vhost_set_features_op)(struct vhost_dev *dev, uint64_t features); typedef int (*vhost_get_features_op)(struct vhost_dev *dev, @@ -186,6 +190,8 @@ typedef struct VhostOps { vhost_free_worker_op vhost_free_worker; vhost_get_vring_worker_op vhost_get_vring_worker; vhost_attach_vring_worker_op vhost_attach_vring_worker; + vhost_set_features_ex_op vhost_set_features_ex; + vhost_get_features_ex_op vhost_get_features_ex; vhost_set_features_op vhost_set_features; vhost_get_features_op vhost_get_features; vhost_set_backend_cap_op vhost_set_backend_cap; diff --git a/include/hw/virtio/vhost.h b/include/hw/virtio/vhost.h index 66be6afc88..39fbffc6bc 100644 --- a/include/hw/virtio/vhost.h +++ b/include/hw/virtio/vhost.h @@ -107,9 +107,9 @@ struct vhost_dev { * future use should be discouraged and the variable retired as * its easy to confuse with the VirtIO backend_features. */ - uint64_t features; - uint64_t acked_features; - uint64_t backend_features; + VIRTIO_DECLARE_FEATURES(features); + VIRTIO_DECLARE_FEATURES(acked_features); + VIRTIO_DECLARE_FEATURES(backend_features); =20 /** * @protocol_features: is the vhost-user only feature set by @@ -333,6 +333,21 @@ void vhost_virtqueue_mask(struct vhost_dev *hdev, Virt= IODevice *vdev, int n, uint64_t vhost_get_features(struct vhost_dev *hdev, const int *feature_bit= s, uint64_t features); =20 +/** + * vhost_get_features_ex() - sanitize the extended features set + * @hdev: common vhost_dev structure + * @feature_bits: pointer to terminated table of feature bits + * @features: original features set, filtered out on return + * + * This is the extended variant of vhost_get_features(), supporting the + * the extended features set. Filter it with the intersection of what is + * supported by the vhost backend (hdev->features) and the supported + * feature_bits. + */ +void vhost_get_features_ex(struct vhost_dev *hdev, + const int *feature_bits, + uint64_t *features); + /** * vhost_ack_features() - set vhost acked_features * @hdev: common vhost_dev structure @@ -344,6 +359,18 @@ uint64_t vhost_get_features(struct vhost_dev *hdev, co= nst int *feature_bits, */ void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits, uint64_t features); + +/** + * vhost_ack_features_ex() - set vhost full set of acked_features + * @hdev: common vhost_dev structure + * @feature_bits: pointer to terminated table of feature bits + * @features: requested feature set + * + * This sets the internal hdev->acked_features to the intersection of + * the backends advertised features and the supported feature_bits. + */ +void vhost_ack_features_ex(struct vhost_dev *hdev, const int *feature_bits, + const uint64_t *features); unsigned int vhost_get_max_memslots(void); unsigned int vhost_get_free_memslots(void); =20 --=20 2.50.0 From nobody Sat Nov 15 08:50:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752828889; cv=none; d=zohomail.com; s=zohoarc; b=LeWQDcd66jYl4IRhPNCnbttWQWpvLBljCmKS1tgT5C+qgrt919bKmUqa5Fqzr34kZm6Qs9zus/zjgMJubL0Vu5iKhx6yRLtgrSOWJHJ1c7rJiIS81OK307s7eHQdL8JjugwqQ3kICbuJFqePP7Mff7YD7AmfqAeUMaYG1ugjViY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752828889; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bY1Ezaf9wxG2bqI3/c7UjbNgLSN4UmGaBJO2A+7q28A=; b=ct2ODgy/MNwDMnoeM1iweU9OLurTxzKmWIKXZ4mMLUfzaa7zbphwVU+PXQqPBqjIowOWJl2nGEaaTVZnvnDcVBAspMPX+ZlkVWiRMAcb2Tjm/bxvaoFnPXBFxSP6pYO7+UNVxjoYJzyXcliakIgNddhdM14c0wT/897/3kUBWxs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752828889563800.0541981955066; Fri, 18 Jul 2025 01:54:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucgr0-00021N-VJ; Fri, 18 Jul 2025 04:54:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqw-0001nc-N6 for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:54:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqu-0001H5-Pi for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:54:02 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-316-NOYpAjCdN9OtP-Hf4gwOhQ-1; Fri, 18 Jul 2025 04:53:55 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E7B081800165; Fri, 18 Jul 2025 08:53:53 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.19]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 826B119560A1; Fri, 18 Jul 2025 08:53:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752828840; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bY1Ezaf9wxG2bqI3/c7UjbNgLSN4UmGaBJO2A+7q28A=; b=Qr+aPMiJIXHq3QN0lSC+lgdAC+jgyXkCHq14DfaB1BaVMRBc2C5qsHEVJb25lOyZJqyQVo FmkSme/klo/sVI/e9qBDtk4KUqWZVNwmjzFcpPHFo0BMnPzbI0PLpAMkptiHgODrXPt+l2 1HxBfudHTOMC4TY1sfrnTZwSy5mImU8= X-MC-Unique: NOYpAjCdN9OtP-Hf4gwOhQ-1 X-Mimecast-MFC-AGG-ID: NOYpAjCdN9OtP-Hf4gwOhQ_1752828834 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC v3 08/13] qmp: update virtio features map to support extended features Date: Fri, 18 Jul 2025 10:52:34 +0200 Message-ID: <8a42515171c651101aa487519fbbc53dbe4c4c29.1752828082.git.pabeni@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752828892079116600 Content-Type: text/plain; charset="utf-8" Extend the VirtioDeviceFeatures struct with an additional u64 to track unknown features in the 64-127 bit range and decode the full virtio features spaces for vhost and virtio devices. Also add entries for the soon-to-be-supported virtio net GSO over UDP features. Signed-off-by: Paolo Abeni --- v2 -> v3: - unknown-dev-features-dword2 -> unknown-dev-features2 - _array -> _ex - fixed typos in entries description v1 -> v2: - uint128_t -> uint64_t[] --- hw/virtio/virtio-hmp-cmds.c | 3 +- hw/virtio/virtio-qmp.c | 89 ++++++++++++++++++++++++++----------- hw/virtio/virtio-qmp.h | 3 +- qapi/virtio.json | 8 +++- 4 files changed, 73 insertions(+), 30 deletions(-) diff --git a/hw/virtio/virtio-hmp-cmds.c b/hw/virtio/virtio-hmp-cmds.c index 7d8677bcf0..1daae482d3 100644 --- a/hw/virtio/virtio-hmp-cmds.c +++ b/hw/virtio/virtio-hmp-cmds.c @@ -74,7 +74,8 @@ static void hmp_virtio_dump_features(Monitor *mon, } =20 if (features->has_unknown_dev_features) { - monitor_printf(mon, " unknown-features(0x%016"PRIx64")\n", + monitor_printf(mon, " unknown-features(0x%016"PRIx64"%016"PRIx64"= )\n", + features->unknown_dev_features2, features->unknown_dev_features); } } diff --git a/hw/virtio/virtio-qmp.c b/hw/virtio/virtio-qmp.c index 3b6377cf0d..03c6163cf4 100644 --- a/hw/virtio/virtio-qmp.c +++ b/hw/virtio/virtio-qmp.c @@ -325,6 +325,20 @@ static const qmp_virtio_feature_map_t virtio_net_featu= re_map[] =3D { FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \ "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features " "negotiation supported"), + FEATURE_ENTRY(VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO, \ + "VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO: Driver can receive GSO ove= r " + "UDP tunnel packets"), + FEATURE_ENTRY(VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_CSUM, \ + "VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO: Driver can receive GSO ove= r " + "UDP tunnel packets requiring checksum offload for the outer " + "header"), + FEATURE_ENTRY(VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO, \ + "VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO: Device can receive GSO over= " + "UDP tunnel packets"), + FEATURE_ENTRY(VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO_CSUM, \ + "VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO: Device can receive GSO over= " + "UDP tunnel packets requiring checksum offload for the outer " + "header"), { -1, "" } }; #endif @@ -510,6 +524,24 @@ static const qmp_virtio_feature_map_t virtio_gpio_feat= ure_map[] =3D { list; \ }) =20 +#define CONVERT_FEATURES_EX(type, map, bitmap) \ + ({ \ + type *list =3D NULL; \ + type *node; \ + for (i =3D 0; map[i].virtio_bit !=3D -1; i++) { \ + bit =3D map[i].virtio_bit; \ + if (!virtio_has_feature_ex(bitmap, bit)) { \ + continue; \ + } \ + node =3D g_new0(type, 1); \ + node->value =3D g_strdup(map[i].feature_desc); \ + node->next =3D list; \ + list =3D node; \ + virtio_clear_feature_ex(bitmap, bit); \ + } \ + list; \ + }) + VirtioDeviceStatus *qmp_decode_status(uint8_t bitmap) { VirtioDeviceStatus *status; @@ -545,109 +577,112 @@ VhostDeviceProtocols *qmp_decode_protocols(uint64_t= bitmap) return vhu_protocols; } =20 -VirtioDeviceFeatures *qmp_decode_features(uint16_t device_id, uint64_t bit= map) +VirtioDeviceFeatures *qmp_decode_features(uint16_t device_id, + const uint64_t *bmap) { + uint64_t bitmap[VIRTIO_FEATURES_DWORDS]; VirtioDeviceFeatures *features; uint64_t bit; int i; =20 + virtio_features_copy(bitmap, bmap); features =3D g_new0(VirtioDeviceFeatures, 1); features->has_dev_features =3D true; =20 /* transport features */ - features->transports =3D CONVERT_FEATURES(strList, virtio_transport_ma= p, 0, - bitmap); + features->transports =3D CONVERT_FEATURES_EX(strList, virtio_transport= _map, + bitmap); =20 /* device features */ switch (device_id) { #ifdef CONFIG_VIRTIO_SERIAL case VIRTIO_ID_CONSOLE: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_serial_feature_map, 0, bitmap= ); + CONVERT_FEATURES_EX(strList, virtio_serial_feature_map, bitmap= ); break; #endif #ifdef CONFIG_VIRTIO_BLK case VIRTIO_ID_BLOCK: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_blk_feature_map, 0, bitmap); + CONVERT_FEATURES_EX(strList, virtio_blk_feature_map, bitmap); break; #endif #ifdef CONFIG_VIRTIO_GPU case VIRTIO_ID_GPU: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_gpu_feature_map, 0, bitmap); + CONVERT_FEATURES_EX(strList, virtio_gpu_feature_map, bitmap); break; #endif #ifdef CONFIG_VIRTIO_NET case VIRTIO_ID_NET: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_net_feature_map, 0, bitmap); + CONVERT_FEATURES_EX(strList, virtio_net_feature_map, bitmap); break; #endif #ifdef CONFIG_VIRTIO_SCSI case VIRTIO_ID_SCSI: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_scsi_feature_map, 0, bitmap); + CONVERT_FEATURES_EX(strList, virtio_scsi_feature_map, bitmap); break; #endif #ifdef CONFIG_VIRTIO_BALLOON case VIRTIO_ID_BALLOON: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_balloon_feature_map, 0, bitma= p); + CONVERT_FEATURES_EX(strList, virtio_balloon_feature_map, bitma= p); break; #endif #ifdef CONFIG_VIRTIO_IOMMU case VIRTIO_ID_IOMMU: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_iommu_feature_map, 0, bitmap); + CONVERT_FEATURES_EX(strList, virtio_iommu_feature_map, bitmap); break; #endif #ifdef CONFIG_VIRTIO_INPUT case VIRTIO_ID_INPUT: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_input_feature_map, 0, bitmap); + CONVERT_FEATURES_EX(strList, virtio_input_feature_map, bitmap); break; #endif #ifdef CONFIG_VHOST_USER_FS case VIRTIO_ID_FS: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_fs_feature_map, 0, bitmap); + CONVERT_FEATURES_EX(strList, virtio_fs_feature_map, bitmap); break; #endif #ifdef CONFIG_VHOST_VSOCK case VIRTIO_ID_VSOCK: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_vsock_feature_map, 0, bitmap); + CONVERT_FEATURES_EX(strList, virtio_vsock_feature_map, bitmap); break; #endif #ifdef CONFIG_VIRTIO_CRYPTO case VIRTIO_ID_CRYPTO: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_crypto_feature_map, 0, bitmap= ); + CONVERT_FEATURES_EX(strList, virtio_crypto_feature_map, bitmap= ); break; #endif #ifdef CONFIG_VIRTIO_MEM case VIRTIO_ID_MEM: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_mem_feature_map, 0, bitmap); + CONVERT_FEATURES_EX(strList, virtio_mem_feature_map, bitmap); break; #endif #ifdef CONFIG_VIRTIO_I2C_ADAPTER case VIRTIO_ID_I2C_ADAPTER: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_i2c_feature_map, 0, bitmap); + CONVERT_FEATURES_EX(strList, virtio_i2c_feature_map, bitmap); break; #endif #ifdef CONFIG_VIRTIO_RNG case VIRTIO_ID_RNG: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_rng_feature_map, 0, bitmap); + CONVERT_FEATURES_EX(strList, virtio_rng_feature_map, bitmap); break; #endif #ifdef CONFIG_VHOST_USER_GPIO case VIRTIO_ID_GPIO: features->dev_features =3D - CONVERT_FEATURES(strList, virtio_gpio_feature_map, 0, bitmap); + CONVERT_FEATURES_EX(strList, virtio_gpio_feature_map, bitmap); break; #endif /* No features */ @@ -680,9 +715,10 @@ VirtioDeviceFeatures *qmp_decode_features(uint16_t dev= ice_id, uint64_t bitmap) g_assert_not_reached(); } =20 - features->has_unknown_dev_features =3D bitmap !=3D 0; + features->has_unknown_dev_features =3D !virtio_features_empty(bitmap); if (features->has_unknown_dev_features) { - features->unknown_dev_features =3D bitmap; + features->unknown_dev_features =3D bitmap[0]; + features->unknown_dev_features2 =3D bitmap[1]; } =20 return features; @@ -743,11 +779,11 @@ VirtioStatus *qmp_x_query_virtio_status(const char *p= ath, Error **errp) status->device_id =3D vdev->device_id; status->vhost_started =3D vdev->vhost_started; status->guest_features =3D qmp_decode_features(vdev->device_id, - vdev->guest_features); + vdev->guest_features_ex); status->host_features =3D qmp_decode_features(vdev->device_id, - vdev->host_features); + vdev->host_features_ex); status->backend_features =3D qmp_decode_features(vdev->device_id, - vdev->backend_features); + vdev->backend_features_ex= ); =20 switch (vdev->device_endian) { case VIRTIO_DEVICE_ENDIAN_LITTLE: @@ -785,11 +821,12 @@ VirtioStatus *qmp_x_query_virtio_status(const char *p= ath, Error **errp) status->vhost_dev->nvqs =3D hdev->nvqs; status->vhost_dev->vq_index =3D hdev->vq_index; status->vhost_dev->features =3D - qmp_decode_features(vdev->device_id, hdev->features); + qmp_decode_features(vdev->device_id, hdev->features_ex); status->vhost_dev->acked_features =3D - qmp_decode_features(vdev->device_id, hdev->acked_features); + qmp_decode_features(vdev->device_id, hdev->acked_features_ex); status->vhost_dev->backend_features =3D - qmp_decode_features(vdev->device_id, hdev->backend_features); + qmp_decode_features(vdev->device_id, hdev->backend_features_ex= ); + status->vhost_dev->protocol_features =3D qmp_decode_protocols(hdev->protocol_features); status->vhost_dev->max_queues =3D hdev->max_queues; diff --git a/hw/virtio/virtio-qmp.h b/hw/virtio/virtio-qmp.h index 245a446a56..e0a1e49035 100644 --- a/hw/virtio/virtio-qmp.h +++ b/hw/virtio/virtio-qmp.h @@ -18,6 +18,7 @@ VirtIODevice *qmp_find_virtio_device(const char *path); VirtioDeviceStatus *qmp_decode_status(uint8_t bitmap); VhostDeviceProtocols *qmp_decode_protocols(uint64_t bitmap); -VirtioDeviceFeatures *qmp_decode_features(uint16_t device_id, uint64_t bit= map); +VirtioDeviceFeatures *qmp_decode_features(uint16_t device_id, + const uint64_t *bitmap); =20 #endif diff --git a/qapi/virtio.json b/qapi/virtio.json index 9d652fe4a8..f2e2dd6e97 100644 --- a/qapi/virtio.json +++ b/qapi/virtio.json @@ -490,14 +490,18 @@ # unique features) # # @unknown-dev-features: Virtio device features bitmap that have not -# been decoded +# been decoded (bits 0-63) +# +# @unknown-dev-features2: Virtio device features bitmap that have not +# been decoded (bits 64-127) # # Since: 7.2 ## { 'struct': 'VirtioDeviceFeatures', 'data': { 'transports': [ 'str' ], '*dev-features': [ 'str' ], - '*unknown-dev-features': 'uint64' } } + '*unknown-dev-features': 'uint64', + '*unknown-dev-features2': 'uint64' } } =20 ## # @VirtQueueStatus: --=20 2.50.0 From nobody Sat Nov 15 08:50:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752828883; cv=none; d=zohomail.com; s=zohoarc; b=dmITwxD/qV6HD6wK34UWfC1pHgQVnLWdqOJRl9iYPSKQBsnsjFSX/icwpCcfWnnLLe8qSpbaXolsOWNzKU7ld5tR4xu3R78B417zart6zSGwLlUAsM1pKr8d8uAhwv47aCsSfrsrDG0LuY+TAJPDx2BzOGlCwda/DtWUPp/MiLI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752828883; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SL+GETdKban5g91ExaSvmecQrNfHVSXJ9ooj81M5Q9A=; b=lW/UIbaHVI614QL6U2Q3cxiRH0i/DQ7bVZUPYNOgT+mNDn/A8AEp9UNoZvkfMFIhi6b9SZcBGj1lqEa12Cj+9NwiJ9l/J7iEFOMe9fC/l6gnsTqdtPwYSPHhRVOBTbnxqODrb8HJ5bIGDvhnmQRB6pzxCS+XsXQ+3MZaH0JJbOs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752828883194255.8255994217526; Fri, 18 Jul 2025 01:54:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucgrB-0002Cg-W9; Fri, 18 Jul 2025 04:54:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgr1-00026A-GK for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:54:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgqz-0001If-9L for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:54:07 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-466-EGYlpH9cPLa66DIJxssMAA-1; Fri, 18 Jul 2025 04:54:01 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6BF6619560B3; Fri, 18 Jul 2025 08:53:59 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.19]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7751C1956089; Fri, 18 Jul 2025 08:53:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752828844; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SL+GETdKban5g91ExaSvmecQrNfHVSXJ9ooj81M5Q9A=; b=SpStsfY7hKr9Ub0XxdFNPK2zgGtwAaDsN16e88F/NOnwQJs3SbuZhw5WKOWARr+/+aQFdh HQ3XE0nHaL7Judt0Sol1/otNEDoWlOHrA/gwd6P6S8RGLVUPtIDp4ogeh6iDKEA/na6q/t /QRUN2g2jmNQaZsGDBq4CgnSVzbOHcg= X-MC-Unique: EGYlpH9cPLa66DIJxssMAA-1 X-Mimecast-MFC-AGG-ID: EGYlpH9cPLa66DIJxssMAA_1752828839 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC v3 09/13] vhost-backend: implement extended features support Date: Fri, 18 Jul 2025 10:52:35 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752828885689116600 Content-Type: text/plain; charset="utf-8" Leverage the kernel extended features manipulation ioctls(), if available, and fallback to old ops otherwise. Error out when setting extended features but kernel support is not available. Note that extended support for get/set backend features is not needed, as the only feature that can be changed belongs to the 64 bit range. Signed-off-by: Paolo Abeni --- v1 -> v2: - synced with kernel ioctl changes --- hw/virtio/vhost-backend.c | 62 ++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c index 833804dd40..6fde994403 100644 --- a/hw/virtio/vhost-backend.c +++ b/hw/virtio/vhost-backend.c @@ -20,6 +20,11 @@ #include #include =20 +struct vhost_features { + uint64_t count; + uint64_t features[VIRTIO_FEATURES_DWORDS]; +}; + static int vhost_kernel_call(struct vhost_dev *dev, unsigned long int requ= est, void *arg) { @@ -182,12 +187,6 @@ static int vhost_kernel_get_vring_worker(struct vhost_= dev *dev, return vhost_kernel_call(dev, VHOST_GET_VRING_WORKER, worker); } =20 -static int vhost_kernel_set_features(struct vhost_dev *dev, - uint64_t features) -{ - return vhost_kernel_call(dev, VHOST_SET_FEATURES, &features); -} - static int vhost_kernel_set_backend_cap(struct vhost_dev *dev) { uint64_t features; @@ -210,10 +209,51 @@ static int vhost_kernel_set_backend_cap(struct vhost_= dev *dev) return 0; } =20 -static int vhost_kernel_get_features(struct vhost_dev *dev, - uint64_t *features) +static int vhost_kernel_set_features(struct vhost_dev *dev, + const uint64_t *features) { - return vhost_kernel_call(dev, VHOST_GET_FEATURES, features); + struct vhost_features farray; + bool extended_in_use; + int r; + + farray.count =3D VIRTIO_FEATURES_DWORDS; + virtio_features_copy(farray.features, features); + extended_in_use =3D virtio_features_use_extended(farray.features); + + /* + * Can't check for ENOTTY: for unknown ioctls the kernel interprets + * the argument as a virtio queue id and most likely errors out valida= ting + * such id, instead of reporting an unknown operation. + */ + r =3D vhost_kernel_call(dev, VHOST_SET_FEATURES_ARRAY, &farray); + if (!r) { + return 0; + } + + if (extended_in_use) { + error_report("Trying to set extended features without kernel suppo= rt"); + return -EINVAL; + } + return vhost_kernel_call(dev, VHOST_SET_FEATURES, &farray.features[0]); +} + +static int vhost_kernel_get_features(struct vhost_dev *dev, uint64_t *feat= ures) +{ + struct vhost_features farray; + int r; + + farray.count =3D VIRTIO_FEATURES_DWORDS; + r =3D vhost_kernel_call(dev, VHOST_GET_FEATURES_ARRAY, &farray); + if (r) { + memset(&farray, 0, sizeof(farray)); + r =3D vhost_kernel_call(dev, VHOST_GET_FEATURES, &farray.features[= 0]); + } + if (r) { + return r; + } + + virtio_features_copy(features, farray.features); + return 0; } =20 static int vhost_kernel_set_owner(struct vhost_dev *dev) @@ -341,8 +381,8 @@ const VhostOps kernel_ops =3D { .vhost_attach_vring_worker =3D vhost_kernel_attach_vring_worker, .vhost_new_worker =3D vhost_kernel_new_worker, .vhost_free_worker =3D vhost_kernel_free_worker, - .vhost_set_features =3D vhost_kernel_set_features, - .vhost_get_features =3D vhost_kernel_get_features, + .vhost_set_features_ex =3D vhost_kernel_set_features, + .vhost_get_features_ex =3D vhost_kernel_get_features, .vhost_set_backend_cap =3D vhost_kernel_set_backend_cap, .vhost_set_owner =3D vhost_kernel_set_owner, .vhost_get_vq_index =3D vhost_kernel_get_vq_index, --=20 2.50.0 From nobody Sat Nov 15 08:50:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752829112; cv=none; d=zohomail.com; s=zohoarc; b=QsJo2P5BvKI6Jusq7NJR0ckT5BKbhTXPBXFdIn1yKYJ0HI42tKkEajGxMKnmDA2Kduj1zBqXA9ptg9PECzdmUFMhKQH1IY01P7o1JHhqj39//d6GrG2Mz+fCIJR1qfXaNcnxph1vvbI2wn4uY7mZO9NU9Wrj9fjcNVzdivmm5WA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752829112; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=R3eaiMgWp97MVuul4ARrtwpieGOua2/uili0FeBNTgA=; b=ggqLZpKAhXiNw1Vymx9AgOdAsDoNb02gJLOWsdpuZ2gBTUjJcYEJRmIjz3S8apTPrpqXQMQekYzoT6xSO3DtgLIXrBKSE4mxUbuH2J+enuMGjP1ApxkqW5D295/ydXpSvXmZphjmiCvwW/vHt3oJbhqwqappilSB4nlYfu2ScZs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752829112540330.5574542614735; Fri, 18 Jul 2025 01:58:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucgrW-0002eA-KC; Fri, 18 Jul 2025 04:54:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgr5-0002Fs-5i for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:54:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgr3-0001Jm-8w for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:54:10 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-171-P4Kh3o9wODGbtt3GGag9uw-1; Fri, 18 Jul 2025 04:54:05 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 599081800294; Fri, 18 Jul 2025 08:54:04 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.19]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EB1C71956089; Fri, 18 Jul 2025 08:53:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752828848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R3eaiMgWp97MVuul4ARrtwpieGOua2/uili0FeBNTgA=; b=FAf6H9iCbH3T/8XFdyLcxkpiYgsOut7LOC0FNIXSiaLDDSwzuRhAMKFauOIfq8h6NJMszD hOFBNx3F0Z5GjnyNNxeTcYvN1FbDSR7kW1qrXjIhqCkYzRIBKNYp+b0KlPEP9tMviEbvga bV2XSHDLrHYfr95J7T2AEzkmr8leQXI= X-MC-Unique: P4Kh3o9wODGbtt3GGag9uw-1 X-Mimecast-MFC-AGG-ID: P4Kh3o9wODGbtt3GGag9uw_1752828844 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC v3 10/13] vhost-net: implement extended features support Date: Fri, 18 Jul 2025 10:52:36 +0200 Message-ID: <083cd54b7ee4909fdedbf5c9128e60563469057e.1752828082.git.pabeni@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752829114032116600 Content-Type: text/plain; charset="utf-8" Provide extended version of the features manipulation helpers, and let the device initialization deal with the full features space, adjusting the relevant format strings accordingly. Signed-off-by: Paolo Abeni --- v2 -> v3: - use virtio_features_andnot return value instead of virtio_features_empty - rebased on top of "net: Consolidate vhost feature bits into vhost_net structure" - _array -> _ex v1 -> v2: - uint128_t -> uint64_t[] - provide extended variant of the features manipulation helpers --- hw/net/vhost_net-stub.c | 8 +++---- hw/net/vhost_net.c | 46 ++++++++++++++++++++++------------------- include/net/vhost_net.h | 33 ++++++++++++++++++++++++++--- 3 files changed, 58 insertions(+), 29 deletions(-) diff --git a/hw/net/vhost_net-stub.c b/hw/net/vhost_net-stub.c index 7d49f82906..0740d5a2eb 100644 --- a/hw/net/vhost_net-stub.c +++ b/hw/net/vhost_net-stub.c @@ -46,9 +46,8 @@ void vhost_net_cleanup(struct vhost_net *net) { } =20 -uint64_t vhost_net_get_features(struct vhost_net *net, uint64_t features) +void vhost_net_get_features_ex(struct vhost_net *net, uint64_t *features) { - return features; } =20 int vhost_net_get_config(struct vhost_net *net, uint8_t *config, @@ -62,13 +61,12 @@ int vhost_net_set_config(struct vhost_net *net, const u= int8_t *data, return 0; } =20 -void vhost_net_ack_features(struct vhost_net *net, uint64_t features) +void vhost_net_ack_features_ex(struct vhost_net *net, const uint64_t *feat= ures) { } =20 -uint64_t vhost_net_get_acked_features(VHostNetState *net) +void vhost_net_get_acked_features_ex(VHostNetState *net, uint64_t *feature= s) { - return 0; } =20 bool vhost_net_virtqueue_pending(VHostNetState *net, int idx) diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c index 540492b37d..33fc6ba2f9 100644 --- a/hw/net/vhost_net.c +++ b/hw/net/vhost_net.c @@ -35,10 +35,9 @@ #include "hw/virtio/virtio-bus.h" #include "linux-headers/linux/vhost.h" =20 -uint64_t vhost_net_get_features(struct vhost_net *net, uint64_t features) +void vhost_net_get_features_ex(struct vhost_net *net, uint64_t *features) { - return vhost_get_features(&net->dev, net->feature_bits, - features); + vhost_get_features_ex(&net->dev, net->feature_bits, features); } int vhost_net_get_config(struct vhost_net *net, uint8_t *config, uint32_t config_len) @@ -51,10 +50,11 @@ int vhost_net_set_config(struct vhost_net *net, const u= int8_t *data, return vhost_dev_set_config(&net->dev, data, offset, size, flags); } =20 -void vhost_net_ack_features(struct vhost_net *net, uint64_t features) +void vhost_net_ack_features_ex(struct vhost_net *net, const uint64_t *feat= ures) { - net->dev.acked_features =3D net->dev.backend_features; - vhost_ack_features(&net->dev, net->feature_bits, features); + virtio_features_copy(net->dev.acked_features_ex, + net->dev.backend_features_ex); + vhost_ack_features_ex(&net->dev, net->feature_bits, features); } =20 uint64_t vhost_net_get_max_queues(VHostNetState *net) @@ -62,9 +62,9 @@ uint64_t vhost_net_get_max_queues(VHostNetState *net) return net->dev.max_queues; } =20 -uint64_t vhost_net_get_acked_features(VHostNetState *net) +void vhost_net_get_acked_features_ex(VHostNetState *net, uint64_t *feature= s) { - return net->dev.acked_features; + virtio_features_copy(features, net->dev.acked_features_ex); } =20 void vhost_net_save_acked_features(NetClientState *nc) @@ -234,7 +234,8 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) int r; bool backend_kernel =3D options->backend_type =3D=3D VHOST_BACKEND_TYP= E_KERNEL; struct vhost_net *net =3D g_new0(struct vhost_net, 1); - uint64_t features =3D 0; + uint64_t missing_features[VIRTIO_FEATURES_DWORDS]; + uint64_t features[VIRTIO_FEATURES_DWORDS]; Error *local_err =3D NULL; =20 if (!options->net_backend) { @@ -261,7 +262,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *optio= ns) net->backend =3D r; net->dev.protocol_features =3D 0; } else { - net->dev.backend_features =3D 0; + virtio_features_clear(net->dev.backend_features_ex); net->dev.protocol_features =3D 0; net->backend =3D -1; =20 @@ -279,28 +280,31 @@ struct vhost_net *vhost_net_init(VhostNetOptions *opt= ions) if (backend_kernel) { if (!qemu_has_vnet_hdr_len(options->net_backend, sizeof(struct virtio_net_hdr_mrg_rxbuf))) { - net->dev.features &=3D ~(1ULL << VIRTIO_NET_F_MRG_RXBUF); + net->dev.features &=3D ~VIRTIO_BIT(VIRTIO_NET_F_MRG_RXBUF); } - if (~net->dev.features & net->dev.backend_features) { - fprintf(stderr, "vhost lacks feature mask 0x%" PRIx64 - " for backend\n", - (uint64_t)(~net->dev.features & net->dev.backend_featur= es)); + + if (virtio_features_andnot(missing_features, + net->dev.backend_features_ex, + net->dev.features_ex)) { + fprintf(stderr, "vhost lacks feature mask 0x" VIRTIO_FEATURES_= FMT + " for backend\n", VIRTIO_FEATURES_PR(missing_features)); goto fail; } } =20 /* Set sane init value. Override when guest acks. */ if (options->get_acked_features) { - features =3D options->get_acked_features(net->nc); - if (~net->dev.features & features) { - fprintf(stderr, "vhost lacks feature mask 0x%" PRIx64 - " for backend\n", - (uint64_t)(~net->dev.features & features)); + virtio_features_from_u64(features, + options->get_acked_features(net->nc)); + if (virtio_features_andnot(missing_features, features, + net->dev.features_ex)) { + fprintf(stderr, "vhost lacks feature mask 0x" VIRTIO_FEATURES_= FMT + " for backend\n", VIRTIO_FEATURES_PR(missing_features)= ); goto fail; } } =20 - vhost_net_ack_features(net, features); + vhost_net_ack_features_ex(net, features); =20 return net; =20 diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h index 879781dad7..1d07b437c7 100644 --- a/include/net/vhost_net.h +++ b/include/net/vhost_net.h @@ -2,6 +2,7 @@ #define VHOST_NET_H =20 #include "net/net.h" +#include "hw/virtio/virtio-features.h" #include "hw/virtio/vhost-backend.h" =20 struct vhost_net; @@ -33,8 +34,26 @@ void vhost_net_stop(VirtIODevice *dev, NetClientState *n= cs, =20 void vhost_net_cleanup(VHostNetState *net); =20 -uint64_t vhost_net_get_features(VHostNetState *net, uint64_t features); -void vhost_net_ack_features(VHostNetState *net, uint64_t features); +void vhost_net_get_features_ex(VHostNetState *net, uint64_t *features); +static inline uint64_t vhost_net_get_features(VHostNetState *net, + uint64_t features) +{ + uint64_t features_array[VIRTIO_FEATURES_DWORDS]; + + virtio_features_from_u64(features_array, features); + vhost_net_get_features_ex(net, features_array); + return features_array[0]; +} + +void vhost_net_ack_features_ex(VHostNetState *net, const uint64_t *feature= s); +static inline void vhost_net_ack_features(VHostNetState *net, + uint64_t features) +{ + uint64_t features_array[VIRTIO_FEATURES_DWORDS]; + + virtio_features_from_u64(features_array, features); + vhost_net_ack_features_ex(net, features_array); +} =20 int vhost_net_get_config(struct vhost_net *net, uint8_t *config, uint32_t config_len); @@ -51,7 +70,15 @@ VHostNetState *get_vhost_net(NetClientState *nc); =20 int vhost_net_set_vring_enable(NetClientState *nc, int enable); =20 -uint64_t vhost_net_get_acked_features(VHostNetState *net); +void vhost_net_get_acked_features_ex(VHostNetState *net, uint64_t *feature= s); +static inline uint64_t vhost_net_get_acked_features(VHostNetState *net) +{ + uint64_t features[VIRTIO_FEATURES_DWORDS]; + + vhost_net_get_acked_features_ex(net, features); + assert(!virtio_features_use_extended(features)); + return features[0]; +} =20 int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu); =20 --=20 2.50.0 From nobody Sat Nov 15 08:50:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752828986; cv=none; d=zohomail.com; s=zohoarc; b=jh62xK7DtubRNcOOzb/Q2c5QYXKlJiAHfndC/5DiqYmOu35rWr7pQi18ps58Dgla1VpTYbC5rQe2UUyricqR93wdUmX+e7DZVmaOg6aJjgccGFmWsLmRcHsWPPwpRWGZlbeu4ZGfbedY2o9I0ZHMadjaXAmgaDJiadQClexLYe8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752828986; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=go9xSvmqIGsKJQjCF+kKzaEwbuM7hT2kUhy3kUd8SwY=; b=BhnaVbPaTt+2vNlJJURou6y/ajL0F76JkgJ8KxKcQzfmxyseb3QFHJkT1087UNVdFXruYvcni+cZFuoGSMmPXHXWqn/w6EZgVMRS0MV9Zy6zo/oLzOnbcVhuuoGA+z0EYLo0tiFlaH43np4cftSJhltyAJ7CMoRL54pHS+UXb/Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752828986657749.2582797434069; Fri, 18 Jul 2025 01:56:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucgrY-0002kT-LG; Fri, 18 Jul 2025 04:54:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgrD-0002KR-M6 for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:54:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgrA-0001LT-UP for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:54:18 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-213-AkWiiDtmMnGq0ZyzzMIanA-1; Fri, 18 Jul 2025 04:54:10 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8A5A61800359; Fri, 18 Jul 2025 08:54:09 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.19]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DABD71956089; Fri, 18 Jul 2025 08:54:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752828856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=go9xSvmqIGsKJQjCF+kKzaEwbuM7hT2kUhy3kUd8SwY=; b=TBSRb3DJuY/6Krv365bHCAbwV2FSMVqTHpJnTGOdCYqr7gXLimgQiMWUoe6DDHb0hV4qR/ yP5Pdx8QrBEwnRGpS75GXrUpf4+m5KLQqQ92v74ZVlKCkDLjLkRm/Y+MGvCL387mgb+Xjb X0EBTkZEDghIYJlu08UzmraDy101lwI= X-MC-Unique: AkWiiDtmMnGq0ZyzzMIanA-1 X-Mimecast-MFC-AGG-ID: AkWiiDtmMnGq0ZyzzMIanA_1752828849 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC v3 11/13] virtio-net: implement extended features support Date: Fri, 18 Jul 2025 10:52:37 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752828989085116600 Content-Type: text/plain; charset="utf-8" Use the extended types and helpers to manipulate the virtio_net features. Note that offloads are still 64bits wide, as per specification, and extended offloads will be mapped into such range. Signed-off-by: Paolo Abeni --- v2 -> v3: - rebased on top of 2deec9ab7d ("virtio-net: Move virtio_net_get_features() down") - _array -> _ex v1 -> v2: - uint128_t -> uint64_t[] - more verbose macro definitions --- hw/net/virtio-net.c | 136 +++++++++++++++++++-------------- include/hw/virtio/virtio-net.h | 2 +- 2 files changed, 80 insertions(+), 58 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 8953c329e7..53413ec4d5 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -90,6 +90,19 @@ VIRTIO_NET_RSS_HASH_TYPE_TCP_EX |= \ VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) =20 +/* + * Features starting from VIRTIO_NET_FEATURES_MAP_MIN bit correspond + * to guest offloads in the VIRTIO_NET_OFFLOAD_MAP range + */ +#define VIRTIO_NET_OFFLOAD_MAP_MIN 46 +#define VIRTIO_NET_OFFLOAD_MAP_LENGTH 4 +#define VIRTIO_NET_OFFLOAD_MAP MAKE_64BIT_MASK( \ + VIRTIO_NET_OFFLOAD_MAP_MIN, \ + VIRTIO_NET_OFFLOAD_MAP_LENGT= H) +#define VIRTIO_NET_FEATURES_MAP_MIN 65 +#define VIRTIO_NET_F2O_SHIFT (VIRTIO_NET_OFFLOAD_MAP_MIN - \ + VIRTIO_NET_FEATURES_MAP_MIN + 64) + static const VirtIOFeature feature_sizes[] =3D { {.flags =3D 1ULL << VIRTIO_NET_F_MAC, .end =3D endof(struct virtio_net_config, mac)}, @@ -786,7 +799,14 @@ static void virtio_net_apply_guest_offloads(VirtIONet = *n) qemu_set_offload(qemu_get_queue(n->nic)->peer, &ol); } =20 -static uint64_t virtio_net_guest_offloads_by_features(uint64_t features) +static uint64_t virtio_net_features_to_offload(const uint64_t *features) +{ + return (features[0] & ~VIRTIO_NET_OFFLOAD_MAP) | + ((features[1] << VIRTIO_NET_F2O_SHIFT) & VIRTIO_NET_OFFLOAD_MAP= ); +} + +static uint64_t +virtio_net_guest_offloads_by_features(const uint64_t *features) { static const uint64_t guest_offloads_mask =3D (1ULL << VIRTIO_NET_F_GUEST_CSUM) | @@ -797,13 +817,13 @@ static uint64_t virtio_net_guest_offloads_by_features= (uint64_t features) (1ULL << VIRTIO_NET_F_GUEST_USO4) | (1ULL << VIRTIO_NET_F_GUEST_USO6); =20 - return guest_offloads_mask & features; + return guest_offloads_mask & virtio_net_features_to_offload(features); } =20 uint64_t virtio_net_supported_guest_offloads(const VirtIONet *n) { VirtIODevice *vdev =3D VIRTIO_DEVICE(n); - return virtio_net_guest_offloads_by_features(vdev->guest_features); + return virtio_net_guest_offloads_by_features(vdev->guest_features_ex); } =20 typedef struct { @@ -882,34 +902,39 @@ static void failover_add_primary(VirtIONet *n, Error = **errp) error_propagate(errp, err); } =20 -static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features) +static void virtio_net_set_features(VirtIODevice *vdev, + const uint64_t *in_features) { + uint64_t features[VIRTIO_FEATURES_DWORDS]; VirtIONet *n =3D VIRTIO_NET(vdev); Error *err =3D NULL; int i; =20 + virtio_features_copy(features, in_features); if (n->mtu_bypass_backend && !virtio_has_feature(vdev->backend_features, VIRTIO_NET_F_MTU))= { - features &=3D ~(1ULL << VIRTIO_NET_F_MTU); + virtio_clear_feature_ex(features, VIRTIO_NET_F_MTU); } =20 virtio_net_set_multiqueue(n, - virtio_has_feature(features, VIRTIO_NET_F_RS= S) || - virtio_has_feature(features, VIRTIO_NET_F_MQ= )); + virtio_has_feature_ex(features, + VIRTIO_NET_F_RSS) || + virtio_has_feature_ex(features, + VIRTIO_NET_F_MQ)); =20 virtio_net_set_mrg_rx_bufs(n, - virtio_has_feature(features, + virtio_has_feature_ex(features, VIRTIO_NET_F_MRG_RXBUF), - virtio_has_feature(features, + virtio_has_feature_ex(features, VIRTIO_F_VERSION_1), - virtio_has_feature(features, + virtio_has_feature_ex(features, VIRTIO_NET_F_HASH_REPORT= )); =20 - n->rsc4_enabled =3D virtio_has_feature(features, VIRTIO_NET_F_RSC_EXT)= && - virtio_has_feature(features, VIRTIO_NET_F_GUEST_TSO4); - n->rsc6_enabled =3D virtio_has_feature(features, VIRTIO_NET_F_RSC_EXT)= && - virtio_has_feature(features, VIRTIO_NET_F_GUEST_TSO6); - n->rss_data.redirect =3D virtio_has_feature(features, VIRTIO_NET_F_RSS= ); + n->rsc4_enabled =3D virtio_has_feature_ex(features, VIRTIO_NET_F_RSC_E= XT) && + virtio_has_feature_ex(features, VIRTIO_NET_F_GUEST_TSO4); + n->rsc6_enabled =3D virtio_has_feature_ex(features, VIRTIO_NET_F_RSC_E= XT) && + virtio_has_feature_ex(features, VIRTIO_NET_F_GUEST_TSO6); + n->rss_data.redirect =3D virtio_has_feature_ex(features, VIRTIO_NET_F_= RSS); =20 if (n->has_vnet_hdr) { n->curr_guest_offloads =3D @@ -923,7 +948,7 @@ static void virtio_net_set_features(VirtIODevice *vdev,= uint64_t features) if (!get_vhost_net(nc->peer)) { continue; } - vhost_net_ack_features(get_vhost_net(nc->peer), features); + vhost_net_ack_features_ex(get_vhost_net(nc->peer), features); =20 /* * keep acked_features in NetVhostUserState up-to-date so it @@ -932,11 +957,11 @@ static void virtio_net_set_features(VirtIODevice *vde= v, uint64_t features) vhost_net_save_acked_features(nc->peer); } =20 - if (!virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN)) { + if (!virtio_has_feature_ex(features, VIRTIO_NET_F_CTRL_VLAN)) { memset(n->vlans, 0xff, MAX_VLAN >> 3); } =20 - if (virtio_has_feature(features, VIRTIO_NET_F_STANDBY)) { + if (virtio_has_feature_ex(features, VIRTIO_NET_F_STANDBY)) { qapi_event_send_failover_negotiated(n->netclient_name); qatomic_set(&n->failover_primary_hidden, false); failover_add_primary(n, &err); @@ -1901,10 +1926,10 @@ static ssize_t virtio_net_receive_rcu(NetClientStat= e *nc, const uint8_t *buf, virtio_error(vdev, "virtio-net unexpected empty queue: " "i %zd mergeable %d offset %zd, size %zd, " "guest hdr len %zd, host hdr len %zd " - "guest features 0x%" PRIx64, + "guest features 0x" VIRTIO_FEATURES_FMT, i, n->mergeable_rx_bufs, offset, size, n->guest_hdr_len, n->host_hdr_len, - vdev->guest_features); + VIRTIO_FEATURES_PR(vdev->guest_features_ex)); } err =3D -1; goto err; @@ -3011,8 +3036,8 @@ static int virtio_net_pre_load_queues(VirtIODevice *v= dev, uint32_t n) return 0; } =20 -static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t featu= res, - Error **errp) +static void virtio_net_get_features(VirtIODevice *vdev, uint64_t *features, + Error **errp) { VirtIONet *n =3D VIRTIO_NET(vdev); NetClientState *nc =3D qemu_get_queue(n->nic); @@ -3026,68 +3051,67 @@ static uint64_t virtio_net_get_features(VirtIODevic= e *vdev, uint64_t features, (supported_hash_types & peer_hash_types) =3D=3D supported_hash_typ= es; =20 /* Firstly sync all virtio-net possible supported features */ - features |=3D n->host_features; + virtio_features_or(features, features, n->host_features_ex); =20 - virtio_add_feature(&features, VIRTIO_NET_F_MAC); + virtio_add_feature_ex(features, VIRTIO_NET_F_MAC); =20 if (!peer_has_vnet_hdr(n)) { - virtio_clear_feature(&features, VIRTIO_NET_F_CSUM); - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_TSO4); - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_TSO6); - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_ECN); + virtio_clear_feature_ex(features, VIRTIO_NET_F_CSUM); + virtio_clear_feature_ex(features, VIRTIO_NET_F_HOST_TSO4); + virtio_clear_feature_ex(features, VIRTIO_NET_F_HOST_TSO6); + virtio_clear_feature_ex(features, VIRTIO_NET_F_HOST_ECN); =20 - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_CSUM); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO4); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO6); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ECN); + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_CSUM); + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_TSO4); + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_TSO6); + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_ECN); =20 - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_USO); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO4); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO6); + virtio_clear_feature_ex(features, VIRTIO_NET_F_HOST_USO); + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_USO4); + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_USO6); =20 - virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT); + virtio_clear_feature_ex(features, VIRTIO_NET_F_HASH_REPORT); } =20 if (!peer_has_vnet_hdr(n) || !peer_has_ufo(n)) { - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_UFO); - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_UFO); + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_UFO); + virtio_clear_feature_ex(features, VIRTIO_NET_F_HOST_UFO); } - if (!peer_has_uso(n)) { - virtio_clear_feature(&features, VIRTIO_NET_F_HOST_USO); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO4); - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO6); + virtio_clear_feature_ex(features, VIRTIO_NET_F_HOST_USO); + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_USO4); + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_USO6); } =20 if (!get_vhost_net(nc->peer)) { if (!use_own_hash) { - virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT); - virtio_clear_feature(&features, VIRTIO_NET_F_RSS); - } else if (virtio_has_feature(features, VIRTIO_NET_F_RSS)) { + virtio_clear_feature_ex(features, VIRTIO_NET_F_HASH_REPORT); + virtio_clear_feature_ex(features, VIRTIO_NET_F_RSS); + } else if (virtio_has_feature_ex(features, VIRTIO_NET_F_RSS)) { virtio_net_load_ebpf(n, errp); } =20 - return features; + return; } =20 if (!use_peer_hash) { - virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT); + virtio_clear_feature_ex(features, VIRTIO_NET_F_HASH_REPORT); =20 if (!use_own_hash || !virtio_net_attach_ebpf_to_backend(n->nic, -1= )) { if (!virtio_net_load_ebpf(n, errp)) { - return features; + return; } =20 - virtio_clear_feature(&features, VIRTIO_NET_F_RSS); + virtio_clear_feature_ex(features, VIRTIO_NET_F_RSS); } } =20 - features =3D vhost_net_get_features(get_vhost_net(nc->peer), features); - vdev->backend_features =3D features; + vhost_net_get_features_ex(get_vhost_net(nc->peer), features); + virtio_features_copy(vdev->backend_features_ex, features); =20 if (n->mtu_bypass_backend && (n->host_features & 1ULL << VIRTIO_NET_F_MTU)) { - features |=3D (1ULL << VIRTIO_NET_F_MTU); + virtio_add_feature_ex(features, VIRTIO_NET_F_MTU); } =20 /* @@ -3102,10 +3126,8 @@ static uint64_t virtio_net_get_features(VirtIODevice= *vdev, uint64_t features, * support it. */ if (!virtio_has_feature(vdev->backend_features, VIRTIO_NET_F_CTRL_VQ))= { - virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ANNOUNCE); + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_ANNOUNCE); } - - return features; } =20 static int virtio_net_post_load_device(void *opaque, int version_id) @@ -4237,8 +4259,8 @@ static void virtio_net_class_init(ObjectClass *klass,= const void *data) vdc->unrealize =3D virtio_net_device_unrealize; vdc->get_config =3D virtio_net_get_config; vdc->set_config =3D virtio_net_set_config; - vdc->get_features =3D virtio_net_get_features; - vdc->set_features =3D virtio_net_set_features; + vdc->get_features_ex =3D virtio_net_get_features; + vdc->set_features_ex =3D virtio_net_set_features; vdc->bad_features =3D virtio_net_bad_features; vdc->reset =3D virtio_net_reset; vdc->queue_reset =3D virtio_net_queue_reset; diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 73fdefc0dc..5b8ab7bda7 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -182,7 +182,7 @@ struct VirtIONet { uint32_t has_vnet_hdr; size_t host_hdr_len; size_t guest_hdr_len; - uint64_t host_features; + VIRTIO_DECLARE_FEATURES(host_features); uint32_t rsc_timeout; uint8_t rsc4_enabled; uint8_t rsc6_enabled; --=20 2.50.0 From nobody Sat Nov 15 08:50:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752828907; cv=none; d=zohomail.com; s=zohoarc; b=PXk0fgnxdYho61PLhYyKWAcSm2Cn4o0VWA3oGH8cky8HhQpXR60I4XZuT1Udb4vghsxji5bEVi2smvv9GUodZKpVYwjINvZ6IWw1DxgPC1Gvtu21xIcaBtZjY2rF8hvNn0uyc+lyYnI3UwUdVn6R70BfZGiWci3cbdXUdH8LxO0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752828907; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VuRL3zkjfJxUauldVrc9E+mvnSBJKMYujVm2SAMFVJo=; b=Hs6uOL0B/y1TONUWsDZwXxhX8O9tBOEFZN/Y0nJMu+SZ446SLuTMWTAbqYfDhMnjSG9enb16r7sNyJXyTcC2ld2cKeLntsYyZ8WjOFZPx7TE9x/JPU5/Si9W2XaYb8ggnanzJdN7imRacnmFtXtD8k1Uw+q+JV7tnhs+jvuCbA4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 175282890776230.885289349255572; Fri, 18 Jul 2025 01:55:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucgre-0003Df-HT; Fri, 18 Jul 2025 04:54:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgrJ-0002Uj-A6 for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:54:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgrG-0001N1-L9 for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:54:25 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-47-WfsJbV7BP-GOmGpPdvbTqA-1; Fri, 18 Jul 2025 04:54:18 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7360E1800D96; Fri, 18 Jul 2025 08:54:14 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.19]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 194641956089; Fri, 18 Jul 2025 08:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752828861; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VuRL3zkjfJxUauldVrc9E+mvnSBJKMYujVm2SAMFVJo=; b=OmkhiLU/P3hioq2BHuUiA4+onOAelqlax+mnEkZtEIawF8N9/A4vtXNkvkFxZ5mFskMb89 FsCsZ33f7uNreNAeF1aiQUlSJA+4+04HzlVDUnV3rCinU/G8LiSdaEDlT9M5GPis3G5AB9 9LZFABgqfICAKwhBRObfDRjHfOyb8pc= X-MC-Unique: WfsJbV7BP-GOmGpPdvbTqA-1 X-Mimecast-MFC-AGG-ID: WfsJbV7BP-GOmGpPdvbTqA_1752828854 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC v3 12/13] net: implement tunnel probing Date: Fri, 18 Jul 2025 10:52:38 +0200 Message-ID: <6ec36a1cc2497f827b9e024acc6adb2515dd9335.1752828082.git.pabeni@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752828910320116600 Content-Type: text/plain; charset="utf-8" Tap devices support GSO over UDP tunnel offload. Probe for such feature in a similar manner to other offloads. GSO over UDP tunnel needs to be enabled in addition to a "plain" offload (TSO or USO). No need to check separately for the outer header checksum offload: the kernel is going to support both of them or none. Signed-off-by: Paolo Abeni --- v2 -> v3: - use bool type for tap_probe_has_tunnel() - rebased on top of 2deec9ab7d ("virtio-net: Move virtio_net_get_features() down") - _array -> _ex v1 -> v2: - peer_has_tunnel return a bool - move TUN_F definition in net/tun-linux.h --- hw/net/virtio-net.c | 37 +++++++++++++++++++++++++++++++++++++ include/net/net.h | 3 +++ net/net.c | 9 +++++++++ net/tap-bsd.c | 5 +++++ net/tap-linux.c | 11 +++++++++++ net/tap-linux.h | 9 +++++++++ net/tap-solaris.c | 5 +++++ net/tap-stub.c | 5 +++++ net/tap.c | 11 +++++++++++ net/tap_int.h | 1 + 10 files changed, 96 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 53413ec4d5..70c85f7f77 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -649,6 +649,15 @@ static int peer_has_uso(VirtIONet *n) return qemu_has_uso(qemu_get_queue(n->nic)->peer); } =20 +static bool peer_has_tunnel(VirtIONet *n) +{ + if (!peer_has_vnet_hdr(n)) { + return false; + } + + return qemu_has_tunnel(qemu_get_queue(n->nic)->peer); +} + static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs, int version_1, int hash_report) { @@ -3070,6 +3079,13 @@ static void virtio_net_get_features(VirtIODevice *vd= ev, uint64_t *features, virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_USO4); virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_USO6); =20 + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GS= O); + virtio_clear_feature_ex(features, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO= ); + virtio_clear_feature_ex(features, + VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_CSUM); + virtio_clear_feature_ex(features, + VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO_CSUM); + virtio_clear_feature_ex(features, VIRTIO_NET_F_HASH_REPORT); } =20 @@ -3083,6 +3099,15 @@ static void virtio_net_get_features(VirtIODevice *vd= ev, uint64_t *features, virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_USO6); } =20 + if (!peer_has_tunnel(n)) { + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GS= O); + virtio_clear_feature_ex(features, VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO= ); + virtio_clear_feature_ex(features, + VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_CSUM); + virtio_clear_feature_ex(features, + VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO_CSUM); + } + if (!get_vhost_net(nc->peer)) { if (!use_own_hash) { virtio_clear_feature_ex(features, VIRTIO_NET_F_HASH_REPORT); @@ -4137,6 +4162,10 @@ static const VMStateDescription vmstate_virtio_net = =3D { .dev_unplug_pending =3D dev_unplug_pending, }; =20 +#define DEFINE_PROP_FEATURE(_name, _state, _field, _bit, _defval) \ + DEFINE_PROP_BIT64(_name, _state, _field[VIRTIO_DWORD(_bit)], \ + (_bit) % 64, _defval) + static const Property virtio_net_properties[] =3D { DEFINE_PROP_BIT64("csum", VirtIONet, host_features, VIRTIO_NET_F_CSUM, true), @@ -4245,6 +4274,14 @@ static const Property virtio_net_properties[] =3D { rss_data.specified_hash_types, VIRTIO_NET_HASH_REPORT_UDPv6_EX - 1, ON_OFF_AUTO_AUTO), + DEFINE_PROP_FEATURE("host_tunnel", VirtIONet, host_features_ex, + VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO, true), + DEFINE_PROP_FEATURE("host_tunnel_csum", VirtIONet, host_features_ex, + VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO_CSUM, true), + DEFINE_PROP_FEATURE("guest_tunnel", VirtIONet, host_features_ex, + VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO, true), + DEFINE_PROP_FEATURE("guest_tunnel_csum", VirtIONet, host_features_ex, + VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_CSUM, true), }; =20 static void virtio_net_class_init(ObjectClass *klass, const void *data) diff --git a/include/net/net.h b/include/net/net.h index 48ba333d02..9a9084690d 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -65,6 +65,7 @@ typedef void (NetClientDestructor)(NetClientState *); typedef RxFilterInfo *(QueryRxFilter)(NetClientState *); typedef bool (HasUfo)(NetClientState *); typedef bool (HasUso)(NetClientState *); +typedef bool (HasTunnel)(NetClientState *); typedef bool (HasVnetHdr)(NetClientState *); typedef bool (HasVnetHdrLen)(NetClientState *, int); typedef void (SetOffload)(NetClientState *, const NetOffloads *); @@ -95,6 +96,7 @@ typedef struct NetClientInfo { NetPoll *poll; HasUfo *has_ufo; HasUso *has_uso; + HasTunnel *has_tunnel; HasVnetHdr *has_vnet_hdr; HasVnetHdrLen *has_vnet_hdr_len; SetOffload *set_offload; @@ -197,6 +199,7 @@ void qemu_set_info_str(NetClientState *nc, void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]); bool qemu_has_ufo(NetClientState *nc); bool qemu_has_uso(NetClientState *nc); +bool qemu_has_tunnel(NetClientState *nc); bool qemu_has_vnet_hdr(NetClientState *nc); bool qemu_has_vnet_hdr_len(NetClientState *nc, int len); void qemu_set_offload(NetClientState *nc, const NetOffloads *ol); diff --git a/net/net.c b/net/net.c index 63872b6855..9536184a0c 100644 --- a/net/net.c +++ b/net/net.c @@ -522,6 +522,15 @@ bool qemu_has_uso(NetClientState *nc) return nc->info->has_uso(nc); } =20 +bool qemu_has_tunnel(NetClientState *nc) +{ + if (!nc || !nc->info->has_tunnel) { + return false; + } + + return nc->info->has_tunnel(nc); +} + bool qemu_has_vnet_hdr(NetClientState *nc) { if (!nc || !nc->info->has_vnet_hdr) { diff --git a/net/tap-bsd.c b/net/tap-bsd.c index 86b6edee94..751d4c819c 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -217,6 +217,11 @@ int tap_probe_has_uso(int fd) return 0; } =20 +bool tap_probe_has_tunnel(int fd) +{ + return false; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap-linux.c b/net/tap-linux.c index a1c58f74f5..e2628be798 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -196,6 +196,17 @@ int tap_probe_has_uso(int fd) return 1; } =20 +bool tap_probe_has_tunnel(int fd) +{ + unsigned offload; + + offload =3D TUN_F_CSUM | TUN_F_TSO4 | TUN_F_UDP_TUNNEL_GSO; + if (ioctl(fd, TUNSETOFFLOAD, offload) < 0) { + return false; + } + return true; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { if (ioctl(fd, TUNSETVNETHDRSZ, &len) =3D=3D -1) { diff --git a/net/tap-linux.h b/net/tap-linux.h index 9a58cecb7f..8cd6b5874b 100644 --- a/net/tap-linux.h +++ b/net/tap-linux.h @@ -53,4 +53,13 @@ #define TUN_F_USO4 0x20 /* I can handle USO for IPv4 packets */ #define TUN_F_USO6 0x40 /* I can handle USO for IPv6 packets */ =20 +/* I can handle TSO/USO for UDP tunneled packets */ +#define TUN_F_UDP_TUNNEL_GSO 0x080 + +/* + * I can handle TSO/USO for UDP tunneled packets requiring csum offload for + * the outer header + */ +#define TUN_F_UDP_TUNNEL_GSO_CSUM 0x100 + #endif /* QEMU_TAP_LINUX_H */ diff --git a/net/tap-solaris.c b/net/tap-solaris.c index 833c066bee..ac1ae25761 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -222,6 +222,11 @@ int tap_probe_has_uso(int fd) return 0; } =20 +bool tap_probe_has_tunnel(int fd) +{ + return false; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap-stub.c b/net/tap-stub.c index 67d14ad4d5..f7a5e0c163 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -52,6 +52,11 @@ int tap_probe_has_uso(int fd) return 0; } =20 +bool tap_probe_has_tunnel(int fd) +{ + return false; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap.c b/net/tap.c index b49db19f83..23c6c118e7 100644 --- a/net/tap.c +++ b/net/tap.c @@ -76,6 +76,7 @@ typedef struct TAPState { bool using_vnet_hdr; bool has_ufo; bool has_uso; + bool has_tunnel; bool enabled; VHostNetState *vhost_net; unsigned host_vnet_hdr_len; @@ -241,6 +242,14 @@ static bool tap_has_uso(NetClientState *nc) return s->has_uso; } =20 +static bool tap_has_tunnel(NetClientState *nc) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); + return s->has_tunnel; +} + static bool tap_has_vnet_hdr(NetClientState *nc) { TAPState *s =3D DO_UPCAST(TAPState, nc, nc); @@ -369,6 +378,7 @@ static NetClientInfo net_tap_info =3D { .cleanup =3D tap_cleanup, .has_ufo =3D tap_has_ufo, .has_uso =3D tap_has_uso, + .has_tunnel =3D tap_has_tunnel, .has_vnet_hdr =3D tap_has_vnet_hdr, .has_vnet_hdr_len =3D tap_has_vnet_hdr_len, .set_offload =3D tap_set_offload, @@ -398,6 +408,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer, s->using_vnet_hdr =3D false; s->has_ufo =3D tap_probe_has_ufo(s->fd); s->has_uso =3D tap_probe_has_uso(s->fd); + s->has_tunnel =3D tap_probe_has_tunnel(s->fd); s->enabled =3D true; tap_set_offload(&s->nc, &ol); /* diff --git a/net/tap_int.h b/net/tap_int.h index f8bbe1cb0c..b76a05044b 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -38,6 +38,7 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, = Error **errp); int tap_probe_vnet_hdr(int fd, Error **errp); int tap_probe_has_ufo(int fd); int tap_probe_has_uso(int fd); +bool tap_probe_has_tunnel(int fd); void tap_fd_set_offload(int fd, const NetOffloads *ol); void tap_fd_set_vnet_hdr_len(int fd, int len); int tap_fd_set_vnet_le(int fd, int vnet_is_le); --=20 2.50.0 From nobody Sat Nov 15 08:50:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1752828945; cv=none; d=zohomail.com; s=zohoarc; b=Cnxb+vSjghO9YugL/NWcY3IeNej/rNP8ARDPTiWjgtjLo7wjY1sSlTVlgqERsG639n6cekIeOH5vFfgrV3lMYe/tkM2DI4S0I04zM3CYrO+u5NnuXADpRCgig3komyIDkiuewQzm0iR6shl7nJD6JHpG1e+m0y5ZclVB3zpNU5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752828945; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uDFfJlXSLMn2grR9IUzgoui/UM6IjIPhYxegsMcWe5g=; b=FvCnk2c3nrUS9HUCU6gQAfy5DB3Q7MSvlqNNDXA9ggQR4Zg4Rqx0Jqi1vr72qoRnVjIa9+q80QGpKkCqj7aN3GP/fTTx2UTRL/8LE94VIPooVh54821inFk+NUuXFVG+V49qIIiLul3vO8ZDYCDZcy8DvHxJZ292QUfMziZp3RQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752828945684900.9647636349163; Fri, 18 Jul 2025 01:55:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucgra-0002vX-CY; Fri, 18 Jul 2025 04:54:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgrP-0002XU-6j for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:54:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucgrN-0001Oo-2U for qemu-devel@nongnu.org; Fri, 18 Jul 2025 04:54:30 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-9ioSlwHFO0mk54XB12nijQ-1; Fri, 18 Jul 2025 04:54:23 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 46AC01978C8B; Fri, 18 Jul 2025 08:54:20 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.33.19]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 022E419560A1; Fri, 18 Jul 2025 08:54:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752828868; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uDFfJlXSLMn2grR9IUzgoui/UM6IjIPhYxegsMcWe5g=; b=AuUgoIWYfqJtFdXqBqeqz/UeYR0/9CEbO+QVdtDkURA8N0VBNQJzlhldEmsPW4adc7sDYp 9aVhyrF10SkmXdEbAc2B/W8wT2Dk8oCn7jgVawHmQJj3AvDqC84e0Qb+4jbsSO9UWbLsZ1 y6dj6B9iFD50EKYWnmeVfCG1SlvQmmM= X-MC-Unique: 9ioSlwHFO0mk54XB12nijQ-1 X-Mimecast-MFC-AGG-ID: 9ioSlwHFO0mk54XB12nijQ_1752828862 From: Paolo Abeni To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Dmitry Fleytman , Akihiko Odaki , Jason Wang , Sriram Yagnaraman , "Michael S. Tsirkin" , Stefano Garzarella , Cornelia Huck , Luigi Rizzo , Giuseppe Lettieri , Vincenzo Maffione , Eric Blake , Markus Armbruster Subject: [PATCH RFC v3 13/13] net: implement UDP tunnel features offloading Date: Fri, 18 Jul 2025 10:52:39 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pabeni@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1752828946604116600 Content-Type: text/plain; charset="utf-8" When any host or guest GSO over UDP tunnel offload is enabled the virtio net header includes the additional tunnel-related fields, update the size accordingly. Push the GSO over UDP tunnel offloads all the way down to the tap device extending the newly introduced NetFeatures struct, and eventually enable the associated features. As per virtio specification, to convert features bit to offload bit, map the extended features into the reserved range. Finally, make the vhost backend aware of the exact header layout, to copy it correctly. The tunnel-related field are present if either the guest or the host negotiated any UDP tunnel related feature: add them to the kernel supported features list, to allow qemu transfer to the backend the needed information. Signed-off-by: Paolo Abeni --- v2 -> v3: - rebased on top of "net: Consolidate vhost feature bits into vhost_net structure" - _array -> _ex v1 -> v2: - squashed vhost support into this patch - dropped tun offload consistency checks; they are implemented in the kernel side - virtio_has_tnl_hdr ->virtio_has_tunnel_hdr --- hw/net/virtio-net.c | 34 ++++++++++++++++++++++++++-------- include/net/net.h | 2 ++ net/net.c | 3 ++- net/tap-linux.c | 6 ++++++ net/tap.c | 2 ++ 5 files changed, 38 insertions(+), 9 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 70c85f7f77..46f7efac7d 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -103,6 +103,12 @@ #define VIRTIO_NET_F2O_SHIFT (VIRTIO_NET_OFFLOAD_MAP_MIN - \ VIRTIO_NET_FEATURES_MAP_MIN + 64) =20 +static bool virtio_has_tunnel_hdr(const uint64_t *features) +{ + return virtio_has_feature_ex(features, VIRTIO_NET_F_GUEST_UDP_TUNNEL_G= SO) | + virtio_has_feature_ex(features, VIRTIO_NET_F_HOST_UDP_TUNNEL_GS= O); +} + static const VirtIOFeature feature_sizes[] =3D { {.flags =3D 1ULL << VIRTIO_NET_F_MAC, .end =3D endof(struct virtio_net_config, mac)}, @@ -659,7 +665,8 @@ static bool peer_has_tunnel(VirtIONet *n) } =20 static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs, - int version_1, int hash_report) + int version_1, int hash_report, + int tunnel) { int i; NetClientState *nc; @@ -667,9 +674,11 @@ static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, i= nt mergeable_rx_bufs, n->mergeable_rx_bufs =3D mergeable_rx_bufs; =20 if (version_1) { - n->guest_hdr_len =3D hash_report ? - sizeof(struct virtio_net_hdr_v1_hash) : - sizeof(struct virtio_net_hdr_mrg_rxbuf); + n->guest_hdr_len =3D tunnel ? + sizeof(struct virtio_net_hdr_v1_hash_tunnel) : + (hash_report ? + sizeof(struct virtio_net_hdr_v1_hash) : + sizeof(struct virtio_net_hdr_mrg_rxbuf)); n->rss_data.populate_hash =3D !!hash_report; } else { n->guest_hdr_len =3D n->mergeable_rx_bufs ? @@ -803,6 +812,10 @@ static void virtio_net_apply_guest_offloads(VirtIONet = *n) .ufo =3D !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_U= FO)), .uso4 =3D !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_U= SO4)), .uso6 =3D !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_U= SO6)), + .tnl =3D !!(n->curr_guest_offloads & + (1ULL << VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_MAPPED)), + .tnl_csum =3D !!(n->curr_guest_offloads & + (1ULL << VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_CSUM_MAPP= ED)), }; =20 qemu_set_offload(qemu_get_queue(n->nic)->peer, &ol); @@ -824,7 +837,9 @@ virtio_net_guest_offloads_by_features(const uint64_t *f= eatures) (1ULL << VIRTIO_NET_F_GUEST_ECN) | (1ULL << VIRTIO_NET_F_GUEST_UFO) | (1ULL << VIRTIO_NET_F_GUEST_USO4) | - (1ULL << VIRTIO_NET_F_GUEST_USO6); + (1ULL << VIRTIO_NET_F_GUEST_USO6) | + (1ULL << VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_MAPPED) | + (1ULL << VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_CSUM_MAPPED); =20 return guest_offloads_mask & virtio_net_features_to_offload(features); } @@ -937,7 +952,8 @@ static void virtio_net_set_features(VirtIODevice *vdev, virtio_has_feature_ex(features, VIRTIO_F_VERSION_1), virtio_has_feature_ex(features, - VIRTIO_NET_F_HASH_REPORT= )); + VIRTIO_NET_F_HASH_REPORT= ), + virtio_has_tunnel_hdr(features)); =20 n->rsc4_enabled =3D virtio_has_feature_ex(features, VIRTIO_NET_F_RSC_E= XT) && virtio_has_feature_ex(features, VIRTIO_NET_F_GUEST_TSO4); @@ -3160,13 +3176,15 @@ static int virtio_net_post_load_device(void *opaque= , int version_id) VirtIONet *n =3D opaque; VirtIODevice *vdev =3D VIRTIO_DEVICE(n); int i, link_down; + bool has_tunnel_hdr =3D virtio_has_tunnel_hdr(vdev->guest_features_ex); =20 trace_virtio_net_post_load_device(); virtio_net_set_mrg_rx_bufs(n, n->mergeable_rx_bufs, virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1), virtio_vdev_has_feature(vdev, - VIRTIO_NET_F_HASH_R= EPORT)); + VIRTIO_NET_F_HASH_RE= PORT), + has_tunnel_hdr); =20 /* MAC_TABLE_ENTRIES may be different from the saved image */ if (n->mac_table.in_use > MAC_TABLE_ENTRIES) { @@ -3986,7 +4004,7 @@ static void virtio_net_device_realize(DeviceState *de= v, Error **errp) =20 n->vqs[0].tx_waiting =3D 0; n->tx_burst =3D n->net_conf.txburst; - virtio_net_set_mrg_rx_bufs(n, 0, 0, 0); + virtio_net_set_mrg_rx_bufs(n, 0, 0, 0, 0); n->promisc =3D 1; /* for compatibility */ =20 n->mac_table.macs =3D g_malloc0(MAC_TABLE_ENTRIES * ETH_ALEN); diff --git a/include/net/net.h b/include/net/net.h index 9a9084690d..72b476ee1d 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -43,6 +43,8 @@ typedef struct NetOffloads { bool ufo; bool uso4; bool uso6; + bool tnl; + bool tnl_csum; } NetOffloads; =20 #define DEFINE_NIC_PROPERTIES(_state, _conf) \ diff --git a/net/net.c b/net/net.c index 9536184a0c..27e0d27807 100644 --- a/net/net.c +++ b/net/net.c @@ -575,7 +575,8 @@ void qemu_set_vnet_hdr_len(NetClientState *nc, int len) =20 assert(len =3D=3D sizeof(struct virtio_net_hdr_mrg_rxbuf) || len =3D=3D sizeof(struct virtio_net_hdr) || - len =3D=3D sizeof(struct virtio_net_hdr_v1_hash)); + len =3D=3D sizeof(struct virtio_net_hdr_v1_hash) || + len =3D=3D sizeof(struct virtio_net_hdr_v1_hash_tunnel)); =20 nc->vnet_hdr_len =3D len; nc->info->set_vnet_hdr_len(nc, len); diff --git a/net/tap-linux.c b/net/tap-linux.c index e2628be798..8e275d2ea4 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -279,6 +279,12 @@ void tap_fd_set_offload(int fd, const NetOffloads *ol) if (ol->uso6) { offload |=3D TUN_F_USO6; } + if (ol->tnl) { + offload |=3D TUN_F_UDP_TUNNEL_GSO; + } + if (ol->tnl_csum) { + offload |=3D TUN_F_UDP_TUNNEL_GSO_CSUM; + } } =20 if (ioctl(fd, TUNSETOFFLOAD, offload) !=3D 0) { diff --git a/net/tap.c b/net/tap.c index 23c6c118e7..2dfa843547 100644 --- a/net/tap.c +++ b/net/tap.c @@ -62,6 +62,8 @@ static const int kernel_feature_bits[] =3D { VIRTIO_F_NOTIFICATION_DATA, VIRTIO_NET_F_RSC_EXT, VIRTIO_NET_F_HASH_REPORT, + VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO, + VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO, VHOST_INVALID_FEATURE_BIT }; =20 --=20 2.50.0