kernel: update fraglist GRO patch to the latest upstream submission
[openwrt/staging/pepe2k.git] / target / linux / generic / pending-6.1 / 680-net-add-TCP-fraglist-GRO-support.patch
index 13043729c3ab23c5734b6611748a5a5a687c2bc6..841c0de3e1b8a4f3537fdc839432c5fb7ccdd8f3 100644 (file)
@@ -130,36 +130,38 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
  {
 --- a/net/ipv4/tcp_offload.c
 +++ b/net/ipv4/tcp_offload.c
-@@ -27,6 +27,68 @@ static void tcp_gso_tstamp(struct sk_buf
+@@ -27,6 +27,70 @@ static void tcp_gso_tstamp(struct sk_buf
        }
  }
  
 +static void __tcpv4_gso_segment_csum(struct sk_buff *seg,
-+                                   __be32 *oldip, __be32 *newip,
-+                                   __be16 *oldport, __be16 *newport)
++                                   __be32 *oldip, __be32 newip,
++                                   __be16 *oldport, __be16 newport)
 +{
 +      struct tcphdr *th;
 +      struct iphdr *iph;
 +
-+      if (*oldip == *newip && *oldport == *newport)
++      if (*oldip == newip && *oldport == newport)
 +              return;
 +
 +      th = tcp_hdr(seg);
 +      iph = ip_hdr(seg);
 +
-+      inet_proto_csum_replace4(&th->check, seg, *oldip, *newip, true);
-+      inet_proto_csum_replace2(&th->check, seg, *oldport, *newport, false);
-+      *oldport = *newport;
++      inet_proto_csum_replace4(&th->check, seg, *oldip, newip, true);
++      inet_proto_csum_replace2(&th->check, seg, *oldport, newport, false);
++      *oldport = newport;
 +
-+      csum_replace4(&iph->check, *oldip, *newip);
-+      *oldip = *newip;
++      csum_replace4(&iph->check, *oldip, newip);
++      *oldip = newip;
 +}
 +
 +static struct sk_buff *__tcpv4_gso_segment_list_csum(struct sk_buff *segs)
 +{
++      const struct tcphdr *th;
++      const struct iphdr *iph;
 +      struct sk_buff *seg;
-+      struct tcphdr *th, *th2;
-+      struct iphdr *iph, *iph2;
++      struct tcphdr *th2;
++      struct iphdr *iph2;
 +
 +      seg = segs;
 +      th = tcp_hdr(seg);
@@ -167,7 +169,7 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
 +      th2 = tcp_hdr(seg->next);
 +      iph2 = ip_hdr(seg->next);
 +
-+      if (!(*(u32 *)&th->source ^ *(u32 *)&th2->source) &&
++      if (!(*(const u32 *)&th->source ^ *(const u32 *)&th2->source) &&
 +          iph->daddr == iph2->daddr && iph->saddr == iph2->saddr)
 +              return segs;
 +
@@ -176,11 +178,11 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
 +              iph2 = ip_hdr(seg);
 +
 +              __tcpv4_gso_segment_csum(seg,
-+                                       &iph2->saddr, &iph->saddr,
-+                                       &th2->source, &th->source);
++                                       &iph2->saddr, iph->saddr,
++                                       &th2->source, th->source);
 +              __tcpv4_gso_segment_csum(seg,
-+                                       &iph2->daddr, &iph->daddr,
-+                                       &th2->dest, &th->dest);
++                                       &iph2->daddr, iph->daddr,
++                                       &th2->dest, th->dest);
 +      }
 +
 +      return segs;
@@ -199,7 +201,7 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
  static struct sk_buff *tcp4_gso_segment(struct sk_buff *skb,
                                        netdev_features_t features)
  {
-@@ -36,6 +98,9 @@ static struct sk_buff *tcp4_gso_segment(
+@@ -36,6 +100,9 @@ static struct sk_buff *tcp4_gso_segment(
        if (!pskb_may_pull(skb, sizeof(struct tcphdr)))
                return ERR_PTR(-EINVAL);
  
@@ -209,7 +211,7 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
        if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
                const struct iphdr *iph = ip_hdr(skb);
                struct tcphdr *th = tcp_hdr(skb);
-@@ -177,61 +242,76 @@ out:
+@@ -177,61 +244,76 @@ out:
        return segs;
  }
  
@@ -316,15 +318,14 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
        flush = NAPI_GRO_CB(p)->flush;
        flush |= (__force int)(flags & TCP_FLAG_CWR);
        flush |= (__force int)((flags ^ tcp_flag_word(th2)) &
-@@ -268,6 +348,19 @@ found:
+@@ -268,6 +350,18 @@ found:
        flush |= p->decrypted ^ skb->decrypted;
  #endif
  
-+      if (NAPI_GRO_CB(p)->is_flist) {
++      if (unlikely(NAPI_GRO_CB(p)->is_flist)) {
 +              flush |= (__force int)(flags ^ tcp_flag_word(th2));
 +              flush |= skb->ip_summed != p->ip_summed;
 +              flush |= skb->csum_level != p->csum_level;
-+              flush |= !pskb_may_pull(skb, skb_gro_offset(skb));
 +              flush |= NAPI_GRO_CB(p)->count >= 64;
 +
 +              if (flush || skb_gro_receive_list(p, skb))
@@ -336,7 +337,7 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
        if (flush || skb_gro_receive(p, skb)) {
                mss = 1;
                goto out_check_final;
-@@ -289,7 +382,6 @@ out_check_final:
+@@ -289,7 +383,6 @@ out_check_final:
        if (p && (!NAPI_GRO_CB(skb)->same_flow || flush))
                pp = p;
  
@@ -344,17 +345,17 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
        NAPI_GRO_CB(skb)->flush |= (flush != 0);
  
        return pp;
-@@ -315,18 +407,56 @@ int tcp_gro_complete(struct sk_buff *skb
+@@ -315,18 +408,58 @@ int tcp_gro_complete(struct sk_buff *skb
  }
  EXPORT_SYMBOL(tcp_gro_complete);
  
 +static void tcp4_check_fraglist_gro(struct list_head *head, struct sk_buff *skb,
 +                                  struct tcphdr *th)
 +{
-+      const struct iphdr *iph = skb_gro_network_header(skb);
-+      struct net *net = dev_net(skb->dev);
++      const struct iphdr *iph;
 +      struct sk_buff *p;
 +      struct sock *sk;
++      struct net *net;
 +      int iif, sdif;
 +
 +      if (!(skb->dev->features & NETIF_F_GRO_FRAGLIST))
@@ -367,6 +368,8 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
 +      }
 +
 +      inet_get_iif_sdif(skb, &iif, &sdif);
++      iph = skb_gro_network_header(skb);
++      net = dev_net(skb->dev);
 +      sk = __inet_lookup_established(net, net->ipv4.tcp_death_row.hashinfo,
 +                                     iph->saddr, th->source,
 +                                     iph->daddr, ntohs(th->dest),
@@ -406,11 +409,11 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
  }
  
  INDIRECT_CALLABLE_SCOPE int tcp4_gro_complete(struct sk_buff *skb, int thoff)
-@@ -334,6 +464,15 @@ INDIRECT_CALLABLE_SCOPE int tcp4_gro_com
+@@ -334,6 +467,15 @@ INDIRECT_CALLABLE_SCOPE int tcp4_gro_com
        const struct iphdr *iph = ip_hdr(skb);
        struct tcphdr *th = tcp_hdr(skb);
  
-+      if (NAPI_GRO_CB(skb)->is_flist) {
++      if (unlikely(NAPI_GRO_CB(skb)->is_flist)) {
 +              skb_shinfo(skb)->gso_type |= SKB_GSO_FRAGLIST | SKB_GSO_TCPV4;
 +              skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count;
 +
@@ -460,7 +463,7 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
  static struct sk_buff *udp_gro_receive_segment(struct list_head *head,
 --- a/net/ipv6/tcpv6_offload.c
 +++ b/net/ipv6/tcpv6_offload.c
-@@ -7,24 +7,65 @@
+@@ -7,24 +7,67 @@
   */
  #include <linux/indirect_call_wrapper.h>
  #include <linux/skbuff.h>
@@ -475,10 +478,10 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
 +                                  struct tcphdr *th)
 +{
 +#if IS_ENABLED(CONFIG_IPV6)
-+      const struct ipv6hdr *hdr = skb_gro_network_header(skb);
-+      struct net *net = dev_net(skb->dev);
++      const struct ipv6hdr *hdr;
 +      struct sk_buff *p;
 +      struct sock *sk;
++      struct net *net;
 +      int iif, sdif;
 +
 +      if (!(skb->dev->features & NETIF_F_GRO_FRAGLIST))
@@ -491,6 +494,8 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
 +      }
 +
 +      inet6_get_iif_sdif(skb, &iif, &sdif);
++      hdr = skb_gro_network_header(skb);
++      net = dev_net(skb->dev);
 +      sk = __inet6_lookup_established(net, net->ipv4.tcp_death_row.hashinfo,
 +                                      &hdr->saddr, th->source,
 +                                      &hdr->daddr, ntohs(th->dest),
@@ -531,11 +536,11 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
  }
  
  INDIRECT_CALLABLE_SCOPE int tcp6_gro_complete(struct sk_buff *skb, int thoff)
-@@ -32,6 +73,15 @@ INDIRECT_CALLABLE_SCOPE int tcp6_gro_com
+@@ -32,6 +75,15 @@ INDIRECT_CALLABLE_SCOPE int tcp6_gro_com
        const struct ipv6hdr *iph = ipv6_hdr(skb);
        struct tcphdr *th = tcp_hdr(skb);
  
-+      if (NAPI_GRO_CB(skb)->is_flist) {
++      if (unlikely(NAPI_GRO_CB(skb)->is_flist)) {
 +              skb_shinfo(skb)->gso_type |= SKB_GSO_FRAGLIST | SKB_GSO_TCPV6;
 +              skb_shinfo(skb)->gso_segs = NAPI_GRO_CB(skb)->count;
 +
@@ -547,12 +552,74 @@ Signe-off-by: Felix Fietkau <nbd@nbd.name>
        th->check = ~tcp_v6_check(skb->len - thoff, &iph->saddr,
                                  &iph->daddr, 0);
        skb_shinfo(skb)->gso_type |= SKB_GSO_TCPV6;
-@@ -50,6 +100,9 @@ static struct sk_buff *tcp6_gso_segment(
+@@ -39,6 +91,61 @@ INDIRECT_CALLABLE_SCOPE int tcp6_gro_com
+       return tcp_gro_complete(skb);
+ }
++static void __tcpv6_gso_segment_csum(struct sk_buff *seg,
++                                   __be16 *oldport, __be16 newport)
++{
++      struct tcphdr *th;
++
++      if (*oldport == newport)
++              return;
++
++      th = tcp_hdr(seg);
++      inet_proto_csum_replace2(&th->check, seg, *oldport, newport, false);
++      *oldport = newport;
++}
++
++static struct sk_buff *__tcpv6_gso_segment_list_csum(struct sk_buff *segs)
++{
++      const struct tcphdr *th;
++      const struct ipv6hdr *iph;
++      struct sk_buff *seg;
++      struct tcphdr *th2;
++      struct ipv6hdr *iph2;
++
++      seg = segs;
++      th = tcp_hdr(seg);
++      iph = ipv6_hdr(seg);
++      th2 = tcp_hdr(seg->next);
++      iph2 = ipv6_hdr(seg->next);
++
++      if (!(*(const u32 *)&th->source ^ *(const u32 *)&th2->source) &&
++          ipv6_addr_equal(&iph->saddr, &iph2->saddr) &&
++          ipv6_addr_equal(&iph->daddr, &iph2->daddr))
++              return segs;
++
++      while ((seg = seg->next)) {
++              th2 = tcp_hdr(seg);
++              iph2 = ipv6_hdr(seg);
++
++              iph2->saddr = iph->saddr;
++              iph2->daddr = iph->daddr;
++              __tcpv6_gso_segment_csum(seg, &th2->source, th->source);
++              __tcpv6_gso_segment_csum(seg, &th2->dest, th->dest);
++      }
++
++      return segs;
++}
++
++static struct sk_buff *__tcp6_gso_segment_list(struct sk_buff *skb,
++                                            netdev_features_t features)
++{
++      skb = skb_segment_list(skb, features, skb_mac_header_len(skb));
++      if (IS_ERR(skb))
++              return skb;
++
++      return __tcpv6_gso_segment_list_csum(skb);
++}
++
+ static struct sk_buff *tcp6_gso_segment(struct sk_buff *skb,
+                                       netdev_features_t features)
+ {
+@@ -50,6 +157,9 @@ static struct sk_buff *tcp6_gso_segment(
        if (!pskb_may_pull(skb, sizeof(*th)))
                return ERR_PTR(-EINVAL);
  
 +      if (skb_shinfo(skb)->gso_type & SKB_GSO_FRAGLIST)
-+              return skb_segment_list(skb, features, skb_mac_header_len(skb));
++              return __tcp6_gso_segment_list(skb, features);
 +
        if (unlikely(skb->ip_summed != CHECKSUM_PARTIAL)) {
                const struct ipv6hdr *ipv6h = ipv6_hdr(skb);