From nobody Sun Sep 28 16:37:06 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=1758550889; cv=none; d=zohomail.com; s=zohoarc; b=UWnUdCUsdB01MEyZxL/G2nbs3U4tEPiTDRb0nLB+oueOttsDyAQR3PCbMx5Yqn+1rl1KOrKuwUndnOCKlMakwT6QzS/uPWVaYsv+jr3zI+7s7fslAgd7z09PC+XJgP5GCF6qM4m96VQrak6hIawdTOGU0uUg2XtsbiQKD7+7j6A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1758550889; 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=BwmP1MeHIp8o/0bq6seYjSmdNO07QedGk+Ji7LjgTiE=; b=HV3Fuu60sRdTA7BUUuA4qXPtb7JPrIiaNwzqp4fRtyvs/6ySLkqafi9UX/OdXVTV6mRYyhr8GK1hXIZDTnYGAn4DUxv2kvMUx1L0uWrXV71AZdjmYGPceY07L7lzTPcgliKG9HylLp/OiNPN6WWDuXqriwuu2tSFHjyU4ufna0E= 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 1758550889155407.33094360961; Mon, 22 Sep 2025 07:21:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v0hP9-00074O-NE; Mon, 22 Sep 2025 10:20:35 -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 1v0hP5-00072d-Qc for qemu-devel@nongnu.org; Mon, 22 Sep 2025 10:20:32 -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 1v0hP0-00076x-7O for qemu-devel@nongnu.org; Mon, 22 Sep 2025 10:20:31 -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-287-vcHATCYbMoqDWoRH2U4Viw-1; Mon, 22 Sep 2025 10:20:21 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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 A10F018002CF; Mon, 22 Sep 2025 14:20:18 +0000 (UTC) Received: from gerbillo.redhat.com (unknown [10.44.32.247]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 06EFE1956048; Mon, 22 Sep 2025 14:20:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1758550824; 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=BwmP1MeHIp8o/0bq6seYjSmdNO07QedGk+Ji7LjgTiE=; b=hLqxM0+/laknsVQRveewvmb3xJpiCmDhv1IjUrT3ZGAXNGlzy0fvX9PEBO4Cfj+1RQGkIg 8aShWBYX0qs9v/XdNAFA1xUDmhQ4TC0PQ0BMHxQu42KHfgPZMD++GzrmnaXfUrG+frUPok TzCAfz1ySHWlptxPbVKCk05H+Fmd0ZY= X-MC-Unique: vcHATCYbMoqDWoRH2U4Viw-1 X-Mimecast-MFC-AGG-ID: vcHATCYbMoqDWoRH2U4Viw_1758550818 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 v7 13/14] net: implement tunnel probing Date: Mon, 22 Sep 2025 16:18:27 +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.12 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: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.442, 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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: 1758550891288116600 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. The new features are disabled by default to avoid compat issues, and could be enabled, after that hw_compat_10_1 will be added, together with the related compat entries. Reviewed-by: Akihiko Odaki Acked-by: Jason Wang Signed-off-by: Paolo Abeni -- v6 -> v7: - fixed commit message typo v4 -> v5: - disable features by default - DEFINE_PROP_FEATURE -> VIRTIO_DEFINE_PROP_FEATURE - reformatted props definitions v3 -> v4: - move DEFINE_PROP_FEATURE() in patch 4 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 | 41 +++++++++++++++++++++++++++++++++++++++++ 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, 100 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 89cf008401..0abb8c8a62 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) { @@ -3073,6 +3082,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 @@ -3086,6 +3102,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); @@ -4248,6 +4273,22 @@ static const Property virtio_net_properties[] =3D { rss_data.specified_hash_types, VIRTIO_NET_HASH_REPORT_UDPv6_EX - 1, ON_OFF_AUTO_AUTO), + VIRTIO_DEFINE_PROP_FEATURE("host_tunnel", VirtIONet, + host_features_ex, + VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO, + false), + VIRTIO_DEFINE_PROP_FEATURE("host_tunnel_csum", VirtIONet, + host_features_ex, + VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO_CSUM, + false), + VIRTIO_DEFINE_PROP_FEATURE("guest_tunnel", VirtIONet, + host_features_ex, + VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO, + false), + VIRTIO_DEFINE_PROP_FEATURE("guest_tunnel_csum", VirtIONet, + host_features_ex, + VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_CSUM, + false), }; =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 38eb28cb58..bbf84d1828 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -225,6 +225,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 79a9dd0da0..98b0ae9602 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -201,6 +201,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 ef8e0feeb0..75397e6c54 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -227,6 +227,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 df23283744..5124372316 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; @@ -246,6 +247,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); @@ -374,6 +383,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, @@ -403,6 +413,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.51.0