net-gro: Prepare GRO stack for the upcoming tunneling support
Subsystems (4)
PATCH v3 1/1 net-gro: Prepare GRO stack for the upcoming tunneling support
From: Jerry Chu <[email protected]>
This patch modifies the GRO stack to avoid the use of "network_header" and associated macros like ip_hdr() and ipv6_hdr() in order to allow an arbitary number of IP hdrs (v4 or v6) to be used in the encapsulation chain. This lays the foundation for various IP tunneling support (IP-in-IP, GRE, VXLAN, SIT,...) to be added later.
With this patch, the GRO stack traversing now is mostly based on skb_gro_offset rather than special hdr offsets saved in skb (e.g., skb->network_header). As a result all but the top layer (i.e., the the transport layer) must have hdrs of the same length in order for a pkt to be considered for aggregation. Therefore when adding a new encap layer (e.g., for tunneling), one must check and skip flows (e.g., by setting NAPI_GRO_CB(p)->same_flow to 0) that have a different hdr length.
Note that unlike the network header, the transport header can and will continue to be set by the GRO code since there will be at most one "transport layer" in the encap chain.
--- include/linux/netdevice.h | 2 +- net/core/dev.c | 76 ++++++++++++++++------------------------------- net/ipv4/af_inet.c | 25 ++++++++++++---- net/ipv4/tcp_offload.c | 9 +++--- net/ipv6/ip6_offload.c | 54 ++++++++++++++++++++++++++------- net/ipv6/tcpv6_offload.c | 6 ++-- 6 files changed, 97 insertions(+), 75 deletions(-)
include/linux/netdevice.h +1 -1
@@ -1673,7 +1673,7 @@ struct offload_callbacks {int (*gso_send_check)(struct sk_buff *skb);struct sk_buff **(*gro_receive)(struct sk_buff **head,struct sk_buff *skb); -int (*gro_complete)(struct sk_buff *skb); +int (*gro_complete)(struct sk_buff *skb,int nhoff); };struct packet_offload {
net/core/dev.c +25 -51
125 lines not on this page · raw message
net/ipv4/af_inet.c +19 -6
@@ -1377,8 +1377,12 @@ static struct sk_buff **inet_gro_receive(struct sk_buff **head,if (!NAPI_GRO_CB (p)->same_flow)continue ; - iph2 =ip_hdr (p); - + iph2 = (struct iphdr *)(p->data + off); +/* The above works because, with the exception of the top +* (inner most) layer, we only aggregate pkts with the same +* hdr length so all the hdrs we'll need to verify will start +* at the same offset. +*/ if ((iph->protocol ^ iph2->protocol) | ((__force u32 )iph->saddr ^ (__force u32 )iph2->saddr) | ((__force u32 )iph->daddr ^ (__force u32 )iph2->daddr)) {
@@ -1397,6 +1401,11 @@ static struct sk_buff **inet_gro_receive(struct sk_buff **head, }NAPI_GRO_CB (skb)->flush |= flush; +skb_set_network_header (skb, off); +/* The above will be needed by the transport layer if there is one +* immediately following this IP hdr. +*/ +skb_gro_pull (skb,sizeof (*iph));skb_set_transport_header (skb,skb_gro_offset (skb));
@@ -1411,10 +1420,10 @@ out:return pp; } -static int inet_gro_complete (struct sk_buff *skb) +static int inet_gro_complete (struct sk_buff *skb,int nhoff) { -__be16 newlen =htons (skb->len -skb_network_offset (skb)); -struct iphdr *iph =ip_hdr (skb); +__be16 newlen =htons (skb->len - nhoff); +struct iphdr *iph = (struct iphdr *)(skb->data + nhoff);const struct net_offload *ops;int proto = iph->protocol;int err = -ENOSYS ;
@@ -1427,7 +1436,11 @@ static int inet_gro_complete(struct sk_buff *skb)if (WARN_ON (!ops || !ops->callbacks.gro_complete)) goto out_unlock; - err = ops->callbacks.gro_complete (skb); +/* Only need to add sizeof(*iph) to get to the next hdr below +* because any hdr with option will have been flushed in +* inet_gro_receive(). +*/ + err = ops->callbacks.gro_complete (skb, nhoff +sizeof (*iph)); out_unlock:rcu_read_unlock ();
net/ipv4/tcp_offload.c +5 -4
@@ -240,7 +240,7 @@ int tcp_gro_complete(struct sk_buff *skb) {struct tcphdr *th =tcp_hdr (skb); - skb->csum_start =skb_transport_header (skb) - skb->head; + skb->csum_start = (unsigned char *)th - skb->head; skb->csum_offset = offsetof(struct tcphdr , check); skb->ip_summed =CHECKSUM_PARTIAL ;
@@ -272,6 +272,7 @@ static int tcp_v4_gso_send_check(struct sk_buff *skb)static struct sk_buff **tcp4_gro_receive (struct sk_buff **head,struct sk_buff *skb) { +/* Use the IP hdr immediately proceeding for this transport */ const struct iphdr *iph =skb_gro_network_header (skb);__wsum wsum;
@@ -303,13 +304,13 @@ skip_csum:return tcp_gro_receive (head, skb); } -static int tcp4_gro_complete (struct sk_buff *skb) +static int tcp4_gro_complete (struct sk_buff *skb,int thoff) {const struct iphdr *iph =ip_hdr (skb);struct tcphdr *th =tcp_hdr (skb); - th->check = ~tcp_v4_check (skb->len -skb_transport_offset (skb), - iph->saddr, iph->daddr,0 ); + th->check = ~tcp_v4_check (skb->len - thoff, iph->saddr, + iph->daddr,0 );skb_shinfo (skb)->gso_type =SKB_GSO_TCPV4 ;return tcp_gro_complete (skb);
net/ipv6/ip6_offload.c +44 -10
89 lines not on this page · raw message
net/ipv6/tcpv6_offload.c +3 -3
@@ -66,13 +66,13 @@ skip_csum:return tcp_gro_receive (head, skb); } -static int tcp6_gro_complete (struct sk_buff *skb) +static int tcp6_gro_complete (struct sk_buff *skb,int thoff) {const struct ipv6hdr *iph =ipv6_hdr (skb);struct tcphdr *th =tcp_hdr (skb); - th->check = ~tcp_v6_check (skb->len -skb_transport_offset (skb), - &iph->saddr, &iph->daddr,0 ); + th->check = ~tcp_v6_check (skb->len - thoff, &iph->saddr, + &iph->daddr,0 );skb_shinfo (skb)->gso_type =SKB_GSO_TCPV6 ;return tcp_gro_complete (skb);
Signature · 1 line
1.8.5.1
From: "H.K. Jerry Chu" <[email protected]>
Date: Wed, 11 Dec 2013 20:53:45 -0800
Quoted 17 lines
From: Jerry Chu <[email protected]>
This patch modifies the GRO stack to avoid the use of "
network_header" and associated macros likeip_hdr()andipv6_hdr()in order to allow an arbitary number of IP hdrs (v4 or v6) to be used in the encapsulation chain. This lays the foundation for various IP tunneling support (IP-in-IP, GRE, VXLAN, SIT,...) to be added later.With this patch, the GRO stack traversing now is mostly based on
skb_gro_offsetrather than special hdr offsets saved in skb (e.g.,skb->network_header). As a result all but the top layer (i.e., the the transport layer) must have hdrs of the same length in order for a pkt to be considered for aggregation. Therefore when adding a new encap layer (e.g., for tunneling), one must check and skip flows (e.g., by setting NAPI_GRO_CB(p)->same_flow to 0) that have a different hdr length.
Quoted 7 lines
Note that unlike the network header, the transport header can and will continue to be set by the GRO code since there will be at most one "transport layer" in the encap chain.
Signed-off-by H.K. Jerry Chu <[email protected]>Suggested-by Eric Dumazet <[email protected]>Reviewed-by Eric Dumazet <[email protected]>
Applied, thanks.
Quoted 24 lines · David Miller
From: "H.K. Jerry Chu" <[email protected]>
Date: Wed, 11 Dec 2013 20:53:45 -0800Quoted 21 lines
From: Jerry Chu <[email protected]>
This patch modifies the GRO stack to avoid the use of "
network_header" and associated macros likeip_hdr()andipv6_hdr()in order to allow an arbitary number of IP hdrs (v4 or v6) to be used in the encapsulation chain. This lays the foundation for various IP tunneling support (IP-in-IP, GRE, VXLAN, SIT,...) to be added later.With this patch, the GRO stack traversing now is mostly based on
skb_gro_offsetrather than special hdr offsets saved in skb (e.g.,skb->network_header). As a result all but the top layer (i.e., the the transport layer) must have hdrs of the same length in order for a pkt to be considered for aggregation. Therefore when adding a new encap layer (e.g., for tunneling), one must check and skip flows (e.g., by setting NAPI_GRO_CB(p)->same_flow to 0) that have a different hdr length.Note that unlike the network header, the transport header can and will continue to be set by the GRO code since there will be at most one "transport layer" in the encap chain.
Quoted 5 lines
Quoted 3 lines
Signed-off-by H.K. Jerry Chu <[email protected]>Suggested-by Eric Dumazet <[email protected]>Reviewed-by Eric Dumazet <[email protected]>Applied, thanks.
Thanks, David. I will submit a patch for GRE soon to demonstrate just how easy it is to add tunneling support to GRO after the assumption of only one IP hdr in the encap chain is removed. (I already have the code but it doesn't support the CSUM flag. I'm thinking adding it plus csum offload support before submitting the patch.)
Best,
Jerry
PATCH 1/1 ipv6: fix compiler warning in ipv6_exthdrs_len
In reply to H.K. Jerry ChuCommit 299603e8370a93dd5d8e8d800f0dff1ce2c53d36 ("net-gro: Prepare GRO stack for the upcoming tunneling support") used an uninitialized variable which leads to the following compiler warning:
net/ipv6/ip6_offload.c: In function ‘ipv6_gro_complete’:net/ipv6/ip6_offload.c:178:24: warning: ‘optlen’ may be used uninitialized in this function [-Wmaybe-uninitialized]
opth = (void *)opth + optlen;
^
net/ipv6/ip6_offload.c:164:22: note: ‘optlen’ was declared here
int len = 0, proto, optlen;
^Fix it up.
---
I just noticed this and tried to fix it. Jerry, could you please review? I hope I got it right. ;)
net/ipv6/ip6_offload.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/ipv6/ip6_offload.c +5 -4
@@ -161,7 +161,7 @@ static int ipv6_exthdrs_len(struct ipv6hdr *iph, const struct net_offload **opps) {struct ipv6_opt_hdr *opth =NULL ; -int len =0 , proto, optlen; +int len =0 , optlen =0 , proto; proto = iph->nexthdr;for (;;) {
@@ -172,11 +172,12 @@ static int ipv6_exthdrs_len(struct ipv6hdr *iph,if (!((*opps)->flags &INET6_PROTO_GSO_EXTHDR ))break ; } -if (opth ==NULL ) +if (opth ==NULL ) { opth = (void *)(iph+1 ); -else + }else { + optlen =ipv6_optlen (opth); opth = (void *)opth + optlen; - optlen =ipv6_optlen (opth); + } len += optlen; proto = opth->nexthdr; }
Signature · 1 line
1.8.3.1
Re: [PATCH net-next] ipv6: fix compiler warning in ipv6_exthdrs_len
From: Hannes Frederic Sowa <[email protected]>
Date: Sat, 14 Dec 2013 07:29:29 +0100
Quoted 11 lines
Commit
299603e8370a93dd5d8e8d800f0dff1ce2c53d36("net-gro: Prepare GRO stack for the upcoming tunneling support") used an uninitialized variable which leads to the following compiler warning:
net/ipv6/ip6_offload.c: In function ‘ipv6_gro_complete’:net/ipv6/ip6_offload.c:178:24: warning: ‘optlen’ may be used uninitialized in this function [-Wmaybe-uninitialized]opth = (void *)opth + optlen; ^ net/ipv6/ip6_offload.c:164:22: note: ‘optlen’ was declared here int len = 0, proto, optlen; ^
Quoted 4 lines
Fix it up.
Cc Jerry Chu <[email protected]>Signed-off-by Hannes Frederic Sowa <[email protected]>
Applied.
Re: [PATCH net-next] ipv6: fix compiler warning in ipv6_exthdrs_len
Quoted 16 lines · David Miller
From: Hannes Frederic Sowa <[email protected]>
Date: Sat, 14 Dec 2013 07:29:29 +0100Quoted 13 lines
Commit
299603e8370a93dd5d8e8d800f0dff1ce2c53d36("net-gro: Prepare GRO stack for the upcoming tunneling support") used an uninitialized variable which leads to the following compiler warning:
net/ipv6/ip6_offload.c: In function ‘ipv6_gro_complete’:net/ipv6/ip6_offload.c:178:24: warning: ‘optlen’ may be used uninitialized in this function [-Wmaybe-uninitialized]opth = (void *)opth + optlen; ^ net/ipv6/ip6_offload.c:164:22: note: ‘optlen’ was declared here int len = 0, proto, optlen; ^Fix it up.
Quoted 4 lines
Quoted 2 lines
Cc Jerry Chu <[email protected]>Signed-off-by Hannes Frederic Sowa <[email protected]>Applied.
Please back out the above "fix" - it actually breaks the original code because the fix will cause exthdrs_len to be one optlen short.
There was no bug in the original code, just the compiler warning (and I do not get any warning, although I admit I did not run with the -W flag).
In any case I will submit a revision shortly that will silent any warning if exists.
Jerry
PATCH 1/1 ipv6: revert misguided compiler warning fix on ipv6_exthdrs_len
This essentlally reverts commit f52d81dc27c3456c702e83183035142c222acdc7 ("ipv6: fix compiler warning in ipv6_exthdrs_len") and silences the warning with uninitialized_var.
---
Quoted 20 lines · Jerry Chu
Quoted 19 lines · David Miller
From: Hannes Frederic Sowa <[email protected]>
Date: Sat, 14 Dec 2013 07:29:29 +0100Quoted 15 lines
Commit
299603e8370a93dd5d8e8d800f0dff1ce2c53d36("net-gro: Prepare GRO stack for the upcoming tunneling support") used an uninitialized variable which leads to the following compiler warning:
net/ipv6/ip6_offload.c: In function ‘ipv6_gro_complete’:net/ipv6/ip6_offload.c:178:24: warning: ‘optlen’ may be used uninitialized in this function [-Wmaybe-uninitialized]opth = (void *)opth + optlen; ^ net/ipv6/ip6_offload.c:164:22: note: ‘optlen’ was declared here int len = 0, proto, optlen; ^Fix it up.
Cc Jerry Chu <[email protected]>Signed-off-by Hannes Frederic Sowa <[email protected]>
Quoted 7 lines
Quoted 1 line
Applied.
Please back out the above "fix" - it actually breaks the original code because the fix will cause
exthdrs_lento be one optlen short.There was no bug in the original code, just the compiler warning (and I do not get any warning, although I admit I did not run with the -W flag).
Sorry, I see now, of course. Btw. I didn't use any special flags, just a normal kernel build with gcc 4.8.2.
Quoted 2 lines
In any case I will submit a revision shortly that will silent any warning if exists.
I hope you are ok with this.
Sorry,
Hannes
net/ipv6/ip6_offload.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
net/ipv6/ip6_offload.c +4 -5
@@ -161,7 +161,7 @@ static int ipv6_exthdrs_len(struct ipv6hdr *iph, const struct net_offload **opps) {struct ipv6_opt_hdr *opth =NULL ; -int len =0 , optlen =0 , proto; +int len =0 , proto,uninitialized_var (optlen ); proto = iph->nexthdr;for (;;) {
@@ -172,12 +172,11 @@ static int ipv6_exthdrs_len(struct ipv6hdr *iph,if (!((*opps)->flags &INET6_PROTO_GSO_EXTHDR ))break ; } -if (opth ==NULL ) { +if (opth ==NULL ) opth = (void *)(iph+1 ); - }else { - optlen =ipv6_optlen (opth); +else opth = (void *)opth + optlen; - } + optlen =ipv6_optlen (opth); len += optlen; proto = opth->nexthdr; }
Signature · 1 line
1.8.3.1
Re: [PATCH net-next] ipv6: revert misguided compiler warning fix on ipv6_exthdrs_len
Quoted 3 lines · Hannes Frederic Sowa
This essentlally reverts commit
f52d81dc27c3456c702e83183035142c222acdc7("ipv6: fix compiler warning inipv6_exthdrs_len") and silences the warning withuninitialized_var.
David, please discard this. Jerry already posted a nicer cleanup.
Sorry,
Hannes
David Miller
maintainerRe: [PATCH net-next] ipv6: revert misguided compiler warning fix on ipv6_exthdrs_len
From: Hannes Frederic Sowa <[email protected]>
Date: Sun, 15 Dec 2013 18:23:22 +0100
Quoted 6 lines · Hannes Frederic Sowa
Quoted 3 lines
This essentlally reverts commit
f52d81dc27c3456c702e83183035142c222acdc7("ipv6: fix compiler warning inipv6_exthdrs_len") and silences the warning withuninitialized_var.David, please discard this. Jerry already posted a nicer cleanup.
I can't resolve these two patches in any reasonable way.
Specifically, whether I revert your patch or not, I cannot get Jerry's patch to apply cleanly.
I can't figure out what Jerry's patch is against at all.