Skip to contentSkip to conversation

gro: add UDP GRO and VXLAN UDP GRO support

PATCH Superseded [email protected] 2 participants 8 messages Jul 1, 2020 – Sep 2, 2020 Arm/Amlogic Meson SoC support

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gro: add UDP GRO and VXLAN UDP GRO support

From: Yi Yang <[email protected]>

UDP GRO and VXLAN UDP GRO can help improve VM-to-VM UDP performance when VM is enabled UFO or GSO, GRO must be supported if GSO, UFO or VXLAN UFO is enabled , otherwise, performance gain will be hurt.

With this enabled in DPDK, OVS DPDK can leverage it to improve VM-to-VM UDP performance, this will make sure IP fragments will be reassembled once it is received from physical NIC.

---
 lib/librte_gro/Makefile         |   2 +
 lib/librte_gro/gro_udp4.c       | 443 ++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_udp4.h       | 296 +++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.c | 556 ++++++++++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.h | 152 +++++++++++
 lib/librte_gro/meson.build      |   2 +-
 lib/librte_gro/rte_gro.c        | 192 +++++++++++---
 lib/librte_gro/rte_gro.h        |   8 +-
 8 files changed, 1617 insertions(+), 34 deletions(-)
 create mode 100644 lib/librte_gro/gro_udp4.c
 create mode 100644 lib/librte_gro/gro_udp4.h
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.c
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.h
lib/librte_gro/Makefile +2 -0
index e848687..30dd8c7 100644
@@ -15,7 +15,9 @@ EXPORT_MAP := rte_gro_version.map
 # source files
 SRCS-$(CONFIG_RTE_LIBRTE_GRO) += rte_gro.c
 SRCS-$(CONFIG_RTE_LIBRTE_GRO) += gro_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GRO) += gro_udp4.c
 SRCS-$(CONFIG_RTE_LIBRTE_GRO) += gro_vxlan_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GRO) += gro_vxlan_udp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GRO)-include += rte_gro.h
lib/librte_gro/gro_udp4.c new file +443 -0

443 lines not on this page · raw message

lib/librte_gro/gro_udp4.h new file +296 -0

296 lines not on this page · raw message

lib/librte_gro/gro_vxlan_udp4.c new file +556 -0

556 lines not on this page · raw message

lib/librte_gro/gro_vxlan_udp4.h new file +152 -0

152 lines not on this page · raw message

lib/librte_gro/meson.build +1 -1
index 501668c..ea8b45c 100644
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
-sources = files('rte_gro.c', 'gro_tcp4.c', 'gro_vxlan_tcp4.c')
+sources = files('rte_gro.c', 'gro_tcp4.c', 'gro_udp4.c', 'gro_vxlan_tcp4.c', 'gro_vxlan_udp4.c')
 headers = files('rte_gro.h')
 deps += ['ethdev']
lib/librte_gro/rte_gro.c +160 -32

322 lines not on this page · raw message

lib/librte_gro/rte_gro.h +7 -1
index 8d781b5..9f9ed49 100644
@@ -31,7 +31,13 @@
 /**< TCP/IPv4 GRO flag */
 #define RTE_GRO_IPV4_VXLAN_TCP_IPV4_INDEX 1
 #define RTE_GRO_IPV4_VXLAN_TCP_IPV4 (1ULL << RTE_GRO_IPV4_VXLAN_TCP_IPV4_INDEX)
-/**< VxLAN GRO flag. */
+/**< VxLAN TCP/IPv4 GRO flag. */
+#define RTE_GRO_UDP_IPV4_INDEX 2
+#define RTE_GRO_UDP_IPV4 (1ULL << RTE_GRO_UDP_IPV4_INDEX)
+/**< UDP/IPv4 GRO flag */
+#define RTE_GRO_IPV4_VXLAN_UDP_IPV4_INDEX 3
+#define RTE_GRO_IPV4_VXLAN_UDP_IPV4 (1ULL << RTE_GRO_IPV4_VXLAN_UDP_IPV4_INDEX)
+/**< VxLAN UDP/IPv4 GRO flag. */
 
 /**
  * Structure used to create GRO context objects or used to pass
Signature · 1 line
1.8.3.1
#1 lore raw

Hi Yi,

This patch supports UDP and VxLAN/UDP, but both are in one patch. It's too large, and please split it into small patches.

Thanks,
Jiayu

Quoted 59 lines

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Wednesday, July 1, 2020 2:48 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH] gro: add UDP GRO and VXLAN UDP GRO support

From: Yi Yang <[email protected]>

UDP GRO and VXLAN UDP GRO can help improve VM-to-VM UDP performance when VM is enabled UFO or GSO, GRO must be supported if GSO, UFO or VXLAN UFO is enabled , otherwise, performance gain will be hurt.

With this enabled in DPDK, OVS DPDK can leverage it to improve VM-to-VM UDP performance, this will make sure IP fragments will be reassembled once it is received from physical NIC.

---
 lib/librte_gro/Makefile         |   2 +
 lib/librte_gro/gro_udp4.c       | 443 ++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_udp4.h       | 296 +++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.c | 556
++++++++++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.h | 152 +++++++++++
 lib/librte_gro/meson.build      |   2 +-
 lib/librte_gro/rte_gro.c        | 192 +++++++++++---
 lib/librte_gro/rte_gro.h        |   8 +-
 8 files changed, 1617 insertions(+), 34 deletions(-)
 create mode 100644 lib/librte_gro/gro_udp4.c
 create mode 100644 lib/librte_gro/gro_udp4.h
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.c
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.h
lib/librte_gro/gro_udp4.c new file +22 -0
+
+
+/*
+ * update the packet length for the flushed packet.
+ */
+static inline void
+update_header(struct gro_udp4_item *item)
+{
+	struct rte_ipv4_hdr *ipv4_hdr;
+	struct rte_mbuf *pkt = item->firstseg;
+	uint16_t frag_offset;
+
+	ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->l2_len);
+	ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len -
+			pkt->l2_len);
+
+	/* Clear MF bit if it is last fragment */
+	if (item->is_last_frag) {
+		frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+		ipv4_hdr->fragment_offset =
+			rte_cpu_to_be_16(frag_offset &

~RTE_IPV4_HDR_MF_FLAG);

Review

Quoted 1 line
(quoted diff) +1 -0
+	}

Need to clear MF bit for non-last fragments, and we also need to clear offset value.

Quoted 16 lines
lib/librte_gro/gro_udp4.c new file +16 -0
+}
+
+int32_t
+gro_udp4_reassemble(struct rte_mbuf *pkt,
+		struct gro_udp4_tbl *tbl,
+		uint64_t start_time)
+{
+	struct rte_ether_hdr *eth_hdr;
+	struct rte_ipv4_hdr *ipv4_hdr;
+	uint16_t udp_dl, ip_dl;
+	uint16_t ip_id, hdr_len;
+	uint16_t frag_offset = 0;
+	uint8_t is_last_frag;
+
+	struct udp4_flow_key key;
+	uint32_t cur_idx, prev_idx, item_idx;

lib/librte_gro/gro_udp4.c line 222

Quoted 10 lines
lib/librte_gro/gro_udp4.c new file +10 -0
+	uint32_t i, max_flow_num, remaining_flow_num;
+	int cmp;
+	uint8_t find;
+
+	/*
+	 * Don't process the packet whose UDP header length is not equal
+	 * to 20.
+	 */
+	if (unlikely(pkt->l4_len != UDP_HDRLEN))
+		return -1;

UDP header is fixed 8-byte. No need to check here.

Quoted 8 lines
lib/librte_gro/gro_udp4.c new file +8 -0
+
+	eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
+	ipv4_hdr = (struct rte_ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);
+	hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len;
+
+	/*
+	 * Don't process non-fragment packet.
+	 */

lib/librte_gro/gro_udp4.c line 240

Quoted 10 lines
lib/librte_gro/gro_udp4.c new file +10 -0
+	if (!is_ipv4_fragment(ipv4_hdr))
+		return -1;
+
+	/*
+	 * Don't process the packet whose payload length is less than or
+	 * equal to 0.
+	 */
+	udp_dl = pkt->pkt_len - hdr_len;
+	if (udp_dl <= 0)
+		return -1;

Udp_dl is unit16_t which will not be negative.

Quoted 7 lines
lib/librte_gro/gro_udp4.c new file +6 -0
+
+	ip_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len;
+	ip_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+	is_last_frag = ((frag_offset & RTE_IPV4_HDR_MF_FLAG) == 0) ? 1 : 0;
+	frag_offset = (uint16_t)(frag_offset & RTE_IPV4_HDR_OFFSET_MASK)

<< 3;

author
#2 lore raw
Quoted 4 lines · Jiayu

Hi Yi,

This patch supports UDP and VxLAN/UDP, but both are in one patch. It's too large, and please split it into small patches.

Jiayu, thank you so much for your great review , I'll send v2 to split it into two patches and fix your comments. Detailed replies for comments embedded, please check them.

Quoted 58 lines

Thanks,
Jiayu

Quoted 54 lines

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Wednesday, July 1, 2020 2:48 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH] gro: add UDP GRO and VXLAN UDP GRO support

From: Yi Yang <[email protected]>

UDP GRO and VXLAN UDP GRO can help improve VM-to-VM UDP performance when VM is enabled UFO or GSO, GRO must be supported if GSO, UFO or VXLAN UFO is enabled , otherwise, performance gain will be hurt.

With this enabled in DPDK, OVS DPDK can leverage it to improve VM-to-VM UDP performance, this will make sure IP fragments will be reassembled once it is received from physical NIC.

---
 lib/librte_gro/Makefile         |   2 +
 lib/librte_gro/gro_udp4.c       | 443 ++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_udp4.h       | 296 +++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.c | 556
++++++++++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.h | 152 +++++++++++
 lib/librte_gro/meson.build      |   2 +-
 lib/librte_gro/rte_gro.c        | 192 +++++++++++---
 lib/librte_gro/rte_gro.h        |   8 +-
 8 files changed, 1617 insertions(+), 34 deletions(-)
 create mode 100644 lib/librte_gro/gro_udp4.c
 create mode 100644 lib/librte_gro/gro_udp4.h
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.c
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.h
lib/librte_gro/gro_udp4.c new file +18 -0
+
+
+/*
+ * update the packet length for the flushed packet.
+ */
+static inline void
+update_header(struct gro_udp4_item *item)
+{
+	struct rte_ipv4_hdr *ipv4_hdr;
+	struct rte_mbuf *pkt = item->firstseg;
+	uint16_t frag_offset;
+
+	ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->l2_len);
+	ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len -
+			pkt->l2_len);
+
+	/* Clear MF bit if it is last fragment */
Quoted 8 lines

Review

Quoted 6 lines
lib/librte_gro/gro_udp4.c new file +4 -0
+	if (item->is_last_frag) {
+		frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+		ipv4_hdr->fragment_offset =
+			rte_cpu_to_be_16(frag_offset &

~RTE_IPV4_HDR_MF_FLAG);

(quoted diff) +1 -0
+	}

Need to clear MF bit for non-last fragments, and we also need to clear offset value.

For non-last fragment, MF (More Fragment) bit is necessary, why do you think we need to clear MF bit for it? Only last fragment should clear MF bit. offset value must be set correctly because it is a IP fragment.

Quoted 21 lines
Quoted 21 lines
lib/librte_gro/gro_udp4.c new file +20 -0
+}
+
+int32_t
+gro_udp4_reassemble(struct rte_mbuf *pkt,
+		struct gro_udp4_tbl *tbl,
+		uint64_t start_time)
+{
+	struct rte_ether_hdr *eth_hdr;
+	struct rte_ipv4_hdr *ipv4_hdr;
+	uint16_t udp_dl, ip_dl;
+	uint16_t ip_id, hdr_len;
+	uint16_t frag_offset = 0;
+	uint8_t is_last_frag;
+
+	struct udp4_flow_key key;
+	uint32_t cur_idx, prev_idx, item_idx;
+	uint32_t i, max_flow_num, remaining_flow_num;
+	int cmp;
+	uint8_t find;
+
Quoted 8 lines

lib/librte_gro/gro_udp4.c line 222

Quoted 6 lines
lib/librte_gro/gro_udp4.c new file +6 -0
+	/*
+	 * Don't process the packet whose UDP header length is not equal
+	 * to 20.
+	 */
+	if (unlikely(pkt->l4_len != UDP_HDRLEN))
+		return -1;

UDP header is fixed 8-byte. No need to check here.

Agree, will remove it in v2.

Quoted 13 lines
Quoted 13 lines
lib/librte_gro/gro_udp4.c new file +12 -0
+
+	eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
+	ipv4_hdr = (struct rte_ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);
+	hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len;
+
+	/*
+	 * Don't process non-fragment packet.
+	 */
+	if (!is_ipv4_fragment(ipv4_hdr))
+		return -1;
+
+	/*
Quoted 8 lines

lib/librte_gro/gro_udp4.c line 240

Quoted 6 lines
lib/librte_gro/gro_udp4.c new file +6 -0
+	 * Don't process the packet whose payload length is less than or
+	 * equal to 0.
+	 */
+	udp_dl = pkt->pkt_len - hdr_len;
+	if (udp_dl <= 0)
+		return -1;

Udp_dl is unit16_t which will not be negative.

Good catch, I should use int16_t here, will do it in v2.

Quoted 8 lines
Quoted 8 lines
lib/librte_gro/gro_udp4.c new file +6 -0
+
+	ip_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len;
+	ip_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+	is_last_frag = ((frag_offset & RTE_IPV4_HDR_MF_FLAG) == 0) ? 1 : 0;
+	frag_offset = (uint16_t)(frag_offset & RTE_IPV4_HDR_OFFSET_MASK)

<< 3;

author
#3 lore raw

Jiayu, BTW, after I check it again, I think udp header length check is necessary, it is actually a sanity check io order to ensure it is indeed a udp packet, gro_tcp4.c did same thing.

Quoted 142 lines · yang_y_yi
Quoted 4 lines · Jiayu

Hi Yi,

This patch supports UDP and VxLAN/UDP, but both are in one patch. It's too large, and please split it into small patches.

Jiayu, thank you so much for your great review , I'll send v2 to split it into two patches and fix your comments. Detailed replies for comments embedded, please check them.

Quoted 58 lines

Thanks,
Jiayu

Quoted 54 lines

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Wednesday, July 1, 2020 2:48 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH] gro: add UDP GRO and VXLAN UDP GRO support

From: Yi Yang <[email protected]>

UDP GRO and VXLAN UDP GRO can help improve VM-to-VM UDP performance when VM is enabled UFO or GSO, GRO must be supported if GSO, UFO or VXLAN UFO is enabled , otherwise, performance gain will be hurt.

With this enabled in DPDK, OVS DPDK can leverage it to improve VM-to-VM UDP performance, this will make sure IP fragments will be reassembled once it is received from physical NIC.

---
 lib/librte_gro/Makefile         |   2 +
 lib/librte_gro/gro_udp4.c       | 443 ++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_udp4.h       | 296 +++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.c | 556
++++++++++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.h | 152 +++++++++++
 lib/librte_gro/meson.build      |   2 +-
 lib/librte_gro/rte_gro.c        | 192 +++++++++++---
 lib/librte_gro/rte_gro.h        |   8 +-
 8 files changed, 1617 insertions(+), 34 deletions(-)
 create mode 100644 lib/librte_gro/gro_udp4.c
 create mode 100644 lib/librte_gro/gro_udp4.h
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.c
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.h
lib/librte_gro/gro_udp4.c new file +18 -0
+
+
+/*
+ * update the packet length for the flushed packet.
+ */
+static inline void
+update_header(struct gro_udp4_item *item)
+{
+	struct rte_ipv4_hdr *ipv4_hdr;
+	struct rte_mbuf *pkt = item->firstseg;
+	uint16_t frag_offset;
+
+	ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->l2_len);
+	ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len -
+			pkt->l2_len);
+
+	/* Clear MF bit if it is last fragment */
Quoted 8 lines

Review

Quoted 6 lines
lib/librte_gro/gro_udp4.c new file +4 -0
+	if (item->is_last_frag) {
+		frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+		ipv4_hdr->fragment_offset =
+			rte_cpu_to_be_16(frag_offset &

~RTE_IPV4_HDR_MF_FLAG);

(quoted diff) +1 -0
+	}

Need to clear MF bit for non-last fragments, and we also need to clear offset value.

For non-last fragment, MF (More Fragment) bit is necessary, why do you think we need to clear MF bit for it? Only last fragment should clear MF bit. offset value must be set correctly because it is a IP fragment.

Quoted 21 lines
Quoted 21 lines
lib/librte_gro/gro_udp4.c new file +20 -0
+}
+
+int32_t
+gro_udp4_reassemble(struct rte_mbuf *pkt,
+		struct gro_udp4_tbl *tbl,
+		uint64_t start_time)
+{
+	struct rte_ether_hdr *eth_hdr;
+	struct rte_ipv4_hdr *ipv4_hdr;
+	uint16_t udp_dl, ip_dl;
+	uint16_t ip_id, hdr_len;
+	uint16_t frag_offset = 0;
+	uint8_t is_last_frag;
+
+	struct udp4_flow_key key;
+	uint32_t cur_idx, prev_idx, item_idx;
+	uint32_t i, max_flow_num, remaining_flow_num;
+	int cmp;
+	uint8_t find;
+
Quoted 8 lines

lib/librte_gro/gro_udp4.c line 222

Quoted 6 lines
lib/librte_gro/gro_udp4.c new file +6 -0
+	/*
+	 * Don't process the packet whose UDP header length is not equal
+	 * to 20.
+	 */
+	if (unlikely(pkt->l4_len != UDP_HDRLEN))
+		return -1;

UDP header is fixed 8-byte. No need to check here.

Agree, will remove it in v2.

Quoted 13 lines
Quoted 13 lines
lib/librte_gro/gro_udp4.c new file +12 -0
+
+	eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
+	ipv4_hdr = (struct rte_ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);
+	hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len;
+
+	/*
+	 * Don't process non-fragment packet.
+	 */
+	if (!is_ipv4_fragment(ipv4_hdr))
+		return -1;
+
+	/*
Quoted 8 lines

lib/librte_gro/gro_udp4.c line 240

Quoted 6 lines
lib/librte_gro/gro_udp4.c new file +6 -0
+	 * Don't process the packet whose payload length is less than or
+	 * equal to 0.
+	 */
+	udp_dl = pkt->pkt_len - hdr_len;
+	if (udp_dl <= 0)
+		return -1;

Udp_dl is unit16_t which will not be negative.

Good catch, I should use int16_t here, will do it in v2.

Quoted 8 lines
Quoted 8 lines
lib/librte_gro/gro_udp4.c new file +6 -0
+
+	ip_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len;
+	ip_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+	is_last_frag = ((frag_offset & RTE_IPV4_HDR_MF_FLAG) == 0) ? 1 : 0;
+	frag_offset = (uint16_t)(frag_offset & RTE_IPV4_HDR_OFFSET_MASK)

<< 3;

#4 lore raw

Yi,

Packet type is checked by mbuf->packet_type field, and input packets should provide correct packet_type value. TCP GRO only process TCP packets whose header length is between 20 and 60 bytes. So we check l4_len.

From: yang_y_yi <[email protected]>
Sent: Tuesday, September 1, 2020 4:43 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re:Re: [dpdk-dev] [PATCH] gro: add UDP GRO and VXLAN UDP GRO support

Jiayu, BTW, after I check it again, I think udp header length check is necessary, it is actually a sanity check io order to ensure it is indeed a udp packet, gro_tcp4.c did same thing.

Quoted 283 lines · At 2020-09-01 14:10:41, "yang_y_yi" <[email protected]<mailto:[email protected]…
Quoted 7 lines · At 2020-09-01 12:27:29, "Hu, Jiayu" <[email protected]<mailto:[email protected]…

Hi Yi,

This patch supports UDP and VxLAN/UDP, but both are in one patch.

It's too large, and please split it into small patches.

Jiayu, thank you so much for your great review , I'll send v2 to split it into two patches and fix your comments. Detailed replies for comments embedded, please check them.

Quoted 124 lines

Thanks,

Jiayu

Quoted 115 lines

-----Original Message-----

From: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>

Sent: Wednesday, July 1, 2020 2:48 PM

To: [email protected]<mailto:[email protected]>

[email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>

Subject: [PATCH] gro: add UDP GRO and VXLAN UDP GRO support

From: Yi Yang <[email protected]<mailto:[email protected]>>

UDP GRO and VXLAN UDP GRO can help improve VM-to-VM

UDP performance when VM is enabled UFO or GSO, GRO

must be supported if GSO, UFO or VXLAN UFO is enabled

, otherwise, performance gain will be hurt.

With this enabled in DPDK, OVS DPDK can leverage it

to improve VM-to-VM UDP performance, this will make

sure IP fragments will be reassembled once it is

received from physical NIC.

---

 lib/librte_gro/Makefile         |   2 +
 lib/librte_gro/gro_udp4.c       | 443 ++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_udp4.h       | 296 +++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.c | 556

++++++++++++++++++++++++++++++++++++++++

 lib/librte_gro/gro_vxlan_udp4.h | 152 +++++++++++
 lib/librte_gro/meson.build      |   2 +-
 lib/librte_gro/rte_gro.c        | 192 +++++++++++---
 lib/librte_gro/rte_gro.h        |   8 +-
 8 files changed, 1617 insertions(+), 34 deletions(-)
 create mode 100644 lib/librte_gro/gro_udp4.c
 create mode 100644 lib/librte_gro/gro_udp4.h
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.c
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.h
(quoted diff) +22 -0
+
 
+
 
+/*
 
+ * update the packet length for the flushed packet.
 
+ */
 
+static inline void
 
+update_header(struct gro_udp4_item *item)
 
+{
 
+  struct rte_ipv4_hdr *ipv4_hdr;
 
+  struct rte_mbuf *pkt = item->firstseg;
 
+  uint16_t frag_offset;
 
+
 
+  ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
 
+                 pkt->l2_len);
 
+  ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len -
 
+                 pkt->l2_len);
 
+
 
+  /* Clear MF bit if it is last fragment */
 
+  if (item->is_last_frag) {
 
+         frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
 
+         ipv4_hdr->fragment_offset =
 
+                 rte_cpu_to_be_16(frag_offset &
Quoted 7 lines
Quoted 3 lines

~RTE_IPV4_HDR_MF_FLAG);

+ }

Need to clear MF bit for non-last fragments, and we also need to clear offset value.

For non-last fragment, MF (More Fragment) bit is necessary, why do you think we need to clear MF bit for it? Only last fragment should clear MF bit. offset value must be set correctly because it is a IP fragment.

Quoted 50 lines
Quoted 49 lines
lib/librte_gro/gro_udp4.c new file +24 -0
+}
 
+
 
+int32_t
 
+gro_udp4_reassemble(struct rte_mbuf *pkt,
 
+         struct gro_udp4_tbl *tbl,
 
+         uint64_t start_time)
 
+{
 
+  struct rte_ether_hdr *eth_hdr;
 
+  struct rte_ipv4_hdr *ipv4_hdr;
 
+  uint16_t udp_dl, ip_dl;
 
+  uint16_t ip_id, hdr_len;
 
+  uint16_t frag_offset = 0;
 
+  uint8_t is_last_frag;
 
+
 
+  struct udp4_flow_key key;
 
+  uint32_t cur_idx, prev_idx, item_idx;
 
+  uint32_t i, max_flow_num, remaining_flow_num;
 
+  int cmp;
 
+  uint8_t find;
 
+
 
+  /*
 
+   * Don't process the packet whose UDP header length is not equal
 
+   * to 20.
 
+   */
Quoted 7 lines

lib/librte_gro/gro_udp4.c line 222

Quoted 3 lines
lib/librte_gro/gro_udp4.c new file +2 -0
+  if (unlikely(pkt->l4_len != UDP_HDRLEN))
 
+         return -1;

UDP header is fixed 8-byte. No need to check here.

Agree, will remove it in v2.

Quoted 34 lines
Quoted 33 lines
lib/librte_gro/gro_udp4.c new file +16 -0
+
 
+  eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
 
+  ipv4_hdr = (struct rte_ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);
 
+  hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len;
 
+
 
+  /*
 
+   * Don't process non-fragment packet.
 
+   */
 
+  if (!is_ipv4_fragment(ipv4_hdr))
 
+         return -1;
 
+
 
+  /*
 
+   * Don't process the packet whose payload length is less than or
 
+   * equal to 0.
 
+   */
 
+  udp_dl = pkt->pkt_len - hdr_len;
Quoted 7 lines

lib/librte_gro/gro_udp4.c line 240

Quoted 3 lines
lib/librte_gro/gro_udp4.c new file +2 -0
+  if (udp_dl <= 0)
 
+         return -1;

Udp_dl is unit16_t which will not be negative.

Good catch, I should use int16_t here, will do it in v2.

Quoted 15 lines
Quoted 15 lines
(quoted diff) +6 -0
+
 
+  ip_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len;
 
+  ip_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
 
+  frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
 
+  is_last_frag = ((frag_offset & RTE_IPV4_HDR_MF_FLAG) == 0) ? 1 : 0;
 
+  frag_offset = (uint16_t)(frag_offset & RTE_IPV4_HDR_OFFSET_MASK)

<< 3;

author
#5 lore raw

Jiayu, TCP header length is variable if there is TCP option, it is usually 20 if no TCP option, but correct value must be between 20 and 60 (including 20 and 60), I think we can't assume l4 header length has been set correctly if packet_type is set correctly, this is my point. I think it will be better if we can add a rte_gro_rx_prepare as rte_eth_tx_prepare. GRO can't work normally only if one of all the related fields isn't set correctly. So I don't think such sanity check is a bad thing.

At 2020-09-02 13:44:56, "Hu, Jiayu" <[email protected]> wrote:

Yi,

Packet type is checked by mbuf->packet_type field, and input

packets should provide correct packet_type value. TCP GRO

only process TCP packets whose header length is between

20 and 60 bytes. So we check l4_len.

From: yang_y_yi <[email protected]>
Sent: Tuesday, September 1, 2020 4:43 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re:Re: [dpdk-dev] [PATCH] gro: add UDP GRO and VXLAN UDP GRO support

Jiayu, BTW, after I check it again, I think udp header length check is necessary, it is actually a sanity check io order to ensure it is indeed a udp packet, gro_tcp4.c did same thing.

Quoted 142 lines · yang_y_yi
Quoted 4 lines · Jiayu

Hi Yi,

This patch supports UDP and VxLAN/UDP, but both are in one patch. It's too large, and please split it into small patches.

Jiayu, thank you so much for your great review , I'll send v2 to split it into two patches and fix your comments. Detailed replies for comments embedded, please check them.

Quoted 58 lines

Thanks,
Jiayu

Quoted 54 lines

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Wednesday, July 1, 2020 2:48 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH] gro: add UDP GRO and VXLAN UDP GRO support

From: Yi Yang <[email protected]>

UDP GRO and VXLAN UDP GRO can help improve VM-to-VM UDP performance when VM is enabled UFO or GSO, GRO must be supported if GSO, UFO or VXLAN UFO is enabled , otherwise, performance gain will be hurt.

With this enabled in DPDK, OVS DPDK can leverage it to improve VM-to-VM UDP performance, this will make sure IP fragments will be reassembled once it is received from physical NIC.

---
 lib/librte_gro/Makefile         |   2 +
 lib/librte_gro/gro_udp4.c       | 443 ++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_udp4.h       | 296 +++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.c | 556
++++++++++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.h | 152 +++++++++++
 lib/librte_gro/meson.build      |   2 +-
 lib/librte_gro/rte_gro.c        | 192 +++++++++++---
 lib/librte_gro/rte_gro.h        |   8 +-
 8 files changed, 1617 insertions(+), 34 deletions(-)
 create mode 100644 lib/librte_gro/gro_udp4.c
 create mode 100644 lib/librte_gro/gro_udp4.h
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.c
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.h
lib/librte_gro/gro_udp4.c new file +18 -0
+
+
+/*
+ * update the packet length for the flushed packet.
+ */
+static inline void
+update_header(struct gro_udp4_item *item)
+{
+  struct rte_ipv4_hdr *ipv4_hdr;
+  struct rte_mbuf *pkt = item->firstseg;
+  uint16_t frag_offset;
+
+  ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+                 pkt->l2_len);
+  ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len -
+                 pkt->l2_len);
+
+  /* Clear MF bit if it is last fragment */
Quoted 8 lines
Quoted 6 lines
lib/librte_gro/gro_udp4.c new file +4 -0
+  if (item->is_last_frag) {
+         frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+         ipv4_hdr->fragment_offset =
+                 rte_cpu_to_be_16(frag_offset &

~RTE_IPV4_HDR_MF_FLAG);
+ }

Need to clear MF bit for non-last fragments, and we also need to clear offset value.

For non-last fragment, MF (More Fragment) bit is necessary, why do you think we need to clear MF bit for it? Only last fragment should clear MF bit. offset value must be set correctly because it is a IP fragment.

Quoted 21 lines
Quoted 21 lines
lib/librte_gro/gro_udp4.c new file +20 -0
+}
+
+int32_t
+gro_udp4_reassemble(struct rte_mbuf *pkt,
+         struct gro_udp4_tbl *tbl,
+         uint64_t start_time)
+{
+  struct rte_ether_hdr *eth_hdr;
+  struct rte_ipv4_hdr *ipv4_hdr;
+  uint16_t udp_dl, ip_dl;
+  uint16_t ip_id, hdr_len;
+  uint16_t frag_offset = 0;
+  uint8_t is_last_frag;
+
+  struct udp4_flow_key key;
+  uint32_t cur_idx, prev_idx, item_idx;
+  uint32_t i, max_flow_num, remaining_flow_num;
+  int cmp;
+  uint8_t find;
+
Quoted 8 lines

lib/librte_gro/gro_udp4.c line 222

Quoted 6 lines
lib/librte_gro/gro_udp4.c new file +6 -0
+  /*
+   * Don't process the packet whose UDP header length is not equal
+   * to 20.
+   */
+  if (unlikely(pkt->l4_len != UDP_HDRLEN))
+         return -1;

UDP header is fixed 8-byte. No need to check here.

Agree, will remove it in v2.

Quoted 13 lines
Quoted 13 lines
lib/librte_gro/gro_udp4.c new file +12 -0
+
+  eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
+  ipv4_hdr = (struct rte_ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);
+  hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len;
+
+  /*
+   * Don't process non-fragment packet.
+   */
+  if (!is_ipv4_fragment(ipv4_hdr))
+         return -1;
+
+  /*
Quoted 8 lines

lib/librte_gro/gro_udp4.c line 240

Quoted 6 lines
lib/librte_gro/gro_udp4.c new file +6 -0
+   * Don't process the packet whose payload length is less than or
+   * equal to 0.
+   */
+  udp_dl = pkt->pkt_len - hdr_len;
+  if (udp_dl <= 0)
+         return -1;

Udp_dl is unit16_t which will not be negative.

Good catch, I should use int16_t here, will do it in v2.

Quoted 8 lines
Quoted 8 lines
lib/librte_gro/gro_udp4.c new file +6 -0
+
+  ip_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len;
+  ip_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+  frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+  is_last_frag = ((frag_offset & RTE_IPV4_HDR_MF_FLAG) == 0) ? 1 : 0;
+  frag_offset = (uint16_t)(frag_offset & RTE_IPV4_HDR_OFFSET_MASK)

<< 3;

#6 lore raw

GRO lib requires users to provide correct mbuf->l2_len/packet_type etc.. This is for avoiding parsing packet headers. If we believe users give correct packet_type, we also should believe l2_len/l4_len etc. are correct. Otherwise, we need to get layer 4 header length from ipv4 header, rather than mbuf->l4_len.

rte_gro_rx_prepare() is a good way to do sanity check or prepare l2_len etc. fields, but this function should be optional, IMO. Either user or rte_gro_rx_prepare() provides correct l2_len etc. value.

Thanks,
Jiayu
From: yang_y_yi <[email protected]>
Sent: Wednesday, September 2, 2020 1:58 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re:RE: Re:Re: [dpdk-dev] [PATCH] gro: add UDP GRO and VXLAN UDP GRO support
Importance: High

Jiayu, TCP header length is variable if there is TCP option, it is usually 20 if no TCP option, but correct value must be between 20 and 60 (including 20 and 60), I think we can't assume l4 header length has been set correctly if packet_type is set correctly, this is my point. I think it will be better if we can add a rte_gro_rx_prepare as rte_eth_tx_prepare. GRO can't work normally only if one of all the related fields isn't set correctly. So I don't think such sanity check is a bad thing.

At 2020-09-02 13:44:56, "Hu, Jiayu" <[email protected]<mailto:[email protected]>> wrote:
Yi,

Packet type is checked by mbuf->packet_type field, and input packets should provide correct packet_type value. TCP GRO only process TCP packets whose header length is between 20 and 60 bytes. So we check l4_len.

From: yang_y_yi <[email protected]<mailto:[email protected]>>
Sent: Tuesday, September 1, 2020 4:43 PM
To: Hu, Jiayu <[email protected]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>
Subject: Re:Re: [dpdk-dev] [PATCH] gro: add UDP GRO and VXLAN UDP GRO support

Jiayu, BTW, after I check it again, I think udp header length check is necessary, it is actually a sanity check io order to ensure it is indeed a udp packet, gro_tcp4.c did same thing.

Quoted 283 lines · At 2020-09-01 14:10:41, "yang_y_yi" <[email protected]<mailto:[email protected]…
Quoted 7 lines · At 2020-09-01 12:27:29, "Hu, Jiayu" <[email protected]<mailto:[email protected]…

Hi Yi,

This patch supports UDP and VxLAN/UDP, but both are in one patch.

It's too large, and please split it into small patches.

Jiayu, thank you so much for your great review , I'll send v2 to split it into two patches and fix your comments. Detailed replies for comments embedded, please check them.

Quoted 124 lines

Thanks,

Jiayu

Quoted 115 lines

-----Original Message-----

From: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>

Sent: Wednesday, July 1, 2020 2:48 PM

To: [email protected]<mailto:[email protected]>

[email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>

Subject: [PATCH] gro: add UDP GRO and VXLAN UDP GRO support

From: Yi Yang <[email protected]<mailto:[email protected]>>

UDP GRO and VXLAN UDP GRO can help improve VM-to-VM

UDP performance when VM is enabled UFO or GSO, GRO

must be supported if GSO, UFO or VXLAN UFO is enabled

, otherwise, performance gain will be hurt.

With this enabled in DPDK, OVS DPDK can leverage it

to improve VM-to-VM UDP performance, this will make

sure IP fragments will be reassembled once it is

received from physical NIC.

---

 lib/librte_gro/Makefile         |   2 +
 lib/librte_gro/gro_udp4.c       | 443 ++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_udp4.h       | 296 +++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.c | 556

++++++++++++++++++++++++++++++++++++++++

 lib/librte_gro/gro_vxlan_udp4.h | 152 +++++++++++
 lib/librte_gro/meson.build      |   2 +-
 lib/librte_gro/rte_gro.c        | 192 +++++++++++---
 lib/librte_gro/rte_gro.h        |   8 +-
 8 files changed, 1617 insertions(+), 34 deletions(-)
 create mode 100644 lib/librte_gro/gro_udp4.c
 create mode 100644 lib/librte_gro/gro_udp4.h
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.c
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.h
(quoted diff) +22 -0
+
 
+
 
+/*
 
+ * update the packet length for the flushed packet.
 
+ */
 
+static inline void
 
+update_header(struct gro_udp4_item *item)
 
+{
 
+  struct rte_ipv4_hdr *ipv4_hdr;
 
+  struct rte_mbuf *pkt = item->firstseg;
 
+  uint16_t frag_offset;
 
+
 
+  ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
 
+                 pkt->l2_len);
 
+  ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len -
 
+                 pkt->l2_len);
 
+
 
+  /* Clear MF bit if it is last fragment */
 
+  if (item->is_last_frag) {
 
+         frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
 
+         ipv4_hdr->fragment_offset =
 
+                 rte_cpu_to_be_16(frag_offset &
Quoted 7 lines
Quoted 3 lines

~RTE_IPV4_HDR_MF_FLAG);

+ }

Need to clear MF bit for non-last fragments, and we also need to clear offset value.

For non-last fragment, MF (More Fragment) bit is necessary, why do you think we need to clear MF bit for it? Only last fragment should clear MF bit. offset value must be set correctly because it is a IP fragment.

Quoted 50 lines
Quoted 49 lines
lib/librte_gro/gro_udp4.c new file +24 -0
+}
 
+
 
+int32_t
 
+gro_udp4_reassemble(struct rte_mbuf *pkt,
 
+         struct gro_udp4_tbl *tbl,
 
+         uint64_t start_time)
 
+{
 
+  struct rte_ether_hdr *eth_hdr;
 
+  struct rte_ipv4_hdr *ipv4_hdr;
 
+  uint16_t udp_dl, ip_dl;
 
+  uint16_t ip_id, hdr_len;
 
+  uint16_t frag_offset = 0;
 
+  uint8_t is_last_frag;
 
+
 
+  struct udp4_flow_key key;
 
+  uint32_t cur_idx, prev_idx, item_idx;
 
+  uint32_t i, max_flow_num, remaining_flow_num;
 
+  int cmp;
 
+  uint8_t find;
 
+
 
+  /*
 
+   * Don't process the packet whose UDP header length is not equal
 
+   * to 20.
 
+   */
Quoted 7 lines

lib/librte_gro/gro_udp4.c line 222

Quoted 3 lines
lib/librte_gro/gro_udp4.c new file +2 -0
+  if (unlikely(pkt->l4_len != UDP_HDRLEN))
 
+         return -1;

UDP header is fixed 8-byte. No need to check here.

Agree, will remove it in v2.

Quoted 34 lines
Quoted 33 lines
lib/librte_gro/gro_udp4.c new file +16 -0
+
 
+  eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
 
+  ipv4_hdr = (struct rte_ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);
 
+  hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len;
 
+
 
+  /*
 
+   * Don't process non-fragment packet.
 
+   */
 
+  if (!is_ipv4_fragment(ipv4_hdr))
 
+         return -1;
 
+
 
+  /*
 
+   * Don't process the packet whose payload length is less than or
 
+   * equal to 0.
 
+   */
 
+  udp_dl = pkt->pkt_len - hdr_len;
Quoted 7 lines

lib/librte_gro/gro_udp4.c line 240

Quoted 3 lines
lib/librte_gro/gro_udp4.c new file +2 -0
+  if (udp_dl <= 0)
 
+         return -1;

Udp_dl is unit16_t which will not be negative.

Good catch, I should use int16_t here, will do it in v2.

Quoted 15 lines
Quoted 15 lines
(quoted diff) +6 -0
+
 
+  ip_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len;
 
+  ip_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
 
+  frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
 
+  is_last_frag = ((frag_offset & RTE_IPV4_HDR_MF_FLAG) == 0) ? 1 : 0;
 
+  frag_offset = (uint16_t)(frag_offset & RTE_IPV4_HDR_OFFSET_MASK)

<< 3;

author
#7 lore raw

Thanks Jiayu, I have removed it and sent out v3, please help ack if no more comments.

At 2020-09-02 14:26:37, "Hu, Jiayu" <[email protected]> wrote:

GRO lib requires users to provide correct mbuf->l2_len/packet_type etc..

This is for avoiding parsing packet headers. If we believe users give correct

packet_type, we also should believe l2_len/l4_len etc. are correct. Otherwise,

we need to get layer 4 header length from ipv4 header, rather than mbuf->l4_len.

rte_gro_rx_prepare() is a good way to do sanity check or prepare l2_len etc. fields,

but this function should be optional, IMO. Either user or rte_gro_rx_prepare() provides

correct l2_len etc. value.

Thanks,

Jiayu

From: yang_y_yi <[email protected]>
Sent: Wednesday, September 2, 2020 1:58 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: Re:RE: Re:Re: [dpdk-dev] [PATCH] gro: add UDP GRO and VXLAN UDP GRO support
Importance: High

Jiayu, TCP header length is variable if there is TCP option, it is usually 20 if no TCP option, but correct value must be between 20 and 60 (including 20 and 60), I think we can't assume l4 header length has been set correctly if packet_type is set correctly, this is my point. I think it will be better if we can add a rte_gro_rx_prepare as rte_eth_tx_prepare. GRO can't work normally only if one of all the related fields isn't set correctly. So I don't think such sanity check is a bad thing.

At 2020-09-02 13:44:56, "Hu, Jiayu" <[email protected]> wrote:

Yi,

Packet type is checked by mbuf->packet_type field, and input

packets should provide correct packet_type value. TCP GRO

only process TCP packets whose header length is between

20 and 60 bytes. So we check l4_len.

From: yang_y_yi <[email protected]>
Sent: Tuesday, September 1, 2020 4:43 PM
To: Hu, Jiayu <[email protected]>
Cc:[email protected]; [email protected]; [email protected]
Subject: Re:Re: [dpdk-dev] [PATCH] gro: add UDP GRO and VXLAN UDP GRO support

Jiayu, BTW, after I check it again, I think udp header length check is necessary, it is actually a sanity check io order to ensure it is indeed a udp packet, gro_tcp4.c did same thing.

Quoted 142 lines · yang_y_yi
Quoted 4 lines · Jiayu

Hi Yi,

This patch supports UDP and VxLAN/UDP, but both are in one patch. It's too large, and please split it into small patches.

Jiayu, thank you so much for your great review , I'll send v2 to split it into two patches and fix your comments. Detailed replies for comments embedded, please check them.

Quoted 58 lines

Thanks,
Jiayu

Quoted 54 lines

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Wednesday, July 1, 2020 2:48 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: [PATCH] gro: add UDP GRO and VXLAN UDP GRO support

From: Yi Yang <[email protected]>

UDP GRO and VXLAN UDP GRO can help improve VM-to-VM UDP performance when VM is enabled UFO or GSO, GRO must be supported if GSO, UFO or VXLAN UFO is enabled , otherwise, performance gain will be hurt.

With this enabled in DPDK, OVS DPDK can leverage it to improve VM-to-VM UDP performance, this will make sure IP fragments will be reassembled once it is received from physical NIC.

---
 lib/librte_gro/Makefile         |   2 +
 lib/librte_gro/gro_udp4.c       | 443 ++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_udp4.h       | 296 +++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.c | 556
++++++++++++++++++++++++++++++++++++++++
 lib/librte_gro/gro_vxlan_udp4.h | 152 +++++++++++
 lib/librte_gro/meson.build      |   2 +-
 lib/librte_gro/rte_gro.c        | 192 +++++++++++---
 lib/librte_gro/rte_gro.h        |   8 +-
 8 files changed, 1617 insertions(+), 34 deletions(-)
 create mode 100644 lib/librte_gro/gro_udp4.c
 create mode 100644 lib/librte_gro/gro_udp4.h
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.c
 create mode 100644 lib/librte_gro/gro_vxlan_udp4.h
(quoted diff) +18 -0
+
+
+/*
+ * update the packet length for the flushed packet.
+ */
+static inline void
+update_header(struct gro_udp4_item *item)
+{
+  struct rte_ipv4_hdr *ipv4_hdr;
+  struct rte_mbuf *pkt = item->firstseg;
+  uint16_t frag_offset;
+
+  ipv4_hdr = (struct rte_ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+                 pkt->l2_len);
+  ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len -
+                 pkt->l2_len);
+
+  /* Clear MF bit if it is last fragment */
Quoted 8 lines
Quoted 6 lines
(quoted diff) +4 -0
+  if (item->is_last_frag) {
+         frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+         ipv4_hdr->fragment_offset =
+                 rte_cpu_to_be_16(frag_offset &

~RTE_IPV4_HDR_MF_FLAG);
+ }

Need to clear MF bit for non-last fragments, and we also need to clear offset value.

For non-last fragment, MF (More Fragment) bit is necessary, why do you think we need to clear MF bit for it? Only last fragment should clear MF bit. offset value must be set correctly because it is a IP fragment.

Quoted 21 lines
Quoted 21 lines
(quoted diff) +20 -0
+}
+
+int32_t
+gro_udp4_reassemble(struct rte_mbuf *pkt,
+         struct gro_udp4_tbl *tbl,
+         uint64_t start_time)
+{
+  struct rte_ether_hdr *eth_hdr;
+  struct rte_ipv4_hdr *ipv4_hdr;
+  uint16_t udp_dl, ip_dl;
+  uint16_t ip_id, hdr_len;
+  uint16_t frag_offset = 0;
+  uint8_t is_last_frag;
+
+  struct udp4_flow_key key;
+  uint32_t cur_idx, prev_idx, item_idx;
+  uint32_t i, max_flow_num, remaining_flow_num;
+  int cmp;
+  uint8_t find;
+
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+  /*
+   * Don't process the packet whose UDP header length is not equal
+   * to 20.
+   */
+  if (unlikely(pkt->l4_len != UDP_HDRLEN))
+         return -1;

UDP header is fixed 8-byte. No need to check here.

Agree, will remove it in v2.

Quoted 13 lines
Quoted 13 lines
(quoted diff) +12 -0
+
+  eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *);
+  ipv4_hdr = (struct rte_ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);
+  hdr_len = pkt->l2_len + pkt->l3_len + pkt->l4_len;
+
+  /*
+   * Don't process non-fragment packet.
+   */
+  if (!is_ipv4_fragment(ipv4_hdr))
+         return -1;
+
+  /*
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+   * Don't process the packet whose payload length is less than or
+   * equal to 0.
+   */
+  udp_dl = pkt->pkt_len - hdr_len;
+  if (udp_dl <= 0)
+         return -1;

Udp_dl is unit16_t which will not be negative.

Good catch, I should use int16_t here, will do it in v2.

Quoted 8 lines
Quoted 8 lines
(quoted diff) +6 -0
+
+  ip_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len;
+  ip_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+  frag_offset = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+  is_last_frag = ((frag_offset & RTE_IPV4_HDR_MF_FLAG) == 0) ? 1 : 0;
+  frag_offset = (uint16_t)(frag_offset & RTE_IPV4_HDR_OFFSET_MASK)

<< 3;