Skip to contentSkip to conversation

udp: Avoid post-GRO UDP checksum recalculation

PATCH Superseded Sean Tranchetti 3 participants 3 messages May 23, 2019 – May 25, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 udp: Avoid post-GRO UDP checksum recalculation

Currently, when resegmenting an unexpected UDP GRO packet, the full UDP checksum will be calculated for every new SKB created by skb_segment() because the netdev features passed in by udp_rcv_segment() lack any information about checksum offload capabilities.

We have no need to perform this calculation again, as
1) The GRO implementation guarantees that any packets making it to the udp_rcv_segment() function had correct checksums, and, more importantly,
2) Upon the successful return of udp_rcv_segment(), we immediately pull the UDP header off and either queue the segment to the socket or hand it off to a new protocol handler. In either case, the checksum is not needed.

Fixes cf329aa42b66 ("udp: cope with UDP GRO packet misdirection")
Cc Paolo Abeni <[email protected]>
Cc Subash Abhinov Kasiviswanathan <[email protected]>
---
 include/net/udp.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/net/udp.h +5 -1
index d8ce937..6164d5c 100644
@@ -472,11 +472,15 @@ static inline struct sk_buff *udp_rcv_segment(struct sock *sk,
 					      struct sk_buff *skb, bool ipv4)
 {
 	struct sk_buff *segs;
+	netdev_features_t features = NETIF_F_SG;
+
+	/* Avoid csum recalculation in skb_segment() */
+	features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
 
 	/* the GSO CB lays after the UDP one, no need to save and restore any
 	 * CB fragment
 	 */
-	segs = __skb_gso_segment(skb, NETIF_F_SG, false);
+	segs = __skb_gso_segment(skb, features, false);
 	if (unlikely(IS_ERR_OR_NULL(segs))) {
 		int segs_nr = skb_shinfo(skb)->gso_segs;
 
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 5 lines · Sean Tranchetti

Currently, when resegmenting an unexpected UDP GRO packet, the full UDP checksum will be calculated for every new SKB created by skb_segment() because the netdev features passed in by udp_rcv_segment() lack any information about checksum offload capabilities.

Quoted 8 lines

We have no need to perform this calculation again, as
1) The GRO implementation guarantees that any packets making it to the udp_rcv_segment() function had correct checksums, and, more importantly,
2) Upon the successful return of udp_rcv_segment(), we immediately pull the UDP header off and either queue the segment to the socket or hand it off to a new protocol handler. In either case, the checksum is not needed.

I *think* there is a possible, even if unlikely, exception to the
above: if userspace has set the IP_CHECKSUM sockopt, recvmsg can later try to access skb csum.

I think that setting NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM only if !inet_get_convert_csum() would address the above,

Other than that LGTM, thanks for catching this!

Paolo

p.s. I suspect that with this patch GRO + resegmentation is notably faster than the plain unaggregated path, do you have by chance any related datapoint?

maintainer
#2 lore raw
In reply to Sean Tranchetti

From: Sean Tranchetti <[email protected]>
Date: Thu, 23 May 2019 13:36:17 -0600

include/net/udp.h static inline struct sk_buff *udp_rcv_segment(struct sock *sk, · line 475

Quoted 5 lines
include/net/udp.h +1 -0
@@ -472,11 +472,15 @@ static inline struct sk_buff *udp_rcv_segment(struct sock *sk,
 					      struct sk_buff *skb, bool ipv4)
 {
 	struct sk_buff *segs;
+	netdev_features_t features = NETIF_F_SG;

When you respin this based upon Paolo's feedback, please reverse christmas tree these local variables.

Thank you.