Re: [PATCH net-next 2/2] net: optimize skb_postpull_rcsum()
From: Eric Dumazet <edumazet@google.com>
Date: 2021-12-02 15:22:31
On Thu, Dec 2, 2021 at 7:06 AM David Laight [off-list ref] wrote:
From: Vladimir Olteanquoted
Sent: 02 December 2021 13:11...quoted
quoted
--- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h@@ -3485,7 +3485,11 @@ __skb_postpull_rcsum(struct sk_buff *skb, const void *start, unsigned intlen,quoted
static inline void skb_postpull_rcsum(struct sk_buff *skb, const void *start, unsigned int len) { - __skb_postpull_rcsum(skb, start, len, 0); + if (skb->ip_summed == CHECKSUM_COMPLETE) + skb->csum = ~csum_partial(start, len, ~skb->csum);You can't do that, the domain is 1..0xffff (or maybe 0xffffffff). The invert has to convert ~0 to ~0 not zero. ...quoted
There seems to be a disparity when the skb->csum is calculated by skb_postpull_rcsum as zero. Before, it was calculated as 0xffff.Which is what that will do for some inputs at least. Maybe: skb->csum = 1 + ~csum_partial(start, len, ~skb->csum + 1); is right. I think that is the same as: skb->csum = -csum_partial(start, len, -skb->csum); Although letting the compiler do that transform probably makes the code easier to read.
Interesting, update_csum_diff4() and update_csum_diff16() seem to both use. skb->csum = ~csum_partial((char *)diff, sizeof(diff), ~skb->csum);