2022-12-07 12:20:11

by Andrew Melnichenko

[permalink] [raw]
Subject: [PATCH v5 0/6] TUN/VirtioNet USO features support.

Added new offloads for TUN devices TUN_F_USO4 and TUN_F_USO6.
Technically they enable NETIF_F_GSO_UDP_L4
(and only if USO4 & USO6 are set simultaneously).
It allows the transmission of large UDP packets.

UDP Segmentation Offload (USO/GSO_UDP_L4) - ability to split UDP packets
into several segments. It's similar to UFO, except it doesn't use IP
fragmentation. The drivers may push big packets and the NIC will split
them(or assemble them in case of receive), but in the case of VirtioNet
we just pass big UDP to the host. So we are freeing the driver from doing
the unnecessary job of splitting. The same thing for several guests
on one host, we can pass big packets between guests.

Different features USO4 and USO6 are required for qemu where Windows
guests can enable disable USO receives for IPv4 and IPv6 separately.
On the other side, Linux can't really differentiate USO4 and USO6, for now.
For now, to enable USO for TUN it requires enabling USO4 and USO6 together.
In the future, there would be a mechanism to control UDP_L4 GSO separately.

New types for virtio-net already in virtio-net specification:
https://github.com/oasis-tcs/virtio-spec/issues/120

Test it WIP Qemu https://github.com/daynix/qemu/tree/USOv3

Changes since v4 & RFC:
* Fixed typo and refactored.
* Tun USO offload refactored.
* Add support for guest-to-guest segmentation offload (thx Jason).

Andrew Melnychenko (6):
udp: allow header check for dodgy GSO_UDP_L4 packets.
uapi/linux/if_tun.h: Added new offload types for USO4/6.
driver/net/tun: Added features for USO.
uapi/linux/virtio_net.h: Added USO types.
linux/virtio_net.h: Support USO offload in vnet header.
drivers/net/virtio_net.c: Added USO support.

drivers/net/tap.c | 10 ++++++++--
drivers/net/tun.c | 8 +++++++-
drivers/net/virtio_net.c | 19 +++++++++++++++----
include/linux/virtio_net.h | 9 +++++++++
include/uapi/linux/if_tun.h | 2 ++
include/uapi/linux/virtio_net.h | 4 ++++
net/ipv4/udp_offload.c | 3 ++-
net/ipv6/udp_offload.c | 3 ++-
8 files changed, 49 insertions(+), 9 deletions(-)

--
2.38.1


2022-12-07 12:21:43

by Andrew Melnichenko

[permalink] [raw]
Subject: [PATCH v5 1/6] udp: allow header check for dodgy GSO_UDP_L4 packets.

Allow UDP_L4 for robust packets.

Signed-off-by: Jason Wang <[email protected]>
Signed-off-by: Andrew Melnychenko <[email protected]>
---
net/ipv4/udp_offload.c | 3 ++-
net/ipv6/udp_offload.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index 6d1a4bec2614..f65b1a7a0c26 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -387,7 +387,8 @@ static struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb,
if (!pskb_may_pull(skb, sizeof(struct udphdr)))
goto out;

- if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4)
+ if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4 &&
+ !skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST))
return __udp_gso_segment(skb, features, false);

mss = skb_shinfo(skb)->gso_size;
diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c
index 7720d04ed396..057293293e30 100644
--- a/net/ipv6/udp_offload.c
+++ b/net/ipv6/udp_offload.c
@@ -42,7 +42,8 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb,
if (!pskb_may_pull(skb, sizeof(struct udphdr)))
goto out;

- if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4)
+ if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP_L4 &&
+ !skb_gso_ok(skb, features | NETIF_F_GSO_ROBUST))
return __udp_gso_segment(skb, features, true);

mss = skb_shinfo(skb)->gso_size;
--
2.38.1

2022-12-07 12:22:04

by Andrew Melnichenko

[permalink] [raw]
Subject: [PATCH v5 3/6] driver/net/tun: Added features for USO.

Added support for USO4 and USO6.
For now, to "enable" USO, it's required to set both USO4 and USO6 simultaneously.
USO enables NETIF_F_GSO_UDP_L4.

Signed-off-by: Andrew Melnychenko <[email protected]>
---
drivers/net/tap.c | 10 ++++++++--
drivers/net/tun.c | 8 +++++++-
2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/net/tap.c b/drivers/net/tap.c
index 9e75ed3f08ce..a2be1994b389 100644
--- a/drivers/net/tap.c
+++ b/drivers/net/tap.c
@@ -957,6 +957,10 @@ static int set_offload(struct tap_queue *q, unsigned long arg)
if (arg & TUN_F_TSO6)
feature_mask |= NETIF_F_TSO6;
}
+
+ /* TODO: for now USO4 and USO6 should work simultaneously */
+ if ((arg & (TUN_F_USO4 | TUN_F_USO6)) == (TUN_F_USO4 | TUN_F_USO6))
+ features |= NETIF_F_GSO_UDP_L4;
}

/* tun/tap driver inverts the usage for TSO offloads, where
@@ -967,7 +971,8 @@ static int set_offload(struct tap_queue *q, unsigned long arg)
* When user space turns off TSO, we turn off GSO/LRO so that
* user-space will not receive TSO frames.
*/
- if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6))
+ if (feature_mask & (NETIF_F_TSO | NETIF_F_TSO6) ||
+ (feature_mask & (TUN_F_USO4 | TUN_F_USO6)) == (TUN_F_USO4 | TUN_F_USO6))
features |= RX_OFFLOADS;
else
features &= ~RX_OFFLOADS;
@@ -1091,7 +1096,8 @@ static long tap_ioctl(struct file *file, unsigned int cmd,
case TUNSETOFFLOAD:
/* let the user check for future flags */
if (arg & ~(TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6 |
- TUN_F_TSO_ECN | TUN_F_UFO))
+ TUN_F_TSO_ECN | TUN_F_UFO |
+ TUN_F_USO4 | TUN_F_USO6))
return -EINVAL;

rtnl_lock();
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 24001112c323..a7b9808368d0 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -185,7 +185,7 @@ struct tun_struct {
struct net_device *dev;
netdev_features_t set_features;
#define TUN_USER_FEATURES (NETIF_F_HW_CSUM|NETIF_F_TSO_ECN|NETIF_F_TSO| \
- NETIF_F_TSO6)
+ NETIF_F_TSO6 | NETIF_F_GSO_UDP_L4)

int align;
int vnet_hdr_sz;
@@ -2885,6 +2885,12 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
}

arg &= ~TUN_F_UFO;
+
+ /* TODO: for now USO4 and USO6 should work simultaneously */
+ if (arg & TUN_F_USO4 && arg & TUN_F_USO6) {
+ features |= NETIF_F_GSO_UDP_L4;
+ arg &= ~(TUN_F_USO4 | TUN_F_USO6);
+ }
}

/* This gives the user a way to test for new features in future by
--
2.38.1

2022-12-12 10:00:26

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH v5 0/6] TUN/VirtioNet USO features support.

Hello:

This series was applied to netdev/net-next.git (master)
by David S. Miller <[email protected]>:

On Wed, 7 Dec 2022 13:35:52 +0200 you wrote:
> Added new offloads for TUN devices TUN_F_USO4 and TUN_F_USO6.
> Technically they enable NETIF_F_GSO_UDP_L4
> (and only if USO4 & USO6 are set simultaneously).
> It allows the transmission of large UDP packets.
>
> UDP Segmentation Offload (USO/GSO_UDP_L4) - ability to split UDP packets
> into several segments. It's similar to UFO, except it doesn't use IP
> fragmentation. The drivers may push big packets and the NIC will split
> them(or assemble them in case of receive), but in the case of VirtioNet
> we just pass big UDP to the host. So we are freeing the driver from doing
> the unnecessary job of splitting. The same thing for several guests
> on one host, we can pass big packets between guests.
>
> [...]

Here is the summary with links:
- [v5,1/6] udp: allow header check for dodgy GSO_UDP_L4 packets.
https://git.kernel.org/netdev/net-next/c/1fd54773c267
- [v5,2/6] uapi/linux/if_tun.h: Added new offload types for USO4/6.
https://git.kernel.org/netdev/net-next/c/b22bbdd17a5a
- [v5,3/6] driver/net/tun: Added features for USO.
https://git.kernel.org/netdev/net-next/c/399e0827642f
- [v5,4/6] uapi/linux/virtio_net.h: Added USO types.
https://git.kernel.org/netdev/net-next/c/34061b348ae9
- [v5,5/6] linux/virtio_net.h: Support USO offload in vnet header.
https://git.kernel.org/netdev/net-next/c/860b7f27b8f7
- [v5,6/6] drivers/net/virtio_net.c: Added USO support.
https://git.kernel.org/netdev/net-next/c/418044e1de30

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html