tcp: gso: really support BIG TCP
Subsystems (3)
PATCH 1/1 tcp: gso: really support BIG TCP
We missed that tcp_gso_segment() was assuming skb->len was smaller than 65535 :
oldlen = (u16)~skb->len;
This part came with commit 0718bcc09b35 ("[NET]: Fix CHECKSUM_HW GSO problems.")
This leads to wrong TCP checksum.
Simply use csum_fold() to support 32bit packet lengthes.
oldlen name is a bit misleading, as it is the contribution of skb->len on the input skb TCP checksum. I added a comment to clarify this point.
--- net/ipv4/tcp_offload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/tcp_offload.c +2 -1
@@ -75,7 +75,8 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,if (!pskb_may_pull (skb, thlen)) goto out; - oldlen = (u16 )~skb->len; +/* Contribution of skb->len in current TCP checksum */ + oldlen = (__force u32 )csum_fold ((__force __wsum )skb->len);__skb_pull (skb, thlen); mss =skb_shinfo (skb)->gso_size;
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
Quoted 41 lines
-----Original Message-----
From: Eric Dumazet <[email protected]>
Sent: Thursday, June 1, 2023 2:18 PM
To: David S . Miller <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>
Cc: [email protected]; Xin Long <[email protected]>; David Ahern <[email protected]>; [email protected]; Eric Dumazet <[email protected]>; Alexander Duyck <[email protected]>
Subject: [PATCH net] tcp: gso: really support BIG TCPQuoted 1 line
We missed that
tcp_gso_segment()was assumingskb->lenwas smaller than 65535 :oldlen = (u16)~skb->len;
This part came with commit
0718bcc09b35("[NET]: FixCHECKSUM_HWGSO problems.")This leads to wrong TCP checksum.
Simply use
csum_fold()to support 32bit packet lengthes.oldlen name is a bit misleading, as it is the contribution of
skb->lenon the input skb TCP checksum. I added a comment to clarify this point.Fixes 09f3d1a3a52c ("ipv6/gso: remove temporary HBH/jumbo header")Signed-off-by Eric Dumazet <[email protected]>Cc Alexander Duyck <[email protected]>--- net/ipv4/tcp_offload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/ipv4/tcp_offload.c index renamed from net/ipv4/tcp_offload.c +0
-0
45dda788938704c3f762256266d9ea29b6ded4a5..5a1a163b2d859696df8f204b50e3fc76c14b64e9100644
net/ipv4/tcp_offload.c struct sk_buff *tcp_gso_segment(struct sk_buff *skb, · line 82
Quoted 9 lines
net/ipv4/tcp_offload.c +2
-1@@ -75,7 +75,8 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,if (!pskb_may_pull (skb, thlen)) goto out; - oldlen = (u16 )~skb->len; +/* Contribution of skb->len in current TCP checksum */ + oldlen = (__force u32 )csum_fold ((__force __wsum )skb->len);__skb_pull (skb, thlen); mss =skb_shinfo (skb)->gso_size;
The only thing I am not sure about with this change is if we risk overflowing a u32 with all the math that may occur. The original code couldn't exceed a u16 for delta since we were essentially adding -oldlen + new header + mss. With us now allowing the use of a value larger than 16 bit we should be able to have the resultant value exceed 16b which means we might overflow when we add it to the current checksum.
As such we may want to look at holding off on the csum_fold until after we have added the new header and mss and then store the folded value in delta.
Quoted 50 lines · Alexander Duyck
Quoted 50 lines
-----Original Message-----
From: Eric Dumazet <[email protected]>
Sent: Thursday, June 1, 2023 2:18 PM
To: David S . Miller <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>
Cc: [email protected]; Xin Long <[email protected]>; David Ahern <[email protected]>; [email protected]; Eric Dumazet <[email protected]>; Alexander Duyck <[email protected]>
Subject: [PATCH net] tcp: gso: really support BIG TCPQuoted 1 line
We missed that
tcp_gso_segment()was assumingskb->lenwas smaller than 65535 :oldlen = (u16)~skb->len;
This part came with commit
0718bcc09b35("[NET]: FixCHECKSUM_HWGSO problems.")This leads to wrong TCP checksum.
Simply use
csum_fold()to support 32bit packet lengthes.oldlen name is a bit misleading, as it is the contribution of
skb->lenon the input skb TCP checksum. I added a comment to clarify this point.Fixes 09f3d1a3a52c ("ipv6/gso: remove temporary HBH/jumbo header")Signed-off-by Eric Dumazet <[email protected]>Cc Alexander Duyck <[email protected]>--- net/ipv4/tcp_offload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/ipv4/tcp_offload.c index renamed from net/ipv4/tcp_offload.c +0
-0
45dda788938704c3f762256266d9ea29b6ded4a5..5a1a163b2d859696df8f204b50e3fc76c14b64e9100644net/ipv4/tcp_offload.c +2
-1@@ -75,7 +75,8 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,if (!pskb_may_pull (skb, thlen)) goto out; - oldlen = (u16 )~skb->len; +/* Contribution of skb->len in current TCP checksum */ + oldlen = (__force u32 )csum_fold ((__force __wsum )skb->len);__skb_pull (skb, thlen);
Quoted 6 lines
net/ipv4/tcp_offload.c struct sk_buff *tcp_gso_segment(struct sk_buff *skb, · line 82
Quoted 1 line
net/ipv4/tcp_offload.c +0
-0mss =skb_shinfo (skb)->gso_size;The only thing I am not sure about with this change is if we risk overflowing a u32 with all the math that may occur. The original code couldn't exceed a u16 for delta since we were essentially adding -oldlen + new header + mss. With us now allowing the use of a value larger than 16 bit we should be able to have the resultant value exceed 16b which means we might overflow when we add it to the current checksum.
As such we may want to look at holding off on the
csum_folduntil after we have added the new header and mss and then store the folded value in delta.
I think you missed that csum_fold() result is also a 16bit value.
Logic Herbert added years ago will work the same.
Here is the pure C implementation of csum_fold(), I hope this will clear your concerns.
static inline __sum16 csum_fold(__wsum csum)
{
u32 sum = (__force u32)csum;
sum = (sum & 0xffff) + (sum >> 16);
sum = (sum & 0xffff) + (sum >> 16);
return (__force __sum16)~sum;
}TCP ipv6 stack populates th->check with tcp_v6_send_check() ->
__tcp_v6_send_check(skb, &sk->sk_v6_rcv_saddr, &sk->sk_v6_daddr);
->
th->check = ~tcp_v6_check(skb->len, saddr, daddr, 0);
Thanks !
Quoted 51 lines · Eric Dumazet
Quoted 50 lines · Alexander Duyck
Quoted 50 lines
-----Original Message-----
From: Eric Dumazet <[email protected]>
Sent: Thursday, June 1, 2023 2:18 PM
To: David S . Miller <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>
Cc: [email protected]; Xin Long <[email protected]>; David Ahern <[email protected]>; [email protected]; Eric Dumazet <[email protected]>; Alexander Duyck <[email protected]>
Subject: [PATCH net] tcp: gso: really support BIG TCPQuoted 1 line
We missed that
tcp_gso_segment()was assumingskb->lenwas smaller than 65535 :oldlen = (u16)~skb->len;
This part came with commit
0718bcc09b35("[NET]: FixCHECKSUM_HWGSO problems.")This leads to wrong TCP checksum.
Simply use
csum_fold()to support 32bit packet lengthes.oldlen name is a bit misleading, as it is the contribution of
skb->lenon the input skb TCP checksum. I added a comment to clarify this point.Fixes 09f3d1a3a52c ("ipv6/gso: remove temporary HBH/jumbo header")Signed-off-by Eric Dumazet <[email protected]>Cc Alexander Duyck <[email protected]>--- net/ipv4/tcp_offload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/ipv4/tcp_offload.c index renamed from net/ipv4/tcp_offload.c +0
-0
45dda788938704c3f762256266d9ea29b6ded4a5..5a1a163b2d859696df8f204b50e3fc76c14b64e9100644net/ipv4/tcp_offload.c +2
-1@@ -75,7 +75,8 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,if (!pskb_may_pull (skb, thlen)) goto out; - oldlen = (u16 )~skb->len; +/* Contribution of skb->len in current TCP checksum */ + oldlen = (__force u32 )csum_fold ((__force __wsum )skb->len);__skb_pull (skb, thlen);
Quoted 8 lines
Quoted 6 lines
net/ipv4/tcp_offload.c struct sk_buff *tcp_gso_segment(struct sk_buff *skb, · line 82
Quoted 1 line
net/ipv4/tcp_offload.c +0
-0mss =skb_shinfo (skb)->gso_size;The only thing I am not sure about with this change is if we risk overflowing a u32 with all the math that may occur. The original code couldn't exceed a u16 for delta since we were essentially adding -oldlen + new header + mss. With us now allowing the use of a value larger than 16 bit we should be able to have the resultant value exceed 16b which means we might overflow when we add it to the current checksum.
As such we may want to look at holding off on the
csum_folduntil after we have added the new header and mss and then store the folded value in delta.I think you missed that
csum_fold()result is also a 16bit value.
I saw that. My concern was more about delta versus the oldlen value itself though. Specifically your folded value is added to thlen + mss which can then overflow past a 16b value, and when byteswapped and then added to the original checksum there is a risk of potential overflow.
The general idea was that ~skb->len + (segment length) will always technically be less than 0 since the original skb->len should always be larger or equal to the new segmented length. So the code as it was would always generate a value 16 or less in length.
This was important when we computed delta and added it to the original value since we were using htonl which would byteswap things so we could potentially generate a 32b value, but it couldn't overflow since the two addends consisted of the upper 16b and lower 16b.
That is why I am thinking we are better off just dropping the "(u16)" cast and just passing ~skb->len as the old_len.
To address this we then have a couple different approaches we could take:
1. use csum_fold on the "delta" value either before or after the htonl.
2. use csum_add instead "+" for the addition of (th->check + delta)
I'm thinking option 2 may be the better way to go as it would just add 2 addc operations, one for newcheck and one at the end of the function for th->check.
Quoted 60 lines · Alexander H Duyck
Quoted 58 lines · Eric Dumazet
Quoted 56 lines · Alexander Duyck
Quoted 42 lines
-----Original Message-----
From: Eric Dumazet <[email protected]>
Sent: Thursday, June 1, 2023 2:18 PM
To: David S . Miller <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>
Cc: [email protected]; Xin Long <[email protected]>; David Ahern <[email protected]>; [email protected]; Eric Dumazet <[email protected]>; Alexander Duyck <[email protected]>
Subject: [PATCH net] tcp: gso: really support BIG TCPQuoted 1 line
We missed that
tcp_gso_segment()was assumingskb->lenwas smaller than 65535 :oldlen = (u16)~skb->len;
This part came with commit
0718bcc09b35("[NET]: FixCHECKSUM_HWGSO problems.")This leads to wrong TCP checksum.
Simply use
csum_fold()to support 32bit packet lengthes.oldlen name is a bit misleading, as it is the contribution of
skb->lenon the input skb TCP checksum. I added a comment to clarify this point.Fixes 09f3d1a3a52c ("ipv6/gso: remove temporary HBH/jumbo header")Signed-off-by Eric Dumazet <[email protected]>Cc Alexander Duyck <[email protected]>--- net/ipv4/tcp_offload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/ipv4/tcp_offload.c index renamed from net/ipv4/tcp_offload.c +0
-0
45dda788938704c3f762256266d9ea29b6ded4a5..5a1a163b2d859696df8f204b50e3fc76c14b64e9100644net/ipv4/tcp_offload.c struct sk_buff *tcp_gso_segment(struct sk_buff *skb, · line 82
Quoted 9 lines
net/ipv4/tcp_offload.c +2
-1@@ -75,7 +75,8 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,if (!pskb_may_pull (skb, thlen)) goto out; - oldlen = (u16 )~skb->len; +/* Contribution of skb->len in current TCP checksum */ + oldlen = (__force u32 )csum_fold ((__force __wsum )skb->len);__skb_pull (skb, thlen); mss =skb_shinfo (skb)->gso_size;The only thing I am not sure about with this change is if we risk overflowing a u32 with all the math that may occur. The original code couldn't exceed a u16 for delta since we were essentially adding -oldlen + new header + mss. With us now allowing the use of a value larger than 16 bit we should be able to have the resultant value exceed 16b which means we might overflow when we add it to the current checksum.
As such we may want to look at holding off on the
csum_folduntil after we have added the new header and mss and then store the folded value in delta.
Quoted 6 lines
Quoted 1 line
I think you missed that
csum_fold()result is also a 16bit value.I saw that. My concern was more about delta versus the oldlen value itself though. Specifically your folded value is added to thlen + mss which can then overflow past a 16b value, and when byteswapped and then added to the original checksum there is a risk of potential overflow.
I do not think it matters. Herbert Xu said that what matters is that
oldlen + (thlen + mss) would not overflow a 32bit value./
Quoted 14 lines
The general idea was that ~skb->len + (segment length) will always technically be less than 0 since the original
skb->lenshould always be larger or equal to the new segmented length. So the code as it was would always generate a value 16 or less in length.This was important when we computed delta and added it to the original value since we were using htonl which would byteswap things so we could potentially generate a 32b value, but it couldn't overflow since the two addends consisted of the upper 16b and lower 16b.
That is why I am thinking we are better off just dropping the "(u16)" cast and just passing ~skb->len as the
old_len.
Quoted 8 lines
To address this we then have a couple different approaches we could take:
1. usecsum_foldon the "delta" value either before or after the htonl.
2. usecsum_addinstead "+" for the addition of (th->check+ delta)I'm thinking option 2 may be the better way to go as it would just add 2 addc operations, one for newcheck and one at the end of the function for
th->check.
Are you working on a patch yourself ? What would be the ETA ?
Thanks.
Quoted 93 lines · Eric Dumazet
Quoted 60 lines · Alexander H Duyck
Quoted 58 lines · Eric Dumazet
Quoted 56 lines · Alexander Duyck
Quoted 42 lines
-----Original Message-----
From: Eric Dumazet <[email protected]>
Sent: Thursday, June 1, 2023 2:18 PM
To: David S . Miller <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>
Cc: [email protected]; Xin Long <[email protected]>; David Ahern <[email protected]>; [email protected]; Eric Dumazet <[email protected]>; Alexander Duyck <[email protected]>
Subject: [PATCH net] tcp: gso: really support BIG TCPQuoted 1 line
We missed that
tcp_gso_segment()was assumingskb->lenwas smaller than 65535 :oldlen = (u16)~skb->len;
This part came with commit
0718bcc09b35("[NET]: FixCHECKSUM_HWGSO problems.")This leads to wrong TCP checksum.
Simply use
csum_fold()to support 32bit packet lengthes.oldlen name is a bit misleading, as it is the contribution of
skb->lenon the input skb TCP checksum. I added a comment to clarify this point.Fixes 09f3d1a3a52c ("ipv6/gso: remove temporary HBH/jumbo header")Signed-off-by Eric Dumazet <[email protected]>Cc Alexander Duyck <[email protected]>--- net/ipv4/tcp_offload.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)net/ipv4/tcp_offload.c index renamed from net/ipv4/tcp_offload.c +0
-0
45dda788938704c3f762256266d9ea29b6ded4a5..5a1a163b2d859696df8f204b50e3fc76c14b64e9100644net/ipv4/tcp_offload.c struct sk_buff *tcp_gso_segment(struct sk_buff *skb, · line 82
Quoted 9 lines
net/ipv4/tcp_offload.c +2
-1@@ -75,7 +75,8 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,if (!pskb_may_pull (skb, thlen)) goto out; - oldlen = (u16 )~skb->len; +/* Contribution of skb->len in current TCP checksum */ + oldlen = (__force u32 )csum_fold ((__force __wsum )skb->len);__skb_pull (skb, thlen); mss =skb_shinfo (skb)->gso_size;The only thing I am not sure about with this change is if we risk overflowing a u32 with all the math that may occur. The original code couldn't exceed a u16 for delta since we were essentially adding -oldlen + new header + mss. With us now allowing the use of a value larger than 16 bit we should be able to have the resultant value exceed 16b which means we might overflow when we add it to the current checksum.
As such we may want to look at holding off on the
csum_folduntil after we have added the new header and mss and then store the folded value in delta.Quoted 6 lines
Quoted 1 line
I think you missed that
csum_fold()result is also a 16bit value.I saw that. My concern was more about delta versus the oldlen value itself though. Specifically your folded value is added to thlen + mss which can then overflow past a 16b value, and when byteswapped and then added to the original checksum there is a risk of potential overflow.
I do not think it matters. Herbert Xu said that what matters is that
oldlen + (thlen + mss) would not overflow a 32bit value./
Quoted 19 lines
The general idea was that ~skb->len + (segment length) will always technically be less than 0 since the original
skb->lenshould always be larger or equal to the new segmented length. So the code as it was would always generate a value 16 or less in length.This was important when we computed delta and added it to the original value since we were using htonl which would byteswap things so we could potentially generate a 32b value, but it couldn't overflow since the two addends consisted of the upper 16b and lower 16b.
That is why I am thinking we are better off just dropping the "(u16)" cast and just passing ~skb->len as the
old_len.To address this we then have a couple different approaches we could take:
1. usecsum_foldon the "delta" value either before or after the htonl.
2. usecsum_addinstead "+" for the addition of (th->check+ delta)
Quoted 7 lines
Quoted 3 lines
I'm thinking option 2 may be the better way to go as it would just add 2 addc operations, one for newcheck and one at the end of the function for
th->check.Are you working on a patch yourself ? What would be the ETA ?
Thanks.
To be clear, I spent a lot of time trying to code something like the following, then I chose a much simpler solution (patch as you see it)
This was the WIP (and not working at all)
net/ipv4/tcp_offload.c +0 -0
100644
net/ipv4/tcp_offload.c +6 -6
@@ -60,11 +60,11 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb, {struct sk_buff *segs =ERR_PTR (-EINVAL );unsigned int sum_truesize =0 ; +unsigned int oldlen, newlen;struct tcphdr *th;unsigned int thlen;unsigned int seq; -__be32 delta; -unsigned int oldlen; +__wsum delta;unsigned int mss;struct sk_buff *gso_skb = skb;__sum16 newcheck;
@@ -78,7 +78,7 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,if (!pskb_may_pull (skb, thlen)) goto out; - oldlen = (u16 )~skb->len; + oldlen = skb->len;__skb_pull (skb, thlen); mss =skb_shinfo (skb)->gso_size;
@@ -113,7 +113,9 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,if (skb_is_gso (segs)) mss *=skb_shinfo (segs)->gso_segs; - delta =htonl (oldlen + (thlen + mss)); + newlen = thlen + mss; + delta =csum_sub (htonl (newlen),htonl (oldlen)); + newcheck =csum_fold (csum_add (csum_unfold (th->check), delta)); skb = segs; th =tcp_hdr (skb);
@@ -122,8 +124,6 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,if (unlikely (skb_shinfo (gso_skb)->tx_flags &SKBTX_SW_TSTAMP ))tcp_gso_tstamp (segs,skb_shinfo (gso_skb)->tskey, seq, mss); - newcheck = ~csum_fold ((__force __wsum)((__force u32 )th->check + - (__force u32 )delta));while (skb->next) { th->fin = th->psh =0 ;
@@ -168,11 +168,11 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb, WARN_ON_ONCE(refcount_sub_and_test(-delta,
&skb->sk->sk_wmem_alloc));
}- delta = htonl(oldlen + (skb_tail_pointer(skb) -
- skb_transport_header(skb)) +
- skb->data_len);
- th->check = ~csum_fold((__force __wsum)((__force u32)th->check +
- (__force u32)delta));
+ newlen = skb_tail_pointer(skb) - skb_transport_header(skb) +
+ skb->data_len;
+ delta = csum_sub(htonl(newlen), htonl(oldlen));
+ th->check = csum_fold(csum_add(csum_unfold(th->check), delta));
+
if (skb->ip_summed == CHECKSUM_PARTIAL)
gso_reset_checksum(skb, ~th->check);
elseOn Fri, Jun 2, 2023 at 8:25 AM Eric Dumazet <[email protected]> wrote:
<...>
Quoted 1 line
This was the WIP (and not working at all)
This is way more than what I was thinking Some of what I had stated was just pseudocode. No need for the addition of newlen for instance.
Quoted 9 lines
net/ipv4/tcp_offload.c +0
-0100644
net/ipv4/tcp_offload.c +0
-0@@ -60,11 +60,11 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb, {struct sk_buff *segs =ERR_PTR (-EINVAL );unsigned int sum_truesize =0 ;
net/ipv4/tcp_offload.c struct sk_buff *tcp_gso_segment(struct sk_buff *skb, · line 70
Quoted 10 lines
net/ipv4/tcp_offload.c +2
-2+unsigned int oldlen, newlen;struct tcphdr *th;unsigned int thlen;unsigned int seq; -__be32 delta; -unsigned int oldlen; +__wsum delta;unsigned int mss;struct sk_buff *gso_skb = skb;__sum16 newcheck;
I wouldn't even bother with any of these changes.
net/ipv4/tcp_offload.c struct sk_buff *tcp_gso_segment(struct sk_buff *skb, · line 84
Quoted 9 lines
net/ipv4/tcp_offload.c +1
-1@@ -78,7 +78,7 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,if (!pskb_may_pull (skb, thlen)) goto out; - oldlen = (u16 )~skb->len; + oldlen = skb->len;__skb_pull (skb, thlen); mss =skb_shinfo (skb)->gso_size;
As I stated before I would just drop the "(u16)". We are expanding the oldlen to a u32, but don't have to worry about it overflowing because skb->len should always be greater than or equal to our segmented length. So the most it could reach is ~0 if skb->len == segmented length.
net/ipv4/tcp_offload.c struct sk_buff *tcp_gso_segment(struct sk_buff *skb, · line 121
Quoted 11 lines
net/ipv4/tcp_offload.c +3
-1@@ -113,7 +113,9 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,if (skb_is_gso (segs)) mss *=skb_shinfo (segs)->gso_segs; - delta =htonl (oldlen + (thlen + mss)); + newlen = thlen + mss; + delta =csum_sub (htonl (newlen),htonl (oldlen)); + newcheck =csum_fold (csum_add (csum_unfold (th->check), delta)); skb = segs; th =tcp_hdr (skb)
I think all of this can just be dropped.
net/ipv4/tcp_offload.c struct sk_buff *tcp_gso_segment(struct sk_buff *skb, · line 129
Quoted 9 lines
net/ipv4/tcp_offload.c +0
-2@@ -122,8 +124,6 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,if (unlikely (skb_shinfo (gso_skb)->tx_flags &SKBTX_SW_TSTAMP ))tcp_gso_tstamp (segs,skb_shinfo (gso_skb)->tskey, seq, mss); - newcheck = ~csum_fold ((__force __wsum)((__force u32 )th->check + - (__force u32 )delta));while (skb->next) { th->fin = th->psh =0 ;
So the change I would make here is:
newcheck = ~csum_fold(csum_add(csum_unfold(th->check, ()), (__force __wsum)delta);
Quoted 17 lines
net/ipv4/tcp_offload.c +5
-5@@ -168,11 +168,11 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,WARN_ON_ONCE (refcount_sub_and_test (-delta, &skb->sk->sk_wmem_alloc)); } - delta =htonl (oldlen + (skb_tail_pointer (skb) - -skb_transport_header (skb)) + - skb->data_len); - th->check = ~csum_fold ((__force __wsum)((__force u32 )th->check + - (__force u32 )delta)); + newlen =skb_tail_pointer (skb) -skb_transport_header (skb) + + skb->data_len; + delta =csum_sub (htonl (newlen),htonl (oldlen)); + th->check =csum_fold (csum_add (csum_unfold (th->check), delta)); +if (skb->ip_summed ==CHECKSUM_PARTIAL )gso_reset_checksum (skb, ~th->check);
Quoted 1 line
else
Likewise here, the only thing that has to be replaced is the th->check line so it would be:th->check = ~csum_fold(csum_add(csum_unfold(th->check, ()), (__force __wsum)delta);
From: Alexander Duyck
Quoted 1 line
Sent: 02 June 2023 16:39
...
Quoted 10 lines
I wouldn't even bother with any of these changes.
Quoted 8 lines
net/ipv4/tcp_offload.c +1
-1@@ -78,7 +78,7 @@ struct sk_buff *tcp_gso_segment(struct sk_buff *skb,if (!pskb_may_pull (skb, thlen)) goto out; - oldlen = (u16 )~skb->len; + oldlen = skb->len;__skb_pull (skb, thlen);
Quoted 7 lines
net/ipv4/tcp_offload.c struct sk_buff *tcp_gso_segment(struct sk_buff *skb, · line 84
Quoted 1 line
net/ipv4/tcp_offload.c +0
-0mss =skb_shinfo (skb)->gso_size;As I stated before I would just drop the "(u16)". We are expanding the oldlen to a u32, but don't have to worry about it overflowing because
skb->lenshould always be greater than or equal to our segmented length. So the most it could reach is ~0 ifskb->len== segmented length.
Have you missed the ~ ?
The (u16) makes it equivalent to skb->len ^ 0xffff. Otherwise all the high bit are set and any arithmetic will generate a carry and the wrong value.
FWIW this C version of csum_fold() (eg from arch/arc) generates better code than the existing versions on pretty much every architecture.
return (~sum - ror32(sum, 16)) >> 16;
The main exception will be sparc (which has a carry flag but no rotate) and arm with its barrel shifter.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)