[v2] gro: fix gro with tcp push flag

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

Checks

Context Check Description
ci/checkpatch warning coding style issues
ci/Intel-compilation warning apply issues

Commit Message

Jun Qiu Oct. 14, 2022, 1:48 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.

    Referring to the Linux kernel implementation, packets with PUSH
    flag can also perform GRO. And if one of the packets containing
    PUSH flag, the packets after GRO will carry PUSH flag.

    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       | 13 +++++++++----
 lib/gro/gro_tcp4.h       |  5 ++++-
 lib/gro/gro_vxlan_tcp4.c | 15 ++++++++++-----
 lib/gro/gro_vxlan_tcp4.h |  3 ++-
 lib/gro/rte_gro.c        | 12 ++++++++----
 lib/gro/rte_gro.h        |  5 +++++
 6 files changed, 38 insertions(+), 15 deletions(-)
  

Patch

diff --git a/lib/gro/gro_tcp4.c b/lib/gro/gro_tcp4.c
index 0110db5748..b93eb5e6a4 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
@@ -221,9 +223,12 @@  gro_tcp4_reassemble(struct rte_mbuf *pkt,
 
 	/*
 	 * Don't process the packet which has FIN, SYN, RST, URG, ECE
-	 * or CWR set.
+	 * or CWR set, the PSH flag is ignored at the user's discretion.
 	 */
-	if (tcp_hdr->tcp_flags & (~(RTE_TCP_ACK_FLAG | RTE_TCP_PSH_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 2974faf228..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,
diff --git a/lib/gro/gro_vxlan_tcp4.c b/lib/gro/gro_vxlan_tcp4.c
index 884802af0b..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, 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 | RTE_TCP_PSH_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..7b1d20b97c 100644
--- a/lib/gro/gro_vxlan_tcp4.h
+++ b/lib/gro/gro_vxlan_tcp4.h
@@ -117,7 +117,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.
+	 */
 };
 
 /**