On Thu, May 25, 2023 at 10:40:51PM +0200, Jan Klemkow wrote:
> On Wed, May 24, 2023 at 05:28:58PM +0200, Alexander Bluhm wrote:
> > On Tue, May 23, 2023 at 02:14:57PM +0200, Jan Klemkow wrote:
> > > This diff sets needed offloading flags and the calculated mss to LRO
> > > mbufs in ix(4).  Thus, we can forward this packets and process them via
> > > tcp_if_output_tso().  This diff also uses tcp_if_output_tso() in
> > > ip6_forward().

After lot of testing by Hrvoje and fixing corner cases with Jan,
this is the diff we currently have.  There a no more known problems
with TCP large receive offloading.

ok?

bluhm

Index: dev/pci/if_ix.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/dev/pci/if_ix.c,v
retrieving revision 1.196
diff -u -p -r1.196 if_ix.c
--- dev/pci/if_ix.c     23 May 2023 09:16:16 -0000      1.196
+++ dev/pci/if_ix.c     31 May 2023 13:48:25 -0000
@@ -3245,6 +3245,8 @@ ixgbe_rxeof(struct rx_ring *rxr)
                        sendmp = NULL;
                        mp->m_next = nxbuf->buf;
                } else { /* Sending this frame? */
+                       uint16_t pkts;
+
                        ixgbe_rx_checksum(staterr, sendmp);
 
                        if (hashtype != IXGBE_RXDADV_RSSTYPE_NONE) {
@@ -3252,19 +3254,45 @@ ixgbe_rxeof(struct rx_ring *rxr)
                                SET(sendmp->m_pkthdr.csum_flags, M_FLOWID);
                        }
 
-                       if (sendmp->m_pkthdr.ph_mss == 1)
-                               sendmp->m_pkthdr.ph_mss = 0;
+                       pkts = sendmp->m_pkthdr.ph_mss;
+                       sendmp->m_pkthdr.ph_mss = 0;
 
-                       if (sendmp->m_pkthdr.ph_mss > 0) {
+                       if (pkts > 1) {
                                struct ether_extracted ext;
-                               uint16_t pkts = sendmp->m_pkthdr.ph_mss;
+                               uint32_t hdrlen, paylen;
 
+                               /* Calculate header size. */
                                ether_extract_headers(sendmp, &ext);
-                               if (ext.tcp)
+                               hdrlen = sizeof(*ext.eh);
+                               if (ext.ip4)
+                                       hdrlen += ext.ip4->ip_hl << 2;
+                               if (ext.ip6)
+                                       hdrlen += sizeof(*ext.ip6);
+                               if (ext.tcp) {
+                                       hdrlen += ext.tcp->th_off << 2;
                                        tcpstat_inc(tcps_inhwlro);
-                               else
+                                       tcpstat_add(tcps_inpktlro, pkts);
+                               } else {
                                        tcpstat_inc(tcps_inbadlro);
-                               tcpstat_add(tcps_inpktlro, pkts);
+                               }
+
+                               /*
+                                * If we gonna forward this packet, we have to
+                                * mark it as TSO, set a correct mss,
+                                * and recalculate the TCP checksum.
+                                */
+                               paylen = sendmp->m_pkthdr.len - hdrlen;
+                               if (ext.tcp && paylen >= pkts) {
+                                       SET(sendmp->m_pkthdr.csum_flags,
+                                           M_TCP_TSO);
+                                       sendmp->m_pkthdr.ph_mss = paylen / pkts;
+                               }
+                               if (ext.tcp &&
+                                   ISSET(sendmp->m_pkthdr.csum_flags,
+                                   M_TCP_CSUM_IN_OK)) {
+                                       SET(sendmp->m_pkthdr.csum_flags,
+                                           M_TCP_CSUM_OUT);
+                               }
                        }
 
                        ml_enqueue(&ml, sendmp);
Index: netinet6/ip6_forward.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/sys/netinet6/ip6_forward.c,v
retrieving revision 1.109
diff -u -p -r1.109 ip6_forward.c
--- netinet6/ip6_forward.c      5 Apr 2023 13:56:31 -0000       1.109
+++ netinet6/ip6_forward.c      31 May 2023 13:48:25 -0000
@@ -63,8 +63,10 @@
 #include <netinet/ip_ah.h>
 #include <netinet/ip_esp.h>
 #include <netinet/udp.h>
-#include <netinet/tcp.h>
 #endif
+#include <netinet/tcp.h>
+#include <netinet/tcp_timer.h>
+#include <netinet/tcp_var.h>
 
 /*
  * Forward a packet.  If some error occurs return the sender
@@ -316,7 +318,11 @@ reroute:
                goto reroute;
        }
 #endif
-       in6_proto_cksum_out(m, ifp);
+
+       error = tcp_if_output_tso(ifp, &m, sin6tosa(sin6), rt, IFCAP_TSOv6,
+           ifp->if_mtu);
+       if (error || m == NULL)
+               goto freecopy;
 
        /* Check the size after pf_test to give pf a chance to refragment. */
        if (m->m_pkthdr.len > ifp->if_mtu) {
@@ -327,6 +333,7 @@ reroute:
                goto out;
        }
 
+       in6_proto_cksum_out(m, ifp);
        error = ifp->if_output(ifp, m, sin6tosa(sin6), rt);
        if (error) {
                ip6stat_inc(ip6s_cantforward);

Reply via email to