Skip to contentSkip to conversation

app/testpmd: perform SW IP checksum for GRO packets

PATCH Superseded Wenwu Ma 6 participants 9 messages May 11, 2022 – May 19, 2022

lore
Share & tools
lore

Wenwu Ma

author
#0 lore raw

PATCH 1/1 app/testpmd: perform SW IP checksum for GRO packets

The GRO library doesn't re-calculate checksums for merged packets. If users want the merged packets to have correct IP checksums, they should select HW IP checksum calculation for the port which the merged packets are transmitted to. But if the port doesn't support HW IP checksum, users may perform a SW IP checksum. This patch add the code about it.

---
 app/test-pmd/csumonly.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
app/test-pmd/csumonly.c +12 -0
index 8b6665d6f3..76ce58f6d0 100644
@@ -824,6 +824,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 	void **gro_ctx;
 	uint16_t gro_pkts_num;
 	uint8_t gro_enable;
+	struct rte_ipv4_hdr *ipv4_hdr;
 #endif
 	uint16_t nb_rx;
 	uint16_t nb_tx;
@@ -1098,6 +1099,17 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 				fs->gro_times = 0;
 			}
 		}
+
+		for (i = 0; i < nb_rx; i++) {
+			if ((pkts_burst[i]->ol_flags & RTE_MBUF_F_TX_IPV4) &&
+				(tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
+				ipv4_hdr = rte_pktmbuf_mtod_offset(pkts_burst[i],
+							struct rte_ipv4_hdr *,
+							pkts_burst[i]->l2_len);
+				ipv4_hdr->hdr_checksum = 0;
+				ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
+			}
+		}
 	}
 #endif
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 8 lines · Wenwu Ma

The GRO library doesn't re-calculate checksums for merged packets. If users want the merged packets to have correct IP checksums, they should select HW IP checksum calculation for the port which the merged packets are transmitted to. But if the port doesn't support HW IP checksum, users may perform a SW IP checksum. This patch add the code about it.

It looks like a fix, please add a Fixes: line.
Out of curiosity, would there be an issue too when using the gso library?

Quoted 2 lines
Signature · 1 line
David Marchand
author
#2 lore raw
Quoted 16 lines

-----Original Message-----
From: David Marchand <[email protected]>
Sent: 2022年5月11日 15:28
To: Ma, WenwuX <[email protected]>
Cc: Li, Xiaoyun <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; dev <[email protected]>; Hu, Jiayu <[email protected]>; Wang, Yinan <[email protected]>; He, Xingguang <[email protected]>
Subject: Re: [PATCH] app/testpmd: perform SW IP checksum for GRO packets

Quoted 1 line · Wenwu Ma
Quoted 8 lines
Quoted 6 lines

The GRO library doesn't re-calculate checksums for merged packets. If users want the merged packets to have correct IP checksums, they should select HW IP checksum calculation for the port which the merged packets are transmitted to. But if the port doesn't support HW IP checksum, users may perform a SW IP checksum. This patch add the code about it.

It looks like a fix, please add a Fixes: line.

ok

Quoted 2 lines

Out of curiosity, would there be an issue too when using the gso library?

yes, gso library has the same issue. IP checksum need to be re-calculated for fragmented packets

Quoted 6 lines
Quoted 2 lines

--
David Marchand

author
#3 lore raw

PATCH v2 1/1 app/testpmd: perform SW IP checksum for GRO/GSO packets

In reply to Wenwu Ma

The GRO/GSO library doesn't re-calculate checksums for merged/fragmented packets. If users want the packets to have correct IP checksums, they should select HW IP checksum calculation for the port which the packets are transmitted to. But if the port doesn't support HW IP checksum, users may perform a SW IP checksum. This patch add the code about it.

Fixes b7091f1dcfbc ("app/testpmd: enable the heavyweight mode TCP/IPv4 GRO")
Fixes 52f38a2055ed ("app/testpmd: enable TCP/IPv4 VxLAN and GRE GSO")
---
 app/test-pmd/csumonly.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
app/test-pmd/csumonly.c +24 -0
index 8b6665d6f3..e69f31d92c 100644
@@ -778,6 +778,26 @@ pkt_copy_split(const struct rte_mbuf *pkt)
 	return md[0];
 }
 
+/*
+ * Re-calculate IP checksum for merged/fragmented packets.
+ */
+static void
+pkts_ip_csum_recalc(struct rte_mbuf **pkts_burst, const uint16_t nb_pkts, uint64_t tx_offloads)
+{
+	int i;
+	struct rte_ipv4_hdr *ipv4_hdr;
+	for (i = 0; i < nb_pkts; i++) {
+		if ((pkts_burst[i]->ol_flags & RTE_MBUF_F_TX_IPV4) &&
+			(tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
+			ipv4_hdr = rte_pktmbuf_mtod_offset(pkts_burst[i],
+						struct rte_ipv4_hdr *,
+						pkts_burst[i]->l2_len);
+			ipv4_hdr->hdr_checksum = 0;
+			ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
+		}
+	}
+}
+
 /*
  * Receive a burst of packets, and for each packet:
  *  - parse packet, and try to recognize a supported packet type (1)
@@ -1098,6 +1118,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 				fs->gro_times = 0;
 			}
 		}
+
+		pkts_ip_csum_recalc(pkts_burst, nb_rx, tx_offloads);
 	}
 #endif
 
@@ -1131,6 +1153,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 
 		tx_pkts_burst = gso_segments;
 		nb_rx = nb_segments;
+
+		pkts_ip_csum_recalc(tx_pkts_burst, nb_rx, tx_offloads);
 	} else
 #endif
 		tx_pkts_burst = pkts_burst;
Signature · 1 line
2.25.1
author
#4 lore raw

PATCH v3 1/1 app/testpmd: perform SW IP checksum for GRO/GSO packets

In reply to Wenwu Ma

The GRO/GSO library doesn't re-calculate checksums for merged/fragmented packets. If users want the packets to have correct IP checksums, they should select HW IP checksum calculation for the port which the packets are transmitted to. But if the port doesn't support HW IP checksum, users may perform a SW IP checksum. This patch add the code about it.

Fixes b7091f1dcfbc ("app/testpmd: enable the heavyweight mode TCP/IPv4 GRO")
Fixes 52f38a2055ed ("app/testpmd: enable TCP/IPv4 VxLAN and GRE GSO")
---
 app/test-pmd/csumonly.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
app/test-pmd/csumonly.c +26 -0
index 8b6665d6f3..2498ee88a2 100644
@@ -778,6 +778,28 @@ pkt_copy_split(const struct rte_mbuf *pkt)
 	return md[0];
 }
 
+#if defined(RTE_LIB_GRO) || defined(RTE_LIB_GSO)
+/*
+ * Re-calculate IP checksum for merged/fragmented packets.
+ */
+static void
+pkts_ip_csum_recalc(struct rte_mbuf **pkts_burst, const uint16_t nb_pkts, uint64_t tx_offloads)
+{
+	int i;
+	struct rte_ipv4_hdr *ipv4_hdr;
+	for (i = 0; i < nb_pkts; i++) {
+		if ((pkts_burst[i]->ol_flags & RTE_MBUF_F_TX_IPV4) &&
+			(tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) == 0) {
+			ipv4_hdr = rte_pktmbuf_mtod_offset(pkts_burst[i],
+						struct rte_ipv4_hdr *,
+						pkts_burst[i]->l2_len);
+			ipv4_hdr->hdr_checksum = 0;
+			ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
+		}
+	}
+}
+#endif
+
 /*
  * Receive a burst of packets, and for each packet:
  *  - parse packet, and try to recognize a supported packet type (1)
@@ -1098,6 +1120,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 				fs->gro_times = 0;
 			}
 		}
+
+		pkts_ip_csum_recalc(pkts_burst, nb_rx, tx_offloads);
 	}
 #endif
 
@@ -1131,6 +1155,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)
 
 		tx_pkts_burst = gso_segments;
 		nb_rx = nb_segments;
+
+		pkts_ip_csum_recalc(tx_pkts_burst, nb_rx, tx_offloads);
 	} else
 #endif
 		tx_pkts_burst = pkts_burst;
Signature · 1 line
2.25.1
Reviewed-by on v3 1/1
#5 lore raw

RE: [PATCH v3] app/testpmd: perform SW IP checksum for GRO/GSO packets

Quoted 82 lines

-----Original Message-----
From: Ma, WenwuX <[email protected]>
Sent: Thursday, May 12, 2022 9:08 AM
To: Li, Xiaoyun <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Wang, Yinan <[email protected]>; He, Xingguang <[email protected]>; Ma, WenwuX <[email protected]>; [email protected]
Subject: [PATCH v3] app/testpmd: perform SW IP checksum for GRO/GSO packets

The GRO/GSO library doesn't re-calculate checksums for merged/fragmented packets. If users want the packets to have correct IP checksums, they should select HW IP checksum calculation for the port which the packets are transmitted to. But if the port doesn't support HW IP checksum, users may perform a SW IP checksum. This patch add the code about it.

Fixes b7091f1dcfbc ("app/testpmd: enable the heavyweight mode TCP/IPv4

GRO")

Fixes 52f38a2055ed ("app/testpmd: enable TCP/IPv4 VxLAN and GRE GSO")
---
 app/test-pmd/csumonly.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
app/test-pmd/csumonly.c index renamed from app/test-pmd/csumonly.c +0 -0

8b6665d6f3..2498ee88a2 100644

app/test-pmd/csumonly.c +22 -0
@@ -778,6 +778,28 @@ pkt_copy_split(const struct rte_mbuf *pkt)
 	return md[0];
 }
 
+#if defined(RTE_LIB_GRO) || defined(RTE_LIB_GSO)
+/*
+ * Re-calculate IP checksum for merged/fragmented packets.
+ */
+static void
+pkts_ip_csum_recalc(struct rte_mbuf **pkts_burst, const uint16_t
+nb_pkts, uint64_t tx_offloads) {
+	int i;
+	struct rte_ipv4_hdr *ipv4_hdr;
+	for (i = 0; i < nb_pkts; i++) {
+		if ((pkts_burst[i]->ol_flags & RTE_MBUF_F_TX_IPV4) &&
+			(tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)
 == 0) {
+			ipv4_hdr = rte_pktmbuf_mtod_offset(pkts_burst[i],
+						struct rte_ipv4_hdr *,
+						pkts_burst[i]->l2_len);
+			ipv4_hdr->hdr_checksum = 0;
+			ipv4_hdr->hdr_checksum =
 rte_ipv4_cksum(ipv4_hdr);
+		}
+	}
+}
+#endif
+
 /*

* Receive a burst of packets, and for each packet:
* - parse packet, and try to recognize a supported packet type (1) @@ -
1098,6 +1120,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)

app/test-pmd/csumonly.c +4 -0
 				fs->gro_times = 0;
 			}
 		}
+
+		pkts_ip_csum_recalc(pkts_burst, nb_rx, tx_offloads);
 	}
 #endif
@@ -1131,6 +1155,8 @@ pkt_burst_checksum_forward(struct fwd_stream
 *fs)
 
 		tx_pkts_burst = gso_segments;
 		nb_rx = nb_segments;
+
+		pkts_ip_csum_recalc(tx_pkts_burst, nb_rx, tx_offloads);
 	} else
 #endif
Quoted 3 lines

tx_pkts_burst = pkts_burst;
--
2.25.1

Thanks,
Jiayu

Tested-by on v3 1/1
#6 lore raw

RE: [PATCH v3] app/testpmd: perform SW IP checksum for GRO/GSO packets

In reply to Wenwu Ma
Quoted 19 lines

-----Original Message-----
From: Wenwu Ma <[email protected]>
Sent: Thursday, May 12, 2022 9:08 AM
To: Li, Xiaoyun <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Wang, Yinan <[email protected]>; He, Xingguang <[email protected]>; Ma, WenwuX <[email protected]>; [email protected]
Subject: [PATCH v3] app/testpmd: perform SW IP checksum for GRO/GSO packets

The GRO/GSO library doesn't re-calculate checksums for merged/fragmented packets. If users want the packets to have correct IP checksums, they should select HW IP checksum calculation for the port which the packets are transmitted to. But if the port doesn't support HW IP checksum, users may perform a SW IP checksum. This patch add the code about it.

Quoted 7 lines
Fixes b7091f1dcfbc ("app/testpmd: enable the heavyweight mode TCP/IPv4

GRO")

Fixes 52f38a2055ed ("app/testpmd: enable TCP/IPv4 VxLAN and GRE GSO")

---

Acked-by on v3 1/1
#7 lore raw

RE: [PATCH v3] app/testpmd: perform SW IP checksum for GRO/GSO packets

In reply to Wenwu Ma

Hi Wenwu,
LGTM.

Quoted 18 lines

-----Original Message-----
From: Ma, WenwuX <[email protected]>
Sent: Thursday, May 12, 2022 9:08 AM
To: Li, Xiaoyun <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Wang, Yinan <[email protected]>; He, Xingguang <[email protected]>; Ma, WenwuX <[email protected]>; [email protected]
Subject: [PATCH v3] app/testpmd: perform SW IP checksum for GRO/GSO packets

The GRO/GSO library doesn't re-calculate checksums for merged/fragmented packets. If users want the packets to have correct IP checksums, they should select HW IP checksum calculation for the port which the packets are transmitted to. But if the port doesn't support HW IP checksum, users may perform a SW IP checksum. This patch add the code about it.

Quoted 6 lines
Fixes b7091f1dcfbc ("app/testpmd: enable the heavyweight mode TCP/IPv4

GRO")

Fixes 52f38a2055ed ("app/testpmd: enable TCP/IPv4 VxLAN and GRE GSO")
Quoted 60 lines
---
 app/test-pmd/csumonly.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
app/test-pmd/csumonly.c index renamed from app/test-pmd/csumonly.c +0 -0

8b6665d6f3..2498ee88a2 100644

app/test-pmd/csumonly.c +22 -0
@@ -778,6 +778,28 @@ pkt_copy_split(const struct rte_mbuf *pkt)
 	return md[0];
 }
 
+#if defined(RTE_LIB_GRO) || defined(RTE_LIB_GSO)
+/*
+ * Re-calculate IP checksum for merged/fragmented packets.
+ */
+static void
+pkts_ip_csum_recalc(struct rte_mbuf **pkts_burst, const uint16_t
+nb_pkts, uint64_t tx_offloads) {
+	int i;
+	struct rte_ipv4_hdr *ipv4_hdr;
+	for (i = 0; i < nb_pkts; i++) {
+		if ((pkts_burst[i]->ol_flags & RTE_MBUF_F_TX_IPV4) &&
+			(tx_offloads & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)
 == 0) {
+			ipv4_hdr = rte_pktmbuf_mtod_offset(pkts_burst[i],
+						struct rte_ipv4_hdr *,
+						pkts_burst[i]->l2_len);
+			ipv4_hdr->hdr_checksum = 0;
+			ipv4_hdr->hdr_checksum =
 rte_ipv4_cksum(ipv4_hdr);
+		}
+	}
+}
+#endif
+
 /*

* Receive a burst of packets, and for each packet:
* - parse packet, and try to recognize a supported packet type (1) @@ -
1098,6 +1120,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs)

app/test-pmd/csumonly.c +4 -0
 				fs->gro_times = 0;
 			}
 		}
+
+		pkts_ip_csum_recalc(pkts_burst, nb_rx, tx_offloads);
 	}
 #endif
@@ -1131,6 +1155,8 @@ pkt_burst_checksum_forward(struct fwd_stream
 *fs)
 
 		tx_pkts_burst = gso_segments;
 		nb_rx = nb_segments;
+
+		pkts_ip_csum_recalc(tx_pkts_burst, nb_rx, tx_offloads);
 	} else
 #endif

tx_pkts_burst = pkts_burst;
--
2.25.1

#8 lore raw

Re: [PATCH v3] app/testpmd: perform SW IP checksum for GRO/GSO packets

Quoted 21 lines · Yuying

Hi Wenwu,
LGTM.

Quoted 18 lines

-----Original Message-----
From: Ma, WenwuX <[email protected]>
Sent: Thursday, May 12, 2022 9:08 AM
To: Li, Xiaoyun <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Wang, Yinan <[email protected]>; He, Xingguang <[email protected]>; Ma, WenwuX <[email protected]>; [email protected]
Subject: [PATCH v3] app/testpmd: perform SW IP checksum for GRO/GSO packets

The GRO/GSO library doesn't re-calculate checksums for merged/fragmented packets. If users want the packets to have correct IP checksums, they should select HW IP checksum calculation for the port which the packets are transmitted to. But if the port doesn't support HW IP checksum, users may perform a SW IP checksum. This patch add the code about it.

Quoted 8 lines
Quoted 6 lines
Fixes b7091f1dcfbc ("app/testpmd: enable the heavyweight mode TCP/IPv4

GRO")

Fixes 52f38a2055ed ("app/testpmd: enable TCP/IPv4 VxLAN and GRE GSO")

Since CI is happy with the patch now [1].

[1] https://lab.dpdk.org/results/dashboard/patchsets/22087/

Applied, thanks.