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> --- hw/net/virtio-net.c | 39 +++++++++++++++++++++++++++++++++++++++ include/net/net.h | 3 +++ net/net.c | 9 +++++++++ net/tap-bsd.c | 5 +++++ net/tap-linux.c | 19 +++++++++++++++++++ net/tap-solaris.c | 5 +++++ net/tap-stub.c | 5 +++++ net/tap.c | 11 +++++++++++ net/tap_int.h | 1 + 9 files changed, 97 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 193469fc27..05cf23700f 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -646,6 +646,15 @@ static int peer_has_uso(VirtIONet *n) return qemu_has_uso(qemu_get_queue(n->nic)->peer); } +static int peer_has_tunnel(VirtIONet *n) +{ + if (!peer_has_vnet_hdr(n)) { + return 0; + } + + 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) { @@ -789,6 +798,15 @@ static virtio_features_t virtio_net_get_features(VirtIODevice *vdev, virtio_clear_feature_ex(&features, VIRTIO_NET_F_GUEST_USO4); virtio_clear_feature_ex(&features, VIRTIO_NET_F_GUEST_USO6); +#ifdef CONFIG_INT128 + 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); +#endif + virtio_clear_feature_ex(&features, VIRTIO_NET_F_HASH_REPORT); } @@ -803,6 +821,17 @@ static virtio_features_t virtio_net_get_features(VirtIODevice *vdev, virtio_clear_feature_ex(&features, VIRTIO_NET_F_GUEST_USO6); } +#ifdef CONFIG_INT128 + 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); + } +#endif + if (!get_vhost_net(nc->peer)) { return features; } @@ -4153,6 +4182,16 @@ static const Property virtio_net_properties[] = { VIRTIO_NET_F_GUEST_USO6, true), DEFINE_PROP_BIT64("host_uso", VirtIONet, host_features, VIRTIO_NET_F_HOST_USO, true), +#ifdef CONFIG_INT128 + DEFINE_PROP_BITVF("host_tunnel", VirtIONet, host_features_ex, + VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO, true), + DEFINE_PROP_BITVF("host_tunnel_csum", VirtIONet, host_features_ex, + VIRTIO_NET_F_HOST_UDP_TUNNEL_GSO_CSUM, true), + DEFINE_PROP_BITVF("guest_tunnel", VirtIONet, host_features_ex, + VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO, true), + DEFINE_PROP_BITVF("guest_tunnel_csum", VirtIONet, host_features_ex, + VIRTIO_NET_F_GUEST_UDP_TUNNEL_GSO_CSUM, true), +#endif }; static void virtio_net_class_init(ObjectClass *klass, const void *data) diff --git a/include/net/net.h b/include/net/net.h index cdd5b109b0..391d983e49 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -55,6 +55,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 *, int, int, int, int, int, int, int); @@ -83,6 +84,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; @@ -183,6 +185,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, int csum, int tso4, int tso6, diff --git a/net/net.c b/net/net.c index 39d6f28158..9c83d3b137 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); } +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 b4c84441ba..3f01c8921e 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -217,6 +217,11 @@ int tap_probe_has_uso(int fd) return 0; } +int tap_probe_has_tunnel(int fd) +{ + return 0; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap-linux.c b/net/tap-linux.c index 22ec2f45d2..2df601551e 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -37,6 +37,14 @@ #define PATH_NET_TUN "/dev/net/tun" +#ifndef TUN_F_UDP_TUNNEL_GSO +#define TUN_F_UDP_TUNNEL_GSO 0x080 +#endif + +#ifndef TUN_F_UDP_TUNNEL_GSO_CSUM +#define TUN_F_UDP_TUNNEL_GSO_CSUM 0x100 +#endif + int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required, int mq_required, Error **errp) { @@ -196,6 +204,17 @@ int tap_probe_has_uso(int fd) return 1; } +int tap_probe_has_tunnel(int fd) +{ + unsigned offload; + + offload = TUN_F_CSUM | TUN_F_TSO4 | TUN_F_UDP_TUNNEL_GSO; + if (ioctl(fd, TUNSETOFFLOAD, offload) < 0) { + return 0; + } + return 1; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { if (ioctl(fd, TUNSETVNETHDRSZ, &len) == -1) { diff --git a/net/tap-solaris.c b/net/tap-solaris.c index 51b7830bef..b1aa40d46b 100644 --- a/net/tap-solaris.c +++ b/net/tap-solaris.c @@ -221,6 +221,11 @@ int tap_probe_has_uso(int fd) return 0; } +int tap_probe_has_tunnel(int fd) +{ + return 0; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap-stub.c b/net/tap-stub.c index 38673434cb..5f57d6baac 100644 --- a/net/tap-stub.c +++ b/net/tap-stub.c @@ -52,6 +52,11 @@ int tap_probe_has_uso(int fd) return 0; } +int tap_probe_has_tunnel(int fd) +{ + return 0; +} + void tap_fd_set_vnet_hdr_len(int fd, int len) { } diff --git a/net/tap.c b/net/tap.c index ae1c7e3983..f6e8cd5f1c 100644 --- a/net/tap.c +++ b/net/tap.c @@ -58,6 +58,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; @@ -223,6 +224,14 @@ static bool tap_has_uso(NetClientState *nc) return s->has_uso; } +static bool tap_has_tunnel(NetClientState *nc) +{ + TAPState *s = DO_UPCAST(TAPState, nc, nc); + + assert(nc->info->type == NET_CLIENT_DRIVER_TAP); + return s->has_tunnel; +} + static bool tap_has_vnet_hdr(NetClientState *nc) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -340,6 +349,7 @@ static NetClientInfo net_tap_info = { .cleanup = tap_cleanup, .has_ufo = tap_has_ufo, .has_uso = tap_has_uso, + .has_tunnel = tap_has_tunnel, .has_vnet_hdr = tap_has_vnet_hdr, .has_vnet_hdr_len = tap_has_vnet_hdr_len, .set_offload = tap_set_offload, @@ -367,6 +377,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer, s->using_vnet_hdr = false; s->has_ufo = tap_probe_has_ufo(s->fd); s->has_uso = tap_probe_has_uso(s->fd); + s->has_tunnel = tap_probe_has_tunnel(s->fd); s->enabled = true; tap_set_offload(&s->nc, 0, 0, 0, 0, 0, 0, 0); /* diff --git a/net/tap_int.h b/net/tap_int.h index 8857ff299d..2a8aa3632f 100644 --- a/net/tap_int.h +++ b/net/tap_int.h @@ -37,6 +37,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); +int tap_probe_has_tunnel(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_vnet_hdr_len(int fd, int len); -- 2.49.0