On Fri, Jul 18, 2025 at 4:54 PM Paolo Abeni <pab...@redhat.com> wrote: > > 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 <pab...@redhat.com> > --- > 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); > } > > +static bool peer_has_tunnel(VirtIONet *n)
Nit: it looks better to use peer_has_udp_gso_tunnel(). > +{ > + 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 > *vdev, uint64_t *features, > virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_USO4); > virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_USO6); > > + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO); > + 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); > } > > @@ -3083,6 +3099,15 @@ static void virtio_net_get_features(VirtIODevice > *vdev, uint64_t *features, > virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_USO6); > } > > + if (!peer_has_tunnel(n)) { > + virtio_clear_feature_ex(features, VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO); > + 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 = { > .dev_unplug_pending = dev_unplug_pending, > }; > > +#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[] = { > DEFINE_PROP_BIT64("csum", VirtIONet, host_features, > VIRTIO_NET_F_CSUM, true), > @@ -4245,6 +4274,14 @@ static const Property virtio_net_properties[] = { > 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), > }; Need compatibility work like: d83f46d189 ("virtio-pci: compat page aligned ATS") Thanks