Skip to contentSkip to conversation

Support TCP/IPv4, VxLAN and GRE GSO in DPDK

PATCH Superseded Jiayu Hu 7 participants 157 messages Aug 24, 2017 – Oct 8, 2017 Library code Page 2 of 3

lore
Share & tools
lore
#62 lore raw

Re: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

In reply to Jiayu Hu
Quoted 124 lines

From: Hu, Jiayu
Sent: Thursday, September 14, 2017 7:07 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>; Tan, Jianfeng <[email protected]>
Subject: Re: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Hi Konstantin,

Quoted 10 lines · Konstantin

Hi Jiayu,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Tuesday, September 12, 2017 12:18 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: Kavanagh, Mark B <[email protected]>; Tan, Jianfeng

<[email protected]>

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 1 line

result, when all of its GSOed segments are freed, the packet is

freed

Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
Quoted 40 lines

automatically.

lib/librte_gso/rte_gso.c +19 -2
index dda50ee..95f6ea6 100644
@@ -33,18 +33,53 @@
 
 #include <errno.h>
 
+#include <rte_log.h>
+
 #include "rte_gso.h"
+#include "gso_common.h"
+#include "gso_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
-		struct rte_gso_ctx gso_ctx __rte_unused,
+		struct rte_gso_ctx gso_ctx,
 		struct rte_mbuf **pkts_out,
 		uint16_t nb_pkts_out)
 {
+	struct rte_mempool *direct_pool, *indirect_pool;
+	struct rte_mbuf *pkt_seg;
+	uint16_t gso_size;
+	uint8_t ipid_delta;
+	int ret = 1;
+
 	if (pkt == NULL || pkts_out == NULL || nb_pkts_out < 1)
 		return -EINVAL;
 
-	pkts_out[0] = pkt;
+	if (gso_ctx.gso_size >= pkt->pkt_len ||
+			(pkt->packet_type & gso_ctx.gso_types) !=
+			pkt->packet_type) {
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	direct_pool = gso_ctx.direct_pool;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

lib/librte_gso/rte_gso.c line 69

Quoted 5 lines
lib/librte_gso/rte_gso.c +5 -0
+	indirect_pool = gso_ctx.indirect_pool;
+	gso_size = gso_ctx.gso_size;
+	ipid_delta = gso_ctx.ipid_flag == RTE_GSO_IPID_INCREASE;
+
+	if (is_ipv4_tcp(pkt->packet_type)) {

Probably we need here:
If (is_ipv4_tcp(pkt->packet_type) && (gso_ctx->gso_types &

DEV_TX_OFFLOAD_TCP_TSO) != 0) {...

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines

Sorry, actually it probably should be:
If (pkt->ol_flags & (PKT_TX_TCP_SEG | PKT_TX_IPV4) == PKT_TX_IPV4 &&

      (gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO) != 0) {...

I don't quite understand why the GSO library should be aware if the TSO flag is set or not. Applications can query device TSO capability before they call the GSO library. Do I misundertsand anything?

Additionally, we don't need to check if the packet is a TCP/IPv4 packet

here?

Quoted 2 lines

Well, right now PMD we doesn't rely on ptype to figure out what type of

packet and

Quoted 5 lines

what TX offload have to be performed.
Instead it looks at TX part of ol_flags, and
My thought was that as what we doing is actually TSO in SW, it would be good to use the same API here too.
Also with that approach, by setting ol_flags properly user can use the same

gso_ctx and still

Quoted 3 lines

specify what segmentation to perform on a per-packet basis.

Alternative way is to rely on ptype to distinguish should segmentation be

performed on that package or not.

Quoted 1 line

The only advantage I see here is that if someone would like to add GSO for

some new protocol,

Quoted 2 lines

he wouldn't need to introduce new TX flag value for mbuf.ol_flags. Though he still would need to update TX_OFFLOAD_* capabilities and probably

packet_type definitions.

Quoted 3 lines

So from my perspective first variant (use HW TSO API) is more plausible. Wonder what is your and Mark opinions here?

In the first choice, you mean:
the GSO library uses gso_ctx->gso_types and mbuf->ol_flags to call a specific GSO
segmentation function (e.g. gso_tcp4_segment(), gso_tunnel_xxx()) for each input packet.
Applications should parse the packet type, and set an exactly correct DEV_TX_OFFLOAD_*_TSO
flag to gso_types and ol_flags according to the packet type. That is, the value of gso_types
is on a per-packet basis. Using gso_ctx->gso_types and mbuf->ol_flags at the same time
is because that DEV_TX_OFFLOAD_*_TSO only tells tunnelling type and the inner L4 type, and
we need to know L3 type by ol_flags. With this design, HW segmentation and SW segmentation
are indeed consistent.

Quoted 8 lines

If I understand it correctly, applications need to set 'ol_flags = PKT_TX_IPV4' and
'gso_types = DEV_TX_OFFLOAD_VXLAN_TNL_TSO' for a "ether+ipv4+udp+vxlan+ether+ipv4+
tcp+payload" packet. But PKT_TX_IPV4 just present the inner L3 type for tunneled packet.
How about the outer L3 type? Always assume the inner and the outer L3 type are the same?

Hi Jiayu,

If I'm not mistaken, I think what Konstantin is suggesting is as follows:

- The DEV_TX_OFFLOAD_*_TSO flags are currently used to describe a NIC's TSO capabilities; the GSO capabilities may also be described using the same macros, to provide a consistent view of segmentation capabilities across the HW and SW implementations.

- As part of segmentation, it's still a case of checking the packet type, but then setting the appropriate ol_flags in the mbuf, which the GSO library can use to segment the packet.

Thanks,
Mark

Quoted 3 lines

Jiayu

Quoted 1 line

Konstantin

author
#63 lore raw

Re: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Hi Mark,

Quoted 153 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, September 14, 2017 4:52 PM
To: Hu, Jiayu <[email protected]>; Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 4 lines

From: Hu, Jiayu
Sent: Thursday, September 14, 2017 7:07 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>; Tan,

Jianfeng

Quoted 69 lines

<[email protected]>
Subject: Re: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Hi Konstantin,

Quoted 10 lines · Konstantin

Hi Jiayu,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Tuesday, September 12, 2017 12:18 PM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: Kavanagh, Mark B <[email protected]>; Tan, Jianfeng

<[email protected]>

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 1 line

result, when all of its GSOed segments are freed, the packet is

freed

Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
Quoted 40 lines
Quoted 40 lines

automatically.

lib/librte_gso/rte_gso.c +19 -2
index dda50ee..95f6ea6 100644
@@ -33,18 +33,53 @@
 
 #include <errno.h>
 
+#include <rte_log.h>
+
 #include "rte_gso.h"
+#include "gso_common.h"
+#include "gso_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
-		struct rte_gso_ctx gso_ctx __rte_unused,
+		struct rte_gso_ctx gso_ctx,
 		struct rte_mbuf **pkts_out,
 		uint16_t nb_pkts_out)
 {
+	struct rte_mempool *direct_pool, *indirect_pool;
+	struct rte_mbuf *pkt_seg;
+	uint16_t gso_size;
+	uint8_t ipid_delta;
+	int ret = 1;
+
 	if (pkt == NULL || pkts_out == NULL || nb_pkts_out < 1)
 		return -EINVAL;
 
-	pkts_out[0] = pkt;
+	if (gso_ctx.gso_size >= pkt->pkt_len ||
+			(pkt->packet_type & gso_ctx.gso_types) !=
+			pkt->packet_type) {
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	direct_pool = gso_ctx.direct_pool;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

lib/librte_gso/rte_gso.c line 69

Quoted 5 lines
lib/librte_gso/rte_gso.c +5 -0
+	indirect_pool = gso_ctx.indirect_pool;
+	gso_size = gso_ctx.gso_size;
+	ipid_delta = gso_ctx.ipid_flag == RTE_GSO_IPID_INCREASE;
+
+	if (is_ipv4_tcp(pkt->packet_type)) {

Probably we need here:
If (is_ipv4_tcp(pkt->packet_type) && (gso_ctx->gso_types &

Quoted 4 lines

DEV_TX_OFFLOAD_TCP_TSO) != 0) {...

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Sorry, actually it probably should be:
If (pkt->ol_flags & (PKT_TX_TCP_SEG | PKT_TX_IPV4) == PKT_TX_IPV4

&&

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
      (gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO) != 0) {...

I don't quite understand why the GSO library should be aware if the TSO flag is set or not. Applications can query device TSO capability before they call the GSO library. Do I misundertsand anything?

Quoted 8 lines
Quoted 1 line
Quoted 1 line

Additionally, we don't need to check if the packet is a TCP/IPv4 packet

here?

Quoted 2 lines

Well, right now PMD we doesn't rely on ptype to figure out what type of

packet and

Quoted 3 lines

what TX offload have to be performed.
Instead it looks at TX part of ol_flags, and
My thought was that as what we doing is actually TSO in SW, it would be

good

Quoted 2 lines
Quoted 2 lines

to use the same API here too.
Also with that approach, by setting ol_flags properly user can use the

same

Quoted 6 lines

gso_ctx and still

Quoted 3 lines

specify what segmentation to perform on a per-packet basis.

Alternative way is to rely on ptype to distinguish should segmentation be

performed on that package or not.

Quoted 1 line

The only advantage I see here is that if someone would like to add GSO

for

Quoted 3 lines

some new protocol,

Quoted 2 lines

he wouldn't need to introduce new TX flag value for mbuf.ol_flags. Though he still would need to update TX_OFFLOAD_* capabilities and

probably

Quoted 7 lines

packet_type definitions.

Quoted 3 lines

So from my perspective first variant (use HW TSO API) is more plausible. Wonder what is your and Mark opinions here?

In the first choice, you mean:
the GSO library uses gso_ctx->gso_types and mbuf->ol_flags to call a

specific

Quoted 2 lines

GSO
segmentation function (e.g. gso_tcp4_segment(), gso_tunnel_xxx()) for

each

Quoted 6 lines

input packet.
Applications should parse the packet type, and set an exactly correct DEV_TX_OFFLOAD_*_TSO
flag to gso_types and ol_flags according to the packet type. That is, the value of gso_types
is on a per-packet basis. Using gso_ctx->gso_types and mbuf->ol_flags at

the

Quoted 2 lines

same time
is because that DEV_TX_OFFLOAD_*_TSO only tells tunnelling type and the

inner

Quoted 2 lines

L4 type, and
we need to know L3 type by ol_flags. With this design, HW segmentation

and SW

Quoted 10 lines

segmentation
are indeed consistent.

If I understand it correctly, applications need to set 'ol_flags = PKT_TX_IPV4' and
'gso_types = DEV_TX_OFFLOAD_VXLAN_TNL_TSO' for a "ether+ipv4+udp+vxlan+ether+ipv4+
tcp+payload" packet. But PKT_TX_IPV4 just present the inner L3 type for tunneled packet.
How about the outer L3 type? Always assume the inner and the outer L3

type are

Quoted 1 line

the same?

Quoted 8 lines

Hi Jiayu,

If I'm not mistaken, I think what Konstantin is suggesting is as follows:

- The DEV_TX_OFFLOAD_*_TSO flags are currently used to describe a NIC's TSO capabilities; the GSO capabilities may also be described using the same macros, to provide a consistent view of segmentation capabilities across the HW and SW implementations.

Yes, DEV_TX_OFFLOAD_*_TSO stored in gso_types are used to by applications to tell the GSO library what GSO types are required. The GSO library uses ol_flags to decide which segmentation function to use.

Thanks,
Jiayu

Quoted 11 lines

- As part of segmentation, it's still a case of checking the packet type, but then setting the appropriate ol_flags in the mbuf, which the GSO library can use to segment the packet.

Thanks,
Mark

Quoted 3 lines

Jiayu

Quoted 1 line

Konstantin

author
#64 lore raw

PATCH v3 3/5 gso: add VxLAN GSO support

In reply to Jiayu Hu

From: Mark Kavanagh <[email protected]>

This patch adds GSO support for VxLAN-encapsulated packets. Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

VxLAN GSO assumes that all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize each output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 lib/librte_gso/Makefile          |  1 +
 lib/librte_gso/gso_common.c      | 48 ++++++++++++++++++++++-
 lib/librte_gso/gso_common.h      | 33 ++++++++++++++++
 lib/librte_gso/gso_tunnel_tcp4.c | 85 ++++++++++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_tunnel_tcp4.h | 76 +++++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso.c         |  7 +++-
 6 files changed, 248 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c +47 -1

63 lines not on this page · raw message

lib/librte_gso/gso_common.h +33 -0
index 3c76520..2377a1d 100644
@@ -56,6 +56,39 @@ static inline uint8_t is_ipv4_tcp(uint32_t ptype)
 	}
 }
 
+#define IS_INNER_IPV4_HDR(ptype) (((ptype) == RTE_PTYPE_INNER_L3_IPV4) | \
+			((ptype) == RTE_PTYPE_INNER_L3_IPV4_EXT) | \
+			((ptype) == RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN))
+
+#define ETHER_UDP_VXLAN_ETHER_TCP_PKT (RTE_PTYPE_L2_ETHER | \
+		RTE_PTYPE_L4_UDP | RTE_PTYPE_TUNNEL_VXLAN | \
+		RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L4_TCP)
+#define ETHER_VLAN_UDP_VXLAN_ETHER_TCP_PKT (RTE_PTYPE_L2_ETHER_VLAN | \
+		RTE_PTYPE_L4_UDP | RTE_PTYPE_TUNNEL_VXLAN | \
+		RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L4_TCP)
+#define ETHER_UDP_VXLAN_ETHER_VLAN_TCP_PKT (RTE_PTYPE_L2_ETHER | \
+		RTE_PTYPE_L4_UDP | RTE_PTYPE_TUNNEL_VXLAN | \
+		RTE_PTYPE_INNER_L2_ETHER_VLAN | RTE_PTYPE_INNER_L4_TCP)
+#define ETHER_VLAN_UDP_VXLAN_ETHER_VLAN_TCP_PKT (RTE_PTYPE_L2_ETHER_VLAN | \
+		RTE_PTYPE_L4_UDP | RTE_PTYPE_TUNNEL_VXLAN | \
+		RTE_PTYPE_INNER_L2_ETHER_VLAN | RTE_PTYPE_INNER_L4_TCP)
+static inline uint8_t is_ipv4_vxlan_ipv4_tcp(uint32_t ptype)
+{
+	uint32_t type;
+
+	type = ptype & (~(RTE_PTYPE_L3_MASK | RTE_PTYPE_INNER_L3_MASK));
+	switch (type) {
+	case ETHER_UDP_VXLAN_ETHER_TCP_PKT:
+	case ETHER_VLAN_UDP_VXLAN_ETHER_TCP_PKT:
+	case ETHER_UDP_VXLAN_ETHER_VLAN_TCP_PKT:
+	case ETHER_VLAN_UDP_VXLAN_ETHER_VLAN_TCP_PKT:
+		return (RTE_ETH_IS_IPV4_HDR(ptype) > 0) ?
+			IS_INNER_IPV4_HDR(ptype & RTE_PTYPE_INNER_L3_MASK) : 0;
+	default:
+		return 0;
+	}
+}
+
 /**
  * Internal function which updates relevant packet headers, following
  * segmentation. This is required to update, for example, the IPv4
lib/librte_gso/gso_tunnel_tcp4.c new file +85 -0

85 lines not on this page · raw message

lib/librte_gso/gso_tunnel_tcp4.h new file +76 -0

76 lines not on this page · raw message

lib/librte_gso/rte_gso.c +6 -1
index 95f6ea6..226c75a 100644
@@ -38,6 +38,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp4.h"
+#include "gso_tunnel_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -66,7 +67,11 @@ rte_gso_segment(struct rte_mbuf *pkt,
 	gso_size = gso_ctx.gso_size;
 	ipid_delta = gso_ctx.ipid_flag == RTE_GSO_IPID_INCREASE;
 
-	if (is_ipv4_tcp(pkt->packet_type)) {
+	if (is_ipv4_vxlan_ipv4_tcp(pkt->packet_type)) {
+		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else if (is_ipv4_tcp(pkt->packet_type)) {
 		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
 				pkts_out, nb_pkts_out);
Signature · 1 line
2.7.4
author
#65 lore raw

PATCH v3 4/5 gso: add GRE GSO support

In reply to Jiayu Hu

From: Mark Kavanagh <[email protected]>

This patch adds GSO support for GRE-tunneled packets. Supported GRE packets must contain an outer IPv4 header, and inner TCP/IPv4 headers. They may also contain a single VLAN tag. GRE GSO assumes that all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with VxLAN GSO, GRE GSO uses a two-segment MBUF to organize each output packet, which requires multi-segment mbuf support in the TX functions of the NIC driver. Also, if a packet is GSOed, GRE GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 lib/librte_gso/gso_common.c | 22 ++++++++++++++++++++++
 lib/librte_gso/gso_common.h | 19 +++++++++++++++++++
 lib/librte_gso/rte_gso.c    |  3 ++-
 3 files changed, 43 insertions(+), 1 deletion(-)
lib/librte_gso/gso_common.c +22 -0
index c6779d0..bd56924 100644
@@ -37,6 +37,7 @@
 #include <rte_memcpy.h>
 #include <rte_mempool.h>
 #include <rte_ether.h>
+#include <rte_gre.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
 #include <rte_udp.h>
@@ -237,12 +238,33 @@ update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,
 	update_inner_tcp4_header(pkt, ipid_delta, segs, nb_segs);
 }
 
+static inline void
+update_ipv4_gre_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t i, id;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->outer_l2_len);
+	id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	for (i = 0; i < nb_segs; i++) {
+		update_outer_ipv4_header(segs[i], id);
+		id += ipid_delta;
+	}
+
+	/* Update inner TCP/IPv4 headers */
+	update_inner_tcp4_header(pkt, ipid_delta, segs, nb_segs);
+}
+
 void
 gso_update_pkt_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
 		struct rte_mbuf **segs, uint16_t nb_segs)
 {
 	if (is_ipv4_vxlan_ipv4_tcp(pkt->packet_type))
 		update_ipv4_vxlan_tcp4_header(pkt, ipid_delta, segs, nb_segs);
+	else if (is_ipv4_gre_ipv4_tcp(pkt->packet_type))
+		update_ipv4_gre_tcp4_header(pkt, ipid_delta, segs, nb_segs);
 	else if (is_ipv4_tcp(pkt->packet_type))
 		update_inner_tcp4_header(pkt, ipid_delta, segs, nb_segs);
 }
lib/librte_gso/gso_common.h +19 -0
index 2377a1d..f6d3238 100644
@@ -89,6 +89,25 @@ static inline uint8_t is_ipv4_vxlan_ipv4_tcp(uint32_t ptype)
 	}
 }
 
+#define ETHER_GRE_TCP (RTE_PTYPE_L2_ETHER | RTE_PTYPE_TUNNEL_GRE | \
+		RTE_PTYPE_INNER_L4_TCP)
+#define ETHER_VLAN_GRE_TCP (RTE_PTYPE_L2_ETHER_VLAN | RTE_PTYPE_TUNNEL_GRE | \
+		RTE_PTYPE_INNER_L4_TCP)
+static inline uint8_t is_ipv4_gre_ipv4_tcp(uint32_t ptype)
+{
+	uint32_t type;
+
+	type = ptype & (~(RTE_PTYPE_L3_MASK | RTE_PTYPE_INNER_L3_MASK));
+	switch (type) {
+	case ETHER_GRE_TCP:
+	case ETHER_VLAN_GRE_TCP:
+		return (RTE_ETH_IS_IPV4_HDR(ptype) > 0) ?
+			IS_INNER_IPV4_HDR(ptype & RTE_PTYPE_INNER_L3_MASK) : 0;
+	default:
+		return 0;
+	}
+}
+
 /**
  * Internal function which updates relevant packet headers, following
  * segmentation. This is required to update, for example, the IPv4
lib/librte_gso/rte_gso.c +2 -1
index 226c75a..e0925ae 100644
@@ -67,7 +67,8 @@ rte_gso_segment(struct rte_mbuf *pkt,
 	gso_size = gso_ctx.gso_size;
 	ipid_delta = gso_ctx.ipid_flag == RTE_GSO_IPID_INCREASE;
 
-	if (is_ipv4_vxlan_ipv4_tcp(pkt->packet_type)) {
+	if (is_ipv4_vxlan_ipv4_tcp(pkt->packet_type) ||
+			is_ipv4_gre_ipv4_tcp(pkt->packet_type)) {
 		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
 				pkts_out, nb_pkts_out);
Signature · 1 line
2.7.4
author
#66 lore raw

PATCH v3 5/5 app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

In reply to Jiayu Hu

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

---
 app/test-pmd/cmdline.c  | 178 ++++++++++++++++++++++++++++++++++++++++++++++++
 app/test-pmd/config.c   |  24 +++++++
 app/test-pmd/csumonly.c | 102 +++++++++++++++++++++++++--
 app/test-pmd/testpmd.c  |  16 +++++
 app/test-pmd/testpmd.h  |  10 +++
 5 files changed, 326 insertions(+), 4 deletions(-)
app/test-pmd/cmdline.c +178 -0
index cd8c358..03b98a3 100644
@@ -431,6 +431,17 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"    Set max flow number and max packet number per-flow"
 			" for GRO.\n\n"
 
+			"set port (port_id) gso (on|off)"
+			"    Enable or disable Generic Segmentation Offload in"
+			" csum forwarding engine.\n\n"
+
+			"set gso segsz (length)\n"
+			"    Set max packet length for output GSO segments,"
+			" including packet header and payload.\n\n"
+
+			"show port (port_id) gso\n"
+			"    Show GSO configuration.\n\n"
+
 			"set fwd (%s)\n"
 			"    Set packet forwarding mode.\n\n"
 
@@ -3963,6 +3974,170 @@ cmdline_parse_inst_t cmd_gro_set = {
 	},
 };
 
+/* *** ENABLE/DISABLE GSO *** */
+struct cmd_gso_enable_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_mode;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_enable_parsed(void *parsed_result,
+		__attribute__((unused)) struct cmdline *cl,
+		__attribute__((unused)) void *data)
+{
+	struct cmd_gso_enable_result *res;
+
+	res = parsed_result;
+	if (!strcmp(res->cmd_keyword, "gso"))
+		setup_gso(res->cmd_mode, res->cmd_pid);
+}
+
+cmdline_parse_token_string_t cmd_gso_enable_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_enable_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_enable_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_enable_mode =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_mode, "on#off");
+cmdline_parse_token_num_t cmd_gso_enable_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_enable = {
+	.f = cmd_gso_enable_parsed,
+	.data = NULL,
+	.help_str = "set port <port_id> gso on|off",
+	.tokens = {
+		(void *)&cmd_gso_enable_set,
+		(void *)&cmd_gso_enable_port,
+		(void *)&cmd_gso_enable_pid,
+		(void *)&cmd_gso_enable_keyword,
+		(void *)&cmd_gso_enable_mode,
+		NULL,
+	},
+};
+
+/* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
+struct cmd_gso_size_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_segsz;
+	uint16_t cmd_size;
+};
+
+static void
+cmd_gso_size_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_size_result *res = parsed_result;
+
+	if (test_done == 0) {
+		printf("Before set GSO segsz, please stop fowarding first\n");
+		return;
+	}
+
+	if (!strcmp(res->cmd_keyword, "gso") &&
+			!strcmp(res->cmd_segsz, "segsz")) {
+		if (res->cmd_size == 0) {
+			printf("gso_size should be larger than 0."
+					" Please input a legal value\n");
+		} else
+			gso_max_segment_size = res->cmd_size;
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_size_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_size_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_size_segsz =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_segsz, "segsz");
+cmdline_parse_token_num_t cmd_gso_size_size =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
+				cmd_size, UINT16);
+
+cmdline_parse_inst_t cmd_gso_size = {
+	.f = cmd_gso_size_parsed,
+	.data = NULL,
+	.help_str = "set gso segsz <length>",
+	.tokens = {
+		(void *)&cmd_gso_size_set,
+		(void *)&cmd_gso_size_keyword,
+		(void *)&cmd_gso_size_segsz,
+		(void *)&cmd_gso_size_size,
+		NULL,
+	},
+};
+
+/* *** SHOW GSO CONFIGURATION *** */
+struct cmd_gso_show_result {
+	cmdline_fixed_string_t cmd_show;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_show_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_show_result *res = parsed_result;
+
+	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
+		printf("invalid port id %u\n", res->cmd_pid);
+		return;
+	}
+
+	if (!strcmp(res->cmd_keyword, "gso")) {
+		if (gso_ports[res->cmd_pid].enable) {
+			printf("Max GSO segment size: %uB\n"
+					"Support GSO protocols: TCP/IPv4,"
+					" VxlAN and GRE\n",
+					gso_max_segment_size);
+		} else
+			printf("Port %u doesn't enable GSO\n", res->cmd_pid);
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_show_show =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_show, "show");
+cmdline_parse_token_string_t cmd_gso_show_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_show_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_num_t cmd_gso_show_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
+				cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_show = {
+	.f = cmd_gso_show_parsed,
+	.data = NULL,
+	.help_str = "show port <port_id> gso",
+	.tokens = {
+		(void *)&cmd_gso_show_show,
+		(void *)&cmd_gso_show_port,
+		(void *)&cmd_gso_show_pid,
+		(void *)&cmd_gso_show_keyword,
+		NULL,
+	},
+};
+
 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
 struct cmd_set_flush_rx {
 	cmdline_fixed_string_t set;
@@ -14251,6 +14426,9 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
 	(cmdline_parse_inst_t *)&cmd_enable_gro,
 	(cmdline_parse_inst_t *)&cmd_gro_set,
+	(cmdline_parse_inst_t *)&cmd_gso_enable,
+	(cmdline_parse_inst_t *)&cmd_gso_size,
+	(cmdline_parse_inst_t *)&cmd_gso_show,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
app/test-pmd/config.c +24 -0
index 3ae3e1c..3434346 100644
@@ -2454,6 +2454,30 @@ setup_gro(const char *mode, uint8_t port_id)
 	}
 }
 
+void
+setup_gso(const char *mode, uint8_t port_id)
+{
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		printf("invalid port id %u\n", port_id);
+		return;
+	}
+	if (strcmp(mode, "on") == 0) {
+		if (test_done == 0) {
+			printf("before enable GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 1;
+	} else if (strcmp(mode, "off") == 0) {
+		if (test_done == 0) {
+			printf("before disable GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 0;
+	}
+}
+
 char*
 list_pkt_forwarding_modes(void)
 {
app/test-pmd/csumonly.c +98 -4

233 lines not on this page · raw message

app/test-pmd/testpmd.c +16 -0
index 7d40139..dd4b365 100644
@@ -400,6 +400,9 @@ static int eth_event_callback(uint8_t port_id,
  */
 static int all_ports_started(void);
 
+struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+uint16_t gso_max_segment_size = ETHER_MAX_LEN;
+
 /*
  * Helper function to check if socket is already discovered.
  * If yes, return positive value. If not, return zero.
@@ -570,6 +573,7 @@ init_config(void)
 	unsigned int nb_mbuf_per_pool;
 	lcoreid_t  lc_id;
 	uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
+	uint32_t gso_types = 0;
 
 	memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
 
@@ -654,6 +658,12 @@ init_config(void)
 
 	init_port_config();
 
+	gso_types = RTE_PTYPE_L2_ETHER_VLAN | RTE_PTYPE_L2_ETHER |
+		RTE_PTYPE_INNER_L2_ETHER | RTE_PTYPE_INNER_L2_ETHER_VLAN |
+		RTE_PTYPE_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_L4_TCP |
+		RTE_PTYPE_L4_UDP | RTE_PTYPE_TUNNEL_VXLAN |
+		RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN | RTE_PTYPE_INNER_L4_TCP |
+		RTE_PTYPE_TUNNEL_GRE;
 	/*
 	 * Records which Mbuf pool to use by each logical core, if needed.
 	 */
@@ -664,6 +674,12 @@ init_config(void)
 		if (mbp == NULL)
 			mbp = mbuf_pool_find(0);
 		fwd_lcores[lc_id]->mbp = mbp;
+		/* initialize GSO context */
+		fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
+		fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN;
+		fwd_lcores[lc_id]->gso_ctx.ipid_flag = RTE_GSO_IPID_INCREASE;
 	}
 
 	/* Configuration of packet forwarding streams. */
app/test-pmd/testpmd.h +10 -0
index c9d7739..725af1a 100644
@@ -36,6 +36,7 @@
 
 #include <rte_pci.h>
 #include <rte_gro.h>
+#include <rte_gso.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -205,6 +206,7 @@ struct rte_port {
  * CPU id. configuration table.
  */
 struct fwd_lcore {
+	struct rte_gso_ctx gso_ctx;     /**< GSO context */
 	struct rte_mempool *mbp; /**< The mbuf pool to use by this core */
 	streamid_t stream_idx;   /**< index of 1st stream in "fwd_streams" */
 	streamid_t stream_nb;    /**< number of streams in "fwd_streams" */
@@ -442,6 +444,13 @@ struct gro_status {
 };
 extern struct gro_status gro_ports[RTE_MAX_ETHPORTS];
 
+#define GSO_MAX_PKT_BURST 2048
+struct gso_status {
+	uint8_t enable;
+};
+extern struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+extern uint16_t gso_max_segment_size;
+
 static inline unsigned int
 lcore_num(void)
 {
@@ -641,6 +650,7 @@ void get_5tuple_filter(uint8_t port_id, uint16_t index);
 int rx_queue_id_is_invalid(queueid_t rxq_id);
 int tx_queue_id_is_invalid(queueid_t txq_id);
 void setup_gro(const char *mode, uint8_t port_id);
+void setup_gso(const char *mode, uint8_t port_id);
 
 /* Functions to manage the set of filtered Multicast MAC addresses */
 void mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr);
Signature · 1 line
2.7.4
#67 lore raw

Re: [PATCH v3 5/5] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 18 lines · Jiayu Hu

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

Quoted 8 lines
---
 app/test-pmd/cmdline.c  | 178 ++++++++++++++++++++++++++++++++++++++++++++++++
 app/test-pmd/config.c   |  24 +++++++
 app/test-pmd/csumonly.c | 102 +++++++++++++++++++++++++--
 app/test-pmd/testpmd.c  |  16 +++++
 app/test-pmd/testpmd.h  |  10 +++

Can you please update tespmd document (testpmd_funcs.rst) with new commands.

<...>

author
#68 lore raw

Re: [PATCH v3 5/5] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Hi Ferruh,

Quoted 32 lines

-----Original Message-----
From: Yigit, Ferruh
Sent: Friday, September 15, 2017 2:33 AM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: Ananyev, Konstantin <[email protected]>; Kavanagh, Mark B <[email protected]>; Tan, Jianfeng <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v3 5/5] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 14 lines · Jiayu Hu

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Quoted 8 lines

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

---
 app/test-pmd/cmdline.c  | 178
Quoted 7 lines

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

Quoted 4 lines
 app/test-pmd/config.c   |  24 +++++++
 app/test-pmd/csumonly.c | 102 +++++++++++++++++++++++++--
 app/test-pmd/testpmd.c  |  16 +++++
 app/test-pmd/testpmd.h  |  10 +++

Can you please update tespmd document (testpmd_funcs.rst) with new commands.

Thanks, I will update it sooner.

Jiayu

Quoted 2 lines

<...>

author
#69 lore raw

v4 cover Support TCP/IPv4, VxLAN and GRE GSO in DPDK

In reply to Jiayu Hu

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The last patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine.

The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunnelled packets from VMs is 1514B. So current experiment method can't used to measure VxLAN and GRE GSO performance, but test the functionality via setting small GSO segment length (e.g. 500B).

To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse-tunnel on "P0"
- csum parse-tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and disabled kernel GRO. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

The experimental data of GRE GRO will be shown later, and the prog_guide will be added later.

Change log
==========
v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.
- change the defination of gso_types in struct rte_gso_ctx.
- replace rte_pktmbuf_detach() with rte_pktmbuf_free().
- refactor gso_update_pkt_headers().
- change the return value of rte_gso_segment().
- remove parameter checks in rte_gso_segment().
- use rte_net_get_ptype() in app/test-pmd/csumonly.c to fill mbuf->packet_type.
- add a new GSO command in testpmd to show GSO configuration for ports.
- misc: fix typo and optimize function description.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (2):
gso: add VxLAN GSO support
gso: add GRE GSO support

 app/test-pmd/cmdline.c                      | 178 +++++++++++++++++
 app/test-pmd/config.c                       |  24 +++
 app/test-pmd/csumonly.c                     |  69 ++++++-
 app/test-pmd/testpmd.c                      |  13 ++
 app/test-pmd/testpmd.h                      |  10 +
 config/common_base                          |   5 +
 doc/api/doxy-api-index.md                   |   1 +
 doc/api/doxy-api.conf                       |   1 +
 doc/guides/rel_notes/release_17_11.rst      |  19 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  41 ++++
 lib/Makefile                                |   2 +
 lib/librte_eal/common/include/rte_log.h     |   1 +
 lib/librte_gso/Makefile                     |  52 +++++
 lib/librte_gso/gso_common.c                 | 291 ++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h                 | 157 +++++++++++++++
 lib/librte_gso/gso_tcp4.c                   |  82 ++++++++
 lib/librte_gso/gso_tcp4.h                   |  76 ++++++++
 lib/librte_gso/gso_tunnel_tcp4.c            |  89 +++++++++
 lib/librte_gso/gso_tunnel_tcp4.h            |  76 ++++++++
 lib/librte_gso/rte_gso.c                    | 107 ++++++++++
 lib/librte_gso/rte_gso.h                    | 144 ++++++++++++++
 lib/librte_gso/rte_gso_version.map          |   7 +
 mk/rte.app.mk                               |   1 +
 23 files changed, 1441 insertions(+), 5 deletions(-)
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
Signature · 1 line
2.7.4
author
#70 lore raw

PATCH v4 1/5 gso: add Generic Segmentation Offload API framework

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. To segment a packet requires two steps. The first is to set proper flags to mbuf->ol_flags, where the flags are the same as that of TSO. The second is to call the segmentation API, rte_gso_segment(). This patch introduces the GSO API framework to DPDK.

rte_gso_segment() splits an input packet into small ones in each invocation. The GSO library refers to these small packets generated by rte_gso_segment() as GSO segments. Each of the newly-created GSO segments is organized as a two-segment MBUF, where the first segment is a standard MBUF, which stores a copy of packet header, and the second is an indirect MBUF which points to a section of data in the input packet. rte_gso_segment() reduces the refcnt of the input packet by 1. Therefore, when all GSO segments are freed, the input packet is freed automatically. Additionally, since each GSO segment has multiple MBUFs (i.e. 2 MBUFs), the driver of the interface which the GSO segments are sent to should support to transmit multi-segment packets.

---
 config/common_base                     |   5 ++
 doc/api/doxy-api-index.md              |   1 +
 doc/api/doxy-api.conf                  |   1 +
 doc/guides/rel_notes/release_17_11.rst |   1 +
 lib/Makefile                           |   2 +
 lib/librte_gso/Makefile                |  49 +++++++++++
 lib/librte_gso/rte_gso.c               |  52 ++++++++++++
 lib/librte_gso/rte_gso.h               | 144 +++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map     |   7 ++
 mk/rte.app.mk                          |   1 +
 10 files changed, 263 insertions(+)
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
config/common_base +5 -0
index 5e97a08..603e340 100644
@@ -652,6 +652,11 @@ CONFIG_RTE_LIBRTE_IP_FRAG_TBL_STAT=n
 CONFIG_RTE_LIBRTE_GRO=y
 
 #
+# Compile GSO library
+#
+CONFIG_RTE_LIBRTE_GSO=y
+
+#
 # Compile librte_meter
 #
 CONFIG_RTE_LIBRTE_METER=y
doc/api/doxy-api-index.md +1 -0
index 19e0d4f..6512918 100644
@@ -101,6 +101,7 @@ The public API headers are grouped by topics:
   [TCP]                (@ref rte_tcp.h),
   [UDP]                (@ref rte_udp.h),
   [GRO]                (@ref rte_gro.h),
+  [GSO]                (@ref rte_gso.h),
   [frag/reass]         (@ref rte_ip_frag.h),
   [LPM IPv4 route]     (@ref rte_lpm.h),
   [LPM IPv6 route]     (@ref rte_lpm6.h),
doc/api/doxy-api.conf +1 -0
index 823554f..408f2e6 100644
@@ -47,6 +47,7 @@ INPUT                   = doc/api/doxy-api-index.md \
                           lib/librte_ether \
                           lib/librte_eventdev \
                           lib/librte_gro \
+                          lib/librte_gso \
                           lib/librte_hash \
                           lib/librte_ip_frag \
                           lib/librte_jobstats \
doc/guides/rel_notes/release_17_11.rst +1 -0
index 8bf91bd..7508be7 100644
@@ -174,6 +174,7 @@ The libraries prepended with a plus sign were incremented in this version.
      librte_ethdev.so.7
      librte_eventdev.so.2
      librte_gro.so.1
+   + librte_gso.so.1
      librte_hash.so.2
      librte_ip_frag.so.1
      librte_jobstats.so.1
lib/Makefile +2 -0
index 86caba1..3d123f4 100644
@@ -108,6 +108,8 @@ DIRS-$(CONFIG_RTE_LIBRTE_REORDER) += librte_reorder
 DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
+DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
lib/librte_gso/Makefile new file +49 -0

49 lines not on this page · raw message

lib/librte_gso/rte_gso.c new file +52 -0

52 lines not on this page · raw message

lib/librte_gso/rte_gso.h new file +144 -0

144 lines not on this page · raw message

lib/librte_gso/rte_gso_version.map new file +7 -0
new file mode 100644
index 0000000..e1fd453
@@ -0,0 +1,7 @@
+DPDK_17.11 {
+	global:
+
+	rte_gso_segment;
+
+	local: *;
+};
mk/rte.app.mk +1 -0
index c25fdd9..d4c9873 100644
@@ -66,6 +66,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PDUMP)          += -lrte_pdump
 _LDLIBS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR)    += -lrte_distributor
 _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG)        += -lrte_ip_frag
 _LDLIBS-$(CONFIG_RTE_LIBRTE_GRO)            += -lrte_gro
+_LDLIBS-$(CONFIG_RTE_LIBRTE_GSO)            += -lrte_gso
 _LDLIBS-$(CONFIG_RTE_LIBRTE_METER)          += -lrte_meter
 _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lrte_sched
 _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM)            += -lrte_lpm
Signature · 1 line
2.7.4
author
#71 lore raw

PATCH v4 2/5 gso: add TCP/IPv4 GSO support

In reply to Jiayu Hu

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSOed, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

TCP/IPv4 GSO clears the PKT_TX_TCP_SEG flag for the input packet and GSO segments on the event of success.

---
 doc/guides/rel_notes/release_17_11.rst  |  12 ++
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 202 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 107 +++++++++++++++++
 lib/librte_gso/gso_tcp4.c               |  82 +++++++++++++
 lib/librte_gso/gso_tcp4.h               |  76 ++++++++++++
 lib/librte_gso/rte_gso.c                |  52 +++++++-
 8 files changed, 531 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
doc/guides/rel_notes/release_17_11.rst +12 -0
index 7508be7..7453bb0 100644
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MSS is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets, which may include a single VLAN tag.
+
+  The GSO library doesn't check if the input packets have correct
+  checksums, and doesn't update checksums for output packets.
+  Additionally, the GSO library doesn't process IP fragmented packets.
+
 
 Resolved Issues
 ---------------
lib/librte_eal/common/include/rte_log.h +1 -0
index ec8dba7..2fa1199 100644
@@ -87,6 +87,7 @@ extern struct rte_logs rte_logs;
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
lib/librte_gso/Makefile +2 -0
index aeaacbc..2be64d1 100644
@@ -42,6 +42,8 @@ LIBABIVER := 1
 
 #source files
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +202 -0

202 lines not on this page · raw message

lib/librte_gso/gso_common.h new file +107 -0

107 lines not on this page · raw message

lib/librte_gso/gso_tcp4.c new file +82 -0

82 lines not on this page · raw message

lib/librte_gso/gso_tcp4.h new file +76 -0

76 lines not on this page · raw message

lib/librte_gso/rte_gso.c +49 -3

68 lines not on this page · raw message

Signature · 1 line
2.7.4
Tested-by on v4 2/5
#72 lore raw

Re: [PATCH v4 2/5] gso: add TCP/IPv4 GSO support

Quoted 29 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Jiayu Hu
Sent: Tuesday, September 19, 2017 3:33 PM
To: [email protected]
Cc: Ananyev, Konstantin <[email protected]>; Kavanagh, Mark B <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Hu, Jiayu <[email protected]>
Subject: [dpdk-dev] [PATCH v4 2/5] gso: add TCP/IPv4 GSO support

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSOed, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

Quoted 5 lines

TCP/IPv4 GSO clears the PKT_TX_TCP_SEG flag for the input packet and GSO segments on the event of success.

This patch is test on my bench. Iperf result as following:
TSO : 18 Gbps
DPDK GSO: 10 Gbps
No TSO/GSO: 4 Gbps

Quoted 684 lines
---
 doc/guides/rel_notes/release_17_11.rst  |  12 ++
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 202
++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 107 +++++++++++++++++
 lib/librte_gso/gso_tcp4.c               |  82 +++++++++++++
 lib/librte_gso/gso_tcp4.h               |  76 ++++++++++++
 lib/librte_gso/rte_gso.c                |  52 +++++++-
 8 files changed, 531 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
doc/guides/rel_notes/release_17_11.rst +0 -0
index 7508be7..7453bb0 100644
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
 

=========================================================

doc/guides/rel_notes/release_17_11.rst +12 -0
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MSS is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets, which may include a single VLAN tag.
+
+  The GSO library doesn't check if the input packets have correct
+  checksums, and doesn't update checksums for output packets.
+  Additionally, the GSO library doesn't process IP fragmented packets.
+
 
 Resolved Issues
 ---------------
lib/librte_eal/common/include/rte_log.h +1 -0
index ec8dba7..2fa1199 100644
@@ -87,6 +87,7 @@ extern struct rte_logs rte_logs;
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
lib/librte_gso/Makefile +2 -0
index aeaacbc..2be64d1 100644
@@ -42,6 +42,8 @@ LIBABIVER := 1
 
 #source files
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +21 -0
new file mode 100644
index 0000000..b2c84f6
@@ -0,0 +1,202 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND

CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */

lib/librte_gso/gso_common.c new file +96 -0
+
+#include <stdbool.h>
+#include <errno.h>
+
+#include <rte_memcpy.h>
+#include <rte_mempool.h>
+#include <rte_ether.h>
+#include <rte_ip.h>
+#include <rte_tcp.h>
+
+#include "gso_common.h"
+
+static inline void
+hdr_segment_init(struct rte_mbuf *hdr_segment, struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset)
+{
+	/* Copy MBUF metadata */
+	hdr_segment->nb_segs = 1;
+	hdr_segment->port = pkt->port;
+	hdr_segment->ol_flags = pkt->ol_flags;
+	hdr_segment->packet_type = pkt->packet_type;
+	hdr_segment->pkt_len = pkt_hdr_offset;
+	hdr_segment->data_len = pkt_hdr_offset;
+	hdr_segment->tx_offload = pkt->tx_offload;
+
+	/* Copy the packet header */
+	rte_memcpy(rte_pktmbuf_mtod(hdr_segment, char *),
+			rte_pktmbuf_mtod(pkt, char *),
+			pkt_hdr_offset);
+}
+
+static inline void
+free_gso_segment(struct rte_mbuf **pkts, uint16_t nb_pkts)
+{
+	uint16_t i;
+
+	for (i = 0; i < nb_pkts; i++)
+		rte_pktmbuf_free(pkts[i]);
+}
+
+int
+gso_do_segment(struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset,
+		uint16_t pyld_unit_size,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct rte_mbuf *pkt_in;
+	struct rte_mbuf *hdr_segment, *pyld_segment, *prev_segment;
+	uint16_t pkt_in_data_pos, segment_bytes_remaining;
+	uint16_t pyld_len, nb_segs;
+	bool more_in_pkt, more_out_segs;
+
+	pkt_in = pkt;
+	nb_segs = 0;
+	more_in_pkt = 1;
+	pkt_in_data_pos = pkt_hdr_offset;
+
+	while (more_in_pkt) {
+		if (unlikely(nb_segs >= nb_pkts_out)) {
+			free_gso_segment(pkts_out, nb_segs);
+			return -EINVAL;
+		}
+
+		/* Allocate a direct MBUF */
+		hdr_segment = rte_pktmbuf_alloc(direct_pool);
+		if (unlikely(hdr_segment == NULL)) {
+			free_gso_segment(pkts_out, nb_segs);
+			return -ENOMEM;
+		}
+		/* Fill the packet header */
+		hdr_segment_init(hdr_segment, pkt, pkt_hdr_offset);
+
+		prev_segment = hdr_segment;
+		segment_bytes_remaining = pyld_unit_size;
+		more_out_segs = 1;
+
+		while (more_out_segs && more_in_pkt) {
+			/* Allocate an indirect MBUF */
+			pyld_segment = rte_pktmbuf_alloc(indirect_pool);
+			if (unlikely(pyld_segment == NULL)) {
+				rte_pktmbuf_free(hdr_segment);
+				free_gso_segment(pkts_out, nb_segs);
+				return -ENOMEM;
+			}
+			/* Attach to current MBUF segment of pkt */
+			rte_pktmbuf_attach(pyld_segment, pkt_in);
+
+			prev_segment->next = pyld_segment;
+			prev_segment = pyld_segment;
+
+			pyld_len = segment_bytes_remaining;
+			if (pyld_len + pkt_in_data_pos > pkt_in->data_len)
+				pyld_len = pkt_in->data_len -

pkt_in_data_pos;

lib/librte_gso/gso_common.c new file +31 -0
+
+			pyld_segment->data_off = pkt_in_data_pos +
+				pkt_in->data_off;
+			pyld_segment->data_len = pyld_len;
+
+			/* Update header segment */
+			hdr_segment->pkt_len += pyld_len;
+			hdr_segment->nb_segs++;
+
+			pkt_in_data_pos += pyld_len;
+			segment_bytes_remaining -= pyld_len;
+
+			/* Finish processing a MBUF segment of pkt */
+			if (pkt_in_data_pos == pkt_in->data_len) {
+				pkt_in = pkt_in->next;
+				pkt_in_data_pos = 0;
+				if (pkt_in == NULL)
+					more_in_pkt = 0;
+			}
+
+			/* Finish generating a GSO segment */
+			if (segment_bytes_remaining == 0)
+				more_out_segs = 0;
+		}
+		pkts_out[nb_segs++] = hdr_segment;
+	}
+	return nb_segs;
+}
+
+static inline void
+__update_ipv4_tcp_header(struct rte_mbuf *pkt, uint16_t l2_len, uint16_t

id,

lib/librte_gso/gso_common.c new file +43 -0
+		uint32_t sent_seq, uint8_t non_tail)
+{
+	struct tcp_hdr *tcp_hdr;
+	struct ipv4_hdr *ipv4_hdr;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			l2_len);
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+
+	ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len -
+			l2_len);
+	ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
+
+	tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
+	if (likely(non_tail))
+		tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK |
+					TCP_HDR_FIN_MASK));
+}
+
+void
+update_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	struct tcp_hdr *tcp_hdr;
+	struct ipv4_hdr *ipv4_hdr;
+	uint32_t sent_seq;
+	uint16_t id, l2_len, tail_idx, i;
+
+	l2_len = pkt->l2_len;
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			l2_len);
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+
+	for (i = 0; i < nb_segs; i++) {
+		__update_ipv4_tcp_header(segs[i], l2_len, id, sent_seq,
+				i < tail_idx);
+		id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
lib/librte_gso/gso_common.h new file +21 -0
new file mode 100644
index 0000000..2a01cd0
@@ -0,0 +1,107 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND

CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */

lib/librte_gso/gso_common.h new file +10 -0
+
+#ifndef _GSO_COMMON_H_
+#define _GSO_COMMON_H_
+
+#include <stdint.h>
+
+#include <rte_mbuf.h>
+#include <rte_ip.h>
+
+#define IS_FRAGMENTED(frag_off) (((frag_off) &

IPV4_HDR_OFFSET_MASK) != 0 \

lib/librte_gso/gso_common.h new file +1 -0
+		|| ((frag_off) & IPV4_HDR_MF_FLAG) ==

IPV4_HDR_MF_FLAG)

lib/librte_gso/gso_common.h new file +5 -0
+
+#define TCP_HDR_PSH_MASK ((uint8_t)0x08)
+#define TCP_HDR_FIN_MASK ((uint8_t)0x01)
+
+#define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) ==

\

lib/librte_gso/gso_common.h new file +25 -0
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
+
+/**
+ * Internal function which updates relevant packet headers for TCP/IPv4
+ * packets, following segmentation. This is required to update, for
+ * example, the IPv4 'total_length' field, to reflect the reduced length
+ * of the now-segmented packet.
+ *
+ * @param pkt
+ *  The original packet.
+ * @param ipid_delta
+ *  The increasing uint of IP ids.
+ * @param segs
+ *  Pointer array used for storing mbuf addresses for GSO segments.
+ * @param nb_segs
+ *  The number of GSO segments placed in segs.
+ */
+void update_tcp4_header(struct rte_mbuf *pkt,
+		uint8_t ipid_delta,
+		struct rte_mbuf **segs,
+		uint16_t nb_segs);
+
+/**
+ * Internal function which divides the input packet into small segments.
+ * Each of the newly-created segments is organized as a two-segment

MBUF,
+ * where the first segment is a standard mbuf, which stores a copy of
+ * packet header, and the second is an indirect mbuf which points to a
+ * section of data in the input packet.
+ *
+ * @param pkt
+ * Packet to segment.
+ * @param pkt_hdr_offset
+ * Packet header offset, measured in bytes.
+ * @param pyld_unit_size
+ * The max payload length of a GSO segment.
+ * @param direct_pool
+ * MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ * MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out

+ *  Pointer array used to keep the mbuf addresses of output segments. If
+ *  the memory space in pkts_out is insufficient, gso_do_segment() fails
+ *  and returns -EINVAL.

+ * @param nb_pkts_out
+ * The max number of items that pkts_out can keep.
+ *
+ * @return

+ *  - The number of segments created in the event of success.
+ *  - Return -ENOMEM if run out of memory in MBUF pools.
+ *  - Return -EINVAL for invalid parameters.

+ */

lib/librte_gso/gso_common.h new file +8 -0
+int gso_do_segment(struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset,
+		uint16_t pyld_unit_size,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#endif
lib/librte_gso/gso_tcp4.c new file +21 -0
new file mode 100644
index 0000000..e3b9dab
@@ -0,0 +1,82 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND

CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */

lib/librte_gso/gso_tcp4.c new file +50 -0
+
+
+#include <rte_ether.h>
+#include <rte_ip.h>
+
+#include "gso_common.h"
+#include "gso_tcp4.h"
+
+int
+gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size, hdr_offset;
+	uint16_t frag_off;
+	int ret = 1;
+
+	/* Don't process the fragmented packet */
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->l2_len);
+	frag_off = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+	if (unlikely(IS_FRAGMENTED(frag_off))) {
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	/* Don't process the packet without data */
+	tcp_dl = pkt->pkt_len - pkt->l2_len - pkt->l3_len - pkt->l4_len;
+	if (unlikely(tcp_dl == 0)) {
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	hdr_offset = pkt->l2_len + pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset;
+
+	/* Segment the payload */
+	ret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,
+			indirect_pool, pkts_out, nb_pkts_out);
+	if (ret > 1)
+		update_tcp4_header(pkt, ipid_delta, pkts_out, ret);
+
+	return ret;
+}
lib/librte_gso/gso_tcp4.h new file +21 -0
new file mode 100644
index 0000000..84fa72f
@@ -0,0 +1,76 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND

CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
+ */

lib/librte_gso/gso_tcp4.h new file +44 -0
+
+#ifndef _GSO_TCP4_H_
+#define _GSO_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment an IPv4/TCP packet. This function doesn't check if the input
+ * packet has correct checksums, and doesn't update checksums for output
+ * GSO segments. Furthermore, it doesn't process IP fragment packets.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param gso_size
+ *  The max length of a GSO segment, measured in bytes.
+ * @param ipid_delta
+ *  The increasing uint of IP ids.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when gso_tcp4_segment() successes. If the memory space in
+ *  pkts_out is insufficient, gso_tcp4_segment() fails and returns
+ *  -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that 'pkts_out' can keep.
+ *
+ * @return
+ *   - The number of GSO segments filled in pkts_out on success.
+ *   - Return -ENOMEM if run out of memory in MBUF pools.
+ *   - Return -EINVAL for invalid parameters.
+ */
+int gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ip_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+
+#endif
lib/librte_gso/rte_gso.c +49 -4
index b773636..c65b9ae 100644
@@ -33,7 +33,12 @@
 
 #include <errno.h>
 
+#include <rte_log.h>
+#include <rte_ethdev.h>
+
 #include "rte_gso.h"
+#include "gso_common.h"
+#include "gso_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -41,12 +46,53 @@ rte_gso_segment(struct rte_mbuf *pkt,
 		struct rte_mbuf **pkts_out,
 		uint16_t nb_pkts_out)
 {
+	struct rte_mempool *direct_pool, *indirect_pool;
+	struct rte_mbuf *pkt_seg;
+	uint64_t ol_flags;
+	uint16_t gso_size;
+	uint8_t ipid_delta;
+	int ret = 1;
+
 	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
 			nb_pkts_out < 1)
 		return -EINVAL;
 
-	pkt->ol_flags &= (~PKT_TX_TCP_SEG);
-	pkts_out[0] = pkt;
+	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
+				DEV_TX_OFFLOAD_TCP_TSO) !=
+			gso_ctx->gso_types) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	direct_pool = gso_ctx->direct_pool;
+	indirect_pool = gso_ctx->indirect_pool;
+	gso_size = gso_ctx->gso_size;
+	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
+	ol_flags = pkt->ol_flags;
+
+	if (IS_IPV4_TCP(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		pkts_out[0] = pkt;
+		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
+		return ret;
+	}
+
+	if (ret > 1) {
+		pkt_seg = pkt;
+		while (pkt_seg) {
+			rte_mbuf_refcnt_update(pkt_seg, -1);
+			pkt_seg = pkt_seg->next;
+		}
+	} else if (ret < 0) {
+		/* Revert the ol_flags on the even of failure. */
+		pkt->ol_flags = ol_flags;
+	}
 
-	return 1;
+	return ret;
 }
--

2.7.4

author
#73 lore raw

PATCH v4 3/5 gso: add VxLAN GSO support

In reply to Jiayu Hu

From: Mark Kavanagh <[email protected]>

This patch adds GSO support for VxLAN-encapsulated packets. Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

VxLAN GSO doesn't check if all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize each output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

VxLAN GSO clears the PKT_TX_TCP_SEG flag for the input packet and GSO segments on the event of success.

---
 doc/guides/rel_notes/release_17_11.rst |  3 ++
 lib/librte_gso/Makefile                |  1 +
 lib/librte_gso/gso_common.c            | 58 +++++++++++++++++++++++
 lib/librte_gso/gso_common.h            | 25 ++++++++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 87 ++++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_tunnel_tcp4.h       | 76 +++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso.c               | 13 +++--
 7 files changed, 260 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
doc/guides/rel_notes/release_17_11.rst +3 -0
index 7453bb0..2dc6b89 100644
@@ -48,6 +48,9 @@ New Features
   ones (e.g. MTU is 1500B). Supported packet types are:
 
   * TCP/IPv4 packets, which may include a single VLAN tag.
+  * VxLAN packets, which must have an outer IPv4 header (prepended by
+    an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
+    an optional VLAN tag).
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c +58 -0

67 lines not on this page · raw message

lib/librte_gso/gso_common.h +25 -0
index 2a01cd0..0b0d8ed 100644
@@ -48,6 +48,11 @@
 #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
 
+#define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_VXLAN))
+
 /**
  * Internal function which updates relevant packet headers for TCP/IPv4
  * packets, following segmentation. This is required to update, for
@@ -69,6 +74,26 @@ void update_tcp4_header(struct rte_mbuf *pkt,
 		uint16_t nb_segs);
 
 /**
+ * Internal function which updates relevant packet headers for VxLAN
+ * packets, following segmentation. This is required to update, for
+ * example, the IPv4 'total_length' field, to reflect the reduced length
+ * of the now-segmented packet.
+ *
+ * @param pkt
+ *  The original packet.
+ * @param ipid_delta
+ *  The increasing uint of IP ids.
+ * @param segs
+ *  Pointer array used for storing mbuf addresses for GSO segments.
+ * @param nb_segs
+ *  The number of GSO segments placed in segs.
+ */
+void update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt,
+		uint8_t ipid_delta,
+		struct rte_mbuf **segs,
+		uint16_t nb_segs);
+
+/**
  * Internal function which divides the input packet into small segments.
  * Each of the newly-created segments is organized as a two-segment MBUF,
  * where the first segment is a standard mbuf, which stores a copy of
lib/librte_gso/gso_tunnel_tcp4.c new file +87 -0

87 lines not on this page · raw message

lib/librte_gso/gso_tunnel_tcp4.h new file +76 -0

76 lines not on this page · raw message

lib/librte_gso/rte_gso.c +10 -3
index c65b9ae..d1a723b 100644
@@ -39,6 +39,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp4.h"
+#include "gso_tunnel_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -58,8 +59,9 @@ rte_gso_segment(struct rte_mbuf *pkt,
 		return -EINVAL;
 
 	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
-				DEV_TX_OFFLOAD_TCP_TSO) !=
-			gso_ctx->gso_types) {
+				(DEV_TX_OFFLOAD_TCP_TSO |
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
+				gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
 		return ret;
@@ -71,7 +73,12 @@ rte_gso_segment(struct rte_mbuf *pkt,
 	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_TCP(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else if (IS_IPV4_TCP(pkt->ol_flags)) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
Signature · 1 line
2.7.4
#74 lore raw

Re: [PATCH v4 3/5] gso: add VxLAN GSO support

Quoted 6 lines · Jiayu Hu

From: Mark Kavanagh <[email protected]>

This patch adds GSO support for VxLAN-encapsulated packets. Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

This patch not only adds support for VxLAN, but also support for tunnel framework. Better to mention it in the first place.

Quoted 4 lines

VxLAN GSO doesn't check if all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

Quoted 8 lines

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize each output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

VxLAN GSO clears the PKT_TX_TCP_SEG flag for the input packet and GSO segments on the event of success.

This flag is not cleared here, it's cleared in the gso interface. So remove above sentence?

Quoted 75 lines
---
  doc/guides/rel_notes/release_17_11.rst |  3 ++
  lib/librte_gso/Makefile                |  1 +
  lib/librte_gso/gso_common.c            | 58 +++++++++++++++++++++++
  lib/librte_gso/gso_common.h            | 25 ++++++++++
  lib/librte_gso/gso_tunnel_tcp4.c       | 87 ++++++++++++++++++++++++++++++++++
  lib/librte_gso/gso_tunnel_tcp4.h       | 76 +++++++++++++++++++++++++++++
  lib/librte_gso/rte_gso.c               | 13 +++--
  7 files changed, 260 insertions(+), 3 deletions(-)

create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h

doc/guides/rel_notes/release_17_11.rst +3 -0
index 7453bb0..2dc6b89 100644
@@ -48,6 +48,9 @@ New Features
    ones (e.g. MTU is 1500B). Supported packet types are:
 
    * TCP/IPv4 packets, which may include a single VLAN tag.
+  * VxLAN packets, which must have an outer IPv4 header (prepended by
+    an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
+    an optional VLAN tag).
 
    The GSO library doesn't check if the input packets have correct
    checksums, and doesn't update checksums for output packets.
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
  SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
  SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
  SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
  # install this header file
  SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c +19 -0
index b2c84f6..90fcb2a 100644
@@ -39,6 +39,7 @@
  #include <rte_ether.h>
  #include <rte_ip.h>
  #include <rte_tcp.h>
+#include <rte_udp.h>
 
  #include "gso_common.h"
 
@@ -200,3 +201,60 @@ update_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,
  		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
  	}
  }
+
+static inline void
+__update_outer_ipv4_header(struct rte_mbuf *pkt, uint16_t id)
+{
+	struct ipv4_hdr *ipv4_hdr;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->outer_l2_len);
+	ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len -
+			pkt->outer_l2_len);
+	ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
+}
+
+static inline void
+__update_outer_udp_header(struct rte_mbuf *pkt)
+{
+	struct udp_hdr *udp_hdr;
+	uint16_t length;

lib/librte_gso/gso_common.c update_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta, · line 231

Quoted 10 lines
lib/librte_gso/gso_common.c +10 -0
+
+	length = pkt->outer_l2_len + pkt->outer_l3_len;
+	udp_hdr = (struct udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			length);
+	udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - length);
+}
+
+void
+update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)

This function is specific to tunnel, better move to gso_tunnel_tcp4.c

Quoted 132 lines
lib/librte_gso/gso_common.c +29 -0
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	uint32_t sent_seq;
+	uint16_t l2_len, outer_id, inner_id, tail_idx, i;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->outer_l2_len);
+	outer_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+
+	l2_len = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			l2_len);
+	inner_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+
+	for (i = 0; i < nb_segs; i++) {
+		__update_outer_ipv4_header(segs[i], outer_id);
+		outer_id += ipid_delta;
+		__update_outer_udp_header(segs[i]);
+
+		__update_ipv4_tcp_header(segs[i], l2_len, inner_id, sent_seq,
+				i < tail_idx);
+		inner_id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
lib/librte_gso/gso_common.h +25 -0
index 2a01cd0..0b0d8ed 100644
@@ -48,6 +48,11 @@
  #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
  		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
 
+#define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_VXLAN))
+
  /**
   * Internal function which updates relevant packet headers for TCP/IPv4
   * packets, following segmentation. This is required to update, for
@@ -69,6 +74,26 @@ void update_tcp4_header(struct rte_mbuf *pkt,
  		uint16_t nb_segs);
 
  /**
+ * Internal function which updates relevant packet headers for VxLAN
+ * packets, following segmentation. This is required to update, for
+ * example, the IPv4 'total_length' field, to reflect the reduced length
+ * of the now-segmented packet.
+ *
+ * @param pkt
+ *  The original packet.
+ * @param ipid_delta
+ *  The increasing uint of IP ids.
+ * @param segs
+ *  Pointer array used for storing mbuf addresses for GSO segments.
+ * @param nb_segs
+ *  The number of GSO segments placed in segs.
+ */
+void update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt,
+		uint8_t ipid_delta,
+		struct rte_mbuf **segs,
+		uint16_t nb_segs);
+
+/**
   * Internal function which divides the input packet into small segments.
   * Each of the newly-created segments is organized as a two-segment MBUF,
   * where the first segment is a standard mbuf, which stores a copy of
lib/librte_gso/gso_tunnel_tcp4.c new file +54 -0
new file mode 100644
index 0000000..cc017bd
@@ -0,0 +1,87 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <rte_ether.h>
+#include <rte_ip.h>
+
+#include "gso_common.h"
+#include "gso_tunnel_tcp4.h"
+
+int
+gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ipv4_hdr *inner_ipv4_hdr;
+	uint16_t pyld_unit_size, hdr_offset;
+	uint16_t tcp_dl, frag_off;
+	int ret = 1;
+
+	hdr_offset = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;

lib/librte_gso/gso_tunnel_tcp4.c line 64

Quoted 10 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +10 -0
+	inner_ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			hdr_offset);
+	/*
+	 * Don't process the packet whose MF bit and offset in the inner
+	 * IPv4 header are non-zero.
+	 */
+	frag_off = rte_be_to_cpu_16(inner_ipv4_hdr->fragment_offset);
+	if (unlikely(IS_FRAGMENTED(frag_off))) {
+		pkts_out[0] = pkt;
+		return ret;

Please use "return 1;" for readability.

lib/librte_gso/gso_tunnel_tcp4.c line 71

Quoted 7 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +7 -0
+	}
+
+	/* Don't process the packet without data */
+	tcp_dl = pkt->pkt_len - pkt->l2_len - pkt->l3_len - pkt->l4_len;
+	if (unlikely(tcp_dl == 0)) {
+		pkts_out[0] = pkt;
+		return ret;

Ditto.

Quoted 71 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +16 -0
+	}
+
+	hdr_offset += pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset;
+
+	/* Segment the payload */
+	ret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,
+			indirect_pool, pkts_out, nb_pkts_out);
+	if (ret <= 1)
+		return ret;
+
+	if (pkt->ol_flags & PKT_TX_TUNNEL_VXLAN)
+		update_ipv4_vxlan_tcp4_header(pkt, ipid_delta, pkts_out, ret);
+
+	return ret;
+}
lib/librte_gso/gso_tunnel_tcp4.h new file +49 -0
new file mode 100644
index 0000000..a848a2e
@@ -0,0 +1,76 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GSO_TUNNEL_TCP4_H_
+#define _GSO_TUNNEL_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment an tunneling packet with inner TCP/IPv4 headers. This function
+ * doesn't check if the input packet has correct checksums, and doesn't
+ * update checksums for output GSO segments. Furthermore, it doesn't
+ * process IP fragment packets.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param gso_size
+ *  The max length of a GSO segment, measured in bytes.

lib/librte_gso/gso_tunnel_tcp4.h line 59

Quoted 10 lines
lib/librte_gso/gso_tunnel_tcp4.h new file +10 -0
+ * @param ipid_delta
+ *  The increasing uint of IP ids.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when gso_tunnel_tcp4_segment() successes. If the memory
+ *  space in pkts_out is insufficient, gso_tcp4_segment() fails and

"gso_tcp4_segment()" -> "it".

Thanks,
Jianfeng

author
#75 lore raw

Re: [PATCH v4 3/5] gso: add VxLAN GSO support

Hi Jianfeng,

Quoted 32 lines

-----Original Message-----
From: Tan, Jianfeng
Sent: Wednesday, September 20, 2017 11:11 AM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: Ananyev, Konstantin <[email protected]>; Kavanagh, Mark B <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: Re: [PATCH v4 3/5] gso: add VxLAN GSO support

Quoted 6 lines · Jiayu Hu

From: Mark Kavanagh <[email protected]>

This patch adds GSO support for VxLAN-encapsulated packets. Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

This patch not only adds support for VxLAN, but also support for tunnel framework. Better to mention it in the first place.

Quoted 5 lines

VxLAN GSO doesn't check if all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize

each

Quoted 5 lines

output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

Quoted 5 lines
Quoted 2 lines

VxLAN GSO clears the PKT_TX_TCP_SEG flag for the input packet and GSO segments on the event of success.

This flag is not cleared here, it's cleared in the gso interface. So remove above sentence?

Make sense. I will remove the above sentence.

Quoted 84 lines
Quoted 10 lines
---
  doc/guides/rel_notes/release_17_11.rst |  3 ++
  lib/librte_gso/Makefile                |  1 +
  lib/librte_gso/gso_common.c            | 58 +++++++++++++++++++++++
  lib/librte_gso/gso_common.h            | 25 ++++++++++
  lib/librte_gso/gso_tunnel_tcp4.c       | 87

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

Quoted 1 line
  lib/librte_gso/gso_tunnel_tcp4.h       | 76

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

Review

Quoted 6 lines
  lib/librte_gso/rte_gso.c               | 13 +++--
  7 files changed, 260 insertions(+), 3 deletions(-)

create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h

(quoted diff) +0 -0

b/doc/guides/rel_notes/release_17_11.rst

lib/librte_gso/gso_common.c update_tcp4_header(struct rte_mbuf *pkt,

Quoted 38 lines

index 7453bb0..2dc6b89 100644

doc/guides/rel_notes/release_17_11.rst +3 -0
@@ -48,6 +48,9 @@ New Features
    ones (e.g. MTU is 1500B). Supported packet types are:
 
    * TCP/IPv4 packets, which may include a single VLAN tag.
+  * VxLAN packets, which must have an outer IPv4 header (prepended by
+    an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
+    an optional VLAN tag).
 
    The GSO library doesn't check if the input packets have correct
    checksums, and doesn't update checksums for output packets.
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
  SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
  SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
  SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
  # install this header file
  SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c +1 -0
index b2c84f6..90fcb2a 100644
@@ -39,6 +39,7 @@
  #include <rte_ether.h>
  #include <rte_ip.h>
  #include <rte_tcp.h>
+#include <rte_udp.h>
 
  #include "gso_common.h"
 
@@ -200,3 +201,60 @@ update_tcp4_header(struct rte_mbuf *pkt,

uint8_t ipid_delta,

Quoted 25 lines
lib/librte_gso/gso_common.c +22 -0
  		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
  	}
  }
+
+static inline void
+__update_outer_ipv4_header(struct rte_mbuf *pkt, uint16_t id)
+{
+	struct ipv4_hdr *ipv4_hdr;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->outer_l2_len);
+	ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len -
+			pkt->outer_l2_len);
+	ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
+}
+
+static inline void
+__update_outer_udp_header(struct rte_mbuf *pkt)
+{
+	struct udp_hdr *udp_hdr;
+	uint16_t length;
+
+	length = pkt->outer_l2_len + pkt->outer_l3_len;
+	udp_hdr = (struct udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			length);
Quoted 8 lines

lib/librte_gso/gso_common.c update_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta, · line 231

Quoted 6 lines
lib/librte_gso/gso_common.c +6 -0
+	udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - length);
+}
+
+void
+update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)

This function is specific to tunnel, better move to gso_tunnel_tcp4.c

Make sense. I will remove GRE header update function too.

Quoted 154 lines
Quoted 15 lines
lib/librte_gso/gso_common.c +14 -0
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	uint32_t sent_seq;
+	uint16_t l2_len, outer_id, inner_id, tail_idx, i;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->outer_l2_len);
+	outer_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+
+	l2_len = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			l2_len);
+	inner_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);

lib/librte_gso/gso_common.c update_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,

Quoted 10 lines
lib/librte_gso/gso_common.c +10 -0
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+
+	for (i = 0; i < nb_segs; i++) {
+		__update_outer_ipv4_header(segs[i], outer_id);
+		outer_id += ipid_delta;
+		__update_outer_udp_header(segs[i]);
+
+		__update_ipv4_tcp_header(segs[i], l2_len, inner_id,

sent_seq,

lib/librte_gso/gso_common.h line 48

Quoted 11 lines
lib/librte_gso/gso_common.c +5 -0
+				i < tail_idx);
+		inner_id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
lib/librte_gso/gso_common.h +0 -0
index 2a01cd0..0b0d8ed 100644
@@ -48,6 +48,11 @@
  #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) ==

\

lib/librte_gso/gso_common.h

Quoted 3 lines
lib/librte_gso/gso_common.h +1 -0
  		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
 
+#define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG |

PKT_TX_IPV4 | \

lib/librte_gso/gso_common.h line 52

Quoted 1 line
lib/librte_gso/gso_common.h +1 -0
+				PKT_TX_OUTER_IPV4 |

PKT_TX_TUNNEL_VXLAN)) == \

Quoted 22 lines
lib/librte_gso/gso_common.h +15 -0
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_VXLAN))
+
  /**
   * Internal function which updates relevant packet headers for TCP/IPv4
   * packets, following segmentation. This is required to update, for
@@ -69,6 +74,26 @@ void update_tcp4_header(struct rte_mbuf *pkt,
  		uint16_t nb_segs);
 
  /**
+ * Internal function which updates relevant packet headers for VxLAN
+ * packets, following segmentation. This is required to update, for
+ * example, the IPv4 'total_length' field, to reflect the reduced length
+ * of the now-segmented packet.
+ *
+ * @param pkt
+ *  The original packet.
+ * @param ipid_delta
+ *  The increasing uint of IP ids.
+ * @param segs
+ *  Pointer array used for storing mbuf addresses for GSO segments.
+ * @param nb_segs

lib/librte_gso/gso_common.h void update_tcp4_header(struct rte_mbuf *pkt, · line 98

Quoted 10 lines
lib/librte_gso/gso_common.h +8 -0
+ *  The number of GSO segments placed in segs.
+ */
+void update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt,
+		uint8_t ipid_delta,
+		struct rte_mbuf **segs,
+		uint16_t nb_segs);
+
+/**
   * Internal function which divides the input packet into small segments.
   * Each of the newly-created segments is organized as a two-segment

MBUF,

Review

Quoted 2 lines
lib/librte_gso/gso_common.h +0 -0
   * where the first segment is a standard mbuf, which stores a copy of
(quoted diff) +0 -0

b/lib/librte_gso/gso_tunnel_tcp4.c

Quoted 16 lines

new file mode 100644
index 0000000..cc017bd

lib/librte_gso/gso_tunnel_tcp4.c new file +11 -0
@@ -0,0 +1,87 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright

lib/librte_gso/gso_tunnel_tcp4.c line 21

Quoted 10 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +10 -0
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND

CONTRIBUTORS

lib/librte_gso/gso_tunnel_tcp4.c line 22

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.c new file +1 -0
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT

NOT

lib/librte_gso/gso_tunnel_tcp4.c line 23

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.c new file +1 -0
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND

FITNESS FOR

lib/librte_gso/gso_tunnel_tcp4.c line 24

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.c new file +1 -0
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE

COPYRIGHT

lib/librte_gso/gso_tunnel_tcp4.c line 25

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.c new file +1 -0
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,

INCIDENTAL,

lib/librte_gso/gso_tunnel_tcp4.c line 26

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.c new file +1 -0
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,

BUT NOT

lib/librte_gso/gso_tunnel_tcp4.c line 27

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.c new file +1 -0
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

LOSS OF USE,

lib/librte_gso/gso_tunnel_tcp4.c line 28

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.c new file +1 -0
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED

AND ON ANY

lib/librte_gso/gso_tunnel_tcp4.c line 29

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.c new file +1 -0
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR

TORT

lib/librte_gso/gso_tunnel_tcp4.c line 30

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.c new file +1 -0
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT

OF THE USE

lib/librte_gso/gso_tunnel_tcp4.c line 31

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.c new file +1 -0
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH

DAMAGE.

Quoted 27 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +27 -0
+ */
+
+#include <rte_ether.h>
+#include <rte_ip.h>
+
+#include "gso_common.h"
+#include "gso_tunnel_tcp4.h"
+
+int
+gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ipv4_hdr *inner_ipv4_hdr;
+	uint16_t pyld_unit_size, hdr_offset;
+	uint16_t tcp_dl, frag_off;
+	int ret = 1;
+
+	hdr_offset = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;
+	inner_ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			hdr_offset);
+	/*
+	 * Don't process the packet whose MF bit and offset in the inner
Quoted 8 lines

lib/librte_gso/gso_tunnel_tcp4.c line 64

Quoted 6 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +6 -0
+	 * IPv4 header are non-zero.
+	 */
+	frag_off = rte_be_to_cpu_16(inner_ipv4_hdr->fragment_offset);
+	if (unlikely(IS_FRAGMENTED(frag_off))) {
+		pkts_out[0] = pkt;
+		return ret;

Please use "return 1;" for readability.

OK.

Quoted 99 lines

lib/librte_gso/gso_tunnel_tcp4.c line 71

Quoted 8 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +7 -0
+	}
+
+	/* Don't process the packet without data */
+	tcp_dl = pkt->pkt_len - pkt->l2_len - pkt->l3_len - pkt->l4_len;
+	if (unlikely(tcp_dl == 0)) {
+		pkts_out[0] = pkt;
+		return ret;

Ditto.

lib/librte_gso/gso_tunnel_tcp4.c

Quoted 13 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +13 -0
+	}
+
+	hdr_offset += pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset;
+
+	/* Segment the payload */
+	ret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,
+			indirect_pool, pkts_out, nb_pkts_out);
+	if (ret <= 1)
+		return ret;
+
+	if (pkt->ol_flags & PKT_TX_TUNNEL_VXLAN)
+		update_ipv4_vxlan_tcp4_header(pkt, ipid_delta, pkts_out,

ret);

Review

Quoted 4 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +3 -0
+
+	return ret;
+}
(quoted diff) +0 -0

b/lib/librte_gso/gso_tunnel_tcp4.h

Quoted 16 lines

new file mode 100644
index 0000000..a848a2e

lib/librte_gso/gso_tunnel_tcp4.h new file +11 -0
@@ -0,0 +1,76 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright

lib/librte_gso/gso_tunnel_tcp4.h line 21

Quoted 10 lines
lib/librte_gso/gso_tunnel_tcp4.h new file +10 -0
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND

CONTRIBUTORS

lib/librte_gso/gso_tunnel_tcp4.h line 22

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.h new file +1 -0
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT

NOT

lib/librte_gso/gso_tunnel_tcp4.h line 23

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.h new file +1 -0
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND

FITNESS FOR

lib/librte_gso/gso_tunnel_tcp4.h line 24

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.h new file +1 -0
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE

COPYRIGHT

lib/librte_gso/gso_tunnel_tcp4.h line 25

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.h new file +1 -0
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,

INCIDENTAL,

lib/librte_gso/gso_tunnel_tcp4.h line 26

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.h new file +1 -0
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,

BUT NOT

lib/librte_gso/gso_tunnel_tcp4.h line 27

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.h new file +1 -0
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;

LOSS OF USE,

lib/librte_gso/gso_tunnel_tcp4.h line 28

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.h new file +1 -0
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED

AND ON ANY

lib/librte_gso/gso_tunnel_tcp4.h line 29

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.h new file +1 -0
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR

TORT

lib/librte_gso/gso_tunnel_tcp4.h line 30

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.h new file +1 -0
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT

OF THE USE

lib/librte_gso/gso_tunnel_tcp4.h line 31

Quoted 1 line
lib/librte_gso/gso_tunnel_tcp4.h new file +1 -0
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH

DAMAGE.

Quoted 22 lines
lib/librte_gso/gso_tunnel_tcp4.h new file +22 -0
+ */
+
+#ifndef _GSO_TUNNEL_TCP4_H_
+#define _GSO_TUNNEL_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment an tunneling packet with inner TCP/IPv4 headers. This function
+ * doesn't check if the input packet has correct checksums, and doesn't
+ * update checksums for output GSO segments. Furthermore, it doesn't
+ * process IP fragment packets.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param gso_size
+ *  The max length of a GSO segment, measured in bytes.
+ * @param ipid_delta
+ *  The increasing uint of IP ids.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
Quoted 8 lines

lib/librte_gso/gso_tunnel_tcp4.h line 59

Quoted 6 lines
lib/librte_gso/gso_tunnel_tcp4.h new file +6 -0
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when gso_tunnel_tcp4_segment() successes. If the memory
+ *  space in pkts_out is insufficient, gso_tcp4_segment() fails and

"gso_tcp4_segment()" -> "it".

Yes, a typo here. Thanks.

Thanks,
Jiayu

Quoted 3 lines

Thanks,
Jianfeng

author
#76 lore raw

PATCH v4 4/5 gso: add GRE GSO support

In reply to Jiayu Hu

From: Mark Kavanagh <[email protected]>

This patch adds GSO support for GRE-tunneled packets. Supported GRE packets must contain an outer IPv4 header, and inner TCP/IPv4 headers. They may also contain a single VLAN tag. GRE GSO doesn't check if all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with VxLAN GSO, GRE GSO uses a two-segment MBUF to organize each output packet, which requires multi-segment mbuf support in the TX functions of the NIC driver. Also, if a packet is GSOed, GRE GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

GRE GSO clears the PKT_TX_TCP_SEG flag for the input packet and GSO segments on the event of success.

---
 doc/guides/rel_notes/release_17_11.rst |  3 +++
 lib/librte_gso/gso_common.c            | 31 +++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h            | 25 +++++++++++++++++++++++++
 lib/librte_gso/gso_tunnel_tcp4.c       |  2 ++
 lib/librte_gso/rte_gso.c               |  8 +++++---
 5 files changed, 66 insertions(+), 3 deletions(-)
doc/guides/rel_notes/release_17_11.rst +3 -0
index 2dc6b89..119f662 100644
@@ -51,6 +51,9 @@ New Features
   * VxLAN packets, which must have an outer IPv4 header (prepended by
     an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
     an optional VLAN tag).
+  * GRE packets, which must contain an outer IPv4 header (prepended by
+    an optional VLAN tag), and inner TCP/IPv4 headers (with an optional
+    VLAN tag).
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/gso_common.c +31 -0
index 90fcb2a..3629625 100644
@@ -37,6 +37,7 @@
 #include <rte_memcpy.h>
 #include <rte_mempool.h>
 #include <rte_ether.h>
+#include <rte_gre.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
 #include <rte_udp.h>
@@ -258,3 +259,33 @@ update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,
 		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
 	}
 }
+
+void
+update_ipv4_gre_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	uint32_t sent_seq;
+	uint16_t l2_len, outer_id, inner_id, tail_idx, i;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->outer_l2_len);
+	outer_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+
+	l2_len = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) + l2_len);
+	inner_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+	for (i = 0; i < nb_segs; i++) {
+		__update_outer_ipv4_header(segs[i], outer_id);
+		outer_id += ipid_delta;
+
+		__update_ipv4_tcp_header(segs[i], l2_len, inner_id, sent_seq,
+				i < tail_idx);
+		inner_id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
lib/librte_gso/gso_common.h +25 -0
index 0b0d8ed..433e952 100644
@@ -53,6 +53,11 @@
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
 		 PKT_TX_TUNNEL_VXLAN))
 
+#define IS_IPV4_GRE_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_GRE)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_GRE))
+
 /**
  * Internal function which updates relevant packet headers for TCP/IPv4
  * packets, following segmentation. This is required to update, for
@@ -94,6 +99,26 @@ void update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt,
 		uint16_t nb_segs);
 
 /**
+ * Internal function which updates relevant packet headers for GRE
+ * packets, following segmentation. This is required to update, for
+ * example, the IPv4 'total_length' field, to reflect the reduced
+ * length of the now-segmented packet.
+ *
+ * @param pkt
+ *  The original packet.
+ * @param ipid_delta
+ *  The increasing uint of IP ids.
+ * @param segs
+ *  Pointer array used for storing mbuf addresses for GSO segments.
+ * @param nb_segs
+ *  The number of GSO segments placed in segs.
+ */
+void update_ipv4_gre_tcp4_header(struct rte_mbuf *pkt,
+		uint8_t ipid_delta,
+		struct rte_mbuf **segs,
+		uint16_t nb_segs);
+
+/**
  * Internal function which divides the input packet into small segments.
  * Each of the newly-created segments is organized as a two-segment MBUF,
  * where the first segment is a standard mbuf, which stores a copy of
lib/librte_gso/gso_tunnel_tcp4.c +2 -0
index cc017bd..5d5930a 100644
@@ -82,6 +82,8 @@ gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
 
 	if (pkt->ol_flags & PKT_TX_TUNNEL_VXLAN)
 		update_ipv4_vxlan_tcp4_header(pkt, ipid_delta, pkts_out, ret);
+	else if (pkt->ol_flags & PKT_TX_TUNNEL_GRE)
+		update_ipv4_gre_tcp4_header(pkt, ipid_delta, pkts_out, ret);
 
 	return ret;
 }
lib/librte_gso/rte_gso.c +5 -3
index d1a723b..5464831 100644
@@ -60,8 +60,9 @@ rte_gso_segment(struct rte_mbuf *pkt,
 
 	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
 				(DEV_TX_OFFLOAD_TCP_TSO |
-				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
-				gso_ctx->gso_types) {
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+				 DEV_TX_OFFLOAD_GRE_TNL_TSO)) !=
+				 gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
 		return ret;
@@ -73,7 +74,8 @@ rte_gso_segment(struct rte_mbuf *pkt,
 	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags) ||
+			IS_IPV4_GRE_TCP4(pkt->ol_flags)) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
Signature · 1 line
2.7.4
#77 lore raw

Re: [PATCH v4 4/5] gso: add GRE GSO support

Hi,

Quoted 54 lines · Jiayu Hu

From: Mark Kavanagh <[email protected]>

This patch adds GSO support for GRE-tunneled packets. Supported GRE packets must contain an outer IPv4 header, and inner TCP/IPv4 headers. They may also contain a single VLAN tag. GRE GSO doesn't check if all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with VxLAN GSO, GRE GSO uses a two-segment MBUF to organize each output packet, which requires multi-segment mbuf support in the TX functions of the NIC driver. Also, if a packet is GSOed, GRE GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

GRE GSO clears the PKT_TX_TCP_SEG flag for the input packet and GSO segments on the event of success.

---
  doc/guides/rel_notes/release_17_11.rst |  3 +++
  lib/librte_gso/gso_common.c            | 31 +++++++++++++++++++++++++++++++
  lib/librte_gso/gso_common.h            | 25 +++++++++++++++++++++++++
  lib/librte_gso/gso_tunnel_tcp4.c       |  2 ++
  lib/librte_gso/rte_gso.c               |  8 +++++---
  5 files changed, 66 insertions(+), 3 deletions(-)
doc/guides/rel_notes/release_17_11.rst +3 -0
index 2dc6b89..119f662 100644
@@ -51,6 +51,9 @@ New Features
    * VxLAN packets, which must have an outer IPv4 header (prepended by
      an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
      an optional VLAN tag).
+  * GRE packets, which must contain an outer IPv4 header (prepended by
+    an optional VLAN tag), and inner TCP/IPv4 headers (with an optional
+    VLAN tag).
 
    The GSO library doesn't check if the input packets have correct
    checksums, and doesn't update checksums for output packets.
lib/librte_gso/gso_common.c +1 -0
index 90fcb2a..3629625 100644
@@ -37,6 +37,7 @@
  #include <rte_memcpy.h>
  #include <rte_mempool.h>
  #include <rte_ether.h>
+#include <rte_gre.h>
  #include <rte_ip.h>
  #include <rte_tcp.h>
  #include <rte_udp.h>

lib/librte_gso/gso_common.c update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta, · line 266

Quoted 8 lines
lib/librte_gso/gso_common.c +5 -0
@@ -258,3 +259,33 @@ update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,
  		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
  	}
  }
+
+void
+update_ipv4_gre_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{

This function seems to have too many duplicated code with above function, can we merge?

Quoted 8 lines
lib/librte_gso/gso_common.c +8 -0
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	uint32_t sent_seq;
+	uint16_t l2_len, outer_id, inner_id, tail_idx, i;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->outer_l2_len);
+	outer_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);

lib/librte_gso/gso_common.c update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta, · line 284

Quoted 10 lines
lib/librte_gso/gso_common.c +10 -0
+
+	l2_len = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) + l2_len);
+	inner_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+	for (i = 0; i < nb_segs; i++) {
+		__update_outer_ipv4_header(segs[i], outer_id);
+		outer_id += ipid_delta;

We should update both outer and inner IPID? Could you add some spec reference here?

Quoted 26 lines
lib/librte_gso/gso_common.c +7 -0
+
+		__update_ipv4_tcp_header(segs[i], l2_len, inner_id, sent_seq,
+				i < tail_idx);
+		inner_id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
lib/librte_gso/gso_common.h +5 -0
index 0b0d8ed..433e952 100644
@@ -53,6 +53,11 @@
  		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
  		 PKT_TX_TUNNEL_VXLAN))
 
+#define IS_IPV4_GRE_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_GRE)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_GRE))
+
  /**
   * Internal function which updates relevant packet headers for TCP/IPv4
   * packets, following segmentation. This is required to update, for
@@ -94,6 +99,26 @@ void update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt,
  		uint16_t nb_segs);
 

lib/librte_gso/gso_common.h void update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt, · line 110

Quoted 10 lines
lib/librte_gso/gso_common.h +9 -0
  /**
+ * Internal function which updates relevant packet headers for GRE
+ * packets, following segmentation. This is required to update, for
+ * example, the IPv4 'total_length' field, to reflect the reduced
+ * length of the now-segmented packet.
+ *
+ * @param pkt
+ *  The original packet.
+ * @param ipid_delta
+ *  The increasing uint of IP ids.

uint -> unit?

Quoted 53 lines
lib/librte_gso/gso_common.h +11 -0
+ * @param segs
+ *  Pointer array used for storing mbuf addresses for GSO segments.
+ * @param nb_segs
+ *  The number of GSO segments placed in segs.
+ */
+void update_ipv4_gre_tcp4_header(struct rte_mbuf *pkt,
+		uint8_t ipid_delta,
+		struct rte_mbuf **segs,
+		uint16_t nb_segs);
+
+/**
   * Internal function which divides the input packet into small segments.
   * Each of the newly-created segments is organized as a two-segment MBUF,
   * where the first segment is a standard mbuf, which stores a copy of
lib/librte_gso/gso_tunnel_tcp4.c +2 -0
index cc017bd..5d5930a 100644
@@ -82,6 +82,8 @@ gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
 
  	if (pkt->ol_flags & PKT_TX_TUNNEL_VXLAN)
  		update_ipv4_vxlan_tcp4_header(pkt, ipid_delta, pkts_out, ret);
+	else if (pkt->ol_flags & PKT_TX_TUNNEL_GRE)
+		update_ipv4_gre_tcp4_header(pkt, ipid_delta, pkts_out, ret);
 
  	return ret;
  }
lib/librte_gso/rte_gso.c +5 -3
index d1a723b..5464831 100644
@@ -60,8 +60,9 @@ rte_gso_segment(struct rte_mbuf *pkt,
 
  	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
  				(DEV_TX_OFFLOAD_TCP_TSO |
-				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
-				gso_ctx->gso_types) {
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+				 DEV_TX_OFFLOAD_GRE_TNL_TSO)) !=
+				 gso_ctx->gso_types) {
  		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
  		pkts_out[0] = pkt;
  		return ret;
@@ -73,7 +74,8 @@ rte_gso_segment(struct rte_mbuf *pkt,
  	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
  	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags) ||
+			IS_IPV4_GRE_TCP4(pkt->ol_flags)) {
  		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
  		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
  				direct_pool, indirect_pool,
author
#78 lore raw

Re: [PATCH v4 4/5] gso: add GRE GSO support

Hi Jianfeng,

Quoted 70 lines

-----Original Message-----
From: Tan, Jianfeng
Sent: Wednesday, September 20, 2017 10:54 AM
To: Hu, Jiayu <[email protected]>; [email protected]
Cc: Ananyev, Konstantin <[email protected]>; Kavanagh, Mark B <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: Re: [PATCH v4 4/5] gso: add GRE GSO support

Hi,

Quoted 14 lines · Jiayu Hu

From: Mark Kavanagh <[email protected]>

This patch adds GSO support for GRE-tunneled packets. Supported GRE packets must contain an outer IPv4 header, and inner TCP/IPv4 headers. They may also contain a single VLAN tag. GRE GSO doesn't check if all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with VxLAN GSO, GRE GSO uses a two-segment MBUF to organize each output packet, which requires multi-segment mbuf support in the TX functions of the NIC driver. Also, if a packet is GSOed, GRE GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

Quoted 8 lines

GRE GSO clears the PKT_TX_TCP_SEG flag for the input packet and GSO segments on the event of success.

---
  doc/guides/rel_notes/release_17_11.rst |  3 +++
  lib/librte_gso/gso_common.c            | 31

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

Review

Quoted 6 lines
  lib/librte_gso/gso_common.h            | 25 +++++++++++++++++++++++++
  lib/librte_gso/gso_tunnel_tcp4.c       |  2 ++
  lib/librte_gso/rte_gso.c               |  8 +++++---
  5 files changed, 66 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_17_11.rst

lib/librte_gso/gso_common.c update_ipv4_vxlan_tcp4_header(struct rte_mbuf

Quoted 26 lines

index 2dc6b89..119f662 100644

doc/guides/rel_notes/release_17_11.rst +3 -0
@@ -51,6 +51,9 @@ New Features
    * VxLAN packets, which must have an outer IPv4 header (prepended by
      an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
      an optional VLAN tag).
+  * GRE packets, which must contain an outer IPv4 header (prepended by
+    an optional VLAN tag), and inner TCP/IPv4 headers (with an optional
+    VLAN tag).
 
    The GSO library doesn't check if the input packets have correct
    checksums, and doesn't update checksums for output packets.
lib/librte_gso/gso_common.c +1 -0
index 90fcb2a..3629625 100644
@@ -37,6 +37,7 @@
  #include <rte_memcpy.h>
  #include <rte_mempool.h>
  #include <rte_ether.h>
+#include <rte_gre.h>
  #include <rte_ip.h>
  #include <rte_tcp.h>
  #include <rte_udp.h>
@@ -258,3 +259,33 @@ update_ipv4_vxlan_tcp4_header(struct rte_mbuf

*pkt, uint8_t ipid_delta,

Quoted 11 lines

lib/librte_gso/gso_common.c update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta, · line 266

Quoted 8 lines
lib/librte_gso/gso_common.c +5 -0
  		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
  	}
  }
+
+void
+update_ipv4_gre_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{

This function seems to have too many duplicated code with above function, can we merge?

Yes, they can be merged into one.

Quoted 13 lines

lib/librte_gso/gso_common.c update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,

Quoted 12 lines
lib/librte_gso/gso_common.c +11 -0
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	uint32_t sent_seq;
+	uint16_t l2_len, outer_id, inner_id, tail_idx, i;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->outer_l2_len);
+	outer_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+
+	l2_len = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +

l2_len);

Quoted 10 lines

lib/librte_gso/gso_common.c update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta, · line 284

Quoted 7 lines
lib/librte_gso/gso_common.c +7 -0
+	inner_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+	for (i = 0; i < nb_segs; i++) {
+		__update_outer_ipv4_header(segs[i], outer_id);
+		outer_id += ipid_delta;

We should update both outer and inner IPID? Could you add some spec reference here?

I check the VxLAN RFC, but it doesn't have strict limits on the value of outer IP ID. In the implementation of Linux GSO, the outer IP ID is always incremental, where SKB_GSO_TCP_FIXEDID is only meaningful to inner IP ID.

If no objections, I will take the same design as Linux. Wonder your opinions, @Jianfeng @Konstantin @Mark.

Thanks,
Jiayu

Quoted 100 lines

lib/librte_gso/gso_common.c update_ipv4_vxlan_tcp4_header(struct rte_mbuf · line 286

Quoted 3 lines
lib/librte_gso/gso_common.c +2 -0
+
+		__update_ipv4_tcp_header(segs[i], l2_len, inner_id,

sent_seq,

Quoted 10 lines
lib/librte_gso/gso_common.c +5 -0
+				i < tail_idx);
+		inner_id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
lib/librte_gso/gso_common.h +0 -0
index 0b0d8ed..433e952 100644

lib/librte_gso/gso_common.h line 56

Quoted 4 lines
lib/librte_gso/gso_common.h +1 -0
@@ -53,6 +53,11 @@
  		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
  		 PKT_TX_TUNNEL_VXLAN))
 
+#define IS_IPV4_GRE_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG |

PKT_TX_IPV4 | \

lib/librte_gso/gso_common.h line 57

Quoted 1 line
lib/librte_gso/gso_common.h +1 -0
+				PKT_TX_OUTER_IPV4 |

PKT_TX_TUNNEL_GRE)) == \

lib/librte_gso/gso_common.h void update_ipv4_vxlan_tcp4_header(struct

Quoted 7 lines
lib/librte_gso/gso_common.h +3 -0
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_GRE))
+
  /**
   * Internal function which updates relevant packet headers for TCP/IPv4
   * packets, following segmentation. This is required to update, for
@@ -94,6 +99,26 @@ void update_ipv4_vxlan_tcp4_header(struct

rte_mbuf *pkt,

lib/librte_gso/gso_common.h void update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt, · line 110

Quoted 12 lines
lib/librte_gso/gso_common.h +9 -0
  		uint16_t nb_segs);
 
  /**
+ * Internal function which updates relevant packet headers for GRE
+ * packets, following segmentation. This is required to update, for
+ * example, the IPv4 'total_length' field, to reflect the reduced
+ * length of the now-segmented packet.
+ *
+ * @param pkt
+ *  The original packet.
+ * @param ipid_delta
+ *  The increasing uint of IP ids.

uint -> unit?

lib/librte_gso/gso_common.h void update_ipv4_vxlan_tcp4_header(struct rte_mbuf *pkt,

Quoted 13 lines
lib/librte_gso/gso_common.h +11 -0
+ * @param segs
+ *  Pointer array used for storing mbuf addresses for GSO segments.
+ * @param nb_segs
+ *  The number of GSO segments placed in segs.
+ */
+void update_ipv4_gre_tcp4_header(struct rte_mbuf *pkt,
+		uint8_t ipid_delta,
+		struct rte_mbuf **segs,
+		uint16_t nb_segs);
+
+/**
   * Internal function which divides the input packet into small segments.
   * Each of the newly-created segments is organized as a two-segment

MBUF,

Review

Quoted 2 lines
lib/librte_gso/gso_common.h +0 -0
   * where the first segment is a standard mbuf, which stores a copy of
(quoted diff) +0 -0

b/lib/librte_gso/gso_tunnel_tcp4.c

lib/librte_gso/gso_tunnel_tcp4.c gso_tunnel_tcp4_segment(struct rte_mbuf *pkt, · line 84

Quoted 7 lines

index cc017bd..5d5930a 100644

lib/librte_gso/gso_tunnel_tcp4.c +0 -0
@@ -82,6 +82,8 @@ gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
 
  	if (pkt->ol_flags & PKT_TX_TUNNEL_VXLAN)
  		update_ipv4_vxlan_tcp4_header(pkt, ipid_delta, pkts_out,

ret);

Quoted 31 lines
lib/librte_gso/gso_tunnel_tcp4.c +2 -0
+	else if (pkt->ol_flags & PKT_TX_TUNNEL_GRE)
+		update_ipv4_gre_tcp4_header(pkt, ipid_delta, pkts_out, ret);
 
  	return ret;
  }
lib/librte_gso/rte_gso.c +5 -3
index d1a723b..5464831 100644
@@ -60,8 +60,9 @@ rte_gso_segment(struct rte_mbuf *pkt,
 
  	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
  				(DEV_TX_OFFLOAD_TCP_TSO |
-				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
-				gso_ctx->gso_types) {
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+				 DEV_TX_OFFLOAD_GRE_TNL_TSO)) !=
+				 gso_ctx->gso_types) {
  		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
  		pkts_out[0] = pkt;
  		return ret;
@@ -73,7 +74,8 @@ rte_gso_segment(struct rte_mbuf *pkt,
  	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
  	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags) ||
+			IS_IPV4_GRE_TCP4(pkt->ol_flags)) {
  		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
  		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
  				direct_pool, indirect_pool,
author
#79 lore raw

PATCH v4 5/5 app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

In reply to Jiayu Hu

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

---
 app/test-pmd/cmdline.c                      | 178 ++++++++++++++++++++++++++++
 app/test-pmd/config.c                       |  24 ++++
 app/test-pmd/csumonly.c                     |  69 ++++++++++-
 app/test-pmd/testpmd.c                      |  13 ++
 app/test-pmd/testpmd.h                      |  10 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  41 +++++++
 6 files changed, 330 insertions(+), 5 deletions(-)
app/test-pmd/cmdline.c +178 -0
index ccdf239..2f308ed 100644
@@ -431,6 +431,17 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"    Set max flow number and max packet number per-flow"
 			" for GRO.\n\n"
 
+			"set port (port_id) gso (on|off)"
+			"    Enable or disable Generic Segmentation Offload in"
+			" csum forwarding engine.\n\n"
+
+			"set gso segsz (length)\n"
+			"    Set max packet length for output GSO segments,"
+			" including packet header and payload.\n\n"
+
+			"show port (port_id) gso\n"
+			"    Show GSO configuration.\n\n"
+
 			"set fwd (%s)\n"
 			"    Set packet forwarding mode.\n\n"
 
@@ -3967,6 +3978,170 @@ cmdline_parse_inst_t cmd_gro_set = {
 	},
 };
 
+/* *** ENABLE/DISABLE GSO *** */
+struct cmd_gso_enable_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_mode;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_enable_parsed(void *parsed_result,
+		__attribute__((unused)) struct cmdline *cl,
+		__attribute__((unused)) void *data)
+{
+	struct cmd_gso_enable_result *res;
+
+	res = parsed_result;
+	if (!strcmp(res->cmd_keyword, "gso"))
+		setup_gso(res->cmd_mode, res->cmd_pid);
+}
+
+cmdline_parse_token_string_t cmd_gso_enable_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_enable_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_enable_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_enable_mode =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_mode, "on#off");
+cmdline_parse_token_num_t cmd_gso_enable_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_enable = {
+	.f = cmd_gso_enable_parsed,
+	.data = NULL,
+	.help_str = "set port <port_id> gso on|off",
+	.tokens = {
+		(void *)&cmd_gso_enable_set,
+		(void *)&cmd_gso_enable_port,
+		(void *)&cmd_gso_enable_pid,
+		(void *)&cmd_gso_enable_keyword,
+		(void *)&cmd_gso_enable_mode,
+		NULL,
+	},
+};
+
+/* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
+struct cmd_gso_size_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_segsz;
+	uint16_t cmd_size;
+};
+
+static void
+cmd_gso_size_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_size_result *res = parsed_result;
+
+	if (test_done == 0) {
+		printf("Before set GSO segsz, please stop fowarding first\n");
+		return;
+	}
+
+	if (!strcmp(res->cmd_keyword, "gso") &&
+			!strcmp(res->cmd_segsz, "segsz")) {
+		if (res->cmd_size == 0) {
+			printf("gso_size should be larger than 0."
+					" Please input a legal value\n");
+		} else
+			gso_max_segment_size = res->cmd_size;
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_size_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_size_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_size_segsz =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_segsz, "segsz");
+cmdline_parse_token_num_t cmd_gso_size_size =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
+				cmd_size, UINT16);
+
+cmdline_parse_inst_t cmd_gso_size = {
+	.f = cmd_gso_size_parsed,
+	.data = NULL,
+	.help_str = "set gso segsz <length>",
+	.tokens = {
+		(void *)&cmd_gso_size_set,
+		(void *)&cmd_gso_size_keyword,
+		(void *)&cmd_gso_size_segsz,
+		(void *)&cmd_gso_size_size,
+		NULL,
+	},
+};
+
+/* *** SHOW GSO CONFIGURATION *** */
+struct cmd_gso_show_result {
+	cmdline_fixed_string_t cmd_show;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_show_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_show_result *res = parsed_result;
+
+	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
+		printf("invalid port id %u\n", res->cmd_pid);
+		return;
+	}
+
+	if (!strcmp(res->cmd_keyword, "gso")) {
+		if (gso_ports[res->cmd_pid].enable) {
+			printf("Max GSO segment size: %uB\n"
+					"Support GSO protocols: TCP/IPv4,"
+					" VxlAN and GRE\n",
+					gso_max_segment_size);
+		} else
+			printf("Port %u doesn't enable GSO\n", res->cmd_pid);
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_show_show =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_show, "show");
+cmdline_parse_token_string_t cmd_gso_show_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_show_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_num_t cmd_gso_show_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
+				cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_show = {
+	.f = cmd_gso_show_parsed,
+	.data = NULL,
+	.help_str = "show port <port_id> gso",
+	.tokens = {
+		(void *)&cmd_gso_show_show,
+		(void *)&cmd_gso_show_port,
+		(void *)&cmd_gso_show_pid,
+		(void *)&cmd_gso_show_keyword,
+		NULL,
+	},
+};
+
 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
 struct cmd_set_flush_rx {
 	cmdline_fixed_string_t set;
@@ -14255,6 +14430,9 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
 	(cmdline_parse_inst_t *)&cmd_enable_gro,
 	(cmdline_parse_inst_t *)&cmd_gro_set,
+	(cmdline_parse_inst_t *)&cmd_gso_enable,
+	(cmdline_parse_inst_t *)&cmd_gso_size,
+	(cmdline_parse_inst_t *)&cmd_gso_show,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
app/test-pmd/config.c +24 -0
index 3ae3e1c..3434346 100644
@@ -2454,6 +2454,30 @@ setup_gro(const char *mode, uint8_t port_id)
 	}
 }
 
+void
+setup_gso(const char *mode, uint8_t port_id)
+{
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		printf("invalid port id %u\n", port_id);
+		return;
+	}
+	if (strcmp(mode, "on") == 0) {
+		if (test_done == 0) {
+			printf("before enable GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 1;
+	} else if (strcmp(mode, "off") == 0) {
+		if (test_done == 0) {
+			printf("before disable GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 0;
+	}
+}
+
 char*
 list_pkt_forwarding_modes(void)
 {
app/test-pmd/csumonly.c +64 -5

140 lines not on this page · raw message

app/test-pmd/testpmd.c +13 -0
index e097ee0..97e349d 100644
@@ -400,6 +400,9 @@ static int eth_event_callback(uint8_t port_id,
  */
 static int all_ports_started(void);
 
+struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
+
 /*
  * Helper function to check if socket is already discovered.
  * If yes, return positive value. If not, return zero.
@@ -570,6 +573,7 @@ init_config(void)
 	unsigned int nb_mbuf_per_pool;
 	lcoreid_t  lc_id;
 	uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
+	uint32_t gso_types = 0;
 
 	memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
 
@@ -654,6 +658,8 @@ init_config(void)
 
 	init_port_config();
 
+	gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+		DEV_TX_OFFLOAD_GRE_TNL_TSO;
 	/*
 	 * Records which Mbuf pool to use by each logical core, if needed.
 	 */
@@ -664,6 +670,13 @@ init_config(void)
 		if (mbp == NULL)
 			mbp = mbuf_pool_find(0);
 		fwd_lcores[lc_id]->mbp = mbp;
+		/* initialize GSO context */
+		fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
+		fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
+			ETHER_CRC_LEN;
+		fwd_lcores[lc_id]->gso_ctx.ipid_flag = !RTE_GSO_IPID_FIXED;
 	}
 
 	/* Configuration of packet forwarding streams. */
app/test-pmd/testpmd.h +10 -0
index 1d1ee75..ff842a1 100644
@@ -36,6 +36,7 @@
 
 #include <rte_pci.h>
 #include <rte_gro.h>
+#include <rte_gso.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -205,6 +206,7 @@ struct rte_port {
  * CPU id. configuration table.
  */
 struct fwd_lcore {
+	struct rte_gso_ctx gso_ctx;     /**< GSO context */
 	struct rte_mempool *mbp; /**< The mbuf pool to use by this core */
 	streamid_t stream_idx;   /**< index of 1st stream in "fwd_streams" */
 	streamid_t stream_nb;    /**< number of streams in "fwd_streams" */
@@ -442,6 +444,13 @@ struct gro_status {
 };
 extern struct gro_status gro_ports[RTE_MAX_ETHPORTS];
 
+#define GSO_MAX_PKT_BURST 2048
+struct gso_status {
+	uint8_t enable;
+};
+extern struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+extern uint16_t gso_max_segment_size;
+
 static inline unsigned int
 lcore_num(void)
 {
@@ -642,6 +651,7 @@ void get_5tuple_filter(uint8_t port_id, uint16_t index);
 int rx_queue_id_is_invalid(queueid_t rxq_id);
 int tx_queue_id_is_invalid(queueid_t txq_id);
 void setup_gro(const char *mode, uint8_t port_id);
+void setup_gso(const char *mode, uint8_t port_id);
 
 /* Functions to manage the set of filtered Multicast MAC addresses */
 void mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr);
doc/guides/testpmd_app_ug/testpmd_funcs.rst +41 -0

47 lines not on this page · raw message

Signature · 1 line
2.7.4
#80 lore raw

v5 cover Support TCP/IPv4, VxLAN and GRE GSO in DPDK

In reply to Jiayu Hu

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunnelled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse-tunnel on "P0"
- csum parse-tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and disabled kernel GRO. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

Change log
==========
v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.
- change the defination of gso_types in struct rte_gso_ctx.
- replace rte_pktmbuf_detach() with rte_pktmbuf_free().
- refactor gso_update_pkt_headers().
- change the return value of rte_gso_segment().
- remove parameter checks in rte_gso_segment().
- use rte_net_get_ptype() in app/test-pmd/csumonly.c to fill mbuf->packet_type.
- add a new GSO command in testpmd to show GSO configuration for ports.
- misc: fix typo and optimize function description.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

 MAINTAINERS                                        |   6 +
 app/test-pmd/cmdline.c                             | 178 ++++++++
 app/test-pmd/config.c                              |  24 ++
 app/test-pmd/csumonly.c                            |  69 ++-
 app/test-pmd/testpmd.c                             |  13 +
 app/test-pmd/testpmd.h                             |  10 +
 config/common_base                                 |   5 +
 doc/api/doxy-api-index.md                          |   1 +
 doc/api/doxy-api.conf                              |   1 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 doc/guides/rel_notes/release_17_11.rst             |  19 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst        |  46 ++
 lib/Makefile                                       |   2 +
 lib/librte_eal/common/include/rte_log.h            |   1 +
 lib/librte_gso/Makefile                            |  52 +++
 lib/librte_gso/gso_common.c                        | 153 +++++++
 lib/librte_gso/gso_common.h                        | 171 ++++++++
 lib/librte_gso/gso_tcp4.c                          | 106 +++++
 lib/librte_gso/gso_tcp4.h                          |  74 ++++
 lib/librte_gso/gso_tunnel_tcp4.c                   | 129 ++++++
 lib/librte_gso/gso_tunnel_tcp4.h                   |  75 ++++
 lib/librte_gso/rte_gso.c                           | 107 +++++
 lib/librte_gso/rte_gso.h                           | 145 +++++++
 lib/librte_gso/rte_gso_version.map                 |   7 +
 mk/rte.app.mk                                      |   1 +
 28 files changed, 2437 insertions(+), 5 deletions(-)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
Signature · 1 line
1.9.3
#81 lore raw

v6 cover Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception that the tunnel type created for both the guest's virtio-net, and the host's kernel interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received on P1, is less than 500B.

Change log
==========
v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.
- change the defination of gso_types in struct rte_gso_ctx.
- replace rte_pktmbuf_detach() with rte_pktmbuf_free().
- refactor gso_update_pkt_headers().
- change the return value of rte_gso_segment().
- remove parameter checks in rte_gso_segment().
- use rte_net_get_ptype() in app/test-pmd/csumonly.c to fill mbuf->packet_type.
- add a new GSO command in testpmd to show GSO configuration for ports.
- misc: fix typo and optimize function description.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

 MAINTAINERS                                        |   6 +
 app/test-pmd/cmdline.c                             | 178 ++++++++
 app/test-pmd/config.c                              |  24 ++
 app/test-pmd/csumonly.c                            |  69 ++-
 app/test-pmd/testpmd.c                             |  13 +
 app/test-pmd/testpmd.h                             |  10 +
 config/common_base                                 |   5 +
 doc/api/doxy-api-index.md                          |   1 +
 doc/api/doxy-api.conf                              |   1 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 doc/guides/rel_notes/release_17_11.rst             |  19 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst        |  46 ++
 lib/Makefile                                       |   2 +
 lib/librte_eal/common/include/rte_log.h            |   1 +
 lib/librte_gso/Makefile                            |  52 +++
 lib/librte_gso/gso_common.c                        | 153 +++++++
 lib/librte_gso/gso_common.h                        | 171 ++++++++
 lib/librte_gso/gso_tcp4.c                          | 104 +++++
 lib/librte_gso/gso_tcp4.h                          |  74 ++++
 lib/librte_gso/gso_tunnel_tcp4.c                   | 129 ++++++
 lib/librte_gso/gso_tunnel_tcp4.h                   |  75 ++++
 lib/librte_gso/rte_gso.c                           | 107 +++++
 lib/librte_gso/rte_gso.h                           | 145 +++++++
 lib/librte_gso/rte_gso_version.map                 |   7 +
 mk/rte.app.mk                                      |   1 +
 28 files changed, 2435 insertions(+), 5 deletions(-)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
Signature · 1 line
1.9.3
#82 lore raw

PATCH v6 1/6 gso: add Generic Segmentation Offload API framework

From: Jiayu Hu <[email protected]>

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. To segment a packet requires two steps. The first is to set proper flags to mbuf->ol_flags, where the flags are the same as that of TSO. The second is to call the segmentation API, rte_gso_segment(). This patch introduces the GSO API framework to DPDK.

rte_gso_segment() splits an input packet into small ones in each invocation. The GSO library refers to these small packets generated by rte_gso_segment() as GSO segments. Each of the newly-created GSO segments is organized as a two-segment MBUF, where the first segment is a standard MBUF, which stores a copy of packet header, and the second is an indirect MBUF which points to a section of data in the input packet. rte_gso_segment() reduces the refcnt of the input packet by 1. Therefore, when all GSO segments are freed, the input packet is freed automatically. Additionally, since each GSO segment has multiple MBUFs (i.e. 2 MBUFs), the driver of the interface which the GSO segments are sent to should support to transmit multi-segment packets.

The GSO framework clears the PKT_TX_TCP_SEG flag for both the input packet, and all produced GSO segments in the event of success, since segmentation in hardware is no longer required at that point.

---
 config/common_base                     |   5 ++
 doc/api/doxy-api-index.md              |   1 +
 doc/api/doxy-api.conf                  |   1 +
 doc/guides/rel_notes/release_17_11.rst |   1 +
 lib/Makefile                           |   2 +
 lib/librte_gso/Makefile                |  49 +++++++++++
 lib/librte_gso/rte_gso.c               |  52 ++++++++++++
 lib/librte_gso/rte_gso.h               | 145 +++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map     |   7 ++
 mk/rte.app.mk                          |   1 +
 10 files changed, 264 insertions(+)
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
config/common_base +5 -0
index 12f6be9..58ca5c0 100644
@@ -653,6 +653,11 @@ CONFIG_RTE_LIBRTE_IP_FRAG_TBL_STAT=n
 CONFIG_RTE_LIBRTE_GRO=y
 
 #
+# Compile GSO library
+#
+CONFIG_RTE_LIBRTE_GSO=y
+
+#
 # Compile librte_meter
 #
 CONFIG_RTE_LIBRTE_METER=y
doc/api/doxy-api-index.md +1 -0
index 19e0d4f..6512918 100644
@@ -101,6 +101,7 @@ The public API headers are grouped by topics:
   [TCP]                (@ref rte_tcp.h),
   [UDP]                (@ref rte_udp.h),
   [GRO]                (@ref rte_gro.h),
+  [GSO]                (@ref rte_gso.h),
   [frag/reass]         (@ref rte_ip_frag.h),
   [LPM IPv4 route]     (@ref rte_lpm.h),
   [LPM IPv6 route]     (@ref rte_lpm6.h),
doc/api/doxy-api.conf +1 -0
index 823554f..408f2e6 100644
@@ -47,6 +47,7 @@ INPUT                   = doc/api/doxy-api-index.md \
                           lib/librte_ether \
                           lib/librte_eventdev \
                           lib/librte_gro \
+                          lib/librte_gso \
                           lib/librte_hash \
                           lib/librte_ip_frag \
                           lib/librte_jobstats \
doc/guides/rel_notes/release_17_11.rst +1 -0
index 8bf91bd..7508be7 100644
@@ -174,6 +174,7 @@ The libraries prepended with a plus sign were incremented in this version.
      librte_ethdev.so.7
      librte_eventdev.so.2
      librte_gro.so.1
+   + librte_gso.so.1
      librte_hash.so.2
      librte_ip_frag.so.1
      librte_jobstats.so.1
lib/Makefile +2 -0
index 86caba1..3d123f4 100644
@@ -108,6 +108,8 @@ DIRS-$(CONFIG_RTE_LIBRTE_REORDER) += librte_reorder
 DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
+DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
lib/librte_gso/Makefile new file +49 -0

49 lines not on this page · raw message

lib/librte_gso/rte_gso.c new file +52 -0

52 lines not on this page · raw message

lib/librte_gso/rte_gso.h new file +145 -0

145 lines not on this page · raw message

lib/librte_gso/rte_gso_version.map new file +7 -0
new file mode 100644
index 0000000..e1fd453
@@ -0,0 +1,7 @@
+DPDK_17.11 {
+	global:
+
+	rte_gso_segment;
+
+	local: *;
+};
mk/rte.app.mk +1 -0
index c25fdd9..d4c9873 100644
@@ -66,6 +66,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PDUMP)          += -lrte_pdump
 _LDLIBS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR)    += -lrte_distributor
 _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG)        += -lrte_ip_frag
 _LDLIBS-$(CONFIG_RTE_LIBRTE_GRO)            += -lrte_gro
+_LDLIBS-$(CONFIG_RTE_LIBRTE_GSO)            += -lrte_gso
 _LDLIBS-$(CONFIG_RTE_LIBRTE_METER)          += -lrte_meter
 _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lrte_sched
 _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM)            += -lrte_lpm
Signature · 1 line
1.9.3
#83 lore raw

Re: [PATCH v6 1/6] gso: add Generic Segmentation Offload API framework

Quoted 306 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Ananyev, Konstantin <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B <[email protected]>
Subject: [PATCH v6 1/6] gso: add Generic Segmentation Offload API framework

From: Jiayu Hu <[email protected]>

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. To segment a packet requires two steps. The first is to set proper flags to mbuf->ol_flags, where the flags are the same as that of TSO. The second is to call the segmentation API, rte_gso_segment(). This patch introduces the GSO API framework to DPDK.

rte_gso_segment() splits an input packet into small ones in each invocation. The GSO library refers to these small packets generated by rte_gso_segment() as GSO segments. Each of the newly-created GSO segments is organized as a two-segment MBUF, where the first segment is a standard MBUF, which stores a copy of packet header, and the second is an indirect MBUF which points to a section of data in the input packet. rte_gso_segment() reduces the refcnt of the input packet by 1. Therefore, when all GSO segments are freed, the input packet is freed automatically. Additionally, since each GSO segment has multiple MBUFs (i.e. 2 MBUFs), the driver of the interface which the GSO segments are sent to should support to transmit multi-segment packets.

The GSO framework clears the PKT_TX_TCP_SEG flag for both the input packet, and all produced GSO segments in the event of success, since segmentation in hardware is no longer required at that point.

---
 config/common_base                     |   5 ++
 doc/api/doxy-api-index.md              |   1 +
 doc/api/doxy-api.conf                  |   1 +
 doc/guides/rel_notes/release_17_11.rst |   1 +
 lib/Makefile                           |   2 +
 lib/librte_gso/Makefile                |  49 +++++++++++
 lib/librte_gso/rte_gso.c               |  52 ++++++++++++
 lib/librte_gso/rte_gso.h               | 145 +++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map     |   7 ++
 mk/rte.app.mk                          |   1 +
 10 files changed, 264 insertions(+)
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
config/common_base +5 -0
index 12f6be9..58ca5c0 100644
@@ -653,6 +653,11 @@ CONFIG_RTE_LIBRTE_IP_FRAG_TBL_STAT=n
 CONFIG_RTE_LIBRTE_GRO=y
 
 #
+# Compile GSO library
+#
+CONFIG_RTE_LIBRTE_GSO=y
+
+#
 # Compile librte_meter
 #
 CONFIG_RTE_LIBRTE_METER=y
doc/api/doxy-api-index.md +1 -0
index 19e0d4f..6512918 100644
@@ -101,6 +101,7 @@ The public API headers are grouped by topics:
   [TCP]                (@ref rte_tcp.h),
   [UDP]                (@ref rte_udp.h),
   [GRO]                (@ref rte_gro.h),
+  [GSO]                (@ref rte_gso.h),
   [frag/reass]         (@ref rte_ip_frag.h),
   [LPM IPv4 route]     (@ref rte_lpm.h),
   [LPM IPv6 route]     (@ref rte_lpm6.h),
doc/api/doxy-api.conf +1 -0
index 823554f..408f2e6 100644
@@ -47,6 +47,7 @@ INPUT                   = doc/api/doxy-api-index.md \
                           lib/librte_ether \
                           lib/librte_eventdev \
                           lib/librte_gro \
+                          lib/librte_gso \
                           lib/librte_hash \
                           lib/librte_ip_frag \
                           lib/librte_jobstats \
doc/guides/rel_notes/release_17_11.rst +1 -0
index 8bf91bd..7508be7 100644
@@ -174,6 +174,7 @@ The libraries prepended with a plus sign were incremented in this version.
      librte_ethdev.so.7
      librte_eventdev.so.2
      librte_gro.so.1
+   + librte_gso.so.1
      librte_hash.so.2
      librte_ip_frag.so.1
      librte_jobstats.so.1
lib/Makefile +2 -0
index 86caba1..3d123f4 100644
@@ -108,6 +108,8 @@ DIRS-$(CONFIG_RTE_LIBRTE_REORDER) += librte_reorder
 DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
+DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
lib/librte_gso/Makefile new file +49 -0
new file mode 100644
index 0000000..aeaacbc
@@ -0,0 +1,49 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2017 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#     * Neither the name of Intel Corporation nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# library name
+LIB = librte_gso.a
+
+CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
+
+EXPORT_MAP := rte_gso_version.map
+
+LIBABIVER := 1
+
+#source files
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+
+# install this header file
+SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
+
+include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_gso/rte_gso.c new file +52 -0
new file mode 100644
index 0000000..b773636
@@ -0,0 +1,52 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <errno.h>
+
+#include "rte_gso.h"
+
+int
+rte_gso_segment(struct rte_mbuf *pkt,
+		const struct rte_gso_ctx *gso_ctx,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
+			nb_pkts_out < 1)
+		return -EINVAL;
+
+	pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+	pkts_out[0] = pkt;
+
+	return 1;
+}
lib/librte_gso/rte_gso.h new file +64 -0
new file mode 100644
index 0000000..53725e6
@@ -0,0 +1,145 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_GSO_H_
+#define _RTE_GSO_H_
+
+/**
+ * @file
+ * Interface to GSO library
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/* GSO IP id flags for the IPv4 header */
+#define RTE_GSO_IPID_FIXED (1ULL << 0)
+/**< Use fixed IP ids for output GSO segments. Setting
+ * !RTE_GSO_IPID_FIXED indicates using incremental IP ids.
+ */
+
+/**
+ * GSO context structure.
+ */
+struct rte_gso_ctx {
+	struct rte_mempool *direct_pool;
+	/**< MBUF pool for allocating direct buffers, which are used
+	 * to store packet headers for GSO segments.
+	 */
+	struct rte_mempool *indirect_pool;
+	/**< MBUF pool for allocating indirect buffers, which are used

lib/librte_gso/rte_gso.h line 74

Quoted 10 lines
lib/librte_gso/rte_gso.h new file +10 -0
+	 * to locate packet payloads for GSO segments. The indirect
+	 * buffer doesn't contain any data, but simply points to an
+	 * offset within the packet to segment.
+	 */
+	uint64_t ipid_flag;
+	/**< flag to indicate GSO uses fixed or incremental IP ids for
+	 * IPv4 headers of output GSO segments. If applications want
+	 * fixed IP ids, set RTE_GSO_IPID_FIXED to ipid_flag. Conversely,
+	 * if applications want incremental IP ids, set !RTE_GSO_IPID_FIXED.
+	 */

Minor nit - I think better to just name it 'flag' - as in future some other non IPID related flags might be added.
Also make sure that all flag values have RTE_GSO_FLAG (or so prefixes), and move explanation of particular flag value to its definition. Konstantin

Quoted 98 lines
lib/librte_gso/rte_gso.h new file +71 -0
+	uint32_t gso_types;
+	/**< the bit mask of required GSO types. The GSO library
+	 * uses the same macros as that of describing device TX
+	 * offloading capabilities (i.e. DEV_TX_OFFLOAD_*_TSO) for
+	 * gso_types.
+	 *
+	 * For example, if applications want to segment TCP/IPv4
+	 * packets, set DEV_TX_OFFLOAD_TCP_TSO in gso_types.
+	 */
+	uint16_t gso_size;
+	/**< maximum size of an output GSO segment, including packet
+	 * header and payload, measured in bytes.
+	 */
+};
+
+/**
+ * Segmentation function, which supports processing of both single- and
+ * multi- MBUF packets.
+ *
+ * Note that we refer to the packets that are segmented from the input
+ * packet as 'GSO segments'. rte_gso_segment() doesn't check if the
+ * input packet has correct checksums, and doesn't update checksums for
+ * output GSO segments. Additionally, it doesn't process IP fragment
+ * packets.
+ *
+ * Before calling rte_gso_segment(), applications must set proper ol_flags
+ * for the packet. The GSO library uses the same macros as that of TSO.
+ * For example, set PKT_TX_TCP_SEG and PKT_TX_IPV4 in ol_flags to segment
+ * a TCP/IPv4 packet. If rte_gso_segment() succceds, the PKT_TX_TCP_SEG
+ * flag is removed for all GSO segments and the input packet.
+ *
+ * Each of the newly-created GSO segments is organized as a two-segment
+ * MBUF, where the first segment is a standard MBUF, which stores a copy
+ * of packet header, and the second is an indirect MBUF which points to
+ * a section of data in the input packet. Since each GSO segment has
+ * multiple MBUFs (i.e. typically 2 MBUFs), the driver of the interface which
+ * the GSO segments are sent to should support transmission of multi-segment
+ * packets.
+ *
+ * If the input packet is GSO'd, its mbuf refcnt reduces by 1. Therefore,
+ * when all GSO segments are freed, the input packet is freed automatically.
+ *
+ * If the memory space in pkts_out or MBUF pools is insufficient, this
+ * function fails, and it returns (-1) * errno. Otherwise, GSO succeeds,
+ * and this function returns the number of output GSO segments filled in
+ * pkts_out.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param ctx
+ *  GSO context object pointer.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when rte_gso_segment() succeeds.
+ * @param nb_pkts_out
+ *  The max number of items that pkts_out can keep.
+ *
+ * @return
+ *  - The number of GSO segments filled in pkts_out on success.
+ *  - Return -ENOMEM if run out of memory in MBUF pools.
+ *  - Return -EINVAL for invalid parameters.
+ */
+int rte_gso_segment(struct rte_mbuf *pkt,
+		const struct rte_gso_ctx *ctx,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_GSO_H_ */
lib/librte_gso/rte_gso_version.map new file +7 -0
new file mode 100644
index 0000000..e1fd453
@@ -0,0 +1,7 @@
+DPDK_17.11 {
+	global:
+
+	rte_gso_segment;
+
+	local: *;
+};
mk/rte.app.mk +1 -1
index c25fdd9..d4c9873 100644
@@ -66,6 +66,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PDUMP)          += -lrte_pdump
 _LDLIBS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR)    += -lrte_distributor
 _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG)        += -lrte_ip_frag
 _LDLIBS-$(CONFIG_RTE_LIBRTE_GRO)            += -lrte_gro
+_LDLIBS-$(CONFIG_RTE_LIBRTE_GSO)            += -lrte_gso
 _LDLIBS-$(CONFIG_RTE_LIBRTE_METER)          += -lrte_meter
 _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lrte_sched
 _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM)            += -lrte_lpm
--

1.9.3

#84 lore raw

Re: [PATCH v6 1/6] gso: add Generic Segmentation Offload API framework

Quoted 329 lines

From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 2:11 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 1/6] gso: add Generic Segmentation Offload API framework

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>;

Ananyev, Konstantin <[email protected]>; Yigit,

Quoted 1 line

Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B

<[email protected]>

Quoted 33 lines

Subject: [PATCH v6 1/6] gso: add Generic Segmentation Offload API framework

From: Jiayu Hu <[email protected]>

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. To segment a packet requires two steps. The first is to set proper flags to mbuf->ol_flags, where the flags are the same as that of TSO. The second is to call the segmentation API, rte_gso_segment(). This patch introduces the GSO API framework to DPDK.

rte_gso_segment() splits an input packet into small ones in each invocation. The GSO library refers to these small packets generated by rte_gso_segment() as GSO segments. Each of the newly-created GSO segments is organized as a two-segment MBUF, where the first segment is a standard MBUF, which stores a copy of packet header, and the second is an indirect MBUF which points to a section of data in the input packet. rte_gso_segment() reduces the refcnt of the input packet by 1. Therefore, when all GSO segments are freed, the input packet is freed automatically. Additionally, since each GSO segment has multiple MBUFs (i.e. 2 MBUFs), the driver of the interface which the GSO segments are sent to should support to transmit multi-segment packets.

The GSO framework clears the PKT_TX_TCP_SEG flag for both the input packet, and all produced GSO segments in the event of success, since segmentation in hardware is no longer required at that point.

Quoted 9 lines
---
 config/common_base                     |   5 ++
 doc/api/doxy-api-index.md              |   1 +
 doc/api/doxy-api.conf                  |   1 +
 doc/guides/rel_notes/release_17_11.rst |   1 +
 lib/Makefile                           |   2 +
 lib/librte_gso/Makefile                |  49 +++++++++++
 lib/librte_gso/rte_gso.c               |  52 ++++++++++++
 lib/librte_gso/rte_gso.h               | 145

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

Review

Quoted 49 lines
 lib/librte_gso/rte_gso_version.map     |   7 ++
 mk/rte.app.mk                          |   1 +
 10 files changed, 264 insertions(+)
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
config/common_base +5 -0
index 12f6be9..58ca5c0 100644
@@ -653,6 +653,11 @@ CONFIG_RTE_LIBRTE_IP_FRAG_TBL_STAT=n
 CONFIG_RTE_LIBRTE_GRO=y
 
 #
+# Compile GSO library
+#
+CONFIG_RTE_LIBRTE_GSO=y
+
+#
 # Compile librte_meter
 #
 CONFIG_RTE_LIBRTE_METER=y
doc/api/doxy-api-index.md +1 -0
index 19e0d4f..6512918 100644
@@ -101,6 +101,7 @@ The public API headers are grouped by topics:
   [TCP]                (@ref rte_tcp.h),
   [UDP]                (@ref rte_udp.h),
   [GRO]                (@ref rte_gro.h),
+  [GSO]                (@ref rte_gso.h),
   [frag/reass]         (@ref rte_ip_frag.h),
   [LPM IPv4 route]     (@ref rte_lpm.h),
   [LPM IPv6 route]     (@ref rte_lpm6.h),
doc/api/doxy-api.conf +1 -0
index 823554f..408f2e6 100644
@@ -47,6 +47,7 @@ INPUT                   = doc/api/doxy-api-index.md \
                           lib/librte_ether \
                           lib/librte_eventdev \
                           lib/librte_gro \
+                          lib/librte_gso \
                           lib/librte_hash \
                           lib/librte_ip_frag \
                           lib/librte_jobstats \
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_17_11.rst

doc/guides/rel_notes/release_17_11.rst The libraries prepended with a plus sign were

Quoted 4 lines

index 8bf91bd..7508be7 100644

doc/guides/rel_notes/release_17_11.rst +0 -0
@@ -174,6 +174,7 @@ The libraries prepended with a plus sign were

incremented in this version.

Quoted 211 lines
doc/guides/rel_notes/release_17_11.rst +1 -0
      librte_ethdev.so.7
      librte_eventdev.so.2
      librte_gro.so.1
+   + librte_gso.so.1
      librte_hash.so.2
      librte_ip_frag.so.1
      librte_jobstats.so.1
lib/Makefile +2 -0
index 86caba1..3d123f4 100644
@@ -108,6 +108,8 @@ DIRS-$(CONFIG_RTE_LIBRTE_REORDER) += librte_reorder
 DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
+DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
lib/librte_gso/Makefile new file +49 -0
new file mode 100644
index 0000000..aeaacbc
@@ -0,0 +1,49 @@
+#   BSD LICENSE
+#
+#   Copyright(c) 2017 Intel Corporation. All rights reserved.
+#   All rights reserved.
+#
+#   Redistribution and use in source and binary forms, with or without
+#   modification, are permitted provided that the following conditions
+#   are met:
+#
+#     * Redistributions of source code must retain the above copyright
+#       notice, this list of conditions and the following disclaimer.
+#     * Redistributions in binary form must reproduce the above copyright
+#       notice, this list of conditions and the following disclaimer in
+#       the documentation and/or other materials provided with the
+#       distribution.
+#     * Neither the name of Intel Corporation nor the names of its
+#       contributors may be used to endorse or promote products derived
+#       from this software without specific prior written permission.
+#
+#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+#   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+#   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+#   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+#   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+#   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+#   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+#   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+#   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+#   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+#   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+include $(RTE_SDK)/mk/rte.vars.mk
+
+# library name
+LIB = librte_gso.a
+
+CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
+
+EXPORT_MAP := rte_gso_version.map
+
+LIBABIVER := 1
+
+#source files
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+
+# install this header file
+SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
+
+include $(RTE_SDK)/mk/rte.lib.mk
lib/librte_gso/rte_gso.c new file +52 -0
new file mode 100644
index 0000000..b773636
@@ -0,0 +1,52 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <errno.h>
+
+#include "rte_gso.h"
+
+int
+rte_gso_segment(struct rte_mbuf *pkt,
+		const struct rte_gso_ctx *gso_ctx,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
+			nb_pkts_out < 1)
+		return -EINVAL;
+
+	pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+	pkts_out[0] = pkt;
+
+	return 1;
+}
lib/librte_gso/rte_gso.h new file +72 -0
new file mode 100644
index 0000000..53725e6
@@ -0,0 +1,145 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _RTE_GSO_H_
+#define _RTE_GSO_H_
+
+/**
+ * @file
+ * Interface to GSO library
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/* GSO IP id flags for the IPv4 header */
+#define RTE_GSO_IPID_FIXED (1ULL << 0)
+/**< Use fixed IP ids for output GSO segments. Setting
+ * !RTE_GSO_IPID_FIXED indicates using incremental IP ids.
+ */
+
+/**
+ * GSO context structure.
+ */
+struct rte_gso_ctx {
+	struct rte_mempool *direct_pool;
+	/**< MBUF pool for allocating direct buffers, which are used
+	 * to store packet headers for GSO segments.
+	 */
+	struct rte_mempool *indirect_pool;
+	/**< MBUF pool for allocating indirect buffers, which are used
+	 * to locate packet payloads for GSO segments. The indirect
+	 * buffer doesn't contain any data, but simply points to an
+	 * offset within the packet to segment.
+	 */
+	uint64_t ipid_flag;
+	/**< flag to indicate GSO uses fixed or incremental IP ids for
+	 * IPv4 headers of output GSO segments. If applications want
+	 * fixed IP ids, set RTE_GSO_IPID_FIXED to ipid_flag. Conversely,
Quoted 8 lines

lib/librte_gso/rte_gso.h line 74

Quoted 2 lines
lib/librte_gso/rte_gso.h new file +2 -0
+	 * if applications want incremental IP ids, set !RTE_GSO_IPID_FIXED.
+	 */

Minor nit - I think better to just name it 'flag' - as in future some other non IPID related flags might be added.
Also make sure that all flag values have RTE_GSO_FLAG (or so prefixes), and move explanation of particular flag value to its definition. Konstantin

Will do Konstantin - thanks!

Quoted 103 lines
Quoted 27 lines
lib/librte_gso/rte_gso.h new file +26 -0
+	uint32_t gso_types;
+	/**< the bit mask of required GSO types. The GSO library
+	 * uses the same macros as that of describing device TX
+	 * offloading capabilities (i.e. DEV_TX_OFFLOAD_*_TSO) for
+	 * gso_types.
+	 *
+	 * For example, if applications want to segment TCP/IPv4
+	 * packets, set DEV_TX_OFFLOAD_TCP_TSO in gso_types.
+	 */
+	uint16_t gso_size;
+	/**< maximum size of an output GSO segment, including packet
+	 * header and payload, measured in bytes.
+	 */
+};
+
+/**
+ * Segmentation function, which supports processing of both single- and
+ * multi- MBUF packets.
+ *
+ * Note that we refer to the packets that are segmented from the input
+ * packet as 'GSO segments'. rte_gso_segment() doesn't check if the
+ * input packet has correct checksums, and doesn't update checksums for
+ * output GSO segments. Additionally, it doesn't process IP fragment
+ * packets.
+ *
+ * Before calling rte_gso_segment(), applications must set proper ol_flags

lib/librte_gso/rte_gso.h

Quoted 10 lines
lib/librte_gso/rte_gso.h new file +10 -0
+ * for the packet. The GSO library uses the same macros as that of TSO.
+ * For example, set PKT_TX_TCP_SEG and PKT_TX_IPV4 in ol_flags to segment
+ * a TCP/IPv4 packet. If rte_gso_segment() succceds, the PKT_TX_TCP_SEG
+ * flag is removed for all GSO segments and the input packet.
+ *
+ * Each of the newly-created GSO segments is organized as a two-segment
+ * MBUF, where the first segment is a standard MBUF, which stores a copy
+ * of packet header, and the second is an indirect MBUF which points to
+ * a section of data in the input packet. Since each GSO segment has
+ * multiple MBUFs (i.e. typically 2 MBUFs), the driver of the interface

which

lib/librte_gso/rte_gso.h line 111

Quoted 1 line
lib/librte_gso/rte_gso.h new file +1 -0
+ * the GSO segments are sent to should support transmission of multi-

segment

lib/librte_gso/rte_gso.h

Quoted 4 lines
lib/librte_gso/rte_gso.h new file +4 -0
+ * packets.
+ *
+ * If the input packet is GSO'd, its mbuf refcnt reduces by 1. Therefore,
+ * when all GSO segments are freed, the input packet is freed

automatically.

Review

Quoted 31 lines
lib/librte_gso/rte_gso.h new file +30 -0
+ *
+ * If the memory space in pkts_out or MBUF pools is insufficient, this
+ * function fails, and it returns (-1) * errno. Otherwise, GSO succeeds,
+ * and this function returns the number of output GSO segments filled in
+ * pkts_out.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param ctx
+ *  GSO context object pointer.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when rte_gso_segment() succeeds.
+ * @param nb_pkts_out
+ *  The max number of items that pkts_out can keep.
+ *
+ * @return
+ *  - The number of GSO segments filled in pkts_out on success.
+ *  - Return -ENOMEM if run out of memory in MBUF pools.
+ *  - Return -EINVAL for invalid parameters.
+ */
+int rte_gso_segment(struct rte_mbuf *pkt,
+		const struct rte_gso_ctx *ctx,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_GSO_H_ */
(quoted diff) +0 -0

b/lib/librte_gso/rte_gso_version.map

Quoted 26 lines

new file mode 100644
index 0000000..e1fd453

lib/librte_gso/rte_gso_version.map new file +7 -0
@@ -0,0 +1,7 @@
+DPDK_17.11 {
+	global:
+
+	rte_gso_segment;
+
+	local: *;
+};
mk/rte.app.mk +1 -1
index c25fdd9..d4c9873 100644
@@ -66,6 +66,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PDUMP)          += -lrte_pdump
 _LDLIBS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR)    += -lrte_distributor
 _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG)        += -lrte_ip_frag
 _LDLIBS-$(CONFIG_RTE_LIBRTE_GRO)            += -lrte_gro
+_LDLIBS-$(CONFIG_RTE_LIBRTE_GSO)            += -lrte_gso
 _LDLIBS-$(CONFIG_RTE_LIBRTE_METER)          += -lrte_meter
 _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lrte_sched
 _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM)            += -lrte_lpm
--

1.9.3

#85 lore raw

PATCH v6 2/6 gso: add TCP/IPv4 GSO support

In reply to Mark Kavanagh

From: Jiayu Hu <[email protected]>

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst  |  12 +++
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 153 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               | 104 ++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
 lib/librte_gso/rte_gso.c                |  52 ++++++++++-
 8 files changed, 536 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
doc/guides/rel_notes/release_17_11.rst +12 -0
index 7508be7..c414f73 100644
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MTU is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets, which may include a single VLAN tag.
+
+  The GSO library doesn't check if the input packets have correct
+  checksums, and doesn't update checksums for output packets.
+  Additionally, the GSO library doesn't process IP fragmented packets.
+
 
 Resolved Issues
 ---------------
lib/librte_eal/common/include/rte_log.h +1 -0
index ec8dba7..2fa1199 100644
@@ -87,6 +87,7 @@ struct rte_logs {
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
lib/librte_gso/Makefile +2 -0
index aeaacbc..2be64d1 100644
@@ -42,6 +42,8 @@ LIBABIVER := 1
 
 #source files
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +153 -0

153 lines not on this page · raw message

lib/librte_gso/gso_common.h new file +141 -0

141 lines not on this page · raw message

lib/librte_gso/gso_tcp4.c new file +104 -0

104 lines not on this page · raw message

lib/librte_gso/gso_tcp4.h new file +74 -0

74 lines not on this page · raw message

lib/librte_gso/rte_gso.c +49 -3

68 lines not on this page · raw message

Signature · 1 line
1.9.3
#86 lore raw

Re: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

Hi Mark,

Quoted 634 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Ananyev, Konstantin <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B <[email protected]>
Subject: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

From: Jiayu Hu <[email protected]>

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst  |  12 +++
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 153 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               | 104 ++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
 lib/librte_gso/rte_gso.c                |  52 ++++++++++-
 8 files changed, 536 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
doc/guides/rel_notes/release_17_11.rst +12 -0
index 7508be7..c414f73 100644
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MTU is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets, which may include a single VLAN tag.
+
+  The GSO library doesn't check if the input packets have correct
+  checksums, and doesn't update checksums for output packets.
+  Additionally, the GSO library doesn't process IP fragmented packets.
+
 
 Resolved Issues
 ---------------
lib/librte_eal/common/include/rte_log.h +1 -0
index ec8dba7..2fa1199 100644
@@ -87,6 +87,7 @@ struct rte_logs {
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
lib/librte_gso/Makefile +2 -0
index aeaacbc..2be64d1 100644
@@ -42,6 +42,8 @@ LIBABIVER := 1
 
 #source files
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +153 -0
new file mode 100644
index 0000000..ee75d4c
@@ -0,0 +1,153 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdbool.h>
+#include <errno.h>
+
+#include <rte_memcpy.h>
+#include <rte_mempool.h>
+
+#include "gso_common.h"
+
+static inline void
+hdr_segment_init(struct rte_mbuf *hdr_segment, struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset)
+{
+	/* Copy MBUF metadata */
+	hdr_segment->nb_segs = 1;
+	hdr_segment->port = pkt->port;
+	hdr_segment->ol_flags = pkt->ol_flags;
+	hdr_segment->packet_type = pkt->packet_type;
+	hdr_segment->pkt_len = pkt_hdr_offset;
+	hdr_segment->data_len = pkt_hdr_offset;
+	hdr_segment->tx_offload = pkt->tx_offload;
+
+	/* Copy the packet header */
+	rte_memcpy(rte_pktmbuf_mtod(hdr_segment, char *),
+			rte_pktmbuf_mtod(pkt, char *),
+			pkt_hdr_offset);
+}
+
+static inline void
+free_gso_segment(struct rte_mbuf **pkts, uint16_t nb_pkts)
+{
+	uint16_t i;
+
+	for (i = 0; i < nb_pkts; i++)
+		rte_pktmbuf_free(pkts[i]);
+}
+
+int
+gso_do_segment(struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset,
+		uint16_t pyld_unit_size,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct rte_mbuf *pkt_in;
+	struct rte_mbuf *hdr_segment, *pyld_segment, *prev_segment;
+	uint16_t pkt_in_data_pos, segment_bytes_remaining;
+	uint16_t pyld_len, nb_segs;
+	bool more_in_pkt, more_out_segs;
+
+	pkt_in = pkt;
+	nb_segs = 0;
+	more_in_pkt = 1;
+	pkt_in_data_pos = pkt_hdr_offset;
+
+	while (more_in_pkt) {
+		if (unlikely(nb_segs >= nb_pkts_out)) {
+			free_gso_segment(pkts_out, nb_segs);
+			return -EINVAL;
+		}
+
+		/* Allocate a direct MBUF */
+		hdr_segment = rte_pktmbuf_alloc(direct_pool);
+		if (unlikely(hdr_segment == NULL)) {
+			free_gso_segment(pkts_out, nb_segs);
+			return -ENOMEM;
+		}
+		/* Fill the packet header */
+		hdr_segment_init(hdr_segment, pkt, pkt_hdr_offset);
+
+		prev_segment = hdr_segment;
+		segment_bytes_remaining = pyld_unit_size;
+		more_out_segs = 1;
+
+		while (more_out_segs && more_in_pkt) {
+			/* Allocate an indirect MBUF */
+			pyld_segment = rte_pktmbuf_alloc(indirect_pool);
+			if (unlikely(pyld_segment == NULL)) {
+				rte_pktmbuf_free(hdr_segment);
+				free_gso_segment(pkts_out, nb_segs);
+				return -ENOMEM;
+			}
+			/* Attach to current MBUF segment of pkt */
+			rte_pktmbuf_attach(pyld_segment, pkt_in);
+
+			prev_segment->next = pyld_segment;
+			prev_segment = pyld_segment;
+
+			pyld_len = segment_bytes_remaining;
+			if (pyld_len + pkt_in_data_pos > pkt_in->data_len)
+				pyld_len = pkt_in->data_len - pkt_in_data_pos;
+
+			pyld_segment->data_off = pkt_in_data_pos +
+				pkt_in->data_off;
+			pyld_segment->data_len = pyld_len;
+
+			/* Update header segment */
+			hdr_segment->pkt_len += pyld_len;
+			hdr_segment->nb_segs++;
+
+			pkt_in_data_pos += pyld_len;
+			segment_bytes_remaining -= pyld_len;
+
+			/* Finish processing a MBUF segment of pkt */
+			if (pkt_in_data_pos == pkt_in->data_len) {
+				pkt_in = pkt_in->next;
+				pkt_in_data_pos = 0;
+				if (pkt_in == NULL)
+					more_in_pkt = 0;
+			}
+
+			/* Finish generating a GSO segment */
+			if (segment_bytes_remaining == 0)
+				more_out_segs = 0;
+		}
+		pkts_out[nb_segs++] = hdr_segment;
+	}
+	return nb_segs;
+}
lib/librte_gso/gso_common.h new file +141 -0
new file mode 100644
index 0000000..8d9b94e
@@ -0,0 +1,141 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GSO_COMMON_H_
+#define _GSO_COMMON_H_
+
+#include <stdint.h>
+
+#include <rte_mbuf.h>
+#include <rte_ip.h>
+#include <rte_tcp.h>
+
+#define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
+		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)
+
+#define TCP_HDR_PSH_MASK ((uint8_t)0x08)
+#define TCP_HDR_FIN_MASK ((uint8_t)0x01)
+
+#define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
+
+/**
+ * Internal function which updates the TCP header of a packet, following
+ * segmentation. This is required to update the header's 'sent' sequence
+ * number, and also to clear 'PSH' and 'FIN' flags for non-tail segments.
+ *
+ * @param pkt
+ *  The packet containing the TCP header.
+ * @param l4_offset
+ *  The offset of the TCP header from the start of the packet.
+ * @param sent_seq
+ *  The sent sequence number.
+ * @param non-tail
+ *  Indicates whether or not this is a tail segment.
+ */
+static inline void
+update_tcp_header(struct rte_mbuf *pkt, uint16_t l4_offset, uint32_t sent_seq,
+		uint8_t non_tail)
+{
+	struct tcp_hdr *tcp_hdr;
+
+	tcp_hdr = (struct tcp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			l4_offset);
+	tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
+	if (likely(non_tail))
+		tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK |
+					TCP_HDR_FIN_MASK));
+}
+
+/**
+ * Internal function which updates the IPv4 header of a packet, following
+ * segmentation. This is required to update the header's 'total_length' field,
+ * to reflect the reduced length of the now-segmented packet. Furthermore, the
+ * header's 'packet_id' field must be updated to reflect the new ID of the
+ * now-segmented packet.
+ *
+ * @param pkt
+ *  The packet containing the IPv4 header.
+ * @param l3_offset
+ *  The offset of the IPv4 header from the start of the packet.
+ * @param id
+ *  The new ID of the packet.
+  */
+static inline void
+update_ipv4_header(struct rte_mbuf *pkt, uint16_t l3_offset, uint16_t id)
+{
+	struct ipv4_hdr *ipv4_hdr;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			l3_offset);
+	ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len - l3_offset);
+	ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
+}
+
+/**
+ * Internal function which divides the input packet into small segments.
+ * Each of the newly-created segments is organized as a two-segment MBUF,
+ * where the first segment is a standard mbuf, which stores a copy of
+ * packet header, and the second is an indirect mbuf which points to a
+ * section of data in the input packet.
+ *
+ * @param pkt
+ *  Packet to segment.
+ * @param pkt_hdr_offset
+ *  Packet header offset, measured in bytes.
+ * @param pyld_unit_size
+ *  The max payload length of a GSO segment.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to keep the mbuf addresses of output segments. If
+ *  the memory space in pkts_out is insufficient, gso_do_segment() fails
+ *  and returns -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that pkts_out can keep.
+ *
+ * @return
+ *  - The number of segments created in the event of success.
+ *  - Return -ENOMEM if run out of memory in MBUF pools.
+ *  - Return -EINVAL for invalid parameters.
+ */
+int gso_do_segment(struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset,
+		uint16_t pyld_unit_size,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#endif
lib/librte_gso/gso_tcp4.c new file +104 -0
new file mode 100644
index 0000000..d83e610
@@ -0,0 +1,104 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "gso_common.h"
+#include "gso_tcp4.h"
+
+static void
+update_ipv4_tcp_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	uint32_t sent_seq;
+	uint16_t id, tail_idx, i;
+	uint16_t l3_offset = pkt->l2_len;
+	uint16_t l4_offset = l3_offset + pkt->l3_len;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char*) +
+			l3_offset);
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+
+	for (i = 0; i < nb_segs; i++) {
+		update_ipv4_header(segs[i], l3_offset, id);
+		update_tcp_header(segs[i], l4_offset, sent_seq, i < tail_idx);
+		id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
+
+int
+gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size, hdr_offset;
+	uint16_t frag_off;
+	int ret;
+
+	/* Don't process the fragmented packet */
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->l2_len);
+	frag_off = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+	if (unlikely(IS_FRAGMENTED(frag_off))) {
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	/* Don't process the packet without data */
+	tcp_dl = pkt->pkt_len - pkt->l2_len - pkt->l3_len - pkt->l4_len;
+	if (unlikely(tcp_dl == 0)) {
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	hdr_offset = pkt->l2_len + pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset;
+
+	/* Segment the payload */
+	ret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,
+			indirect_pool, pkts_out, nb_pkts_out);
+	if (ret > 1)
+		update_ipv4_tcp_headers(pkt, ipid_delta, pkts_out, ret);
+
+	return ret;
+}
lib/librte_gso/gso_tcp4.h new file +74 -0
new file mode 100644
index 0000000..1c57441
@@ -0,0 +1,74 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GSO_TCP4_H_
+#define _GSO_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment an IPv4/TCP packet. This function doesn't check if the input
+ * packet has correct checksums, and doesn't update checksums for output
+ * GSO segments. Furthermore, it doesn't process IP fragment packets.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param gso_size
+ *  The max length of a GSO segment, measured in bytes.
+ * @param ipid_delta
+ *  The increasing unit of IP ids.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when the function succeeds. If the memory space in
+ *  pkts_out is insufficient, it fails and returns -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that 'pkts_out' can keep.
+ *
+ * @return
+ *   - The number of GSO segments filled in pkts_out on success.
+ *   - Return -ENOMEM if run out of memory in MBUF pools.
+ *   - Return -EINVAL for invalid parameters.
+ */
+int gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ip_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#endif
lib/librte_gso/rte_gso.c +23 -2
index b773636..a4fce50 100644
@@ -33,7 +33,12 @@
 
 #include <errno.h>
 
+#include <rte_log.h>
+#include <rte_ethdev.h>
+
 #include "rte_gso.h"
+#include "gso_common.h"
+#include "gso_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -41,12 +46,53 @@
 		struct rte_mbuf **pkts_out,
 		uint16_t nb_pkts_out)
 {
+	struct rte_mempool *direct_pool, *indirect_pool;
+	struct rte_mbuf *pkt_seg;
+	uint64_t ol_flags;
+	uint16_t gso_size;
+	uint8_t ipid_delta;
+	int ret = 1;
+
 	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
 			nb_pkts_out < 1)
 		return -EINVAL;
 
-	pkt->ol_flags &= (~PKT_TX_TCP_SEG);
-	pkts_out[0] = pkt;
+	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
+				DEV_TX_OFFLOAD_TCP_TSO) !=
+			gso_ctx->gso_types) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	direct_pool = gso_ctx->direct_pool;
+	indirect_pool = gso_ctx->indirect_pool;
+	gso_size = gso_ctx->gso_size;

lib/librte_gso/rte_gso.c line 80

Quoted 10 lines
lib/librte_gso/rte_gso.c +10 -0
+	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
+	ol_flags = pkt->ol_flags;
+
+	if (IS_IPV4_TCP(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);

Not sure why do you clean this flag if you don't support that packet type and no action was perfomed?
Suppose you have a mix ipv4 and ipv6 packets - gso lib would do ipv4 and someone else (HW?) can do ipv4 segmentation.
BTW, did you notice that buiding of shared target fails?
Konstantin

Quoted 21 lines
lib/librte_gso/rte_gso.c +16 -2
+		pkts_out[0] = pkt;
+		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
+		return 1;
+	}
+
+	if (ret > 1) {
+		pkt_seg = pkt;
+		while (pkt_seg) {
+			rte_mbuf_refcnt_update(pkt_seg, -1);
+			pkt_seg = pkt_seg->next;
+		}
+	} else if (ret < 0) {
+		/* Revert the ol_flags in the event of failure. */
+		pkt->ol_flags = ol_flags;
+	}
 
-	return 1;
+	return ret;
 }
--

1.9.3

#87 lore raw

Re: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

Quoted 662 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 2:32 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

Hi Mark,

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>;

Ananyev, Konstantin <[email protected]>; Yigit,

Quoted 1 line

Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B

<[email protected]>

Quoted 21 lines

Subject: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

From: Jiayu Hu <[email protected]>

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

Quoted 8 lines
---
 doc/guides/rel_notes/release_17_11.rst  |  12 +++
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 153

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

Review

Quoted 11 lines
 lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               | 104 ++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
 lib/librte_gso/rte_gso.c                |  52 ++++++++++-
 8 files changed, 536 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_17_11.rst

Review

Quoted 23 lines

index 7508be7..c414f73 100644

doc/guides/rel_notes/release_17_11.rst +12 -0
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MTU is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets, which may include a single VLAN tag.
+
+  The GSO library doesn't check if the input packets have correct
+  checksums, and doesn't update checksums for output packets.
+  Additionally, the GSO library doesn't process IP fragmented packets.
+
 
 Resolved Issues
 ---------------
(quoted diff) +0 -0

b/lib/librte_eal/common/include/rte_log.h

Quoted 246 lines

index ec8dba7..2fa1199 100644

lib/librte_eal/common/include/rte_log.h +1 -0
@@ -87,6 +87,7 @@ struct rte_logs {
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
lib/librte_gso/Makefile +2 -0
index aeaacbc..2be64d1 100644
@@ -42,6 +42,8 @@ LIBABIVER := 1
 
 #source files
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +153 -0
new file mode 100644
index 0000000..ee75d4c
@@ -0,0 +1,153 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdbool.h>
+#include <errno.h>
+
+#include <rte_memcpy.h>
+#include <rte_mempool.h>
+
+#include "gso_common.h"
+
+static inline void
+hdr_segment_init(struct rte_mbuf *hdr_segment, struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset)
+{
+	/* Copy MBUF metadata */
+	hdr_segment->nb_segs = 1;
+	hdr_segment->port = pkt->port;
+	hdr_segment->ol_flags = pkt->ol_flags;
+	hdr_segment->packet_type = pkt->packet_type;
+	hdr_segment->pkt_len = pkt_hdr_offset;
+	hdr_segment->data_len = pkt_hdr_offset;
+	hdr_segment->tx_offload = pkt->tx_offload;
+
+	/* Copy the packet header */
+	rte_memcpy(rte_pktmbuf_mtod(hdr_segment, char *),
+			rte_pktmbuf_mtod(pkt, char *),
+			pkt_hdr_offset);
+}
+
+static inline void
+free_gso_segment(struct rte_mbuf **pkts, uint16_t nb_pkts)
+{
+	uint16_t i;
+
+	for (i = 0; i < nb_pkts; i++)
+		rte_pktmbuf_free(pkts[i]);
+}
+
+int
+gso_do_segment(struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset,
+		uint16_t pyld_unit_size,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct rte_mbuf *pkt_in;
+	struct rte_mbuf *hdr_segment, *pyld_segment, *prev_segment;
+	uint16_t pkt_in_data_pos, segment_bytes_remaining;
+	uint16_t pyld_len, nb_segs;
+	bool more_in_pkt, more_out_segs;
+
+	pkt_in = pkt;
+	nb_segs = 0;
+	more_in_pkt = 1;
+	pkt_in_data_pos = pkt_hdr_offset;
+
+	while (more_in_pkt) {
+		if (unlikely(nb_segs >= nb_pkts_out)) {
+			free_gso_segment(pkts_out, nb_segs);
+			return -EINVAL;
+		}
+
+		/* Allocate a direct MBUF */
+		hdr_segment = rte_pktmbuf_alloc(direct_pool);
+		if (unlikely(hdr_segment == NULL)) {
+			free_gso_segment(pkts_out, nb_segs);
+			return -ENOMEM;
+		}
+		/* Fill the packet header */
+		hdr_segment_init(hdr_segment, pkt, pkt_hdr_offset);
+
+		prev_segment = hdr_segment;
+		segment_bytes_remaining = pyld_unit_size;
+		more_out_segs = 1;
+
+		while (more_out_segs && more_in_pkt) {
+			/* Allocate an indirect MBUF */
+			pyld_segment = rte_pktmbuf_alloc(indirect_pool);
+			if (unlikely(pyld_segment == NULL)) {
+				rte_pktmbuf_free(hdr_segment);
+				free_gso_segment(pkts_out, nb_segs);
+				return -ENOMEM;
+			}
+			/* Attach to current MBUF segment of pkt */
+			rte_pktmbuf_attach(pyld_segment, pkt_in);
+
+			prev_segment->next = pyld_segment;
+			prev_segment = pyld_segment;
+
+			pyld_len = segment_bytes_remaining;
+			if (pyld_len + pkt_in_data_pos > pkt_in->data_len)
+				pyld_len = pkt_in->data_len - pkt_in_data_pos;
+
+			pyld_segment->data_off = pkt_in_data_pos +
+				pkt_in->data_off;
+			pyld_segment->data_len = pyld_len;
+
+			/* Update header segment */
+			hdr_segment->pkt_len += pyld_len;
+			hdr_segment->nb_segs++;
+
+			pkt_in_data_pos += pyld_len;
+			segment_bytes_remaining -= pyld_len;
+
+			/* Finish processing a MBUF segment of pkt */
+			if (pkt_in_data_pos == pkt_in->data_len) {
+				pkt_in = pkt_in->next;
+				pkt_in_data_pos = 0;
+				if (pkt_in == NULL)
+					more_in_pkt = 0;
+			}
+
+			/* Finish generating a GSO segment */
+			if (segment_bytes_remaining == 0)
+				more_out_segs = 0;
+		}
+		pkts_out[nb_segs++] = hdr_segment;
+	}
+	return nb_segs;
+}
lib/librte_gso/gso_common.h new file +57 -0
new file mode 100644
index 0000000..8d9b94e
@@ -0,0 +1,141 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GSO_COMMON_H_
+#define _GSO_COMMON_H_
+
+#include <stdint.h>
+
+#include <rte_mbuf.h>
+#include <rte_ip.h>
+#include <rte_tcp.h>
+
+#define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
+		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)
+
+#define TCP_HDR_PSH_MASK ((uint8_t)0x08)
+#define TCP_HDR_FIN_MASK ((uint8_t)0x01)
+
+#define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
+
+/**
+ * Internal function which updates the TCP header of a packet, following
+ * segmentation. This is required to update the header's 'sent' sequence
+ * number, and also to clear 'PSH' and 'FIN' flags for non-tail segments.
+ *
+ * @param pkt

lib/librte_gso/gso_common.h line 67

Quoted 10 lines
lib/librte_gso/gso_common.h new file +10 -0
+ *  The packet containing the TCP header.
+ * @param l4_offset
+ *  The offset of the TCP header from the start of the packet.
+ * @param sent_seq
+ *  The sent sequence number.
+ * @param non-tail
+ *  Indicates whether or not this is a tail segment.
+ */
+static inline void
+update_tcp_header(struct rte_mbuf *pkt, uint16_t l4_offset, uint32_t

sent_seq,

Quoted 5 lines
lib/librte_gso/gso_common.h new file +5 -0
+		uint8_t non_tail)
+{
+	struct tcp_hdr *tcp_hdr;
+
+	tcp_hdr = (struct tcp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +

lib/librte_gso/gso_common.h

Quoted 10 lines
lib/librte_gso/gso_common.h new file +10 -0
+			l4_offset);
+	tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
+	if (likely(non_tail))
+		tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK |
+					TCP_HDR_FIN_MASK));
+}
+
+/**
+ * Internal function which updates the IPv4 header of a packet, following
+ * segmentation. This is required to update the header's 'total_length'

field,

lib/librte_gso/gso_common.h line 83

Quoted 1 line
lib/librte_gso/gso_common.h new file +1 -0
+ * to reflect the reduced length of the now-segmented packet. Furthermore,

the

Quoted 301 lines
lib/librte_gso/gso_common.h new file +58 -0
+ * header's 'packet_id' field must be updated to reflect the new ID of the
+ * now-segmented packet.
+ *
+ * @param pkt
+ *  The packet containing the IPv4 header.
+ * @param l3_offset
+ *  The offset of the IPv4 header from the start of the packet.
+ * @param id
+ *  The new ID of the packet.
+  */
+static inline void
+update_ipv4_header(struct rte_mbuf *pkt, uint16_t l3_offset, uint16_t id)
+{
+	struct ipv4_hdr *ipv4_hdr;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			l3_offset);
+	ipv4_hdr->total_length = rte_cpu_to_be_16(pkt->pkt_len - l3_offset);
+	ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
+}
+
+/**
+ * Internal function which divides the input packet into small segments.
+ * Each of the newly-created segments is organized as a two-segment MBUF,
+ * where the first segment is a standard mbuf, which stores a copy of
+ * packet header, and the second is an indirect mbuf which points to a
+ * section of data in the input packet.
+ *
+ * @param pkt
+ *  Packet to segment.
+ * @param pkt_hdr_offset
+ *  Packet header offset, measured in bytes.
+ * @param pyld_unit_size
+ *  The max payload length of a GSO segment.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to keep the mbuf addresses of output segments. If
+ *  the memory space in pkts_out is insufficient, gso_do_segment() fails
+ *  and returns -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that pkts_out can keep.
+ *
+ * @return
+ *  - The number of segments created in the event of success.
+ *  - Return -ENOMEM if run out of memory in MBUF pools.
+ *  - Return -EINVAL for invalid parameters.
+ */
+int gso_do_segment(struct rte_mbuf *pkt,
+		uint16_t pkt_hdr_offset,
+		uint16_t pyld_unit_size,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#endif
lib/librte_gso/gso_tcp4.c new file +104 -0
new file mode 100644
index 0000000..d83e610
@@ -0,0 +1,104 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "gso_common.h"
+#include "gso_tcp4.h"
+
+static void
+update_ipv4_tcp_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	uint32_t sent_seq;
+	uint16_t id, tail_idx, i;
+	uint16_t l3_offset = pkt->l2_len;
+	uint16_t l4_offset = l3_offset + pkt->l3_len;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char*) +
+			l3_offset);
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+
+	for (i = 0; i < nb_segs; i++) {
+		update_ipv4_header(segs[i], l3_offset, id);
+		update_tcp_header(segs[i], l4_offset, sent_seq, i < tail_idx);
+		id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
+
+int
+gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size, hdr_offset;
+	uint16_t frag_off;
+	int ret;
+
+	/* Don't process the fragmented packet */
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->l2_len);
+	frag_off = rte_be_to_cpu_16(ipv4_hdr->fragment_offset);
+	if (unlikely(IS_FRAGMENTED(frag_off))) {
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	/* Don't process the packet without data */
+	tcp_dl = pkt->pkt_len - pkt->l2_len - pkt->l3_len - pkt->l4_len;
+	if (unlikely(tcp_dl == 0)) {
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	hdr_offset = pkt->l2_len + pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset;
+
+	/* Segment the payload */
+	ret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,
+			indirect_pool, pkts_out, nb_pkts_out);
+	if (ret > 1)
+		update_ipv4_tcp_headers(pkt, ipid_delta, pkts_out, ret);
+
+	return ret;
+}
lib/librte_gso/gso_tcp4.h new file +74 -0
new file mode 100644
index 0000000..1c57441
@@ -0,0 +1,74 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GSO_TCP4_H_
+#define _GSO_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment an IPv4/TCP packet. This function doesn't check if the input
+ * packet has correct checksums, and doesn't update checksums for output
+ * GSO segments. Furthermore, it doesn't process IP fragment packets.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param gso_size
+ *  The max length of a GSO segment, measured in bytes.
+ * @param ipid_delta
+ *  The increasing unit of IP ids.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when the function succeeds. If the memory space in
+ *  pkts_out is insufficient, it fails and returns -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that 'pkts_out' can keep.
+ *
+ * @return
+ *   - The number of GSO segments filled in pkts_out on success.
+ *   - Return -ENOMEM if run out of memory in MBUF pools.
+ *   - Return -EINVAL for invalid parameters.
+ */
+int gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ip_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#endif
lib/librte_gso/rte_gso.c +31 -2
index b773636..a4fce50 100644
@@ -33,7 +33,12 @@
 
 #include <errno.h>
 
+#include <rte_log.h>
+#include <rte_ethdev.h>
+
 #include "rte_gso.h"
+#include "gso_common.h"
+#include "gso_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -41,12 +46,53 @@
 		struct rte_mbuf **pkts_out,
 		uint16_t nb_pkts_out)
 {
+	struct rte_mempool *direct_pool, *indirect_pool;
+	struct rte_mbuf *pkt_seg;
+	uint64_t ol_flags;
+	uint16_t gso_size;
+	uint8_t ipid_delta;
+	int ret = 1;
+
 	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
 			nb_pkts_out < 1)
 		return -EINVAL;
 
-	pkt->ol_flags &= (~PKT_TX_TCP_SEG);
-	pkts_out[0] = pkt;
+	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
+				DEV_TX_OFFLOAD_TCP_TSO) !=
+			gso_ctx->gso_types) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	direct_pool = gso_ctx->direct_pool;
+	indirect_pool = gso_ctx->indirect_pool;
+	gso_size = gso_ctx->gso_size;
+	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
+	ol_flags = pkt->ol_flags;
+
+	if (IS_IPV4_TCP(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
Quoted 8 lines

lib/librte_gso/rte_gso.c line 80

Quoted 2 lines
lib/librte_gso/rte_gso.c +2 -0
+	} else {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);

Not sure why do you clean this flag if you don't support that packet type and no action was perfomed?
Suppose you have a mix ipv4 and ipv6 packets - gso lib would do ipv4 and someone else
(HW?) can do ipv4 segmentation.

I can't say for definite, since I didn't implement this change. However, I can only presume that the assumption here is that since segmentation is being done in S/W that the underlying H/W does not support TSO. Since the underlying HW can't segment the packet in HW, we should clear the flag; otherwise, if an mbuf marked for TCP segmentation is passed to the driver of a NIC that does not support/understand that feature, the behavior is undefined. Is this a fair assumption in your opinion, or is it the case that the packet would simply be transmitted un-segmented in that case, and so we shouldn't clear the flag?

Thanks again,
Mark

Quoted 2 lines

BTW, did you notice that building of shared target fails? Konstantin

I didn't, but I'll take a look right now - thanks for the catch!

Quoted 23 lines
Quoted 23 lines
lib/librte_gso/rte_gso.c +16 -2
+		pkts_out[0] = pkt;
+		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
+		return 1;
+	}
+
+	if (ret > 1) {
+		pkt_seg = pkt;
+		while (pkt_seg) {
+			rte_mbuf_refcnt_update(pkt_seg, -1);
+			pkt_seg = pkt_seg->next;
+		}
+	} else if (ret < 0) {
+		/* Revert the ol_flags in the event of failure. */
+		pkt->ol_flags = ol_flags;
+	}
 
-	return 1;
+	return ret;
 }
--

1.9.3

#88 lore raw

Re: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

Quoted 47 lines
Quoted 38 lines
Quoted 38 lines

int
rte_gso_segment(struct rte_mbuf *pkt,

lib/librte_gso/rte_gso.c +26 -2
@@ -41,12 +46,53 @@
 		struct rte_mbuf **pkts_out,
 		uint16_t nb_pkts_out)
 {
+	struct rte_mempool *direct_pool, *indirect_pool;
+	struct rte_mbuf *pkt_seg;
+	uint64_t ol_flags;
+	uint16_t gso_size;
+	uint8_t ipid_delta;
+	int ret = 1;
+
 	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
 			nb_pkts_out < 1)
 		return -EINVAL;
 
-	pkt->ol_flags &= (~PKT_TX_TCP_SEG);
-	pkts_out[0] = pkt;
+	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
+				DEV_TX_OFFLOAD_TCP_TSO) !=
+			gso_ctx->gso_types) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	direct_pool = gso_ctx->direct_pool;
+	indirect_pool = gso_ctx->indirect_pool;
+	gso_size = gso_ctx->gso_size;
+	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
+	ol_flags = pkt->ol_flags;
+
+	if (IS_IPV4_TCP(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
Quoted 8 lines

lib/librte_gso/rte_gso.c line 80

Quoted 2 lines
lib/librte_gso/rte_gso.c +2 -0
+	} else {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);

Not sure why do you clean this flag if you don't support that packet type and no action was perfomed?
Suppose you have a mix ipv4 and ipv6 packets - gso lib would do ipv4 and someone else
(HW?) can do ipv4 segmentation.

Quoted 6 lines

I can't say for definite, since I didn't implement this change. However, I can only presume that the assumption here is that since segmentation is being done in S/W that the underlying H/W does not support TSO.
Since the underlying HW can't segment the packet in HW, we should clear the flag; otherwise, if an mbuf marked for TCP segmentation is passed to the driver of a NIC that does not support/understand that feature, the behavior is undefined.
Is this a fair assumption in your opinion, or is it the case that the packet would simply be transmitted un-segmented in that case, and so we shouldn't clear the flag?

Yes, I think if we shouldn't clear the flag if we didn't do any segmentation (we just encounter a packet type that we don't support). Konstantin

Quoted 32 lines

Thanks again,
Mark

Quoted 2 lines

BTW, did you notice that building of shared target fails? Konstantin

I didn't, but I'll take a look right now - thanks for the catch!

Quoted 23 lines
Quoted 23 lines
lib/librte_gso/rte_gso.c +16 -2
+		pkts_out[0] = pkt;
+		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
+		return 1;
+	}
+
+	if (ret > 1) {
+		pkt_seg = pkt;
+		while (pkt_seg) {
+			rte_mbuf_refcnt_update(pkt_seg, -1);
+			pkt_seg = pkt_seg->next;
+		}
+	} else if (ret < 0) {
+		/* Revert the ol_flags in the event of failure. */
+		pkt->ol_flags = ol_flags;
+	}
 
-	return 1;
+	return ret;
 }
--

1.9.3

#89 lore raw

Re: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

Quoted 61 lines

From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 3:49 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

Quoted 47 lines
Quoted 38 lines
Quoted 38 lines

int
rte_gso_segment(struct rte_mbuf *pkt,

lib/librte_gso/rte_gso.c +26 -2
@@ -41,12 +46,53 @@
 		struct rte_mbuf **pkts_out,
 		uint16_t nb_pkts_out)
 {
+	struct rte_mempool *direct_pool, *indirect_pool;
+	struct rte_mbuf *pkt_seg;
+	uint64_t ol_flags;
+	uint16_t gso_size;
+	uint8_t ipid_delta;
+	int ret = 1;
+
 	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
 			nb_pkts_out < 1)
 		return -EINVAL;
 
-	pkt->ol_flags &= (~PKT_TX_TCP_SEG);
-	pkts_out[0] = pkt;
+	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
+				DEV_TX_OFFLOAD_TCP_TSO) !=
+			gso_ctx->gso_types) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	direct_pool = gso_ctx->direct_pool;
+	indirect_pool = gso_ctx->indirect_pool;
+	gso_size = gso_ctx->gso_size;
+	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
+	ol_flags = pkt->ol_flags;
+
+	if (IS_IPV4_TCP(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
Quoted 8 lines

lib/librte_gso/rte_gso.c line 80

Quoted 2 lines
lib/librte_gso/rte_gso.c +2 -0
+	} else {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);

Not sure why do you clean this flag if you don't support that packet type and no action was perfomed?
Suppose you have a mix ipv4 and ipv6 packets - gso lib would do ipv4 and someone else
(HW?) can do ipv4 segmentation.

Quoted 1 line

I can't say for definite, since I didn't implement this change. However, I

can only presume that the assumption here is that since

Quoted 1 line

segmentation is being done in S/W that the underlying H/W does not support

TSO.

Quoted 1 line

Since the underlying HW can't segment the packet in HW, we should clear the

flag; otherwise, if an mbuf marked for TCP segmentation is

Quoted 1 line

passed to the driver of a NIC that does not support/understand that feature,

Quoted 8 lines

the behavior is undefined.

Quoted 1 line

Is this a fair assumption in your opinion, or is it the case that the packet

would simply be transmitted un-segmented in that case, and so we

Quoted 1 line

shouldn't clear the flag?

Yes, I think if we shouldn't clear the flag if we didn't do any segmentation (we just encounter a packet type that we don't support). Konstantin

Okay, thanks for clarifying - I'll update the code accordingly. -Mark

Quoted 33 lines
Quoted 33 lines

Thanks again,
Mark

Quoted 2 lines

BTW, did you notice that building of shared target fails? Konstantin

I didn't, but I'll take a look right now - thanks for the catch!

Quoted 23 lines
Quoted 23 lines
lib/librte_gso/rte_gso.c +16 -2
+		pkts_out[0] = pkt;
+		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
+		return 1;
+	}
+
+	if (ret > 1) {
+		pkt_seg = pkt;
+		while (pkt_seg) {
+			rte_mbuf_refcnt_update(pkt_seg, -1);
+			pkt_seg = pkt_seg->next;
+		}
+	} else if (ret < 0) {
+		/* Revert the ol_flags in the event of failure. */
+		pkt->ol_flags = ol_flags;
+	}
 
-	return 1;
+	return ret;
 }
--

1.9.3

#90 lore raw

Re: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

In reply to Mark Kavanagh
Quoted 65 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 2:32 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

Hi Mark,

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Ananyev, Konstantin <[email protected]>;

Yigit,

Quoted 48 lines

Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B <[email protected]>
Subject: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

From: Jiayu Hu <[email protected]>

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst  |  12 +++
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 153 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               | 104 ++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
 lib/librte_gso/rte_gso.c                |  52 ++++++++++-
 8 files changed, 536 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
doc/guides/rel_notes/release_17_11.rst +0 -0
index 7508be7..c414f73 100644
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
Quoted 7 lines

doc/guides/rel_notes/release_17_11.rst New Features · line 50

Quoted 7 lines
doc/guides/rel_notes/release_17_11.rst +7 -0
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MTU is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets, which may include a single VLAN tag.

As a nit: I think it doesn't matter as you are relying on mbuf->l2_len. Konstantin

#91 lore raw

Re: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

Quoted 81 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 2:36 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

Quoted 5 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 2:32 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>;

Yigit, Ferruh <[email protected]>; [email protected]

Quoted 9 lines

Subject: RE: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

Hi Mark,

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng

<[email protected]>; Ananyev, Konstantin <[email protected]>;

Quoted 2 lines

Yigit,

Quoted 1 line

Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B

<[email protected]>

Quoted 21 lines
Quoted 21 lines

Subject: [PATCH v6 2/6] gso: add TCP/IPv4 GSO support

From: Jiayu Hu <[email protected]>

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

Quoted 8 lines
Quoted 8 lines
---
 doc/guides/rel_notes/release_17_11.rst  |  12 +++
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 153

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

Quoted 1 line
Quoted 1 line
 lib/librte_gso/gso_common.h             | 141

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

Quoted 10 lines

Review

Quoted 10 lines
 lib/librte_gso/gso_tcp4.c               | 104 ++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
 lib/librte_gso/rte_gso.c                |  52 ++++++++++-
 8 files changed, 536 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_17_11.rst

Quoted 7 lines
Quoted 7 lines

index 7508be7..c414f73 100644

doc/guides/rel_notes/release_17_11.rst +0 -0
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
Quoted 11 lines
Quoted 7 lines

doc/guides/rel_notes/release_17_11.rst New Features · line 50

Quoted 7 lines
doc/guides/rel_notes/release_17_11.rst +7 -0
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MTU is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets, which may include a single VLAN tag.

As a nit: I think it doesn't matter as you are relying on mbuf->l2_len. Konstantin

Okay, I'll remove any mention of VLAN tags in the description - thanks!

#92 lore raw

PATCH v6 3/6 gso: add VxLAN GSO support

In reply to Mark Kavanagh

This patch adds a framework that allows GSO on tunneled packets. Furthermore, it leverages that framework to provide GSO support for VxLAN-encapsulated packets.

Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

VxLAN GSO doesn't check if input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize each output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSO'd segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst |   3 +
 lib/librte_gso/Makefile                |   1 +
 lib/librte_gso/gso_common.h            |  25 +++++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 123 +++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_tunnel_tcp4.h       |  75 ++++++++++++++++++++
 lib/librte_gso/rte_gso.c               |  13 +++-
 6 files changed, 237 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
doc/guides/rel_notes/release_17_11.rst +3 -0
index c414f73..25b8a78 100644
@@ -48,6 +48,9 @@ New Features
   ones (e.g. MTU is 1500B). Supported packet types are:
 
   * TCP/IPv4 packets, which may include a single VLAN tag.
+  * VxLAN packets, which must have an outer IPv4 header (prepended by
+    an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
+    an optional VLAN tag).
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.h +25 -0
index 8d9b94e..c051295 100644
@@ -39,6 +39,7 @@
 #include <rte_mbuf.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
+#include <rte_udp.h>
 
 #define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
 		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)
@@ -49,6 +50,30 @@
 #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
 
+#define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_VXLAN))
+
+/**
+ * Internal function which updates the UDP header of a packet, following
+ * segmentation. This is required to update the header's datagram length field.
+ *
+ * @param pkt
+ *  The packet containing the UDP header.
+ * @param udp_offset
+ *  The offset of the UDP header from the start of the packet.
+ */
+static inline void
+update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset)
+{
+	struct udp_hdr *udp_hdr;
+
+	udp_hdr = (struct udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			udp_offset);
+	udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset);
+}
+
 /**
  * Internal function which updates the TCP header of a packet, following
  * segmentation. This is required to update the header's 'sent' sequence
lib/librte_gso/gso_tunnel_tcp4.c new file +123 -0

123 lines not on this page · raw message

lib/librte_gso/gso_tunnel_tcp4.h new file +75 -0

75 lines not on this page · raw message

lib/librte_gso/rte_gso.c +10 -3
index a4fce50..6095689 100644
@@ -39,6 +39,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp4.h"
+#include "gso_tunnel_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -58,8 +59,9 @@
 		return -EINVAL;
 
 	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
-				DEV_TX_OFFLOAD_TCP_TSO) !=
-			gso_ctx->gso_types) {
+				(DEV_TX_OFFLOAD_TCP_TSO |
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
+				gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
 		return 1;
@@ -71,7 +73,12 @@
 	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_TCP(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else if (IS_IPV4_TCP(pkt->ol_flags)) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
Signature · 1 line
1.9.3
#93 lore raw

Re: [PATCH v6 3/6] gso: add VxLAN GSO support

Quoted 212 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Ananyev, Konstantin <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B <[email protected]>
Subject: [PATCH v6 3/6] gso: add VxLAN GSO support

This patch adds a framework that allows GSO on tunneled packets. Furthermore, it leverages that framework to provide GSO support for VxLAN-encapsulated packets.

Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

VxLAN GSO doesn't check if input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize each output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSO'd segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst |   3 +
 lib/librte_gso/Makefile                |   1 +
 lib/librte_gso/gso_common.h            |  25 +++++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 123 +++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_tunnel_tcp4.h       |  75 ++++++++++++++++++++
 lib/librte_gso/rte_gso.c               |  13 +++-
 6 files changed, 237 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
doc/guides/rel_notes/release_17_11.rst +3 -0
index c414f73..25b8a78 100644
@@ -48,6 +48,9 @@ New Features
   ones (e.g. MTU is 1500B). Supported packet types are:
 
   * TCP/IPv4 packets, which may include a single VLAN tag.
+  * VxLAN packets, which must have an outer IPv4 header (prepended by
+    an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
+    an optional VLAN tag).
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.h +25 -0
index 8d9b94e..c051295 100644
@@ -39,6 +39,7 @@
 #include <rte_mbuf.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
+#include <rte_udp.h>
 
 #define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
 		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)
@@ -49,6 +50,30 @@
 #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
 
+#define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_VXLAN))
+
+/**
+ * Internal function which updates the UDP header of a packet, following
+ * segmentation. This is required to update the header's datagram length field.
+ *
+ * @param pkt
+ *  The packet containing the UDP header.
+ * @param udp_offset
+ *  The offset of the UDP header from the start of the packet.
+ */
+static inline void
+update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset)
+{
+	struct udp_hdr *udp_hdr;
+
+	udp_hdr = (struct udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			udp_offset);
+	udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset);
+}
+
 /**
  * Internal function which updates the TCP header of a packet, following
  * segmentation. This is required to update the header's 'sent' sequence
lib/librte_gso/gso_tunnel_tcp4.c new file +96 -0
new file mode 100644
index 0000000..34bbbd7
@@ -0,0 +1,123 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "gso_common.h"
+#include "gso_tunnel_tcp4.h"
+
+static void
+update_tunnel_ipv4_tcp_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	uint32_t sent_seq;
+	uint16_t outer_id, inner_id, tail_idx, i;
+	uint16_t outer_ipv4_offset, inner_ipv4_offset, udp_offset, tcp_offset;
+
+	outer_ipv4_offset = pkt->outer_l2_len;
+	udp_offset = outer_ipv4_offset + pkt->outer_l3_len;
+	inner_ipv4_offset = udp_offset + pkt->l2_len;
+	tcp_offset = inner_ipv4_offset + pkt->l3_len;
+
+	/* Outer IPv4 header. */
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			outer_ipv4_offset);
+	outer_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+
+	/* Inner IPv4 header. */
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			inner_ipv4_offset);
+	inner_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+
+	for (i = 0; i < nb_segs; i++) {
+		update_ipv4_header(segs[i], outer_ipv4_offset, outer_id);
+		update_udp_header(segs[i], udp_offset);
+		update_ipv4_header(segs[i], inner_ipv4_offset, inner_id);
+		update_tcp_header(segs[i], tcp_offset, sent_seq, i < tail_idx);
+		outer_id++;
+		inner_id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
+
+int
+gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ipv4_hdr *inner_ipv4_hdr;
+	uint16_t pyld_unit_size, hdr_offset;
+	uint16_t tcp_dl, frag_off;
+	int ret = 1;
+
+	hdr_offset = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;
+	inner_ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			hdr_offset);
+	/*
+	 * Don't process the packet whose MF bit or offset in the inner
+	 * IPv4 header are non-zero.

lib/librte_gso/gso_tunnel_tcp4.c line 106

Quoted 10 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +10 -0
+	 */
+	frag_off = rte_be_to_cpu_16(inner_ipv4_hdr->fragment_offset);
+	if (unlikely(IS_FRAGMENTED(frag_off))) {
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	/* Don't process the packet without data */
+	tcp_dl = pkt->pkt_len - pkt->l2_len - pkt->l3_len - pkt->l4_len;
+	if (unlikely(tcp_dl == 0)) {

You probably need to take into account outer_len* too.. Probably better to move that check after final hdr_offset calculations:

...
hdr_offset += pkt->l3_len + pkt->l4_len;
if (hdr_offset >= pkt->pkt_len) {..;' return 1;}
...

Quoted 123 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +17 -0
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	hdr_offset += pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset;
+
+	/* Segment the payload */
+	ret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,
+			indirect_pool, pkts_out, nb_pkts_out);
+	if (ret <= 1)
+		return ret;
+
+	update_tunnel_ipv4_tcp_headers(pkt, ipid_delta, pkts_out, ret);
+
+	return ret;
+}
lib/librte_gso/gso_tunnel_tcp4.h new file +75 -0
new file mode 100644
index 0000000..3c67f0c
@@ -0,0 +1,75 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GSO_TUNNEL_TCP4_H_
+#define _GSO_TUNNEL_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment a tunneling packet with inner TCP/IPv4 headers. This function
+ * doesn't check if the input packet has correct checksums, and doesn't
+ * update checksums for output GSO segments. Furthermore, it doesn't
+ * process IP fragment packets.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param gso_size
+ *  The max length of a GSO segment, measured in bytes.
+ * @param ipid_delta
+ *  The increasing unit of IP ids.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when it succeeds. If the memory space in pkts_out is
+ *  insufficient, it fails and returns -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that 'pkts_out' can keep.
+ *
+ * @return
+ *   - The number of GSO segments filled in pkts_out on success.
+ *   - Return -ENOMEM if run out of memory in MBUF pools.
+ *   - Return -EINVAL for invalid parameters.
+ */
+int gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#endif
lib/librte_gso/rte_gso.c +4 -2
index a4fce50..6095689 100644
@@ -39,6 +39,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp4.h"
+#include "gso_tunnel_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -58,8 +59,9 @@
 		return -EINVAL;
 
 	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
-				DEV_TX_OFFLOAD_TCP_TSO) !=
-			gso_ctx->gso_types) {
+				(DEV_TX_OFFLOAD_TCP_TSO |
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
+				gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
 		return 1;

lib/librte_gso/rte_gso.c line 81

Quoted 10 lines
lib/librte_gso/rte_gso.c +6 -1
@@ -71,7 +73,12 @@
 	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_TCP(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else if (IS_IPV4_TCP(pkt->ol_flags)) {

Hmm it doesn't look quite right.
Imagine user doesn't want libgso to segment plain TCP packets with that ctx, just VXLAN+TCP.

I think you need to merge that if and one above to something like that:

If (IS_IPV4_VXLAN_TCP4(pkt->ol_flags))
&& (gso_ctx->gso_types & (DEV_TX_OFFLOAD_VXLAN_TNL_TSO | DEV_TX_OFFLOAD_TCP_TSO)) ==
(DEV_TX_OFFLOAD_VXLAN_TNL_TSO | DEV_TX_OFFLOAD_TCP_TSO)) {
...
} else if (IS_IPV4_TCP(pkt->ol_flags) && (gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO)) {
...

} else {
     /* unsupported packet, skip */
}

Konstantin

Quoted 5 lines
lib/librte_gso/rte_gso.c +0 -1
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
--

1.9.3

#94 lore raw

Re: [PATCH v6 3/6] gso: add VxLAN GSO support

Quoted 234 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 3:12 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 3/6] gso: add VxLAN GSO support

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>;

Ananyev, Konstantin <[email protected]>; Yigit,

Quoted 1 line

Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B

<[email protected]>

Quoted 20 lines

Subject: [PATCH v6 3/6] gso: add VxLAN GSO support

This patch adds a framework that allows GSO on tunneled packets. Furthermore, it leverages that framework to provide GSO support for VxLAN-encapsulated packets.

Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

VxLAN GSO doesn't check if input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize each output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSO'd segments are freed, the packet is freed automatically.

Quoted 7 lines
---
 doc/guides/rel_notes/release_17_11.rst |   3 +
 lib/librte_gso/Makefile                |   1 +
 lib/librte_gso/gso_common.h            |  25 +++++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 123

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

Review

Quoted 7 lines
 lib/librte_gso/gso_tunnel_tcp4.h       |  75 ++++++++++++++++++++
 lib/librte_gso/rte_gso.c               |  13 +++-
 6 files changed, 237 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_17_11.rst

Quoted 38 lines

index c414f73..25b8a78 100644

doc/guides/rel_notes/release_17_11.rst +3 -0
@@ -48,6 +48,9 @@ New Features
   ones (e.g. MTU is 1500B). Supported packet types are:
 
   * TCP/IPv4 packets, which may include a single VLAN tag.
+  * VxLAN packets, which must have an outer IPv4 header (prepended by
+    an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
+    an optional VLAN tag).
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.h +1 -0
index 8d9b94e..c051295 100644
@@ -39,6 +39,7 @@
 #include <rte_mbuf.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
+#include <rte_udp.h>
 
 #define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
 		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)

lib/librte_gso/gso_common.h line 53

Quoted 4 lines
lib/librte_gso/gso_common.h +1 -0
@@ -49,6 +50,30 @@
 #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
 
+#define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 |

\

lib/librte_gso/gso_common.h

Quoted 7 lines
lib/librte_gso/gso_common.h +7 -0
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_VXLAN))
+
+/**
+ * Internal function which updates the UDP header of a packet, following
+ * segmentation. This is required to update the header's datagram length

field.

Review

Quoted 20 lines
lib/librte_gso/gso_common.h +16 -0
+ *
+ * @param pkt
+ *  The packet containing the UDP header.
+ * @param udp_offset
+ *  The offset of the UDP header from the start of the packet.
+ */
+static inline void
+update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset)
+{
+	struct udp_hdr *udp_hdr;
+
+	udp_hdr = (struct udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			udp_offset);
+	udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset);
+}
+
 /**
  * Internal function which updates the TCP header of a packet, following
  * segmentation. This is required to update the header's 'sent' sequence
(quoted diff) +0 -0

b/lib/librte_gso/gso_tunnel_tcp4.c

Quoted 106 lines

new file mode 100644
index 0000000..34bbbd7

lib/librte_gso/gso_tunnel_tcp4.c new file +101 -0
@@ -0,0 +1,123 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "gso_common.h"
+#include "gso_tunnel_tcp4.h"
+
+static void
+update_tunnel_ipv4_tcp_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	uint32_t sent_seq;
+	uint16_t outer_id, inner_id, tail_idx, i;
+	uint16_t outer_ipv4_offset, inner_ipv4_offset, udp_offset, tcp_offset;
+
+	outer_ipv4_offset = pkt->outer_l2_len;
+	udp_offset = outer_ipv4_offset + pkt->outer_l3_len;
+	inner_ipv4_offset = udp_offset + pkt->l2_len;
+	tcp_offset = inner_ipv4_offset + pkt->l3_len;
+
+	/* Outer IPv4 header. */
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			outer_ipv4_offset);
+	outer_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+
+	/* Inner IPv4 header. */
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			inner_ipv4_offset);
+	inner_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+
+	for (i = 0; i < nb_segs; i++) {
+		update_ipv4_header(segs[i], outer_ipv4_offset, outer_id);
+		update_udp_header(segs[i], udp_offset);
+		update_ipv4_header(segs[i], inner_ipv4_offset, inner_id);
+		update_tcp_header(segs[i], tcp_offset, sent_seq, i < tail_idx);
+		outer_id++;
+		inner_id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
+
+int
+gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ipv4_hdr *inner_ipv4_hdr;
+	uint16_t pyld_unit_size, hdr_offset;
+	uint16_t tcp_dl, frag_off;
+	int ret = 1;
+
+	hdr_offset = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;
+	inner_ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			hdr_offset);
+	/*
+	 * Don't process the packet whose MF bit or offset in the inner
+	 * IPv4 header are non-zero.
+	 */
+	frag_off = rte_be_to_cpu_16(inner_ipv4_hdr->fragment_offset);
+	if (unlikely(IS_FRAGMENTED(frag_off))) {
+		pkts_out[0] = pkt;
+		return 1;
Quoted 8 lines

lib/librte_gso/gso_tunnel_tcp4.c line 106

Quoted 5 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +5 -0
+	}
+
+	/* Don't process the packet without data */
+	tcp_dl = pkt->pkt_len - pkt->l2_len - pkt->l3_len - pkt->l4_len;
+	if (unlikely(tcp_dl == 0)) {

You probably need to take into account outer_len* too.. Probably better to move that check after final hdr_offset calculations:

Agreed - thanks.

Quoted 133 lines

...
hdr_offset += pkt->l3_len + pkt->l4_len;
if (hdr_offset >= pkt->pkt_len) {..;' return 1;}
...

Review

Quoted 18 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +17 -0
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	hdr_offset += pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset;
+
+	/* Segment the payload */
+	ret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,
+			indirect_pool, pkts_out, nb_pkts_out);
+	if (ret <= 1)
+		return ret;
+
+	update_tunnel_ipv4_tcp_headers(pkt, ipid_delta, pkts_out, ret);
+
+	return ret;
+}
(quoted diff) +0 -0

b/lib/librte_gso/gso_tunnel_tcp4.h

Quoted 108 lines

new file mode 100644
index 0000000..3c67f0c

lib/librte_gso/gso_tunnel_tcp4.h new file +75 -0
@@ -0,0 +1,75 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GSO_TUNNEL_TCP4_H_
+#define _GSO_TUNNEL_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment a tunneling packet with inner TCP/IPv4 headers. This function
+ * doesn't check if the input packet has correct checksums, and doesn't
+ * update checksums for output GSO segments. Furthermore, it doesn't
+ * process IP fragment packets.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param gso_size
+ *  The max length of a GSO segment, measured in bytes.
+ * @param ipid_delta
+ *  The increasing unit of IP ids.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when it succeeds. If the memory space in pkts_out is
+ *  insufficient, it fails and returns -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that 'pkts_out' can keep.
+ *
+ * @return
+ *   - The number of GSO segments filled in pkts_out on success.
+ *   - Return -ENOMEM if run out of memory in MBUF pools.
+ *   - Return -EINVAL for invalid parameters.
+ */
+int gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#endif
lib/librte_gso/rte_gso.c +4 -2
index a4fce50..6095689 100644
@@ -39,6 +39,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp4.h"
+#include "gso_tunnel_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -58,8 +59,9 @@
 		return -EINVAL;
 
 	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
-				DEV_TX_OFFLOAD_TCP_TSO) !=
-			gso_ctx->gso_types) {
+				(DEV_TX_OFFLOAD_TCP_TSO |
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
+				gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
 		return 1;
@@ -71,7 +73,12 @@
 	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
Quoted 11 lines

lib/librte_gso/rte_gso.c line 81

Quoted 7 lines
lib/librte_gso/rte_gso.c +6 -1
-	if (IS_IPV4_TCP(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else if (IS_IPV4_TCP(pkt->ol_flags)) {

Hmm it doesn't look quite right.
Imagine user doesn't want libgso to segment plain TCP packets with that ctx, just VXLAN+TCP.

That's a very good point - I'll update the code as per your suggestion. Thanks!

Quoted 22 lines

I think you need to merge that if and one above to something like that:

If (IS_IPV4_VXLAN_TCP4(pkt->ol_flags))
&& (gso_ctx->gso_types & (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
DEV_TX_OFFLOAD_TCP_TSO)) ==
(DEV_TX_OFFLOAD_VXLAN_TNL_TSO | DEV_TX_OFFLOAD_TCP_TSO)) {
...
} else if (IS_IPV4_TCP(pkt->ol_flags) && (gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO)) {
...

} else {
    /* unsupported packet, skip */
}

Konstantin

Quoted 5 lines
lib/librte_gso/rte_gso.c +0 -1
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
--

1.9.3

#95 lore raw

Re: [PATCH v6 3/6] gso: add VxLAN GSO support

In reply to Ananyev, Konstantin
Quoted 385 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 3:12 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 3/6] gso: add VxLAN GSO support

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>;

Ananyev, Konstantin <[email protected]>; Yigit,

Quoted 1 line

Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B

<[email protected]>

Quoted 20 lines

Subject: [PATCH v6 3/6] gso: add VxLAN GSO support

This patch adds a framework that allows GSO on tunneled packets. Furthermore, it leverages that framework to provide GSO support for VxLAN-encapsulated packets.

Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

VxLAN GSO doesn't check if input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize each output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSO'd segments are freed, the packet is freed automatically.

Quoted 7 lines
---
 doc/guides/rel_notes/release_17_11.rst |   3 +
 lib/librte_gso/Makefile                |   1 +
 lib/librte_gso/gso_common.h            |  25 +++++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 123

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

Review

Quoted 7 lines
 lib/librte_gso/gso_tunnel_tcp4.h       |  75 ++++++++++++++++++++
 lib/librte_gso/rte_gso.c               |  13 +++-
 6 files changed, 237 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_17_11.rst

Quoted 38 lines

index c414f73..25b8a78 100644

doc/guides/rel_notes/release_17_11.rst +3 -0
@@ -48,6 +48,9 @@ New Features
   ones (e.g. MTU is 1500B). Supported packet types are:
 
   * TCP/IPv4 packets, which may include a single VLAN tag.
+  * VxLAN packets, which must have an outer IPv4 header (prepended by
+    an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
+    an optional VLAN tag).
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.h +1 -0
index 8d9b94e..c051295 100644
@@ -39,6 +39,7 @@
 #include <rte_mbuf.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
+#include <rte_udp.h>
 
 #define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
 		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)

lib/librte_gso/gso_common.h line 53

Quoted 4 lines
lib/librte_gso/gso_common.h +1 -0
@@ -49,6 +50,30 @@
 #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
 
+#define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 |

\

lib/librte_gso/gso_common.h

Quoted 7 lines
lib/librte_gso/gso_common.h +7 -0
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_VXLAN))
+
+/**
+ * Internal function which updates the UDP header of a packet, following
+ * segmentation. This is required to update the header's datagram length

field.

Review

Quoted 20 lines
lib/librte_gso/gso_common.h +16 -0
+ *
+ * @param pkt
+ *  The packet containing the UDP header.
+ * @param udp_offset
+ *  The offset of the UDP header from the start of the packet.
+ */
+static inline void
+update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset)
+{
+	struct udp_hdr *udp_hdr;
+
+	udp_hdr = (struct udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			udp_offset);
+	udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset);
+}
+
 /**
  * Internal function which updates the TCP header of a packet, following
  * segmentation. This is required to update the header's 'sent' sequence
(quoted diff) +0 -0

b/lib/librte_gso/gso_tunnel_tcp4.c

Quoted 101 lines

new file mode 100644
index 0000000..34bbbd7

lib/librte_gso/gso_tunnel_tcp4.c new file +96 -0
@@ -0,0 +1,123 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "gso_common.h"
+#include "gso_tunnel_tcp4.h"
+
+static void
+update_tunnel_ipv4_tcp_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	uint32_t sent_seq;
+	uint16_t outer_id, inner_id, tail_idx, i;
+	uint16_t outer_ipv4_offset, inner_ipv4_offset, udp_offset, tcp_offset;
+
+	outer_ipv4_offset = pkt->outer_l2_len;
+	udp_offset = outer_ipv4_offset + pkt->outer_l3_len;
+	inner_ipv4_offset = udp_offset + pkt->l2_len;
+	tcp_offset = inner_ipv4_offset + pkt->l3_len;
+
+	/* Outer IPv4 header. */
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			outer_ipv4_offset);
+	outer_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+
+	/* Inner IPv4 header. */
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			inner_ipv4_offset);
+	inner_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+
+	for (i = 0; i < nb_segs; i++) {
+		update_ipv4_header(segs[i], outer_ipv4_offset, outer_id);
+		update_udp_header(segs[i], udp_offset);
+		update_ipv4_header(segs[i], inner_ipv4_offset, inner_id);
+		update_tcp_header(segs[i], tcp_offset, sent_seq, i < tail_idx);
+		outer_id++;
+		inner_id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
+
+int
+gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ipv4_hdr *inner_ipv4_hdr;
+	uint16_t pyld_unit_size, hdr_offset;
+	uint16_t tcp_dl, frag_off;
+	int ret = 1;
+
+	hdr_offset = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;
+	inner_ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			hdr_offset);
+	/*
+	 * Don't process the packet whose MF bit or offset in the inner
+	 * IPv4 header are non-zero.

lib/librte_gso/gso_tunnel_tcp4.c line 106

Quoted 10 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +10 -0
+	 */
+	frag_off = rte_be_to_cpu_16(inner_ipv4_hdr->fragment_offset);
+	if (unlikely(IS_FRAGMENTED(frag_off))) {
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	/* Don't process the packet without data */
+	tcp_dl = pkt->pkt_len - pkt->l2_len - pkt->l3_len - pkt->l4_len;
+	if (unlikely(tcp_dl == 0)) {

You probably need to take into account outer_len* too.. Probably better to move that check after final hdr_offset calculations:

...
hdr_offset += pkt->l3_len + pkt->l4_len;
if (hdr_offset >= pkt->pkt_len) {..;' return 1;}
...

Review

Quoted 18 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +17 -0
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	hdr_offset += pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset;
+
+	/* Segment the payload */
+	ret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,
+			indirect_pool, pkts_out, nb_pkts_out);
+	if (ret <= 1)
+		return ret;
+
+	update_tunnel_ipv4_tcp_headers(pkt, ipid_delta, pkts_out, ret);
+
+	return ret;
+}
(quoted diff) +0 -0

b/lib/librte_gso/gso_tunnel_tcp4.h

Quoted 105 lines

new file mode 100644
index 0000000..3c67f0c

lib/librte_gso/gso_tunnel_tcp4.h new file +75 -0
@@ -0,0 +1,75 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GSO_TUNNEL_TCP4_H_
+#define _GSO_TUNNEL_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment a tunneling packet with inner TCP/IPv4 headers. This function
+ * doesn't check if the input packet has correct checksums, and doesn't
+ * update checksums for output GSO segments. Furthermore, it doesn't
+ * process IP fragment packets.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param gso_size
+ *  The max length of a GSO segment, measured in bytes.
+ * @param ipid_delta
+ *  The increasing unit of IP ids.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when it succeeds. If the memory space in pkts_out is
+ *  insufficient, it fails and returns -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that 'pkts_out' can keep.
+ *
+ * @return
+ *   - The number of GSO segments filled in pkts_out on success.
+ *   - Return -ENOMEM if run out of memory in MBUF pools.
+ *   - Return -EINVAL for invalid parameters.
+ */
+int gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#endif
lib/librte_gso/rte_gso.c +4 -2
index a4fce50..6095689 100644
@@ -39,6 +39,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp4.h"
+#include "gso_tunnel_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -58,8 +59,9 @@
 		return -EINVAL;
 
 	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
-				DEV_TX_OFFLOAD_TCP_TSO) !=
-			gso_ctx->gso_types) {
+				(DEV_TX_OFFLOAD_TCP_TSO |
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
+				gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
 		return 1;

lib/librte_gso/rte_gso.c line 81

Quoted 10 lines
lib/librte_gso/rte_gso.c +6 -1
@@ -71,7 +73,12 @@
 	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_TCP(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else if (IS_IPV4_TCP(pkt->ol_flags)) {

Hmm it doesn't look quite right.
Imagine user doesn't want libgso to segment plain TCP packets with that ctx, just VXLAN+TCP.

Quoted 6 lines

I think you need to merge that if and one above to something like that:

If (IS_IPV4_VXLAN_TCP4(pkt->ol_flags))
&& (gso_ctx->gso_types & (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
DEV_TX_OFFLOAD_TCP_TSO)) ==
(DEV_TX_OFFLOAD_VXLAN_TNL_TSO | DEV_TX_OFFLOAD_TCP_TSO)) {

One question on this Konstantin - in the case of VxLAN, do we even need to check if DEV_TX_OFFLOAD_TCP_TSO is set in gso_ctx, since that pertains to plain TCP packets? If DEV_TX_OFFLOAD_VXLAN_TNL_TSO is set, then the inner protocol is probably irrelevant, since we'll segment regardless.

Bearing that in mind, I imagine that the above code block should look as follows, but I'm interested in your thoughts on same:

if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags))
&& (gso_ctx->gso_types & (DEV_TX_OFFLOAD_VXLAN_TNL_TSO) ==

   (DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
    ...
} else if (...

...

Thanks,
Mark

Quoted 15 lines

...
} else if (IS_IPV4_TCP(pkt->ol_flags) && (gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO)) {
...

} else {
    /* unsupported packet, skip */
}

Konstantin

Quoted 5 lines
lib/librte_gso/rte_gso.c +0 -1
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
--

1.9.3

#96 lore raw

Re: [PATCH v6 3/6] gso: add VxLAN GSO support

Quoted 405 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Wednesday, October 4, 2017 5:14 PM
To: Ananyev, Konstantin <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 3/6] gso: add VxLAN GSO support

Quoted 385 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 3:12 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 3/6] gso: add VxLAN GSO support

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>;

Ananyev, Konstantin <[email protected]>; Yigit,

Quoted 1 line

Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B

<[email protected]>

Quoted 20 lines

Subject: [PATCH v6 3/6] gso: add VxLAN GSO support

This patch adds a framework that allows GSO on tunneled packets. Furthermore, it leverages that framework to provide GSO support for VxLAN-encapsulated packets.

Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

VxLAN GSO doesn't check if input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize each output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSO'd segments are freed, the packet is freed automatically.

Quoted 7 lines
---
 doc/guides/rel_notes/release_17_11.rst |   3 +
 lib/librte_gso/Makefile                |   1 +
 lib/librte_gso/gso_common.h            |  25 +++++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 123

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

Review

Quoted 7 lines
 lib/librte_gso/gso_tunnel_tcp4.h       |  75 ++++++++++++++++++++
 lib/librte_gso/rte_gso.c               |  13 +++-
 6 files changed, 237 insertions(+), 3 deletions(-)
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
(quoted diff) +0 -0

b/doc/guides/rel_notes/release_17_11.rst

Quoted 38 lines

index c414f73..25b8a78 100644

doc/guides/rel_notes/release_17_11.rst +3 -0
@@ -48,6 +48,9 @@ New Features
   ones (e.g. MTU is 1500B). Supported packet types are:
 
   * TCP/IPv4 packets, which may include a single VLAN tag.
+  * VxLAN packets, which must have an outer IPv4 header (prepended by
+    an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
+    an optional VLAN tag).
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.h +1 -0
index 8d9b94e..c051295 100644
@@ -39,6 +39,7 @@
 #include <rte_mbuf.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
+#include <rte_udp.h>
 
 #define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
 		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)

lib/librte_gso/gso_common.h line 53

Quoted 4 lines
lib/librte_gso/gso_common.h +1 -0
@@ -49,6 +50,30 @@
 #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
 
+#define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 |

\

lib/librte_gso/gso_common.h

Quoted 7 lines
lib/librte_gso/gso_common.h +7 -0
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_VXLAN))
+
+/**
+ * Internal function which updates the UDP header of a packet, following
+ * segmentation. This is required to update the header's datagram length

field.

Review

Quoted 20 lines
lib/librte_gso/gso_common.h +16 -0
+ *
+ * @param pkt
+ *  The packet containing the UDP header.
+ * @param udp_offset
+ *  The offset of the UDP header from the start of the packet.
+ */
+static inline void
+update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset)
+{
+	struct udp_hdr *udp_hdr;
+
+	udp_hdr = (struct udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			udp_offset);
+	udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset);
+}
+
 /**
  * Internal function which updates the TCP header of a packet, following
  * segmentation. This is required to update the header's 'sent' sequence
(quoted diff) +0 -0

b/lib/librte_gso/gso_tunnel_tcp4.c

Quoted 101 lines

new file mode 100644
index 0000000..34bbbd7

lib/librte_gso/gso_tunnel_tcp4.c new file +96 -0
@@ -0,0 +1,123 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "gso_common.h"
+#include "gso_tunnel_tcp4.h"
+
+static void
+update_tunnel_ipv4_tcp_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	uint32_t sent_seq;
+	uint16_t outer_id, inner_id, tail_idx, i;
+	uint16_t outer_ipv4_offset, inner_ipv4_offset, udp_offset, tcp_offset;
+
+	outer_ipv4_offset = pkt->outer_l2_len;
+	udp_offset = outer_ipv4_offset + pkt->outer_l3_len;
+	inner_ipv4_offset = udp_offset + pkt->l2_len;
+	tcp_offset = inner_ipv4_offset + pkt->l3_len;
+
+	/* Outer IPv4 header. */
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			outer_ipv4_offset);
+	outer_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+
+	/* Inner IPv4 header. */
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			inner_ipv4_offset);
+	inner_id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+
+	tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+	tail_idx = nb_segs - 1;
+
+	for (i = 0; i < nb_segs; i++) {
+		update_ipv4_header(segs[i], outer_ipv4_offset, outer_id);
+		update_udp_header(segs[i], udp_offset);
+		update_ipv4_header(segs[i], inner_ipv4_offset, inner_id);
+		update_tcp_header(segs[i], tcp_offset, sent_seq, i < tail_idx);
+		outer_id++;
+		inner_id += ipid_delta;
+		sent_seq += (segs[i]->pkt_len - segs[i]->data_len);
+	}
+}
+
+int
+gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ipv4_hdr *inner_ipv4_hdr;
+	uint16_t pyld_unit_size, hdr_offset;
+	uint16_t tcp_dl, frag_off;
+	int ret = 1;
+
+	hdr_offset = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;
+	inner_ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			hdr_offset);
+	/*
+	 * Don't process the packet whose MF bit or offset in the inner
+	 * IPv4 header are non-zero.

lib/librte_gso/gso_tunnel_tcp4.c line 106

Quoted 10 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +10 -0
+	 */
+	frag_off = rte_be_to_cpu_16(inner_ipv4_hdr->fragment_offset);
+	if (unlikely(IS_FRAGMENTED(frag_off))) {
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	/* Don't process the packet without data */
+	tcp_dl = pkt->pkt_len - pkt->l2_len - pkt->l3_len - pkt->l4_len;
+	if (unlikely(tcp_dl == 0)) {

You probably need to take into account outer_len* too.. Probably better to move that check after final hdr_offset calculations:

...
hdr_offset += pkt->l3_len + pkt->l4_len;
if (hdr_offset >= pkt->pkt_len) {..;' return 1;}
...

Review

Quoted 18 lines
lib/librte_gso/gso_tunnel_tcp4.c new file +17 -0
+		pkts_out[0] = pkt;
+		return 1;
+	}
+
+	hdr_offset += pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset;
+
+	/* Segment the payload */
+	ret = gso_do_segment(pkt, hdr_offset, pyld_unit_size, direct_pool,
+			indirect_pool, pkts_out, nb_pkts_out);
+	if (ret <= 1)
+		return ret;
+
+	update_tunnel_ipv4_tcp_headers(pkt, ipid_delta, pkts_out, ret);
+
+	return ret;
+}
(quoted diff) +0 -0

b/lib/librte_gso/gso_tunnel_tcp4.h

Quoted 105 lines

new file mode 100644
index 0000000..3c67f0c

lib/librte_gso/gso_tunnel_tcp4.h new file +75 -0
@@ -0,0 +1,75 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
+ *
+ *   Redistribution and use in source and binary forms, with or without
+ *   modification, are permitted provided that the following conditions
+ *   are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of Intel Corporation nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _GSO_TUNNEL_TCP4_H_
+#define _GSO_TUNNEL_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment a tunneling packet with inner TCP/IPv4 headers. This function
+ * doesn't check if the input packet has correct checksums, and doesn't
+ * update checksums for output GSO segments. Furthermore, it doesn't
+ * process IP fragment packets.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param gso_size
+ *  The max length of a GSO segment, measured in bytes.
+ * @param ipid_delta
+ *  The increasing unit of IP ids.
+ * @param direct_pool
+ *  MBUF pool used for allocating direct buffers for output segments.
+ * @param indirect_pool
+ *  MBUF pool used for allocating indirect buffers for output segments.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when it succeeds. If the memory space in pkts_out is
+ *  insufficient, it fails and returns -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that 'pkts_out' can keep.
+ *
+ * @return
+ *   - The number of GSO segments filled in pkts_out on success.
+ *   - Return -ENOMEM if run out of memory in MBUF pools.
+ *   - Return -EINVAL for invalid parameters.
+ */
+int gso_tunnel_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		uint8_t ipid_delta,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+#endif
lib/librte_gso/rte_gso.c +4 -2
index a4fce50..6095689 100644
@@ -39,6 +39,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp4.h"
+#include "gso_tunnel_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -58,8 +59,9 @@
 		return -EINVAL;
 
 	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
-				DEV_TX_OFFLOAD_TCP_TSO) !=
-			gso_ctx->gso_types) {
+				(DEV_TX_OFFLOAD_TCP_TSO |
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
+				gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
 		return 1;

lib/librte_gso/rte_gso.c line 81

Quoted 10 lines
lib/librte_gso/rte_gso.c +6 -1
@@ -71,7 +73,12 @@
 	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_TCP(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else if (IS_IPV4_TCP(pkt->ol_flags)) {

Hmm it doesn't look quite right.
Imagine user doesn't want libgso to segment plain TCP packets with that ctx, just VXLAN+TCP.

Quoted 6 lines

I think you need to merge that if and one above to something like that:

If (IS_IPV4_VXLAN_TCP4(pkt->ol_flags))
&& (gso_ctx->gso_types & (DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
DEV_TX_OFFLOAD_TCP_TSO)) ==
(DEV_TX_OFFLOAD_VXLAN_TNL_TSO | DEV_TX_OFFLOAD_TCP_TSO)) {

One question on this Konstantin - in the case of VxLAN, do we even need to check if DEV_TX_OFFLOAD_TCP_TSO is set in gso_ctx, since that pertains to plain TCP packets?
If DEV_TX_OFFLOAD_VXLAN_TNL_TSO is set, then the inner protocol is probably irrelevant, since we'll segment regardless.

Quoted 8 lines

Bearing that in mind, I imagine that the above code block should look as follows, but I'm interested in your thoughts on same:

if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags))
&& (gso_ctx->gso_types & (DEV_TX_OFFLOAD_VXLAN_TNL_TSO) ==

   (DEV_TX_OFFLOAD_VXLAN_TNL_TSO) {
    ...
} else if (...

...

Yes, I think you are right.
Thanks
Konstantin

Quoted 19 lines

Thanks,
Mark

Quoted 15 lines

...
} else if (IS_IPV4_TCP(pkt->ol_flags) && (gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO)) {
...

} else {
    /* unsupported packet, skip */
}

Konstantin

Quoted 5 lines
lib/librte_gso/rte_gso.c +0 -1
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
--

1.9.3

#97 lore raw

PATCH v6 4/6 gso: add GRE GSO support

In reply to Mark Kavanagh

This patch adds GSO support for GRE-tunneled packets. Supported GRE packets must contain an outer IPv4 header, and inner TCP/IPv4 headers. They may also contain a single VLAN tag. GRE GSO doesn't check if all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with VxLAN GSO, GRE GSO uses a two-segment MBUF to organize each output packet, which requires multi-segment mbuf support in the TX functions of the NIC driver. Also, if a packet is GSOed, GRE GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst |  3 +++
 lib/librte_gso/gso_common.h            |  5 +++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 14 ++++++++++----
 lib/librte_gso/rte_gso.c               |  8 +++++---
 4 files changed, 23 insertions(+), 7 deletions(-)
doc/guides/rel_notes/release_17_11.rst +3 -0
index 25b8a78..808f537 100644
@@ -51,6 +51,9 @@ New Features
   * VxLAN packets, which must have an outer IPv4 header (prepended by
     an optional VLAN tag), and contain an inner TCP/IPv4 packet (with
     an optional VLAN tag).
+  * GRE packets, which must contain an outer IPv4 header (prepended by
+    an optional VLAN tag), and inner TCP/IPv4 headers (with an optional
+    VLAN tag).
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/gso_common.h +5 -0
index c051295..1e99cc0 100644
@@ -55,6 +55,11 @@
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
 		 PKT_TX_TUNNEL_VXLAN))
 
+#define IS_IPV4_GRE_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_GRE)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_GRE))
+
 /**
  * Internal function which updates the UDP header of a packet, following
  * segmentation. This is required to update the header's datagram length field.
lib/librte_gso/gso_tunnel_tcp4.c +10 -4
index 34bbbd7..d79fc6b 100644
@@ -42,11 +42,13 @@
 	struct tcp_hdr *tcp_hdr;
 	uint32_t sent_seq;
 	uint16_t outer_id, inner_id, tail_idx, i;
-	uint16_t outer_ipv4_offset, inner_ipv4_offset, udp_offset, tcp_offset;
+	uint16_t outer_ipv4_offset, inner_ipv4_offset;
+	uint16_t udp_gre_offset, tcp_offset;
+	uint8_t update_udp_hdr;
 
 	outer_ipv4_offset = pkt->outer_l2_len;
-	udp_offset = outer_ipv4_offset + pkt->outer_l3_len;
-	inner_ipv4_offset = udp_offset + pkt->l2_len;
+	udp_gre_offset = outer_ipv4_offset + pkt->outer_l3_len;
+	inner_ipv4_offset = udp_gre_offset + pkt->l2_len;
 	tcp_offset = inner_ipv4_offset + pkt->l3_len;
 
 	/* Outer IPv4 header. */
@@ -63,9 +65,13 @@
 	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
 	tail_idx = nb_segs - 1;
 
+	/* Only update UDP header for VxLAN packets. */
+	update_udp_hdr = (pkt->ol_flags & PKT_TX_TUNNEL_VXLAN) ? 1 : 0;
+
 	for (i = 0; i < nb_segs; i++) {
 		update_ipv4_header(segs[i], outer_ipv4_offset, outer_id);
-		update_udp_header(segs[i], udp_offset);
+		if (update_udp_hdr)
+			update_udp_header(segs[i], udp_gre_offset);
 		update_ipv4_header(segs[i], inner_ipv4_offset, inner_id);
 		update_tcp_header(segs[i], tcp_offset, sent_seq, i < tail_idx);
 		outer_id++;
lib/librte_gso/rte_gso.c +5 -3
index 6095689..b748ab1 100644
@@ -60,8 +60,9 @@
 
 	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
 				(DEV_TX_OFFLOAD_TCP_TSO |
-				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
-				gso_ctx->gso_types) {
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+				 DEV_TX_OFFLOAD_GRE_TNL_TSO)) !=
+				 gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
 		return 1;
@@ -73,7 +74,8 @@
 	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags) ||
+			IS_IPV4_GRE_TCP4(pkt->ol_flags)) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
Signature · 1 line
1.9.3
#98 lore raw

Re: [PATCH v6 4/6] gso: add GRE GSO support

Quoted 18 lines
lib/librte_gso/rte_gso.c +3 -2
index 6095689..b748ab1 100644
@@ -60,8 +60,9 @@
 
 	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
 				(DEV_TX_OFFLOAD_TCP_TSO |
-				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
-				gso_ctx->gso_types) {
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+				 DEV_TX_OFFLOAD_GRE_TNL_TSO)) !=
+				 gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
 		return 1;

lib/librte_gso/rte_gso.c line 78

Quoted 6 lines
lib/librte_gso/rte_gso.c +2 -1
@@ -73,7 +74,8 @@
 	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags) ||
+			IS_IPV4_GRE_TCP4(pkt->ol_flags)) {

Same comment as for previous patch: user might want that ctx to Segment vxlan packets and not segment gro packets. Konstantin

Quoted 5 lines
lib/librte_gso/rte_gso.c +0 -1
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
--

1.9.3

#99 lore raw

Re: [PATCH v6 4/6] gso: add GRE GSO support

Quoted 31 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 3:16 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 4/6] gso: add GRE GSO support

Quoted 20 lines
lib/librte_gso/rte_gso.c +3 -2
index 6095689..b748ab1 100644
@@ -60,8 +60,9 @@
 
 	if ((gso_ctx->gso_size >= pkt->pkt_len) || (gso_ctx->gso_types &
 				(DEV_TX_OFFLOAD_TCP_TSO |
-				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
-				gso_ctx->gso_types) {
+				 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+				 DEV_TX_OFFLOAD_GRE_TNL_TSO)) !=
+				 gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
 		return 1;
@@ -73,7 +74,8 @@
 	ipid_delta = (gso_ctx->ipid_flag != RTE_GSO_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
Quoted 7 lines

lib/librte_gso/rte_gso.c line 78

Quoted 3 lines
lib/librte_gso/rte_gso.c +2 -1
-	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags) ||
+			IS_IPV4_GRE_TCP4(pkt->ol_flags)) {

Same comment as for previous patch: user might want that ctx to Segment vxlan packets and not segment gro packets. Konstantin

Thanks Konstantin - I'll update appropriately.

Quoted 6 lines
Quoted 6 lines
lib/librte_gso/rte_gso.c +0 -1
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
--

1.9.3

#100 lore raw

PATCH v6 5/6 app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

In reply to Mark Kavanagh

From: Jiayu Hu <[email protected]>

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

---
 app/test-pmd/cmdline.c                      | 178 ++++++++++++++++++++++++++++
 app/test-pmd/config.c                       |  24 ++++
 app/test-pmd/csumonly.c                     |  69 ++++++++++-
 app/test-pmd/testpmd.c                      |  13 ++
 app/test-pmd/testpmd.h                      |  10 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  46 +++++++
 6 files changed, 335 insertions(+), 5 deletions(-)
app/test-pmd/cmdline.c +178 -0
index ccdf239..05b0ce8 100644
@@ -431,6 +431,17 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"    Set max flow number and max packet number per-flow"
 			" for GRO.\n\n"
 
+			"set port (port_id) gso (on|off)"
+			"    Enable or disable Generic Segmentation Offload in"
+			" csum forwarding engine.\n\n"
+
+			"set gso segsz (length)\n"
+			"    Set max packet length for output GSO segments,"
+			" including packet header and payload.\n\n"
+
+			"show port (port_id) gso\n"
+			"    Show GSO configuration.\n\n"
+
 			"set fwd (%s)\n"
 			"    Set packet forwarding mode.\n\n"
 
@@ -3967,6 +3978,170 @@ struct cmd_gro_set_result {
 	},
 };
 
+/* *** ENABLE/DISABLE GSO *** */
+struct cmd_gso_enable_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_mode;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_enable_parsed(void *parsed_result,
+		__attribute__((unused)) struct cmdline *cl,
+		__attribute__((unused)) void *data)
+{
+	struct cmd_gso_enable_result *res;
+
+	res = parsed_result;
+	if (!strcmp(res->cmd_keyword, "gso"))
+		setup_gso(res->cmd_mode, res->cmd_pid);
+}
+
+cmdline_parse_token_string_t cmd_gso_enable_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_enable_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_enable_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_enable_mode =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_mode, "on#off");
+cmdline_parse_token_num_t cmd_gso_enable_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_enable = {
+	.f = cmd_gso_enable_parsed,
+	.data = NULL,
+	.help_str = "set port <port_id> gso on|off",
+	.tokens = {
+		(void *)&cmd_gso_enable_set,
+		(void *)&cmd_gso_enable_port,
+		(void *)&cmd_gso_enable_pid,
+		(void *)&cmd_gso_enable_keyword,
+		(void *)&cmd_gso_enable_mode,
+		NULL,
+	},
+};
+
+/* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
+struct cmd_gso_size_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_segsz;
+	uint16_t cmd_size;
+};
+
+static void
+cmd_gso_size_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_size_result *res = parsed_result;
+
+	if (test_done == 0) {
+		printf("Before setting GSO segsz, please first stop fowarding\n");
+		return;
+	}
+
+	if (!strcmp(res->cmd_keyword, "gso") &&
+			!strcmp(res->cmd_segsz, "segsz")) {
+		if (res->cmd_size == 0) {
+			printf("gso_size should be larger than 0."
+					" Please input a legal value\n");
+		} else
+			gso_max_segment_size = res->cmd_size;
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_size_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_size_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_size_segsz =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_segsz, "segsz");
+cmdline_parse_token_num_t cmd_gso_size_size =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
+				cmd_size, UINT16);
+
+cmdline_parse_inst_t cmd_gso_size = {
+	.f = cmd_gso_size_parsed,
+	.data = NULL,
+	.help_str = "set gso segsz <length>",
+	.tokens = {
+		(void *)&cmd_gso_size_set,
+		(void *)&cmd_gso_size_keyword,
+		(void *)&cmd_gso_size_segsz,
+		(void *)&cmd_gso_size_size,
+		NULL,
+	},
+};
+
+/* *** SHOW GSO CONFIGURATION *** */
+struct cmd_gso_show_result {
+	cmdline_fixed_string_t cmd_show;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_show_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_show_result *res = parsed_result;
+
+	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
+		printf("invalid port id %u\n", res->cmd_pid);
+		return;
+	}
+	if (!strcmp(res->cmd_keyword, "gso")) {
+		if (gso_ports[res->cmd_pid].enable) {
+			printf("Max GSO'd packet size: %uB\n"
+					"Supported GSO types: TCP/IPv4, "
+					"VxLAN with inner TCP/IPv4 packet, "
+					"GRE with inner TCP/IPv4  packet\n",
+					gso_max_segment_size);
+		} else
+			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_show_show =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_show, "show");
+cmdline_parse_token_string_t cmd_gso_show_port =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_show_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_num_t cmd_gso_show_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
+				cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_show = {
+	.f = cmd_gso_show_parsed,
+	.data = NULL,
+	.help_str = "show port <port_id> gso",
+	.tokens = {
+		(void *)&cmd_gso_show_show,
+		(void *)&cmd_gso_show_port,
+		(void *)&cmd_gso_show_pid,
+		(void *)&cmd_gso_show_keyword,
+		NULL,
+	},
+};
+
 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
 struct cmd_set_flush_rx {
 	cmdline_fixed_string_t set;
@@ -14255,6 +14430,9 @@ struct cmd_cmdfile_result {
 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
 	(cmdline_parse_inst_t *)&cmd_enable_gro,
 	(cmdline_parse_inst_t *)&cmd_gro_set,
+	(cmdline_parse_inst_t *)&cmd_gso_enable,
+	(cmdline_parse_inst_t *)&cmd_gso_size,
+	(cmdline_parse_inst_t *)&cmd_gso_show,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
app/test-pmd/config.c +24 -0
index 3ae3e1c..88d09d0 100644
@@ -2454,6 +2454,30 @@ struct igb_ring_desc_16_bytes {
 	}
 }
 
+void
+setup_gso(const char *mode, uint8_t port_id)
+{
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		printf("invalid port id %u\n", port_id);
+		return;
+	}
+	if (strcmp(mode, "on") == 0) {
+		if (test_done == 0) {
+			printf("before enabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 1;
+	} else if (strcmp(mode, "off") == 0) {
+		if (test_done == 0) {
+			printf("before disabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 0;
+	}
+}
+
 char*
 list_pkt_forwarding_modes(void)
 {
app/test-pmd/csumonly.c +64 -5

136 lines not on this page · raw message

app/test-pmd/testpmd.c +13 -0
index e097ee0..97e349d 100644
@@ -400,6 +400,9 @@ static int eth_event_callback(uint8_t port_id,
  */
 static int all_ports_started(void);
 
+struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
+
 /*
  * Helper function to check if socket is already discovered.
  * If yes, return positive value. If not, return zero.
@@ -570,6 +573,7 @@ static int eth_event_callback(uint8_t port_id,
 	unsigned int nb_mbuf_per_pool;
 	lcoreid_t  lc_id;
 	uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
+	uint32_t gso_types = 0;
 
 	memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
 
@@ -654,6 +658,8 @@ static int eth_event_callback(uint8_t port_id,
 
 	init_port_config();
 
+	gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+		DEV_TX_OFFLOAD_GRE_TNL_TSO;
 	/*
 	 * Records which Mbuf pool to use by each logical core, if needed.
 	 */
@@ -664,6 +670,13 @@ static int eth_event_callback(uint8_t port_id,
 		if (mbp == NULL)
 			mbp = mbuf_pool_find(0);
 		fwd_lcores[lc_id]->mbp = mbp;
+		/* initialize GSO context */
+		fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
+		fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
+			ETHER_CRC_LEN;
+		fwd_lcores[lc_id]->gso_ctx.ipid_flag = !RTE_GSO_IPID_FIXED;
 	}
 
 	/* Configuration of packet forwarding streams. */
app/test-pmd/testpmd.h +10 -0
index 1d1ee75..ff842a1 100644
@@ -36,6 +36,7 @@
 
 #include <rte_pci.h>
 #include <rte_gro.h>
+#include <rte_gso.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -205,6 +206,7 @@ struct rte_port {
  * CPU id. configuration table.
  */
 struct fwd_lcore {
+	struct rte_gso_ctx gso_ctx;     /**< GSO context */
 	struct rte_mempool *mbp; /**< The mbuf pool to use by this core */
 	streamid_t stream_idx;   /**< index of 1st stream in "fwd_streams" */
 	streamid_t stream_nb;    /**< number of streams in "fwd_streams" */
@@ -442,6 +444,13 @@ struct gro_status {
 };
 extern struct gro_status gro_ports[RTE_MAX_ETHPORTS];
 
+#define GSO_MAX_PKT_BURST 2048
+struct gso_status {
+	uint8_t enable;
+};
+extern struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+extern uint16_t gso_max_segment_size;
+
 static inline unsigned int
 lcore_num(void)
 {
@@ -642,6 +651,7 @@ void port_rss_hash_key_update(portid_t port_id, char rss_type[],
 int rx_queue_id_is_invalid(queueid_t rxq_id);
 int tx_queue_id_is_invalid(queueid_t txq_id);
 void setup_gro(const char *mode, uint8_t port_id);
+void setup_gso(const char *mode, uint8_t port_id);
 
 /* Functions to manage the set of filtered Multicast MAC addresses */
 void mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr);
doc/guides/testpmd_app_ug/testpmd_funcs.rst +46 -0

52 lines not on this page · raw message

Signature · 1 line
1.9.3
#101 lore raw

Re: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 46 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Ananyev, Konstantin <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B <[email protected]>
Subject: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

From: Jiayu Hu <[email protected]>

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

---
 app/test-pmd/cmdline.c                      | 178 ++++++++++++++++++++++++++++
 app/test-pmd/config.c                       |  24 ++++
 app/test-pmd/csumonly.c                     |  69 ++++++++++-
 app/test-pmd/testpmd.c                      |  13 ++
 app/test-pmd/testpmd.h                      |  10 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  46 +++++++
 6 files changed, 335 insertions(+), 5 deletions(-)
app/test-pmd/cmdline.c +0 -0
index ccdf239..05b0ce8 100644

app/test-pmd/cmdline.c static void cmd_help_long_parsed(void *parsed_result, · line 440

Quoted 10 lines
app/test-pmd/cmdline.c +7 -0
@@ -431,6 +431,17 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"    Set max flow number and max packet number per-flow"
 			" for GRO.\n\n"
 
+			"set port (port_id) gso (on|off)"
+			"    Enable or disable Generic Segmentation Offload in"
+			" csum forwarding engine.\n\n"
+
+			"set gso segsz (length)\n"
+			"    Set max packet length for output GSO segments,"
+			" including packet header and payload.\n\n"

Probably a good future improvement would be to allow user to specify gso_type too.

Quoted 75 lines
app/test-pmd/cmdline.c +68 -0
+
+			"show port (port_id) gso\n"
+			"    Show GSO configuration.\n\n"
+
 			"set fwd (%s)\n"
 			"    Set packet forwarding mode.\n\n"
 
@@ -3967,6 +3978,170 @@ struct cmd_gro_set_result {
 	},
 };
 
+/* *** ENABLE/DISABLE GSO *** */
+struct cmd_gso_enable_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_mode;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_enable_parsed(void *parsed_result,
+		__attribute__((unused)) struct cmdline *cl,
+		__attribute__((unused)) void *data)
+{
+	struct cmd_gso_enable_result *res;
+
+	res = parsed_result;
+	if (!strcmp(res->cmd_keyword, "gso"))
+		setup_gso(res->cmd_mode, res->cmd_pid);
+}
+
+cmdline_parse_token_string_t cmd_gso_enable_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_enable_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_enable_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_enable_mode =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_mode, "on#off");
+cmdline_parse_token_num_t cmd_gso_enable_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_enable = {
+	.f = cmd_gso_enable_parsed,
+	.data = NULL,
+	.help_str = "set port <port_id> gso on|off",
+	.tokens = {
+		(void *)&cmd_gso_enable_set,
+		(void *)&cmd_gso_enable_port,
+		(void *)&cmd_gso_enable_pid,
+		(void *)&cmd_gso_enable_keyword,
+		(void *)&cmd_gso_enable_mode,
+		NULL,
+	},
+};
+
+/* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
+struct cmd_gso_size_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_segsz;
+	uint16_t cmd_size;
+};
+
+static void
+cmd_gso_size_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{

app/test-pmd/cmdline.c struct cmd_gro_set_result { · line 4054

Quoted 10 lines
app/test-pmd/cmdline.c +10 -0
+	struct cmd_gso_size_result *res = parsed_result;
+
+	if (test_done == 0) {
+		printf("Before setting GSO segsz, please first stop fowarding\n");
+		return;
+	}
+
+	if (!strcmp(res->cmd_keyword, "gso") &&
+			!strcmp(res->cmd_segsz, "segsz")) {
+		if (res->cmd_size == 0) {

As your gso_size includes packet header too, you probably shouldn't allow gso_size less then some minimal value of l2_len + l3_len + l4_len + ...
Another alternative change gso_ctx.gso_size to count only payload size.

Quoted 205 lines
app/test-pmd/cmdline.c +93 -0
+			printf("gso_size should be larger than 0."
+					" Please input a legal value\n");
+		} else
+			gso_max_segment_size = res->cmd_size;
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_size_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_size_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_size_segsz =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_segsz, "segsz");
+cmdline_parse_token_num_t cmd_gso_size_size =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
+				cmd_size, UINT16);
+
+cmdline_parse_inst_t cmd_gso_size = {
+	.f = cmd_gso_size_parsed,
+	.data = NULL,
+	.help_str = "set gso segsz <length>",
+	.tokens = {
+		(void *)&cmd_gso_size_set,
+		(void *)&cmd_gso_size_keyword,
+		(void *)&cmd_gso_size_segsz,
+		(void *)&cmd_gso_size_size,
+		NULL,
+	},
+};
+
+/* *** SHOW GSO CONFIGURATION *** */
+struct cmd_gso_show_result {
+	cmdline_fixed_string_t cmd_show;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_show_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_show_result *res = parsed_result;
+
+	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
+		printf("invalid port id %u\n", res->cmd_pid);
+		return;
+	}
+	if (!strcmp(res->cmd_keyword, "gso")) {
+		if (gso_ports[res->cmd_pid].enable) {
+			printf("Max GSO'd packet size: %uB\n"
+					"Supported GSO types: TCP/IPv4, "
+					"VxLAN with inner TCP/IPv4 packet, "
+					"GRE with inner TCP/IPv4  packet\n",
+					gso_max_segment_size);
+		} else
+			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_show_show =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_show, "show");
+cmdline_parse_token_string_t cmd_gso_show_port =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_show_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_num_t cmd_gso_show_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
+				cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_show = {
+	.f = cmd_gso_show_parsed,
+	.data = NULL,
+	.help_str = "show port <port_id> gso",
+	.tokens = {
+		(void *)&cmd_gso_show_show,
+		(void *)&cmd_gso_show_port,
+		(void *)&cmd_gso_show_pid,
+		(void *)&cmd_gso_show_keyword,
+		NULL,
+	},
+};
+
 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
 struct cmd_set_flush_rx {
 	cmdline_fixed_string_t set;
@@ -14255,6 +14430,9 @@ struct cmd_cmdfile_result {
 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
 	(cmdline_parse_inst_t *)&cmd_enable_gro,
 	(cmdline_parse_inst_t *)&cmd_gro_set,
+	(cmdline_parse_inst_t *)&cmd_gso_enable,
+	(cmdline_parse_inst_t *)&cmd_gso_size,
+	(cmdline_parse_inst_t *)&cmd_gso_show,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
app/test-pmd/config.c +24 -0
index 3ae3e1c..88d09d0 100644
@@ -2454,6 +2454,30 @@ struct igb_ring_desc_16_bytes {
 	}
 }
 
+void
+setup_gso(const char *mode, uint8_t port_id)
+{
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		printf("invalid port id %u\n", port_id);
+		return;
+	}
+	if (strcmp(mode, "on") == 0) {
+		if (test_done == 0) {
+			printf("before enabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 1;
+	} else if (strcmp(mode, "off") == 0) {
+		if (test_done == 0) {
+			printf("before disabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 0;
+	}
+}
+
 char*
 list_pkt_forwarding_modes(void)
 {
app/test-pmd/csumonly.c +13 -1
index 90c8119..bd1a287 100644
@@ -70,6 +70,8 @@
 #include <rte_string_fns.h>
 #include <rte_flow.h>
 #include <rte_gro.h>
+#include <rte_gso.h>
+
 #include "testpmd.h"
 
 #define IP_DEFTTL  64   /* from RFC 1340. */
@@ -91,6 +93,7 @@
 /* structure that caches offload info for the current packet */
 struct testpmd_offload_info {
 	uint16_t ethertype;
+	uint8_t gso_enable;
 	uint16_t l2_len;
 	uint16_t l3_len;
 	uint16_t l4_len;
@@ -381,6 +384,8 @@ struct simple_gre_hdr {
 				get_udptcp_checksum(l3_hdr, tcp_hdr,
 					info->ethertype);
 		}
+		if (info->gso_enable)
+			ol_flags |= PKT_TX_TCP_SEG;
 	} else if (info->l4_proto == IPPROTO_SCTP) {
 		sctp_hdr = (struct sctp_hdr *)((char *)l3_hdr + info->l3_len);
 		sctp_hdr->cksum = 0;
@@ -627,6 +632,9 @@ struct simple_gre_hdr {
 pkt_burst_checksum_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
+	struct rte_mbuf *gso_segments[GSO_MAX_PKT_BURST];
+	struct rte_gso_ctx *gso_ctx;
+	struct rte_mbuf **tx_pkts_burst;
 	struct rte_port *txp;
 	struct rte_mbuf *m, *p;
 	struct ether_hdr *eth_hdr;
@@ -634,13 +642,15 @@ struct simple_gre_hdr {
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint16_t nb_prep;
-	uint16_t i;
+	uint16_t i, j;
 	uint64_t rx_ol_flags, tx_ol_flags;
 	uint16_t testpmd_ol_flags;
 	uint32_t retry;
 	uint32_t rx_bad_ip_csum;
 	uint32_t rx_bad_l4_csum;
 	struct testpmd_offload_info info;
+	uint16_t nb_segments = 0;
+	int ret;
 
 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
 	uint64_t start_tsc;
@@ -674,6 +684,8 @@ struct simple_gre_hdr {
 	memset(&info, 0, sizeof(info));
 	info.tso_segsz = txp->tso_segsz;
 	info.tunnel_tso_segsz = txp->tunnel_tso_segsz;
+	if (gso_ports[fs->tx_port].enable)
+		info.gso_enable = 1;
 
 	for (i = 0; i < nb_rx; i++) {
 		if (likely(i < nb_rx - 1))

app/test-pmd/csumonly.c struct simple_gre_hdr { · line 871

Quoted 9 lines
app/test-pmd/csumonly.c +6 -0
@@ -851,13 +863,59 @@ struct simple_gre_hdr {
 		}
 	}
 
+	if (gso_ports[fs->tx_port].enable == 0)
+		tx_pkts_burst = pkts_burst;
+	else {
+		gso_ctx = &(current_fwd_lcore()->gso_ctx);
+		gso_ctx->gso_size = gso_max_segment_size;
+		for (i = 0; i < nb_rx; i++) {

It seems quite a lot of code to handle an error case, which I suppose will happen pretty rare.
Why not just:

ret = rte_gso_segment(pkts_burst[i], gso_ctx,

					&gso_segments[nb_segments],
					RTE_DIM(gso_segments) - nb_segments);
If (ret < 0)  {
    RTE_LOG(DEBUG, ....);
     rte_free(pkts_burst[i]);
} else

nb_segments += ret;

Quoted 105 lines
app/test-pmd/csumonly.c +45 -4
+			if (unlikely(nb_rx - i >= GSO_MAX_PKT_BURST -
+						nb_segments)) {
+				/*
+				 * insufficient space in gso_segments,
+				 * stop GSO.
+				 */
+				for (j = i; j < GSO_MAX_PKT_BURST -
+						nb_segments; j++) {
+					pkts_burst[j]->ol_flags &=
+						(~PKT_TX_TCP_SEG);
+					gso_segments[nb_segments++] =
+						pkts_burst[j];
+				}
+				for (; j < nb_rx; j++)
+					rte_pktmbuf_free(pkts_burst[j]);
+				break;
+			}
+			ret = rte_gso_segment(pkts_burst[i], gso_ctx,
+					&gso_segments[nb_segments],
+					GSO_MAX_PKT_BURST - nb_segments);
+			if (ret >= 1)
+				nb_segments += ret;
+			else if (ret < 0) {
+				/*
+				 * insufficient MBUFs or space in
+				 * gso_segments, stop GSO.
+				 */
+				for (j = i; j < nb_rx; j++) {
+					pkts_burst[j]->ol_flags &=
+						(~PKT_TX_TCP_SEG);
+					gso_segments[nb_segments++] =
+						pkts_burst[j];
+				}
+				break;
+			}
+		}
+		tx_pkts_burst = gso_segments;
+		nb_rx = nb_segments;
+	}
+
 	nb_prep = rte_eth_tx_prepare(fs->tx_port, fs->tx_queue,
-			pkts_burst, nb_rx);
+			tx_pkts_burst, nb_rx);
 	if (nb_prep != nb_rx)
 		printf("Preparing packet burst to transmit failed: %s\n",
 				rte_strerror(rte_errno));
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst,
+	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, tx_pkts_burst,
 			nb_prep);
 
 	/*
@@ -868,7 +926,7 @@ struct simple_gre_hdr {
 		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
 			rte_delay_us(burst_tx_delay_time);
 			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
+					&tx_pkts_burst[nb_tx], nb_rx - nb_tx);
 		}
 	}
 	fs->tx_packets += nb_tx;
@@ -881,9 +939,10 @@ struct simple_gre_hdr {
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
 		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
+			rte_pktmbuf_free(tx_pkts_burst[nb_tx]);
 		} while (++nb_tx < nb_rx);
 	}
+
 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
 	end_tsc = rte_rdtsc();
 	core_cycles = (end_tsc - start_tsc);
app/test-pmd/testpmd.c +6 -0
index e097ee0..97e349d 100644
@@ -400,6 +400,9 @@ static int eth_event_callback(uint8_t port_id,
  */
 static int all_ports_started(void);
 
+struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
+
 /*
  * Helper function to check if socket is already discovered.
  * If yes, return positive value. If not, return zero.
@@ -570,6 +573,7 @@ static int eth_event_callback(uint8_t port_id,
 	unsigned int nb_mbuf_per_pool;
 	lcoreid_t  lc_id;
 	uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
+	uint32_t gso_types = 0;
 
 	memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
 
@@ -654,6 +658,8 @@ static int eth_event_callback(uint8_t port_id,
 
 	init_port_config();
 
+	gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+		DEV_TX_OFFLOAD_GRE_TNL_TSO;
 	/*
 	 * Records which Mbuf pool to use by each logical core, if needed.
 	 */

app/test-pmd/testpmd.c static int eth_event_callback(uint8_t port_id, · line 679

Quoted 10 lines
app/test-pmd/testpmd.c +7 -0
@@ -664,6 +670,13 @@ static int eth_event_callback(uint8_t port_id,
 		if (mbp == NULL)
 			mbp = mbuf_pool_find(0);
 		fwd_lcores[lc_id]->mbp = mbp;
+		/* initialize GSO context */
+		fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
+		fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
+			ETHER_CRC_LEN;
+		fwd_lcores[lc_id]->gso_ctx.ipid_flag = !RTE_GSO_IPID_FIXED;

Just
fwd_lcores[lc_id]->gso_ctx.ipid_flag = 0;
should do here.

Konstantin

#102 lore raw

Re: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 62 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 4:09 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>;

Ananyev, Konstantin <[email protected]>; Yigit,

Quoted 1 line

Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B

<[email protected]>

Quoted 18 lines

Subject: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

From: Jiayu Hu <[email protected]>

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Quoted 8 lines

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

---
 app/test-pmd/cmdline.c                      | 178

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

Quoted 15 lines
 app/test-pmd/config.c                       |  24 ++++
 app/test-pmd/csumonly.c                     |  69 ++++++++++-
 app/test-pmd/testpmd.c                      |  13 ++
 app/test-pmd/testpmd.h                      |  10 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  46 +++++++
 6 files changed, 335 insertions(+), 5 deletions(-)
app/test-pmd/cmdline.c +0 -0
index ccdf239..05b0ce8 100644
@@ -431,6 +431,17 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"    Set max flow number and max packet number per-flow"
 			" for GRO.\n\n"
 
Quoted 10 lines

app/test-pmd/cmdline.c static void cmd_help_long_parsed(void *parsed_result, · line 440

Quoted 7 lines
app/test-pmd/cmdline.c +7 -0
+			"set port (port_id) gso (on|off)"
+			"    Enable or disable Generic Segmentation Offload in"
+			" csum forwarding engine.\n\n"
+
+			"set gso segsz (length)\n"
+			"    Set max packet length for output GSO segments,"
+			" including packet header and payload.\n\n"

Probably a good future improvement would be to allow user to specify gso_type too.

Would you like to see that change implemented in time for the 17.11 release?

Quoted 83 lines
Quoted 83 lines
app/test-pmd/cmdline.c +75 -0
+
+			"show port (port_id) gso\n"
+			"    Show GSO configuration.\n\n"
+
 			"set fwd (%s)\n"
 			"    Set packet forwarding mode.\n\n"
 
@@ -3967,6 +3978,170 @@ struct cmd_gro_set_result {
 	},
 };
 
+/* *** ENABLE/DISABLE GSO *** */
+struct cmd_gso_enable_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_mode;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_enable_parsed(void *parsed_result,
+		__attribute__((unused)) struct cmdline *cl,
+		__attribute__((unused)) void *data)
+{
+	struct cmd_gso_enable_result *res;
+
+	res = parsed_result;
+	if (!strcmp(res->cmd_keyword, "gso"))
+		setup_gso(res->cmd_mode, res->cmd_pid);
+}
+
+cmdline_parse_token_string_t cmd_gso_enable_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_enable_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_enable_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_enable_mode =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_mode, "on#off");
+cmdline_parse_token_num_t cmd_gso_enable_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_enable = {
+	.f = cmd_gso_enable_parsed,
+	.data = NULL,
+	.help_str = "set port <port_id> gso on|off",
+	.tokens = {
+		(void *)&cmd_gso_enable_set,
+		(void *)&cmd_gso_enable_port,
+		(void *)&cmd_gso_enable_pid,
+		(void *)&cmd_gso_enable_keyword,
+		(void *)&cmd_gso_enable_mode,
+		NULL,
+	},
+};
+
+/* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
+struct cmd_gso_size_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_segsz;
+	uint16_t cmd_size;
+};
+
+static void
+cmd_gso_size_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_size_result *res = parsed_result;
+
+	if (test_done == 0) {
+		printf("Before setting GSO segsz, please first stop fowarding\n");
+		return;
+	}
+
Quoted 8 lines

app/test-pmd/cmdline.c struct cmd_gro_set_result { · line 4054

Quoted 3 lines
app/test-pmd/cmdline.c +3 -0
+	if (!strcmp(res->cmd_keyword, "gso") &&
+			!strcmp(res->cmd_segsz, "segsz")) {
+		if (res->cmd_size == 0) {

As your gso_size includes packet header too, you probably shouldn't allow gso_size less
then some minimal value of l2_len + l3_len + l4_len + ... Another alternative change gso_ctx.gso_size to count only payload size.

Okay - I'll take a look at this, thanks.

Quoted 220 lines
Quoted 206 lines
app/test-pmd/cmdline.c +93 -0
+			printf("gso_size should be larger than 0."
+					" Please input a legal value\n");
+		} else
+			gso_max_segment_size = res->cmd_size;
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_size_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_size_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_size_segsz =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_segsz, "segsz");
+cmdline_parse_token_num_t cmd_gso_size_size =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
+				cmd_size, UINT16);
+
+cmdline_parse_inst_t cmd_gso_size = {
+	.f = cmd_gso_size_parsed,
+	.data = NULL,
+	.help_str = "set gso segsz <length>",
+	.tokens = {
+		(void *)&cmd_gso_size_set,
+		(void *)&cmd_gso_size_keyword,
+		(void *)&cmd_gso_size_segsz,
+		(void *)&cmd_gso_size_size,
+		NULL,
+	},
+};
+
+/* *** SHOW GSO CONFIGURATION *** */
+struct cmd_gso_show_result {
+	cmdline_fixed_string_t cmd_show;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_show_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_show_result *res = parsed_result;
+
+	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
+		printf("invalid port id %u\n", res->cmd_pid);
+		return;
+	}
+	if (!strcmp(res->cmd_keyword, "gso")) {
+		if (gso_ports[res->cmd_pid].enable) {
+			printf("Max GSO'd packet size: %uB\n"
+					"Supported GSO types: TCP/IPv4, "
+					"VxLAN with inner TCP/IPv4 packet, "
+					"GRE with inner TCP/IPv4  packet\n",
+					gso_max_segment_size);
+		} else
+			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_show_show =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_show, "show");
+cmdline_parse_token_string_t cmd_gso_show_port =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_show_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_num_t cmd_gso_show_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
+				cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_show = {
+	.f = cmd_gso_show_parsed,
+	.data = NULL,
+	.help_str = "show port <port_id> gso",
+	.tokens = {
+		(void *)&cmd_gso_show_show,
+		(void *)&cmd_gso_show_port,
+		(void *)&cmd_gso_show_pid,
+		(void *)&cmd_gso_show_keyword,
+		NULL,
+	},
+};
+
 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
 struct cmd_set_flush_rx {
 	cmdline_fixed_string_t set;
@@ -14255,6 +14430,9 @@ struct cmd_cmdfile_result {
 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
 	(cmdline_parse_inst_t *)&cmd_enable_gro,
 	(cmdline_parse_inst_t *)&cmd_gro_set,
+	(cmdline_parse_inst_t *)&cmd_gso_enable,
+	(cmdline_parse_inst_t *)&cmd_gso_size,
+	(cmdline_parse_inst_t *)&cmd_gso_show,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
app/test-pmd/config.c +24 -0
index 3ae3e1c..88d09d0 100644
@@ -2454,6 +2454,30 @@ struct igb_ring_desc_16_bytes {
 	}
 }
 
+void
+setup_gso(const char *mode, uint8_t port_id)
+{
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		printf("invalid port id %u\n", port_id);
+		return;
+	}
+	if (strcmp(mode, "on") == 0) {
+		if (test_done == 0) {
+			printf("before enabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 1;
+	} else if (strcmp(mode, "off") == 0) {
+		if (test_done == 0) {
+			printf("before disabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 0;
+	}
+}
+
 char*
 list_pkt_forwarding_modes(void)
 {
app/test-pmd/csumonly.c +13 -1
index 90c8119..bd1a287 100644
@@ -70,6 +70,8 @@
 #include <rte_string_fns.h>
 #include <rte_flow.h>
 #include <rte_gro.h>
+#include <rte_gso.h>
+
 #include "testpmd.h"
 
 #define IP_DEFTTL  64   /* from RFC 1340. */
@@ -91,6 +93,7 @@
 /* structure that caches offload info for the current packet */
 struct testpmd_offload_info {
 	uint16_t ethertype;
+	uint8_t gso_enable;
 	uint16_t l2_len;
 	uint16_t l3_len;
 	uint16_t l4_len;
@@ -381,6 +384,8 @@ struct simple_gre_hdr {
 				get_udptcp_checksum(l3_hdr, tcp_hdr,
 					info->ethertype);
 		}
+		if (info->gso_enable)
+			ol_flags |= PKT_TX_TCP_SEG;
 	} else if (info->l4_proto == IPPROTO_SCTP) {
 		sctp_hdr = (struct sctp_hdr *)((char *)l3_hdr + info->l3_len);
 		sctp_hdr->cksum = 0;
@@ -627,6 +632,9 @@ struct simple_gre_hdr {
 pkt_burst_checksum_forward(struct fwd_stream *fs)
 {
 	struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
+	struct rte_mbuf *gso_segments[GSO_MAX_PKT_BURST];
+	struct rte_gso_ctx *gso_ctx;
+	struct rte_mbuf **tx_pkts_burst;
 	struct rte_port *txp;
 	struct rte_mbuf *m, *p;
 	struct ether_hdr *eth_hdr;
@@ -634,13 +642,15 @@ struct simple_gre_hdr {
 	uint16_t nb_rx;
 	uint16_t nb_tx;
 	uint16_t nb_prep;
-	uint16_t i;
+	uint16_t i, j;
 	uint64_t rx_ol_flags, tx_ol_flags;
 	uint16_t testpmd_ol_flags;
 	uint32_t retry;
 	uint32_t rx_bad_ip_csum;
 	uint32_t rx_bad_l4_csum;
 	struct testpmd_offload_info info;
+	uint16_t nb_segments = 0;
+	int ret;
 
 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
 	uint64_t start_tsc;
@@ -674,6 +684,8 @@ struct simple_gre_hdr {
 	memset(&info, 0, sizeof(info));
 	info.tso_segsz = txp->tso_segsz;
 	info.tunnel_tso_segsz = txp->tunnel_tso_segsz;
+	if (gso_ports[fs->tx_port].enable)
+		info.gso_enable = 1;
 
 	for (i = 0; i < nb_rx; i++) {
 		if (likely(i < nb_rx - 1))

app/test-pmd/csumonly.c struct simple_gre_hdr { · line 871

Quoted 9 lines
app/test-pmd/csumonly.c +6 -0
@@ -851,13 +863,59 @@ struct simple_gre_hdr {
 		}
 	}
 
+	if (gso_ports[fs->tx_port].enable == 0)
+		tx_pkts_burst = pkts_burst;
+	else {
+		gso_ctx = &(current_fwd_lcore()->gso_ctx);
+		gso_ctx->gso_size = gso_max_segment_size;
+		for (i = 0; i < nb_rx; i++) {

It seems quite a lot of code to handle an error case, which I suppose will happen pretty rare.
Why not just:

Quoted 8 lines

ret = rte_gso_segment(pkts_burst[i], gso_ctx,

					&gso_segments[nb_segments],
					RTE_DIM(gso_segments) - nb_segments);
If (ret < 0)  {
   RTE_LOG(DEBUG, ....);
    rte_free(pkts_burst[i]);
} else

nb_segments += ret;

Ditto - thanks!

Quoted 114 lines
Quoted 114 lines
app/test-pmd/csumonly.c +45 -4
+			if (unlikely(nb_rx - i >= GSO_MAX_PKT_BURST -
+						nb_segments)) {
+				/*
+				 * insufficient space in gso_segments,
+				 * stop GSO.
+				 */
+				for (j = i; j < GSO_MAX_PKT_BURST -
+						nb_segments; j++) {
+					pkts_burst[j]->ol_flags &=
+						(~PKT_TX_TCP_SEG);
+					gso_segments[nb_segments++] =
+						pkts_burst[j];
+				}
+				for (; j < nb_rx; j++)
+					rte_pktmbuf_free(pkts_burst[j]);
+				break;
+			}
+			ret = rte_gso_segment(pkts_burst[i], gso_ctx,
+					&gso_segments[nb_segments],
+					GSO_MAX_PKT_BURST - nb_segments);
+			if (ret >= 1)
+				nb_segments += ret;
+			else if (ret < 0) {
+				/*
+				 * insufficient MBUFs or space in
+				 * gso_segments, stop GSO.
+				 */
+				for (j = i; j < nb_rx; j++) {
+					pkts_burst[j]->ol_flags &=
+						(~PKT_TX_TCP_SEG);
+					gso_segments[nb_segments++] =
+						pkts_burst[j];
+				}
+				break;
+			}
+		}
+		tx_pkts_burst = gso_segments;
+		nb_rx = nb_segments;
+	}
+
 	nb_prep = rte_eth_tx_prepare(fs->tx_port, fs->tx_queue,
-			pkts_burst, nb_rx);
+			tx_pkts_burst, nb_rx);
 	if (nb_prep != nb_rx)
 		printf("Preparing packet burst to transmit failed: %s\n",
 				rte_strerror(rte_errno));
 
-	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst,
+	nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, tx_pkts_burst,
 			nb_prep);
 
 	/*
@@ -868,7 +926,7 @@ struct simple_gre_hdr {
 		while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
 			rte_delay_us(burst_tx_delay_time);
 			nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
-					&pkts_burst[nb_tx], nb_rx - nb_tx);
+					&tx_pkts_burst[nb_tx], nb_rx - nb_tx);
 		}
 	}
 	fs->tx_packets += nb_tx;
@@ -881,9 +939,10 @@ struct simple_gre_hdr {
 	if (unlikely(nb_tx < nb_rx)) {
 		fs->fwd_dropped += (nb_rx - nb_tx);
 		do {
-			rte_pktmbuf_free(pkts_burst[nb_tx]);
+			rte_pktmbuf_free(tx_pkts_burst[nb_tx]);
 		} while (++nb_tx < nb_rx);
 	}
+
 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
 	end_tsc = rte_rdtsc();
 	core_cycles = (end_tsc - start_tsc);
app/test-pmd/testpmd.c +9 -0
index e097ee0..97e349d 100644
@@ -400,6 +400,9 @@ static int eth_event_callback(uint8_t port_id,
  */
 static int all_ports_started(void);
 
+struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
+
 /*
  * Helper function to check if socket is already discovered.
  * If yes, return positive value. If not, return zero.
@@ -570,6 +573,7 @@ static int eth_event_callback(uint8_t port_id,
 	unsigned int nb_mbuf_per_pool;
 	lcoreid_t  lc_id;
 	uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
+	uint32_t gso_types = 0;
 
 	memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
 
@@ -654,6 +658,8 @@ static int eth_event_callback(uint8_t port_id,
 
 	init_port_config();
 
+	gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+		DEV_TX_OFFLOAD_GRE_TNL_TSO;
 	/*
 	 * Records which Mbuf pool to use by each logical core, if needed.
 	 */
@@ -664,6 +670,13 @@ static int eth_event_callback(uint8_t port_id,
 		if (mbp == NULL)
 			mbp = mbuf_pool_find(0);
 		fwd_lcores[lc_id]->mbp = mbp;
+		/* initialize GSO context */
+		fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
Quoted 8 lines

app/test-pmd/testpmd.c static int eth_event_callback(uint8_t port_id, · line 679

Quoted 4 lines
app/test-pmd/testpmd.c +4 -0
+		fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
+		fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
+			ETHER_CRC_LEN;
+		fwd_lcores[lc_id]->gso_ctx.ipid_flag = !RTE_GSO_IPID_FIXED;

Just
fwd_lcores[lc_id]->gso_ctx.ipid_flag = 0;
should do here.

Agreed.

Thanks again,
Mark

Quoted 2 lines

Konstantin

#103 lore raw

Re: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 82 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Wednesday, October 4, 2017 5:23 PM
To: Ananyev, Konstantin <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 60 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 4:09 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>;

Ananyev, Konstantin <[email protected]>; Yigit,

Quoted 1 line

Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B

<[email protected]>

Quoted 18 lines

Subject: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

From: Jiayu Hu <[email protected]>

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Quoted 8 lines

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

---
 app/test-pmd/cmdline.c                      | 178

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

Quoted 15 lines
 app/test-pmd/config.c                       |  24 ++++
 app/test-pmd/csumonly.c                     |  69 ++++++++++-
 app/test-pmd/testpmd.c                      |  13 ++
 app/test-pmd/testpmd.h                      |  10 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  46 +++++++
 6 files changed, 335 insertions(+), 5 deletions(-)
app/test-pmd/cmdline.c +0 -0
index ccdf239..05b0ce8 100644
@@ -431,6 +431,17 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"    Set max flow number and max packet number per-flow"
 			" for GRO.\n\n"
 
Quoted 10 lines

app/test-pmd/cmdline.c static void cmd_help_long_parsed(void *parsed_result, · line 440

Quoted 7 lines
app/test-pmd/cmdline.c +7 -0
+			"set port (port_id) gso (on|off)"
+			"    Enable or disable Generic Segmentation Offload in"
+			" csum forwarding engine.\n\n"
+
+			"set gso segsz (length)\n"
+			"    Set max packet length for output GSO segments,"
+			" including packet header and payload.\n\n"

Probably a good future improvement would be to allow user to specify gso_type too.

Quoted 1 line

Would you like to see that change implemented in time for the 17.11 release?

I think that's too late for such change in 17.11.
My thought was about 18.02 here.
Konstantin

#104 lore raw

Re: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 91 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 5:27 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Wednesday, October 4, 2017 5:23 PM
To: Ananyev, Konstantin <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>;

Yigit, Ferruh <[email protected]>; [email protected]

Quoted 19 lines

Subject: RE: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 15 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Wednesday, October 4, 2017 4:09 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng

<[email protected]>;

Quoted 37 lines
Quoted 37 lines

Ananyev, Konstantin <[email protected]>; Yigit,

Quoted 1 line

Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B

<[email protected]>

Quoted 18 lines

Subject: [PATCH v6 5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

From: Jiayu Hu <[email protected]>

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Quoted 8 lines

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

---
 app/test-pmd/cmdline.c                      | 178

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

Quoted 7 lines
 app/test-pmd/config.c                       |  24 ++++
 app/test-pmd/csumonly.c                     |  69 ++++++++++-
 app/test-pmd/testpmd.c                      |  13 ++
 app/test-pmd/testpmd.h                      |  10 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  46 +++++++
 6 files changed, 335 insertions(+), 5 deletions(-)
Quoted 5 lines
Quoted 5 lines

app/test-pmd/cmdline.c static void cmd_help_long_parsed(void

Quoted 5 lines
app/test-pmd/cmdline.c +0 -0
index ccdf239..05b0ce8 100644
@@ -431,6 +431,17 @@ static void cmd_help_long_parsed(void

*parsed_result,

Quoted 12 lines
Quoted 12 lines

app/test-pmd/cmdline.c static void cmd_help_long_parsed(void *parsed_result, · line 440

Quoted 10 lines
app/test-pmd/cmdline.c +7 -0
 			"    Set max flow number and max packet number per-flow"
 			" for GRO.\n\n"
 
+			"set port (port_id) gso (on|off)"
+			"    Enable or disable Generic Segmentation Offload in"
+			" csum forwarding engine.\n\n"
+
+			"set gso segsz (length)\n"
+			"    Set max packet length for output GSO segments,"
+			" including packet header and payload.\n\n"

Probably a good future improvement would be to allow user to specify

Quoted 8 lines

gso_type

Quoted 3 lines
Quoted 1 line

too.

Would you like to see that change implemented in time for the 17.11 release?

I think that's too late for such change in 17.11.
My thought was about 18.02 here.
Konstantin

No problem - thanks Konstantin.

#105 lore raw

PATCH v6 6/6 doc: add GSO programmer's guide

In reply to Mark Kavanagh

Add programmer's guide doc to explain the design and use of the GSO library.

---
 MAINTAINERS                                        |   6 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 5 files changed, 1053 insertions(+)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
MAINTAINERS +6 -0
index 8df2a7f..8f0a4bd 100644
@@ -644,6 +644,12 @@ M: Jiayu Hu <[email protected]>
 F: lib/librte_gro/
 F: doc/guides/prog_guide/generic_receive_offload_lib.rst
 
+Generic Segmentation Offload
+M: Jiayu Hu <[email protected]>
+M: Mark Kavanagh <[email protected]>
+F: lib/librte_gso/
+F: doc/guides/prog_guide/generic_segmentation_offload_lib.rst
+
 Distributor
 M: Bruce Richardson <[email protected]>
 M: David Hunt <[email protected]>
doc/guides/prog_guide/generic_segmentation_offload_lib.rst new file +256 -0

256 lines not on this page · raw message

doc/guides/prog_guide/img/gso-output-segment-format.svg new file +313 -0

313 lines not on this page · raw message

doc/guides/prog_guide/img/gso-three-seg-mbuf.svg new file +477 -0

477 lines not on this page · raw message

doc/guides/prog_guide/index.rst +1 -0
index 40f04a1..c7c8b17 100644
@@ -56,6 +56,7 @@ Programmer's Guide
     reorder_lib
     ip_fragment_reassembly_lib
     generic_receive_offload_lib
+    generic_segmentation_offload_lib
     pdump_lib
     multi_proc_support
     kernel_nic_interface
Signature · 1 line
1.9.3
Acked-by on v6 6/6
#106 lore raw

Re: [PATCH v6 6/6] doc: add GSO programmer's guide

Quoted 12 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Mark Kavanagh
Sent: Monday, October 2, 2017 5:46 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Ananyev, Konstantin <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B <[email protected]>
Subject: [dpdk-dev] [PATCH v6 6/6] doc: add GSO programmer's guide

Quoted 5 lines

Add programmer's guide doc to explain the design and use of the GSO library.

#107 lore raw

v7 cover Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

In reply to Mark Kavanagh

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception that the tunnel type created for both the guest's virtio-net, and the host's kernel interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received on P1, is less than 500B.

Change log
==========
v7:
- add RTE_GSO_SEG_SIZE_MIN macro; use this to validate gso_ctx.gso_segsz.
- rename 'ipid_flag' member of gso_ctx to 'flag'.
- remove mention of VLAN tags in supported packet types.
- don't clear PKT_TX_TCP_SEG flag if GSO fails.
- take all packet overhead into account when checking for empty packet.
- ensure that only enabled GSO types are enacted upon (i.e. no fall-through to TCP/IPv4 case from tunneled case).
- validate user-supplied gso segsz arg against RTE_GSO_SEG_SIZE_MIN in testpmd.
- simplify error-checking/handling for GSO failure case in testpmd csum engine.
- use 0 instead of !RTE_GSO_IPID_FIXED in testpmd.

v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

 MAINTAINERS                                        |   6 +
 app/test-pmd/cmdline.c                             | 179 ++++++++
 app/test-pmd/config.c                              |  24 ++
 app/test-pmd/csumonly.c                            |  43 +-
 app/test-pmd/testpmd.c                             |  13 +
 app/test-pmd/testpmd.h                             |  10 +
 config/common_base                                 |   5 +
 doc/api/doxy-api-index.md                          |   1 +
 doc/api/doxy-api.conf                              |   1 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 doc/guides/rel_notes/release_17_11.rst             |  17 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst        |  46 ++
 lib/Makefile                                       |   2 +
 lib/librte_eal/common/include/rte_log.h            |   1 +
 lib/librte_gso/Makefile                            |  52 +++
 lib/librte_gso/gso_common.c                        | 153 +++++++
 lib/librte_gso/gso_common.h                        | 171 ++++++++
 lib/librte_gso/gso_tcp4.c                          | 104 +++++
 lib/librte_gso/gso_tcp4.h                          |  74 ++++
 lib/librte_gso/gso_tunnel_tcp4.c                   | 126 ++++++
 lib/librte_gso/gso_tunnel_tcp4.h                   |  75 ++++
 lib/librte_gso/rte_gso.c                           | 111 +++++
 lib/librte_gso/rte_gso.h                           | 148 +++++++
 lib/librte_gso/rte_gso_version.map                 |   7 +
 mk/rte.app.mk                                      |   1 +
 28 files changed, 2413 insertions(+), 4 deletions(-)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
Signature · 1 line
1.9.3
#108 lore raw

PATCH v7 1/6 gso: add Generic Segmentation Offload API framework

From: Jiayu Hu <[email protected]>

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. To segment a packet requires two steps. The first is to set proper flags to mbuf->ol_flags, where the flags are the same as that of TSO. The second is to call the segmentation API, rte_gso_segment(). This patch introduces the GSO API framework to DPDK.

rte_gso_segment() splits an input packet into small ones in each invocation. The GSO library refers to these small packets generated by rte_gso_segment() as GSO segments. Each of the newly-created GSO segments is organized as a two-segment MBUF, where the first segment is a standard MBUF, which stores a copy of packet header, and the second is an indirect MBUF which points to a section of data in the input packet. rte_gso_segment() reduces the refcnt of the input packet by 1. Therefore, when all GSO segments are freed, the input packet is freed automatically. Additionally, since each GSO segment has multiple MBUFs (i.e. 2 MBUFs), the driver of the interface which the GSO segments are sent to should support to transmit multi-segment packets.

The GSO framework clears the PKT_TX_TCP_SEG flag for both the input packet, and all produced GSO segments in the event of success, since segmentation in hardware is no longer required at that point.

---
 config/common_base                     |   5 ++
 doc/api/doxy-api-index.md              |   1 +
 doc/api/doxy-api.conf                  |   1 +
 doc/guides/rel_notes/release_17_11.rst |   1 +
 lib/Makefile                           |   2 +
 lib/librte_gso/Makefile                |  49 +++++++++++
 lib/librte_gso/rte_gso.c               |  52 ++++++++++++
 lib/librte_gso/rte_gso.h               | 143 +++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map     |   7 ++
 mk/rte.app.mk                          |   1 +
 10 files changed, 262 insertions(+)
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
config/common_base +5 -0
index 12f6be9..58ca5c0 100644
@@ -653,6 +653,11 @@ CONFIG_RTE_LIBRTE_IP_FRAG_TBL_STAT=n
 CONFIG_RTE_LIBRTE_GRO=y
 
 #
+# Compile GSO library
+#
+CONFIG_RTE_LIBRTE_GSO=y
+
+#
 # Compile librte_meter
 #
 CONFIG_RTE_LIBRTE_METER=y
doc/api/doxy-api-index.md +1 -0
index 19e0d4f..6512918 100644
@@ -101,6 +101,7 @@ The public API headers are grouped by topics:
   [TCP]                (@ref rte_tcp.h),
   [UDP]                (@ref rte_udp.h),
   [GRO]                (@ref rte_gro.h),
+  [GSO]                (@ref rte_gso.h),
   [frag/reass]         (@ref rte_ip_frag.h),
   [LPM IPv4 route]     (@ref rte_lpm.h),
   [LPM IPv6 route]     (@ref rte_lpm6.h),
doc/api/doxy-api.conf +1 -0
index 823554f..408f2e6 100644
@@ -47,6 +47,7 @@ INPUT                   = doc/api/doxy-api-index.md \
                           lib/librte_ether \
                           lib/librte_eventdev \
                           lib/librte_gro \
+                          lib/librte_gso \
                           lib/librte_hash \
                           lib/librte_ip_frag \
                           lib/librte_jobstats \
doc/guides/rel_notes/release_17_11.rst +1 -0
index f6f9169..5bb36b7 100644
@@ -174,6 +174,7 @@ The libraries prepended with a plus sign were incremented in this version.
      librte_ethdev.so.7
      librte_eventdev.so.2
      librte_gro.so.1
+   + librte_gso.so.1
      librte_hash.so.2
      librte_ip_frag.so.1
      librte_jobstats.so.1
lib/Makefile +2 -0
index 86caba1..3d123f4 100644
@@ -108,6 +108,8 @@ DIRS-$(CONFIG_RTE_LIBRTE_REORDER) += librte_reorder
 DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
+DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
lib/librte_gso/Makefile new file +49 -0

49 lines not on this page · raw message

lib/librte_gso/rte_gso.c new file +52 -0

52 lines not on this page · raw message

lib/librte_gso/rte_gso.h new file +143 -0

143 lines not on this page · raw message

lib/librte_gso/rte_gso_version.map new file +7 -0
new file mode 100644
index 0000000..e1fd453
@@ -0,0 +1,7 @@
+DPDK_17.11 {
+	global:
+
+	rte_gso_segment;
+
+	local: *;
+};
mk/rte.app.mk +1 -0
index c25fdd9..d4c9873 100644
@@ -66,6 +66,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PDUMP)          += -lrte_pdump
 _LDLIBS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR)    += -lrte_distributor
 _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG)        += -lrte_ip_frag
 _LDLIBS-$(CONFIG_RTE_LIBRTE_GRO)            += -lrte_gro
+_LDLIBS-$(CONFIG_RTE_LIBRTE_GSO)            += -lrte_gso
 _LDLIBS-$(CONFIG_RTE_LIBRTE_METER)          += -lrte_meter
 _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lrte_sched
 _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM)            += -lrte_lpm
Signature · 1 line
1.9.3
#109 lore raw

PATCH v7 2/6 gso: add TCP/IPv4 GSO support

In reply to Mark Kavanagh

From: Jiayu Hu <[email protected]>

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst  |  12 +++
 lib/Makefile                            |   2 +-
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 153 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               | 104 ++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
 lib/librte_gso/rte_gso.c                |  52 ++++++++++-
 lib/librte_gso/rte_gso.h                |   7 +-
 10 files changed, 543 insertions(+), 5 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
doc/guides/rel_notes/release_17_11.rst +12 -0
index 5bb36b7..dd37169 100644
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MTU is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets.
+
+  The GSO library doesn't check if the input packets have correct
+  checksums, and doesn't update checksums for output packets.
+  Additionally, the GSO library doesn't process IP fragmented packets.
+
 
 Resolved Issues
 ---------------
lib/Makefile +1 -1
index 3d123f4..5ecd1b3 100644
@@ -109,7 +109,7 @@ DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
 DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
-DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net librte_mempool
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
lib/librte_eal/common/include/rte_log.h +1 -0
index ec8dba7..2fa1199 100644
@@ -87,6 +87,7 @@ struct rte_logs {
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
lib/librte_gso/Makefile +2 -0
index aeaacbc..2be64d1 100644
@@ -42,6 +42,8 @@ LIBABIVER := 1
 
 #source files
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +153 -0

153 lines not on this page · raw message

lib/librte_gso/gso_common.h new file +141 -0

141 lines not on this page · raw message

lib/librte_gso/gso_tcp4.c new file +104 -0

104 lines not on this page · raw message

lib/librte_gso/gso_tcp4.h new file +74 -0

74 lines not on this page · raw message

lib/librte_gso/rte_gso.c +49 -3

68 lines not on this page · raw message

lib/librte_gso/rte_gso.h +6 -1
index 7d343d7..7ca2d81 100644
@@ -46,6 +46,10 @@
 #include <stdint.h>
 #include <rte_mbuf.h>
 
+/* Minimum GSO segment size. */
+#define RTE_GSO_SEG_SIZE_MIN (sizeof(struct ether_hdr) + \
+		sizeof(struct ipv4_hdr) + sizeof(struct tcp_hdr) + 1)
+
 /* GSO flags for rte_gso_ctx. */
 #define RTE_GSO_FLAG_IPID_FIXED (1ULL << 0)
 /**< Use fixed IP ids for output GSO segments. Setting
@@ -81,7 +85,8 @@ struct rte_gso_ctx {
 	 */
 	uint16_t gso_size;
 	/**< maximum size of an output GSO segment, including packet
-	 * header and payload, measured in bytes.
+	 * header and payload, measured in bytes. Must exceed
+	 * RTE_GSO_SEG_SIZE_MIN.
 	 */
 };
 
Signature · 1 line
1.9.3
#110 lore raw

PATCH v7 3/6 gso: add VxLAN GSO support

In reply to Mark Kavanagh

This patch adds a framework that allows GSO on tunneled packets. Furthermore, it leverages that framework to provide GSO support for VxLAN-encapsulated packets.

Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

VxLAN GSO doesn't check if input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize each output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSO'd segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst |   2 +
 lib/librte_gso/Makefile                |   1 +
 lib/librte_gso/gso_common.h            |  25 +++++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 120 +++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_tunnel_tcp4.h       |  75 +++++++++++++++++++++
 lib/librte_gso/rte_gso.c               |  14 +++-
 6 files changed, 235 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
doc/guides/rel_notes/release_17_11.rst +2 -0
index dd37169..c58eeb1 100644
@@ -48,6 +48,8 @@ New Features
   ones (e.g. MTU is 1500B). Supported packet types are:
 
   * TCP/IPv4 packets.
+  * VxLAN packets, which must have an outer IPv4 header, and contain
+    an inner TCP/IPv4 packet.
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.h +25 -0
index a8ad638..95d54e7 100644
@@ -39,6 +39,7 @@
 #include <rte_mbuf.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
+#include <rte_udp.h>
 
 #define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
 		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)
@@ -49,6 +50,30 @@
 #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
 
+#define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_VXLAN))
+
+/**
+ * Internal function which updates the UDP header of a packet, following
+ * segmentation. This is required to update the header's datagram length field.
+ *
+ * @param pkt
+ *  The packet containing the UDP header.
+ * @param udp_offset
+ *  The offset of the UDP header from the start of the packet.
+ */
+static inline void
+update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset)
+{
+	struct udp_hdr *udp_hdr;
+
+	udp_hdr = (struct udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			udp_offset);
+	udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset);
+}
+
 /**
  * Internal function which updates the TCP header of a packet, following
  * segmentation. This is required to update the header's 'sent' sequence
lib/librte_gso/gso_tunnel_tcp4.c new file +120 -0

120 lines not on this page · raw message

lib/librte_gso/gso_tunnel_tcp4.h new file +75 -0

75 lines not on this page · raw message

lib/librte_gso/rte_gso.c +12 -2
index 2b6fc2d..a6f38e2 100644
@@ -39,6 +39,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp4.h"
+#include "gso_tunnel_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -59,7 +60,8 @@
 
 	if ((gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN) ||
 			(gso_ctx->gso_size >= pkt->pkt_len) ||
-			(gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO) !=
+			(gso_ctx->gso_types & (DEV_TX_OFFLOAD_TCP_TSO |
+			                       DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
 			gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
@@ -72,12 +74,20 @@
 	ipid_delta = (gso_ctx->flag != RTE_GSO_FLAG_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_TCP(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)
+		&& (gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else if (IS_IPV4_TCP(pkt->ol_flags) &&
+			(gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO)) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
 				pkts_out, nb_pkts_out);
 	} else {
+		/* unsupported packet, skip */
 		pkts_out[0] = pkt;
 		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
 		return 1;
Signature · 1 line
1.9.3
#111 lore raw

PATCH v7 4/6 gso: add GRE GSO support

In reply to Mark Kavanagh

This patch adds GSO support for GRE-tunneled packets. Supported GRE packets must contain an outer IPv4 header, and inner TCP/IPv4 headers. They may also contain a single VLAN tag. GRE GSO doesn't check if all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with VxLAN GSO, GRE GSO uses a two-segment MBUF to organize each output packet, which requires multi-segment mbuf support in the TX functions of the NIC driver. Also, if a packet is GSOed, GRE GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst |  2 ++
 lib/librte_gso/gso_common.h            |  5 +++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 14 ++++++++++----
 lib/librte_gso/rte_gso.c               |  9 ++++++---
 4 files changed, 23 insertions(+), 7 deletions(-)
doc/guides/rel_notes/release_17_11.rst +2 -0
index c58eeb1..2faa630 100644
@@ -50,6 +50,8 @@ New Features
   * TCP/IPv4 packets.
   * VxLAN packets, which must have an outer IPv4 header, and contain
     an inner TCP/IPv4 packet.
+  * GRE packets, which must contain an outer IPv4 header, and inner
+    TCP/IPv4 headers.
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/gso_common.h +5 -0
index 95d54e7..145ea49 100644
@@ -55,6 +55,11 @@
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
 		 PKT_TX_TUNNEL_VXLAN))
 
+#define IS_IPV4_GRE_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_GRE)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_GRE))
+
 /**
  * Internal function which updates the UDP header of a packet, following
  * segmentation. This is required to update the header's datagram length field.
lib/librte_gso/gso_tunnel_tcp4.c +10 -4
index 5e8c8e5..8d0cfd7 100644
@@ -42,11 +42,13 @@
 	struct tcp_hdr *tcp_hdr;
 	uint32_t sent_seq;
 	uint16_t outer_id, inner_id, tail_idx, i;
-	uint16_t outer_ipv4_offset, inner_ipv4_offset, udp_offset, tcp_offset;
+	uint16_t outer_ipv4_offset, inner_ipv4_offset;
+	uint16_t udp_gre_offset, tcp_offset;
+	uint8_t update_udp_hdr;
 
 	outer_ipv4_offset = pkt->outer_l2_len;
-	udp_offset = outer_ipv4_offset + pkt->outer_l3_len;
-	inner_ipv4_offset = udp_offset + pkt->l2_len;
+	udp_gre_offset = outer_ipv4_offset + pkt->outer_l3_len;
+	inner_ipv4_offset = udp_gre_offset + pkt->l2_len;
 	tcp_offset = inner_ipv4_offset + pkt->l3_len;
 
 	/* Outer IPv4 header. */
@@ -63,9 +65,13 @@
 	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
 	tail_idx = nb_segs - 1;
 
+	/* Only update UDP header for VxLAN packets. */
+	update_udp_hdr = (pkt->ol_flags & PKT_TX_TUNNEL_VXLAN) ? 1 : 0;
+
 	for (i = 0; i < nb_segs; i++) {
 		update_ipv4_header(segs[i], outer_ipv4_offset, outer_id);
-		update_udp_header(segs[i], udp_offset);
+		if (update_udp_hdr)
+			update_udp_header(segs[i], udp_gre_offset);
 		update_ipv4_header(segs[i], inner_ipv4_offset, inner_id);
 		update_tcp_header(segs[i], tcp_offset, sent_seq, i < tail_idx);
 		outer_id++;
lib/librte_gso/rte_gso.c +6 -3
index a6f38e2..1d4082a 100644
@@ -61,7 +61,8 @@
 	if ((gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN) ||
 			(gso_ctx->gso_size >= pkt->pkt_len) ||
 			(gso_ctx->gso_types & (DEV_TX_OFFLOAD_TCP_TSO |
-			                       DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
+			                       DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+			                       DEV_TX_OFFLOAD_GRE_TNL_TSO)) !=
 			gso_ctx->gso_types) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		pkts_out[0] = pkt;
@@ -74,8 +75,10 @@
 	ipid_delta = (gso_ctx->flag != RTE_GSO_FLAG_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)
-		&& (gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) {
+	if ((IS_IPV4_VXLAN_TCP4(pkt->ol_flags) &&
+			(gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) ||
+			((IS_IPV4_GRE_TCP4(pkt->ol_flags) &&
+			 (gso_ctx->gso_types & DEV_TX_OFFLOAD_GRE_TNL_TSO)))) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
Signature · 1 line
1.9.3
#112 lore raw

PATCH v7 5/6 app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

In reply to Mark Kavanagh

From: Jiayu Hu <[email protected]>

This patch adds GSO support to the csum forwarding engine. Oversized packets transmitted over a GSO-enabled port will undergo segmentation (with the exception of packet-types unsupported by the GSO library). GSO support is disabled by default.

GSO support may be toggled on a per-port basis, using the command:

"set port <port_id> gso on|off"

The maximum packet length (including the packet header and payload) for GSO segments may be set with the command:

"set gso segsz <length>"

Show GSO configuration for a given port with the command:

"show port <port_id> gso"

---
 app/test-pmd/cmdline.c                      | 179 ++++++++++++++++++++++++++++
 app/test-pmd/config.c                       |  24 ++++
 app/test-pmd/csumonly.c                     |  43 ++++++-
 app/test-pmd/testpmd.c                      |  13 ++
 app/test-pmd/testpmd.h                      |  10 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  46 +++++++
 6 files changed, 311 insertions(+), 4 deletions(-)
app/test-pmd/cmdline.c +179 -0
index ccdf239..92e6171 100644
@@ -431,6 +431,17 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"    Set max flow number and max packet number per-flow"
 			" for GRO.\n\n"
 
+			"set port (port_id) gso (on|off)"
+			"    Enable or disable Generic Segmentation Offload in"
+			" csum forwarding engine.\n\n"
+
+			"set gso segsz (length)\n"
+			"    Set max packet length for output GSO segments,"
+			" including packet header and payload.\n\n"
+
+			"show port (port_id) gso\n"
+			"    Show GSO configuration.\n\n"
+
 			"set fwd (%s)\n"
 			"    Set packet forwarding mode.\n\n"
 
@@ -3967,6 +3978,171 @@ struct cmd_gro_set_result {
 	},
 };
 
+/* *** ENABLE/DISABLE GSO *** */
+struct cmd_gso_enable_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_mode;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_enable_parsed(void *parsed_result,
+		__attribute__((unused)) struct cmdline *cl,
+		__attribute__((unused)) void *data)
+{
+	struct cmd_gso_enable_result *res;
+
+	res = parsed_result;
+	if (!strcmp(res->cmd_keyword, "gso"))
+		setup_gso(res->cmd_mode, res->cmd_pid);
+}
+
+cmdline_parse_token_string_t cmd_gso_enable_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_enable_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_enable_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_enable_mode =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_mode, "on#off");
+cmdline_parse_token_num_t cmd_gso_enable_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result,
+			cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_enable = {
+	.f = cmd_gso_enable_parsed,
+	.data = NULL,
+	.help_str = "set port <port_id> gso on|off",
+	.tokens = {
+		(void *)&cmd_gso_enable_set,
+		(void *)&cmd_gso_enable_port,
+		(void *)&cmd_gso_enable_pid,
+		(void *)&cmd_gso_enable_keyword,
+		(void *)&cmd_gso_enable_mode,
+		NULL,
+	},
+};
+
+/* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */
+struct cmd_gso_size_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_keyword;
+	cmdline_fixed_string_t cmd_segsz;
+	uint16_t cmd_size;
+};
+
+static void
+cmd_gso_size_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_size_result *res = parsed_result;
+
+	if (test_done == 0) {
+		printf("Before setting GSO segsz, please first stop fowarding\n");
+		return;
+	}
+
+	if (!strcmp(res->cmd_keyword, "gso") &&
+			!strcmp(res->cmd_segsz, "segsz")) {
+		if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
+			printf("gso_size should be larger than %lu."
+					" Please input a legal value\n",
+					RTE_GSO_SEG_SIZE_MIN);
+		else
+			gso_max_segment_size = res->cmd_size;
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_size_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_set, "set");
+cmdline_parse_token_string_t cmd_gso_size_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_string_t cmd_gso_size_segsz =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_segsz, "segsz");
+cmdline_parse_token_num_t cmd_gso_size_size =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
+				cmd_size, UINT16);
+
+cmdline_parse_inst_t cmd_gso_size = {
+	.f = cmd_gso_size_parsed,
+	.data = NULL,
+	.help_str = "set gso segsz <length>",
+	.tokens = {
+		(void *)&cmd_gso_size_set,
+		(void *)&cmd_gso_size_keyword,
+		(void *)&cmd_gso_size_segsz,
+		(void *)&cmd_gso_size_size,
+		NULL,
+	},
+};
+
+/* *** SHOW GSO CONFIGURATION *** */
+struct cmd_gso_show_result {
+	cmdline_fixed_string_t cmd_show;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	uint8_t cmd_pid;
+};
+
+static void
+cmd_gso_show_parsed(void *parsed_result,
+		       __attribute__((unused)) struct cmdline *cl,
+		       __attribute__((unused)) void *data)
+{
+	struct cmd_gso_show_result *res = parsed_result;
+
+	if (!rte_eth_dev_is_valid_port(res->cmd_pid)) {
+		printf("invalid port id %u\n", res->cmd_pid);
+		return;
+	}
+	if (!strcmp(res->cmd_keyword, "gso")) {
+		if (gso_ports[res->cmd_pid].enable) {
+			printf("Max GSO'd packet size: %uB\n"
+					"Supported GSO types: TCP/IPv4, "
+					"VxLAN with inner TCP/IPv4 packet, "
+					"GRE with inner TCP/IPv4  packet\n",
+					gso_max_segment_size);
+		} else
+			printf("GSO is not enabled on Port %u\n", res->cmd_pid);
+	}
+}
+
+cmdline_parse_token_string_t cmd_gso_show_show =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_show, "show");
+cmdline_parse_token_string_t cmd_gso_show_port =
+TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+		cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_show_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result,
+				cmd_keyword, "gso");
+cmdline_parse_token_num_t cmd_gso_show_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result,
+				cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_show = {
+	.f = cmd_gso_show_parsed,
+	.data = NULL,
+	.help_str = "show port <port_id> gso",
+	.tokens = {
+		(void *)&cmd_gso_show_show,
+		(void *)&cmd_gso_show_port,
+		(void *)&cmd_gso_show_pid,
+		(void *)&cmd_gso_show_keyword,
+		NULL,
+	},
+};
+
 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
 struct cmd_set_flush_rx {
 	cmdline_fixed_string_t set;
@@ -14255,6 +14431,9 @@ struct cmd_cmdfile_result {
 	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
 	(cmdline_parse_inst_t *)&cmd_enable_gro,
 	(cmdline_parse_inst_t *)&cmd_gro_set,
+	(cmdline_parse_inst_t *)&cmd_gso_enable,
+	(cmdline_parse_inst_t *)&cmd_gso_size,
+	(cmdline_parse_inst_t *)&cmd_gso_show,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
 	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
app/test-pmd/config.c +24 -0
index 3ae3e1c..88d09d0 100644
@@ -2454,6 +2454,30 @@ struct igb_ring_desc_16_bytes {
 	}
 }
 
+void
+setup_gso(const char *mode, uint8_t port_id)
+{
+	if (!rte_eth_dev_is_valid_port(port_id)) {
+		printf("invalid port id %u\n", port_id);
+		return;
+	}
+	if (strcmp(mode, "on") == 0) {
+		if (test_done == 0) {
+			printf("before enabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 1;
+	} else if (strcmp(mode, "off") == 0) {
+		if (test_done == 0) {
+			printf("before disabling GSO,"
+					" please stop forwarding first\n");
+			return;
+		}
+		gso_ports[port_id].enable = 0;
+	}
+}
+
 char*
 list_pkt_forwarding_modes(void)
 {
app/test-pmd/csumonly.c +39 -4

104 lines not on this page · raw message

app/test-pmd/testpmd.c +13 -0
index e097ee0..b9ee77c 100644
@@ -400,6 +400,9 @@ static int eth_event_callback(uint8_t port_id,
  */
 static int all_ports_started(void);
 
+struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN;
+
 /*
  * Helper function to check if socket is already discovered.
  * If yes, return positive value. If not, return zero.
@@ -570,6 +573,7 @@ static int eth_event_callback(uint8_t port_id,
 	unsigned int nb_mbuf_per_pool;
 	lcoreid_t  lc_id;
 	uint8_t port_per_socket[RTE_MAX_NUMA_NODES];
+	uint32_t gso_types = 0;
 
 	memset(port_per_socket,0,RTE_MAX_NUMA_NODES);
 
@@ -654,6 +658,8 @@ static int eth_event_callback(uint8_t port_id,
 
 	init_port_config();
 
+	gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+		DEV_TX_OFFLOAD_GRE_TNL_TSO;
 	/*
 	 * Records which Mbuf pool to use by each logical core, if needed.
 	 */
@@ -664,6 +670,13 @@ static int eth_event_callback(uint8_t port_id,
 		if (mbp == NULL)
 			mbp = mbuf_pool_find(0);
 		fwd_lcores[lc_id]->mbp = mbp;
+		/* initialize GSO context */
+		fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp;
+		fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types;
+		fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN -
+			ETHER_CRC_LEN;
+		fwd_lcores[lc_id]->gso_ctx.flag = 0;
 	}
 
 	/* Configuration of packet forwarding streams. */
app/test-pmd/testpmd.h +10 -0
index 1d1ee75..ff842a1 100644
@@ -36,6 +36,7 @@
 
 #include <rte_pci.h>
 #include <rte_gro.h>
+#include <rte_gso.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -205,6 +206,7 @@ struct rte_port {
  * CPU id. configuration table.
  */
 struct fwd_lcore {
+	struct rte_gso_ctx gso_ctx;     /**< GSO context */
 	struct rte_mempool *mbp; /**< The mbuf pool to use by this core */
 	streamid_t stream_idx;   /**< index of 1st stream in "fwd_streams" */
 	streamid_t stream_nb;    /**< number of streams in "fwd_streams" */
@@ -442,6 +444,13 @@ struct gro_status {
 };
 extern struct gro_status gro_ports[RTE_MAX_ETHPORTS];
 
+#define GSO_MAX_PKT_BURST 2048
+struct gso_status {
+	uint8_t enable;
+};
+extern struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+extern uint16_t gso_max_segment_size;
+
 static inline unsigned int
 lcore_num(void)
 {
@@ -642,6 +651,7 @@ void port_rss_hash_key_update(portid_t port_id, char rss_type[],
 int rx_queue_id_is_invalid(queueid_t rxq_id);
 int tx_queue_id_is_invalid(queueid_t txq_id);
 void setup_gro(const char *mode, uint8_t port_id);
+void setup_gso(const char *mode, uint8_t port_id);
 
 /* Functions to manage the set of filtered Multicast MAC addresses */
 void mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr);
doc/guides/testpmd_app_ug/testpmd_funcs.rst +46 -0

52 lines not on this page · raw message

Signature · 1 line
1.9.3
#113 lore raw

PATCH v7 6/6 doc: add GSO programmer's guide

In reply to Mark Kavanagh

Add programmer's guide doc to explain the design and use of the GSO library.

---
 MAINTAINERS                                        |   6 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 5 files changed, 1053 insertions(+)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
MAINTAINERS +6 -0
index 8df2a7f..8f0a4bd 100644
@@ -644,6 +644,12 @@ M: Jiayu Hu <[email protected]>
 F: lib/librte_gro/
 F: doc/guides/prog_guide/generic_receive_offload_lib.rst
 
+Generic Segmentation Offload
+M: Jiayu Hu <[email protected]>
+M: Mark Kavanagh <[email protected]>
+F: lib/librte_gso/
+F: doc/guides/prog_guide/generic_segmentation_offload_lib.rst
+
 Distributor
 M: Bruce Richardson <[email protected]>
 M: David Hunt <[email protected]>
doc/guides/prog_guide/generic_segmentation_offload_lib.rst new file +256 -0

256 lines not on this page · raw message

doc/guides/prog_guide/img/gso-output-segment-format.svg new file +313 -0

313 lines not on this page · raw message

doc/guides/prog_guide/img/gso-three-seg-mbuf.svg new file +477 -0

477 lines not on this page · raw message

doc/guides/prog_guide/index.rst +1 -0
index 40f04a1..c7c8b17 100644
@@ -56,6 +56,7 @@ Programmer's Guide
     reorder_lib
     ip_fragment_reassembly_lib
     generic_receive_offload_lib
+    generic_segmentation_offload_lib
     pdump_lib
     multi_proc_support
     kernel_nic_interface
Signature · 1 line
1.9.3
#114 lore raw

Re: [PATCH v7 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

In reply to Mark Kavanagh

Hi Mark,

Quoted 97 lines

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception that the tunnel type created for both the guest's virtio-net, and the host's kernel interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received on P1, is less than 500B.

Quoted 13 lines

Change log
==========
v7:
- add RTE_GSO_SEG_SIZE_MIN macro; use this to validate gso_ctx.gso_segsz.
- rename 'ipid_flag' member of gso_ctx to 'flag'.
- remove mention of VLAN tags in supported packet types.
- don't clear PKT_TX_TCP_SEG flag if GSO fails.
- take all packet overhead into account when checking for empty packet.
- ensure that only enabled GSO types are enacted upon (i.e. no fall-through to TCP/IPv4 case from tunneled case).
- validate user-supplied gso segsz arg against RTE_GSO_SEG_SIZE_MIN in testpmd.
- simplify error-checking/handling for GSO failure case in testpmd csum engine.
- use 0 instead of !RTE_GSO_IPID_FIXED in testpmd.

Looks o in general, just few nits below.
Konstantin

1. there are few checkpatch errors regarding indentation.
2. [dpdk-dev,v7,2/6] gso: add TCP/IPv4 GSO support

int
rte_gso_segment(struct rte_mbuf *pkt,
@@ -41,12 +46,53 @@
struct rte_mbuf **pkts_out,
uint16_t nb_pkts_out)
{
+ struct rte_mempool *direct_pool, *indirect_pool;
+ struct rte_mbuf *pkt_seg;
+ uint64_t ol_flags;
+ uint16_t gso_size;
+ uint8_t ipid_delta;
+ int ret = 1;
+
if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
nb_pkts_out < 1)
return -EINVAL;

- pkt->ol_flags &= (~PKT_TX_TCP_SEG);
- pkts_out[0] = pkt;
+ if ((gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN) ||
+ (gso_ctx->gso_size >= pkt->pkt_len) ||
+ (gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO) !=
+ gso_ctx->gso_types) {
+ pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+ pkts_out[0] = pkt;
+ return 1;
+ }
First and third are just checks for gso_ctx misconfiguration.
I think we don't need to reset PKT_TX_TCP_SEG bit in ol_flags nt case. I'd suggest either remove them at all or merge with the invalid parameters check above:

if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
nb_pkts_out < 1 ||

			gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN ||

gso_ctx->gso_types != DEV_TX_OFFLOAD_TCP_TSO)
return -EINVAL;

if ((gso_ctx->gso_size >= pkt->pkt_len) {
pkt->ol_flags &= (~PKT_TX_TCP_SEG);
pkts_out[0] = pkt;
return 1;
}
....

3. [dpdk-dev,v7,3/6] gso: add VxLAN GSO support

lib/librte_gso/rte_gso.c

int
rte_gso_segment(struct rte_mbuf *pkt,
@@ -59,7 +60,8 @@

...
+ (gso_ctx->gso_types & (DEV_TX_OFFLOAD_TCP_TSO |
+ DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
gso_ctx->gso_types) {

I think the check should be just:
(gso_ctx->gso_types & (DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) != 0)

As we do want to allow only VXLAN segmentation for ctx.

4. [dpdk-dev,v7,4/6] gso: add GRE GSO support
Same comment as above.

Quoted 103 lines

v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

 MAINTAINERS                                        |   6 +
 app/test-pmd/cmdline.c                             | 179 ++++++++
 app/test-pmd/config.c                              |  24 ++
 app/test-pmd/csumonly.c                            |  43 +-
 app/test-pmd/testpmd.c                             |  13 +
 app/test-pmd/testpmd.h                             |  10 +
 config/common_base                                 |   5 +
 doc/api/doxy-api-index.md                          |   1 +
 doc/api/doxy-api.conf                              |   1 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 doc/guides/rel_notes/release_17_11.rst             |  17 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst        |  46 ++
 lib/Makefile                                       |   2 +
 lib/librte_eal/common/include/rte_log.h            |   1 +
 lib/librte_gso/Makefile                            |  52 +++
 lib/librte_gso/gso_common.c                        | 153 +++++++
 lib/librte_gso/gso_common.h                        | 171 ++++++++
 lib/librte_gso/gso_tcp4.c                          | 104 +++++
 lib/librte_gso/gso_tcp4.h                          |  74 ++++
 lib/librte_gso/gso_tunnel_tcp4.c                   | 126 ++++++
 lib/librte_gso/gso_tunnel_tcp4.h                   |  75 ++++
 lib/librte_gso/rte_gso.c                           | 111 +++++
 lib/librte_gso/rte_gso.h                           | 148 +++++++
 lib/librte_gso/rte_gso_version.map                 |   7 +
 mk/rte.app.mk                                      |   1 +
 28 files changed, 2413 insertions(+), 4 deletions(-)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map

--
1.9.3

#115 lore raw

Re: [PATCH v7 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Quoted 123 lines

From: Ananyev, Konstantin
Sent: Thursday, October 5, 2017 2:23 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v7 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Hi Mark,

Quoted 83 lines

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

Quoted 7 lines

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception

that

Quoted 1 line

the tunnel type created for both the guest's virtio-net, and the host's

kernel

Quoted 4 lines

interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received

on

Quoted 11 lines

P1, is less than 500B.

Change log
==========
v7:
- add RTE_GSO_SEG_SIZE_MIN macro; use this to validate gso_ctx.gso_segsz.
- rename 'ipid_flag' member of gso_ctx to 'flag'.
- remove mention of VLAN tags in supported packet types.
- don't clear PKT_TX_TCP_SEG flag if GSO fails.
- take all packet overhead into account when checking for empty packet.
- ensure that only enabled GSO types are enacted upon (i.e. no fall-through

to

Quoted 2 lines

TCP/IPv4 case from tunneled case).
- validate user-supplied gso segsz arg against RTE_GSO_SEG_SIZE_MIN in

Quoted 7 lines

testpmd.

Quoted 1 line

- simplify error-checking/handling for GSO failure case in testpmd csum

engine.

Quoted 1 line

- use 0 instead of !RTE_GSO_IPID_FIXED in testpmd.

Looks o in general, just few nits below.
Konstantin

Thanks Konstantin - I'll address those issues and spin up a new patchset right now. Responses to comments are inline, as usual.

Thanks again,
Mark

Quoted 2 lines

1. there are few checkpatch errors regarding indentation.

I saw the issues regarding indentation - apologies :(

The issue reported with the MAINTAINERS file in patch 6/6 is a bit of a mystery to me though - any ideas?

Quoted 29 lines

2. [dpdk-dev,v7,2/6] gso: add TCP/IPv4 GSO support

int
rte_gso_segment(struct rte_mbuf *pkt,

(quoted diff) +15 -2
@@ -41,12 +46,53 @@
 		struct rte_mbuf **pkts_out,
 		uint16_t nb_pkts_out)
 {
+	struct rte_mempool *direct_pool, *indirect_pool;
+	struct rte_mbuf *pkt_seg;
+	uint64_t ol_flags;
+	uint16_t gso_size;
+	uint8_t ipid_delta;
+	int ret = 1;
+
 	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
 			nb_pkts_out < 1)
 		return -EINVAL;
 
-	pkt->ol_flags &= (~PKT_TX_TCP_SEG);
-	pkts_out[0] = pkt;
+	if ((gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN) ||
+			(gso_ctx->gso_size >= pkt->pkt_len) ||
+			(gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO) !=
+			gso_ctx->gso_types) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		pkts_out[0] = pkt;
+		return 1;
+	}
Quoted 2 lines

First and third are just checks for gso_ctx misconfiguration. I think we don't need to reset PKT_TX_TCP_SEG bit in ol_flags nt case.

Yes, you're right - that error appears to have been introduced while manually resolving a merge conflict while rebasing.

Quoted 9 lines

I'd suggest either remove them at all or merge with the invalid parameters check above:

if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||

			nb_pkts_out < 1 ||
			gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN ||
			gso_ctx->gso_types != DEV_TX_OFFLOAD_TCP_TSO)
		return -EINVAL;
Quoted 6 lines

if ((gso_ctx->gso_size >= pkt->pkt_len) {
pkt->ol_flags &= (~PKT_TX_TCP_SEG);
pkts_out[0] = pkt;
return 1;
}
....

Agreed.

Quoted 15 lines

3. [dpdk-dev,v7,3/6] gso: add VxLAN GSO support

lib/librte_gso/rte_gso.c

int
rte_gso_segment(struct rte_mbuf *pkt,

(quoted diff) +2 -0
@@ -59,7 +60,8 @@
 
...
+			(gso_ctx->gso_types & (DEV_TX_OFFLOAD_TCP_TSO |
+			                       DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) !=
			gso_ctx->gso_types) {
Quoted 5 lines

I think the check should be just:
(gso_ctx->gso_types & (DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) != 0)

As we do want to allow only VXLAN segmentation for ctx.

Ah yes, good catch.

In that case though, wouldn't the statement be:

        if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
                        nb_pkts_out < 1 ||
                        gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN ||
                        (gso_ctx->gso_types & (DEV_TX_OFFLOAD_TCP_TSO |
                        DEV_TX_OFFLOAD_VXLAN_TNL_TSO) == 0))
                return -EINVAL;
Quoted 109 lines

4. [dpdk-dev,v7,4/6] gso: add GRE GSO support
Same comment as above.

Quoted 58 lines

v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

Quoted 12 lines
 MAINTAINERS                                        |   6 +
 app/test-pmd/cmdline.c                             | 179 ++++++++
 app/test-pmd/config.c                              |  24 ++
 app/test-pmd/csumonly.c                            |  43 +-
 app/test-pmd/testpmd.c                             |  13 +
 app/test-pmd/testpmd.h                             |  10 +
 config/common_base                                 |   5 +
 doc/api/doxy-api-index.md                          |   1 +
 doc/api/doxy-api.conf                              |   1 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477

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

Quoted 10 lines
 doc/guides/prog_guide/index.rst                    |   1 +
 doc/guides/rel_notes/release_17_11.rst             |  17 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst        |  46 ++
 lib/Makefile                                       |   2 +
 lib/librte_eal/common/include/rte_log.h            |   1 +
 lib/librte_gso/Makefile                            |  52 +++
 lib/librte_gso/gso_common.c                        | 153 +++++++
 lib/librte_gso/gso_common.h                        | 171 ++++++++
 lib/librte_gso/gso_tcp4.c                          | 104 +++++
 lib/librte_gso/gso_tcp4.h                          |  74 ++++
Quoted 8 lines
 lib/librte_gso/gso_tunnel_tcp4.c                   | 126 ++++++
 lib/librte_gso/gso_tunnel_tcp4.h                   |  75 ++++
 lib/librte_gso/rte_gso.c                           | 111 +++++
 lib/librte_gso/rte_gso.h                           | 148 +++++++
 lib/librte_gso/rte_gso_version.map                 |   7 +
 mk/rte.app.mk                                      |   1 +
 28 files changed, 2413 insertions(+), 4 deletions(-)
 create mode 100644

doc/guides/prog_guide/generic_segmentation_offload_lib.rst

Quoted 15 lines
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map

--
1.9.3

#116 lore raw

PATCH v8 1/6 gso: add Generic Segmentation Offload API framework

In reply to Mark Kavanagh

From: Jiayu Hu <[email protected]>

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. To segment a packet requires two steps. The first is to set proper flags to mbuf->ol_flags, where the flags are the same as that of TSO. The second is to call the segmentation API, rte_gso_segment(). This patch introduces the GSO API framework to DPDK.

rte_gso_segment() splits an input packet into small ones in each invocation. The GSO library refers to these small packets generated by rte_gso_segment() as GSO segments. Each of the newly-created GSO segments is organized as a two-segment MBUF, where the first segment is a standard MBUF, which stores a copy of packet header, and the second is an indirect MBUF which points to a section of data in the input packet. rte_gso_segment() reduces the refcnt of the input packet by 1. Therefore, when all GSO segments are freed, the input packet is freed automatically. Additionally, since each GSO segment has multiple MBUFs (i.e. 2 MBUFs), the driver of the interface which the GSO segments are sent to should support to transmit multi-segment packets.

The GSO framework clears the PKT_TX_TCP_SEG flag for both the input packet, and all produced GSO segments in the event of success, since segmentation in hardware is no longer required at that point.

---
 config/common_base                     |   5 ++
 doc/api/doxy-api-index.md              |   1 +
 doc/api/doxy-api.conf                  |   1 +
 doc/guides/rel_notes/release_17_11.rst |   1 +
 lib/Makefile                           |   2 +
 lib/librte_gso/Makefile                |  49 +++++++++++
 lib/librte_gso/rte_gso.c               |  52 ++++++++++++
 lib/librte_gso/rte_gso.h               | 143 +++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map     |   7 ++
 mk/rte.app.mk                          |   1 +
 10 files changed, 262 insertions(+)
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
config/common_base +5 -0
index 12f6be9..58ca5c0 100644
@@ -653,6 +653,11 @@ CONFIG_RTE_LIBRTE_IP_FRAG_TBL_STAT=n
 CONFIG_RTE_LIBRTE_GRO=y
 
 #
+# Compile GSO library
+#
+CONFIG_RTE_LIBRTE_GSO=y
+
+#
 # Compile librte_meter
 #
 CONFIG_RTE_LIBRTE_METER=y
doc/api/doxy-api-index.md +1 -0
index 19e0d4f..6512918 100644
@@ -101,6 +101,7 @@ The public API headers are grouped by topics:
   [TCP]                (@ref rte_tcp.h),
   [UDP]                (@ref rte_udp.h),
   [GRO]                (@ref rte_gro.h),
+  [GSO]                (@ref rte_gso.h),
   [frag/reass]         (@ref rte_ip_frag.h),
   [LPM IPv4 route]     (@ref rte_lpm.h),
   [LPM IPv6 route]     (@ref rte_lpm6.h),
doc/api/doxy-api.conf +1 -0
index 823554f..408f2e6 100644
@@ -47,6 +47,7 @@ INPUT                   = doc/api/doxy-api-index.md \
                           lib/librte_ether \
                           lib/librte_eventdev \
                           lib/librte_gro \
+                          lib/librte_gso \
                           lib/librte_hash \
                           lib/librte_ip_frag \
                           lib/librte_jobstats \
doc/guides/rel_notes/release_17_11.rst +1 -0
index f6f9169..5bb36b7 100644
@@ -174,6 +174,7 @@ The libraries prepended with a plus sign were incremented in this version.
      librte_ethdev.so.7
      librte_eventdev.so.2
      librte_gro.so.1
+   + librte_gso.so.1
      librte_hash.so.2
      librte_ip_frag.so.1
      librte_jobstats.so.1
lib/Makefile +2 -0
index 86caba1..3d123f4 100644
@@ -108,6 +108,8 @@ DIRS-$(CONFIG_RTE_LIBRTE_REORDER) += librte_reorder
 DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
+DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
lib/librte_gso/Makefile new file +49 -0

49 lines not on this page · raw message

lib/librte_gso/rte_gso.c new file +52 -0

52 lines not on this page · raw message

lib/librte_gso/rte_gso.h new file +143 -0

143 lines not on this page · raw message

lib/librte_gso/rte_gso_version.map new file +7 -0
new file mode 100644
index 0000000..e1fd453
@@ -0,0 +1,7 @@
+DPDK_17.11 {
+	global:
+
+	rte_gso_segment;
+
+	local: *;
+};
mk/rte.app.mk +1 -0
index c25fdd9..d4c9873 100644
@@ -66,6 +66,7 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_PDUMP)          += -lrte_pdump
 _LDLIBS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR)    += -lrte_distributor
 _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG)        += -lrte_ip_frag
 _LDLIBS-$(CONFIG_RTE_LIBRTE_GRO)            += -lrte_gro
+_LDLIBS-$(CONFIG_RTE_LIBRTE_GSO)            += -lrte_gso
 _LDLIBS-$(CONFIG_RTE_LIBRTE_METER)          += -lrte_meter
 _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lrte_sched
 _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM)            += -lrte_lpm
Signature · 1 line
1.9.3
#117 lore raw

PATCH v8 2/6 gso: add TCP/IPv4 GSO support

In reply to Mark Kavanagh

From: Jiayu Hu <[email protected]>

This patch adds GSO support for TCP/IPv4 packets. Supported packets may include a single VLAN tag. TCP/IPv4 GSO doesn't check if input packets have correct checksums, and doesn't update checksums for output packets (the responsibility for this lies with the application). Additionally, TCP/IPv4 GSO doesn't process IP fragmented packets.

TCP/IPv4 GSO uses two chained MBUFs, one direct MBUF and one indrect MBUF, to organize an output packet. Note that we refer to these two chained MBUFs as a two-segment MBUF. The direct MBUF stores the packet header, while the indirect mbuf simply points to a location within the original packet's payload. Consequently, use of the GSO library requires multi-segment MBUF support in the TX functions of the NIC driver.

If a packet is GSO'd, TCP/IPv4 GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst  |  12 +++
 lib/Makefile                            |   2 +-
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 153 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 141 +++++++++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               | 104 ++++++++++++++++++++++
 lib/librte_gso/gso_tcp4.h               |  74 +++++++++++++++
 lib/librte_gso/rte_gso.c                |  53 ++++++++++-
 lib/librte_gso/rte_gso.h                |   7 +-
 10 files changed, 543 insertions(+), 6 deletions(-)
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
doc/guides/rel_notes/release_17_11.rst +12 -0
index 5bb36b7..dd37169 100644
@@ -41,6 +41,18 @@ New Features
      Also, make sure to start the actual text at the margin.
      =========================================================
 
+* **Added the Generic Segmentation Offload Library.**
+
+  Added the Generic Segmentation Offload (GSO) library to enable
+  applications to split large packets (e.g. MTU is 64KB) into small
+  ones (e.g. MTU is 1500B). Supported packet types are:
+
+  * TCP/IPv4 packets.
+
+  The GSO library doesn't check if the input packets have correct
+  checksums, and doesn't update checksums for output packets.
+  Additionally, the GSO library doesn't process IP fragmented packets.
+
 
 Resolved Issues
 ---------------
lib/Makefile +1 -1
index 3d123f4..5ecd1b3 100644
@@ -109,7 +109,7 @@ DEPDIRS-librte_reorder := librte_eal librte_mempool librte_mbuf
 DIRS-$(CONFIG_RTE_LIBRTE_PDUMP) += librte_pdump
 DEPDIRS-librte_pdump := librte_eal librte_mempool librte_mbuf librte_ether
 DIRS-$(CONFIG_RTE_LIBRTE_GSO) += librte_gso
-DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net
+DEPDIRS-librte_gso := librte_eal librte_mbuf librte_ether librte_net librte_mempool
 
 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
 DIRS-$(CONFIG_RTE_LIBRTE_KNI) += librte_kni
lib/librte_eal/common/include/rte_log.h +1 -0
index ec8dba7..2fa1199 100644
@@ -87,6 +87,7 @@ struct rte_logs {
 #define RTE_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
 #define RTE_LOGTYPE_EFD       18 /**< Log related to EFD. */
 #define RTE_LOGTYPE_EVENTDEV  19 /**< Log related to eventdev. */
+#define RTE_LOGTYPE_GSO       20 /**< Log related to GSO. */
 
 /* these log types can be used in an application */
 #define RTE_LOGTYPE_USER1     24 /**< User-defined log type 1. */
lib/librte_gso/Makefile +2 -0
index aeaacbc..2be64d1 100644
@@ -42,6 +42,8 @@ LIBABIVER := 1
 
 #source files
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +153 -0

153 lines not on this page · raw message

lib/librte_gso/gso_common.h new file +141 -0

141 lines not on this page · raw message

lib/librte_gso/gso_tcp4.c new file +104 -0

104 lines not on this page · raw message

lib/librte_gso/gso_tcp4.h new file +74 -0

74 lines not on this page · raw message

lib/librte_gso/rte_gso.c +49 -4

68 lines not on this page · raw message

lib/librte_gso/rte_gso.h +6 -1
index 7d343d7..7ca2d81 100644
@@ -46,6 +46,10 @@
 #include <stdint.h>
 #include <rte_mbuf.h>
 
+/* Minimum GSO segment size. */
+#define RTE_GSO_SEG_SIZE_MIN (sizeof(struct ether_hdr) + \
+		sizeof(struct ipv4_hdr) + sizeof(struct tcp_hdr) + 1)
+
 /* GSO flags for rte_gso_ctx. */
 #define RTE_GSO_FLAG_IPID_FIXED (1ULL << 0)
 /**< Use fixed IP ids for output GSO segments. Setting
@@ -81,7 +85,8 @@ struct rte_gso_ctx {
 	 */
 	uint16_t gso_size;
 	/**< maximum size of an output GSO segment, including packet
-	 * header and payload, measured in bytes.
+	 * header and payload, measured in bytes. Must exceed
+	 * RTE_GSO_SEG_SIZE_MIN.
 	 */
 };
 
Signature · 1 line
1.9.3
#118 lore raw

PATCH v8 3/6 gso: add VxLAN GSO support

In reply to Mark Kavanagh

This patch adds a framework that allows GSO on tunneled packets. Furthermore, it leverages that framework to provide GSO support for VxLAN-encapsulated packets.

Supported VxLAN packets must have an outer IPv4 header (prepended by an optional VLAN tag), and contain an inner TCP/IPv4 packet (with an optional inner VLAN tag).

VxLAN GSO doesn't check if input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with TCP/IPv4 GSO, VxLAN GSO uses a two-segment MBUF to organize each output packet, which mandates support for multi-segment mbufs in the TX functions of the NIC driver. Also, if a packet is GSOed, VxLAN GSO reduces its MBUF refcnt by 1. As a result, when all of its GSO'd segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst |   2 +
 lib/librte_gso/Makefile                |   1 +
 lib/librte_gso/gso_common.h            |  25 +++++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 120 +++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_tunnel_tcp4.h       |  75 +++++++++++++++++++++
 lib/librte_gso/rte_gso.c               |  14 +++-
 6 files changed, 235 insertions(+), 2 deletions(-)
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
doc/guides/rel_notes/release_17_11.rst +2 -0
index dd37169..c58eeb1 100644
@@ -48,6 +48,8 @@ New Features
   ones (e.g. MTU is 1500B). Supported packet types are:
 
   * TCP/IPv4 packets.
+  * VxLAN packets, which must have an outer IPv4 header, and contain
+    an inner TCP/IPv4 packet.
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/Makefile +1 -0
index 2be64d1..e6d41df 100644
@@ -44,6 +44,7 @@ LIBABIVER := 1
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += rte_gso.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_common.c
 SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tcp4.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel_tcp4.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.h +25 -0
index a8ad638..95d54e7 100644
@@ -39,6 +39,7 @@
 #include <rte_mbuf.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
+#include <rte_udp.h>
 
 #define IS_FRAGMENTED(frag_off) (((frag_off) & IPV4_HDR_OFFSET_MASK) != 0 \
 		|| ((frag_off) & IPV4_HDR_MF_FLAG) == IPV4_HDR_MF_FLAG)
@@ -49,6 +50,30 @@
 #define IS_IPV4_TCP(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4)) == \
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4))
 
+#define IS_IPV4_VXLAN_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_VXLAN))
+
+/**
+ * Internal function which updates the UDP header of a packet, following
+ * segmentation. This is required to update the header's datagram length field.
+ *
+ * @param pkt
+ *  The packet containing the UDP header.
+ * @param udp_offset
+ *  The offset of the UDP header from the start of the packet.
+ */
+static inline void
+update_udp_header(struct rte_mbuf *pkt, uint16_t udp_offset)
+{
+	struct udp_hdr *udp_hdr;
+
+	udp_hdr = (struct udp_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			udp_offset);
+	udp_hdr->dgram_len = rte_cpu_to_be_16(pkt->pkt_len - udp_offset);
+}
+
 /**
  * Internal function which updates the TCP header of a packet, following
  * segmentation. This is required to update the header's 'sent' sequence
lib/librte_gso/gso_tunnel_tcp4.c new file +120 -0

120 lines not on this page · raw message

lib/librte_gso/gso_tunnel_tcp4.h new file +75 -0

75 lines not on this page · raw message

lib/librte_gso/rte_gso.c +12 -2
index e414df4..b4c3e34 100644
@@ -39,6 +39,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp4.h"
+#include "gso_tunnel_tcp4.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -56,7 +57,8 @@
 	if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
 			nb_pkts_out < 1 ||
 			gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN ||
-			gso_ctx->gso_types != DEV_TX_OFFLOAD_TCP_TSO)
+			((gso_ctx->gso_types & (DEV_TX_OFFLOAD_TCP_TSO |
+			DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) == 0))
 		return -EINVAL;
 
 	if (gso_ctx->gso_size >= pkt->pkt_len) {
@@ -71,12 +73,20 @@
 	ipid_delta = (gso_ctx->flag != RTE_GSO_FLAG_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_TCP(pkt->ol_flags)) {
+	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)
+		&& (gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) {
+		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
+		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else if (IS_IPV4_TCP(pkt->ol_flags) &&
+			(gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO)) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
 				pkts_out, nb_pkts_out);
 	} else {
+		/* unsupported packet, skip */
 		pkts_out[0] = pkt;
 		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
 		return 1;
Signature · 1 line
1.9.3
#119 lore raw

PATCH v8 4/6 gso: add GRE GSO support

In reply to Mark Kavanagh

This patch adds GSO support for GRE-tunneled packets. Supported GRE packets must contain an outer IPv4 header, and inner TCP/IPv4 headers. They may also contain a single VLAN tag. GRE GSO doesn't check if all input packets have correct checksums and doesn't update checksums for output packets. Additionally, it doesn't process IP fragmented packets.

As with VxLAN GSO, GRE GSO uses a two-segment MBUF to organize each output packet, which requires multi-segment mbuf support in the TX functions of the NIC driver. Also, if a packet is GSOed, GRE GSO reduces its MBUF refcnt by 1. As a result, when all of its GSOed segments are freed, the packet is freed automatically.

---
 doc/guides/rel_notes/release_17_11.rst |  2 ++
 lib/librte_gso/gso_common.h            |  5 +++++
 lib/librte_gso/gso_tunnel_tcp4.c       | 14 ++++++++++----
 lib/librte_gso/rte_gso.c               |  9 ++++++---
 4 files changed, 23 insertions(+), 7 deletions(-)
doc/guides/rel_notes/release_17_11.rst +2 -0
index c58eeb1..2faa630 100644
@@ -50,6 +50,8 @@ New Features
   * TCP/IPv4 packets.
   * VxLAN packets, which must have an outer IPv4 header, and contain
     an inner TCP/IPv4 packet.
+  * GRE packets, which must contain an outer IPv4 header, and inner
+    TCP/IPv4 headers.
 
   The GSO library doesn't check if the input packets have correct
   checksums, and doesn't update checksums for output packets.
lib/librte_gso/gso_common.h +5 -0
index 95d54e7..145ea49 100644
@@ -55,6 +55,11 @@
 		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
 		 PKT_TX_TUNNEL_VXLAN))
 
+#define IS_IPV4_GRE_TCP4(flag) (((flag) & (PKT_TX_TCP_SEG | PKT_TX_IPV4 | \
+				PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_GRE)) == \
+		(PKT_TX_TCP_SEG | PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | \
+		 PKT_TX_TUNNEL_GRE))
+
 /**
  * Internal function which updates the UDP header of a packet, following
  * segmentation. This is required to update the header's datagram length field.
lib/librte_gso/gso_tunnel_tcp4.c +10 -4
index 5e8c8e5..8d0cfd7 100644
@@ -42,11 +42,13 @@
 	struct tcp_hdr *tcp_hdr;
 	uint32_t sent_seq;
 	uint16_t outer_id, inner_id, tail_idx, i;
-	uint16_t outer_ipv4_offset, inner_ipv4_offset, udp_offset, tcp_offset;
+	uint16_t outer_ipv4_offset, inner_ipv4_offset;
+	uint16_t udp_gre_offset, tcp_offset;
+	uint8_t update_udp_hdr;
 
 	outer_ipv4_offset = pkt->outer_l2_len;
-	udp_offset = outer_ipv4_offset + pkt->outer_l3_len;
-	inner_ipv4_offset = udp_offset + pkt->l2_len;
+	udp_gre_offset = outer_ipv4_offset + pkt->outer_l3_len;
+	inner_ipv4_offset = udp_gre_offset + pkt->l2_len;
 	tcp_offset = inner_ipv4_offset + pkt->l3_len;
 
 	/* Outer IPv4 header. */
@@ -63,9 +65,13 @@
 	sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
 	tail_idx = nb_segs - 1;
 
+	/* Only update UDP header for VxLAN packets. */
+	update_udp_hdr = (pkt->ol_flags & PKT_TX_TUNNEL_VXLAN) ? 1 : 0;
+
 	for (i = 0; i < nb_segs; i++) {
 		update_ipv4_header(segs[i], outer_ipv4_offset, outer_id);
-		update_udp_header(segs[i], udp_offset);
+		if (update_udp_hdr)
+			update_udp_header(segs[i], udp_gre_offset);
 		update_ipv4_header(segs[i], inner_ipv4_offset, inner_id);
 		update_tcp_header(segs[i], tcp_offset, sent_seq, i < tail_idx);
 		outer_id++;
lib/librte_gso/rte_gso.c +6 -3
index b4c3e34..4fc2dd2 100644
@@ -58,7 +58,8 @@
 			nb_pkts_out < 1 ||
 			gso_ctx->gso_size < RTE_GSO_SEG_SIZE_MIN ||
 			((gso_ctx->gso_types & (DEV_TX_OFFLOAD_TCP_TSO |
-			DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) == 0))
+			DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
+			DEV_TX_OFFLOAD_GRE_TNL_TSO)) == 0))
 		return -EINVAL;
 
 	if (gso_ctx->gso_size >= pkt->pkt_len) {
@@ -73,8 +74,10 @@
 	ipid_delta = (gso_ctx->flag != RTE_GSO_FLAG_IPID_FIXED);
 	ol_flags = pkt->ol_flags;
 
-	if (IS_IPV4_VXLAN_TCP4(pkt->ol_flags)
-		&& (gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) {
+	if ((IS_IPV4_VXLAN_TCP4(pkt->ol_flags) &&
+			(gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) ||
+			((IS_IPV4_GRE_TCP4(pkt->ol_flags) &&
+			 (gso_ctx->gso_types & DEV_TX_OFFLOAD_GRE_TNL_TSO)))) {
 		pkt->ol_flags &= (~PKT_TX_TCP_SEG);
 		ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
Signature · 1 line
1.9.3
#120 lore raw

v8 cover Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

In reply to Mark Kavanagh

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception that the tunnel type created for both the guest's virtio-net, and the host's kernel interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received on P1, is less than 500B.

Change log
==========
v8:
- resolve coding style infractions (indentation).
- centralize invalid parameter checking for rte_gso_segment() into a single 'if' statement.
- don't clear PKT_TX_TCP_SEG flag for packets that don't qualify for GSO on account of invalid params.
- allow GSO for tunneled packets only via gso_ctx (by correcting 'if' statement condition).

v7:
- add RTE_GSO_SEG_SIZE_MIN macro; use this to validate gso_ctx.gso_segsz.
- rename 'ipid_flag' member of gso_ctx to 'flag'.
- remove mention of VLAN tags in supported packet types.
- don't clear PKT_TX_TCP_SEG flag if GSO fails.
- take all packet overhead into account when checking for empty packet.
- ensure that only enabled GSO types are enacted upon (i.e. no fall-through to TCP/IPv4 case from tunneled case).
- validate user-supplied gso segsz arg against RTE_GSO_SEG_SIZE_MIN in testpmd.
- simplify error-checking/handling for GSO failure case in testpmd csum engine.
- use 0 instead of !RTE_GSO_IPID_FIXED in testpmd.

v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

 MAINTAINERS                                        |   6 +
 app/test-pmd/cmdline.c                             | 179 ++++++++
 app/test-pmd/config.c                              |  24 ++
 app/test-pmd/csumonly.c                            |  42 +-
 app/test-pmd/testpmd.c                             |  13 +
 app/test-pmd/testpmd.h                             |  10 +
 config/common_base                                 |   5 +
 doc/api/doxy-api-index.md                          |   1 +
 doc/api/doxy-api.conf                              |   1 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 doc/guides/rel_notes/release_17_11.rst             |  17 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst        |  46 ++
 lib/Makefile                                       |   2 +
 lib/librte_eal/common/include/rte_log.h            |   1 +
 lib/librte_gso/Makefile                            |  52 +++
 lib/librte_gso/gso_common.c                        | 153 +++++++
 lib/librte_gso/gso_common.h                        | 171 ++++++++
 lib/librte_gso/gso_tcp4.c                          | 104 +++++
 lib/librte_gso/gso_tcp4.h                          |  74 ++++
 lib/librte_gso/gso_tunnel_tcp4.c                   | 126 ++++++
 lib/librte_gso/gso_tunnel_tcp4.h                   |  75 ++++
 lib/librte_gso/rte_gso.c                           | 110 +++++
 lib/librte_gso/rte_gso.h                           | 148 +++++++
 lib/librte_gso/rte_gso_version.map                 |   7 +
 mk/rte.app.mk                                      |   1 +
 28 files changed, 2411 insertions(+), 4 deletions(-)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map
Signature · 1 line
1.9.3
#121 lore raw

Re: [PATCH v8 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Hi Mark,

Quoted 104 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, October 5, 2017 4:44 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Ananyev, Konstantin <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B <[email protected]>
Subject: [PATCH v8 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception that the tunnel type created for both the guest's virtio-net, and the host's kernel interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received on P1, is less than 500B.

Quoted 10 lines

Change log
==========
v8:
- resolve coding style infractions (indentation).
- centralize invalid parameter checking for rte_gso_segment() into a single 'if' statement.
- don't clear PKT_TX_TCP_SEG flag for packets that don't qualify for GSO on account of invalid params.
- allow GSO for tunneled packets only via gso_ctx (by correcting 'if' statement condition).

Last (hopefully :)) few nits from me:
1. [dpdk-dev,v8,5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO I686 build fails for me, I think you need to:

app/test-pmd/cmdline.c +1 -1
@@ -4052,7 +4052,7 @@ cmd_gso_size_parsed(void *parsed_result,
        if (!strcmp(res->cmd_keyword, "gso") &&
                        !strcmp(res->cmd_segsz, "segsz")) {
                if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
-                       printf("gso_size should be larger than %lu."
+                       printf("gso_size should be larger than %zu."
                                        " Please input a legal value\n",
                                        RTE_GSO_SEG_SIZE_MIN);
                else

2. [dpdk-dev,v8,2/6] gso: add TCP/IPv4 GSO support

int
rte_gso_segment(struct rte_mbuf *pkt,
...
+ } else {
+ pkts_out[0] = pkt;
+ RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
+ return 1;
+ }
+

I still think that log level should be DEBUG here. Konstantin

Quoted 115 lines

v7:
- add RTE_GSO_SEG_SIZE_MIN macro; use this to validate gso_ctx.gso_segsz.
- rename 'ipid_flag' member of gso_ctx to 'flag'.
- remove mention of VLAN tags in supported packet types.
- don't clear PKT_TX_TCP_SEG flag if GSO fails.
- take all packet overhead into account when checking for empty packet.
- ensure that only enabled GSO types are enacted upon (i.e. no fall-through to TCP/IPv4 case from tunneled case).
- validate user-supplied gso segsz arg against RTE_GSO_SEG_SIZE_MIN in testpmd.
- simplify error-checking/handling for GSO failure case in testpmd csum engine.
- use 0 instead of !RTE_GSO_IPID_FIXED in testpmd.

v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

 MAINTAINERS                                        |   6 +
 app/test-pmd/cmdline.c                             | 179 ++++++++
 app/test-pmd/config.c                              |  24 ++
 app/test-pmd/csumonly.c                            |  42 +-
 app/test-pmd/testpmd.c                             |  13 +
 app/test-pmd/testpmd.h                             |  10 +
 config/common_base                                 |   5 +
 doc/api/doxy-api-index.md                          |   1 +
 doc/api/doxy-api.conf                              |   1 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477 +++++++++++++++++++++
 doc/guides/prog_guide/index.rst                    |   1 +
 doc/guides/rel_notes/release_17_11.rst             |  17 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst        |  46 ++
 lib/Makefile                                       |   2 +
 lib/librte_eal/common/include/rte_log.h            |   1 +
 lib/librte_gso/Makefile                            |  52 +++
 lib/librte_gso/gso_common.c                        | 153 +++++++
 lib/librte_gso/gso_common.h                        | 171 ++++++++
 lib/librte_gso/gso_tcp4.c                          | 104 +++++
 lib/librte_gso/gso_tcp4.h                          |  74 ++++
 lib/librte_gso/gso_tunnel_tcp4.c                   | 126 ++++++
 lib/librte_gso/gso_tunnel_tcp4.h                   |  75 ++++
 lib/librte_gso/rte_gso.c                           | 110 +++++
 lib/librte_gso/rte_gso.h                           | 148 +++++++
 lib/librte_gso/rte_gso_version.map                 |   7 +
 mk/rte.app.mk                                      |   1 +
 28 files changed, 2411 insertions(+), 4 deletions(-)
 create mode 100644 doc/guides/prog_guide/generic_segmentation_offload_lib.rst
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map

--
1.9.3

#122 lore raw

Re: [PATCH v8 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Quoted 111 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, October 5, 2017 6:12 PM
To: Kavanagh, Mark B <[email protected]>; [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Subject: RE: [PATCH v8 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Hi Mark,

Quoted 5 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, October 5, 2017 4:44 PM
To: [email protected]
Cc: Hu, Jiayu <[email protected]>; Tan, Jianfeng <[email protected]>;

Ananyev, Konstantin <[email protected]>; Yigit,

Quoted 1 line

Ferruh <[email protected]>; [email protected]; Kavanagh, Mark B

<[email protected]>

Quoted 84 lines

Subject: [PATCH v8 0/6] Support TCP/IPv4, VxLAN, and GRE GSO in DPDK

Generic Segmentation Offload (GSO) is a SW technique to split large packets into small ones. Akin to TSO, GSO enables applications to operate on large packets, thus reducing per-packet processing overhead.

To enable more flexibility to applications, DPDK GSO is implemented as a standalone library. Applications explicitly use the GSO library to segment packets. This patch adds GSO support to DPDK for specific packet types: specifically, TCP/IPv4, VxLAN, and GRE.

The first patch introduces the GSO API framework. The second patch adds GSO support for TCP/IPv4 packets (containing an optional VLAN tag). The third patch adds GSO support for VxLAN packets that contain outer IPv4, and inner TCP/IPv4 headers (plus optional inner and/or outer VLAN tags). The fourth patch adds GSO support for GRE packets that contain outer IPv4, and inner TCP/IPv4 headers (with optional outer VLAN tag). The fifth patch in the series enables TCP/IPv4, VxLAN, and GRE GSO in testpmd's checksum forwarding engine. The final patch in the series adds GSO documentation to the programmer's guide.

Performance Testing
===================
The performance of TCP/IPv4 GSO on a 10Gbps link is demonstrated using iperf. Setup for the test is described as follows:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine with "retry".
c. Select IP and TCP HW checksum calculation for P0; select TCP HW
checksum calculation for vhost-user port.
d. Launch a VM with csum and tso offloading enabled.
e. Run iperf-client on virtio-net port in the VM to send TCP packets.
With enabling csum and tso, the VM can send large TCP/IPv4 packets (mss is up to 64KB).
f. P1 is assigned to linux kernel and enabled kernel GRO. Run
iperf-server on P1.

We conduct three iperf tests:

test-1: enable GSO for P0 in testpmd, and set max GSO segment length
to 1518B. Run two iperf-client in the VM.
test-2: enable TSO for P0 in testpmd, and set TSO segsz to 1518B. Run
two iperf-client in the VM.
test-3: disable GSO and TSO in testpmd. Run two iperf-client in the VM.

Throughput of the above three tests:

test-1: 9.4Gbps
test-2: 9.5Gbps
test-3: 3Mbps

Functional Testing
==================
Unlike TCP packets, VMs can't send large VxLAN or GRE packets. The max length of tunneled packets from VMs is 1514B. So current experiment method can't be used to measure VxLAN and GRE GSO performance, but simply test the functionality via setting small GSO segment length (e.g. 500B).

VxLAN
-----
To test VxLAN GSO functionality, we use the following setup:

a. Connect 2 x 10Gbps physical ports (P0, P1), which are in the same
machine, together physically.
b. Launch testpmd with P0 and a vhost-user port, and use csum forwarding
engine with "retry".
c. Testpmd commands:
- csum parse_tunnel on "P0"
- csum parse_tunnel on "vhost-user port"
- csum set outer-ip hw "P0"
- csum set ip hw "P0"
- csum set tcp hw "P0"
- csum set tcp hw "vhost-user port"
- set port "P0" gso on
- set gso segsz 500
d. Launch a VM with csum and tso offloading enabled.
e. Create a vxlan port for the virtio-net port in the VM. Run iperf-client
on the VxLAN port, so TCP packets are VxLAN encapsulated. However, the max packet length is 1514B.
f. P1 is assigned to linux kernel and kernel GRO is disabled. Similarly,
create a VxLAN port for P1, and run iperf-server on the VxLAN port.

Quoted 7 lines

In testpmd, we can see the length of all packets sent from P0 is smaller than or equal to 500B. Additionally, the packets arriving in P1 is encapsulated and is smaller than or equal to 500B.

GRE
---
The same process may be used to test GRE functionality, with the exception

Quoted 21 lines

that

Quoted 1 line

the tunnel type created for both the guest's virtio-net, and the host's

kernel

Quoted 4 lines

interfaces is GRE:
ip tunnel add <gre tunnel> mode gre remote <remote IP> local <local_ip>

As in the VxLAN testcase, the length of packets sent from P0, and received

on

Quoted 12 lines

P1, is less than 500B.

Change log
==========
v8:
- resolve coding style infractions (indentation).
- centralize invalid parameter checking for rte_gso_segment() into a single 'if' statement.
- don't clear PKT_TX_TCP_SEG flag for packets that don't qualify for GSO on account of invalid params.
- allow GSO for tunneled packets only via gso_ctx (by correcting 'if' statement condition).

Hey Konstantin,

Quoted 1 line

Last (hopefully :)) few nits from me:

No worries! :)

Quoted 2 lines

1. [dpdk-dev,v8,5/6] app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO I686 build fails for me, I think you need to:

Oh wow - sorry about that. I hadn't considered building for that target to be honest - thanks for both the catch, and the fix!

Quoted 25 lines
app/test-pmd/cmdline.c +1 -1
@@ -4052,7 +4052,7 @@ cmd_gso_size_parsed(void *parsed_result,
       if (!strcmp(res->cmd_keyword, "gso") &&
                       !strcmp(res->cmd_segsz, "segsz")) {
               if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN)
-                       printf("gso_size should be larger than %lu."
+                       printf("gso_size should be larger than %zu."
                                       " Please input a legal value\n",
                                       RTE_GSO_SEG_SIZE_MIN);
               else

2. [dpdk-dev,v8,2/6] gso: add TCP/IPv4 GSO support

int
rte_gso_segment(struct rte_mbuf *pkt,
...

app/test-pmd/cmdline.c +6 -0
+	} else {
+		pkts_out[0] = pkt;
+		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
+		return 1;
+	}
+
Quoted 2 lines

I still think that log level should be DEBUG here. Konstantin

No problem. If you pointed that out earlier I certainly missed it - apologies!

Many thanks again,
Mark

Quoted 121 lines
Quoted 9 lines

v7:
- add RTE_GSO_SEG_SIZE_MIN macro; use this to validate gso_ctx.gso_segsz.
- rename 'ipid_flag' member of gso_ctx to 'flag'.
- remove mention of VLAN tags in supported packet types.
- don't clear PKT_TX_TCP_SEG flag if GSO fails.
- take all packet overhead into account when checking for empty packet.
- ensure that only enabled GSO types are enacted upon (i.e. no fall-through

to

Quoted 2 lines

TCP/IPv4 case from tunneled case).
- validate user-supplied gso segsz arg against RTE_GSO_SEG_SIZE_MIN in

testpmd.

Quoted 1 line

- simplify error-checking/handling for GSO failure case in testpmd csum

engine.

Quoted 59 lines

- use 0 instead of !RTE_GSO_IPID_FIXED in testpmd.

v6:
- rebase to HEAD of master (i5dce9fcA)
- remove 'l3_offset' parameter from 'update_ipv4_tcp_headers'

v5:
- add GSO section to the programmer's guide.
- use MF or (previously 'and') offset to check if a packet is IP fragmented.
- move 'update_header' helper functions to gso_common.h.
- move txp/ipv4 'update_header' function to gso_tcp4.c.
- move tunnel 'update_header' function to gso_tunnel_tcp4.c.
- add offset parameter to 'update_header' functions.
- combine GRE and VxLAN tunnel header update functions into a single function.
- correct typos and errors in comments/commit messages.

v4:
- use ol_flags instead of packet_type to decide which segmentation function to use.
- use MF and offset to check if a packet is IP fragmented, instead of using DF.
- remove ETHER_CRC_LEN from gso segment payload length calculation.
- refactor internal header update and other functions.
- remove RTE_GSO_IPID_INCREASE.
- add some of GSO documents.
- set the default GSO length to 1514 and fill PKT_TX_TCP_SEG for the packets sent from GSO-enabled ports in testpmd.
v3:
- support all IPv4 header flags, including RTE_PTYPE_(INNER_)L3_IPV4, RTE_PTYPE_(INNER_)L3_IPV4_EXT and RTE_PTYPE_(INNER_)L3_IPV4_EXT_ UNKNOWN.
- fill mbuf->packet_type instead of using rte_net_get_ptype() in csumonly.c, since rte_net_get_ptype() doesn't support vxlan.
- store the input packet into pkts_out inside gso_tcp4_segment() and gso_tunnel_tcp4_segment() instead of rte_gso_segment(), when no GSO is performed.
- add missing incldues.
- optimize file names, function names and function description.
- fix one bug in testpmd.
v2:
- merge data segments whose data_len is less than mss into a large data segment in gso_do_segment().
- use mbuf->packet_type/l2_len/l3_len etc. instead of parsing the packet header in rte_gso_segment().
- provide IP id macros for applications to select fixed or incremental IP ids.

Jiayu Hu (3):
gso: add Generic Segmentation Offload API framework
gso: add TCP/IPv4 GSO support
app/testpmd: enable TCP/IPv4, VxLAN and GRE GSO

Mark Kavanagh (3):
gso: add VxLAN GSO support
gso: add GRE GSO support
doc: add GSO programmer's guide

Quoted 12 lines
 MAINTAINERS                                        |   6 +
 app/test-pmd/cmdline.c                             | 179 ++++++++
 app/test-pmd/config.c                              |  24 ++
 app/test-pmd/csumonly.c                            |  42 +-
 app/test-pmd/testpmd.c                             |  13 +
 app/test-pmd/testpmd.h                             |  10 +
 config/common_base                                 |   5 +
 doc/api/doxy-api-index.md                          |   1 +
 doc/api/doxy-api.conf                              |   1 +
 .../generic_segmentation_offload_lib.rst           | 256 +++++++++++
 .../prog_guide/img/gso-output-segment-format.svg   | 313 ++++++++++++++
 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg   | 477

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

Quoted 10 lines
 doc/guides/prog_guide/index.rst                    |   1 +
 doc/guides/rel_notes/release_17_11.rst             |  17 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst        |  46 ++
 lib/Makefile                                       |   2 +
 lib/librte_eal/common/include/rte_log.h            |   1 +
 lib/librte_gso/Makefile                            |  52 +++
 lib/librte_gso/gso_common.c                        | 153 +++++++
 lib/librte_gso/gso_common.h                        | 171 ++++++++
 lib/librte_gso/gso_tcp4.c                          | 104 +++++
 lib/librte_gso/gso_tcp4.h                          |  74 ++++
Quoted 8 lines
 lib/librte_gso/gso_tunnel_tcp4.c                   | 126 ++++++
 lib/librte_gso/gso_tunnel_tcp4.h                   |  75 ++++
 lib/librte_gso/rte_gso.c                           | 110 +++++
 lib/librte_gso/rte_gso.h                           | 148 +++++++
 lib/librte_gso/rte_gso_version.map                 |   7 +
 mk/rte.app.mk                                      |   1 +
 28 files changed, 2411 insertions(+), 4 deletions(-)
 create mode 100644

doc/guides/prog_guide/generic_segmentation_offload_lib.rst

Quoted 15 lines
 create mode 100644 doc/guides/prog_guide/img/gso-output-segment-format.svg
 create mode 100644 doc/guides/prog_guide/img/gso-three-seg-mbuf.svg
 create mode 100644 lib/librte_gso/Makefile
 create mode 100644 lib/librte_gso/gso_common.c
 create mode 100644 lib/librte_gso/gso_common.h
 create mode 100644 lib/librte_gso/gso_tcp4.c
 create mode 100644 lib/librte_gso/gso_tcp4.h
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.c
 create mode 100644 lib/librte_gso/gso_tunnel_tcp4.h
 create mode 100644 lib/librte_gso/rte_gso.c
 create mode 100644 lib/librte_gso/rte_gso.h
 create mode 100644 lib/librte_gso/rte_gso_version.map

--
1.9.3