Skip to contentSkip to conversation

net: core: add helper tcp_v6_gso_csum_prep

PATCH Superseded Heiner Kallweit 2 participants 10 messages Feb 17, 2020 – Feb 18, 2020

Subsystems (17)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

cover net: core: add helper tcp_v6_gso_csum_prep

Several network drivers for chips that support TSO6 share the same code for preparing the TCP header. A difference is that some reset the payload_len whilst others don't do this. Let's factor out this common code to a new helper.

Heiner Kallweit (3):
net: core: add helper tcp_v6_gso_csum_prep
r8169: use new helper tcp_v6_gso_csum_prep
net: use new helper tcp_v6_gso_csum_prep

 drivers/net/ethernet/atheros/alx/main.c       |  5 +---
 .../net/ethernet/atheros/atl1c/atl1c_main.c   |  6 ++---
 drivers/net/ethernet/brocade/bna/bnad.c       |  7 +----
 drivers/net/ethernet/cisco/enic/enic_main.c   |  3 +--
 drivers/net/ethernet/intel/e1000/e1000_main.c |  6 +----
 drivers/net/ethernet/intel/e1000e/netdev.c    |  5 +---
 drivers/net/ethernet/jme.c                    |  7 +----
 .../net/ethernet/pensando/ionic/ionic_txrx.c  |  5 +---
 drivers/net/ethernet/qualcomm/emac/emac-mac.c |  7 ++---
 drivers/net/ethernet/realtek/r8169_main.c     | 26 ++-----------------
 drivers/net/ethernet/socionext/netsec.c       |  6 +----
 drivers/net/hyperv/netvsc_drv.c               |  5 +---
 drivers/net/usb/r8152.c                       | 26 ++-----------------
 drivers/net/vmxnet3/vmxnet3_drv.c             |  5 +---
 include/net/ip6_checksum.h                    | 12 +++++++++
 15 files changed, 30 insertions(+), 101 deletions(-)
Signature · 1 line
2.25.0
author maintainer
#1 lore raw

PATCH 1/3 net: core: add helper tcp_v6_gso_csum_prep

Several network drivers for chips that support TSO6 share the same code for preparing the TCP header. A difference is that some reset the payload_len whilst others don't do this. Let's factor out this common code to a new helper.

---
 include/net/ip6_checksum.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/net/ip6_checksum.h +12 -0
index 7bec95df4..ef0130023 100644
@@ -76,6 +76,18 @@ static inline void __tcp_v6_send_check(struct sk_buff *skb,
 	}
 }
 
+static inline void tcp_v6_gso_csum_prep(struct sk_buff *skb,
+					bool clear_payload_len)
+{
+	struct ipv6hdr *ipv6h = ipv6_hdr(skb);
+	struct tcphdr *th = tcp_hdr(skb);
+
+	if (clear_payload_len)
+		ipv6h->payload_len = 0;
+
+	th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0);
+}
+
 #if IS_ENABLED(CONFIG_IPV6)
 static inline void tcp_v6_send_check(struct sock *sk, struct sk_buff *skb)
 {
Signature · 1 line
2.25.0
author maintainer
#4 lore raw

PATCH 2/3 r8169: use new helper tcp_v6_gso_csum_prep

In reply to Heiner Kallweit

Simplify the code by using new helper tcp_v6_gso_csum_prep.

---
 drivers/net/ethernet/realtek/r8169_main.c | 26 ++---------------------
 1 file changed, 2 insertions(+), 24 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +2 -24
index 5a9143b50..75ba10069 100644
@@ -4108,29 +4108,6 @@ static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb)
 	return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34;
 }
 
-/* msdn_giant_send_check()
- * According to the document of microsoft, the TCP Pseudo Header excludes the
- * packet length for IPv6 TCP large packets.
- */
-static int msdn_giant_send_check(struct sk_buff *skb)
-{
-	const struct ipv6hdr *ipv6h;
-	struct tcphdr *th;
-	int ret;
-
-	ret = skb_cow_head(skb, 0);
-	if (ret)
-		return ret;
-
-	ipv6h = ipv6_hdr(skb);
-	th = tcp_hdr(skb);
-
-	th->check = 0;
-	th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0);
-
-	return ret;
-}
-
 static void rtl8169_tso_csum_v1(struct sk_buff *skb, u32 *opts)
 {
 	u32 mss = skb_shinfo(skb)->gso_size;
@@ -4163,9 +4140,10 @@ static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp,
 			break;
 
 		case htons(ETH_P_IPV6):
-			if (msdn_giant_send_check(skb))
+			if (skb_cow_head(skb, 0))
 				return false;
 
+			tcp_v6_gso_csum_prep(skb, false);
 			opts[0] |= TD1_GTSENV6;
 			break;
 
Signature · 1 line
2.25.0
author maintainer
#7 lore raw

PATCH 3/3 net: use new helper tcp_v6_gso_csum_prep

In reply to Heiner Kallweit

Use new helper tcp_v6_gso_csum_prep in additional network drivers.

---
 drivers/net/ethernet/atheros/alx/main.c       |  5 +---
 .../net/ethernet/atheros/atl1c/atl1c_main.c   |  6 ++---
 drivers/net/ethernet/brocade/bna/bnad.c       |  7 +----
 drivers/net/ethernet/cisco/enic/enic_main.c   |  3 +--
 drivers/net/ethernet/intel/e1000/e1000_main.c |  6 +----
 drivers/net/ethernet/intel/e1000e/netdev.c    |  5 +---
 drivers/net/ethernet/jme.c                    |  7 +----
 .../net/ethernet/pensando/ionic/ionic_txrx.c  |  5 +---
 drivers/net/ethernet/qualcomm/emac/emac-mac.c |  7 ++---
 drivers/net/ethernet/socionext/netsec.c       |  6 +----
 drivers/net/hyperv/netvsc_drv.c               |  5 +---
 drivers/net/usb/r8152.c                       | 26 ++-----------------
 drivers/net/vmxnet3/vmxnet3_drv.c             |  5 +---
 13 files changed, 16 insertions(+), 77 deletions(-)
drivers/net/ethernet/atheros/alx/main.c +1 -4
index 1dcbc486e..3e0215887 100644
@@ -1416,10 +1416,7 @@ static int alx_tso(struct sk_buff *skb, struct alx_txd *first)
 							 0, IPPROTO_TCP, 0);
 		first->word1 |= 1 << TPD_IPV4_SHIFT;
 	} else if (skb_is_gso_v6(skb)) {
-		ipv6_hdr(skb)->payload_len = 0;
-		tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
-						       &ipv6_hdr(skb)->daddr,
-						       0, IPPROTO_TCP, 0);
+		tcp_v6_gso_csum_prep(skb, true);
 		/* LSOv2: the first TPD only provides the packet length */
 		first->adrl.l.pkt_len = skb->len;
 		first->word1 |= 1 << TPD_LSO_V2_SHIFT;
drivers/net/ethernet/atheros/atl1c/atl1c_main.c +2 -4
index 4c0b1f855..482e18d0d 100644
@@ -2025,10 +2025,8 @@ static int atl1c_tso_csum(struct atl1c_adapter *adapter,
 						"IPV6 tso with zero data??\n");
 				goto check_sum;
 			} else
-				tcp_hdr(skb)->check = ~csum_ipv6_magic(
-						&ipv6_hdr(skb)->saddr,
-						&ipv6_hdr(skb)->daddr,
-						0, IPPROTO_TCP, 0);
+				tcp_v6_gso_csum_prep(skb, false);
+
 			etpd->word1 |= 1 << TPD_LSO_EN_SHIFT;
 			etpd->word1 |= 1 << TPD_LSO_VER_SHIFT;
 			etpd->pkt_len = cpu_to_le32(skb->len);
drivers/net/ethernet/brocade/bna/bnad.c +1 -6
index 01a50a4b2..c301ad736 100644
@@ -2504,12 +2504,7 @@ bnad_tso_prepare(struct bnad *bnad, struct sk_buff *skb)
 					   IPPROTO_TCP, 0);
 		BNAD_UPDATE_CTR(bnad, tso4);
 	} else {
-		struct ipv6hdr *ipv6h = ipv6_hdr(skb);
-
-		ipv6h->payload_len = 0;
-		tcp_hdr(skb)->check =
-			~csum_ipv6_magic(&ipv6h->saddr, &ipv6h->daddr, 0,
-					 IPPROTO_TCP, 0);
+		tcp_v6_gso_csum_prep(skb, true);
 		BNAD_UPDATE_CTR(bnad, tso6);
 	}
 
drivers/net/ethernet/cisco/enic/enic_main.c +1 -2
index ddf60dc9a..683c628ef 100644
@@ -696,8 +696,7 @@ static void enic_preload_tcp_csum(struct sk_buff *skb)
 		tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
 			ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
 	} else if (skb->protocol == cpu_to_be16(ETH_P_IPV6)) {
-		tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
-			&ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
+		tcp_v6_gso_csum_prep(skb, false);
 	}
 }
 
drivers/net/ethernet/intel/e1000/e1000_main.c +1 -5
index 2bced34c1..0664985e8 100644
@@ -2715,11 +2715,7 @@ static int e1000_tso(struct e1000_adapter *adapter,
 			cmd_length = E1000_TXD_CMD_IP;
 			ipcse = skb_transport_offset(skb) - 1;
 		} else if (skb_is_gso_v6(skb)) {
-			ipv6_hdr(skb)->payload_len = 0;
-			tcp_hdr(skb)->check =
-				~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
-						 &ipv6_hdr(skb)->daddr,
-						 0, IPPROTO_TCP, 0);
+			tcp_v6_gso_csum_prep(skb, true);
 			ipcse = 0;
 		}
 		ipcss = skb_network_offset(skb);
drivers/net/ethernet/intel/e1000e/netdev.c +1 -4
index db4ea58ba..7dda7d407 100644
@@ -5462,10 +5462,7 @@ static int e1000_tso(struct e1000_ring *tx_ring, struct sk_buff *skb,
 		cmd_length = E1000_TXD_CMD_IP;
 		ipcse = skb_transport_offset(skb) - 1;
 	} else if (skb_is_gso_v6(skb)) {
-		ipv6_hdr(skb)->payload_len = 0;
-		tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
-						       &ipv6_hdr(skb)->daddr,
-						       0, IPPROTO_TCP, 0);
+		tcp_v6_gso_csum_prep(skb, true);
 		ipcse = 0;
 	}
 	ipcss = skb_network_offset(skb);
drivers/net/ethernet/jme.c +1 -6
index 2e4975572..cde9be497 100644
@@ -2077,12 +2077,7 @@ jme_tx_tso(struct sk_buff *skb, __le16 *mss, u8 *flags)
 								IPPROTO_TCP,
 								0);
 		} else {
-			struct ipv6hdr *ip6h = ipv6_hdr(skb);
-
-			tcp_hdr(skb)->check = ~csum_ipv6_magic(&ip6h->saddr,
-								&ip6h->daddr, 0,
-								IPPROTO_TCP,
-								0);
+			tcp_v6_gso_csum_prep(skb, false);
 		}
 
 		return 0;
drivers/net/ethernet/pensando/ionic/ionic_txrx.c +1 -4
index e452f4242..3d8469d97 100644
@@ -632,10 +632,7 @@ static int ionic_tx_tcp_pseudo_csum(struct sk_buff *skb)
 					   ip_hdr(skb)->daddr,
 					   0, IPPROTO_TCP, 0);
 	} else if (skb->protocol == cpu_to_be16(ETH_P_IPV6)) {
-		tcp_hdr(skb)->check =
-			~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
-					 &ipv6_hdr(skb)->daddr,
-					 0, IPPROTO_TCP, 0);
+		tcp_v6_gso_csum_prep(skb, false);
 	}
 
 	return 0;
drivers/net/ethernet/qualcomm/emac/emac-mac.c +2 -5
index bebe38d74..01bcc5e68 100644
@@ -1288,11 +1288,8 @@ static int emac_tso_csum(struct emac_adapter *adpt,
 			memset(tpd, 0, sizeof(*tpd));
 			memset(&extra_tpd, 0, sizeof(extra_tpd));
 
-			ipv6_hdr(skb)->payload_len = 0;
-			tcp_hdr(skb)->check =
-				~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
-						 &ipv6_hdr(skb)->daddr,
-						 0, IPPROTO_TCP, 0);
+			tcp_v6_gso_csum_prep(skb, true);
+
 			TPD_PKT_LEN_SET(&extra_tpd, skb->len);
 			TPD_LSO_SET(&extra_tpd, 1);
 			TPD_LSOV_SET(&extra_tpd, 1);
drivers/net/ethernet/socionext/netsec.c +1 -5
index e8224b543..d7a033053 100644
@@ -1148,11 +1148,7 @@ static netdev_tx_t netsec_netdev_start_xmit(struct sk_buff *skb,
 				~tcp_v4_check(0, ip_hdr(skb)->saddr,
 					      ip_hdr(skb)->daddr, 0);
 		} else {
-			ipv6_hdr(skb)->payload_len = 0;
-			tcp_hdr(skb)->check =
-				~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
-						 &ipv6_hdr(skb)->daddr,
-						 0, IPPROTO_TCP, 0);
+			tcp_v6_gso_csum_prep(skb, true);
 		}
 
 		tx_ctrl.tcp_seg_offload_flag = true;
drivers/net/hyperv/netvsc_drv.c +1 -4
index 65e12cb07..f41e48634 100644
@@ -638,10 +638,7 @@ static int netvsc_xmit(struct sk_buff *skb, struct net_device *net, bool xdp_tx)
 		} else {
 			lso_info->lso_v2_transmit.ip_version =
 				NDIS_TCP_LARGE_SEND_OFFLOAD_IPV6;
-			ipv6_hdr(skb)->payload_len = 0;
-			tcp_hdr(skb)->check =
-				~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
-						 &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
+			tcp_v6_gso_csum_prep(skb, true);
 		}
 		lso_info->lso_v2_transmit.tcp_header_offset = skb_transport_offset(skb);
 		lso_info->lso_v2_transmit.mss = skb_shinfo(skb)->gso_size;
drivers/net/usb/r8152.c +2 -24
index 78ddbaf64..4ad2a1d42 100644
@@ -1948,29 +1948,6 @@ static void r8152_csum_workaround(struct r8152 *tp, struct sk_buff *skb,
 	}
 }
 
-/* msdn_giant_send_check()
- * According to the document of microsoft, the TCP Pseudo Header excludes the
- * packet length for IPv6 TCP large packets.
- */
-static int msdn_giant_send_check(struct sk_buff *skb)
-{
-	const struct ipv6hdr *ipv6h;
-	struct tcphdr *th;
-	int ret;
-
-	ret = skb_cow_head(skb, 0);
-	if (ret)
-		return ret;
-
-	ipv6h = ipv6_hdr(skb);
-	th = tcp_hdr(skb);
-
-	th->check = 0;
-	th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0);
-
-	return ret;
-}
-
 static inline void rtl_tx_vlan_tag(struct tx_desc *desc, struct sk_buff *skb)
 {
 	if (skb_vlan_tag_present(skb)) {
@@ -2016,10 +1993,11 @@ static int r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc,
 			break;
 
 		case htons(ETH_P_IPV6):
-			if (msdn_giant_send_check(skb)) {
+			if (skb_cow_head(skb, 0)) {
 				ret = TX_CSUM_TSO;
 				goto unavailable;
 			}
+			tcp_v6_gso_csum_prep(skb, false);
 			opts1 |= GTSENDV6;
 			break;
 
drivers/net/vmxnet3/vmxnet3_drv.c +1 -4
index 18f152fa0..92c2ecf3f 100644
@@ -942,10 +942,7 @@ vmxnet3_prepare_tso(struct sk_buff *skb,
 		tcph->check = ~csum_tcpudp_magic(iph->saddr, iph->daddr, 0,
 						 IPPROTO_TCP, 0);
 	} else if (ctx->ipv6) {
-		struct ipv6hdr *iph = ipv6_hdr(skb);
-
-		tcph->check = ~csum_ipv6_magic(&iph->saddr, &iph->daddr, 0,
-					       IPPROTO_TCP, 0);
+		tcp_v6_gso_csum_prep(skb, false);
 	}
 }
 
Signature · 1 line
2.25.0
Reviewed-by on v1 1/3
#2 lore raw
In reply to Heiner Kallweit
Quoted 24 lines · Heiner Kallweit

Several network drivers for chips that support TSO6 share the same code for preparing the TCP header. A difference is that some reset the payload_len whilst others don't do this. Let's factor out this common code to a new helper.

---
 include/net/ip6_checksum.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/net/ip6_checksum.h +5 -0
index 7bec95df4..ef0130023 100644
@@ -76,6 +76,18 @@ static inline void __tcp_v6_send_check(struct sk_buff *skb,
        }
 }
 
+static inline void tcp_v6_gso_csum_prep(struct sk_buff *skb,
+                                       bool clear_payload_len)
+{
+       struct ipv6hdr *ipv6h = ipv6_hdr(skb);
+       struct tcphdr *th = tcp_hdr(skb);

include/net/ip6_checksum.h static inline void __tcp_v6_send_check(struct sk_buff *skb, · line 93

Quoted 10 lines
include/net/ip6_checksum.h +7 -0
+
+       if (clear_payload_len)
+               ipv6h->payload_len = 0;
+
+       th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0);
+}
+
 #if IS_ENABLED(CONFIG_IPV6)
 static inline void tcp_v6_send_check(struct sock *sk, struct sk_buff *skb)
 {

So functionally I believe this is correct. The only piece I have a question about is if we should just force the clear_payload_len as always being the case since the value should either be ignored/overwritten in any GSO case anyway.

Reviewed-by on v1 3/3
#8 lore raw

Re: [PATCH net-next 3/3] net: use new helper tcp_v6_gso_csum_prep

In reply to Heiner Kallweit
Quoted 4 lines · Heiner Kallweit

Use new helper tcp_v6_gso_csum_prep in additional network drivers.

Quoted 16 lines
---
 drivers/net/ethernet/atheros/alx/main.c       |  5 +---
 .../net/ethernet/atheros/atl1c/atl1c_main.c   |  6 ++---
 drivers/net/ethernet/brocade/bna/bnad.c       |  7 +----
 drivers/net/ethernet/cisco/enic/enic_main.c   |  3 +--
 drivers/net/ethernet/intel/e1000/e1000_main.c |  6 +----
 drivers/net/ethernet/intel/e1000e/netdev.c    |  5 +---
 drivers/net/ethernet/jme.c                    |  7 +----
 .../net/ethernet/pensando/ionic/ionic_txrx.c  |  5 +---
 drivers/net/ethernet/qualcomm/emac/emac-mac.c |  7 ++---
 drivers/net/ethernet/socionext/netsec.c       |  6 +----
 drivers/net/hyperv/netvsc_drv.c               |  5 +---
 drivers/net/usb/r8152.c                       | 26 ++-----------------
 drivers/net/vmxnet3/vmxnet3_drv.c             |  5 +---
 13 files changed, 16 insertions(+), 77 deletions(-)

It might make sense to break this up into several smaller patches based on the maintainers for the various driver bits.

So the changes all look fine to me, but I am not that familiar with the non-Intel drivers.

#5 lore raw

Re: [PATCH net-next 2/3] r8169: use new helper tcp_v6_gso_csum_prep

In reply to Heiner Kallweit
Quoted 44 lines · Heiner Kallweit

Simplify the code by using new helper tcp_v6_gso_csum_prep.

---
 drivers/net/ethernet/realtek/r8169_main.c | 26 ++---------------------
 1 file changed, 2 insertions(+), 24 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +0 -23
index 5a9143b50..75ba10069 100644
@@ -4108,29 +4108,6 @@ static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb)
        return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34;
 }
 
-/* msdn_giant_send_check()
- * According to the document of microsoft, the TCP Pseudo Header excludes the
- * packet length for IPv6 TCP large packets.
- */
-static int msdn_giant_send_check(struct sk_buff *skb)
-{
-       const struct ipv6hdr *ipv6h;
-       struct tcphdr *th;
-       int ret;
-
-       ret = skb_cow_head(skb, 0);
-       if (ret)
-               return ret;
-
-       ipv6h = ipv6_hdr(skb);
-       th = tcp_hdr(skb);
-
-       th->check = 0;
-       th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0);
-
-       return ret;
-}
-
 static void rtl8169_tso_csum_v1(struct sk_buff *skb, u32 *opts)
 {
        u32 mss = skb_shinfo(skb)->gso_size;
@@ -4163,9 +4140,10 @@ static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp,
                        break;

drivers/net/ethernet/realtek/r8169_main.c static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, · line 4149

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +2 -1
 
                case htons(ETH_P_IPV6):
-                       if (msdn_giant_send_check(skb))
+                       if (skb_cow_head(skb, 0))
                                return false;
 
+                       tcp_v6_gso_csum_prep(skb, false);
                        opts[0] |= TD1_GTSENV6;
                        break;
 

This change looks more or less identical to the one you made in "drivers/net/usb/r8152.c" for patch 3. If you have to resubmit it might make sense to pull that change out and include it here since they are both essentially the same change.

author maintainer
#6 lore raw

Re: [PATCH net-next 2/3] r8169: use new helper tcp_v6_gso_csum_prep

Quoted 51 lines · Alexander Duyck
Quoted 50 lines · Heiner Kallweit

Simplify the code by using new helper tcp_v6_gso_csum_prep.

---
 drivers/net/ethernet/realtek/r8169_main.c | 26 ++---------------------
 1 file changed, 2 insertions(+), 24 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +1 -24
index 5a9143b50..75ba10069 100644
@@ -4108,29 +4108,6 @@ static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb)
        return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34;
 }
 
-/* msdn_giant_send_check()
- * According to the document of microsoft, the TCP Pseudo Header excludes the
- * packet length for IPv6 TCP large packets.
- */
-static int msdn_giant_send_check(struct sk_buff *skb)
-{
-       const struct ipv6hdr *ipv6h;
-       struct tcphdr *th;
-       int ret;
-
-       ret = skb_cow_head(skb, 0);
-       if (ret)
-               return ret;
-
-       ipv6h = ipv6_hdr(skb);
-       th = tcp_hdr(skb);
-
-       th->check = 0;
-       th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0);
-
-       return ret;
-}
-
 static void rtl8169_tso_csum_v1(struct sk_buff *skb, u32 *opts)
 {
        u32 mss = skb_shinfo(skb)->gso_size;
@@ -4163,9 +4140,10 @@ static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp,
                        break;
 
                case htons(ETH_P_IPV6):
-                       if (msdn_giant_send_check(skb))
+                       if (skb_cow_head(skb, 0))
                                return false;
 
Quoted 10 lines

drivers/net/ethernet/realtek/r8169_main.c static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, · line 4149

Quoted 4 lines
drivers/net/ethernet/realtek/r8169_main.c +1 -0
+                       tcp_v6_gso_csum_prep(skb, false);
                        opts[0] |= TD1_GTSENV6;
                        break;
 

This change looks more or less identical to the one you made in "drivers/net/usb/r8152.c" for patch 3. If you have to resubmit it might make sense to pull that change out and include it here since they are both essentially the same change.

Right, it's the same change. I just treated r8169 separately because I happen to be maintainer of it.

author maintainer
#3 lore raw
In reply to Alexander Duyck
Quoted 32 lines · Alexander Duyck
Quoted 31 lines · Heiner Kallweit

Several network drivers for chips that support TSO6 share the same code for preparing the TCP header. A difference is that some reset the payload_len whilst others don't do this. Let's factor out this common code to a new helper.

---
 include/net/ip6_checksum.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/net/ip6_checksum.h +12 -0
index 7bec95df4..ef0130023 100644
@@ -76,6 +76,18 @@ static inline void __tcp_v6_send_check(struct sk_buff *skb,
        }
 }
 
+static inline void tcp_v6_gso_csum_prep(struct sk_buff *skb,
+                                       bool clear_payload_len)
+{
+       struct ipv6hdr *ipv6h = ipv6_hdr(skb);
+       struct tcphdr *th = tcp_hdr(skb);
+
+       if (clear_payload_len)
+               ipv6h->payload_len = 0;
+
+       th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0);
+}
+
Quoted 9 lines

include/net/ip6_checksum.h static inline void __tcp_v6_send_check(struct sk_buff *skb, · line 93

Quoted 3 lines
include/net/ip6_checksum.h +0 -0
 #if IS_ENABLED(CONFIG_IPV6)
 static inline void tcp_v6_send_check(struct sock *sk, struct sk_buff *skb)
 {

So functionally I believe this is correct. The only piece I have a question about is if we should just force the clear_payload_len as always being the case since the value should either be ignored/overwritten in any GSO case anyway.

I also thought about this and just wasn't sure whether this functional change may break any driver. But yes, then let's change it this way. Breaking down the series into smaller patches makes it easier to revert an individual patch in case of a problem.

Quoted 2 lines

Thanks for the review.

author maintainer
#9 lore raw

Re: [PATCH net-next 3/3] net: use new helper tcp_v6_gso_csum_prep

In reply to Alexander Duyck
Quoted 22 lines · Alexander Duyck
Quoted 4 lines · Heiner Kallweit

Use new helper tcp_v6_gso_csum_prep in additional network drivers.

Quoted 16 lines
---
 drivers/net/ethernet/atheros/alx/main.c       |  5 +---
 .../net/ethernet/atheros/atl1c/atl1c_main.c   |  6 ++---
 drivers/net/ethernet/brocade/bna/bnad.c       |  7 +----
 drivers/net/ethernet/cisco/enic/enic_main.c   |  3 +--
 drivers/net/ethernet/intel/e1000/e1000_main.c |  6 +----
 drivers/net/ethernet/intel/e1000e/netdev.c    |  5 +---
 drivers/net/ethernet/jme.c                    |  7 +----
 .../net/ethernet/pensando/ionic/ionic_txrx.c  |  5 +---
 drivers/net/ethernet/qualcomm/emac/emac-mac.c |  7 ++---
 drivers/net/ethernet/socionext/netsec.c       |  6 +----
 drivers/net/hyperv/netvsc_drv.c               |  5 +---
 drivers/net/usb/r8152.c                       | 26 ++-----------------
 drivers/net/vmxnet3/vmxnet3_drv.c             |  5 +---
 13 files changed, 16 insertions(+), 77 deletions(-)
Quoted 3 lines

It might make sense to break this up into several smaller patches based on the maintainers for the various driver bits.

OK

Quoted 5 lines

So the changes all look fine to me, but I am not that familiar with the non-Intel drivers.