gro: fix gro with tcp push flag

Message ID 20221014023718.65766-1-jun.qiu@jaguarmicro.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series gro: fix gro with tcp push flag |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Testing fail Testing issues
ci/iol-x86_64-compile-testing success Testing PASS
ci/github-robot: build success github build: passed

Commit Message

Jun Qiu Oct. 14, 2022, 2:37 a.m. UTC
  TCP data packets sometimes carry a PUSH flag. Currently,
only the packets that do not have PUSH flag can be GROed.
The packets that have a PUSH flag cannot be GROed, the packets
that cannot be processed by GRO are placed last.
In this case, the received packets may be out of order.
For example, there are two packets mbuf1 and mbuf2. mbuf1
contains PUSH flag, mbuf2 does not contain PUSH flag.
After GRO processing, mbuf2 is sent for processing before mbuf1.
This out-of-order will affect TCP processing performance and
lead to unnecessary dup-ACK.

Like some hardware LRO implementations, a control flag is provided
for marking that TCP packets carrying PSH flags can be merged.

Fixes: 0d2cbe59b719 ("lib/gro: support TCP/IPv4")
Cc: stable@dpdk.org

Signed-off-by: Jun Qiu <jun.qiu@jaguarmicro.com>
---
 lib/gro/gro_tcp4.c       | 15 ++++++++++-----
 lib/gro/gro_tcp4.h       | 21 +++++++++++++++++----
 lib/gro/gro_vxlan_tcp4.c | 15 ++++++++++-----
 lib/gro/gro_vxlan_tcp4.h |  5 ++++-
 lib/gro/rte_gro.c        | 12 ++++++++----
 lib/gro/rte_gro.h        |  5 +++++
 6 files changed, 54 insertions(+), 19 deletions(-)
  

Patch

diff --git a/lib/gro/gro_tcp4.c b/lib/gro/gro_tcp4.c
index 8f5e800250..0b8f86857e 100644
--- a/lib/gro/gro_tcp4.c
+++ b/lib/gro/gro_tcp4.c
@@ -6,6 +6,7 @@ 
 #include <rte_mbuf.h>
 #include <rte_ethdev.h>
 
+#include "rte_gro.h"
 #include "gro_tcp4.h"
 
 void *
@@ -191,7 +192,8 @@  update_header(struct gro_tcp4_item *item)
 int32_t
 gro_tcp4_reassemble(struct rte_mbuf *pkt,
 		struct gro_tcp4_tbl *tbl,
-		uint64_t start_time)
+		uint64_t start_time,
+		uint16_t flags)
 {
 	struct rte_ether_hdr *eth_hdr;
 	struct rte_ipv4_hdr *ipv4_hdr;
@@ -205,7 +207,7 @@  gro_tcp4_reassemble(struct rte_mbuf *pkt,
 	uint32_t cur_idx, prev_idx, item_idx;
 	uint32_t i, max_flow_num, remaining_flow_num;
 	int cmp;
-	uint8_t find;
+	uint8_t find, tcp_flags;
 
 	/*
 	 * Don't process the packet whose TCP header length is greater
@@ -220,10 +222,13 @@  gro_tcp4_reassemble(struct rte_mbuf *pkt,
 	hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len;
 
 	/*
-	 * Don't process the packet which has FIN, SYN, RST, PSH, URG, ECE
-	 * or CWR set.
+	 * Don't process the packet which has FIN, SYN, RST, URG, ECE
+	 * or CWR set, the PSH flag is ignored at the user's discretion.
 	 */
-	if (tcp_hdr->tcp_flags != RTE_TCP_ACK_FLAG)
+	tcp_flags = tcp_hdr->tcp_flags & (~(RTE_TCP_ACK_FLAG));
+	if (flags & RTE_GRO_TCP_PUSH_IGNORE)
+		tcp_flags = tcp_flags & (~(RTE_TCP_PSH_FLAG));
+	if (tcp_flags)
 		return -1;
 	/*
 	 * Don't process the packet whose payload length is less than or
diff --git a/lib/gro/gro_tcp4.h b/lib/gro/gro_tcp4.h
index 212f97a042..b005bfe7a0 100644
--- a/lib/gro/gro_tcp4.h
+++ b/lib/gro/gro_tcp4.h
@@ -134,6 +134,8 @@  void gro_tcp4_tbl_destroy(void *tbl);
  *  Pointer pointing to the TCP/IPv4 reassembly table
  * @start_time
  *  The time when the packet is inserted into the table
+ * @flags
+ *  Functional flags for GRO
  *
  * @return
  *  - Return a positive value if the packet is merged.
@@ -143,7 +145,8 @@  void gro_tcp4_tbl_destroy(void *tbl);
  */
 int32_t gro_tcp4_reassemble(struct rte_mbuf *pkt,
 		struct gro_tcp4_tbl *tbl,
-		uint64_t start_time);
+		uint64_t start_time,
+		uint16_t flags);
 
 /**
  * This function flushes timeout packets in a TCP/IPv4 reassembly table,
@@ -210,7 +213,8 @@  merge_two_tcp4_packets(struct gro_tcp4_item *item,
 		uint16_t l2_offset)
 {
 	struct rte_mbuf *pkt_head, *pkt_tail, *lastseg;
-	uint16_t hdr_len, l2_len;
+	struct rte_tcp_hdr *head_tcp_hdr, *tail_tcp_hdr;
+	uint16_t hdr_len, l2_len, l3_offset;
 
 	if (cmp > 0) {
 		pkt_head = item->firstseg;
@@ -221,13 +225,22 @@  merge_two_tcp4_packets(struct gro_tcp4_item *item,
 	}
 
 	/* check if the IPv4 packet length is greater than the max value */
-	hdr_len = l2_offset + pkt_head->l2_len + pkt_head->l3_len +
-		pkt_head->l4_len;
+	l3_offset = l2_offset + pkt_head->l2_len + pkt_head->l3_len;
+	hdr_len = l3_offset + pkt_head->l4_len;
 	l2_len = l2_offset > 0 ? pkt_head->outer_l2_len : pkt_head->l2_len;
 	if (unlikely(pkt_head->pkt_len - l2_len + pkt_tail->pkt_len -
 				hdr_len > MAX_IPV4_PKT_LENGTH))
 		return 0;
 
+	/* merge push flag to pkt_head */
+	tail_tcp_hdr = rte_pktmbuf_mtod_offset(pkt_tail,
+				struct rte_tcp_hdr *, l3_offset);
+	if (tail_tcp_hdr->tcp_flags & RTE_TCP_PSH_FLAG) {
+		head_tcp_hdr = rte_pktmbuf_mtod_offset(pkt_head,
+					struct rte_tcp_hdr *, l3_offset);
+		head_tcp_hdr->tcp_flags |= RTE_TCP_PSH_FLAG;
+	}
+
 	/* remove the packet header for the tail packet */
 	rte_pktmbuf_adj(pkt_tail, hdr_len);
 
diff --git a/lib/gro/gro_vxlan_tcp4.c b/lib/gro/gro_vxlan_tcp4.c
index 3be4deb7c7..c7282139ee 100644
--- a/lib/gro/gro_vxlan_tcp4.c
+++ b/lib/gro/gro_vxlan_tcp4.c
@@ -7,6 +7,7 @@ 
 #include <rte_ethdev.h>
 #include <rte_udp.h>
 
+#include "rte_gro.h"
 #include "gro_vxlan_tcp4.h"
 
 void *
@@ -287,7 +288,8 @@  update_vxlan_header(struct gro_vxlan_tcp4_item *item)
 int32_t
 gro_vxlan_tcp4_reassemble(struct rte_mbuf *pkt,
 		struct gro_vxlan_tcp4_tbl *tbl,
-		uint64_t start_time)
+		uint64_t start_time,
+		uint16_t flags)
 {
 	struct rte_ether_hdr *outer_eth_hdr, *eth_hdr;
 	struct rte_ipv4_hdr *outer_ipv4_hdr, *ipv4_hdr;
@@ -304,7 +306,7 @@  gro_vxlan_tcp4_reassemble(struct rte_mbuf *pkt,
 	uint32_t i, max_flow_num, remaining_flow_num;
 	int cmp;
 	uint16_t hdr_len;
-	uint8_t find;
+	uint8_t find, tcp_flags;
 
 	/*
 	 * Don't process the packet whose TCP header length is greater
@@ -326,10 +328,13 @@  gro_vxlan_tcp4_reassemble(struct rte_mbuf *pkt,
 	tcp_hdr = (struct rte_tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
 
 	/*
-	 * Don't process the packet which has FIN, SYN, RST, PSH, URG,
-	 * ECE or CWR set.
+	 * Don't process the packet which has FIN, SYN, RST, URG, ECE
+	 * or CWR set, the PSH flag is ignored at the user's discretion.
 	 */
-	if (tcp_hdr->tcp_flags != RTE_TCP_ACK_FLAG)
+	tcp_flags = tcp_hdr->tcp_flags & (~(RTE_TCP_ACK_FLAG));
+	if (flags & RTE_GRO_TCP_PUSH_IGNORE)
+		tcp_flags = tcp_flags & (~(RTE_TCP_PSH_FLAG));
+	if (tcp_flags)
 		return -1;
 
 	hdr_len = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len +
diff --git a/lib/gro/gro_vxlan_tcp4.h b/lib/gro/gro_vxlan_tcp4.h
index 7832942a68..b6d8b92599 100644
--- a/lib/gro/gro_vxlan_tcp4.h
+++ b/lib/gro/gro_vxlan_tcp4.h
@@ -108,6 +108,8 @@  void gro_vxlan_tcp4_tbl_destroy(void *tbl);
  *  Pointer pointing to the VxLAN reassembly table
  * @start_time
  *  The time when the packet is inserted into the table
+ * @flags
+ *  Functional flags for GRO
  *
  * @return
  *  - Return a positive value if the packet is merged.
@@ -117,7 +119,8 @@  void gro_vxlan_tcp4_tbl_destroy(void *tbl);
  */
 int32_t gro_vxlan_tcp4_reassemble(struct rte_mbuf *pkt,
 		struct gro_vxlan_tcp4_tbl *tbl,
-		uint64_t start_time);
+		uint64_t start_time,
+		uint16_t flags);
 
 /**
  * This function flushes timeout packets in the VxLAN reassembly table,
diff --git a/lib/gro/rte_gro.c b/lib/gro/rte_gro.c
index e35399fd42..ce9ac81142 100644
--- a/lib/gro/rte_gro.c
+++ b/lib/gro/rte_gro.c
@@ -77,6 +77,8 @@  struct gro_ctx {
 	uint64_t gro_types;
 	/* reassembly tables */
 	void *tbls[RTE_GRO_TYPE_MAX_NUM];
+	/**< Functional flags for GRO */
+	uint16_t flags;
 };
 
 void *
@@ -116,6 +118,7 @@  rte_gro_ctx_create(const struct rte_gro_param *param)
 		gro_types |= gro_type_flag;
 	}
 	gro_ctx->gro_types = param->gro_types;
+	gro_ctx->flags = param->flags;
 
 	return gro_ctx;
 }
@@ -245,7 +248,8 @@  rte_gro_reassemble_burst(struct rte_mbuf **pkts,
 		if (IS_IPV4_VXLAN_TCP4_PKT(pkts[i]->packet_type) &&
 				do_vxlan_tcp_gro) {
 			ret = gro_vxlan_tcp4_reassemble(pkts[i],
-							&vxlan_tcp_tbl, 0);
+							&vxlan_tcp_tbl, 0,
+							param->flags);
 			if (ret > 0)
 				/* Merge successfully */
 				nb_after_gro--;
@@ -262,7 +266,7 @@  rte_gro_reassemble_burst(struct rte_mbuf **pkts,
 				unprocess_pkts[unprocess_num++] = pkts[i];
 		} else if (IS_IPV4_TCP_PKT(pkts[i]->packet_type) &&
 				do_tcp4_gro) {
-			ret = gro_tcp4_reassemble(pkts[i], &tcp_tbl, 0);
+			ret = gro_tcp4_reassemble(pkts[i], &tcp_tbl, 0, param->flags);
 			if (ret > 0)
 				/* merge successfully */
 				nb_after_gro--;
@@ -354,7 +358,7 @@  rte_gro_reassemble(struct rte_mbuf **pkts,
 		if (IS_IPV4_VXLAN_TCP4_PKT(pkts[i]->packet_type) &&
 				do_vxlan_tcp_gro) {
 			if (gro_vxlan_tcp4_reassemble(pkts[i], vxlan_tcp_tbl,
-						current_time) < 0)
+						current_time, gro_ctx->flags) < 0)
 				unprocess_pkts[unprocess_num++] = pkts[i];
 		} else if (IS_IPV4_VXLAN_UDP4_PKT(pkts[i]->packet_type) &&
 				do_vxlan_udp_gro) {
@@ -364,7 +368,7 @@  rte_gro_reassemble(struct rte_mbuf **pkts,
 		} else if (IS_IPV4_TCP_PKT(pkts[i]->packet_type) &&
 				do_tcp4_gro) {
 			if (gro_tcp4_reassemble(pkts[i], tcp_tbl,
-						current_time) < 0)
+						current_time, gro_ctx->flags) < 0)
 				unprocess_pkts[unprocess_num++] = pkts[i];
 		} else if (IS_IPV4_UDP_PKT(pkts[i]->packet_type) &&
 				do_udp4_gro) {
diff --git a/lib/gro/rte_gro.h b/lib/gro/rte_gro.h
index 9f9ed4935a..691b8a26cf 100644
--- a/lib/gro/rte_gro.h
+++ b/lib/gro/rte_gro.h
@@ -39,6 +39,7 @@  extern "C" {
 #define RTE_GRO_IPV4_VXLAN_UDP_IPV4 (1ULL << RTE_GRO_IPV4_VXLAN_UDP_IPV4_INDEX)
 /**< VxLAN UDP/IPv4 GRO flag. */
 
+#define RTE_GRO_TCP_PUSH_IGNORE  0x01
 /**
  * Structure used to create GRO context objects or used to pass
  * application-determined parameters to rte_gro_reassemble_burst().
@@ -55,6 +56,10 @@  struct rte_gro_param {
 	 * like reassembly tables. When use rte_gro_reassemble_burst(),
 	 * applications don't need to set this value.
 	 */
+	uint16_t flags;
+	/**< Functional flags for GRO, For example,
+	 * merge TCP packets with push flag.
+	 */
 };
 
 /**