UDP GSO Segmentation clean-ups
Subsystems (3)
cover UDP GSO Segmentation clean-ups
This patch set addresses a number of issues I found while sorting out enabling UDP GSO Segmentation support for ixgbe/ixgbevf. Specifically there were a number of issues related to the checksum and such that seemed to cause either minor irregularities or kernel panics in the case of the offload request being allowed to traverse between name spaces.
With this set applied I am was able to get UDP GSO traffic to pass over vxlan tunnels in both offloaded modes and non-offloaded modes for ixgbe and ixgbevf.
I will include the driver patches as a seperate RFC following this series.
---
Alexander Duyck (5):
udp: Record gso_segs when supporting UDP segmentation offload
udp: Do not pass checksum or MSS as parameters
udp: Add support for software checksum and GSO_PARTIAL with GSO offload
udp: Do not copy destructor if one is not present
net: Add NETIF_F_GSO_UDP_L4 to list of GSO offloads with fallback
include/linux/netdev_features.h | 3 + include/net/udp.h | 3 - net/ipv4/udp.c | 2 + net/ipv4/udp_offload.c | 102 ++++++++++++++++++++++++++------------- net/ipv6/udp_offload.c | 16 ------ 5 files changed, 73 insertions(+), 53 deletions(-)
PATCH 1/5 udp: Record gso_segs when supporting UDP segmentation offload
From: Alexander Duyck <[email protected]>
We need to record the number of segments that will be generated when this frame is segmented. The expectation is that if gso_size is set then gso_segs is set as well. Without this some drivers such as ixgbe get confused if they attempt to offload this as they record 0 segments for the entire packet instead of the correct value.
--- net/ipv4/udp.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv4/udp.c +2 -0
@@ -793,6 +793,8 @@ static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4,skb_shinfo (skb)->gso_size = cork->gso_size;skb_shinfo (skb)->gso_type =SKB_GSO_UDP_L4 ; +skb_shinfo (skb)->gso_segs =DIV_ROUND_UP (len -sizeof (uh), + cork->gso_size); goto csum_partial; }
PATCH 2/5 udp: Do not pass checksum or MSS as parameters
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
This patch is meant to be a start at cleaning up some of the UDP GSO segmentation code. Specifically we were passing mss and a recomputed checksum when we really didn't need to. The function itself could derive that information based on the already provided checksum, the length of the packet stored in the UDP header, and the gso_size.
--- include/net/udp.h | 3 +- net/ipv4/udp_offload.c | 61 +++++++++++++++++++++++++++++++----------------- net/ipv6/udp_offload.c | 7 +----- 3 files changed, 41 insertions(+), 30 deletions(-)
include/net/udp.h +1 -2
@@ -175,8 +175,7 @@ struct sk_buff **udp_gro_receive(struct sk_buff **head, struct sk_buff *skb,int udp_gro_complete (struct sk_buff *skb,int nhoff,udp_lookup_t lookup);struct sk_buff *__udp_gso_segment (struct sk_buff *gso_skb, -netdev_features_t features, -unsigned int mss,__sum16 check); +netdev_features_t features);static inline struct udphdr *udp_gro_udphdr (struct sk_buff *skb) {
net/ipv4/udp_offload.c +39 -22
97 lines not on this page · raw message
net/ipv6/udp_offload.c +1 -6
@@ -20,15 +20,10 @@static struct sk_buff *__udp6_gso_segment (struct sk_buff *gso_skb,netdev_features_t features) { -const struct ipv6hdr *ip6h =ipv6_hdr (gso_skb); -unsigned int mss =skb_shinfo (gso_skb)->gso_size; -if (!can_checksum_protocol (features,htons (ETH_P_IPV6 )))return ERR_PTR (-EIO ); -return __udp_gso_segment (gso_skb, features, mss, -udp_v6_check (sizeof (struct udphdr ) + mss, - &ip6h->saddr, &ip6h->daddr,0 )); +return __udp_gso_segment (gso_skb, features); } static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb,
PATCH 3/5 udp: Add support for software checksum and GSO_PARTIAL with GSO offload
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
This patch adds support for a software provided checksum and GSO_PARTIAL segmentation support. With this we can offload UDP segmentation on devices that only have partial support for tunnels.
Since we are no longer needing the hardware checksum we can drop the checks in the segmentation code that were verifying if it was present.
--- net/ipv4/udp_offload.c | 28 ++++++++++++++++++---------- net/ipv6/udp_offload.c | 11 +---------- 2 files changed, 19 insertions(+), 20 deletions(-)
net/ipv4/udp_offload.c +18 -10
@@ -217,6 +217,13 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,return segs; } +/* GSO partial and frag_list segmentation only requires splitting +* the frame into an MSS multiple and possibly a remainder, both +* cases return a GSO skb. So update the mss now. +*/ +if (skb_is_gso (segs)) + mss *=skb_shinfo (segs)->gso_segs; + seg = segs; uh =udp_hdr (seg);
@@ -237,6 +244,11 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, uh->len = newlen; uh->check = check; +if (seg->ip_summed ==CHECKSUM_PARTIAL ) +gso_reset_checksum (seg, ~check); +else + uh->check =gso_make_checksum (seg, ~check); + seg = seg->next; uh =udp_hdr (seg); }
@@ -250,6 +262,11 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, uh->len = newlen; uh->check = check; +if (seg->ip_summed ==CHECKSUM_PARTIAL ) +gso_reset_checksum (seg, ~check); +else + uh->check =gso_make_checksum (seg, ~check); +/* update refcount for the packet */ refcount_add (sum_truesize - gso_skb->truesize, &sk->sk_wmem_alloc); out:
@@ -257,15 +274,6 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, }EXPORT_SYMBOL_GPL (__udp_gso_segment); -static struct sk_buff *__udp4_gso_segment (struct sk_buff *gso_skb, -netdev_features_t features) -{ -if (!can_checksum_protocol (features,htons (ETH_P_IP ))) -return ERR_PTR (-EIO ); - -return __udp_gso_segment (gso_skb, features); -} -static struct sk_buff *udp4_ufo_fragment (struct sk_buff *skb,netdev_features_t features) {
@@ -289,7 +297,7 @@ static struct sk_buff *udp4_ufo_fragment(struct sk_buff *skb, goto out;if (skb_shinfo (skb)->gso_type &SKB_GSO_UDP_L4 ) -return __udp4_gso_segment (skb, features); +return __udp_gso_segment (skb, features); mss =skb_shinfo (skb)->gso_size;if (unlikely (skb->len <= mss))
net/ipv6/udp_offload.c +1 -10
@@ -17,15 +17,6 @@#include <net/ip6_checksum.h> #include "ip6_offload.h" -static struct sk_buff *__udp6_gso_segment (struct sk_buff *gso_skb, -netdev_features_t features) -{ -if (!can_checksum_protocol (features,htons (ETH_P_IPV6 ))) -return ERR_PTR (-EIO ); - -return __udp_gso_segment (gso_skb, features); -} -static struct sk_buff *udp6_ufo_fragment (struct sk_buff *skb,netdev_features_t features) {
@@ -58,7 +49,7 @@ static struct sk_buff *udp6_ufo_fragment(struct sk_buff *skb, goto out;if (skb_shinfo (skb)->gso_type &SKB_GSO_UDP_L4 ) -return __udp6_gso_segment (skb, features); +return __udp_gso_segment (skb, features);/* Do software UFO. Complete and fill in the UDP checksum as HW cannot * do checksum of UDP packets sent as multiple IP fragments.
PATCH 4/5 udp: Do not copy destructor if one is not present
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
This patch makes it so that if a destructor is not present we avoid trying to update the skb socket or any reference counting that would be associated with the NULL socket and/or descriptor. By doing this we can support traffic coming from another namespace without any issues.
--- net/ipv4/udp_offload.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
net/ipv4/udp_offload.c +13 -6
@@ -195,6 +195,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,unsigned int sum_truesize =0 ;struct udphdr *uh;unsigned int mss; +bool copy_dtor;__sum16 check;__be16 newlen;
@@ -208,12 +209,14 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,skb_pull (gso_skb,sizeof (*uh));/* clear destructor to avoid skb_segment assigning it to tail */ -WARN_ON_ONCE (gso_skb->destructor != sock_wfree); + copy_dtor = gso_skb->destructor == sock_wfree; +WARN_ON_ONCE (gso_skb->destructor && !copy_dtor); gso_skb->destructor =NULL ; segs =skb_segment (gso_skb, features);if (unlikely (IS_ERR_OR_NULL (segs))) { - gso_skb->destructor = sock_wfree; +if (copy_dtor) + gso_skb->destructor = sock_wfree;return segs; }
@@ -234,9 +237,11 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, (__force u32)newlen));for (;;) { - seg->destructor = sock_wfree; - seg->sk = sk; - sum_truesize += seg->truesize; +if (copy_dtor) { + seg->destructor = sock_wfree; + seg->sk = sk; + sum_truesize += seg->truesize; + }if (!seg->next)break ;
@@ -268,7 +273,9 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, uh->check =gso_make_checksum (seg, ~check);/* update refcount for the packet */ -refcount_add (sum_truesize - gso_skb->truesize, &sk->sk_wmem_alloc); +if (copy_dtor) +refcount_add (sum_truesize - gso_skb->truesize, + &sk->sk_wmem_alloc); out:return segs; }
PATCH 5/5 net: Add NETIF_F_GSO_UDP_L4 to list of GSO offloads with fallback
In reply to Alexander DuyckFrom: Alexander Duyck <[email protected]>
Enable UDP offload as a generic software offload since we can now handle it for multiple cases including if the checksum isn't present and via gso_partial in the case of tunnels.
--- include/linux/netdev_features.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/netdev_features.h +2 -1
@@ -184,7 +184,8 @@ enum {/* List of features with software fallbacks. */ #define NETIF_F_GSO_SOFTWARE (NETIF_F_ALL_TSO | \ - NETIF_F_GSO_SCTP) + NETIF_F_GSO_SCTP| \ + NETIF_F_GSO_UDP_L4)/* * If one device supports one of these features, then enable them
Re: [net-next PATCH 1/5] udp: Record gso_segs when supporting UDP segmentation offload
In reply to Alexander DuyckQuoted 19 lines · Alexander Duyck
From: Alexander Duyck <[email protected]>
We need to record the number of segments that will be generated when this frame is segmented. The expectation is that if
gso_sizeis set thengso_segsis set as well. Without this some drivers such as ixgbe get confused if they attempt to offload this as they record 0 segments for the entire packet instead of the correct value.Signed-off-by Alexander Duyck <[email protected]>--- net/ipv4/udp.c | 2 ++ 1 file changed, 2 insertions(+)net/ipv4/udp.c +0
-0
net/ipv4/udp.c static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4, · line 800
Quoted 8 lines
net/ipv4/udp.c +2
-0@@ -793,6 +793,8 @@ static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4,skb_shinfo (skb)->gso_size = cork->gso_size;skb_shinfo (skb)->gso_type =SKB_GSO_UDP_L4 ; +skb_shinfo (skb)->gso_segs =DIV_ROUND_UP (len -sizeof (uh), + cork->gso_size); goto csum_partial; }
Yes, this also fixes qdisc_pkt_len_init()
Re: [net-next PATCH 2/5] udp: Do not pass checksum or MSS as parameters
In reply to Alexander DuyckQuoted 8 lines · Alexander Duyck
From: Alexander Duyck <[email protected]>
This patch is meant to be a start at cleaning up some of the UDP GSO segmentation code. Specifically we were passing mss and a recomputed checksum when we really didn't need to. The function itself could derive that information based on the already provided checksum, the length of the packet stored in the UDP header, and the
gso_size.
Quoted 7 lines
Signed-off-by Alexander Duyck <[email protected]>--- include/net/udp.h | 3 +- net/ipv4/udp_offload.c | 61 +++++++++++++++++++++++++++++++----------------- net/ipv6/udp_offload.c | 7 +----- 3 files changed, 41 insertions(+), 30 deletions(-)
There are really a lot of changes in this patch (not mentioned in changelog).
Can you please split all this in small patches ?
Re: [net-next PATCH 4/5] udp: Do not copy destructor if one is not present
In reply to Alexander DuyckQuoted 25 lines · Alexander Duyck
From: Alexander Duyck <[email protected]>
This patch makes it so that if a destructor is not present we avoid trying to update the skb socket or any reference counting that would be associated with the NULL socket and/or descriptor. By doing this we can support traffic coming from another namespace without any issues.
Signed-off-by Alexander Duyck <[email protected]>--- net/ipv4/udp_offload.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)net/ipv4/udp_offload.c +1
-0@@ -195,6 +195,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,unsigned int sum_truesize =0 ;struct udphdr *uh;unsigned int mss; +bool copy_dtor;__sum16 check;__be16 newlen;
net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 213
Quoted 6 lines
net/ipv4/udp_offload.c +2
-1@@ -208,12 +209,14 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,skb_pull (gso_skb,sizeof (*uh));/* clear destructor to avoid skb_segment assigning it to tail */ -WARN_ON_ONCE (gso_skb->destructor != sock_wfree); + copy_dtor = gso_skb->destructor == sock_wfree; +WARN_ON_ONCE (gso_skb->destructor && !copy_dtor);
Why not simply clear gso_skb->destructor only if copy_dtor is true ?
Then we can get rid of this WARN_ON_ONCE()
Quoted 37 lines
net/ipv4/udp_offload.c +10
-5gso_skb->destructor =NULL ; segs =skb_segment (gso_skb, features);if (unlikely (IS_ERR_OR_NULL (segs))) { - gso_skb->destructor = sock_wfree; +if (copy_dtor) + gso_skb->destructor = sock_wfree;return segs; }@@ -234,9 +237,11 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, (__force u32)newlen));for (;;) { - seg->destructor = sock_wfree; - seg->sk = sk; - sum_truesize += seg->truesize; +if (copy_dtor) { + seg->destructor = sock_wfree; + seg->sk = sk; + sum_truesize += seg->truesize; + }if (!seg->next)break ;@@ -268,7 +273,9 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, uh->check =gso_make_checksum (seg, ~check);/* update refcount for the packet */ -refcount_add (sum_truesize - gso_skb->truesize, &sk->sk_wmem_alloc); +if (copy_dtor) +refcount_add (sum_truesize - gso_skb->truesize, + &sk->sk_wmem_alloc); out:return segs; }
Re: [net-next PATCH 3/5] udp: Add support for software checksum and GSO_PARTIAL with GSO offload
In reply to Alexander DuyckQuoted 21 lines · Alexander Duyck
From: Alexander Duyck <[email protected]>
This patch adds support for a software provided checksum and
GSO_PARTIALsegmentation support. With this we can offload UDP segmentation on devices that only have partial support for tunnels.Since we are no longer needing the hardware checksum we can drop the checks in the segmentation code that were verifying if it was present.
Signed-off-by Alexander Duyck <[email protected]>--- net/ipv4/udp_offload.c | 28 ++++++++++++++++++---------- net/ipv6/udp_offload.c | 11 +---------- 2 files changed, 19 insertions(+), 20 deletions(-)net/ipv4/udp_offload.c +0
-0@@ -217,6 +217,13 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,return segs;
net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 227
Quoted 10 lines
net/ipv4/udp_offload.c +7
-0} +/* GSO partial and frag_list segmentation only requires splitting +* the frame into an MSS multiple and possibly a remainder, both +* cases return a GSO skb. So update the mss now. +*/ +if (skb_is_gso (segs)) + mss *=skb_shinfo (segs)->gso_segs; +
I do not understand this code.
I am also seeing it in tcp, after commit 07b26c9454a2a ("gso: Support partial splitting at the frag_list pointer")
Presumably this broke tcp_gso_tstamp() , right ?
Re: [net-next PATCH 3/5] udp: Add support for software checksum and GSO_PARTIAL with GSO offload
Quoted 26 lines · Eric Dumazet
Quoted 23 lines · Alexander Duyck
From: Alexander Duyck <[email protected]>
This patch adds support for a software provided checksum and
GSO_PARTIALsegmentation support. With this we can offload UDP segmentation on devices that only have partial support for tunnels.Since we are no longer needing the hardware checksum we can drop the checks in the segmentation code that were verifying if it was present.
Signed-off-by Alexander Duyck <[email protected]>--- net/ipv4/udp_offload.c | 28 ++++++++++++++++++---------- net/ipv6/udp_offload.c | 11 +---------- 2 files changed, 19 insertions(+), 20 deletions(-)net/ipv4/udp_offload.c +0
-0@@ -217,6 +217,13 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,return segs; }
Quoted 10 lines
net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 229
Quoted 8 lines
net/ipv4/udp_offload.c +7
-0+/* GSO partial and frag_list segmentation only requires splitting +* the frame into an MSS multiple and possibly a remainder, both +* cases return a GSO skb. So update the mss now. +*/ +if (skb_is_gso (segs)) + mss *=skb_shinfo (segs)->gso_segs; +I do not understand this code.
In the case of GSO partial or frag_list segmentation we only split along certain MSS sized boundaries and we leave the resulting frame as a GSO skb. As a result the actual frame size is a multiple of MSS so we were updating the mss by that value.
Quoted 3 lines
I am also seeing it in tcp, after commit
07b26c9454a2a("gso: Support partial splitting at thefrag_listpointer")Presumably this broke
tcp_gso_tstamp(), right ?
I'm not sure it did. The MSS multiplication is there because the frame now spans multiple MSS chunks in one shot. So tcp_gso_tstamp should still have the correct behavior, I think.
- Alex
Re: [net-next PATCH 4/5] udp: Do not copy destructor if one is not present
In reply to Eric DumazetQuoted 30 lines · Eric Dumazet
Quoted 27 lines · Alexander Duyck
From: Alexander Duyck <[email protected]>
This patch makes it so that if a destructor is not present we avoid trying to update the skb socket or any reference counting that would be associated with the NULL socket and/or descriptor. By doing this we can support traffic coming from another namespace without any issues.
Signed-off-by Alexander Duyck <[email protected]>--- net/ipv4/udp_offload.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)net/ipv4/udp_offload.c +1
-0@@ -195,6 +195,7 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,unsigned int sum_truesize =0 ;struct udphdr *uh;unsigned int mss; +bool copy_dtor;__sum16 check;__be16 newlen;@@ -208,12 +209,14 @@ struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb,skb_pull (gso_skb,sizeof (*uh));
Quoted 8 lines
net/ipv4/udp_offload.c struct sk_buff *__udp_gso_segment(struct sk_buff *gso_skb, · line 213
Quoted 4 lines
net/ipv4/udp_offload.c +2
-1/* clear destructor to avoid skb_segment assigning it to tail */ -WARN_ON_ONCE (gso_skb->destructor != sock_wfree); + copy_dtor = gso_skb->destructor == sock_wfree; +WARN_ON_ONCE (gso_skb->destructor && !copy_dtor);Why not simply clear
gso_skb->destructoronly ifcopy_dtoris true ?Then we can get rid of this
WARN_ON_ONCE()
Sounds good. I think I had code similar to that in an earlier version of this patch, but when I started breaking things up I got rid of this code until I realized I needed it due to a kernel panic triggered by running the offload over a VXLAN from another namespace.
Thanks.
- Alex
Re: [net-next PATCH 2/5] udp: Do not pass checksum or MSS as parameters
In reply to Eric DumazetQuoted 19 lines · Eric Dumazet
Quoted 8 lines · Alexander Duyck
From: Alexander Duyck <[email protected]>
This patch is meant to be a start at cleaning up some of the UDP GSO segmentation code. Specifically we were passing mss and a recomputed checksum when we really didn't need to. The function itself could derive that information based on the already provided checksum, the length of the packet stored in the UDP header, and the
gso_size.Quoted 7 lines
Signed-off-by Alexander Duyck <[email protected]>--- include/net/udp.h | 3 +- net/ipv4/udp_offload.c | 61 +++++++++++++++++++++++++++++++----------------- net/ipv6/udp_offload.c | 7 +----- 3 files changed, 41 insertions(+), 30 deletions(-)
Quoted 3 lines
There are really a lot of changes in this patch (not mentioned in changelog).
Can you please split all this in small patches ?
I'll see what I can do for the next version. I think I can come up with an in-between step that should help to cut this down in size.
Thanks.
- Alex