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 1 of 3

lore
Share & tools
lore

Jiayu Hu

author
#0 lore raw

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 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), together physically. b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine.
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 GSO enabled for P0 in testpmd, observed iperf throughput is ~9Gbps. The experimental data of VxLAN and GRE will be shown later.

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

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

 app/test-pmd/cmdline.c                  | 121 +++++++++
 app/test-pmd/config.c                   |  25 ++
 app/test-pmd/csumonly.c                 |  68 ++++-
 app/test-pmd/testpmd.c                  |   9 +
 app/test-pmd/testpmd.h                  |  10 +
 config/common_base                      |   5 +
 lib/Makefile                            |   2 +
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |  52 ++++
 lib/librte_gso/gso_common.c             | 431 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 180 +++++++++++++
 lib/librte_gso/gso_tcp.c                |  82 ++++++
 lib/librte_gso/gso_tcp.h                |  73 ++++++
 lib/librte_gso/gso_tunnel.c             |  62 +++++
 lib/librte_gso/gso_tunnel.h             |  46 ++++
 lib/librte_gso/rte_gso.c                | 100 ++++++++
 lib/librte_gso/rte_gso.h                | 122 +++++++++
 lib/librte_gso/rte_gso_version.map      |   7 +
 mk/rte.app.mk                           |   1 +
 19 files changed, 1392 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_tcp.c
 create mode 100644 lib/librte_gso/gso_tcp.h
 create mode 100644 lib/librte_gso/gso_tunnel.c
 create mode 100644 lib/librte_gso/gso_tunnel.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
#1 lore raw

PATCH 1/5 lib: 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. This patch introduces the GSO API framework to DPDK.

The GSO library provides a segmentation API, rte_gso_segment(), for applications. It 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. When all GSO segments are freed, the input packet is freed automatically.

---
 config/common_base                 |   5 ++
 lib/Makefile                       |   2 +
 lib/librte_gso/Makefile            |  49 ++++++++++++++++
 lib/librte_gso/rte_gso.c           |  47 ++++++++++++++++
 lib/librte_gso/rte_gso.h           | 111 +++++++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map |   7 +++
 mk/rte.app.mk                      |   1 +
 7 files changed, 222 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
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 +47 -0

47 lines not on this page · raw message

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

111 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
#2 lore raw

Re: [PATCH 1/5] lib: add Generic Segmentation Offload API framework

Hi Jiayu,

Quoted 228 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 introduces the GSO API framework to DPDK.

The GSO library provides a segmentation API, rte_gso_segment(), for applications. It 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. When all GSO segments are freed, the input packet is freed automatically.

---
 config/common_base                 |   5 ++
 lib/Makefile                       |   2 +
 lib/librte_gso/Makefile            |  49 ++++++++++++++++
 lib/librte_gso/rte_gso.c           |  47 ++++++++++++++++
 lib/librte_gso/rte_gso.h           | 111 +++++++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map |   7 +++
 mk/rte.app.mk                      |   1 +
 7 files changed, 222 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
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 +47 -0
new file mode 100644
index 0000000..b81afce
@@ -0,0 +1,47 @@
+/*-
+ *   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_gso.h"
+
+int
+rte_gso_segment(struct rte_mbuf *pkt,
+		struct rte_gso_ctx gso_ctx,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out __rte_unused)
+{
+	if (pkt == NULL || pkts_out == NULL || gso_ctx.direct_pool ==
+			NULL || gso_ctx.indirect_pool == NULL)
+		return -EINVAL;
+
+	return 1;
+}
lib/librte_gso/rte_gso.h new file +54 -0
new file mode 100644
index 0000000..5a8389a
@@ -0,0 +1,111 @@
+/*-
+ *   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 context structure.
+ */
+struct rte_gso_ctx {
+	struct rte_mempool *direct_pool;
+	/**< MBUF pool for allocating direct buffers, which are used

lib/librte_gso/rte_gso.h line 64

Quoted 10 lines
lib/librte_gso/rte_gso.h new file +10 -0
+	 * 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 gso_types;
+	/**< GSO types to perform */

Looking at the way it is used right now - there seems not much value in it... Why not to make it a mask of ptypes for which GSO should be perfomed? Let say for gso_ctx that supports only ip4/tcp it would be:
gso_types = (RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP) and then in rte_gso_segment() we can perfom gso only on packets of requested ptype:

if ((pkt->packet_type & gso_ctx->gso_types) == pkt->packet_type) {
/* do segmentation */
} else {
/* skip segmentation for that packet */
}

lib/librte_gso/rte_gso.h line 66

Quoted 2 lines
lib/librte_gso/rte_gso.h new file +2 -0
+	uint16_t gso_size;
+	/**< maximum size of a GSO segment, measured in bytes */

Is that MSS or MTU?

Quoted 22 lines
lib/librte_gso/rte_gso.h new file +22 -0
+};
+
+/**
+ * Segmentation function, which supports processing of both single- and
+ * multi- segment packets. rte_gso_segment() assumes the input packet
+ * has correct checksums, and it doesn't process IP fragment packets.
+ * Additionally, it assumes that 'pkts_out' is large enough to hold all GSO
+ * segments.
+ *
+ * We refer to the packets that are segmented from the input packet as 'GSO
+ * segments'. If the input packet is GSOed, its mbuf refcnt reduces by 1.
+ * Therefore, when all GSO segments are freed, the input packet is freed
+ * automatically. If the input packet doesn't match the criteria for GSO
+ * (e.g. 'pkt's length is small and doesn't need segmentation), the packet
+ * is skipped and this function returns 1. If the available memory space
+ * in MBUF pools is insufficient, the packet is skipped and return -ENOMEM.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param ctx
+ *  GSO context object.
+ * @param pkts_out

lib/librte_gso/rte_gso.h line 98

Quoted 10 lines
lib/librte_gso/rte_gso.h new file +10 -0
+ *  Pointer array used to stores the mbuf addresses of GSO segments.
+ *  Applications must ensure pkts_out is large enough to hold all GSO
+ *  segments. If the memory space in pkts_out is insufficient, the input
+ *  packet is skipped and return -EINVAL.
+ * @param nb_pkts_out
+ *  The max number of items that pkts_out can keep.
+ *
+ * @return
+ *  - The number of GSO segments created on success.
+ *  - Return 1 if no GSO is performed.

Wouldn't it be better to return number of elems filled in pkts_out[] on success?

Quoted 40 lines
lib/librte_gso/rte_gso.h new file +13 -0
+ *  - Return -ENOMEM if run out of memory in MBUF pools.
+ *  - Return -EINVAL for invalid parameters.
+ */
+int rte_gso_segment(struct rte_mbuf *pkt,
+		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
--

2.7.4

author
#3 lore raw

Re: [PATCH 1/5] lib: add Generic Segmentation Offload API framework

Hi Konstantin,

Quoted 247 lines · Konstantin

Hi Jiayu,

Quoted 228 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 introduces the GSO API framework to DPDK.

The GSO library provides a segmentation API, rte_gso_segment(), for applications. It 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. When all GSO segments are freed, the input packet is freed automatically.

---
 config/common_base                 |   5 ++
 lib/Makefile                       |   2 +
 lib/librte_gso/Makefile            |  49 ++++++++++++++++
 lib/librte_gso/rte_gso.c           |  47 ++++++++++++++++
 lib/librte_gso/rte_gso.h           | 111 +++++++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map |   7 +++
 mk/rte.app.mk                      |   1 +
 7 files changed, 222 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
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 +47 -0
new file mode 100644
index 0000000..b81afce
@@ -0,0 +1,47 @@
+/*-
+ *   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_gso.h"
+
+int
+rte_gso_segment(struct rte_mbuf *pkt,
+		struct rte_gso_ctx gso_ctx,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out __rte_unused)
+{
+	if (pkt == NULL || pkts_out == NULL || gso_ctx.direct_pool ==
+			NULL || gso_ctx.indirect_pool == NULL)
+		return -EINVAL;
+
+	return 1;
+}
lib/librte_gso/rte_gso.h new file +54 -0
new file mode 100644
index 0000000..5a8389a
@@ -0,0 +1,111 @@
+/*-
+ *   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 context structure.
+ */
+struct rte_gso_ctx {
+	struct rte_mempool *direct_pool;
+	/**< MBUF pool for allocating direct buffers, which are used

lib/librte_gso/rte_gso.h line 64

Quoted 10 lines
lib/librte_gso/rte_gso.h new file +10 -0
+	 * 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 gso_types;
+	/**< GSO types to perform */

Looking at the way it is used right now - there seems not much value in it... Why not to make it a mask of ptypes for which GSO should be perfomed? Let say for gso_ctx that supports only ip4/tcp it would be:
gso_types = (RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP) and then in rte_gso_segment() we can perfom gso only on packets of requested ptype:

Quoted 5 lines
if ((pkt->packet_type & gso_ctx->gso_types) == pkt->packet_type) {
   /* do segmentation */
} else {

/* skip segmentation for that packet */
}

Yes, you are right. It's unnecessary to define GRO type macros. We can reuse ptype. I will change it in the next version.

Quoted 5 lines

lib/librte_gso/rte_gso.h line 66

Quoted 3 lines
lib/librte_gso/rte_gso.h new file +2 -0
+	uint16_t gso_size;
+	/**< maximum size of a GSO segment, measured in bytes */

Is that MSS or MTU?

MSS. It's the max length of a complete packet, including packet headers.

Quoted 27 lines
Quoted 27 lines
lib/librte_gso/rte_gso.h new file +26 -0
+};
+
+/**
+ * Segmentation function, which supports processing of both single- and
+ * multi- segment packets. rte_gso_segment() assumes the input packet
+ * has correct checksums, and it doesn't process IP fragment packets.
+ * Additionally, it assumes that 'pkts_out' is large enough to hold all GSO
+ * segments.
+ *
+ * We refer to the packets that are segmented from the input packet as 'GSO
+ * segments'. If the input packet is GSOed, its mbuf refcnt reduces by 1.
+ * Therefore, when all GSO segments are freed, the input packet is freed
+ * automatically. If the input packet doesn't match the criteria for GSO
+ * (e.g. 'pkt's length is small and doesn't need segmentation), the packet
+ * is skipped and this function returns 1. If the available memory space
+ * in MBUF pools is insufficient, the packet is skipped and return -ENOMEM.
+ *
+ * @param pkt
+ *  The packet mbuf to segment.
+ * @param ctx
+ *  GSO context object.
+ * @param pkts_out
+ *  Pointer array used to stores the mbuf addresses of GSO segments.
+ *  Applications must ensure pkts_out is large enough to hold all GSO
+ *  segments. If the memory space in pkts_out is insufficient, the input
+ *  packet is skipped and return -EINVAL.
Quoted 8 lines

lib/librte_gso/rte_gso.h line 98

Quoted 6 lines
lib/librte_gso/rte_gso.h new file +6 -0
+ * @param nb_pkts_out
+ *  The max number of items that pkts_out can keep.
+ *
+ * @return
+ *  - The number of GSO segments created on success.
+ *  - Return 1 if no GSO is performed.

Wouldn't it be better to return number of elems filled in pkts_out[] on success?

Agree. I will change it.

Quoted 41 lines
Quoted 41 lines
lib/librte_gso/rte_gso.h new file +13 -0
+ *  - Return -ENOMEM if run out of memory in MBUF pools.
+ *  - Return -EINVAL for invalid parameters.
+ */
+int rte_gso_segment(struct rte_mbuf *pkt,
+		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
--

2.7.4

author
#4 lore raw

PATCH 2/5 gso/lib: 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 assumes that all 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.

---
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 270 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 120 ++++++++++++++
 lib/librte_gso/gso_tcp.c                |  82 ++++++++++
 lib/librte_gso/gso_tcp.h                |  73 +++++++++
 lib/librte_gso/rte_gso.c                |  44 +++++-
 lib/librte_gso/rte_gso.h                |   3 +
 8 files changed, 593 insertions(+), 2 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_tcp.c
 create mode 100644 lib/librte_gso/gso_tcp.h
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..0f8e38f 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_tcp.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +270 -0

270 lines not on this page · raw message

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

120 lines not on this page · raw message

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

82 lines not on this page · raw message

lib/librte_gso/gso_tcp.h new file +73 -0

73 lines not on this page · raw message

lib/librte_gso/rte_gso.c +42 -2

59 lines not on this page · raw message

lib/librte_gso/rte_gso.h +3 -0
index 5a8389a..77853fa 100644
@@ -46,6 +46,9 @@ extern "C" {
 #include <stdint.h>
 #include <rte_mbuf.h>
 
+#define RTE_GSO_TCP_IPV4 (1ULL << 0)
+/**< GSO flag for TCP/IPv4 packets (containing optional VLAN tag) */
+
 /**
  * GSO context structure.
  */
Signature · 1 line
2.7.4
#5 lore raw

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

Quoted 134 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, August 24, 2017 3:16 PM
To: [email protected]
Cc: Kavanagh, Mark B <[email protected]>; Ananyev, Konstantin <[email protected]>; Tan, Jianfeng <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH 2/5] gso/lib: 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 assumes that all 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.

---
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 270 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 120 ++++++++++++++
 lib/librte_gso/gso_tcp.c                |  82 ++++++++++
 lib/librte_gso/gso_tcp.h                |  73 +++++++++
 lib/librte_gso/rte_gso.c                |  44 +++++-
 lib/librte_gso/rte_gso.h                |   3 +
 8 files changed, 593 insertions(+), 2 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_tcp.c
 create mode 100644 lib/librte_gso/gso_tcp.h
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..0f8e38f 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_tcp.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +59 -0
new file mode 100644
index 0000000..2b54fbd
@@ -0,0 +1,270 @@
+/*-
+ *   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 <string.h>
+
+#include <rte_malloc.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 packet header */
+	rte_memcpy(rte_pktmbuf_mtod(hdr_segment, char *),
+			rte_pktmbuf_mtod(pkt, char *),

lib/librte_gso/gso_common.c line 69

Quoted 10 lines
lib/librte_gso/gso_common.c new file +10 -0
+			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_detach(pkts[i]->next);

I don't think you need to call detach() here explicitly. Just rte_pktmbuf_free(pkts[i]) should do I think.

Quoted 39 lines
lib/librte_gso/gso_common.c new file +39 -0
+		rte_pktmbuf_free(pkts[i]);
+		pkts[i] = NULL;
+	}
+}
+
+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;
+	uint32_t pkt_in_pyld_off;
+	uint16_t pkt_in_segment_len, pkt_out_segment_len;
+	uint16_t nb_segs;
+	bool pkt_in_segment_processed;
+
+	pkt_in_pyld_off = pkt->data_off + pkt_hdr_offset;
+	pkt_in = pkt;
+	nb_segs = 0;
+
+	while (pkt_in) {
+		pkt_in_segment_processed = false;
+		pkt_in_segment_len = pkt_in->data_off + pkt_in->data_len;
+
+		while (!pkt_in_segment_processed) {
+			if (unlikely(nb_segs >= nb_pkts_out)) {
+				free_gso_segment(pkts_out, nb_segs);
+				return -EINVAL;
+			}
+
+			/* allocate direct mbuf */
+			hdr_segment = rte_pktmbuf_alloc(direct_pool);
+			if (unlikely(hdr_segment == NULL)) {
+				free_gso_segment(pkts_out, nb_segs);

lib/librte_gso/gso_common.c line 118

Quoted 10 lines
lib/librte_gso/gso_common.c new file +10 -0
+				return -ENOMEM;
+			}
+
+			/* allocate 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;
+			}

So, if I understand correctly each new packet would always contain just one data segment? Why several data segments couldn't be chained together (if sum of their data_len <= mss)? In a same way as done here:
http://dpdk.org/browse/dpdk/tree/lib/librte_ip_frag/rte_ipv4_fragmentation.c#n93
or here:
https://gerrit.fd.io/r/gitweb?p=tldk.git;a=blob;f=lib/libtle_l4p/tcp_tx_seg.h;h=a8d2425597a7ad6f598aa4bb7fcd7f1da74305f0;hb=HEAD#l23
?

Quoted 78 lines
lib/librte_gso/gso_common.c new file +78 -0
+
+			/* copy packet header */
+			hdr_segment_init(hdr_segment, pkt, pkt_hdr_offset);
+
+			/* attach payload mbuf to current packet segment */
+			rte_pktmbuf_attach(pyld_segment, pkt_in);
+
+			hdr_segment->next = pyld_segment;
+			pkts_out[nb_segs++] = hdr_segment;
+
+			/* calculate payload length */
+			pkt_out_segment_len = pyld_unit_size;
+			if (pkt_in_pyld_off + pkt_out_segment_len >
+					pkt_in_segment_len) {
+				pkt_out_segment_len = pkt_in_segment_len -
+					pkt_in_pyld_off;
+			}
+
+			/* update payload segment */
+			pyld_segment->data_off = pkt_in_pyld_off;
+			pyld_segment->data_len = pkt_out_segment_len;
+
+			/* update header segment */
+			hdr_segment->pkt_len += pyld_segment->data_len;
+			hdr_segment->nb_segs++;
+
+			/* update pkt_in_pyld_off */
+			pkt_in_pyld_off += pkt_out_segment_len;
+			if (pkt_in_pyld_off == pkt_in_segment_len)
+				pkt_in_segment_processed = true;
+		}
+
+		/* 'pkt_in' may contain numerous segments */
+		pkt_in = pkt_in->next;
+		if (pkt_in != NULL)
+			pkt_in_pyld_off = pkt_in->data_off;
+	}
+	return nb_segs;
+}
+
+static inline void
+parse_ipv4(struct ipv4_hdr *ipv4_hdr, struct rte_mbuf *pkt)
+{
+	struct tcp_hdr *tcp_hdr;
+
+	switch (ipv4_hdr->next_proto_id) {
+	case IPPROTO_TCP:
+		pkt->packet_type |= RTE_PTYPE_L4_TCP;
+		pkt->l3_len = IPv4_HDR_LEN(ipv4_hdr);
+		tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+		pkt->l4_len = TCP_HDR_LEN(tcp_hdr);
+		break;
+	}
+}
+
+static inline void
+parse_ethernet(struct ether_hdr *eth_hdr, struct rte_mbuf *pkt)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct vlan_hdr *vlan_hdr;
+	uint16_t ethertype;
+
+	ethertype = rte_be_to_cpu_16(eth_hdr->ether_type);
+	if (ethertype == ETHER_TYPE_VLAN) {
+		vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
+		pkt->l2_len = sizeof(struct vlan_hdr);
+		pkt->packet_type |= RTE_PTYPE_L2_ETHER_VLAN;
+		ethertype = rte_be_to_cpu_16(vlan_hdr->eth_proto);
+	}
+
+	switch (ethertype) {
+	case ETHER_TYPE_IPv4:
+		if (IS_VLAN_PKT(pkt)) {
+			pkt->packet_type |= RTE_PTYPE_L3_IPV4;
+		} else {
+			pkt->packet_type |= RTE_PTYPE_L2_ETHER;
+			pkt->packet_type |= RTE_PTYPE_L3_IPV4;
+		}

lib/librte_gso/gso_common.c line 206

Quoted 10 lines
lib/librte_gso/gso_common.c new file +10 -0
+		pkt->l2_len += sizeof(struct ether_hdr);
+		ipv4_hdr = (struct ipv4_hdr *) ((char *)eth_hdr +
+				pkt->l2_len);
+		parse_ipv4(ipv4_hdr, pkt);
+		break;
+	}
+}
+
+void
+gso_parse_packet(struct rte_mbuf *pkt)

There is a function rte_net_get_ptype() that supposed to provide similar functionality. So we probably don't need to create a new SW parse function here, instead would be better to reuse (and update if needed) an existing one.
Again user already might have l2/l3/l4.../_len and packet_type setuped.
So better to keep SW packet parsing out of scope of that library.

Quoted 32 lines
lib/librte_gso/gso_common.c new file +32 -0
+{
+	struct ether_hdr *eth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
+
+	pkt->packet_type = pkt->tx_offload = 0;
+	parse_ethernet(eth_hdr, pkt);
+}
+
+static inline void
+update_ipv4_header(char *base, uint16_t offset, uint16_t length, uint16_t id)
+{
+	struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)(base + offset);
+
+	ipv4_hdr->total_length = rte_cpu_to_be_16(length - offset);
+	ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
+}
+
+static inline void
+update_tcp_header(char *base, uint16_t offset, uint32_t sent_seq,
+	uint8_t non_tail)
+{
+	struct tcp_hdr *tcp_hdr = (struct tcp_hdr *)(base + offset);
+
+	tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
+	/* clean FIN and PSH for non-tail segments */
+	if (non_tail)
+		tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK | TCP_HDR_FIN_MASK));
+}
+
+void
+gso_update_pkt_headers(struct rte_mbuf *pkt, uint16_t nb_segments,
+		struct rte_mbuf **out_segments)
+{

lib/librte_gso/gso_common.c line 248

Quoted 10 lines
lib/librte_gso/gso_common.c new file +10 -0
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	struct rte_mbuf *seg;
+	uint32_t sent_seq;
+	uint16_t offset, i;
+	uint16_t tail_seg_idx = nb_segments - 1, id;
+
+	switch (pkt->packet_type) {
+	case ETHER_VLAN_IPv4_TCP_PKT:
+	case ETHER_IPv4_TCP_PKT:

Might be worth to put code below in a separate function:
update_inner_tcp_hdr(..) or so.
Then you can reuse it for tunneled cases too.

lib/librte_gso/gso_common.c line 261

Quoted 13 lines
lib/librte_gso/gso_common.c new file +13 -0
+		ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) 
+				pkt->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);
+
+		for (i = 0; i < nb_segments; i++) {
+			seg = out_segments[i];
+
+			offset = seg->l2_len;
+			update_ipv4_header(rte_pktmbuf_mtod(seg, char *),
+					offset, seg->pkt_len, id);
+			id++;

Who would be responsible to make sure that we wouldn't have consecutive packets with the IPV4 id? Would be the upper layer that forms the packet or gso library or ...?

Quoted 320 lines
lib/librte_gso/gso_common.c new file +9 -0
+
+			offset += seg->l3_len;
+			update_tcp_header(rte_pktmbuf_mtod(seg, char *),
+					offset, sent_seq, i < tail_seg_idx);
+			sent_seq += seg->next->data_len;
+		}
+		break;
+	}
+}
lib/librte_gso/gso_common.h new file +120 -0
new file mode 100644
index 0000000..d750041
@@ -0,0 +1,120 @@
+/*-
+ *   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>
+
+#define IPV4_HDR_DF_SHIFT 14
+#define IPV4_HDR_DF_MASK (1 << IPV4_HDR_DF_SHIFT)
+#define IPv4_HDR_LEN(iph) ((iph->version_ihl & 0x0f) * 4)
+
+#define TCP_HDR_PSH_MASK ((uint8_t)0x08)
+#define TCP_HDR_FIN_MASK ((uint8_t)0x01)
+#define TCP_HDR_LEN(tcph) ((tcph->data_off & 0xf0) >> 2)
+
+#define ETHER_IPv4_PKT (RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4)
+/* Supported packet types */
+/* TCP/IPv4 packet. */
+#define ETHER_IPv4_TCP_PKT (ETHER_IPv4_PKT | RTE_PTYPE_L4_TCP)
+
+/* TCP/IPv4 packet with VLAN tag. */
+#define ETHER_VLAN_IPv4_TCP_PKT (RTE_PTYPE_L2_ETHER_VLAN | \
+		RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP)
+
+#define IS_VLAN_PKT(pkt) ((pkt->packet_type & RTE_PTYPE_L2_ETHER_VLAN) == \
+		RTE_PTYPE_L2_ETHER_VLAN)
+
+/**
+ * Internal function which parses a packet, setting outer_l2/l3_len and
+ * l2/l3/l4_len and packet_type.
+ *
+ * @param pkt
+ *  Packet to parse.
+ */
+void gso_parse_packet(struct rte_mbuf *pkt);
+
+/**
+ * Internal function which updates relevant packet headers, 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 nb_segments
+ *  The number of GSO segments into which pkt was split.
+ * @param out_segements
+ *  Pointer array used for storing mbuf addresses for GSO segments.
+ */
+void gso_update_pkt_headers(struct rte_mbuf *pkt, uint16_t nb_segments,
+		struct rte_mbuf **out_segments);
+
+/**
+ * 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 byte.
+ * @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.
+ * @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.
+ *  - If no GSO is performed, return 1.
+ *  - If available memory in mempools is insufficient, return -ENOMEM.
+ *  - -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_tcp.c new file +82 -0
new file mode 100644
index 0000000..9d5fc30
@@ -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.
+ */
+
+
+#include <rte_ether.h>
+#include <rte_ip.h>
+#include <rte_tcp.h>
+
+#include "gso_common.h"
+#include "gso_tcp.h"
+
+int
+gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ether_hdr *eth_hdr;
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size;
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	eth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
+	ipv4_hdr = (struct ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);
+
+	/* don't process fragmented packet */
+	if ((ipv4_hdr->fragment_offset &
+				rte_cpu_to_be_16(IPV4_HDR_DF_MASK)) == 0)
+		return ret;
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) -
+		pkt->l3_len - pkt->l4_len;
+	/* don't process packet without data */
+	if (tcp_dl == 0)
+		return ret;
+
+	hdr_offset = pkt->l2_len + pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset - ETHER_CRC_LEN;
+
+	/* 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)
+		gso_update_pkt_headers(pkt, ret, pkts_out);
+
+	return ret;
+}
lib/librte_gso/gso_tcp.h new file +73 -0
new file mode 100644
index 0000000..f291ccb
@@ -0,0 +1,73 @@
+/*-
+ *   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_TCP_H_
+#define _GSO_TCP_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment an IPv4/TCP packet. This function assumes the input packet has
+ * correct checksums and doesn't update checksums for GSO segment.
+ * 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 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, which is used to store mbuf addresses of GSO segments.
+ *  Caller should guarantee that 'pkts_out' is sufficiently large to store
+ *  all GSO segments.
+ * @param nb_pkts_out
+ *  The max number of items that 'pkts_out' can keep.
+ *
+ * @return
+ *   - The number of GSO segments on success.
+ *   - Return 1 if no GSO is performed.
+ *   - Return -ENOMEM if available memory in mempools is insufficient.
+ *   - Return -EINVAL for invalid parameters.
+ */
+int gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_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/rte_gso.c +4 -0
index b81afce..fac95f2 100644
@@ -31,17 +31,57 @@
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <rte_log.h>
+
 #include "rte_gso.h"
+#include "gso_common.h"
+#include "gso_tcp.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
 		struct rte_gso_ctx gso_ctx,
 		struct rte_mbuf **pkts_out,

lib/librte_gso/rte_gso.c line 52

Quoted 10 lines
lib/librte_gso/rte_gso.c +5 -1
-		uint16_t nb_pkts_out __rte_unused)
+		uint16_t nb_pkts_out)
 {
+	struct rte_mempool *direct_pool, *indirect_pool;
+	struct rte_mbuf *pkt_seg;
+	uint16_t nb_segments, gso_size;
+
 	if (pkt == NULL || pkts_out == NULL || gso_ctx.direct_pool ==
 			NULL || gso_ctx.indirect_pool == NULL)
 		return -EINVAL;

Probably we don't need to check gso_ctx values for each incoming packet. If you feel it is necessary - create new function rte_gso_ctx_check() that could be performed just once per ctx.

lib/librte_gso/rte_gso.c line 56

Quoted 5 lines
lib/librte_gso/rte_gso.c +3 -1
-	return 1;
+	if ((gso_ctx.gso_types & RTE_GSO_TCP_IPV4) == 0 ||
+			gso_ctx.gso_size >= pkt->pkt_len ||
+			gso_ctx.gso_size == 0)

First and third condition seems redundant.

lib/librte_gso/rte_gso.c line 57

Quoted 1 line
lib/librte_gso/rte_gso.c +1 -0
+		return 1;

I think you forgot here:
pkts_out[0] = pkt;

lib/librte_gso/rte_gso.c line 65

Quoted 8 lines
lib/librte_gso/rte_gso.c +8 -0
+
+	pkt_seg = pkt;
+	gso_size = gso_ctx.gso_size;
+	direct_pool = gso_ctx.direct_pool;
+	indirect_pool = gso_ctx.indirect_pool;
+
+	/* Parse packet headers to determine how to segment 'pkt' */
+	gso_parse_packet(pkt);

I don't think we need to parse packet here.
Instead assume that user already filled packet_type and l2/l3/..._len fields correctly.

Quoted 38 lines
lib/librte_gso/rte_gso.c +21 -0
+
+	switch (pkt->packet_type) {
+	case ETHER_VLAN_IPv4_TCP_PKT:
+	case ETHER_IPv4_TCP_PKT:
+		nb_segments = gso_tcp4_segment(pkt, gso_size,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+		break;
+	default:
+		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
+		nb_segments = 1;
+	}
+
+	if (nb_segments > 1) {
+		while (pkt_seg) {
+			rte_mbuf_refcnt_update(pkt_seg, -1);
+			pkt_seg = pkt_seg->next;
+		}
+	}
+
+	return nb_segments;
 }
lib/librte_gso/rte_gso.h +3 -1
index 5a8389a..77853fa 100644
@@ -46,6 +46,9 @@ extern "C" {
 #include <stdint.h>
 #include <rte_mbuf.h>
 
+#define RTE_GSO_TCP_IPV4 (1ULL << 0)
+/**< GSO flag for TCP/IPv4 packets (containing optional VLAN tag) */
+
 /**
  * GSO context structure.
  */
--

2.7.4

author
#6 lore raw

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

Hi Konstantin,

Thanks for your important suggestions. My feedbacks are inline.

Quoted 139 lines · Konstantin
Quoted 139 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, August 24, 2017 3:16 PM
To: [email protected]
Cc: Kavanagh, Mark B <[email protected]>; Ananyev, Konstantin <[email protected]>; Tan, Jianfeng <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH 2/5] gso/lib: 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 assumes that all 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.

---
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 270 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 120 ++++++++++++++
 lib/librte_gso/gso_tcp.c                |  82 ++++++++++
 lib/librte_gso/gso_tcp.h                |  73 +++++++++
 lib/librte_gso/rte_gso.c                |  44 +++++-
 lib/librte_gso/rte_gso.h                |   3 +
 8 files changed, 593 insertions(+), 2 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_tcp.c
 create mode 100644 lib/librte_gso/gso_tcp.h
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..0f8e38f 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_tcp.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +64 -0
new file mode 100644
index 0000000..2b54fbd
@@ -0,0 +1,270 @@
+/*-
+ *   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 <string.h>
+
+#include <rte_malloc.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 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)
Quoted 8 lines

lib/librte_gso/gso_common.c line 69

Quoted 5 lines
lib/librte_gso/gso_common.c new file +5 -0
+{
+	uint16_t i;
+
+	for (i = 0; i < nb_pkts; i++) {
+		rte_pktmbuf_detach(pkts[i]->next);

I don't think you need to call detach() here explicitly. Just rte_pktmbuf_free(pkts[i]) should do I think.

Yes, rte_pktmbuf_free() is enough. I will modify it. Thanks.

Quoted 51 lines
Quoted 40 lines
lib/librte_gso/gso_common.c new file +39 -0
+		rte_pktmbuf_free(pkts[i]);
+		pkts[i] = NULL;
+	}
+}
+
+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;
+	uint32_t pkt_in_pyld_off;
+	uint16_t pkt_in_segment_len, pkt_out_segment_len;
+	uint16_t nb_segs;
+	bool pkt_in_segment_processed;
+
+	pkt_in_pyld_off = pkt->data_off + pkt_hdr_offset;
+	pkt_in = pkt;
+	nb_segs = 0;
+
+	while (pkt_in) {
+		pkt_in_segment_processed = false;
+		pkt_in_segment_len = pkt_in->data_off + pkt_in->data_len;
+
+		while (!pkt_in_segment_processed) {
+			if (unlikely(nb_segs >= nb_pkts_out)) {
+				free_gso_segment(pkts_out, nb_segs);
+				return -EINVAL;
+			}
+
+			/* allocate direct mbuf */
+			hdr_segment = rte_pktmbuf_alloc(direct_pool);
+			if (unlikely(hdr_segment == NULL)) {
+				free_gso_segment(pkts_out, nb_segs);

lib/librte_gso/gso_common.c line 118

Quoted 10 lines
lib/librte_gso/gso_common.c new file +10 -0
+				return -ENOMEM;
+			}
+
+			/* allocate 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;
+			}
Quoted 7 lines

So, if I understand correctly each new packet would always contain just one data segment? Why several data segments couldn't be chained together (if sum of their data_len <= mss)? In a same way as done here:
http://dpdk.org/browse/dpdk/tree/lib/librte_ip_frag/rte_ipv4_fragmentation.c#n93
or here:
https://gerrit.fd.io/r/gitweb?p=tldk.git;a=blob;f=lib/libtle_l4p/tcp_tx_seg.h;h=a8d2425597a7ad6f598aa4bb7fcd7f1da74305f0;hb=HEAD#l23
?

Oh, yes. I can chain these data segments when their total length is less than the GSO segsz. I will change it in the next patch. Thanks very much.

Quoted 87 lines
Quoted 87 lines
lib/librte_gso/gso_common.c new file +86 -0
+
+			/* copy packet header */
+			hdr_segment_init(hdr_segment, pkt, pkt_hdr_offset);
+
+			/* attach payload mbuf to current packet segment */
+			rte_pktmbuf_attach(pyld_segment, pkt_in);
+
+			hdr_segment->next = pyld_segment;
+			pkts_out[nb_segs++] = hdr_segment;
+
+			/* calculate payload length */
+			pkt_out_segment_len = pyld_unit_size;
+			if (pkt_in_pyld_off + pkt_out_segment_len >
+					pkt_in_segment_len) {
+				pkt_out_segment_len = pkt_in_segment_len -
+					pkt_in_pyld_off;
+			}
+
+			/* update payload segment */
+			pyld_segment->data_off = pkt_in_pyld_off;
+			pyld_segment->data_len = pkt_out_segment_len;
+
+			/* update header segment */
+			hdr_segment->pkt_len += pyld_segment->data_len;
+			hdr_segment->nb_segs++;
+
+			/* update pkt_in_pyld_off */
+			pkt_in_pyld_off += pkt_out_segment_len;
+			if (pkt_in_pyld_off == pkt_in_segment_len)
+				pkt_in_segment_processed = true;
+		}
+
+		/* 'pkt_in' may contain numerous segments */
+		pkt_in = pkt_in->next;
+		if (pkt_in != NULL)
+			pkt_in_pyld_off = pkt_in->data_off;
+	}
+	return nb_segs;
+}
+
+static inline void
+parse_ipv4(struct ipv4_hdr *ipv4_hdr, struct rte_mbuf *pkt)
+{
+	struct tcp_hdr *tcp_hdr;
+
+	switch (ipv4_hdr->next_proto_id) {
+	case IPPROTO_TCP:
+		pkt->packet_type |= RTE_PTYPE_L4_TCP;
+		pkt->l3_len = IPv4_HDR_LEN(ipv4_hdr);
+		tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+		pkt->l4_len = TCP_HDR_LEN(tcp_hdr);
+		break;
+	}
+}
+
+static inline void
+parse_ethernet(struct ether_hdr *eth_hdr, struct rte_mbuf *pkt)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct vlan_hdr *vlan_hdr;
+	uint16_t ethertype;
+
+	ethertype = rte_be_to_cpu_16(eth_hdr->ether_type);
+	if (ethertype == ETHER_TYPE_VLAN) {
+		vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
+		pkt->l2_len = sizeof(struct vlan_hdr);
+		pkt->packet_type |= RTE_PTYPE_L2_ETHER_VLAN;
+		ethertype = rte_be_to_cpu_16(vlan_hdr->eth_proto);
+	}
+
+	switch (ethertype) {
+	case ETHER_TYPE_IPv4:
+		if (IS_VLAN_PKT(pkt)) {
+			pkt->packet_type |= RTE_PTYPE_L3_IPV4;
+		} else {
+			pkt->packet_type |= RTE_PTYPE_L2_ETHER;
+			pkt->packet_type |= RTE_PTYPE_L3_IPV4;
+		}
+		pkt->l2_len += sizeof(struct ether_hdr);
+		ipv4_hdr = (struct ipv4_hdr *) ((char *)eth_hdr +
+				pkt->l2_len);
+		parse_ipv4(ipv4_hdr, pkt);
+		break;
+	}
+}
+
Quoted 8 lines

lib/librte_gso/gso_common.c line 206

Quoted 2 lines
lib/librte_gso/gso_common.c new file +2 -0
+void
+gso_parse_packet(struct rte_mbuf *pkt)

There is a function rte_net_get_ptype() that supposed to provide similar functionality. So we probably don't need to create a new SW parse function here, instead would be better to reuse (and update if needed) an existing one.
Again user already might have l2/l3/l4.../_len and packet_type setuped.
So better to keep SW packet parsing out of scope of that library.

Hmm, I know we have discussed this design choice in the GRO library, and I also think it's better to reuse these values.

But from the perspective of OVS, it may add extra overhead, since OVS doesn't parse every packet originally. Maybe @Mark can give us more inputs from the view of OVS.

Quoted 39 lines
Quoted 39 lines
lib/librte_gso/gso_common.c new file +38 -0
+{
+	struct ether_hdr *eth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
+
+	pkt->packet_type = pkt->tx_offload = 0;
+	parse_ethernet(eth_hdr, pkt);
+}
+
+static inline void
+update_ipv4_header(char *base, uint16_t offset, uint16_t length, uint16_t id)
+{
+	struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)(base + offset);
+
+	ipv4_hdr->total_length = rte_cpu_to_be_16(length - offset);
+	ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
+}
+
+static inline void
+update_tcp_header(char *base, uint16_t offset, uint32_t sent_seq,
+	uint8_t non_tail)
+{
+	struct tcp_hdr *tcp_hdr = (struct tcp_hdr *)(base + offset);
+
+	tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
+	/* clean FIN and PSH for non-tail segments */
+	if (non_tail)
+		tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK | TCP_HDR_FIN_MASK));
+}
+
+void
+gso_update_pkt_headers(struct rte_mbuf *pkt, uint16_t nb_segments,
+		struct rte_mbuf **out_segments)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	struct rte_mbuf *seg;
+	uint32_t sent_seq;
+	uint16_t offset, i;
+	uint16_t tail_seg_idx = nb_segments - 1, id;
Quoted 8 lines

lib/librte_gso/gso_common.c line 248

Quoted 4 lines
lib/librte_gso/gso_common.c new file +4 -0
+
+	switch (pkt->packet_type) {
+	case ETHER_VLAN_IPv4_TCP_PKT:
+	case ETHER_IPv4_TCP_PKT:

Might be worth to put code below in a separate function:
update_inner_tcp_hdr(..) or so.
Then you can reuse it for tunneled cases too.

Yes, I will modify it in the next patch. Thanks.

Quoted 17 lines
Quoted 4 lines
lib/librte_gso/gso_common.c new file +3 -0
+		ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) 
+				pkt->l2_len);
+		tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);

lib/librte_gso/gso_common.c line 261

Quoted 10 lines
lib/librte_gso/gso_common.c new file +10 -0
+		id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+		sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+
+		for (i = 0; i < nb_segments; i++) {
+			seg = out_segments[i];
+
+			offset = seg->l2_len;
+			update_ipv4_header(rte_pktmbuf_mtod(seg, char *),
+					offset, seg->pkt_len, id);
+			id++;

Who would be responsible to make sure that we wouldn't have consecutive packets with the IPV4 id? Would be the upper layer that forms the packet or gso library or ...?

Oh yes. I ingore this important issue. I don't think applications can guarantee it. I will check the design of linux and try to figure out a way. Thanks for reminder.

Quoted 327 lines
Quoted 327 lines
lib/librte_gso/gso_common.c new file +9 -0
+
+			offset += seg->l3_len;
+			update_tcp_header(rte_pktmbuf_mtod(seg, char *),
+					offset, sent_seq, i < tail_seg_idx);
+			sent_seq += seg->next->data_len;
+		}
+		break;
+	}
+}
lib/librte_gso/gso_common.h new file +120 -0
new file mode 100644
index 0000000..d750041
@@ -0,0 +1,120 @@
+/*-
+ *   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>
+
+#define IPV4_HDR_DF_SHIFT 14
+#define IPV4_HDR_DF_MASK (1 << IPV4_HDR_DF_SHIFT)
+#define IPv4_HDR_LEN(iph) ((iph->version_ihl & 0x0f) * 4)
+
+#define TCP_HDR_PSH_MASK ((uint8_t)0x08)
+#define TCP_HDR_FIN_MASK ((uint8_t)0x01)
+#define TCP_HDR_LEN(tcph) ((tcph->data_off & 0xf0) >> 2)
+
+#define ETHER_IPv4_PKT (RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4)
+/* Supported packet types */
+/* TCP/IPv4 packet. */
+#define ETHER_IPv4_TCP_PKT (ETHER_IPv4_PKT | RTE_PTYPE_L4_TCP)
+
+/* TCP/IPv4 packet with VLAN tag. */
+#define ETHER_VLAN_IPv4_TCP_PKT (RTE_PTYPE_L2_ETHER_VLAN | \
+		RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP)
+
+#define IS_VLAN_PKT(pkt) ((pkt->packet_type & RTE_PTYPE_L2_ETHER_VLAN) == \
+		RTE_PTYPE_L2_ETHER_VLAN)
+
+/**
+ * Internal function which parses a packet, setting outer_l2/l3_len and
+ * l2/l3/l4_len and packet_type.
+ *
+ * @param pkt
+ *  Packet to parse.
+ */
+void gso_parse_packet(struct rte_mbuf *pkt);
+
+/**
+ * Internal function which updates relevant packet headers, 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 nb_segments
+ *  The number of GSO segments into which pkt was split.
+ * @param out_segements
+ *  Pointer array used for storing mbuf addresses for GSO segments.
+ */
+void gso_update_pkt_headers(struct rte_mbuf *pkt, uint16_t nb_segments,
+		struct rte_mbuf **out_segments);
+
+/**
+ * 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 byte.
+ * @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.
+ * @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.
+ *  - If no GSO is performed, return 1.
+ *  - If available memory in mempools is insufficient, return -ENOMEM.
+ *  - -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_tcp.c new file +82 -0
new file mode 100644
index 0000000..9d5fc30
@@ -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.
+ */
+
+
+#include <rte_ether.h>
+#include <rte_ip.h>
+#include <rte_tcp.h>
+
+#include "gso_common.h"
+#include "gso_tcp.h"
+
+int
+gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ether_hdr *eth_hdr;
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size;
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	eth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
+	ipv4_hdr = (struct ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);
+
+	/* don't process fragmented packet */
+	if ((ipv4_hdr->fragment_offset &
+				rte_cpu_to_be_16(IPV4_HDR_DF_MASK)) == 0)
+		return ret;
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) -
+		pkt->l3_len - pkt->l4_len;
+	/* don't process packet without data */
+	if (tcp_dl == 0)
+		return ret;
+
+	hdr_offset = pkt->l2_len + pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset - ETHER_CRC_LEN;
+
+	/* 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)
+		gso_update_pkt_headers(pkt, ret, pkts_out);
+
+	return ret;
+}
lib/librte_gso/gso_tcp.h new file +73 -0
new file mode 100644
index 0000000..f291ccb
@@ -0,0 +1,73 @@
+/*-
+ *   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_TCP_H_
+#define _GSO_TCP_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment an IPv4/TCP packet. This function assumes the input packet has
+ * correct checksums and doesn't update checksums for GSO segment.
+ * 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 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, which is used to store mbuf addresses of GSO segments.
+ *  Caller should guarantee that 'pkts_out' is sufficiently large to store
+ *  all GSO segments.
+ * @param nb_pkts_out
+ *  The max number of items that 'pkts_out' can keep.
+ *
+ * @return
+ *   - The number of GSO segments on success.
+ *   - Return 1 if no GSO is performed.
+ *   - Return -ENOMEM if available memory in mempools is insufficient.
+ *   - Return -EINVAL for invalid parameters.
+ */
+int gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_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/rte_gso.c +8 -1
index b81afce..fac95f2 100644
@@ -31,17 +31,57 @@
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <rte_log.h>
+
 #include "rte_gso.h"
+#include "gso_common.h"
+#include "gso_tcp.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
 		struct rte_gso_ctx gso_ctx,
 		struct rte_mbuf **pkts_out,
-		uint16_t nb_pkts_out __rte_unused)
+		uint16_t nb_pkts_out)
 {
+	struct rte_mempool *direct_pool, *indirect_pool;
+	struct rte_mbuf *pkt_seg;
+	uint16_t nb_segments, gso_size;
Quoted 8 lines

lib/librte_gso/rte_gso.c line 52

Quoted 4 lines
lib/librte_gso/rte_gso.c +1 -0
+
 	if (pkt == NULL || pkts_out == NULL || gso_ctx.direct_pool ==
 			NULL || gso_ctx.indirect_pool == NULL)
 		return -EINVAL;

Probably we don't need to check gso_ctx values for each incoming packet. If you feel it is necessary - create new function rte_gso_ctx_check() that could be performed just once per ctx.

Agree. I will change it. Thanks.

Quoted 9 lines

lib/librte_gso/rte_gso.c line 56

Quoted 6 lines
lib/librte_gso/rte_gso.c +3 -1
-	return 1;
+	if ((gso_ctx.gso_types & RTE_GSO_TCP_IPV4) == 0 ||
+			gso_ctx.gso_size >= pkt->pkt_len ||
+			gso_ctx.gso_size == 0)

First and third condition seems redundant.

The reason to check gso_ctx.gso_types here is that we don't perform GSO if applications don't set RTE_GSO_TCP_IPV4 to gso_ctx.gso_types, even the input packet is TCP/IPv4. And if gso_ctx.gso_size is 0, we don't need to execute the following codes. So we still need to remove these two conditions?

Quoted 6 lines

lib/librte_gso/rte_gso.c line 57

Quoted 2 lines
lib/librte_gso/rte_gso.c +1 -0
+		return 1;

I think you forgot here:
pkts_out[0] = pkt;

But why should we keep the input packet in the output array? Currently, if GSO is not performed, no packets will be kept in pkts_out[]. Applications can know it by the return value 1 of rte_gso_segment().

Quoted 14 lines

lib/librte_gso/rte_gso.c line 65

Quoted 10 lines
lib/librte_gso/rte_gso.c +8 -0
+
+	pkt_seg = pkt;
+	gso_size = gso_ctx.gso_size;
+	direct_pool = gso_ctx.direct_pool;
+	indirect_pool = gso_ctx.indirect_pool;
+
+	/* Parse packet headers to determine how to segment 'pkt' */
+	gso_parse_packet(pkt);

I don't think we need to parse packet here.
Instead assume that user already filled packet_type and l2/l3/..._len fields correctly.

Hmm, I see it. Thanks.

Thanks,
Jiayu

#7 lore raw

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

Quoted 338 lines

From: Hu, Jiayu
Sent: Wednesday, August 30, 2017 3:56 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>; Tan, Jianfeng <[email protected]>
Subject: Re: [PATCH 2/5] gso/lib: add TCP/IPv4 GSO support

Hi Konstantin,

Thanks for your important suggestions. My feedbacks are inline.

Quoted 7 lines · Konstantin
Quoted 7 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, August 24, 2017 3:16 PM
To: [email protected]
Cc: Kavanagh, Mark B <[email protected]>; Ananyev, Konstantin

<[email protected]>; Tan, Jianfeng

Quoted 20 lines
Quoted 20 lines

<[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH 2/5] gso/lib: 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 assumes that all 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 6 lines
Quoted 6 lines
---
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 270

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

Quoted 11 lines
Quoted 11 lines
 lib/librte_gso/gso_common.h             | 120 ++++++++++++++
 lib/librte_gso/gso_tcp.c                |  82 ++++++++++
 lib/librte_gso/gso_tcp.h                |  73 +++++++++
 lib/librte_gso/rte_gso.c                |  44 +++++-
 lib/librte_gso/rte_gso.h                |   3 +
 8 files changed, 593 insertions(+), 2 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_tcp.c
 create mode 100644 lib/librte_gso/gso_tcp.h
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +0 -0

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

Quoted 35 lines
Quoted 35 lines

index ec8dba7..2fa1199 100644

lib/librte_eal/common/include/rte_log.h +1 -0
@@ -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..0f8e38f 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_tcp.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +5 -0
new file mode 100644
index 0000000..2b54fbd
@@ -0,0 +1,270 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
Quoted 8 lines

lib/librte_gso/gso_common.c

Quoted 8 lines
lib/librte_gso/gso_common.c new file +8 -0
+ *
+ *   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

Quoted 10 lines

lib/librte_gso/gso_common.c

Quoted 10 lines
lib/librte_gso/gso_common.c new file +10 -0
+ *       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

Quoted 2 lines

lib/librte_gso/gso_common.c line 25

Quoted 2 lines
lib/librte_gso/gso_common.c new file +2 -0
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,

INCIDENTAL,

Quoted 2 lines

lib/librte_gso/gso_common.c line 27

Quoted 2 lines
lib/librte_gso/gso_common.c new file +2 -0
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF

USE,

Quoted 1 line

lib/librte_gso/gso_common.c line 28

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

ANY

Quoted 2 lines

lib/librte_gso/gso_common.c line 30

Quoted 2 lines
lib/librte_gso/gso_common.c new file +2 -0
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE

USE

Quoted 34 lines
Quoted 34 lines
lib/librte_gso/gso_common.c new file +34 -0
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdbool.h>
+#include <string.h>
+
+#include <rte_malloc.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 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)
Quoted 8 lines

lib/librte_gso/gso_common.c line 69

Quoted 5 lines
lib/librte_gso/gso_common.c new file +5 -0
+{
+	uint16_t i;
+
+	for (i = 0; i < nb_pkts; i++) {
+		rte_pktmbuf_detach(pkts[i]->next);

I don't think you need to call detach() here explicitly. Just rte_pktmbuf_free(pkts[i]) should do I think.

Yes, rte_pktmbuf_free() is enough. I will modify it. Thanks.

Quoted 44 lines
Quoted 44 lines
lib/librte_gso/gso_common.c new file +43 -0
+		rte_pktmbuf_free(pkts[i]);
+		pkts[i] = NULL;
+	}
+}
+
+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;
+	uint32_t pkt_in_pyld_off;
+	uint16_t pkt_in_segment_len, pkt_out_segment_len;
+	uint16_t nb_segs;
+	bool pkt_in_segment_processed;
+
+	pkt_in_pyld_off = pkt->data_off + pkt_hdr_offset;
+	pkt_in = pkt;
+	nb_segs = 0;
+
+	while (pkt_in) {
+		pkt_in_segment_processed = false;
+		pkt_in_segment_len = pkt_in->data_off + pkt_in->data_len;
+
+		while (!pkt_in_segment_processed) {
+			if (unlikely(nb_segs >= nb_pkts_out)) {
+				free_gso_segment(pkts_out, nb_segs);
+				return -EINVAL;
+			}
+
+			/* allocate direct mbuf */
+			hdr_segment = rte_pktmbuf_alloc(direct_pool);
+			if (unlikely(hdr_segment == NULL)) {
+				free_gso_segment(pkts_out, nb_segs);
+				return -ENOMEM;
+			}
+
+			/* allocate indirect mbuf */
Quoted 8 lines

lib/librte_gso/gso_common.c line 118

Quoted 6 lines
lib/librte_gso/gso_common.c new file +6 -0
+			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;
+			}

So, if I understand correctly each new packet would always contain just one

data segment?

Quoted 1 line

Why several data segments couldn't be chained together (if sum of their

data_len <= mss)?

Quoted 2 lines

In a same way as done here:

http://dpdk.org/browse/dpdk/tree/lib/librte_ip_frag/rte_ipv4_fragmentation.c#n
93

Quoted 2 lines

or here:

https://gerrit.fd.io/r/gitweb?p=tldk.git;a=blob;f=lib/libtle_l4p/tcp_tx_seg.h;
h=a8d2425597a7ad6f598aa4bb7fcd7f1da74305f0;hb=HEAD#l23

Quoted 1 line

?

Oh, yes. I can chain these data segments when their total length is less than the GSO segsz.
I will change it in the next patch. Thanks very much.

Quoted 83 lines
Quoted 83 lines
lib/librte_gso/gso_common.c new file +82 -0
+
+			/* copy packet header */
+			hdr_segment_init(hdr_segment, pkt, pkt_hdr_offset);
+
+			/* attach payload mbuf to current packet segment */
+			rte_pktmbuf_attach(pyld_segment, pkt_in);
+
+			hdr_segment->next = pyld_segment;
+			pkts_out[nb_segs++] = hdr_segment;
+
+			/* calculate payload length */
+			pkt_out_segment_len = pyld_unit_size;
+			if (pkt_in_pyld_off + pkt_out_segment_len >
+					pkt_in_segment_len) {
+				pkt_out_segment_len = pkt_in_segment_len -
+					pkt_in_pyld_off;
+			}
+
+			/* update payload segment */
+			pyld_segment->data_off = pkt_in_pyld_off;
+			pyld_segment->data_len = pkt_out_segment_len;
+
+			/* update header segment */
+			hdr_segment->pkt_len += pyld_segment->data_len;
+			hdr_segment->nb_segs++;
+
+			/* update pkt_in_pyld_off */
+			pkt_in_pyld_off += pkt_out_segment_len;
+			if (pkt_in_pyld_off == pkt_in_segment_len)
+				pkt_in_segment_processed = true;
+		}
+
+		/* 'pkt_in' may contain numerous segments */
+		pkt_in = pkt_in->next;
+		if (pkt_in != NULL)
+			pkt_in_pyld_off = pkt_in->data_off;
+	}
+	return nb_segs;
+}
+
+static inline void
+parse_ipv4(struct ipv4_hdr *ipv4_hdr, struct rte_mbuf *pkt)
+{
+	struct tcp_hdr *tcp_hdr;
+
+	switch (ipv4_hdr->next_proto_id) {
+	case IPPROTO_TCP:
+		pkt->packet_type |= RTE_PTYPE_L4_TCP;
+		pkt->l3_len = IPv4_HDR_LEN(ipv4_hdr);
+		tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
+		pkt->l4_len = TCP_HDR_LEN(tcp_hdr);
+		break;
+	}
+}
+
+static inline void
+parse_ethernet(struct ether_hdr *eth_hdr, struct rte_mbuf *pkt)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct vlan_hdr *vlan_hdr;
+	uint16_t ethertype;
+
+	ethertype = rte_be_to_cpu_16(eth_hdr->ether_type);
+	if (ethertype == ETHER_TYPE_VLAN) {
+		vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
+		pkt->l2_len = sizeof(struct vlan_hdr);
+		pkt->packet_type |= RTE_PTYPE_L2_ETHER_VLAN;
+		ethertype = rte_be_to_cpu_16(vlan_hdr->eth_proto);
+	}
+
+	switch (ethertype) {
+	case ETHER_TYPE_IPv4:
+		if (IS_VLAN_PKT(pkt)) {
+			pkt->packet_type |= RTE_PTYPE_L3_IPV4;
+		} else {
+			pkt->packet_type |= RTE_PTYPE_L2_ETHER;
+			pkt->packet_type |= RTE_PTYPE_L3_IPV4;
+		}
+		pkt->l2_len += sizeof(struct ether_hdr);
+		ipv4_hdr = (struct ipv4_hdr *) ((char *)eth_hdr +
+				pkt->l2_len);
+		parse_ipv4(ipv4_hdr, pkt);
Quoted 8 lines

lib/librte_gso/gso_common.c line 206

Quoted 6 lines
lib/librte_gso/gso_common.c new file +6 -0
+		break;
+	}
+}
+
+void
+gso_parse_packet(struct rte_mbuf *pkt)

There is a function rte_net_get_ptype() that supposed to provide similar

functionality.

Quoted 1 line

So we probably don't need to create a new SW parse function here, instead

would be better

Quoted 3 lines

to reuse (and update if needed) an existing one.
Again user already might have l2/l3/l4.../_len and packet_type setuped. So better to keep SW packet parsing out of scope of that library.

Quoted 7 lines

Hmm, I know we have discussed this design choice in the GRO library, and I also think it's
better to reuse these values.

But from the perspective of OVS, it may add extra overhead, since OVS doesn't parse every
packet originally. Maybe @Mark can give us more inputs from the view of OVS.

Hi Jiayu, Konstantin

For GSO, the application needs to know:
- the packet type (as it only currently supports TCP/IPv4, VxLAN, GRE packets)
- the l2/3/4_lens, etc. (in order to replicate the original packet's headers across outgoing segments)

For this, we can use the rte_net_get_ptype function, as per Konstantin's suggestion, as it provides both - thanks Konstantin!

WRT the extra overhead in OvS: TSO is the defacto standard, and GSO is provided purely as a fallback option. As such, and since the additional packet parsing is a necessity in order to facilitate GSO, the additional overhead is IMO acceptable.

Thanks,
Mark

Quoted 481 lines
Quoted 11 lines

lib/librte_gso/gso_common.c

Quoted 11 lines
lib/librte_gso/gso_common.c new file +9 -0
+{
+	struct ether_hdr *eth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
+
+	pkt->packet_type = pkt->tx_offload = 0;
+	parse_ethernet(eth_hdr, pkt);
+}
+
+static inline void
+update_ipv4_header(char *base, uint16_t offset, uint16_t length, uint16_t

id)

Quoted 29 lines
Quoted 29 lines
lib/librte_gso/gso_common.c new file +29 -0
+{
+	struct ipv4_hdr *ipv4_hdr = (struct ipv4_hdr *)(base + offset);
+
+	ipv4_hdr->total_length = rte_cpu_to_be_16(length - offset);
+	ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
+}
+
+static inline void
+update_tcp_header(char *base, uint16_t offset, uint32_t sent_seq,
+	uint8_t non_tail)
+{
+	struct tcp_hdr *tcp_hdr = (struct tcp_hdr *)(base + offset);
+
+	tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
+	/* clean FIN and PSH for non-tail segments */
+	if (non_tail)
+		tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK | TCP_HDR_FIN_MASK));
+}
+
+void
+gso_update_pkt_headers(struct rte_mbuf *pkt, uint16_t nb_segments,
+		struct rte_mbuf **out_segments)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	struct rte_mbuf *seg;
+	uint32_t sent_seq;
+	uint16_t offset, i;
+	uint16_t tail_seg_idx = nb_segments - 1, id;
Quoted 8 lines

lib/librte_gso/gso_common.c line 248

Quoted 4 lines
lib/librte_gso/gso_common.c new file +4 -0
+
+	switch (pkt->packet_type) {
+	case ETHER_VLAN_IPv4_TCP_PKT:
+	case ETHER_IPv4_TCP_PKT:

Might be worth to put code below in a separate function:
update_inner_tcp_hdr(..) or so.
Then you can reuse it for tunneled cases too.

Yes, I will modify it in the next patch. Thanks.

Quoted 16 lines
Quoted 4 lines
lib/librte_gso/gso_common.c new file +3 -0
+		ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *)
+				pkt->l2_len);
+		tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + pkt->l3_len);

lib/librte_gso/gso_common.c line 261

Quoted 10 lines
lib/librte_gso/gso_common.c new file +10 -0
+		id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+		sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+
+		for (i = 0; i < nb_segments; i++) {
+			seg = out_segments[i];
+
+			offset = seg->l2_len;
+			update_ipv4_header(rte_pktmbuf_mtod(seg, char *),
+					offset, seg->pkt_len, id);
+			id++;

Who would be responsible to make sure that we wouldn't have consecutive

packets with the IPV4 id?

Quoted 1 line

Would be the upper layer that forms the packet or gso library or ...?

Oh yes. I ingore this important issue. I don't think applications can guarantee it.
I will check the design of linux and try to figure out a way. Thanks for reminder.

Quoted 21 lines
Quoted 21 lines
lib/librte_gso/gso_common.c new file +9 -0
+
+			offset += seg->l3_len;
+			update_tcp_header(rte_pktmbuf_mtod(seg, char *),
+					offset, sent_seq, i < tail_seg_idx);
+			sent_seq += seg->next->data_len;
+		}
+		break;
+	}
+}
lib/librte_gso/gso_common.h new file +5 -0
new file mode 100644
index 0000000..d750041
@@ -0,0 +1,120 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
Quoted 8 lines

lib/librte_gso/gso_common.h line 13

Quoted 8 lines
lib/librte_gso/gso_common.h new file +8 -0
+ *
+ *   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

Quoted 10 lines

lib/librte_gso/gso_common.h line 23

Quoted 10 lines
lib/librte_gso/gso_common.h new file +10 -0
+ *       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

Quoted 2 lines

lib/librte_gso/gso_common.h line 25

Quoted 2 lines
lib/librte_gso/gso_common.h new file +2 -0
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,

INCIDENTAL,

Quoted 2 lines

lib/librte_gso/gso_common.h line 27

Quoted 2 lines
lib/librte_gso/gso_common.h new file +2 -0
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF

USE,

Quoted 1 line

lib/librte_gso/gso_common.h line 28

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

ANY

Quoted 2 lines

lib/librte_gso/gso_common.h line 30

Quoted 2 lines
lib/librte_gso/gso_common.h new file +2 -0
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE

USE

Quoted 19 lines
Quoted 19 lines
lib/librte_gso/gso_common.h new file +19 -0
+ *   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>
+
+#define IPV4_HDR_DF_SHIFT 14
+#define IPV4_HDR_DF_MASK (1 << IPV4_HDR_DF_SHIFT)
+#define IPv4_HDR_LEN(iph) ((iph->version_ihl & 0x0f) * 4)
+
+#define TCP_HDR_PSH_MASK ((uint8_t)0x08)
+#define TCP_HDR_FIN_MASK ((uint8_t)0x01)
+#define TCP_HDR_LEN(tcph) ((tcph->data_off & 0xf0) >> 2)
+
+#define ETHER_IPv4_PKT (RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4)
+/* Supported packet types */
Quoted 8 lines

lib/librte_gso/gso_common.h

Quoted 8 lines
lib/librte_gso/gso_common.h new file +8 -0
+/* TCP/IPv4 packet. */
+#define ETHER_IPv4_TCP_PKT (ETHER_IPv4_PKT | RTE_PTYPE_L4_TCP)
+
+/* TCP/IPv4 packet with VLAN tag. */
+#define ETHER_VLAN_IPv4_TCP_PKT (RTE_PTYPE_L2_ETHER_VLAN | \
+		RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP)
+
+#define IS_VLAN_PKT(pkt) ((pkt->packet_type & RTE_PTYPE_L2_ETHER_VLAN) ==

\

Quoted 74 lines
Quoted 74 lines
lib/librte_gso/gso_common.h new file +63 -0
+		RTE_PTYPE_L2_ETHER_VLAN)
+
+/**
+ * Internal function which parses a packet, setting outer_l2/l3_len and
+ * l2/l3/l4_len and packet_type.
+ *
+ * @param pkt
+ *  Packet to parse.
+ */
+void gso_parse_packet(struct rte_mbuf *pkt);
+
+/**
+ * Internal function which updates relevant packet headers, 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 nb_segments
+ *  The number of GSO segments into which pkt was split.
+ * @param out_segements
+ *  Pointer array used for storing mbuf addresses for GSO segments.
+ */
+void gso_update_pkt_headers(struct rte_mbuf *pkt, uint16_t nb_segments,
+		struct rte_mbuf **out_segments);
+
+/**
+ * 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 byte.
+ * @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.
+ * @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.
+ *  - If no GSO is performed, return 1.
+ *  - If available memory in mempools is insufficient, return -ENOMEM.
+ *  - -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_tcp.c new file +5 -0
new file mode 100644
index 0000000..9d5fc30
@@ -0,0 +1,82 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
+ *   All rights reserved.
Quoted 8 lines

lib/librte_gso/gso_tcp.c line 13

Quoted 8 lines
lib/librte_gso/gso_tcp.c new file +8 -0
+ *
+ *   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

Quoted 10 lines

lib/librte_gso/gso_tcp.c line 23

Quoted 10 lines
lib/librte_gso/gso_tcp.c new file +10 -0
+ *       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

Quoted 2 lines

lib/librte_gso/gso_tcp.c line 25

Quoted 2 lines
lib/librte_gso/gso_tcp.c new file +2 -0
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,

INCIDENTAL,

Quoted 2 lines

lib/librte_gso/gso_tcp.c line 27

Quoted 2 lines
lib/librte_gso/gso_tcp.c new file +2 -0
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF

USE,

Quoted 1 line

lib/librte_gso/gso_tcp.c line 28

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

ANY

Quoted 2 lines

lib/librte_gso/gso_tcp.c line 30

Quoted 2 lines
lib/librte_gso/gso_tcp.c new file +2 -0
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE

USE

Quoted 63 lines
Quoted 63 lines
lib/librte_gso/gso_tcp.c new file +52 -0
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include <rte_ether.h>
+#include <rte_ip.h>
+#include <rte_tcp.h>
+
+#include "gso_common.h"
+#include "gso_tcp.h"
+
+int
+gso_tcp4_segment(struct rte_mbuf *pkt,
+		uint16_t gso_size,
+		struct rte_mempool *direct_pool,
+		struct rte_mempool *indirect_pool,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	struct ether_hdr *eth_hdr;
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size;
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	eth_hdr = rte_pktmbuf_mtod(pkt, struct ether_hdr *);
+	ipv4_hdr = (struct ipv4_hdr *)((char *)eth_hdr + pkt->l2_len);
+
+	/* don't process fragmented packet */
+	if ((ipv4_hdr->fragment_offset &
+				rte_cpu_to_be_16(IPV4_HDR_DF_MASK)) == 0)
+		return ret;
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) -
+		pkt->l3_len - pkt->l4_len;
+	/* don't process packet without data */
+	if (tcp_dl == 0)
+		return ret;
+
+	hdr_offset = pkt->l2_len + pkt->l3_len + pkt->l4_len;
+	pyld_unit_size = gso_size - hdr_offset - ETHER_CRC_LEN;
+
+	/* 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)
+		gso_update_pkt_headers(pkt, ret, pkts_out);
+
+	return ret;
+}
lib/librte_gso/gso_tcp.h new file +5 -0
new file mode 100644
index 0000000..f291ccb
@@ -0,0 +1,73 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Quoted 8 lines

lib/librte_gso/gso_tcp.h

Quoted 8 lines
lib/librte_gso/gso_tcp.h new file +8 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

copyright

Quoted 10 lines

lib/librte_gso/gso_tcp.h

Quoted 10 lines
lib/librte_gso/gso_tcp.h new file +10 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

FOR

Quoted 2 lines

lib/librte_gso/gso_tcp.h

Quoted 2 lines
lib/librte_gso/gso_tcp.h new file +2 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

INCIDENTAL,

126 lines not shown · raw message

Parts of this message are not shown here. View the raw message.

#8 lore raw

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

Hi Mark,

Quoted 22 lines
Quoted 12 lines
Quoted 5 lines

lib/librte_gso/gso_common.c line 206

Quoted 3 lines
lib/librte_gso/gso_common.c new file +3 -0
+
+void
+gso_parse_packet(struct rte_mbuf *pkt)

There is a function rte_net_get_ptype() that supposed to provide similar

functionality.

Quoted 1 line

So we probably don't need to create a new SW parse function here, instead

would be better

Quoted 3 lines

to reuse (and update if needed) an existing one.
Again user already might have l2/l3/l4.../_len and packet_type setuped. So better to keep SW packet parsing out of scope of that library.

Quoted 7 lines

Hmm, I know we have discussed this design choice in the GRO library, and I also think it's
better to reuse these values.

But from the perspective of OVS, it may add extra overhead, since OVS doesn't parse every
packet originally. Maybe @Mark can give us more inputs from the view of OVS.

Hi Jiayu, Konstantin

Quoted 8 lines

For GSO, the application needs to know:
- the packet type (as it only currently supports TCP/IPv4, VxLAN, GRE packets)
- the l2/3/4_lens, etc. (in order to replicate the original packet's headers across outgoing segments)

For this, we can use the rte_net_get_ptype function, as per Konstantin's suggestion, as it provides both - thanks Konstantin!

WRT the extra overhead in OvS: TSO is the defacto standard, and GSO is provided purely as a fallback option. As such, and since the additional packet parsing is a necessity in order to facilitate GSO, the additional overhead is IMO acceptable.

As I remember, for TSO in DPDK user still have to provide l2/l3/l4_len and mss information to the PMD.
So unless user knows these value straightway (user creates a packet himself) some packet processing will be unavailable anyway. Konstantin

Quoted 4 lines

Thanks,
Mark

#9 lore raw

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

Quoted 37 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Ananyev, Konstantin
Sent: Wednesday, August 30, 2017 10:39 AM
To: Kavanagh, Mark B <[email protected]>; Hu, Jiayu <[email protected]>
Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: Re: [dpdk-dev] [PATCH 2/5] gso/lib: add TCP/IPv4 GSO support

Hi Mark,

Quoted 26 lines
Quoted 12 lines
Quoted 5 lines

lib/librte_gso/gso_common.c line 206

Quoted 3 lines
lib/librte_gso/gso_common.c new file +3 -0
+
+void
+gso_parse_packet(struct rte_mbuf *pkt)

There is a function rte_net_get_ptype() that supposed to provide similar

functionality.

Quoted 1 line

So we probably don't need to create a new SW parse function here, instead

would be better

Quoted 3 lines

to reuse (and update if needed) an existing one.
Again user already might have l2/l3/l4.../_len and packet_type setuped. So better to keep SW packet parsing out of scope of that library.

Quoted 7 lines

Hmm, I know we have discussed this design choice in the GRO library, and I also think it's
better to reuse these values.

But from the perspective of OVS, it may add extra overhead, since OVS doesn't parse every
packet originally. Maybe @Mark can give us more inputs from the view of OVS.

Hi Jiayu, Konstantin

For GSO, the application needs to know:
- the packet type (as it only currently supports TCP/IPv4, VxLAN, GRE packets)
- the l2/3/4_lens, etc. (in order to replicate the original packet's headers across outgoing segments)

Quoted 8 lines
Quoted 4 lines

For this, we can use the rte_net_get_ptype function, as per Konstantin's suggestion, as it provides both - thanks Konstantin!

WRT the extra overhead in OvS: TSO is the defacto standard, and GSO is provided purely as a fallback option. As such, and since the additional packet parsing is a necessity in order to facilitate GSO, the additional overhead is IMO acceptable.

As I remember, for TSO in DPDK user still have to provide l2/l3/l4_len and mss information to the PMD.
So unless user knows these value straightway (user creates a packet himself) some packet processing will be unavailable anyway. Konstantin

s/unavailable/unavoidable/
sorry for bad typing.
Konstantin

Quoted 4 lines
Quoted 4 lines

Thanks,
Mark

#10 lore raw

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

Quoted 55 lines

From: Ananyev, Konstantin
Sent: Wednesday, August 30, 2017 10:59 AM
To: Ananyev, Konstantin <[email protected]>; Kavanagh, Mark B <[email protected]>; Hu, Jiayu <[email protected]>
Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH 2/5] gso/lib: add TCP/IPv4 GSO support

Quoted 4 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Ananyev, Konstantin
Sent: Wednesday, August 30, 2017 10:39 AM
To: Kavanagh, Mark B <[email protected]>; Hu, Jiayu

<[email protected]>

Quoted 10 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: Re: [dpdk-dev] [PATCH 2/5] gso/lib: add TCP/IPv4 GSO support

Hi Mark,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

lib/librte_gso/gso_common.c line 206

Quoted 3 lines
lib/librte_gso/gso_common.c new file +3 -0
+
+void
+gso_parse_packet(struct rte_mbuf *pkt)

There is a function rte_net_get_ptype() that supposed to provide

similar

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

functionality.

Quoted 1 line

So we probably don't need to create a new SW parse function here,

instead

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

would be better

Quoted 3 lines

to reuse (and update if needed) an existing one.
Again user already might have l2/l3/l4.../_len and packet_type setuped. So better to keep SW packet parsing out of scope of that library.

Hmm, I know we have discussed this design choice in the GRO library, and

I

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

also think it's
better to reuse these values.

But from the perspective of OVS, it may add extra overhead, since OVS

doesn't

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

parse every
packet originally. Maybe @Mark can give us more inputs from the view of

OVS.

Quoted 5 lines
Quoted 5 lines

Hi Jiayu, Konstantin

For GSO, the application needs to know:
- the packet type (as it only currently supports TCP/IPv4, VxLAN, GRE

packets)

Quoted 1 line
Quoted 1 line

- the l2/3/4_lens, etc. (in order to replicate the original packet's

headers across outgoing segments)

Quoted 2 lines
Quoted 2 lines

For this, we can use the rte_net_get_ptype function, as per Konstantin's

suggestion, as it provides both - thanks Konstantin!

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 1 line
Quoted 1 line

WRT the extra overhead in OvS: TSO is the defacto standard, and GSO is

provided purely as a fallback option. As such, and since the

Quoted 1 line
Quoted 1 line

additional packet parsing is a necessity in order to facilitate GSO, the

additional overhead is IMO acceptable.

Quoted 2 lines

As I remember, for TSO in DPDK user still have to provide l2/l3/l4_len and

mss information to the PMD.

Yes, that's correct.

Quoted 2 lines
Quoted 1 line

So unless user knows these value straightway (user creates a packet himself)

some packet processing will be unavailable anyway.

That's correct also. Currently, packets that originate in a VM, and which have been marked for TSO, have the l2_len, etc. fields populated by the 'parse_ethernet' function, called as part of the call stack of the rte_vhost_dequeue_burst function, so that particular overhead is already implicit in the TSO case.

Quoted 10 lines
Quoted 1 line

Konstantin

s/unavailable/unavoidable/
sorry for bad typing.
Konstantin

Quoted 4 lines
Quoted 4 lines

Thanks,
Mark

author
#11 lore raw

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

In reply to Ananyev, Konstantin

Hi Konstantin,

Quoted 50 lines · Konstantin
Quoted 34 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, August 24, 2017 3:16 PM
To: [email protected]
Cc: Kavanagh, Mark B <[email protected]>; Ananyev, Konstantin <[email protected]>; Tan, Jianfeng <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH 2/5] gso/lib: 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 assumes that all 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.

---
int
rte_gso_segment(struct rte_mbuf *pkt,

lib/librte_gso/rte_gso.c +0 -0
 		struct rte_gso_ctx gso_ctx,
 		struct rte_mbuf **pkts_out,

lib/librte_gso/rte_gso.c line 52

Quoted 10 lines
lib/librte_gso/rte_gso.c +5 -1
-		uint16_t nb_pkts_out __rte_unused)
+		uint16_t nb_pkts_out)
 {
+	struct rte_mempool *direct_pool, *indirect_pool;
+	struct rte_mbuf *pkt_seg;
+	uint16_t nb_segments, gso_size;
+
 	if (pkt == NULL || pkts_out == NULL || gso_ctx.direct_pool ==
 			NULL || gso_ctx.indirect_pool == NULL)
 		return -EINVAL;

Probably we don't need to check gso_ctx values for each incoming packet. If you feel it is necessary - create new function rte_gso_ctx_check() that could be performed just once per ctx.

Quoted 1 line
Quoted 7 lines

lib/librte_gso/rte_gso.c line 56

Quoted 4 lines
lib/librte_gso/rte_gso.c +3 -1
-	return 1;
+	if ((gso_ctx.gso_types & RTE_GSO_TCP_IPV4) == 0 ||
+			gso_ctx.gso_size >= pkt->pkt_len ||
+			gso_ctx.gso_size == 0)

First and third condition seems redundant.

Yes, we don't need the first and the third check here. Please ingore the redundant reply in the previous mail.

Thanks,
Jiayu

author
#12 lore raw

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

In reply to Ananyev, Konstantin

Hi Konstantin,

About the IP identifier, I check the linux codes and have some feedbacks inline.

Quoted 49 lines · Konstantin
Quoted 34 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, August 24, 2017 3:16 PM
To: [email protected]
Cc: Kavanagh, Mark B <[email protected]>; Ananyev, Konstantin <[email protected]>; Tan, Jianfeng <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH 2/5] gso/lib: 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 assumes that all 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.

---

lib/librte_gso/gso_common.c new file +4 -0
+void
+gso_update_pkt_headers(struct rte_mbuf *pkt, uint16_t nb_segments,
+		struct rte_mbuf **out_segments)
+{

lib/librte_gso/gso_common.c line 248

Quoted 10 lines
lib/librte_gso/gso_common.c new file +10 -0
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	struct rte_mbuf *seg;
+	uint32_t sent_seq;
+	uint16_t offset, i;
+	uint16_t tail_seg_idx = nb_segments - 1, id;
+
+	switch (pkt->packet_type) {
+	case ETHER_VLAN_IPv4_TCP_PKT:
+	case ETHER_IPv4_TCP_PKT:

Might be worth to put code below in a separate function:
update_inner_tcp_hdr(..) or so.
Then you can reuse it for tunneled cases too.

Quoted 16 lines

lib/librte_gso/gso_common.c line 261

Quoted 13 lines
lib/librte_gso/gso_common.c new file +13 -0
+		ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) 
+				pkt->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);
+
+		for (i = 0; i < nb_segments; i++) {
+			seg = out_segments[i];
+
+			offset = seg->l2_len;
+			update_ipv4_header(rte_pktmbuf_mtod(seg, char *),
+					offset, seg->pkt_len, id);
+			id++;

Who would be responsible to make sure that we wouldn't have consecutive packets with the IPV4 id? Would be the upper layer that forms the packet or gso library or ...?

Linux supports two kinds of IP identifier: fixed identifier and incremental identifier, and which one to use depends on upper protocol modules. Specifically, if the protocol module wants fixed identifiers, it will set SKB_GSO_TCP_FIXEDID to skb->gso_type, and then inet_gso_segment() will keep identifiers the same. Otherwise, all segments will have incremental identifiers. The reason for this design is that some protocols may choose fixed IP identifiers, like TCP (from RFC791). This design also shows that linux ignores the issue of repeated IP identifiers.

Quoted 1 line

From the perspective of DPDK, we need to solve two problems. One is if ignore the issue of

repeated IP identifiers. The other is if the GSO library provides an interface to upper applications to enable them to choose fixed or incremental identifiers, or simply uses incremental IP identifiers.

Do you have any suggestions?

Thanks,
Jiayu

Quoted 12 lines
Quoted 12 lines
lib/librte_gso/gso_common.c new file +9 -1
+
+			offset += seg->l3_len;
+			update_tcp_header(rte_pktmbuf_mtod(seg, char *),
+					offset, sent_seq, i < tail_seg_idx);
+			sent_seq += seg->next->data_len;
+		}
+		break;
+	}
+}
--

2.7.4

#13 lore raw

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

Hi Jiayu,

Quoted 86 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Monday, September 4, 2017 4:32 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>; Tan, Jianfeng <[email protected]>
Subject: Re: [PATCH 2/5] gso/lib: add TCP/IPv4 GSO support

Hi Konstantin,

About the IP identifier, I check the linux codes and have some feedbacks inline.

Quoted 49 lines · Konstantin
Quoted 34 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, August 24, 2017 3:16 PM
To: [email protected]
Cc: Kavanagh, Mark B <[email protected]>; Ananyev, Konstantin <[email protected]>; Tan, Jianfeng <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH 2/5] gso/lib: 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 assumes that all 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.

---

lib/librte_gso/gso_common.c new file +4 -0
+void
+gso_update_pkt_headers(struct rte_mbuf *pkt, uint16_t nb_segments,
+		struct rte_mbuf **out_segments)
+{

lib/librte_gso/gso_common.c line 248

Quoted 10 lines
lib/librte_gso/gso_common.c new file +10 -0
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	struct rte_mbuf *seg;
+	uint32_t sent_seq;
+	uint16_t offset, i;
+	uint16_t tail_seg_idx = nb_segments - 1, id;
+
+	switch (pkt->packet_type) {
+	case ETHER_VLAN_IPv4_TCP_PKT:
+	case ETHER_IPv4_TCP_PKT:

Might be worth to put code below in a separate function:
update_inner_tcp_hdr(..) or so.
Then you can reuse it for tunneled cases too.

Quoted 16 lines

lib/librte_gso/gso_common.c line 261

Quoted 13 lines
lib/librte_gso/gso_common.c new file +13 -0
+		ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *)
+				pkt->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);
+
+		for (i = 0; i < nb_segments; i++) {
+			seg = out_segments[i];
+
+			offset = seg->l2_len;
+			update_ipv4_header(rte_pktmbuf_mtod(seg, char *),
+					offset, seg->pkt_len, id);
+			id++;

Who would be responsible to make sure that we wouldn't have consecutive packets with the IPV4 id? Would be the upper layer that forms the packet or gso library or ...?

Linux supports two kinds of IP identifier: fixed identifier and incremental identifier, and which one to use depends on upper protocol modules. Specifically, if the protocol module wants fixed identifiers, it will set SKB_GSO_TCP_FIXEDID to skb->gso_type, and then inet_gso_segment() will keep identifiers the same. Otherwise, all segments will have incremental identifiers. The reason for this design is that some protocols may choose fixed IP identifiers, like TCP (from RFC791). This design also shows that linux ignores the issue of repeated IP identifiers.

Quoted 6 lines

From the perspective of DPDK, we need to solve two problems. One is if ignore the issue of repeated IP identifiers. The other is if the GSO library provides an interface to upper applications to enable them to choose fixed or incremental identifiers, or simply uses incremental IP identifiers.

Do you have any suggestions?

Do the same as Linux?
I.E. add some flag RRE_GSO_IPID_FIXED (or so) into gso_ctx? Konstantin

Quoted 16 lines

Thanks,
Jiayu

Quoted 12 lines
Quoted 12 lines
lib/librte_gso/gso_common.c new file +9 -1
+
+			offset += seg->l3_len;
+			update_tcp_header(rte_pktmbuf_mtod(seg, char *),
+					offset, sent_seq, i < tail_seg_idx);
+			sent_seq += seg->next->data_len;
+		}
+		break;
+	}
+}
--

2.7.4

author
#14 lore raw

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

Hi Konstantin,

Quoted 114 lines

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

Hi Jiayu,

Quoted 5 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Monday, September 4, 2017 4:32 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>; Tan,

Jianfeng <[email protected]>

Quoted 5 lines

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

Hi Konstantin,

About the IP identifier, I check the linux codes and have some feedbacks

inline.

Quoted 9 lines · Konstantin
Quoted 7 lines
Quoted 7 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, August 24, 2017 3:16 PM
To: [email protected]
Cc: Kavanagh, Mark B <[email protected]>; Ananyev,

Konstantin <[email protected]>; Tan, Jianfeng

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

<[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH 2/5] gso/lib: 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 assumes that all input packets have correct checksums, and doesn't update checksums for

output

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

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

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

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

Quoted 30 lines
Quoted 30 lines
Quoted 15 lines

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.

---

lib/librte_gso/gso_common.c new file +4 -0
+void
+gso_update_pkt_headers(struct rte_mbuf *pkt, uint16_t nb_segments,
+		struct rte_mbuf **out_segments)
+{

lib/librte_gso/gso_common.c line 248

Quoted 10 lines
lib/librte_gso/gso_common.c new file +10 -0
+	struct ipv4_hdr *ipv4_hdr;
+	struct tcp_hdr *tcp_hdr;
+	struct rte_mbuf *seg;
+	uint32_t sent_seq;
+	uint16_t offset, i;
+	uint16_t tail_seg_idx = nb_segments - 1, id;
+
+	switch (pkt->packet_type) {
+	case ETHER_VLAN_IPv4_TCP_PKT:
+	case ETHER_IPv4_TCP_PKT:

Might be worth to put code below in a separate function:
update_inner_tcp_hdr(..) or so.
Then you can reuse it for tunneled cases too.

Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
lib/librte_gso/gso_common.c new file +7 -0
+		ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *)
+				pkt->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);
+
+		for (i = 0; i < nb_segments; i++) {
Quoted 8 lines

lib/librte_gso/gso_common.c line 261

Quoted 6 lines
lib/librte_gso/gso_common.c new file +6 -0
+			seg = out_segments[i];
+
+			offset = seg->l2_len;
+			update_ipv4_header(rte_pktmbuf_mtod(seg, char *),
+					offset, seg->pkt_len, id);
+			id++;

Who would be responsible to make sure that we wouldn't have

consecutive packets with the IPV4 id?

Quoted 3 lines
Quoted 1 line

Would be the upper layer that forms the packet or gso library or ...?

Linux supports two kinds of IP identifier: fixed identifier and incremental

identifier, and

Quoted 1 line

which one to use depends on upper protocol modules. Specifically, if the

protocol module

Quoted 1 line

wants fixed identifiers, it will set SKB_GSO_TCP_FIXEDID to skb->gso_type,

and then

Quoted 1 line

inet_gso_segment() will keep identifiers the same. Otherwise, all segments

will have

Quoted 1 line

incremental identifiers. The reason for this design is that some protocols

may choose fixed

Quoted 1 line

IP identifiers, like TCP (from RFC791). This design also shows that linux

ignores the issue

Quoted 3 lines

of repeated IP identifiers.

From the perspective of DPDK, we need to solve two problems. One is if

ignore the issue of

Quoted 1 line

repeated IP identifiers. The other is if the GSO library provides an interface

to upper

Quoted 1 line

applications to enable them to choose fixed or incremental identifiers, or

Quoted 8 lines

simply uses

Quoted 3 lines

incremental IP identifiers.

Do you have any suggestions?

Do the same as Linux?
I.E. add some flag RRE_GSO_IPID_FIXED (or so) into gso_ctx?

OK, I see. We can do that.

In the GRO library, we check if the IP identifiers are incremental compulsorily. If we enable fixed IP identifier in GSO, it seems we also need to change the GRO library. I mean ignore IP identifier when merge packets, and don't update the IP identifier for the merged packet. What do you think of it?

Thanks,
Jiayu

Quoted 18 lines

Konstantin

Quoted 16 lines

Thanks,
Jiayu

Quoted 12 lines
Quoted 12 lines
lib/librte_gso/gso_common.c new file +9 -1
+
+			offset += seg->l3_len;
+			update_tcp_header(rte_pktmbuf_mtod(seg, char *),
+					offset, sent_seq, i < tail_seg_idx);
+			sent_seq += seg->next->data_len;
+		}
+		break;
+	}
+}
--

2.7.4

#15 lore raw

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

Hi Jiayu,

Quoted 28 lines
Quoted 19 lines
Quoted 1 line

Linux supports two kinds of IP identifier: fixed identifier and incremental

identifier, and

Quoted 1 line

which one to use depends on upper protocol modules. Specifically, if the

protocol module

Quoted 1 line

wants fixed identifiers, it will set SKB_GSO_TCP_FIXEDID to skb->gso_type,

and then

Quoted 1 line

inet_gso_segment() will keep identifiers the same. Otherwise, all segments

will have

Quoted 1 line

incremental identifiers. The reason for this design is that some protocols

may choose fixed

Quoted 1 line

IP identifiers, like TCP (from RFC791). This design also shows that linux

ignores the issue

Quoted 3 lines

of repeated IP identifiers.

From the perspective of DPDK, we need to solve two problems. One is if

ignore the issue of

Quoted 1 line

repeated IP identifiers. The other is if the GSO library provides an interface

to upper

Quoted 1 line

applications to enable them to choose fixed or incremental identifiers, or

Quoted 8 lines

simply uses

Quoted 3 lines

incremental IP identifiers.

Do you have any suggestions?

Do the same as Linux?
I.E. add some flag RRE_GSO_IPID_FIXED (or so) into gso_ctx?

Quoted 6 lines

OK, I see. We can do that.

In the GRO library, we check if the IP identifiers are incremental compulsorily. If we enable fixed IP identifier in GSO, it seems we also need to change the GRO library. I mean ignore IP identifier when merge packets, and don't update the IP identifier for the merged packet. What do you think of it?

I suppose we can, if there is a use-case for it.
Konstantin

Quoted 1 line
author
#16 lore raw

PATCH 3/5 lib/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 | 109 ++++++++++++++++++++++++++++++++++++++++++--
 lib/librte_gso/gso_common.h |  41 ++++++++++++++++-
 lib/librte_gso/gso_tunnel.c |  62 +++++++++++++++++++++++++
 lib/librte_gso/gso_tunnel.h |  46 +++++++++++++++++++
 lib/librte_gso/rte_gso.c    |  12 ++++-
 lib/librte_gso/rte_gso.h    |   4 ++
 7 files changed, 268 insertions(+), 7 deletions(-)
 create mode 100644 lib/librte_gso/gso_tunnel.c
 create mode 100644 lib/librte_gso/gso_tunnel.h
lib/librte_gso/Makefile +1 -0
index 0f8e38f..a4d1a81 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_tcp.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c +104 -5

155 lines not on this page · raw message

lib/librte_gso/gso_common.h +40 -1

62 lines not on this page · raw message

lib/librte_gso/gso_tunnel.c new file +62 -0

62 lines not on this page · raw message

lib/librte_gso/gso_tunnel.h new file +46 -0

46 lines not on this page · raw message

lib/librte_gso/rte_gso.c +11 -1
index fac95f2..f110f18 100644
@@ -36,6 +36,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp.h"
+#include "gso_tunnel.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -51,7 +52,8 @@ rte_gso_segment(struct rte_mbuf *pkt,
 			NULL || gso_ctx.indirect_pool == NULL)
 		return -EINVAL;
 
-	if ((gso_ctx.gso_types & RTE_GSO_TCP_IPV4) == 0 ||
+	if ((gso_ctx.gso_types & (RTE_GSO_TCP_IPV4 |
+					RTE_GSO_IPV4_VXLAN_TCP_IPV4)) == 0 ||
 			gso_ctx.gso_size >= pkt->pkt_len ||
 			gso_ctx.gso_size == 0)
 		return 1;
@@ -71,6 +73,14 @@ rte_gso_segment(struct rte_mbuf *pkt,
 				direct_pool, indirect_pool,
 				pkts_out, nb_pkts_out);
 		break;
+	case ETHER_VLAN_IPv4_UDP_VXLAN_VLAN_IPv4_TCP_PKT:
+	case ETHER_VLAN_IPv4_UDP_VXLAN_IPv4_TCP_PKT:
+	case ETHER_IPv4_UDP_VXLAN_VLAN_IPv4_TCP_PKT:
+	case ETHER_IPv4_UDP_VXLAN_IPv4_TCP_PKT:
+		nb_segments = gso_tunnel_segment(pkt, gso_size,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+		break;
 	default:
 		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
 		nb_segments = 1;
lib/librte_gso/rte_gso.h +4 -0
index 77853fa..e1b2c23 100644
@@ -48,6 +48,10 @@ extern "C" {
 
 #define RTE_GSO_TCP_IPV4 (1ULL << 0)
 /**< GSO flag for TCP/IPv4 packets (containing optional VLAN tag) */
+#define RTE_GSO_IPV4_VXLAN_TCP_IPV4 (1ULL << 1)
+/**< GSO flag for VxLAN packets that contain outer IPv4, and inner
+ * TCP/IPv4 headers (plus optional inner and/or outer VLAN tags).
+ */
 
 /**
  * GSO context structure.
Signature · 1 line
2.7.4
author
#17 lore raw

PATCH 4/5 lib/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 | 66 +++++++++++++++++++++++++++++++++++++++++++--
 lib/librte_gso/gso_common.h | 21 +++++++++++++++
 lib/librte_gso/rte_gso.c    |  5 +++-
 lib/librte_gso/rte_gso.h    |  4 +++
 4 files changed, 93 insertions(+), 3 deletions(-)
lib/librte_gso/gso_common.c +64 -2
index 65cec44..b3e7f9d 100644
@@ -37,6 +37,7 @@
 #include <rte_malloc.h>
 
 #include <rte_ether.h>
+#include <rte_gre.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
 #include <rte_udp.h>
@@ -159,6 +160,8 @@ gso_do_segment(struct rte_mbuf *pkt,
 
 static inline void parse_ethernet(struct ether_hdr *eth_hdr,
 		struct rte_mbuf *pkt);
+static inline void parse_ipv4(struct ipv4_hdr *ipv4_hdr,
+		struct rte_mbuf *pkt);
 
 static inline void
 parse_vxlan(struct udp_hdr *udp_hdr, struct rte_mbuf *pkt)
@@ -190,15 +193,29 @@ parse_udp(struct udp_hdr *udp_hdr, struct rte_mbuf *pkt)
 }
 
 static inline void
+parse_gre(struct gre_hdr *gre_hdr, struct rte_mbuf *pkt)
+{
+	struct ipv4_hdr *ipv4_hdr;
+
+	if (gre_hdr->proto == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
+		ipv4_hdr = (struct ipv4_hdr *)(gre_hdr + 1);
+		pkt->packet_type |= RTE_PTYPE_INNER_L3_IPV4;
+		parse_ipv4(ipv4_hdr, pkt);
+	}
+}
+
+static inline void
 parse_ipv4(struct ipv4_hdr *ipv4_hdr, struct rte_mbuf *pkt)
 {
+	struct gre_hdr *gre_hdr;
 	struct tcp_hdr *tcp_hdr;
 	struct udp_hdr *udp_hdr;
 
 	switch (ipv4_hdr->next_proto_id) {
 	case IPPROTO_TCP:
-		if (IS_VXLAN_PKT(pkt)) {
-			pkt->outer_l3_len = pkt->l3_len;
+		if (IS_TUNNEL_PKT(pkt)) {
+			if (IS_VXLAN_PKT(pkt))
+				pkt->outer_l3_len = pkt->l3_len;
 			pkt->packet_type |= RTE_PTYPE_INNER_L4_TCP;
 		} else
 			pkt->packet_type |= RTE_PTYPE_L4_TCP;
@@ -211,6 +228,14 @@ parse_ipv4(struct ipv4_hdr *ipv4_hdr, struct rte_mbuf *pkt)
 		udp_hdr = (struct udp_hdr *)((char *)ipv4_hdr + pkt->l3_len);
 		parse_udp(udp_hdr, pkt);
 		break;
+	case IPPROTO_GRE:
+		gre_hdr = (struct gre_hdr *)(ipv4_hdr + 1);
+		pkt->outer_l2_len = pkt->l2_len;
+		pkt->outer_l3_len = IPv4_HDR_LEN(ipv4_hdr);
+		pkt->l2_len = sizeof(*gre_hdr);
+		pkt->packet_type |= RTE_PTYPE_TUNNEL_GRE;
+		parse_gre(gre_hdr, pkt);
+		break;
 	}
 }
 
@@ -343,6 +368,43 @@ gso_update_pkt_headers(struct rte_mbuf *pkt, uint16_t nb_segments,
 			sent_seq += seg->next->data_len;
 		}
 		break;
+	case ETHER_VLAN_IPv4_GRE_IPv4_TCP_PKT:
+	case ETHER_IPv4_GRE_IPv4_TCP_PKT:
+		outer_ipv4_hdr =
+			(struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+				pkt->outer_l2_len);
+		ipv4_hdr = (struct ipv4_hdr *)((char *)outer_ipv4_hdr +
+				pkt->outer_l3_len + pkt->l2_len);
+		tcp_hdr = (struct tcp_hdr *)(ipv4_hdr + 1);
+
+		/* Retrieve values from original packet */
+		id = rte_be_to_cpu_16(ipv4_hdr->packet_id);
+		outer_id = rte_be_to_cpu_16(outer_ipv4_hdr->packet_id);
+		sent_seq = rte_be_to_cpu_32(tcp_hdr->sent_seq);
+
+		for (i = 0; i < nb_segments; i++) {
+			seg = out_segments[i];
+
+			/* Update outer IPv4 header */
+			offset = seg->outer_l2_len;
+			update_ipv4_header(rte_pktmbuf_mtod(seg, char *),
+					offset, seg->pkt_len, outer_id);
+			outer_id++;
+
+			/* Update inner IPv4 header */
+			offset += seg->outer_l3_len + seg->l2_len;
+			update_ipv4_header(rte_pktmbuf_mtod(seg, char *),
+					offset, seg->pkt_len, id);
+			id++;
+
+			/* Update inner TCP header */
+			offset += seg->l3_len;
+			update_tcp_header(rte_pktmbuf_mtod(seg, char *),
+					offset, sent_seq, i < tail_seg_idx);
+
+			sent_seq += seg->next->data_len;
+		}
+		break;
 	case ETHER_VLAN_IPv4_TCP_PKT:
 	case ETHER_IPv4_TCP_PKT:
 		ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
lib/librte_gso/gso_common.h +21 -0
index 0ad95d3..2ed264a 100644
@@ -87,6 +87,21 @@
 		RTE_PTYPE_INNER_L3_IPV4 | \
 		RTE_PTYPE_INNER_L4_TCP)
 
+/* GRE packet. */
+#define ETHER_IPv4_GRE_IPv4_TCP_PKT (\
+		ETHER_IPv4_PKT          | \
+		RTE_PTYPE_TUNNEL_GRE    | \
+		RTE_PTYPE_INNER_L3_IPV4 | \
+		RTE_PTYPE_INNER_L4_TCP)
+
+/* GRE packet with VLAN tag. */
+#define ETHER_VLAN_IPv4_GRE_IPv4_TCP_PKT (\
+		RTE_PTYPE_L2_ETHER_VLAN | \
+		RTE_PTYPE_L3_IPV4       | \
+		RTE_PTYPE_TUNNEL_GRE    | \
+		RTE_PTYPE_INNER_L3_IPV4 | \
+		RTE_PTYPE_INNER_L4_TCP)
+
 #define IS_VLAN_PKT(pkt) ((pkt->packet_type & RTE_PTYPE_L2_ETHER_VLAN) == \
 		RTE_PTYPE_L2_ETHER_VLAN)
 #define IS_INNER_VLAN_PKT(pkt) (\
@@ -96,6 +111,12 @@
 #define VXLAN_DEFAULT_PORT 4789
 #define IS_VXLAN_PKT(pkt) ((pkt->packet_type & RTE_PTYPE_TUNNEL_VXLAN) == \
 		RTE_PTYPE_TUNNEL_VXLAN)
+
+#define IS_GRE_PKT(pkt) ((pkt->packet_type & RTE_PTYPE_TUNNEL_GRE) == \
+		RTE_PTYPE_TUNNEL_GRE)
+
+#define IS_TUNNEL_PKT(pkt) ((pkt->packet_type & RTE_PTYPE_TUNNEL_VXLAN) | \
+		(pkt->packet_type & RTE_PTYPE_TUNNEL_GRE))
 /**
  * Internal function which parses a packet, setting outer_l2/l3_len and
  * l2/l3/l4_len and packet_type.
lib/librte_gso/rte_gso.c +4 -1
index f110f18..244bbf6 100644
@@ -53,7 +53,8 @@ rte_gso_segment(struct rte_mbuf *pkt,
 		return -EINVAL;
 
 	if ((gso_ctx.gso_types & (RTE_GSO_TCP_IPV4 |
-					RTE_GSO_IPV4_VXLAN_TCP_IPV4)) == 0 ||
+					RTE_GSO_IPV4_VXLAN_TCP_IPV4 |
+					RTE_GSO_IPV4_GRE_TCP_IPV4)) == 0 ||
 			gso_ctx.gso_size >= pkt->pkt_len ||
 			gso_ctx.gso_size == 0)
 		return 1;
@@ -77,6 +78,8 @@ rte_gso_segment(struct rte_mbuf *pkt,
 	case ETHER_VLAN_IPv4_UDP_VXLAN_IPv4_TCP_PKT:
 	case ETHER_IPv4_UDP_VXLAN_VLAN_IPv4_TCP_PKT:
 	case ETHER_IPv4_UDP_VXLAN_IPv4_TCP_PKT:
+	case ETHER_VLAN_IPv4_GRE_IPv4_TCP_PKT:
+	case ETHER_IPv4_GRE_IPv4_TCP_PKT:
 		nb_segments = gso_tunnel_segment(pkt, gso_size,
 				direct_pool, indirect_pool,
 				pkts_out, nb_pkts_out);
lib/librte_gso/rte_gso.h +4 -0
index e1b2c23..86ca790 100644
@@ -52,6 +52,10 @@ extern "C" {
 /**< GSO flag for VxLAN packets that contain outer IPv4, and inner
  * TCP/IPv4 headers (plus optional inner and/or outer VLAN tags).
  */
+#define RTE_GSO_IPV4_GRE_TCP_IPV4 (1ULL << 2)
+/**< GSO flag for GRE packets that contain outer IPv4, and inner
+ * TCP/IPv4 headers (with optional outer VLAN tag).
+ */
 
 /**
  * GSO context structure.
Signature · 1 line
2.7.4
author
#18 lore raw

PATCH 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 for GSO segments may be set with the command

"set port <port_id> gso_segsz <length>"

---
 app/test-pmd/cmdline.c  | 121 ++++++++++++++++++++++++++++++++++++++++++++++++
 app/test-pmd/config.c   |  25 ++++++++++
 app/test-pmd/csumonly.c |  68 +++++++++++++++++++++++++--
 app/test-pmd/testpmd.c  |   9 ++++
 app/test-pmd/testpmd.h  |  10 ++++
 5 files changed, 228 insertions(+), 5 deletions(-)
app/test-pmd/cmdline.c +121 -0
index cd8c358..754e249 100644
@@ -431,6 +431,13 @@ 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 port <port_id> gso_segsz <length>\n"
+			"    Set max packet length for GSO segment.\n\n"
+
 			"set fwd (%s)\n"
 			"    Set packet forwarding mode.\n\n"
 
@@ -3963,6 +3970,118 @@ cmdline_parse_inst_t cmd_gro_set = {
 	},
 };
 
+/* *** ENABLE/DISABLE GSO FOR PORTS *** */
+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;
+	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 SEGMENT *** */
+struct cmd_gso_size_result {
+	cmdline_fixed_string_t cmd_set;
+	cmdline_fixed_string_t cmd_port;
+	cmdline_fixed_string_t cmd_keyword;
+	uint16_t cmd_segsz;
+	uint8_t cmd_pid;
+};
+
+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 (port_id_is_invalid(res->cmd_pid, ENABLED_WARN))
+		return;
+
+	if (!strcmp(res->cmd_keyword, "gso_segsz")) {
+		if (res->cmd_segsz == 0) {
+			gso_ports[res->cmd_pid].enable = 0;
+			gso_ports[res->cmd_pid].gso_segsz = 0;
+			printf("Input gso_segsz is 0. Disable GSO for"
+					" port %u\n", res->cmd_pid);
+		} else
+			gso_ports[res->cmd_pid].gso_segsz = res->cmd_segsz;
+
+	}
+}
+
+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_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_port, "port");
+cmdline_parse_token_string_t cmd_gso_size_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result,
+				cmd_keyword, "gso_segsz");
+cmdline_parse_token_num_t cmd_gso_size_segsz =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
+				cmd_segsz, UINT16);
+cmdline_parse_token_num_t cmd_gso_size_pid =
+	TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result,
+				cmd_pid, UINT8);
+
+cmdline_parse_inst_t cmd_gso_size = {
+	.f = cmd_gso_size_parsed,
+	.data = NULL,
+	.help_str = "set port <port_id> gso_segsz <length>: set max "
+		"packet length for GSO segment (0 to disable GSO)",
+	.tokens = {
+		(void *)&cmd_gso_size_set,
+		(void *)&cmd_gso_size_port,
+		(void *)&cmd_gso_size_pid,
+		(void *)&cmd_gso_size_keyword,
+		(void *)&cmd_gso_size_segsz,
+		NULL,
+	},
+};
+
 /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
 struct cmd_set_flush_rx {
 	cmdline_fixed_string_t set;
@@ -14251,6 +14370,8 @@ 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_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 +25 -0
index 3ae3e1c..1837fb1 100644
@@ -2454,6 +2454,31 @@ 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;
+		gso_ports[port_id].gso_segsz = ETHER_MAX_LEN;
+	} 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 +63 -5

113 lines not on this page · raw message

app/test-pmd/testpmd.c +9 -0
index 7d40139..16c60f0 100644
@@ -400,6 +400,8 @@ static int eth_event_callback(uint8_t port_id,
  */
 static int all_ports_started(void);
 
+struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+
 /*
  * Helper function to check if socket is already discovered.
  * If yes, return positive value. If not, return zero.
@@ -664,6 +666,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 = RTE_GSO_TCP_IPV4 |
+			RTE_GSO_IPV4_VXLAN_TCP_IPV4 |
+			RTE_GSO_IPV4_GRE_TCP_IPV4;
+		fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN;
 	}
 
 	/* Configuration of packet forwarding streams. */
app/test-pmd/testpmd.h +10 -0
index c9d7739..3697d3f 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 {
+	uint16_t gso_segsz;
+	uint8_t enable;
+};
+extern struct gso_status gso_ports[RTE_MAX_ETHPORTS];
+
 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
#19 lore raw
In reply to Jiayu Hu

Hi Jiayu,
Few questions/comments from me below in in next few mails. Thanks
Konstantin

Quoted 22 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 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:

Quoted 7 lines

a. Connect 2 x 10Gbps physical ports (P0, P1), together physically. b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine.
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.

Not sure I understand the setup correctly:
So testpmd forwards packets between P0 and vhost-user port, right? And who uses P1? iperf-server over linux kernel?
Also is P1 on another box or not?

Quoted 2 lines

With GSO enabled for P0 in testpmd, observed iperf throughput is ~9Gbps.

Ok, and if GSO is disabled what is the throughput?
Another stupid question: if P0 is physical 10G (ixgbe?) we can just enable a TSO on it, right? If so, what would be the TSO numbers here?

In fact, could you probably explain a bit more, what supposed to be a main usage model for that library? Is that to perform segmentation on (virtual) devices that doesn't support HW TSO or ...? Again would it be for a termination point (packets were just formed and filled) by the caller, or is that for box in the middle which just forwards packets between nodes?
If the later one, then we'll probably already have most of our packets segmented properly, no?

Quoted 44 lines

The experimental data of VxLAN and GRE will be shown later.

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

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

 app/test-pmd/cmdline.c                  | 121 +++++++++
 app/test-pmd/config.c                   |  25 ++
 app/test-pmd/csumonly.c                 |  68 ++++-
 app/test-pmd/testpmd.c                  |   9 +
 app/test-pmd/testpmd.h                  |  10 +
 config/common_base                      |   5 +
 lib/Makefile                            |   2 +
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |  52 ++++
 lib/librte_gso/gso_common.c             | 431 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 180 +++++++++++++
 lib/librte_gso/gso_tcp.c                |  82 ++++++
 lib/librte_gso/gso_tcp.h                |  73 ++++++
 lib/librte_gso/gso_tunnel.c             |  62 +++++
 lib/librte_gso/gso_tunnel.h             |  46 ++++
 lib/librte_gso/rte_gso.c                | 100 ++++++++
 lib/librte_gso/rte_gso.h                | 122 +++++++++
 lib/librte_gso/rte_gso_version.map      |   7 +
 mk/rte.app.mk                           |   1 +
 19 files changed, 1392 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_tcp.c
 create mode 100644 lib/librte_gso/gso_tcp.h
 create mode 100644 lib/librte_gso/gso_tunnel.c
 create mode 100644 lib/librte_gso/gso_tunnel.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

--
2.7.4

author
#20 lore raw

Hi Konstantin,

Thanks for your suggestions. Feedbacks are inline.

Thanks,
Jiayu

Quoted 36 lines · Konstantin

Hi Jiayu,
Few questions/comments from me below in in next few mails. Thanks
Konstantin

Quoted 22 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 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:

Quoted 7 lines

a. Connect 2 x 10Gbps physical ports (P0, P1), together physically. b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine.
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.

Quoted 2 lines

Not sure I understand the setup correctly:
So testpmd forwards packets between P0 and vhost-user port, right?

Yes.

Quoted 1 line

And who uses P1? iperf-server over linux kernel?

P1 is possessed by linux kernel.

Quoted 1 line

Also is P1 on another box or not?

P0 and P1 are in the same machine and are connected physically.

Quoted 7 lines
Quoted 3 lines

With GSO enabled for P0 in testpmd, observed iperf throughput is ~9Gbps.

Ok, and if GSO is disabled what is the throughput?
Another stupid question: if P0 is physical 10G (ixgbe?) we can just enable a TSO on it, right? If so, what would be the TSO numbers here?

Here are more detailed experiment information:

test1: only enable GSO for p0, GSO size is 1518, use two iperf-clients (i.e. "-P 2")
test2: only enable TSO for p0, TSO size is 1518, use two iperf-clients
test3: disable TSO and GSO, use two iperf-clients

test1 performance: 8.6Gpbs
test2 throughput: 9.5Gbps
test3 throughput: 3Mbps

Quoted 2 lines

In fact, could you probably explain a bit more, what supposed to be a main usage model for that library?

The GSO library is just a SW segmentation method, which can be used by applications, like OVS. Currently, most of NICs supports to segment TCP and UDP packets, but not for all NICs. So current OVS doesn't enable TSO, as a result of lacking a SW segmentation fallback. Besides, the protocol types in HW segmentation are limited. So it's necessary to provide a SW segmentation solution.

With the GSO library, OVS and other applications are able to receive large packets from VMs and process these large packets, instead of standard ones (i.e. 1518B). So the per-packet overhead is reduced, since the number of packets needed processing is much fewer.

Quoted 1 line

Is that to perform segmentation on (virtual) devices that doesn't support HW TSO or ...?

When launch qemu with enabling TSO or GSO, the virtual device doesn't really do segmentation. It directly sends large packets. Therefore, testpmd can receive large packets from the VM and then perform GSO. The GSO/TSO behavior of virtual devices is different from physical NICs.

Quoted 48 lines

Again would it be for a termination point (packets were just formed and filled) by the caller, or is that for box in the middle which just forwards packets between nodes?
If the later one, then we'll probably already have most of our packets segmented properly, no?

Quoted 44 lines

The experimental data of VxLAN and GRE will be shown later.

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

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

 app/test-pmd/cmdline.c                  | 121 +++++++++
 app/test-pmd/config.c                   |  25 ++
 app/test-pmd/csumonly.c                 |  68 ++++-
 app/test-pmd/testpmd.c                  |   9 +
 app/test-pmd/testpmd.h                  |  10 +
 config/common_base                      |   5 +
 lib/Makefile                            |   2 +
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |  52 ++++
 lib/librte_gso/gso_common.c             | 431 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 180 +++++++++++++
 lib/librte_gso/gso_tcp.c                |  82 ++++++
 lib/librte_gso/gso_tcp.h                |  73 ++++++
 lib/librte_gso/gso_tunnel.c             |  62 +++++
 lib/librte_gso/gso_tunnel.h             |  46 ++++
 lib/librte_gso/rte_gso.c                | 100 ++++++++
 lib/librte_gso/rte_gso.h                | 122 +++++++++
 lib/librte_gso/rte_gso_version.map      |   7 +
 mk/rte.app.mk                           |   1 +
 19 files changed, 1392 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_tcp.c
 create mode 100644 lib/librte_gso/gso_tcp.h
 create mode 100644 lib/librte_gso/gso_tunnel.c
 create mode 100644 lib/librte_gso/gso_tunnel.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

--
2.7.4

#21 lore raw
Quoted 76 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Wednesday, August 30, 2017 8:37 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>; Tan, Jianfeng <[email protected]>
Subject: Re: [PATCH 0/5] Support TCP/IPv4, VxLAN and GRE GSO in DPDK

Hi Konstantin,

Thanks for your suggestions. Feedbacks are inline.

Thanks,
Jiayu

Quoted 36 lines · Konstantin

Hi Jiayu,
Few questions/comments from me below in in next few mails. Thanks
Konstantin

Quoted 22 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 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:

Quoted 7 lines

a. Connect 2 x 10Gbps physical ports (P0, P1), together physically. b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine.
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.

Quoted 2 lines

Not sure I understand the setup correctly:
So testpmd forwards packets between P0 and vhost-user port, right?

Yes.

Quoted 1 line

And who uses P1? iperf-server over linux kernel?

P1 is possessed by linux kernel.

Quoted 1 line

Also is P1 on another box or not?

P0 and P1 are in the same machine and are connected physically.

Quoted 7 lines
Quoted 3 lines

With GSO enabled for P0 in testpmd, observed iperf throughput is ~9Gbps.

Ok, and if GSO is disabled what is the throughput?
Another stupid question: if P0 is physical 10G (ixgbe?) we can just enable a TSO on it, right? If so, what would be the TSO numbers here?

Here are more detailed experiment information:

Quoted 7 lines

test1: only enable GSO for p0, GSO size is 1518, use two iperf-clients (i.e. "-P 2")
test2: only enable TSO for p0, TSO size is 1518, use two iperf-clients
test3: disable TSO and GSO, use two iperf-clients

test1 performance: 8.6Gpbs
test2 throughput: 9.5Gbps
test3 throughput: 3Mbps

Ok thanks for detailed explanation.
I' d suggest you put it into next version cover letter.

Quoted 4 lines
Quoted 3 lines

In fact, could you probably explain a bit more, what supposed to be a main usage model for that library?

Quoted 8 lines

The GSO library is just a SW segmentation method, which can be used by applications, like OVS. Currently, most of NICs supports to segment TCP and UDP packets, but not for all NICs. So current OVS doesn't enable TSO, as a result of lacking a SW segmentation fallback. Besides, the protocol types in HW segmentation are limited. So it's necessary to provide a SW segmentation solution.

With the GSO library, OVS and other applications are able to receive large packets from VMs and process these large packets, instead of standard ones (i.e. 1518B). So the per-packet overhead is reduced, since the number of packets needed processing is much fewer.

Ok, just for my curiosity what is the size of the packets coming from VM? Konstantin

Quoted 55 lines
Quoted 2 lines

Is that to perform segmentation on (virtual) devices that doesn't support HW TSO or ...?

When launch qemu with enabling TSO or GSO, the virtual device doesn't really do segmentation. It directly sends large packets. Therefore, testpmd can receive large packets from the VM and then perform GSO. The GSO/TSO behavior of virtual devices is different from physical NICs.

Quoted 48 lines

Again would it be for a termination point (packets were just formed and filled) by the caller, or is that for box in the middle which just forwards packets between nodes?
If the later one, then we'll probably already have most of our packets segmented properly, no?

Quoted 44 lines

The experimental data of VxLAN and GRE will be shown later.

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

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

 app/test-pmd/cmdline.c                  | 121 +++++++++
 app/test-pmd/config.c                   |  25 ++
 app/test-pmd/csumonly.c                 |  68 ++++-
 app/test-pmd/testpmd.c                  |   9 +
 app/test-pmd/testpmd.h                  |  10 +
 config/common_base                      |   5 +
 lib/Makefile                            |   2 +
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |  52 ++++
 lib/librte_gso/gso_common.c             | 431 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 180 +++++++++++++
 lib/librte_gso/gso_tcp.c                |  82 ++++++
 lib/librte_gso/gso_tcp.h                |  73 ++++++
 lib/librte_gso/gso_tunnel.c             |  62 +++++
 lib/librte_gso/gso_tunnel.h             |  46 ++++
 lib/librte_gso/rte_gso.c                | 100 ++++++++
 lib/librte_gso/rte_gso.h                | 122 +++++++++
 lib/librte_gso/rte_gso_version.map      |   7 +
 mk/rte.app.mk                           |   1 +
 19 files changed, 1392 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_tcp.c
 create mode 100644 lib/librte_gso/gso_tcp.h
 create mode 100644 lib/librte_gso/gso_tunnel.c
 create mode 100644 lib/librte_gso/gso_tunnel.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

--
2.7.4

#22 lore raw
Quoted 90 lines

From: Ananyev, Konstantin
Sent: Wednesday, August 30, 2017 11:49 AM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH 0/5] Support TCP/IPv4, VxLAN and GRE GSO in DPDK

Quoted 5 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Wednesday, August 30, 2017 8:37 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>; Tan,

Jianfeng <[email protected]>

Quoted 51 lines

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

Hi Konstantin,

Thanks for your suggestions. Feedbacks are inline.

Thanks,
Jiayu

Quoted 36 lines · Konstantin

Hi Jiayu,
Few questions/comments from me below in in next few mails. Thanks
Konstantin

Quoted 22 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 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:

Quoted 7 lines

a. Connect 2 x 10Gbps physical ports (P0, P1), together physically. b. Launch testpmd with P0 and a vhost-user port, and use csum
forwarding engine.
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.

Quoted 2 lines

Not sure I understand the setup correctly:
So testpmd forwards packets between P0 and vhost-user port, right?

Yes.

Quoted 14 lines
Quoted 1 line

And who uses P1? iperf-server over linux kernel?

P1 is possessed by linux kernel.

Quoted 1 line

Also is P1 on another box or not?

P0 and P1 are in the same machine and are connected physically.

Quoted 6 lines
Quoted 3 lines

With GSO enabled for P0 in testpmd, observed iperf throughput is ~9Gbps.

Ok, and if GSO is disabled what is the throughput?
Another stupid question: if P0 is physical 10G (ixgbe?) we can just enable

a TSO on it, right?

Quoted 5 lines
Quoted 1 line

If so, what would be the TSO numbers here?

Here are more detailed experiment information:

test1: only enable GSO for p0, GSO size is 1518, use two iperf-clients (i.e.

"-P 2")

Quoted 3 lines

test2: only enable TSO for p0, TSO size is 1518, use two iperf-clients
test3: disable TSO and GSO, use two iperf-clients

Quoted 6 lines
Quoted 3 lines

test1 performance: 8.6Gpbs
test2 throughput: 9.5Gbps
test3 throughput: 3Mbps

Ok thanks for detailed explanation.
I' d suggest you put it into next version cover letter.

Thanks Konstantin - will do.

Quoted 15 lines
Quoted 4 lines
Quoted 4 lines

In fact, could you probably explain a bit more, what supposed to be a main

usage model for that library?

Quoted 2 lines

The GSO library is just a SW segmentation method, which can be used by

applications, like OVS.

Quoted 1 line

Currently, most of NICs supports to segment TCP and UDP packets, but not for

all NICs. So current

Quoted 1 line

OVS doesn't enable TSO, as a result of lacking a SW segmentation fallback.

Besides, the protocol

Quoted 1 line

types in HW segmentation are limited. So it's necessary to provide a SW

segmentation solution.

Quoted 1 line
Quoted 8 lines
Quoted 1 line

With the GSO library, OVS and other applications are able to receive large

packets from VMs and

Quoted 1 line

process these large packets, instead of standard ones (i.e. 1518B). So the

per-packet overhead is

Quoted 1 line

reduced, since the number of packets needed processing is much fewer.

Ok, just for my curiosity what is the size of the packets coming from VM? Konstantin

In the case of TSO (and as a corollary, GSO), I guess that the packet size is bounded to ~64k. In OvS, that packet is dequeued using the rte_vhost_dequeue_burst API, and stored in an mbuf chain. The data capacity of mbufs in OvS is user-defined, up to a limit of 9728B.

Thanks,
Mark

Quoted 65 lines
Quoted 4 lines
Quoted 4 lines

Is that to perform segmentation on (virtual) devices that doesn't support

HW TSO or ...?

Quoted 2 lines

When launch qemu with enabling TSO or GSO, the virtual device doesn't really

do segmentation.

Quoted 1 line

It directly sends large packets. Therefore, testpmd can receive large

packets from the VM and

Quoted 1 line

then perform GSO. The GSO/TSO behavior of virtual devices is different from

physical NICs.

Quoted 2 lines
Quoted 2 lines

Again would it be for a termination point (packets were just formed and

filled) by the caller,

Quoted 1 line
Quoted 1 line

or is that for box in the middle which just forwards packets between

nodes?

Quoted 1 line
Quoted 1 line

If the later one, then we'll probably already have most of our packets

segmented properly, no?

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines

The experimental data of VxLAN and GRE will be shown later.

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

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

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
 app/test-pmd/cmdline.c                  | 121 +++++++++
 app/test-pmd/config.c                   |  25 ++
 app/test-pmd/csumonly.c                 |  68 ++++-
 app/test-pmd/testpmd.c                  |   9 +
 app/test-pmd/testpmd.h                  |  10 +
 config/common_base                      |   5 +
 lib/Makefile                            |   2 +
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |  52 ++++
 lib/librte_gso/gso_common.c             | 431

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

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
 lib/librte_gso/gso_common.h             | 180 +++++++++++++
 lib/librte_gso/gso_tcp.c                |  82 ++++++
 lib/librte_gso/gso_tcp.h                |  73 ++++++
 lib/librte_gso/gso_tunnel.c             |  62 +++++
 lib/librte_gso/gso_tunnel.h             |  46 ++++
 lib/librte_gso/rte_gso.c                | 100 ++++++++
 lib/librte_gso/rte_gso.h                | 122 +++++++++
 lib/librte_gso/rte_gso_version.map      |   7 +
 mk/rte.app.mk                           |   1 +
 19 files changed, 1392 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_tcp.c
 create mode 100644 lib/librte_gso/gso_tcp.h
 create mode 100644 lib/librte_gso/gso_tunnel.c
 create mode 100644 lib/librte_gso/gso_tunnel.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

--
2.7.4

author
#23 lore raw

v2 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: ~9Gbps
test-2: 9.5Gbps
test-3: 3Mbps

The experimental data of VxLAN and GRE will be shown later.

Change log
==========
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                 |  60 ++++++-
 app/test-pmd/testpmd.c                  |  15 ++
 app/test-pmd/testpmd.h                  |  10 ++
 config/common_base                      |   5 +
 lib/Makefile                            |   2 +
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |  52 ++++++
 lib/librte_gso/gso_common.c             | 281 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 156 ++++++++++++++++++
 lib/librte_gso/gso_tcp.c                |  83 ++++++++++
 lib/librte_gso/gso_tcp.h                |  76 +++++++++
 lib/librte_gso/gso_tunnel.c             |  61 +++++++
 lib/librte_gso/gso_tunnel.h             |  75 +++++++++
 lib/librte_gso/rte_gso.c                |  99 +++++++++++
 lib/librte_gso/rte_gso.h                | 133 +++++++++++++++
 lib/librte_gso/rte_gso_version.map      |   7 +
 mk/rte.app.mk                           |   1 +
 19 files changed, 1315 insertions(+), 4 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_tcp.c
 create mode 100644 lib/librte_gso/gso_tcp.h
 create mode 100644 lib/librte_gso/gso_tunnel.c
 create mode 100644 lib/librte_gso/gso_tunnel.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
#24 lore raw

PATCH v2 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. This patch introduces the GSO API framework to DPDK.

The GSO library provides a segmentation API, rte_gso_segment(), for applications. It 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 ++
 lib/Makefile                       |   2 +
 lib/librte_gso/Makefile            |  49 ++++++++++++++
 lib/librte_gso/rte_gso.c           |  48 +++++++++++++
 lib/librte_gso/rte_gso.h           | 133 +++++++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map |   7 ++
 mk/rte.app.mk                      |   1 +
 7 files changed, 245 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
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 +48 -0

48 lines not on this page · raw message

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

133 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
#25 lore raw

PATCH v2 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 assumes that all 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.

---
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |   2 +
 lib/librte_gso/gso_common.c             | 207 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 107 +++++++++++++++++
 lib/librte_gso/gso_tcp.c                |  83 +++++++++++++
 lib/librte_gso/gso_tcp.h                |  76 ++++++++++++
 lib/librte_gso/rte_gso.c                |  46 ++++++-
 7 files changed, 519 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_tcp.c
 create mode 100644 lib/librte_gso/gso_tcp.h
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..0f8e38f 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_tcp.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c new file +207 -0

207 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_tcp.c new file +83 -0

83 lines not on this page · raw message

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

76 lines not on this page · raw message

lib/librte_gso/rte_gso.c +43 -3

61 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#26 lore raw

PATCH v2 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 | 50 ++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h | 36 +++++++++++++++++++++-
 lib/librte_gso/gso_tunnel.c | 61 ++++++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_tunnel.h | 75 +++++++++++++++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso.c    |  9 ++++++
 6 files changed, 231 insertions(+), 1 deletion(-)
 create mode 100644 lib/librte_gso/gso_tunnel.c
 create mode 100644 lib/librte_gso/gso_tunnel.h
lib/librte_gso/Makefile +1 -0
index 0f8e38f..a4d1a81 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_tcp.c
+SRCS-$(CONFIG_RTE_LIBRTE_GSO) += gso_tunnel.c
 
 # install this header file
 SYMLINK-$(CONFIG_RTE_LIBRTE_GSO)-include += rte_gso.h
lib/librte_gso/gso_common.c +50 -0

67 lines not on this page · raw message

lib/librte_gso/gso_common.h +35 -1
index ce3b955..3f76fd1 100644
@@ -44,6 +44,13 @@
 #define TCP_HDR_FIN_MASK ((uint8_t)0x01)
 
 #define ETHER_IPv4_PKT (RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4)
+#define INNER_ETHER_IPv4_TCP_PKT (RTE_PTYPE_INNER_L2_ETHER | \
+		RTE_PTYPE_INNER_L3_IPV4 | \
+		RTE_PTYPE_INNER_L4_TCP)
+#define INNER_ETHER_VLAN_IPv4_TCP_PKT (RTE_PTYPE_INNER_L2_ETHER_VLAN | \
+		RTE_PTYPE_INNER_L3_IPV4 | \
+		RTE_PTYPE_INNER_L4_TCP)
+
 /* TCP/IPv4 packet. */
 #define ETHER_IPv4_TCP_PKT (ETHER_IPv4_PKT | RTE_PTYPE_L4_TCP)
 
@@ -51,6 +58,33 @@
 #define ETHER_VLAN_IPv4_TCP_PKT (RTE_PTYPE_L2_ETHER_VLAN | \
 		RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP)
 
+/* VxLAN packet */
+#define ETHER_IPv4_UDP_VXLAN_IPv4_TCP_PKT (ETHER_IPv4_PKT | \
+		RTE_PTYPE_L4_UDP | \
+		RTE_PTYPE_TUNNEL_VXLAN | \
+		INNER_ETHER_IPv4_TCP_PKT)
+
+/* VxLAN packet with outer VLAN tag. */
+#define ETHER_VLAN_IPv4_UDP_VXLAN_IPv4_TCP_PKT (RTE_PTYPE_L2_ETHER_VLAN | \
+		RTE_PTYPE_L3_IPV4 | \
+		RTE_PTYPE_L4_UDP | \
+		RTE_PTYPE_TUNNEL_VXLAN | \
+		INNER_ETHER_IPv4_TCP_PKT)
+
+/* VxLAN packet with inner VLAN tag. */
+#define ETHER_IPv4_UDP_VXLAN_VLAN_IPv4_TCP_PKT (ETHER_IPv4_PKT | \
+		RTE_PTYPE_L4_UDP | \
+		RTE_PTYPE_TUNNEL_VXLAN | \
+		INNER_ETHER_VLAN_IPv4_TCP_PKT)
+
+/* VxLAN packet with both outer and inner VLAN tags. */
+#define ETHER_VLAN_IPv4_UDP_VXLAN_VLAN_IPv4_TCP_PKT (\
+		RTE_PTYPE_L2_ETHER_VLAN | \
+		RTE_PTYPE_L3_IPV4 | \
+		RTE_PTYPE_L4_UDP | \
+		RTE_PTYPE_TUNNEL_VXLAN | \
+		INNER_ETHER_VLAN_IPv4_TCP_PKT)
+
 /**
  * Internal function which updates relevant packet headers, following
  * segmentation. This is required to update, for example, the IPv4
@@ -79,7 +113,7 @@ void gso_update_pkt_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
  * @param pkt
  *  Packet to segment.
  * @param pkt_hdr_offset
- *  Packet header offset, measured in byte.
+ *  Packet header offset, measured in bytes.
  * @param pyld_unit_size
  *  The max payload length of a GSO segment.
  * @param direct_pool
lib/librte_gso/gso_tunnel.c new file +61 -0

61 lines not on this page · raw message

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

75 lines not on this page · raw message

lib/librte_gso/rte_gso.c +9 -0
index ef03375..0170abc 100644
@@ -36,6 +36,7 @@
 #include "rte_gso.h"
 #include "gso_common.h"
 #include "gso_tcp.h"
+#include "gso_tunnel.h"
 
 int
 rte_gso_segment(struct rte_mbuf *pkt,
@@ -71,6 +72,14 @@ rte_gso_segment(struct rte_mbuf *pkt,
 				direct_pool, indirect_pool,
 				pkts_out, nb_pkts_out);
 		break;
+	case ETHER_VLAN_IPv4_UDP_VXLAN_VLAN_IPv4_TCP_PKT:
+	case ETHER_VLAN_IPv4_UDP_VXLAN_IPv4_TCP_PKT:
+	case ETHER_IPv4_UDP_VXLAN_VLAN_IPv4_TCP_PKT:
+	case ETHER_IPv4_UDP_VXLAN_IPv4_TCP_PKT:
+		ret = gso_tunnel_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+		break;
 	default:
 		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");
 	}
Signature · 1 line
2.7.4
author
#27 lore raw

PATCH v2 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 | 24 ++++++++++++++++++++++++
 lib/librte_gso/gso_common.h | 15 +++++++++++++++
 lib/librte_gso/rte_gso.c    |  2 ++
 3 files changed, 41 insertions(+)
lib/librte_gso/gso_common.c +24 -0
index 1e16c9c..668d2d0 100644
@@ -37,6 +37,7 @@
 #include <rte_malloc.h>
 
 #include <rte_ether.h>
+#include <rte_gre.h>
 #include <rte_ip.h>
 #include <rte_tcp.h>
 #include <rte_udp.h>
@@ -238,6 +239,25 @@ 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)
@@ -249,6 +269,10 @@ gso_update_pkt_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
 	case ETHER_IPv4_UDP_VXLAN_IPv4_TCP_PKT:
 		update_ipv4_vxlan_tcp4_header(pkt, ipid_delta, segs, nb_segs);
 		break;
+	case ETHER_VLAN_IPv4_GRE_IPv4_TCP_PKT:
+	case ETHER_IPv4_GRE_IPv4_TCP_PKT:
+		update_ipv4_gre_tcp4_header(pkt, ipid_delta, segs, nb_segs);
+		break;
 	case ETHER_VLAN_IPv4_TCP_PKT:
 	case ETHER_IPv4_TCP_PKT:
 		update_inner_tcp4_header(pkt, ipid_delta, segs, nb_segs);
lib/librte_gso/gso_common.h +15 -0
index 3f76fd1..bd53bde 100644
@@ -85,6 +85,21 @@
 		RTE_PTYPE_TUNNEL_VXLAN | \
 		INNER_ETHER_VLAN_IPv4_TCP_PKT)
 
+/* GRE packet. */
+#define ETHER_IPv4_GRE_IPv4_TCP_PKT (\
+		ETHER_IPv4_PKT          | \
+		RTE_PTYPE_TUNNEL_GRE    | \
+		RTE_PTYPE_INNER_L3_IPV4 | \
+		RTE_PTYPE_INNER_L4_TCP)
+
+/* GRE packet with VLAN tag. */
+#define ETHER_VLAN_IPv4_GRE_IPv4_TCP_PKT (\
+		RTE_PTYPE_L2_ETHER_VLAN | \
+		RTE_PTYPE_L3_IPV4       | \
+		RTE_PTYPE_TUNNEL_GRE    | \
+		RTE_PTYPE_INNER_L3_IPV4 | \
+		RTE_PTYPE_INNER_L4_TCP)
+
 /**
  * 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 -0
index 0170abc..d40fda9 100644
@@ -76,6 +76,8 @@ rte_gso_segment(struct rte_mbuf *pkt,
 	case ETHER_VLAN_IPv4_UDP_VXLAN_IPv4_TCP_PKT:
 	case ETHER_IPv4_UDP_VXLAN_VLAN_IPv4_TCP_PKT:
 	case ETHER_IPv4_UDP_VXLAN_IPv4_TCP_PKT:
+	case ETHER_VLAN_IPv4_GRE_IPv4_TCP_PKT:
+	case ETHER_IPv4_GRE_IPv4_TCP_PKT:
 		ret = gso_tunnel_segment(pkt, gso_size, ipid_delta,
 				direct_pool, indirect_pool,
 				pkts_out, nb_pkts_out);
Signature · 1 line
2.7.4
author
#28 lore raw

PATCH v2 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 |  60 ++++++++++++++--
 app/test-pmd/testpmd.c  |  15 ++++
 app/test-pmd/testpmd.h  |  10 +++
 5 files changed, 283 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 +56 -4

107 lines not on this page · raw message

app/test-pmd/testpmd.c +15 -0
index 7d40139..e83fc95 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,11 @@ init_config(void)
 
 	init_port_config();
 
+	gso_types = RTE_PTYPE_L2_ETHER_VLAN | RTE_PTYPE_L2_ETHER |
+		RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP |
+		RTE_PTYPE_L4_UDP | RTE_PTYPE_TUNNEL_VXLAN |
+		RTE_PTYPE_INNER_L3_IPV4 | RTE_PTYPE_INNER_L4_TCP |
+		RTE_PTYPE_TUNNEL_GRE;
 	/*
 	 * Records which Mbuf pool to use by each logical core, if needed.
 	 */
@@ -664,6 +673,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
author
#29 lore raw

v3 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: ~9Gbps
test-2: 9.5Gbps
test-3: 3Mbps

The experimental data of VxLAN and GRE will be shown later.

Change log
==========
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                 | 102 +++++++++++-
 app/test-pmd/testpmd.c                  |  16 ++
 app/test-pmd/testpmd.h                  |  10 ++
 config/common_base                      |   5 +
 lib/Makefile                            |   2 +
 lib/librte_eal/common/include/rte_log.h |   1 +
 lib/librte_gso/Makefile                 |  52 ++++++
 lib/librte_gso/gso_common.c             | 270 ++++++++++++++++++++++++++++++++
 lib/librte_gso/gso_common.h             | 165 +++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               |  83 ++++++++++
 lib/librte_gso/gso_tcp4.h               |  76 +++++++++
 lib/librte_gso/gso_tunnel_tcp4.c        |  85 ++++++++++
 lib/librte_gso/gso_tunnel_tcp4.h        |  76 +++++++++
 lib/librte_gso/rte_gso.c                |  91 +++++++++++
 lib/librte_gso/rte_gso.h                | 133 ++++++++++++++++
 lib/librte_gso/rte_gso_version.map      |   7 +
 mk/rte.app.mk                           |   1 +
 19 files changed, 1373 insertions(+), 4 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
#30 lore raw

PATCH v3 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. This patch introduces the GSO API framework to DPDK.

The GSO library provides a segmentation API, rte_gso_segment(), for applications. It 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 ++
 lib/Makefile                       |   2 +
 lib/librte_gso/Makefile            |  49 ++++++++++++++
 lib/librte_gso/rte_gso.c           |  50 ++++++++++++++
 lib/librte_gso/rte_gso.h           | 133 +++++++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map |   7 ++
 mk/rte.app.mk                      |   1 +
 7 files changed, 247 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
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 +50 -0

50 lines not on this page · raw message

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

133 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
#31 lore raw

Re: [PATCH v3 1/5] gso: add Generic Segmentation Offload API framework

Hi Jiayu,
Few comments from be inline.
Konstantin

Quoted 36 lines
lib/librte_gso/rte_gso.c new file +30 -0
new file mode 100644
index 0000000..dda50ee
@@ -0,0 +1,50 @@
+/*-
+ *   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

lib/librte_gso/rte_gso.c line 40

Quoted 10 lines
lib/librte_gso/rte_gso.c new file +10 -0
+ *   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,
+		struct rte_gso_ctx gso_ctx __rte_unused,

No need to pass parameter by value here.
struct rte_gso_ctx *gso_ctx would do.
Even better - const struct rte_gso_ctx *, in case it doesn't need to need to be updated inside that function.

Quoted 59 lines
lib/librte_gso/rte_gso.c new file +10 -0
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	if (pkt == NULL || pkts_out == NULL || nb_pkts_out < 1)
+		return -EINVAL;
+
+	pkts_out[0] = pkt;
+
+	return 1;
+}
lib/librte_gso/rte_gso.h new file +43 -0
new file mode 100644
index 0000000..db757d6
@@ -0,0 +1,133 @@
+/*-
+ *   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" {

lib/librte_gso/rte_gso.h line 53

Quoted 10 lines
lib/librte_gso/rte_gso.h new file +10 -0
+#endif
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/* GSO IP id flags for the IPv4 header */
+#define RTE_GSO_IPID_FIXED (1 << 0)
+/**< Use fixed IP ids for output GSO segments */
+#define RTE_GSO_IPID_INCREASE (1 << 1)
+/**< Use incremental IP ids for output GSO segments */

As values above are mutually exclusive, I think you don't need both flags. Just one seems enough.

Quoted 9 lines
lib/librte_gso/rte_gso.h new file +9 -0
+
+/**
+ * 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.
+	 */

lib/librte_gso/rte_gso.h line 72

Quoted 10 lines
lib/librte_gso/rte_gso.h new file +10 -0
+	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.
+	 */
+	uint32_t gso_types;
+	/**< packet types to perform GSO. For example, if applications
+	 * want to segment TCP/IPv4 packets, may set (RTE_PTYPE_L2_ETHER |
+	 * RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP) to gso_types.

Actually after another thought - it probably should be no ptype mask, but mask of rte_ethdev DEV_TX_OFFLOAD_*_TSO flags that are used to advertise real HW TSO offloads. Let say for GSO that supports TSO over IPv4 it would be:
PKT_TX_TCP_SEG | PKT_TX_IPV4.
That would allow user to use GSO and TSO in a transparent way,
plus ptype is not actually a proper bitmask, but a set of enums,
so it not always possible to distinguish what ptype is supported just by bitmask. Sorry for causing confusion here.

lib/librte_gso/rte_gso.h line 78

Quoted 6 lines
lib/librte_gso/rte_gso.h new file +6 -0
+	 */
+	uint16_t gso_size;
+	/**< maximum size of an output GSO segment, including packet
+	 * header and payload, measured in bytes.
+	 */
+	uint8_t ipid_flag;

I'd suggest uint32_t flags (or even uint64_t). Who knows what extra flags we'll need in future here.

Quoted 55 lines
lib/librte_gso/rte_gso.h new file +55 -0
+	/**< flag to indicate GSO uses fixed or incremental IP ids for
+	 * IPv4 headers of output GSO segments.
+	 */
+};
+
+/**
+ * Segmentation function, which supports processing of both single- and
+ * multi- segment packets.
+ *
+ * Note that we refer to the packets that are segmented from the input
+ * packet as 'GSO segments'. rte_gso_segment() assumes the input packet
+ * has correct checksums, and it doesn't update checksums for output
+ * GSO segments. Additionally, it doesn't process IP fragment packets.
+ *
+ * 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. 2 MBUFs), the driver of the interface which the
+ * GSO segments are sent to should support to transmit multi-segment
+ * packets.
+ *
+ * If the input packet is GSOed, 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 successes,
+ * 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.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when rte_gso_segment() successes.
+ * @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,
+		struct rte_gso_ctx ctx,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_GSO_H_ */
author
#32 lore raw

Re: [PATCH v3 1/5] gso: add Generic Segmentation Offload API framework

Hi Konstantin,

Thanks for your quick feedbacks. Replies are inline.

Thanks,
Jiayu

Quoted 47 lines · Konstantin

Hi Jiayu,
Few comments from be inline.
Konstantin

Quoted 43 lines
lib/librte_gso/rte_gso.c new file +37 -0
new file mode 100644
index 0000000..dda50ee
@@ -0,0 +1,50 @@
+/*-
+ *   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"
+
Quoted 8 lines

lib/librte_gso/rte_gso.c line 40

Quoted 3 lines
lib/librte_gso/rte_gso.c new file +3 -0
+int
+rte_gso_segment(struct rte_mbuf *pkt,
+		struct rte_gso_ctx gso_ctx __rte_unused,

No need to pass parameter by value here.
struct rte_gso_ctx *gso_ctx would do.
Even better - const struct rte_gso_ctx *, in case it doesn't need to need to be updated inside that function.

Yes, agree. I will use rte_gso_ctx *gso_ctx instead.

Quoted 65 lines
Quoted 65 lines
lib/librte_gso/rte_gso.c new file +10 -0
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out)
+{
+	if (pkt == NULL || pkts_out == NULL || nb_pkts_out < 1)
+		return -EINVAL;
+
+	pkts_out[0] = pkt;
+
+	return 1;
+}
lib/librte_gso/rte_gso.h new file +48 -0
new file mode 100644
index 0000000..db757d6
@@ -0,0 +1,133 @@
+/*-
+ *   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>
+
Quoted 8 lines

lib/librte_gso/rte_gso.h line 53

Quoted 5 lines
lib/librte_gso/rte_gso.h new file +5 -0
+/* GSO IP id flags for the IPv4 header */
+#define RTE_GSO_IPID_FIXED (1 << 0)
+/**< Use fixed IP ids for output GSO segments */
+#define RTE_GSO_IPID_INCREASE (1 << 1)
+/**< Use incremental IP ids for output GSO segments */

As values above are mutually exclusive, I think you don't need both flags. Just one seems enough.

Agree, I will remove RTE_GSO_IPID_INCREASE.

Quoted 23 lines
Quoted 11 lines
lib/librte_gso/rte_gso.h new file +9 -0
+
+/**
+ * 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.
+	 */

lib/librte_gso/rte_gso.h line 72

Quoted 10 lines
lib/librte_gso/rte_gso.h new file +10 -0
+	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.
+	 */
+	uint32_t gso_types;
+	/**< packet types to perform GSO. For example, if applications
+	 * want to segment TCP/IPv4 packets, may set (RTE_PTYPE_L2_ETHER |
+	 * RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_TCP) to gso_types.
Quoted 8 lines

Actually after another thought - it probably should be no ptype mask, but mask of rte_ethdev DEV_TX_OFFLOAD_*_TSO flags that are used to advertise real HW TSO offloads. Let say for GSO that supports TSO over IPv4 it would be:
PKT_TX_TCP_SEG | PKT_TX_IPV4.
That would allow user to use GSO and TSO in a transparent way,
plus ptype is not actually a proper bitmask, but a set of enums,
so it not always possible to distinguish what ptype is supported just by bitmask. Sorry for causing confusion here.

Yes, agree. Reusing packet_type indeed introduces lots of macros to applications. DEV_TX_OFFLOAD_*_TSO is a better choice, and it can also make HW offload and SW offload consistent.

Quoted 10 lines

lib/librte_gso/rte_gso.h line 78

Quoted 7 lines
lib/librte_gso/rte_gso.h new file +6 -0
+	 */
+	uint16_t gso_size;
+	/**< maximum size of an output GSO segment, including packet
+	 * header and payload, measured in bytes.
+	 */
+	uint8_t ipid_flag;

I'd suggest uint32_t flags (or even uint64_t). Who knows what extra flags we'll need in future here.

Make sense. I will use uint64_t.

Quoted 56 lines
Quoted 56 lines
lib/librte_gso/rte_gso.h new file +55 -0
+	/**< flag to indicate GSO uses fixed or incremental IP ids for
+	 * IPv4 headers of output GSO segments.
+	 */
+};
+
+/**
+ * Segmentation function, which supports processing of both single- and
+ * multi- segment packets.
+ *
+ * Note that we refer to the packets that are segmented from the input
+ * packet as 'GSO segments'. rte_gso_segment() assumes the input packet
+ * has correct checksums, and it doesn't update checksums for output
+ * GSO segments. Additionally, it doesn't process IP fragment packets.
+ *
+ * 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. 2 MBUFs), the driver of the interface which the
+ * GSO segments are sent to should support to transmit multi-segment
+ * packets.
+ *
+ * If the input packet is GSOed, 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 successes,
+ * 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.
+ * @param pkts_out
+ *  Pointer array used to store the MBUF addresses of output GSO
+ *  segments, when rte_gso_segment() successes.
+ * @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,
+		struct rte_gso_ctx ctx,
+		struct rte_mbuf **pkts_out,
+		uint16_t nb_pkts_out);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTE_GSO_H_ */
#33 lore raw

Re: [PATCH v3 1/5] gso: add Generic Segmentation Offload API framework

In reply to Jiayu Hu
Quoted 23 lines · 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 introduces the GSO API framework to DPDK.

The GSO library provides a segmentation API, rte_gso_segment(), for applications. It 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.

Quoted 8 lines
---
 config/common_base                 |   5 ++
 lib/Makefile                       |   2 +
 lib/librte_gso/Makefile            |  49 ++++++++++++++
 lib/librte_gso/rte_gso.c           |  50 ++++++++++++++
 lib/librte_gso/rte_gso.h           | 133 +++++++++++++++++++++++++++++++++++++
 lib/librte_gso/rte_gso_version.map |   7 ++
 mk/rte.app.mk                      |   1 +

Can you please update documentation for new library:

- library documentation "doc/guides/prog_guide/xxx.rst"
- api documentation: doc/api/doxy-api.conf, doc/api/doxy-api-index.md
- release notes update to announce new library
- release notes, "Shared Library Versions" section with new library.

<...>

author
#34 lore raw

Re: [PATCH v3 1/5] gso: add Generic Segmentation Offload API framework

Hi Ferruh,

Quoted 44 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 1/5] gso: add Generic Segmentation Offload API framework

Quoted 8 lines · 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 introduces the GSO API framework to DPDK.

Quoted 5 lines

The GSO library provides a segmentation API, rte_gso_segment(), for applications. It 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

Quoted 8 lines

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.

Quoted 8 lines
---
 config/common_base                 |   5 ++
 lib/Makefile                       |   2 +
 lib/librte_gso/Makefile            |  49 ++++++++++++++
 lib/librte_gso/rte_gso.c           |  50 ++++++++++++++
 lib/librte_gso/rte_gso.h           | 133

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

Quoted 2 lines
 lib/librte_gso/rte_gso_version.map |   7 ++
 mk/rte.app.mk                      |   1 +
Quoted 6 lines

Can you please update documentation for new library:

- library documentation "doc/guides/prog_guide/xxx.rst"
- api documentation: doc/api/doxy-api.conf, doc/api/doxy-api-index.md
- release notes update to announce new library
- release notes, "Shared Library Versions" section with new library.

Thanks for your reminder. I will update them sooner.

Jiayu

Quoted 2 lines

<...>

author
#35 lore raw

PATCH v3 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 assumes that all 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.

---
 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             | 113 ++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               |  83 +++++++++++++
 lib/librte_gso/gso_tcp4.h               |  76 ++++++++++++
 lib/librte_gso/rte_gso.c                |  41 ++++++-
 7 files changed, 515 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
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 +113 -0

113 lines not on this page · raw message

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

83 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 +38 -3

56 lines not on this page · raw message

Signature · 1 line
2.7.4
#36 lore raw

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

Hi Jayu,

Quoted 8 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Tuesday, September 12, 2017 3:43 AM
To: [email protected]
Cc: Ananyev, Konstantin <[email protected]>; Kavanagh, Mark B <[email protected]>; Tan, Jianfeng <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 4 lines

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

Probably it shouldn't say that checksum have to be valid, right? As you don't update checksum(s) inside the lib - it probably doesn't matter.

Quoted 219 lines

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.

---
 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             | 113 ++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               |  83 +++++++++++++
 lib/librte_gso/gso_tcp4.h               |  76 ++++++++++++
 lib/librte_gso/rte_gso.c                |  41 ++++++-
 7 files changed, 515 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
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 +159 -0
new file mode 100644
index 0000000..7c32e03
@@ -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.
+ */
+
+#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;
+
+			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_inner_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,

lib/librte_gso/gso_common.c line 169

Quoted 10 lines
lib/librte_gso/gso_common.c new file +10 -0
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	struct tcp_hdr *tcp_hdr;
+	struct ipv4_hdr *ipv4_hdr;
+	struct rte_mbuf *seg;
+	uint32_t sent_seq;
+	uint16_t inner_l2_offset;
+	uint16_t id, i;
+
+	inner_l2_offset = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;

Shouldn't it be: pkt->l2_len here?
Or probably even better to pass l2_len as an input parameter.

Quoted 69 lines
lib/librte_gso/gso_common.c new file +33 -0
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			inner_l2_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);
+
+	for (i = 0; i < nb_segs; i++) {
+		seg = segs[i];
+		/* Update the inner IPv4 header */
+		ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(seg, char *) +
+				inner_l2_offset);
+		ipv4_hdr->total_length = rte_cpu_to_be_16(seg->pkt_len -
+				inner_l2_offset);
+		ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
+		id += ipid_delta;
+
+		/* Update the inner TCP header */
+		tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + seg->l3_len);
+		tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
+		if (likely(i < nb_segs - 1))
+			tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK |
+						TCP_HDR_FIN_MASK));
+		sent_seq += (seg->pkt_len - seg->data_len);
+	}
+}
+
+void
+gso_update_pkt_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	if (is_ipv4_tcp(pkt->packet_type))
+		update_inner_tcp4_header(pkt, ipid_delta, segs, nb_segs);
+}
lib/librte_gso/gso_common.h new file +30 -0
new file mode 100644
index 0000000..3c76520
@@ -0,0 +1,113 @@
+/*-
+ *   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

lib/librte_gso/gso_common.h line 40

Quoted 10 lines
lib/librte_gso/gso_common.h new file +10 -0
+ *   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>
+
+#define IPV4_HDR_DF_SHIFT 14

We have that already defined in librte_net/rte_ip.h

lib/librte_gso/gso_common.h line 52

Quoted 12 lines
lib/librte_gso/gso_common.h new file +12 -0
+#define IPV4_HDR_DF_MASK (1 << IPV4_HDR_DF_SHIFT)
+
+#define TCP_HDR_PSH_MASK ((uint8_t)0x08)
+#define TCP_HDR_FIN_MASK ((uint8_t)0x01)
+
+#define ETHER_TCP_PKT (RTE_PTYPE_L2_ETHER | RTE_PTYPE_L4_TCP)
+#define ETHER_VLAN_TCP_PKT (RTE_PTYPE_L2_ETHER_VLAN | RTE_PTYPE_L4_TCP)
+static inline uint8_t is_ipv4_tcp(uint32_t ptype)
+{
+	switch (ptype & (~RTE_PTYPE_L3_MASK)) {
+	case ETHER_VLAN_TCP_PKT:
+	case ETHER_TCP_PKT:

Why not just:
return RTE_ETH_IS_IPV4_HDR(ptype) && (ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP; ?

Quoted 117 lines
lib/librte_gso/gso_common.h new file +61 -0
+		return RTE_ETH_IS_IPV4_HDR(ptype);
+	default:
+		return 0;
+	}
+}
+
+/**
+ * Internal function which updates relevant packet headers, 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 gso_update_pkt_headers(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.
+ */
+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 +50 -0
new file mode 100644
index 0000000..8d4bfb2
@@ -0,0 +1,83 @@
+/*-
+ *   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_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;

lib/librte_gso/gso_tcp4.c line 60

Quoted 10 lines
lib/librte_gso/gso_tcp4.c new file +10 -0
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size;
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->l2_len);
+	/* Don't process the fragmented packet */
+	if (unlikely((ipv4_hdr->fragment_offset & rte_cpu_to_be_16(
+						IPV4_HDR_DF_MASK)) == 0)) {

It is not a check for fragmented packet - it is a check that fragmentation is allowed for that packet. Should be IPV4_HDR_DF_MASK - 1, I think.

lib/librte_gso/gso_tcp4.c line 66

Quoted 6 lines
lib/librte_gso/gso_tcp4.c new file +6 -0
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len -
+		pkt->l4_len;

Why not use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len?

lib/librte_gso/gso_tcp4.c line 74

Quoted 8 lines
lib/librte_gso/gso_tcp4.c new file +8 -0
+	/* Don't process the packet without data */
+	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 - ETHER_CRC_LEN;

Hmm, why do we need to count CRC_LEN here?

Quoted 125 lines
lib/librte_gso/gso_tcp4.c new file +9 -0
+
+	/* 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)
+		gso_update_pkt_headers(pkt, ipid_delta, pkts_out, ret);
+
+	return ret;
+}
lib/librte_gso/gso_tcp4.h new file +76 -0
new file mode 100644
index 0000000..9c07984
@@ -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_TCP4_H_
+#define _GSO_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment an IPv4/TCP packet. This function assumes the input packet has
+ * correct checksums and doesn't update checksums for GSO segment.
+ * 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 +14 -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) {

lib/librte_gso/rte_gso.c line 69

Quoted 10 lines
lib/librte_gso/rte_gso.c +10 -0
+		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_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) {...

lib/librte_gso/rte_gso.c line 74

Quoted 5 lines
lib/librte_gso/rte_gso.c +5 -0
+		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else
+		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");

Shouldn't we do pkt_out[0] = pkt; here?

Quoted 14 lines
lib/librte_gso/rte_gso.c +9 -2
+
+	if (ret > 1) {
+		pkt_seg = pkt;
+		while (pkt_seg) {
+			rte_mbuf_refcnt_update(pkt_seg, -1);
+			pkt_seg = pkt_seg->next;
+		}
+	}
 
-	return 1;
+	return ret;
 }
--

2.7.4

author
#37 lore raw

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

Hi Konstantin,

Quoted 10 lines · Konstantin

Hi Jayu,

Quoted 8 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Tuesday, September 12, 2017 3:43 AM
To: [email protected]
Cc: Ananyev, Konstantin <[email protected]>; Kavanagh, Mark B <[email protected]>; Tan, Jianfeng <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 7 lines
Quoted 4 lines

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

Probably it shouldn't say that checksum have to be valid, right? As you don't update checksum(s) inside the lib - it probably doesn't matter.

Yes, you are right. It's better to use:
"TCP/IPv4 GSO doesn't check if checksums are correct and doesn't update checksums for output packets".

Quoted 225 lines
Quoted 225 lines

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.

---
 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             | 113 ++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               |  83 +++++++++++++
 lib/librte_gso/gso_tcp4.h               |  76 ++++++++++++
 lib/librte_gso/rte_gso.c                |  41 ++++++-
 7 files changed, 515 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
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 +164 -0
new file mode 100644
index 0000000..7c32e03
@@ -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.
+ */
+
+#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;
+
+			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_inner_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;
+	struct rte_mbuf *seg;
Quoted 8 lines

lib/librte_gso/gso_common.c line 169

Quoted 5 lines
lib/librte_gso/gso_common.c new file +5 -0
+	uint32_t sent_seq;
+	uint16_t inner_l2_offset;
+	uint16_t id, i;
+
+	inner_l2_offset = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;

Shouldn't it be: pkt->l2_len here?
Or probably even better to pass l2_len as an input parameter.

Oh, yes. Applications won't guarantee outer_l2_len and outer_l3_len are 0 for non-tunnelling packets. I will add l2_len as a parameter instead.

Quoted 74 lines
Quoted 74 lines
lib/librte_gso/gso_common.c new file +33 -0
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			inner_l2_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);
+
+	for (i = 0; i < nb_segs; i++) {
+		seg = segs[i];
+		/* Update the inner IPv4 header */
+		ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(seg, char *) +
+				inner_l2_offset);
+		ipv4_hdr->total_length = rte_cpu_to_be_16(seg->pkt_len -
+				inner_l2_offset);
+		ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
+		id += ipid_delta;
+
+		/* Update the inner TCP header */
+		tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + seg->l3_len);
+		tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
+		if (likely(i < nb_segs - 1))
+			tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK |
+						TCP_HDR_FIN_MASK));
+		sent_seq += (seg->pkt_len - seg->data_len);
+	}
+}
+
+void
+gso_update_pkt_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	if (is_ipv4_tcp(pkt->packet_type))
+		update_inner_tcp4_header(pkt, ipid_delta, segs, nb_segs);
+}
lib/librte_gso/gso_common.h new file +34 -0
new file mode 100644
index 0000000..3c76520
@@ -0,0 +1,113 @@
+/*-
+ *   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_
Quoted 8 lines

lib/librte_gso/gso_common.h line 40

Quoted 6 lines
lib/librte_gso/gso_common.h new file +6 -0
+#define _GSO_COMMON_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+#define IPV4_HDR_DF_SHIFT 14

We have that already defined in librte_net/rte_ip.h

Yes. I will remove it here.

Quoted 17 lines

lib/librte_gso/gso_common.h line 52

Quoted 13 lines
lib/librte_gso/gso_common.h new file +12 -0
+#define IPV4_HDR_DF_MASK (1 << IPV4_HDR_DF_SHIFT)
+
+#define TCP_HDR_PSH_MASK ((uint8_t)0x08)
+#define TCP_HDR_FIN_MASK ((uint8_t)0x01)
+
+#define ETHER_TCP_PKT (RTE_PTYPE_L2_ETHER | RTE_PTYPE_L4_TCP)
+#define ETHER_VLAN_TCP_PKT (RTE_PTYPE_L2_ETHER_VLAN | RTE_PTYPE_L4_TCP)
+static inline uint8_t is_ipv4_tcp(uint32_t ptype)
+{
+	switch (ptype & (~RTE_PTYPE_L3_MASK)) {
+	case ETHER_VLAN_TCP_PKT:
+	case ETHER_TCP_PKT:

Why not just:
return RTE_ETH_IS_IPV4_HDR(ptype) && (ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP; ?

Yes, we don't need to check if the packet is vlan encapsulated.

Quoted 124 lines
Quoted 124 lines
lib/librte_gso/gso_common.h new file +61 -0
+		return RTE_ETH_IS_IPV4_HDR(ptype);
+	default:
+		return 0;
+	}
+}
+
+/**
+ * Internal function which updates relevant packet headers, 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 gso_update_pkt_headers(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.
+ */
+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 +56 -0
new file mode 100644
index 0000000..8d4bfb2
@@ -0,0 +1,83 @@
+/*-
+ *   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_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;
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
Quoted 8 lines

lib/librte_gso/gso_tcp4.c line 60

Quoted 4 lines
lib/librte_gso/gso_tcp4.c new file +4 -0
+			pkt->l2_len);
+	/* Don't process the fragmented packet */
+	if (unlikely((ipv4_hdr->fragment_offset & rte_cpu_to_be_16(
+						IPV4_HDR_DF_MASK)) == 0)) {

It is not a check for fragmented packet - it is a check that fragmentation is allowed for that packet. Should be IPV4_HDR_DF_MASK - 1, I think.

IMO, IPV4_HDR_DF_MASK whose value is (1 << 14) is used to get DF bit. It's a little-endian value. But ipv4_hdr->fragment_offset is big-endian order. So the value of DF bit should be "ipv4_hdr->fragment_offset & rte_cpu_to_be_16( IPV4_HDR_DF_MASK)". If this value is 0, the input packet is fragmented.

Quoted 9 lines

lib/librte_gso/gso_tcp4.c line 66

Quoted 7 lines
lib/librte_gso/gso_tcp4.c new file +6 -0
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len -
+		pkt->l4_len;

Why not use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len?

Yes, we can use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len here.

Quoted 11 lines

lib/librte_gso/gso_tcp4.c line 74

Quoted 9 lines
lib/librte_gso/gso_tcp4.c new file +8 -0
+	/* Don't process the packet without data */
+	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 - ETHER_CRC_LEN;

Hmm, why do we need to count CRC_LEN here?

Yes, we shouldn't count ETHER_CRC_LEN here. Its length should be included in gso_size.

Quoted 140 lines
Quoted 126 lines
lib/librte_gso/gso_tcp4.c new file +9 -0
+
+	/* 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)
+		gso_update_pkt_headers(pkt, ipid_delta, pkts_out, ret);
+
+	return ret;
+}
lib/librte_gso/gso_tcp4.h new file +76 -0
new file mode 100644
index 0000000..9c07984
@@ -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_TCP4_H_
+#define _GSO_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment an IPv4/TCP packet. This function assumes the input packet has
+ * correct checksums and doesn't update checksums for GSO segment.
+ * 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 +14 -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) {

lib/librte_gso/rte_gso.c line 69

Quoted 10 lines
lib/librte_gso/rte_gso.c +10 -0
+		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_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 7 lines

lib/librte_gso/rte_gso.c line 74

Quoted 5 lines
lib/librte_gso/rte_gso.c +5 -0
+		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else
+		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");

Shouldn't we do pkt_out[0] = pkt; here?

Yes, we need to add it here. Thanks for reminder.

Quoted 15 lines
Quoted 15 lines
lib/librte_gso/rte_gso.c +9 -2
+
+	if (ret > 1) {
+		pkt_seg = pkt;
+		while (pkt_seg) {
+			rte_mbuf_refcnt_update(pkt_seg, -1);
+			pkt_seg = pkt_seg->next;
+		}
+	}
 
-	return 1;
+	return ret;
 }
--

2.7.4

#38 lore raw

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

Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
lib/librte_gso/gso_tcp4.c new file +17 -0
+
+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;
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
Quoted 8 lines
Quoted 8 lines

lib/librte_gso/gso_tcp4.c line 60

Quoted 4 lines
lib/librte_gso/gso_tcp4.c new file +4 -0
+			pkt->l2_len);
+	/* Don't process the fragmented packet */
+	if (unlikely((ipv4_hdr->fragment_offset & rte_cpu_to_be_16(
+						IPV4_HDR_DF_MASK)) == 0)) {

It is not a check for fragmented packet - it is a check that fragmentation is allowed for that packet. Should be IPV4_HDR_DF_MASK - 1, I think.

DF bit doesn't indicate is packet fragmented or not.
It forbids to fragment packet any further.
To check is packet already fragmented or not, you have to check MF bit and frag_offset. Both have to be zero for un-fragmented packets.

Quoted 30 lines

IMO, IPV4_HDR_DF_MASK whose value is (1 << 14) is used to get DF bit. It's a little-endian value. But ipv4_hdr->fragment_offset is big-endian order. So the value of DF bit should be "ipv4_hdr->fragment_offset & rte_cpu_to_be_16( IPV4_HDR_DF_MASK)". If this value is 0, the input packet is fragmented.

Quoted 9 lines

lib/librte_gso/gso_tcp4.c line 66

Quoted 7 lines
lib/librte_gso/gso_tcp4.c new file +6 -0
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len -
+		pkt->l4_len;

Why not use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len?

Yes, we can use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len here.

Quoted 11 lines

lib/librte_gso/gso_tcp4.c line 74

Quoted 9 lines
lib/librte_gso/gso_tcp4.c new file +8 -0
+	/* Don't process the packet without data */
+	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 - ETHER_CRC_LEN;

Hmm, why do we need to count CRC_LEN here?

Quoted 2 lines

Yes, we shouldn't count ETHER_CRC_LEN here. Its length should be included in gso_size.

Why?
What is the point to account crc len into this computation? Why not just assume that gso_size is already a max_frame_size - crc_len As I remember, when we RX packet crc bytes will be already stripped, when user populates the packet, he doesn't care about crc bytes too.

Konstantin

author
#39 lore raw

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

Hi Konstantin,

Quoted 35 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Wednesday, September 13, 2017 5:38 PM
To: Hu, Jiayu <[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

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
lib/librte_gso/gso_tcp4.c new file +13 -0
+
+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;
Quoted 8 lines
Quoted 8 lines

lib/librte_gso/gso_tcp4.c

Quoted 8 lines
lib/librte_gso/gso_tcp4.c new file +8 -0
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->l2_len);
+	/* Don't process the fragmented packet */
+	if (unlikely((ipv4_hdr->fragment_offset & rte_cpu_to_be_16(
+						IPV4_HDR_DF_MASK)) == 0))

{

Quoted 3 lines
Quoted 3 lines

It is not a check for fragmented packet - it is a check that fragmentation

Quoted 8 lines

is allowed for that packet.

Quoted 1 line
Quoted 1 line

Should be IPV4_HDR_DF_MASK - 1, I think.

DF bit doesn't indicate is packet fragmented or not.
It forbids to fragment packet any further.
To check is packet already fragmented or not, you have to check MF bit and frag_offset.
Both have to be zero for un-fragmented packets.

Yes, you are right. I checked the RFC and I misunderstood the meaning of DF bit. When DF bit is set to 1, the packet isn't IP fragmented. When DF bit is 0, the packet may or may not be fragmented. So it can't indicate if the packet is an IP fragment. Only both MF and offset are 0, the packet is not fragmented.

Quoted 33 lines
Quoted 3 lines

IMO, IPV4_HDR_DF_MASK whose value is (1 << 14) is used to get DF bit. It's

a

Quoted 2 lines

little-endian value. But ipv4_hdr->fragment_offset is big-endian order. So the value of DF bit should be "ipv4_hdr->fragment_offset &

rte_cpu_to_be_16(

Quoted 26 lines

IPV4_HDR_DF_MASK)". If this value is 0, the input packet is fragmented.

Quoted 9 lines

lib/librte_gso/gso_tcp4.c line 66

Quoted 7 lines
lib/librte_gso/gso_tcp4.c new file +6 -0
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len -
+		pkt->l4_len;

Why not use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len?

Yes, we can use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len here.

Quoted 11 lines

lib/librte_gso/gso_tcp4.c line 74

Quoted 9 lines
lib/librte_gso/gso_tcp4.c new file +8 -0
+	/* Don't process the packet without data */
+	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 - ETHER_CRC_LEN;

Hmm, why do we need to count CRC_LEN here?

Quoted 8 lines
Quoted 2 lines

Yes, we shouldn't count ETHER_CRC_LEN here. Its length should be included in gso_size.

Why?
What is the point to account crc len into this computation? Why not just assume that gso_size is already a max_frame_size - crc_len As I remember, when we RX packet crc bytes will be already stripped, when user populates the packet, he doesn't care about crc bytes too.

Sorry, maybe I didn't make it clear. I don't mean that applications must count CRC when set gso_segsz. It's related specific scenarios to decide if count CRC in gso_segsz or not, IMO. The GSO library shouldn't be aware of CRC, and just uses gso_segsz to split packets.

Thanks,
Jiayu

Quoted 2 lines

Konstantin

#40 lore raw

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

In reply to Ananyev, Konstantin
Quoted 73 lines

From: Ananyev, Konstantin
Sent: Wednesday, September 13, 2017 10:38 AM
To: Hu, Jiayu <[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

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
lib/librte_gso/gso_tcp4.c new file +16 -0
+
+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;
+	uint16_t hdr_offset;
+	int ret = 1;
+
Quoted 8 lines
Quoted 8 lines

lib/librte_gso/gso_tcp4.c line 60

Quoted 5 lines
lib/librte_gso/gso_tcp4.c new file +5 -0
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->l2_len);
+	/* Don't process the fragmented packet */
+	if (unlikely((ipv4_hdr->fragment_offset & rte_cpu_to_be_16(
+						IPV4_HDR_DF_MASK)) == 0)) {

It is not a check for fragmented packet - it is a check that fragmentation

is allowed for that packet.

Quoted 1 line
Quoted 1 line

Should be IPV4_HDR_DF_MASK - 1, I think.

DF bit doesn't indicate is packet fragmented or not.
It forbids to fragment packet any further.
To check is packet already fragmented or not, you have to check MF bit and frag_offset.
Both have to be zero for un-fragmented packets.

Quoted 4 lines

IMO, IPV4_HDR_DF_MASK whose value is (1 << 14) is used to get DF bit. It's a little-endian value. But ipv4_hdr->fragment_offset is big-endian order. So the value of DF bit should be "ipv4_hdr->fragment_offset &

rte_cpu_to_be_16(

Quoted 26 lines

IPV4_HDR_DF_MASK)". If this value is 0, the input packet is fragmented.

Quoted 9 lines

lib/librte_gso/gso_tcp4.c line 66

Quoted 7 lines
lib/librte_gso/gso_tcp4.c new file +6 -0
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len -
+		pkt->l4_len;

Why not use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len?

Yes, we can use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len here.

Quoted 11 lines

lib/librte_gso/gso_tcp4.c line 74

Quoted 9 lines
lib/librte_gso/gso_tcp4.c new file +8 -0
+	/* Don't process the packet without data */
+	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 - ETHER_CRC_LEN;

Hmm, why do we need to count CRC_LEN here?

Quoted 8 lines
Quoted 2 lines

Yes, we shouldn't count ETHER_CRC_LEN here. Its length should be included in gso_size.

Why?
What is the point to account crc len into this computation? Why not just assume that gso_size is already a max_frame_size - crc_len As I remember, when we RX packet crc bytes will be already stripped, when user populates the packet, he doesn't care about crc bytes too.

Hi Konstantin,

When packet is tx'd, the 4B for CRC are added back into the packet; if the payload is already at max capacity, then the actual segment size will be 4B larger than expected (e.g. 1522B, as opposed to 1518B). To prevent that from happening, we account for the CRC len in this calculation.

If I've missed anything, please do let me know!

Thanks,
Mark

Quoted 2 lines

Konstantin

#41 lore raw

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

Hi Mark,

Quoted 89 lines

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

Quoted 73 lines

From: Ananyev, Konstantin
Sent: Wednesday, September 13, 2017 10:38 AM
To: Hu, Jiayu <[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

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
lib/librte_gso/gso_tcp4.c new file +16 -0
+
+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;
+	uint16_t hdr_offset;
+	int ret = 1;
+
Quoted 8 lines
Quoted 8 lines

lib/librte_gso/gso_tcp4.c line 60

Quoted 5 lines
lib/librte_gso/gso_tcp4.c new file +5 -0
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->l2_len);
+	/* Don't process the fragmented packet */
+	if (unlikely((ipv4_hdr->fragment_offset & rte_cpu_to_be_16(
+						IPV4_HDR_DF_MASK)) == 0)) {

It is not a check for fragmented packet - it is a check that fragmentation

is allowed for that packet.

Quoted 1 line
Quoted 1 line

Should be IPV4_HDR_DF_MASK - 1, I think.

DF bit doesn't indicate is packet fragmented or not.
It forbids to fragment packet any further.
To check is packet already fragmented or not, you have to check MF bit and frag_offset.
Both have to be zero for un-fragmented packets.

Quoted 4 lines

IMO, IPV4_HDR_DF_MASK whose value is (1 << 14) is used to get DF bit. It's a little-endian value. But ipv4_hdr->fragment_offset is big-endian order. So the value of DF bit should be "ipv4_hdr->fragment_offset &

rte_cpu_to_be_16(

Quoted 26 lines

IPV4_HDR_DF_MASK)". If this value is 0, the input packet is fragmented.

Quoted 9 lines

lib/librte_gso/gso_tcp4.c line 66

Quoted 7 lines
lib/librte_gso/gso_tcp4.c new file +6 -0
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len -
+		pkt->l4_len;

Why not use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len?

Yes, we can use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len here.

Quoted 11 lines

lib/librte_gso/gso_tcp4.c line 74

Quoted 9 lines
lib/librte_gso/gso_tcp4.c new file +8 -0
+	/* Don't process the packet without data */
+	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 - ETHER_CRC_LEN;

Hmm, why do we need to count CRC_LEN here?

Quoted 8 lines
Quoted 2 lines

Yes, we shouldn't count ETHER_CRC_LEN here. Its length should be included in gso_size.

Why?
What is the point to account crc len into this computation? Why not just assume that gso_size is already a max_frame_size - crc_len As I remember, when we RX packet crc bytes will be already stripped, when user populates the packet, he doesn't care about crc bytes too.

Quoted 5 lines

Hi Konstantin,

When packet is tx'd, the 4B for CRC are added back into the packet; if the payload is already at max capacity, then the actual segment size will be 4B larger than expected (e.g. 1522B, as opposed to 1518B).
To prevent that from happening, we account for the CRC len in this calculation.

Ok, and what prevents you to set gso_ctx.gso_size = 1514; /*ether frame size without crc bytes */ ?
Konstantin

Quoted 8 lines

If I've missed anything, please do let me know!

Thanks,
Mark

Quoted 2 lines

Konstantin

author
#42 lore raw

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

Hi Konstantin,

Quoted 111 lines

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

Hi Mark,

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Wednesday, September 13, 2017 3:52 PM
To: Ananyev, Konstantin <[email protected]>; Hu, Jiayu

<[email protected]>

Quoted 7 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 4 lines

From: Ananyev, Konstantin
Sent: Wednesday, September 13, 2017 10:38 AM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan, Jianfeng

Quoted 14 lines
Quoted 14 lines

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

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
lib/librte_gso/gso_tcp4.c new file +9 -0
+
+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)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

lib/librte_gso/gso_tcp4.c

Quoted 8 lines
lib/librte_gso/gso_tcp4.c new file +8 -0
+{
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size;
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *)

+

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

lib/librte_gso/gso_tcp4.c line 64

Quoted 4 lines
lib/librte_gso/gso_tcp4.c new file +4 -0
+			pkt->l2_len);
+	/* Don't process the fragmented packet */
+	if (unlikely((ipv4_hdr->fragment_offset & rte_cpu_to_be_16(
+
	IPV4_HDR_DF_MASK)) == 0)) {
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

It is not a check for fragmented packet - it is a check that

fragmentation

Quoted 6 lines
Quoted 6 lines

is allowed for that packet.

Quoted 1 line
Quoted 1 line

Should be IPV4_HDR_DF_MASK - 1, I think.

DF bit doesn't indicate is packet fragmented or not.
It forbids to fragment packet any further.
To check is packet already fragmented or not, you have to check MF bit

and

Quoted 5 lines
Quoted 5 lines

frag_offset.
Both have to be zero for un-fragmented packets.

Quoted 2 lines

IMO, IPV4_HDR_DF_MASK whose value is (1 << 14) is used to get DF bit.

It's a

Quoted 39 lines
Quoted 11 lines
Quoted 2 lines

little-endian value. But ipv4_hdr->fragment_offset is big-endian order. So the value of DF bit should be "ipv4_hdr->fragment_offset &

rte_cpu_to_be_16(

Quoted 8 lines

IPV4_HDR_DF_MASK)". If this value is 0, the input packet is fragmented.

Quoted 6 lines

lib/librte_gso/gso_tcp4.c

Quoted 6 lines
lib/librte_gso/gso_tcp4.c new file +5 -0
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt-

l3_len -

Quoted 18 lines
Quoted 18 lines
Quoted 3 lines

lib/librte_gso/gso_tcp4.c line 66

Quoted 1 line
lib/librte_gso/gso_tcp4.c new file +1 -0
+		pkt->l4_len;

Why not use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len?

Yes, we can use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len here.

Quoted 11 lines

lib/librte_gso/gso_tcp4.c line 74

Quoted 9 lines
lib/librte_gso/gso_tcp4.c new file +8 -0
+	/* Don't process the packet without data */
+	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 - ETHER_CRC_LEN;

Hmm, why do we need to count CRC_LEN here?

Quoted 8 lines
Quoted 2 lines

Yes, we shouldn't count ETHER_CRC_LEN here. Its length should be included in gso_size.

Why?
What is the point to account crc len into this computation? Why not just assume that gso_size is already a max_frame_size - crc_len As I remember, when we RX packet crc bytes will be already stripped, when user populates the packet, he doesn't care about crc bytes too.

Quoted 3 lines

Hi Konstantin,

When packet is tx'd, the 4B for CRC are added back into the packet; if the

payload is already at max capacity, then the actual segment size

Quoted 8 lines
Quoted 2 lines

will be 4B larger than expected (e.g. 1522B, as opposed to 1518B). To prevent that from happening, we account for the CRC len in this

calculation.

Ok, and what prevents you to set gso_ctx.gso_size = 1514; /*ether frame size without crc bytes */
?

Exactly, applications can set 1514 to gso_segsz instead of 1518, if the lower layer will add CRC to the packet.

Jiayu

Quoted 10 lines

Konstantin

Quoted 8 lines

If I've missed anything, please do let me know!

Thanks,
Mark

Quoted 2 lines

Konstantin

#43 lore raw

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

Quoted 89 lines

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

Hi Konstantin,

Quoted 80 lines

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

Hi Mark,

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Wednesday, September 13, 2017 3:52 PM
To: Ananyev, Konstantin <[email protected]>; Hu, Jiayu

<[email protected]>

Quoted 7 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 4 lines

From: Ananyev, Konstantin
Sent: Wednesday, September 13, 2017 10:38 AM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan, Jianfeng

Quoted 14 lines
Quoted 14 lines

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

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
(quoted diff) +9 -0
+
+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)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+{
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size;
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *)

+

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+			pkt->l2_len);
+	/* Don't process the fragmented packet */
+	if (unlikely((ipv4_hdr->fragment_offset & rte_cpu_to_be_16(
+
	IPV4_HDR_DF_MASK)) == 0)) {
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

It is not a check for fragmented packet - it is a check that

fragmentation

Quoted 6 lines
Quoted 6 lines

is allowed for that packet.

Quoted 1 line
Quoted 1 line

Should be IPV4_HDR_DF_MASK - 1, I think.

DF bit doesn't indicate is packet fragmented or not.
It forbids to fragment packet any further.
To check is packet already fragmented or not, you have to check MF bit

and

Quoted 5 lines
Quoted 5 lines

frag_offset.
Both have to be zero for un-fragmented packets.

Quoted 2 lines

IMO, IPV4_HDR_DF_MASK whose value is (1 << 14) is used to get DF bit.

It's a

Quoted 12 lines
Quoted 11 lines
Quoted 2 lines

little-endian value. But ipv4_hdr->fragment_offset is big-endian order. So the value of DF bit should be "ipv4_hdr->fragment_offset &

rte_cpu_to_be_16(

Quoted 8 lines

IPV4_HDR_DF_MASK)". If this value is 0, the input packet is fragmented.

Quoted 6 lines

Review

Quoted 6 lines
(quoted diff) +5 -0
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt-

l3_len -

Quoted 40 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		pkt->l4_len;

Why not use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len?

Yes, we can use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len

here.

Quoted 34 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

Review

Quoted 10 lines
(quoted diff) +8 -0
+	/* Don't process the packet without data */
+	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 - ETHER_CRC_LEN;

Hmm, why do we need to count CRC_LEN here?

Quoted 8 lines
Quoted 2 lines

Yes, we shouldn't count ETHER_CRC_LEN here. Its length should be included in gso_size.

Why?
What is the point to account crc len into this computation? Why not just assume that gso_size is already a max_frame_size - crc_len As I remember, when we RX packet crc bytes will be already stripped, when user populates the packet, he doesn't care about crc bytes too.

Quoted 3 lines

Hi Konstantin,

When packet is tx'd, the 4B for CRC are added back into the packet; if the

payload is already at max capacity, then the actual segment size

Quoted 2 lines

will be 4B larger than expected (e.g. 1522B, as opposed to 1518B). To prevent that from happening, we account for the CRC len in this

calculation.

Ok, and what prevents you to set gso_ctx.gso_size = 1514; /*ether frame size without crc bytes */
?

Hey Konstantin,

If the user sets the gso_size to 1514, the resultant output segments' size should be 1514, and not 1518. Consequently, the payload capacity of each segment would be reduced accordingly.
The user only cares about the output segment size (i.e. gso_ctx.gso_size); we need to ensure that the size of the segments that are produced is consistent with that. As a result, we need to ensure that any packet overhead is accounted for in the segment size, before we can determine how much space remains for data.

Hope this makes sense.

Thanks,
Mark

Quoted 17 lines

Exactly, applications can set 1514 to gso_segsz instead of 1518, if the lower layer
will add CRC to the packet.

Jiayu

Quoted 10 lines

Konstantin

Quoted 8 lines

If I've missed anything, please do let me know!

Thanks,
Mark

Quoted 2 lines

Konstantin

#44 lore raw

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

Quoted 135 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, September 14, 2017 9:35 AM
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 126 lines

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

Hi Konstantin,

Quoted 61 lines

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

Hi Mark,

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Wednesday, September 13, 2017 3:52 PM
To: Ananyev, Konstantin <[email protected]>; Hu, Jiayu

<[email protected]>

Quoted 7 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 4 lines

From: Ananyev, Konstantin
Sent: Wednesday, September 13, 2017 10:38 AM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan, Jianfeng

Quoted 14 lines
Quoted 14 lines

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

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
(quoted diff) +9 -0
+
+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)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+{
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size;
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *)

+

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+			pkt->l2_len);
+	/* Don't process the fragmented packet */
+	if (unlikely((ipv4_hdr->fragment_offset & rte_cpu_to_be_16(
+
	IPV4_HDR_DF_MASK)) == 0)) {
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

It is not a check for fragmented packet - it is a check that

fragmentation

Quoted 6 lines
Quoted 6 lines

is allowed for that packet.

Quoted 1 line
Quoted 1 line

Should be IPV4_HDR_DF_MASK - 1, I think.

DF bit doesn't indicate is packet fragmented or not.
It forbids to fragment packet any further.
To check is packet already fragmented or not, you have to check MF bit

Quoted 24 lines

and

Quoted 5 lines
Quoted 5 lines

frag_offset.
Both have to be zero for un-fragmented packets.

Quoted 2 lines

IMO, IPV4_HDR_DF_MASK whose value is (1 << 14) is used to get DF bit.

It's a

Quoted 17 lines
Quoted 11 lines
Quoted 2 lines

little-endian value. But ipv4_hdr->fragment_offset is big-endian order. So the value of DF bit should be "ipv4_hdr->fragment_offset &

rte_cpu_to_be_16(

Quoted 8 lines

IPV4_HDR_DF_MASK)". If this value is 0, the input packet is fragmented.

Quoted 6 lines

Review

Quoted 6 lines
(quoted diff) +5 -0
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt-

l3_len -

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		pkt->l4_len;

Why not use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len?

Yes, we can use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len

here.

Quoted 31 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

Review

Quoted 10 lines
(quoted diff) +8 -0
+	/* Don't process the packet without data */
+	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 - ETHER_CRC_LEN;

Hmm, why do we need to count CRC_LEN here?

Quoted 8 lines
Quoted 2 lines

Yes, we shouldn't count ETHER_CRC_LEN here. Its length should be included in gso_size.

Why?
What is the point to account crc len into this computation? Why not just assume that gso_size is already a max_frame_size - crc_len As I remember, when we RX packet crc bytes will be already stripped, when user populates the packet, he doesn't care about crc bytes too.

Quoted 3 lines

Hi Konstantin,

When packet is tx'd, the 4B for CRC are added back into the packet; if the

payload is already at max capacity, then the actual segment size

Quoted 2 lines

will be 4B larger than expected (e.g. 1522B, as opposed to 1518B). To prevent that from happening, we account for the CRC len in this

calculation.

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

Ok, and what prevents you to set gso_ctx.gso_size = 1514; /*ether frame size without crc bytes */
?

Hey Konstantin,

If the user sets the gso_size to 1514, the resultant output segments' size should be 1514, and not 1518.

Yes and then NIC HW will add CRC bytes for you.
You are not filling CRC bytes in HW, and when providing to the HW size to send - it is a payload size (CRC bytes are not accounted).
Konstantin

Consequently, the payload capacity

Quoted 27 lines

of each segment would be reduced accordingly.
The user only cares about the output segment size (i.e. gso_ctx.gso_size); we need to ensure that the size of the segments that are produced is consistent with that. As a result, we need to ensure that any packet overhead is accounted for in the segment size, before we can determine how much space remains for data.

Hope this makes sense.

Thanks,
Mark

Quoted 17 lines

Exactly, applications can set 1514 to gso_segsz instead of 1518, if the lower layer
will add CRC to the packet.

Jiayu

Quoted 10 lines

Konstantin

Quoted 8 lines

If I've missed anything, please do let me know!

Thanks,
Mark

Quoted 2 lines

Konstantin

#45 lore raw

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

Quoted 148 lines

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

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, September 14, 2017 9:35 AM
To: Hu, Jiayu <[email protected]>; Ananyev, Konstantin

<[email protected]>

Quoted 79 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 76 lines

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

Hi Konstantin,

Quoted 67 lines

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

Hi Mark,

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Wednesday, September 13, 2017 3:52 PM
To: Ananyev, Konstantin <[email protected]>; Hu, Jiayu

<[email protected]>

Quoted 7 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 4 lines

From: Ananyev, Konstantin
Sent: Wednesday, September 13, 2017 10:38 AM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan, Jianfeng

Quoted 14 lines
Quoted 14 lines

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

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
(quoted diff) +9 -0
+
+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)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+{
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size;
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *)

+

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+			pkt->l2_len);
+	/* Don't process the fragmented packet */
+	if (unlikely((ipv4_hdr->fragment_offset & rte_cpu_to_be_16(
+
	IPV4_HDR_DF_MASK)) == 0)) {
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

It is not a check for fragmented packet - it is a check that

fragmentation

Quoted 6 lines
Quoted 6 lines

is allowed for that packet.

Quoted 1 line
Quoted 1 line

Should be IPV4_HDR_DF_MASK - 1, I think.

DF bit doesn't indicate is packet fragmented or not.
It forbids to fragment packet any further.
To check is packet already fragmented or not, you have to check MF bit

and

Quoted 5 lines
Quoted 5 lines

frag_offset.
Both have to be zero for un-fragmented packets.

Quoted 2 lines

IMO, IPV4_HDR_DF_MASK whose value is (1 << 14) is used to get DF

bit.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

It's a

Quoted 1 line
Quoted 1 line
Quoted 1 line

little-endian value. But ipv4_hdr->fragment_offset is big-endian

order.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

So the value of DF bit should be "ipv4_hdr->fragment_offset &

rte_cpu_to_be_16(

Quoted 1 line

IPV4_HDR_DF_MASK)". If this value is 0, the input packet is

fragmented.

Quoted 27 lines
Quoted 27 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Review

Quoted 7 lines
(quoted diff) +5 -0
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt-

l3_len -

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		pkt->l4_len;

Why not use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len?

Yes, we can use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len

here.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

Review

Quoted 10 lines
(quoted diff) +8 -0
+	/* Don't process the packet without data */
+	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 - ETHER_CRC_LEN;

Hmm, why do we need to count CRC_LEN here?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Yes, we shouldn't count ETHER_CRC_LEN here. Its length should be included in gso_size.

Why?
What is the point to account crc len into this computation? Why not just assume that gso_size is already a max_frame_size -

crc_len

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

As I remember, when we RX packet crc bytes will be already stripped, when user populates the packet, he doesn't care about crc bytes too.

Hi Konstantin,

When packet is tx'd, the 4B for CRC are added back into the packet; if

the

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

payload is already at max capacity, then the actual segment size

Quoted 2 lines

will be 4B larger than expected (e.g. 1522B, as opposed to 1518B). To prevent that from happening, we account for the CRC len in this

calculation.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

Ok, and what prevents you to set gso_ctx.gso_size = 1514; /*ether frame size without crc bytes */
?

Hey Konstantin,

If the user sets the gso_size to 1514, the resultant output segments' size

should be 1514, and not 1518.

Just to clarify - I meant here that the final output segment, including CRC len, should be 1514. I think this is where we're crossing wires ;)

Quoted 6 lines

Yes and then NIC HW will add CRC bytes for you.
You are not filling CRC bytes in HW, and when providing to the HW size to send
- it is a payload size
(CRC bytes are not accounted).
Konstantin

Yes, exactly - in that case though, the gso_size specified by the user is not the actual final output segment size, but (segment size - 4B), right?

We can set that expectation in documentation, but from an application's/user's perspective, do you think that this might be confusing/misleading?

Thanks again,
Mark

Quoted 32 lines

Consequently, the payload capacity

Quoted 2 lines

of each segment would be reduced accordingly.
The user only cares about the output segment size (i.e. gso_ctx.gso_size);

we need to ensure that the size of the segments that are

Quoted 1 line

produced is consistent with that. As a result, we need to ensure that any

packet overhead is accounted for in the segment size, before we

Quoted 9 lines

can determine how much space remains for data.

Hope this makes sense.

Thanks,
Mark

Quoted 2 lines

Exactly, applications can set 1514 to gso_segsz instead of 1518, if the

lower

Quoted 15 lines
Quoted 15 lines

layer
will add CRC to the packet.

Jiayu

Quoted 10 lines

Konstantin

Quoted 8 lines

If I've missed anything, please do let me know!

Thanks,
Mark

Quoted 2 lines

Konstantin

#46 lore raw

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

Quoted 169 lines

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

Quoted 148 lines

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

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, September 14, 2017 9:35 AM
To: Hu, Jiayu <[email protected]>; Ananyev, Konstantin

<[email protected]>

Quoted 79 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 76 lines

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

Hi Konstantin,

Quoted 67 lines

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

Hi Mark,

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Wednesday, September 13, 2017 3:52 PM
To: Ananyev, Konstantin <[email protected]>; Hu, Jiayu

<[email protected]>

Quoted 7 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 4 lines

From: Ananyev, Konstantin
Sent: Wednesday, September 13, 2017 10:38 AM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan, Jianfeng

Quoted 14 lines
Quoted 14 lines

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

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
(quoted diff) +9 -0
+
+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)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+{
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size;
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *)

+

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+			pkt->l2_len);
+	/* Don't process the fragmented packet */
+	if (unlikely((ipv4_hdr->fragment_offset & rte_cpu_to_be_16(
+
	IPV4_HDR_DF_MASK)) == 0)) {
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

It is not a check for fragmented packet - it is a check that

fragmentation

Quoted 6 lines
Quoted 6 lines

is allowed for that packet.

Quoted 1 line
Quoted 1 line

Should be IPV4_HDR_DF_MASK - 1, I think.

DF bit doesn't indicate is packet fragmented or not.
It forbids to fragment packet any further.
To check is packet already fragmented or not, you have to check MF bit

and

Quoted 5 lines
Quoted 5 lines

frag_offset.
Both have to be zero for un-fragmented packets.

Quoted 2 lines

IMO, IPV4_HDR_DF_MASK whose value is (1 << 14) is used to get DF

bit.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

It's a

Quoted 1 line
Quoted 1 line
Quoted 1 line

little-endian value. But ipv4_hdr->fragment_offset is big-endian

order.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

So the value of DF bit should be "ipv4_hdr->fragment_offset &

rte_cpu_to_be_16(

Quoted 1 line

IPV4_HDR_DF_MASK)". If this value is 0, the input packet is

fragmented.

Quoted 27 lines
Quoted 27 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Review

Quoted 7 lines
(quoted diff) +5 -0
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt-

l3_len -

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		pkt->l4_len;

Why not use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len?

Yes, we can use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len

here.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

Review

Quoted 10 lines
(quoted diff) +8 -0
+	/* Don't process the packet without data */
+	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 - ETHER_CRC_LEN;

Hmm, why do we need to count CRC_LEN here?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Yes, we shouldn't count ETHER_CRC_LEN here. Its length should be included in gso_size.

Why?
What is the point to account crc len into this computation? Why not just assume that gso_size is already a max_frame_size -

crc_len

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

As I remember, when we RX packet crc bytes will be already stripped, when user populates the packet, he doesn't care about crc bytes too.

Hi Konstantin,

When packet is tx'd, the 4B for CRC are added back into the packet; if

the

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

payload is already at max capacity, then the actual segment size

Quoted 2 lines

will be 4B larger than expected (e.g. 1522B, as opposed to 1518B). To prevent that from happening, we account for the CRC len in this

calculation.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

Ok, and what prevents you to set gso_ctx.gso_size = 1514; /*ether frame size without crc bytes */
?

Hey Konstantin,

If the user sets the gso_size to 1514, the resultant output segments' size

should be 1514, and not 1518.

Just to clarify - I meant here that the final output segment, including CRC len, should be 1514. I think this is where we're crossing wires ;)

Quoted 1 line
Quoted 8 lines
Quoted 5 lines

Yes and then NIC HW will add CRC bytes for you.
You are not filling CRC bytes in HW, and when providing to the HW size to send
- it is a payload size
(CRC bytes are not accounted).
Konstantin

Yes, exactly - in that case though, the gso_size specified by the user is not the actual final output segment size, but (segment size - 4B), right?

CRC bytes will be add by HW, it is totally transparent for user.

Quoted 3 lines

We can set that expectation in documentation, but from an application's/user's perspective, do you think that this might be confusing/misleading?

I think it would be much more confusing to make user account for CRC bytes. Let say when in DPDK you form a packet and send it out via rte_eth_tx_burst() you specify only your payload size, not payload size plus crc bytes that HW will add for you. Konstantin

Quoted 36 lines

Thanks again,
Mark

Quoted 32 lines

Consequently, the payload capacity

Quoted 2 lines

of each segment would be reduced accordingly.
The user only cares about the output segment size (i.e. gso_ctx.gso_size);

we need to ensure that the size of the segments that are

Quoted 1 line

produced is consistent with that. As a result, we need to ensure that any

packet overhead is accounted for in the segment size, before we

Quoted 9 lines

can determine how much space remains for data.

Hope this makes sense.

Thanks,
Mark

Quoted 2 lines

Exactly, applications can set 1514 to gso_segsz instead of 1518, if the

lower

Quoted 15 lines
Quoted 15 lines

layer
will add CRC to the packet.

Jiayu

Quoted 10 lines

Konstantin

Quoted 8 lines

If I've missed anything, please do let me know!

Thanks,
Mark

Quoted 2 lines

Konstantin

#47 lore raw

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

Quoted 195 lines

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

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, September 14, 2017 10:01 AM
To: Ananyev, Konstantin <[email protected]>; Hu, Jiayu

<[email protected]>

Quoted 66 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 63 lines

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

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, September 14, 2017 9:35 AM
To: Hu, Jiayu <[email protected]>; Ananyev, Konstantin

<[email protected]>

Quoted 49 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 46 lines

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

Hi Konstantin,

Quoted 37 lines

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

Hi Mark,

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Wednesday, September 13, 2017 3:52 PM
To: Ananyev, Konstantin <[email protected]>; Hu, Jiayu

<[email protected]>

Quoted 7 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 4 lines

From: Ananyev, Konstantin
Sent: Wednesday, September 13, 2017 10:38 AM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan, Jianfeng

Quoted 14 lines
Quoted 14 lines

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

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
(quoted diff) +9 -0
+
+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)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+{
+	struct ipv4_hdr *ipv4_hdr;
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size;
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt,

char *)

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

+

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

Review

Quoted 3 lines
(quoted diff) +3 -0
+			pkt->l2_len);
+	/* Don't process the fragmented packet */
+	if (unlikely((ipv4_hdr->fragment_offset &

rte_cpu_to_be_16(

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

+

	IPV4_HDR_DF_MASK)) == 0)) {
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

It is not a check for fragmented packet - it is a check that

fragmentation

Quoted 6 lines
Quoted 6 lines

is allowed for that packet.

Quoted 1 line
Quoted 1 line

Should be IPV4_HDR_DF_MASK - 1, I think.

DF bit doesn't indicate is packet fragmented or not.
It forbids to fragment packet any further.
To check is packet already fragmented or not, you have to check MF

bit

Quoted 22 lines
Quoted 22 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

and

Quoted 5 lines
Quoted 5 lines

frag_offset.
Both have to be zero for un-fragmented packets.

Quoted 2 lines

IMO, IPV4_HDR_DF_MASK whose value is (1 << 14) is used to get DF

bit.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

It's a

Quoted 1 line
Quoted 1 line
Quoted 1 line

little-endian value. But ipv4_hdr->fragment_offset is big-endian

order.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

So the value of DF bit should be "ipv4_hdr->fragment_offset &

rte_cpu_to_be_16(

Quoted 1 line

IPV4_HDR_DF_MASK)". If this value is 0, the input packet is

fragmented.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Review

Quoted 7 lines
(quoted diff) +5 -0
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt-

l3_len -

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

Review

Quoted 1 line
(quoted diff) +1 -0
+		pkt->l4_len;

Why not use pkt->pkt_len - pkt->l2_len -pkt_l3_len -

pkt_l4_len?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Yes, we can use pkt->pkt_len - pkt->l2_len -pkt_l3_len -

pkt_l4_len

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines

here.

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

Review

Quoted 10 lines
(quoted diff) +8 -0
+	/* Don't process the packet without data */
+	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 - ETHER_CRC_LEN;

Hmm, why do we need to count CRC_LEN here?

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

Yes, we shouldn't count ETHER_CRC_LEN here. Its length should be included in gso_size.

Why?
What is the point to account crc len into this computation? Why not just assume that gso_size is already a max_frame_size -

crc_len

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

As I remember, when we RX packet crc bytes will be already

stripped,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

when user populates the packet, he doesn't care about crc bytes

too.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Hi Konstantin,

When packet is tx'd, the 4B for CRC are added back into the packet;

if

Quoted 8 lines
Quoted 8 lines

the

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

payload is already at max capacity, then the actual segment size

Quoted 2 lines

will be 4B larger than expected (e.g. 1522B, as opposed to 1518B). To prevent that from happening, we account for the CRC len in this

calculation.

Ok, and what prevents you to set gso_ctx.gso_size = 1514; /*ether

frame

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

size without crc bytes */
?

Hey Konstantin,

If the user sets the gso_size to 1514, the resultant output segments'

size

Quoted 3 lines
Quoted 1 line

should be 1514, and not 1518.

Just to clarify - I meant here that the final output segment, including CRC

len, should be 1514. I think this is where we're crossing wires ;)

Quoted 4 lines
Quoted 4 lines

Yes and then NIC HW will add CRC bytes for you.
You are not filling CRC bytes in HW, and when providing to the HW size to

send

Quoted 4 lines
Quoted 3 lines

- it is a payload size
(CRC bytes are not accounted).
Konstantin

Quoted 5 lines
Quoted 1 line

Yes, exactly - in that case though, the gso_size specified by the user is

not the actual final output segment size, but (segment size - 4B),

Quoted 1 line

right?

CRC bytes will be add by HW, it is totally transparent for user.

Yes - I completely agree/understand.

Quoted 11 lines
Quoted 3 lines

We can set that expectation in documentation, but from an

application's/user's perspective, do you think that this might be

Quoted 1 line

confusing/misleading?

I think it would be much more confusing to make user account for CRC bytes. Let say when in DPDK you form a packet and send it out via rte_eth_tx_burst() you specify only your payload size, not payload size plus crc bytes that HW will add for you.
Konstantin

I guess I've just been looking at it from a different perspective (i.e. the user wants to decide the final total packet size); using the example of rte_eth_tx_burst above, I see where you're coming from though. Thanks for clarifying,
Mark

Quoted 38 lines
Quoted 9 lines

Thanks again,
Mark

Quoted 4 lines

Consequently, the payload capacity

Quoted 2 lines

of each segment would be reduced accordingly. The user only cares about the output segment size (i.e.

gso_ctx.gso_size);

Quoted 28 lines
Quoted 28 lines

we need to ensure that the size of the segments that are

Quoted 1 line

produced is consistent with that. As a result, we need to ensure that any

packet overhead is accounted for in the segment size, before we

Quoted 9 lines

can determine how much space remains for data.

Hope this makes sense.

Thanks,
Mark

Quoted 2 lines

Exactly, applications can set 1514 to gso_segsz instead of 1518, if the

lower

Quoted 15 lines
Quoted 15 lines

layer
will add CRC to the packet.

Jiayu

Quoted 10 lines

Konstantin

Quoted 8 lines

If I've missed anything, please do let me know!

Thanks,
Mark

Quoted 2 lines

Konstantin

#48 lore raw

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

In reply to Jiayu Hu
Quoted 641 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]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Hi Jayu,

Quoted 8 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Tuesday, September 12, 2017 3:43 AM
To: [email protected]
Cc: Ananyev, Konstantin <[email protected]>; Kavanagh, Mark B <[email protected]>; Tan, Jianfeng <[email protected]>; Hu, Jiayu <[email protected]>
Subject: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 4 lines

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

Probably it shouldn't say that checksum have to be valid, right? As you don't update checksum(s) inside the lib - it probably doesn't matter.

Quoted 219 lines

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.

---
 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             | 113 ++++++++++++++++++
 lib/librte_gso/gso_tcp4.c               |  83 +++++++++++++
 lib/librte_gso/gso_tcp4.h               |  76 ++++++++++++
 lib/librte_gso/rte_gso.c                |  41 ++++++-
 7 files changed, 515 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
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 +159 -0
new file mode 100644
index 0000000..7c32e03
@@ -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.
+ */
+
+#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;
+
+			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_inner_tcp4_header(struct rte_mbuf *pkt, uint8_t ipid_delta,

lib/librte_gso/gso_common.c line 169

Quoted 10 lines
lib/librte_gso/gso_common.c new file +10 -0
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	struct tcp_hdr *tcp_hdr;
+	struct ipv4_hdr *ipv4_hdr;
+	struct rte_mbuf *seg;
+	uint32_t sent_seq;
+	uint16_t inner_l2_offset;
+	uint16_t id, i;
+
+	inner_l2_offset = pkt->outer_l2_len + pkt->outer_l3_len + pkt->l2_len;

Shouldn't it be: pkt->l2_len here?
Or probably even better to pass l2_len as an input parameter.

Quoted 69 lines
lib/librte_gso/gso_common.c new file +33 -0
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			inner_l2_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);
+
+	for (i = 0; i < nb_segs; i++) {
+		seg = segs[i];
+		/* Update the inner IPv4 header */
+		ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(seg, char *) +
+				inner_l2_offset);
+		ipv4_hdr->total_length = rte_cpu_to_be_16(seg->pkt_len -
+				inner_l2_offset);
+		ipv4_hdr->packet_id = rte_cpu_to_be_16(id);
+		id += ipid_delta;
+
+		/* Update the inner TCP header */
+		tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + seg->l3_len);
+		tcp_hdr->sent_seq = rte_cpu_to_be_32(sent_seq);
+		if (likely(i < nb_segs - 1))
+			tcp_hdr->tcp_flags &= (~(TCP_HDR_PSH_MASK |
+						TCP_HDR_FIN_MASK));
+		sent_seq += (seg->pkt_len - seg->data_len);
+	}
+}
+
+void
+gso_update_pkt_headers(struct rte_mbuf *pkt, uint8_t ipid_delta,
+		struct rte_mbuf **segs, uint16_t nb_segs)
+{
+	if (is_ipv4_tcp(pkt->packet_type))
+		update_inner_tcp4_header(pkt, ipid_delta, segs, nb_segs);
+}
lib/librte_gso/gso_common.h new file +30 -0
new file mode 100644
index 0000000..3c76520
@@ -0,0 +1,113 @@
+/*-
+ *   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

lib/librte_gso/gso_common.h line 40

Quoted 10 lines
lib/librte_gso/gso_common.h new file +10 -0
+ *   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>
+
+#define IPV4_HDR_DF_SHIFT 14

We have that already defined in librte_net/rte_ip.h

lib/librte_gso/gso_common.h line 52

Quoted 12 lines
lib/librte_gso/gso_common.h new file +12 -0
+#define IPV4_HDR_DF_MASK (1 << IPV4_HDR_DF_SHIFT)
+
+#define TCP_HDR_PSH_MASK ((uint8_t)0x08)
+#define TCP_HDR_FIN_MASK ((uint8_t)0x01)
+
+#define ETHER_TCP_PKT (RTE_PTYPE_L2_ETHER | RTE_PTYPE_L4_TCP)
+#define ETHER_VLAN_TCP_PKT (RTE_PTYPE_L2_ETHER_VLAN | RTE_PTYPE_L4_TCP)
+static inline uint8_t is_ipv4_tcp(uint32_t ptype)
+{
+	switch (ptype & (~RTE_PTYPE_L3_MASK)) {
+	case ETHER_VLAN_TCP_PKT:
+	case ETHER_TCP_PKT:

Why not just:
return RTE_ETH_IS_IPV4_HDR(ptype) && (ptype & RTE_PTYPE_L4_MASK) == RTE_PTYPE_L4_TCP; ?

Quoted 117 lines
lib/librte_gso/gso_common.h new file +61 -0
+		return RTE_ETH_IS_IPV4_HDR(ptype);
+	default:
+		return 0;
+	}
+}
+
+/**
+ * Internal function which updates relevant packet headers, 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 gso_update_pkt_headers(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.
+ */
+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 +50 -0
new file mode 100644
index 0000000..8d4bfb2
@@ -0,0 +1,83 @@
+/*-
+ *   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_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;

lib/librte_gso/gso_tcp4.c line 60

Quoted 10 lines
lib/librte_gso/gso_tcp4.c new file +10 -0
+	uint16_t tcp_dl;
+	uint16_t pyld_unit_size;
+	uint16_t hdr_offset;
+	int ret = 1;
+
+	ipv4_hdr = (struct ipv4_hdr *)(rte_pktmbuf_mtod(pkt, char *) +
+			pkt->l2_len);
+	/* Don't process the fragmented packet */
+	if (unlikely((ipv4_hdr->fragment_offset & rte_cpu_to_be_16(
+						IPV4_HDR_DF_MASK)) == 0)) {

It is not a check for fragmented packet - it is a check that fragmentation is allowed for that packet. Should be IPV4_HDR_DF_MASK - 1, I think.

lib/librte_gso/gso_tcp4.c line 66

Quoted 6 lines
lib/librte_gso/gso_tcp4.c new file +6 -0
+		pkts_out[0] = pkt;
+		return ret;
+	}
+
+	tcp_dl = rte_be_to_cpu_16(ipv4_hdr->total_length) - pkt->l3_len -
+		pkt->l4_len;

Why not use pkt->pkt_len - pkt->l2_len -pkt_l3_len - pkt_l4_len?

lib/librte_gso/gso_tcp4.c line 74

Quoted 8 lines
lib/librte_gso/gso_tcp4.c new file +8 -0
+	/* Don't process the packet without data */
+	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 - ETHER_CRC_LEN;

Hmm, why do we need to count CRC_LEN here?

Quoted 130 lines
lib/librte_gso/gso_tcp4.c new file +9 -0
+
+	/* 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)
+		gso_update_pkt_headers(pkt, ipid_delta, pkts_out, ret);
+
+	return ret;
+}
lib/librte_gso/gso_tcp4.h new file +76 -0
new file mode 100644
index 0000000..9c07984
@@ -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_TCP4_H_
+#define _GSO_TCP4_H_
+
+#include <stdint.h>
+#include <rte_mbuf.h>
+
+/**
+ * Segment an IPv4/TCP packet. This function assumes the input packet has
+ * correct checksums and doesn't update checksums for GSO segment.
+ * 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 +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

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) {...

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) {...

Konstantin

Quoted 23 lines

lib/librte_gso/rte_gso.c line 74

Quoted 6 lines
lib/librte_gso/rte_gso.c +5 -0
+		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else
+		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");

Shouldn't we do pkt_out[0] = pkt; here?

Quoted 14 lines
lib/librte_gso/rte_gso.c +9 -2
+
+	if (ret > 1) {
+		pkt_seg = pkt;
+		while (pkt_seg) {
+			rte_mbuf_refcnt_update(pkt_seg, -1);
+			pkt_seg = pkt_seg->next;
+		}
+	}
 
-	return 1;
+	return ret;
 }
--

2.7.4

author
#49 lore raw

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

Hi Konstantin,

Quoted 59 lines · Konstantin
Quoted 50 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]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 41 lines

result, when all of its GSOed segments are freed, the packet is freed 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

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 3 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?

Thanks,
Jiayu

Quoted 26 lines

Konstantin

Quoted 23 lines

lib/librte_gso/rte_gso.c line 74

Quoted 6 lines
lib/librte_gso/rte_gso.c +5 -0
+		ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
+				direct_pool, indirect_pool,
+				pkts_out, nb_pkts_out);
+	} else
+		RTE_LOG(WARNING, GSO, "Unsupported packet type\n");

Shouldn't we do pkt_out[0] = pkt; here?

Quoted 14 lines
lib/librte_gso/rte_gso.c +9 -2
+
+	if (ret > 1) {
+		pkt_seg = pkt;
+		while (pkt_seg) {
+			rte_mbuf_refcnt_update(pkt_seg, -1);
+			pkt_seg = pkt_seg->next;
+		}
+	}
 
-	return 1;
+	return ret;
 }
--

2.7.4

#50 lore raw

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

Hi Jiayu,

Quoted 63 lines
Quoted 59 lines
Quoted 50 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]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 41 lines

result, when all of its GSOed segments are freed, the packet is freed 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

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 3 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) {...
Quoted 5 lines

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?

Well, right now PMD we doesn't rely on ptype to figure out what type of packet and 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 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. The only advantage I see here is that if someone would like to add GSO for some new protocol, 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.

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

author
#51 lore raw

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

Hi Konstantin,

Quoted 80 lines · Konstantin

Hi Jiayu,

Quoted 63 lines
Quoted 59 lines
Quoted 50 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]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 41 lines

result, when all of its GSOed segments are freed, the packet is freed 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

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 3 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) {...
Quoted 5 lines

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?

Well, right now PMD we doesn't rely on ptype to figure out what type of packet and 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 specify what segmentation to perform on a per-packet basis.

Quoted 7 lines

Alternative way is to rely on ptype to distinguish should segmentation be performed on that package or not. The only advantage I see here is that if someone would like to add GSO for some new protocol, 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.

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.

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?

Jiayu

Quoted 1 line

Konstantin

#52 lore raw

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

Hi Jiayu,

Quoted 108 lines

-----Original Message-----
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 80 lines · Konstantin

Hi Jiayu,

Quoted 63 lines
Quoted 59 lines
Quoted 50 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]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 41 lines

result, when all of its GSOed segments are freed, the packet is freed 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

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 3 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) {...
Quoted 5 lines

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?

Well, right now PMD we doesn't rely on ptype to figure out what type of packet and 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 specify what segmentation to perform on a per-packet basis.

Quoted 7 lines

Alternative way is to rely on ptype to distinguish should segmentation be performed on that package or not. The only advantage I see here is that if someone would like to add GSO for some new protocol, 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.

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 4 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?

It think that for that case you'll have to set in ol_flags:

PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN | PKT_TX_TCP_SEG

Konstantin

Quoted 3 lines

Jiayu

Quoted 1 line

Konstantin

author
#53 lore raw

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

Hi Konstantin,

Quoted 142 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 4:47 PM
To: Hu, Jiayu <[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 Jiayu,

Quoted 5 lines

-----Original Message-----
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]>

Quoted 15 lines

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
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
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
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 3 lines
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 7 lines
Quoted 7 lines
Quoted 7 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?

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

here?

Quoted 2 lines
Quoted 2 lines

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

packet and

Quoted 3 lines
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 gso_ctx and still

Quoted 3 lines
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
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
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 6 lines
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

Quoted 1 line

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

each input packet.

Quoted 1 line

Applications should parse the packet type, and set an exactly correct

DEV_TX_OFFLOAD_*_TSO

Quoted 1 line

flag to gso_types and ol_flags according to the packet type. That is, the

value of gso_types

Quoted 1 line

is on a per-packet basis. Using gso_ctx->gso_types and mbuf->ol_flags at

the same time

Quoted 1 line

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

inner L4 type, and

Quoted 1 line

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

and SW segmentation

Quoted 3 lines

are indeed consistent.

If I understand it correctly, applications need to set 'ol_flags =

PKT_TX_IPV4' and

Quoted 1 line

'gso_types = DEV_TX_OFFLOAD_VXLAN_TNL_TSO' for a

"ether+ipv4+udp+vxlan+ether+ipv4+

Quoted 1 line

tcp+payload" packet. But PKT_TX_IPV4 just present the inner L3 type for

Quoted 8 lines

tunneled packet.

Quoted 1 line

How about the outer L3 type? Always assume the inner and the outer L3

type are the same?

It think that for that case you'll have to set in ol_flags:

PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN | PKT_TX_TCP_SEG

OK, so it means PKT_TX_TCP_SEG is also used for tunneled TSO. The GSO library doesn't need gso_types anymore.

The first choice makes HW and SW segmentation are totally the same. Applications just need to parse the packet and set proper ol_flags, and the GSO library uses ol_flags to decide which segmentation function to use. I think it's better than the second choice which depending on ptype to choose segmentation function.

Jiayu

Quoted 6 lines

Konstantin

Quoted 3 lines

Jiayu

Quoted 1 line

Konstantin

#54 lore raw

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

Quoted 157 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, September 14, 2017 10:29 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 146 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 4:47 PM
To: Hu, Jiayu <[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 Jiayu,

Quoted 5 lines

-----Original Message-----
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]>

Quoted 15 lines

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
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
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
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 3 lines
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 7 lines
Quoted 7 lines
Quoted 7 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?

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

here?

Quoted 2 lines
Quoted 2 lines

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

packet and

Quoted 3 lines
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 gso_ctx and still

Quoted 3 lines
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
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
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 6 lines
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

Quoted 1 line

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

each input packet.

Quoted 1 line

Applications should parse the packet type, and set an exactly correct

DEV_TX_OFFLOAD_*_TSO

Quoted 1 line

flag to gso_types and ol_flags according to the packet type. That is, the

value of gso_types

Quoted 1 line

is on a per-packet basis. Using gso_ctx->gso_types and mbuf->ol_flags at

the same time

Quoted 1 line

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

inner L4 type, and

Quoted 1 line

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

and SW segmentation

Quoted 3 lines

are indeed consistent.

If I understand it correctly, applications need to set 'ol_flags =

PKT_TX_IPV4' and

Quoted 1 line

'gso_types = DEV_TX_OFFLOAD_VXLAN_TNL_TSO' for a

"ether+ipv4+udp+vxlan+ether+ipv4+

Quoted 1 line

tcp+payload" packet. But PKT_TX_IPV4 just present the inner L3 type for

tunneled packet.

Quoted 1 line

How about the outer L3 type? Always assume the inner and the outer L3

type are the same?

Quoted 7 lines
Quoted 4 lines

It think that for that case you'll have to set in ol_flags:

PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN | PKT_TX_TCP_SEG

OK, so it means PKT_TX_TCP_SEG is also used for tunneled TSO. The GSO library doesn't need gso_types anymore.

You still might need gso_ctx.gso_types to let user limit what types of segmentation that particular gso_ctx supports.
An alternative would be to assume that each gso_ctx supports all currently implemented segmentations.
This is possible too, but probably not very convenient to the user. Konstantin

Quoted 14 lines

The first choice makes HW and SW segmentation are totally the same. Applications just need to parse the packet and set proper ol_flags, and the GSO library uses ol_flags to decide which segmentation function to use. I think it's better than the second choice which depending on ptype to choose segmentation function.

Jiayu

Quoted 6 lines

Konstantin

Quoted 3 lines

Jiayu

Quoted 1 line

Konstantin

author
#55 lore raw

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

Hi Konstantin and Mark,

Quoted 189 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 5:36 PM
To: Hu, Jiayu <[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

Quoted 5 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, September 14, 2017 10:29 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>; Tan,

Jianfeng <[email protected]>

Quoted 9 lines

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

Hi Konstantin,

Quoted 5 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 4:47 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan,

Quoted 10 lines
Quoted 10 lines

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

Hi Jiayu,

Quoted 5 lines

-----Original Message-----
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,

Quoted 11 lines
Quoted 11 lines

Jianfeng <[email protected]>

Quoted 10 lines

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

Hi Konstantin,

Quoted 5 lines · Konstantin

Hi Jiayu,

Quoted 2 lines
Quoted 2 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 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

Quoted 53 lines
Quoted 53 lines

<[email protected]>

Quoted 3 lines
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 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 48 lines
Quoted 35 lines

automatically.

lib/librte_gso/rte_gso.c +14 -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) {

lib/librte_gso/rte_gso.c line 69

Quoted 10 lines
lib/librte_gso/rte_gso.c +10 -0
+		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_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
Quoted 4 lines

DEV_TX_OFFLOAD_TCP_TSO) != 0) {...

Quoted 3 lines
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 4 lines
Quoted 4 lines

&&

Quoted 3 lines
Quoted 3 lines
Quoted 3 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

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

flag is set or not. Applications can query device TSO capability

before

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

they call the GSO library. Do I misundertsand anything?

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

packet

Quoted 3 lines
Quoted 3 lines

here?

Quoted 2 lines
Quoted 2 lines

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

of

Quoted 4 lines
Quoted 4 lines

packet and

Quoted 3 lines
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

Quoted 7 lines
Quoted 7 lines

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 gso_ctx and still

Quoted 3 lines
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

Quoted 2 lines
Quoted 2 lines

performed on that package or not.

Quoted 1 line
Quoted 1 line

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

GSO

Quoted 6 lines
Quoted 6 lines

for some new protocol,

Quoted 2 lines
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 2 lines
Quoted 2 lines

So from my perspective first variant (use HW TSO API) is more

plausible.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

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

Quoted 8 lines
Quoted 8 lines

specific GSO

Quoted 1 line

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

each input packet.

Quoted 1 line

Applications should parse the packet type, and set an exactly correct

DEV_TX_OFFLOAD_*_TSO

Quoted 1 line

flag to gso_types and ol_flags according to the packet type. That is, the

value of gso_types

Quoted 1 line

is on a per-packet basis. Using gso_ctx->gso_types and mbuf->ol_flags

at

Quoted 2 lines
Quoted 2 lines

the same time

Quoted 1 line

is because that DEV_TX_OFFLOAD_*_TSO only tells tunnelling type and

the

Quoted 2 lines
Quoted 2 lines

inner L4 type, and

Quoted 1 line

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

segmentation

Quoted 12 lines
Quoted 12 lines

and SW segmentation

Quoted 3 lines

are indeed consistent.

If I understand it correctly, applications need to set 'ol_flags =

PKT_TX_IPV4' and

Quoted 1 line

'gso_types = DEV_TX_OFFLOAD_VXLAN_TNL_TSO' for a

"ether+ipv4+udp+vxlan+ether+ipv4+

Quoted 1 line

tcp+payload" packet. But PKT_TX_IPV4 just present the inner L3 type for

tunneled packet.

Quoted 1 line

How about the outer L3 type? Always assume the inner and the outer L3

type are the same?

Quoted 7 lines
Quoted 4 lines

It think that for that case you'll have to set in ol_flags:

PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN | PKT_TX_TCP_SEG

OK, so it means PKT_TX_TCP_SEG is also used for tunneled TSO. The GSO library doesn't need gso_types anymore.

Quoted 6 lines

You still might need gso_ctx.gso_types to let user limit what types of segmentation
that particular gso_ctx supports.
An alternative would be to assume that each gso_ctx supports all currently implemented segmentations.
This is possible too, but probably not very convenient to the user.

Hmm, make sense.

One thing to confirm: the value of gso_types should be DEV_TX_OFFLOAD_*_TSO, or new macros?

Jiayu

Quoted 16 lines

Konstantin

Quoted 14 lines

The first choice makes HW and SW segmentation are totally the same. Applications just need to parse the packet and set proper ol_flags, and the GSO library uses ol_flags to decide which segmentation function to use. I think it's better than the second choice which depending on ptype to choose segmentation function.

Jiayu

Quoted 6 lines

Konstantin

Quoted 3 lines

Jiayu

Quoted 1 line

Konstantin

#56 lore raw

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

Quoted 213 lines

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

Hi Konstantin and Mark,

Quoted 48 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 5:36 PM
To: Hu, Jiayu <[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

Quoted 5 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, September 14, 2017 10:29 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>; Tan,

Jianfeng <[email protected]>

Quoted 9 lines

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

Hi Konstantin,

Quoted 5 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 4:47 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan,

Quoted 10 lines
Quoted 10 lines

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

Hi Jiayu,

Quoted 5 lines

-----Original Message-----
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,

Quoted 11 lines
Quoted 11 lines

Jianfeng <[email protected]>

Quoted 10 lines

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

Hi Konstantin,

Quoted 5 lines · Konstantin

Hi Jiayu,

Quoted 2 lines
Quoted 2 lines
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 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

Quoted 4 lines
Quoted 4 lines

<[email protected]>

Quoted 3 lines
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

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

freed

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines

automatically.

(quoted diff) +0 -0

b/lib/librte_gso/rte_gso.c

Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 33 lines

index dda50ee..95f6ea6 100644

lib/librte_gso/rte_gso.c +14 -2
@@ -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) {

lib/librte_gso/rte_gso.c line 69

Quoted 10 lines
lib/librte_gso/rte_gso.c +10 -0
+		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_INCREASE;
+
+	if (is_ipv4_tcp(pkt->packet_type)) {

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

Quoted 9 lines
Quoted 4 lines
Quoted 4 lines

DEV_TX_OFFLOAD_TCP_TSO) != 0) {...

Quoted 3 lines
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 4 lines
Quoted 4 lines

&&

Quoted 3 lines
Quoted 3 lines
Quoted 3 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

Quoted 10 lines

TSO

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

flag is set or not. Applications can query device TSO capability

before

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

they call the GSO library. Do I misundertsand anything?

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

packet

Quoted 3 lines
Quoted 3 lines

here?

Quoted 2 lines
Quoted 2 lines

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

type

Quoted 9 lines

of

Quoted 4 lines
Quoted 4 lines

packet and

Quoted 3 lines
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

Quoted 3 lines
Quoted 3 lines

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

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

same gso_ctx and still

Quoted 3 lines
Quoted 3 lines

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

Alternative way is to rely on ptype to distinguish should

segmentation

Quoted 21 lines

be

Quoted 2 lines
Quoted 2 lines

performed on that package or not.

Quoted 1 line
Quoted 1 line

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

GSO

Quoted 6 lines
Quoted 6 lines

for some new protocol,

Quoted 2 lines
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 2 lines
Quoted 2 lines

So from my perspective first variant (use HW TSO API) is more

plausible.

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 1 line

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

Quoted 1 line

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

each input packet.

Quoted 1 line

Applications should parse the packet type, and set an exactly correct

DEV_TX_OFFLOAD_*_TSO

Quoted 1 line

flag to gso_types and ol_flags according to the packet type. That is,

the

Quoted 17 lines
Quoted 2 lines
Quoted 2 lines

value of gso_types

Quoted 1 line

is on a per-packet basis. Using gso_ctx->gso_types and mbuf->ol_flags

at

Quoted 2 lines
Quoted 2 lines

the same time

Quoted 1 line

is because that DEV_TX_OFFLOAD_*_TSO only tells tunnelling type and

the

Quoted 2 lines
Quoted 2 lines

inner L4 type, and

Quoted 1 line

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

segmentation

Quoted 8 lines
Quoted 8 lines

and SW segmentation

Quoted 3 lines

are indeed consistent.

If I understand it correctly, applications need to set 'ol_flags =

PKT_TX_IPV4' and

Quoted 1 line

'gso_types = DEV_TX_OFFLOAD_VXLAN_TNL_TSO' for a

"ether+ipv4+udp+vxlan+ether+ipv4+

Quoted 1 line

tcp+payload" packet. But PKT_TX_IPV4 just present the inner L3 type

for

Quoted 12 lines
Quoted 11 lines
Quoted 8 lines

tunneled packet.

Quoted 1 line

How about the outer L3 type? Always assume the inner and the outer L3

type are the same?

It think that for that case you'll have to set in ol_flags:

PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN | PKT_TX_TCP_SEG

OK, so it means PKT_TX_TCP_SEG is also used for tunneled TSO. The GSO library doesn't need gso_types anymore.

Quoted 6 lines

You still might need gso_ctx.gso_types to let user limit what types of segmentation
that particular gso_ctx supports.
An alternative would be to assume that each gso_ctx supports all currently implemented segmentations.
This is possible too, but probably not very convenient to the user.

Quoted 4 lines

Hmm, make sense.

One thing to confirm: the value of gso_types should be DEV_TX_OFFLOAD_*_TSO, or new macros?

Hi Jiayu, Konstantin,

I think that the existing macros are fine, as they provide a consistent view of segmentation capabilities to the application/user.

I was initially concerned that they might be too coarse-grained (i.e. only IPv4 is currently supported, and not IPv6), but as per Konstantin's previous example, the DEV_TX_OFFLOAD_*_TSO macros can be used in concert with the packet type to determine whether a packet should be fragmented or not.

Thanks,
Mark

Quoted 19 lines

Jiayu

Quoted 6 lines

Konstantin

Quoted 4 lines

The first choice makes HW and SW segmentation are totally the same. Applications just need to parse the packet and set proper ol_flags, and the GSO library uses ol_flags to decide which segmentation function to

use.

Quoted 10 lines
Quoted 10 lines

I think it's better than the second choice which depending on ptype to choose segmentation function.

Jiayu

Quoted 6 lines

Konstantin

Quoted 3 lines

Jiayu

Quoted 1 line

Konstantin

#57 lore raw

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

Quoted 222 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, September 14, 2017 4:42 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 213 lines

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

Hi Konstantin and Mark,

Quoted 48 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 5:36 PM
To: Hu, Jiayu <[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

Quoted 5 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, September 14, 2017 10:29 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>; Tan,

Jianfeng <[email protected]>

Quoted 9 lines

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

Hi Konstantin,

Quoted 5 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 4:47 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan,

Quoted 10 lines
Quoted 10 lines

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

Hi Jiayu,

Quoted 5 lines

-----Original Message-----
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,

Quoted 11 lines
Quoted 11 lines

Jianfeng <[email protected]>

Quoted 10 lines

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

Hi Konstantin,

Quoted 5 lines · Konstantin

Hi Jiayu,

Quoted 2 lines
Quoted 2 lines
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 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

Quoted 4 lines
Quoted 4 lines

<[email protected]>

Quoted 3 lines
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

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

freed

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines

automatically.

(quoted diff) +0 -0

b/lib/librte_gso/rte_gso.c

Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 46 lines
Quoted 33 lines

index dda50ee..95f6ea6 100644

lib/librte_gso/rte_gso.c +14 -2
@@ -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) {

lib/librte_gso/rte_gso.c line 69

Quoted 10 lines
lib/librte_gso/rte_gso.c +10 -0
+		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_INCREASE;
+
+	if (is_ipv4_tcp(pkt->packet_type)) {

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

Quoted 9 lines
Quoted 4 lines
Quoted 4 lines

DEV_TX_OFFLOAD_TCP_TSO) != 0) {...

Quoted 3 lines
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 4 lines
Quoted 4 lines

&&

Quoted 3 lines
Quoted 3 lines
Quoted 3 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

Quoted 10 lines

TSO

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

flag is set or not. Applications can query device TSO capability

before

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

they call the GSO library. Do I misundertsand anything?

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

packet

Quoted 3 lines
Quoted 3 lines

here?

Quoted 2 lines
Quoted 2 lines

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

type

Quoted 9 lines

of

Quoted 4 lines
Quoted 4 lines

packet and

Quoted 3 lines
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

Quoted 3 lines
Quoted 3 lines

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

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

same gso_ctx and still

Quoted 3 lines
Quoted 3 lines

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

Alternative way is to rely on ptype to distinguish should

segmentation

Quoted 21 lines

be

Quoted 2 lines
Quoted 2 lines

performed on that package or not.

Quoted 1 line
Quoted 1 line

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

GSO

Quoted 6 lines
Quoted 6 lines

for some new protocol,

Quoted 2 lines
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 2 lines
Quoted 2 lines

So from my perspective first variant (use HW TSO API) is more

plausible.

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
Quoted 1 line

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

Quoted 1 line

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

each input packet.

Quoted 1 line

Applications should parse the packet type, and set an exactly correct

DEV_TX_OFFLOAD_*_TSO

Quoted 1 line

flag to gso_types and ol_flags according to the packet type. That is,

the

Quoted 17 lines
Quoted 2 lines
Quoted 2 lines

value of gso_types

Quoted 1 line

is on a per-packet basis. Using gso_ctx->gso_types and mbuf->ol_flags

at

Quoted 2 lines
Quoted 2 lines

the same time

Quoted 1 line

is because that DEV_TX_OFFLOAD_*_TSO only tells tunnelling type and

the

Quoted 2 lines
Quoted 2 lines

inner L4 type, and

Quoted 1 line

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

segmentation

Quoted 8 lines
Quoted 8 lines

and SW segmentation

Quoted 3 lines

are indeed consistent.

If I understand it correctly, applications need to set 'ol_flags =

PKT_TX_IPV4' and

Quoted 1 line

'gso_types = DEV_TX_OFFLOAD_VXLAN_TNL_TSO' for a

"ether+ipv4+udp+vxlan+ether+ipv4+

Quoted 1 line

tcp+payload" packet. But PKT_TX_IPV4 just present the inner L3 type

for

Quoted 18 lines
Quoted 11 lines
Quoted 8 lines

tunneled packet.

Quoted 1 line

How about the outer L3 type? Always assume the inner and the outer L3

type are the same?

It think that for that case you'll have to set in ol_flags:

PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN | PKT_TX_TCP_SEG

OK, so it means PKT_TX_TCP_SEG is also used for tunneled TSO. The GSO library doesn't need gso_types anymore.

You still might need gso_ctx.gso_types to let user limit what types of segmentation
that particular gso_ctx supports.
An alternative would be to assume that each gso_ctx supports all currently implemented segmentations.
This is possible too, but probably not very convenient to the user.

Quoted 8 lines
Quoted 4 lines

Hmm, make sense.

One thing to confirm: the value of gso_types should be DEV_TX_OFFLOAD_*_TSO, or new macros?

Hi Jiayu, Konstantin,

I think that the existing macros are fine, as they provide a consistent view of segmentation capabilities to the application/user.

+1
I also think it is better to re-use DEV_TX_OFFLOAD_*_TSO.

Quoted 27 lines

I was initially concerned that they might be too coarse-grained (i.e. only IPv4 is currently supported, and not IPv6), but as per Konstantin's previous example, the DEV_TX_OFFLOAD_*_TSO macros can be used in concert with the packet type to determine whether a packet should be fragmented or not.

Thanks,
Mark

Quoted 19 lines

Jiayu

Quoted 6 lines

Konstantin

Quoted 4 lines

The first choice makes HW and SW segmentation are totally the same. Applications just need to parse the packet and set proper ol_flags, and the GSO library uses ol_flags to decide which segmentation function to

use.

Quoted 10 lines
Quoted 10 lines

I think it's better than the second choice which depending on ptype to choose segmentation function.

Jiayu

Quoted 6 lines

Konstantin

Quoted 3 lines

Jiayu

Quoted 1 line

Konstantin

author
#58 lore raw

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

Hi Konstantin,

Quoted 260 lines

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

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, September 14, 2017 4:42 PM
To: Hu, Jiayu <[email protected]>; Ananyev, Konstantin

<[email protected]>

Quoted 6 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 3 lines

From: Hu, Jiayu
Sent: Thursday, September 14, 2017 11:01 AM
To: Ananyev, Konstantin <[email protected]>; Kavanagh,

Mark B

Quoted 11 lines
Quoted 11 lines

<[email protected]>
Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Hi Konstantin and Mark,

Quoted 5 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 5:36 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

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

Quoted 5 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, September 14, 2017 10:29 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Jianfeng <[email protected]>

Quoted 9 lines

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

Hi Konstantin,

Quoted 5 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 4:47 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B

<[email protected]>;

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Tan,

Quoted 10 lines
Quoted 10 lines

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

Hi Jiayu,

Quoted 5 lines

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

<[email protected]>;

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Tan,

Quoted 6 lines
Quoted 6 lines

Jianfeng <[email protected]>

Quoted 5 lines

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

Hi Konstantin,

On Thu, Sep 14, 2017 at 06:10:37AM +0800, Ananyev, Konstantin

Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

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,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Jianfeng

Quoted 4 lines
Quoted 4 lines

<[email protected]>

Quoted 3 lines
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

Quoted 18 lines
Quoted 18 lines

is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

freed

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines

automatically.

(quoted diff) +0 -0

b/lib/librte_gso/rte_gso.c

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

index dda50ee..95f6ea6 100644

lib/librte_gso/rte_gso.c +4 -0
@@ -33,18 +33,53 @@
 
 #include <errno.h>
 
+#include <rte_log.h>
+
 #include "rte_gso.h"
+#include "gso_common.h"
+#include "gso_tcp4.h"
 
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
lib/librte_gso/rte_gso.c +1 -1
 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)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

lib/librte_gso/rte_gso.c line 54

Quoted 8 lines
lib/librte_gso/rte_gso.c +6 -0
 {
+	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)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

lib/librte_gso/rte_gso.c line 58

Quoted 5 lines
lib/librte_gso/rte_gso.c +2 -1
 		return -EINVAL;
 
-	pkts_out[0] = pkt;
+	if (gso_ctx.gso_size >= pkt->pkt_len ||
+			(pkt->packet_type &

gso_ctx.gso_types) !=

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

lib/librte_gso/rte_gso.c line 67

Quoted 9 lines
lib/librte_gso/rte_gso.c +9 -0
+			pkt->packet_type) {
+		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_INCREASE;

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

lib/librte_gso/rte_gso.c line 69

Quoted 2 lines
lib/librte_gso/rte_gso.c +2 -0
+
+	if (is_ipv4_tcp(pkt->packet_type)) {

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

&

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

DEV_TX_OFFLOAD_TCP_TSO) != 0) {...

Quoted 3 lines
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 2 lines
Quoted 2 lines

&&

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
      (gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO) != 0)

{...

Quoted 12 lines
Quoted 12 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I don't quite understand why the GSO library should be aware if

the

Quoted 9 lines

TSO

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

flag is set or not. Applications can query device TSO capability

before

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

they call the GSO library. Do I misundertsand anything?

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

packet

Quoted 2 lines
Quoted 2 lines

here?

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

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

type

Quoted 5 lines

of

Quoted 4 lines
Quoted 4 lines

packet and

Quoted 3 lines
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

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

be

Quoted 3 lines
Quoted 3 lines

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

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

same gso_ctx and still

Quoted 3 lines
Quoted 3 lines

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

Alternative way is to rely on ptype to distinguish should

segmentation

Quoted 3 lines

be

Quoted 2 lines
Quoted 2 lines

performed on that package or not.

Quoted 1 line
Quoted 1 line

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

add

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

GSO

Quoted 2 lines
Quoted 2 lines

for some new protocol,

Quoted 1 line
Quoted 1 line

he wouldn't need to introduce new TX flag value for

mbuf.ol_flags.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Though he still would need to update TX_OFFLOAD_* capabilities

and

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

probably packet_type definitions.

Quoted 2 lines
Quoted 2 lines

So from my perspective first variant (use HW TSO API) is more

plausible.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

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

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

specific GSO

Quoted 1 line

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

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

each input packet.

Quoted 1 line

Applications should parse the packet type, and set an exactly

correct

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

DEV_TX_OFFLOAD_*_TSO

Quoted 1 line

flag to gso_types and ol_flags according to the packet type. That is,

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

value of gso_types

Quoted 1 line

is on a per-packet basis. Using gso_ctx->gso_types and mbuf-

ol_flags

Quoted 3 lines
Quoted 3 lines

at

Quoted 2 lines
Quoted 2 lines

the same time

Quoted 1 line

is because that DEV_TX_OFFLOAD_*_TSO only tells tunnelling type

and

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

the

Quoted 2 lines
Quoted 2 lines

inner L4 type, and

Quoted 1 line

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

segmentation

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

and SW segmentation

Quoted 3 lines

are indeed consistent.

If I understand it correctly, applications need to set 'ol_flags =

PKT_TX_IPV4' and

Quoted 1 line

'gso_types = DEV_TX_OFFLOAD_VXLAN_TNL_TSO' for a

"ether+ipv4+udp+vxlan+ether+ipv4+

Quoted 1 line

tcp+payload" packet. But PKT_TX_IPV4 just present the inner L3

type

Quoted 3 lines
Quoted 3 lines

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

tunneled packet.

Quoted 1 line

How about the outer L3 type? Always assume the inner and the

outer L3

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 9 lines
Quoted 6 lines

type are the same?

It think that for that case you'll have to set in ol_flags:

PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN | PKT_TX_TCP_SEG

OK, so it means PKT_TX_TCP_SEG is also used for tunneled TSO. The GSO library doesn't need gso_types anymore.

You still might need gso_ctx.gso_types to let user limit what types of segmentation
that particular gso_ctx supports.
An alternative would be to assume that each gso_ctx supports all currently implemented segmentations.
This is possible too, but probably not very convenient to the user.

Quoted 3 lines
Quoted 3 lines

Hmm, make sense.

One thing to confirm: the value of gso_types should be

DEV_TX_OFFLOAD_*_TSO,

Quoted 2 lines
Quoted 1 line

or new macros?

Quoted 7 lines
Quoted 3 lines

Hi Jiayu, Konstantin,

I think that the existing macros are fine, as they provide a consistent view

of segmentation capabilities to the application/user.

+1
I also think it is better to re-use DEV_TX_OFFLOAD_*_TSO.

There might be an 'issue', if we use 'PKT_TX_TCP_SEG' to tell the GSO library to segment a packet or not. Given the scenario that
an application only wants to do GSO and doesn't want to use TSO.
The application sets 'mbuf->ol_flags=PKT_TX_TCP_SEG' and doesn't
set mbuf->tso_segsz. Then the GSO library segments the packet, and all output GSO segments have the same ol_flags as the input packet (in current GSO library design). Then the output GSO segments are transmitted to rte_eth_tx_prepare(). If the NIC is i40e, its TX prepare function, i40e_prep_pkts, checks if mbuf->tso_segsz is in the range of I40E_MIN_TSO_MSS and I40E_MAX_TSO_MSS, when PKT_TX_TCP_SEG is set. So an error happens in this scenario, since tso_segsz is 0.

In fact, it may confuse the PMD driver when set PKT_TX_TCP_SEG but don't want to do TSO. One solution is that the GSO library removes the PKT_TX_TCP_SEG flag for all GSO segments after finishes segmenting. Wonder you and Mark's opinion.

Thanks,
Jiayu

Quoted 30 lines
Quoted 3 lines

I was initially concerned that they might be too coarse-grained (i.e. only

IPv4 is currently supported, and not IPv6), but as per Konstantin's

Quoted 1 line

previous example, the DEV_TX_OFFLOAD_*_TSO macros can be used in

concert with the packet type to determine whether a packet should

Quoted 24 lines

be fragmented or not.

Thanks,
Mark

Quoted 19 lines

Jiayu

Quoted 6 lines

Konstantin

Quoted 4 lines

The first choice makes HW and SW segmentation are totally the same. Applications just need to parse the packet and set proper ol_flags, and the GSO library uses ol_flags to decide which segmentation function to

use.

Quoted 10 lines
Quoted 10 lines

I think it's better than the second choice which depending on ptype to choose segmentation function.

Jiayu

Quoted 6 lines

Konstantin

Quoted 3 lines

Jiayu

Quoted 1 line

Konstantin

#59 lore raw

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

Hi Jiayu,

Quoted 289 lines

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

Hi Konstantin,

Quoted 260 lines

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

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, September 14, 2017 4:42 PM
To: Hu, Jiayu <[email protected]>; Ananyev, Konstantin

<[email protected]>

Quoted 6 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 3 lines

From: Hu, Jiayu
Sent: Thursday, September 14, 2017 11:01 AM
To: Ananyev, Konstantin <[email protected]>; Kavanagh,

Mark B

Quoted 11 lines
Quoted 11 lines

<[email protected]>
Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Hi Konstantin and Mark,

Quoted 5 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 5:36 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

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

Quoted 5 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, September 14, 2017 10:29 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Jianfeng <[email protected]>

Quoted 9 lines

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

Hi Konstantin,

Quoted 5 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 4:47 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B

<[email protected]>;

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Tan,

Quoted 10 lines
Quoted 10 lines

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

Hi Jiayu,

Quoted 5 lines

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

<[email protected]>;

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Tan,

Quoted 6 lines
Quoted 6 lines

Jianfeng <[email protected]>

Quoted 5 lines

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

Hi Konstantin,

On Thu, Sep 14, 2017 at 06:10:37AM +0800, Ananyev, Konstantin

Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

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,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Jianfeng

Quoted 4 lines
Quoted 4 lines

<[email protected]>

Quoted 3 lines
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

Quoted 18 lines
Quoted 18 lines

is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

freed

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

automatically.
diff --git a/lib/librte_gso/rte_gso.c

b/lib/librte_gso/rte_gso.c

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

index dda50ee..95f6ea6 100644
--- a/lib/librte_gso/rte_gso.c
+++ b/lib/librte_gso/rte_gso.c
@@ -33,18 +33,53 @@

#include <errno.h>

+#include <rte_log.h>
+
#include "rte_gso.h"
+#include "gso_common.h"
+#include "gso_tcp4.h"

Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

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)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

{
+ 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)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

return -EINVAL;

- pkts_out[0] = pkt;
+ if (gso_ctx.gso_size >= pkt->pkt_len ||
+ (pkt->packet_type &

gso_ctx.gso_types) !=

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

+ pkt->packet_type) {
+ 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_INCREASE;

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

+
+ if (is_ipv4_tcp(pkt->packet_type)) {

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

&

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

DEV_TX_OFFLOAD_TCP_TSO) != 0) {...

Quoted 3 lines
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 2 lines
Quoted 2 lines

&&

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
      (gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO) != 0)

{...

Quoted 12 lines
Quoted 12 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I don't quite understand why the GSO library should be aware if

the

Quoted 9 lines

TSO

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

flag is set or not. Applications can query device TSO capability

before

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

they call the GSO library. Do I misundertsand anything?

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

packet

Quoted 2 lines
Quoted 2 lines

here?

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

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

type

Quoted 5 lines

of

Quoted 4 lines
Quoted 4 lines

packet and

Quoted 3 lines
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

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

be

Quoted 3 lines
Quoted 3 lines

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

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

same gso_ctx and still

Quoted 3 lines
Quoted 3 lines

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

Alternative way is to rely on ptype to distinguish should

segmentation

Quoted 3 lines

be

Quoted 2 lines
Quoted 2 lines

performed on that package or not.

Quoted 1 line
Quoted 1 line

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

add

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

GSO

Quoted 2 lines
Quoted 2 lines

for some new protocol,

Quoted 1 line
Quoted 1 line

he wouldn't need to introduce new TX flag value for

mbuf.ol_flags.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Though he still would need to update TX_OFFLOAD_* capabilities

and

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

probably packet_type definitions.

Quoted 2 lines
Quoted 2 lines

So from my perspective first variant (use HW TSO API) is more

plausible.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

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

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

specific GSO

Quoted 1 line

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

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

each input packet.

Quoted 1 line

Applications should parse the packet type, and set an exactly

correct

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

DEV_TX_OFFLOAD_*_TSO

Quoted 1 line

flag to gso_types and ol_flags according to the packet type. That is,

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

value of gso_types

Quoted 1 line

is on a per-packet basis. Using gso_ctx->gso_types and mbuf-

ol_flags

Quoted 3 lines
Quoted 3 lines

at

Quoted 2 lines
Quoted 2 lines

the same time

Quoted 1 line

is because that DEV_TX_OFFLOAD_*_TSO only tells tunnelling type

and

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

the

Quoted 2 lines
Quoted 2 lines

inner L4 type, and

Quoted 1 line

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

segmentation

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

and SW segmentation

Quoted 3 lines

are indeed consistent.

If I understand it correctly, applications need to set 'ol_flags =

PKT_TX_IPV4' and

Quoted 1 line

'gso_types = DEV_TX_OFFLOAD_VXLAN_TNL_TSO' for a

"ether+ipv4+udp+vxlan+ether+ipv4+

Quoted 1 line

tcp+payload" packet. But PKT_TX_IPV4 just present the inner L3

type

Quoted 3 lines
Quoted 3 lines

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

tunneled packet.

Quoted 1 line

How about the outer L3 type? Always assume the inner and the

outer L3

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 9 lines
Quoted 6 lines

type are the same?

It think that for that case you'll have to set in ol_flags:

PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN | PKT_TX_TCP_SEG

OK, so it means PKT_TX_TCP_SEG is also used for tunneled TSO. The GSO library doesn't need gso_types anymore.

You still might need gso_ctx.gso_types to let user limit what types of segmentation
that particular gso_ctx supports.
An alternative would be to assume that each gso_ctx supports all currently implemented segmentations.
This is possible too, but probably not very convenient to the user.

Quoted 3 lines
Quoted 3 lines

Hmm, make sense.

One thing to confirm: the value of gso_types should be

DEV_TX_OFFLOAD_*_TSO,

Quoted 2 lines
Quoted 1 line

or new macros?

Quoted 7 lines
Quoted 3 lines

Hi Jiayu, Konstantin,

I think that the existing macros are fine, as they provide a consistent view

of segmentation capabilities to the application/user.

+1
I also think it is better to re-use DEV_TX_OFFLOAD_*_TSO.

There might be an 'issue', if we use 'PKT_TX_TCP_SEG' to tell the GSO library to segment a packet or not. Given the scenario that
an application only wants to do GSO and doesn't want to use TSO.
The application sets 'mbuf->ol_flags=PKT_TX_TCP_SEG' and doesn't
set mbuf->tso_segsz. Then the GSO library segments the packet, and all output GSO segments have the same ol_flags as the input packet (in current GSO library design). Then the output GSO segments are transmitted to rte_eth_tx_prepare(). If the NIC is i40e, its TX prepare function, i40e_prep_pkts, checks if mbuf->tso_segsz is in the range of I40E_MIN_TSO_MSS and I40E_MAX_TSO_MSS, when PKT_TX_TCP_SEG is set. So an error happens in this scenario, since tso_segsz is 0.

Quoted 3 lines

In fact, it may confuse the PMD driver when set PKT_TX_TCP_SEG but don't want to do TSO. One solution is that the GSO library removes the PKT_TX_TCP_SEG flag for all GSO segments after finishes segmenting.

Yes, that was my thought too: after successful segmentation we probably need to cleanup related ol_flags.
Konstantin

Quoted 34 lines

Wonder you and Mark's opinion.

Thanks,
Jiayu

Quoted 30 lines
Quoted 3 lines

I was initially concerned that they might be too coarse-grained (i.e. only

IPv4 is currently supported, and not IPv6), but as per Konstantin's

Quoted 1 line

previous example, the DEV_TX_OFFLOAD_*_TSO macros can be used in

concert with the packet type to determine whether a packet should

Quoted 24 lines

be fragmented or not.

Thanks,
Mark

Quoted 19 lines

Jiayu

Quoted 6 lines

Konstantin

Quoted 4 lines

The first choice makes HW and SW segmentation are totally the same. Applications just need to parse the packet and set proper ol_flags, and the GSO library uses ol_flags to decide which segmentation function to

use.

Quoted 10 lines
Quoted 10 lines

I think it's better than the second choice which depending on ptype to choose segmentation function.

Jiayu

Quoted 6 lines

Konstantin

Quoted 3 lines

Jiayu

Quoted 1 line

Konstantin

#60 lore raw

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

In reply to Hu, Jiayu
Quoted 300 lines

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

Hi Jiayu,

Quoted 289 lines

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

Hi Konstantin,

Quoted 260 lines

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

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, September 14, 2017 4:42 PM
To: Hu, Jiayu <[email protected]>; Ananyev, Konstantin

<[email protected]>

Quoted 6 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 3 lines

From: Hu, Jiayu
Sent: Thursday, September 14, 2017 11:01 AM
To: Ananyev, Konstantin <[email protected]>; Kavanagh,

Mark B

Quoted 11 lines
Quoted 11 lines

<[email protected]>
Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Hi Konstantin and Mark,

Quoted 5 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 5:36 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

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

Quoted 5 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, September 14, 2017 10:29 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B <[email protected]>;

Tan,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Jianfeng <[email protected]>

Quoted 9 lines

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

Hi Konstantin,

Quoted 5 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 4:47 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B

<[email protected]>;

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Tan,

Quoted 10 lines
Quoted 10 lines

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

Hi Jiayu,

Quoted 5 lines

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

<[email protected]>;

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Tan,

Quoted 6 lines
Quoted 6 lines

Jianfeng <[email protected]>

Quoted 5 lines

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

Hi Konstantin,

On Thu, Sep 14, 2017 at 06:10:37AM +0800, Ananyev, Konstantin

Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

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,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Jianfeng

Quoted 4 lines
Quoted 4 lines

<[email protected]>

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

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

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

packet

Quoted 18 lines
Quoted 18 lines

is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

freed

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

automatically.
diff --git a/lib/librte_gso/rte_gso.c

b/lib/librte_gso/rte_gso.c

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

index dda50ee..95f6ea6 100644
--- a/lib/librte_gso/rte_gso.c
+++ b/lib/librte_gso/rte_gso.c
@@ -33,18 +33,53 @@

#include <errno.h>

+#include <rte_log.h>
+
#include "rte_gso.h"
+#include "gso_common.h"
+#include "gso_tcp4.h"

Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

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)

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

{
+ 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)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

return -EINVAL;

- pkts_out[0] = pkt;
+ if (gso_ctx.gso_size >= pkt->pkt_len ||
+ (pkt->packet_type &

gso_ctx.gso_types) !=

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

+ pkt->packet_type) {
+ 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_INCREASE;

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+
+ if (is_ipv4_tcp(pkt->packet_type)) {

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

&

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

DEV_TX_OFFLOAD_TCP_TSO) != 0) {...

Quoted 3 lines
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 2 lines
Quoted 2 lines

&&

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
      (gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO) != 0)

{...

Quoted 12 lines
Quoted 12 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I don't quite understand why the GSO library should be aware if

the

Quoted 9 lines

TSO

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

flag is set or not. Applications can query device TSO capability

before

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

they call the GSO library. Do I misundertsand anything?

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

packet

Quoted 2 lines
Quoted 2 lines

here?

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

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

type

Quoted 5 lines

of

Quoted 4 lines
Quoted 4 lines

packet and

Quoted 3 lines
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

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

be

Quoted 3 lines
Quoted 3 lines

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

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

same gso_ctx and still

Quoted 3 lines
Quoted 3 lines

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

Alternative way is to rely on ptype to distinguish should

segmentation

Quoted 3 lines

be

Quoted 2 lines
Quoted 2 lines

performed on that package or not.

Quoted 1 line
Quoted 1 line

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

add

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

GSO

Quoted 2 lines
Quoted 2 lines

for some new protocol,

Quoted 1 line
Quoted 1 line

he wouldn't need to introduce new TX flag value for

mbuf.ol_flags.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Though he still would need to update TX_OFFLOAD_* capabilities

and

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

probably packet_type definitions.

Quoted 2 lines
Quoted 2 lines

So from my perspective first variant (use HW TSO API) is more

plausible.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

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

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

specific GSO

Quoted 1 line

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

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

each input packet.

Quoted 1 line

Applications should parse the packet type, and set an exactly

correct

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

DEV_TX_OFFLOAD_*_TSO

Quoted 1 line

flag to gso_types and ol_flags according to the packet type. That is,

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

value of gso_types

Quoted 1 line

is on a per-packet basis. Using gso_ctx->gso_types and mbuf-

ol_flags

Quoted 3 lines
Quoted 3 lines

at

Quoted 2 lines
Quoted 2 lines

the same time

Quoted 1 line

is because that DEV_TX_OFFLOAD_*_TSO only tells tunnelling type

and

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

the

Quoted 2 lines
Quoted 2 lines

inner L4 type, and

Quoted 1 line

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

segmentation

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

and SW segmentation

Quoted 3 lines

are indeed consistent.

If I understand it correctly, applications need to set 'ol_flags =

PKT_TX_IPV4' and

Quoted 1 line

'gso_types = DEV_TX_OFFLOAD_VXLAN_TNL_TSO' for a

"ether+ipv4+udp+vxlan+ether+ipv4+

Quoted 1 line

tcp+payload" packet. But PKT_TX_IPV4 just present the inner L3

type

Quoted 3 lines
Quoted 3 lines

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

tunneled packet.

Quoted 1 line

How about the outer L3 type? Always assume the inner and the

outer L3

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 9 lines
Quoted 6 lines

type are the same?

It think that for that case you'll have to set in ol_flags:

PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 | PKT_TX_TUNNEL_VXLAN | PKT_TX_TCP_SEG

OK, so it means PKT_TX_TCP_SEG is also used for tunneled TSO. The GSO library doesn't need gso_types anymore.

You still might need gso_ctx.gso_types to let user limit what types of segmentation
that particular gso_ctx supports.
An alternative would be to assume that each gso_ctx supports all currently implemented segmentations.
This is possible too, but probably not very convenient to the user.

Quoted 3 lines
Quoted 3 lines

Hmm, make sense.

One thing to confirm: the value of gso_types should be

DEV_TX_OFFLOAD_*_TSO,

Quoted 2 lines
Quoted 1 line

or new macros?

Quoted 7 lines
Quoted 3 lines

Hi Jiayu, Konstantin,

I think that the existing macros are fine, as they provide a consistent view

of segmentation capabilities to the application/user.

+1
I also think it is better to re-use DEV_TX_OFFLOAD_*_TSO.

There might be an 'issue', if we use 'PKT_TX_TCP_SEG' to tell the GSO library to segment a packet or not. Given the scenario that
an application only wants to do GSO and doesn't want to use TSO.
The application sets 'mbuf->ol_flags=PKT_TX_TCP_SEG' and doesn't
set mbuf->tso_segsz. Then the GSO library segments the packet, and all output GSO segments have the same ol_flags as the input packet (in current GSO library design). Then the output GSO segments are transmitted to rte_eth_tx_prepare(). If the NIC is i40e, its TX prepare function, i40e_prep_pkts, checks if mbuf->tso_segsz is in the range of I40E_MIN_TSO_MSS and I40E_MAX_TSO_MSS, when PKT_TX_TCP_SEG is set. So an error happens in this scenario, since tso_segsz is 0.

Quoted 6 lines
Quoted 3 lines

In fact, it may confuse the PMD driver when set PKT_TX_TCP_SEG but don't want to do TSO. One solution is that the GSO library removes the PKT_TX_TCP_SEG flag for all GSO segments after finishes segmenting.

Yes, that was my thought too: after successful segmentation we probably need to cleanup related ol_flags.

In fact, we just don't need to set these flags in our newly created segments.

Quoted 36 lines

Konstantin

Quoted 34 lines

Wonder you and Mark's opinion.

Thanks,
Jiayu

Quoted 30 lines
Quoted 3 lines

I was initially concerned that they might be too coarse-grained (i.e. only

IPv4 is currently supported, and not IPv6), but as per Konstantin's

Quoted 1 line

previous example, the DEV_TX_OFFLOAD_*_TSO macros can be used in

concert with the packet type to determine whether a packet should

Quoted 24 lines

be fragmented or not.

Thanks,
Mark

Quoted 19 lines

Jiayu

Quoted 6 lines

Konstantin

Quoted 4 lines

The first choice makes HW and SW segmentation are totally the same. Applications just need to parse the packet and set proper ol_flags, and the GSO library uses ol_flags to decide which segmentation function to

use.

Quoted 10 lines
Quoted 10 lines

I think it's better than the second choice which depending on ptype to choose segmentation function.

Jiayu

Quoted 6 lines

Konstantin

Quoted 3 lines

Jiayu

Quoted 1 line

Konstantin

author
#61 lore raw

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

Quoted 348 lines

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

Quoted 4 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Friday, September 15, 2017 9:16 AM
To: Hu, Jiayu <[email protected]>; Kavanagh, Mark B

<[email protected]>

Quoted 9 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Hi Jiayu,

Quoted 4 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Friday, September 15, 2017 8:55 AM
To: Ananyev, Konstantin <[email protected]>; Kavanagh,

Mark B <[email protected]>

Quoted 19 lines
Quoted 19 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Hi Konstantin,

Quoted 14 lines

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

Quoted 4 lines

-----Original Message-----
From: Kavanagh, Mark B
Sent: Thursday, September 14, 2017 4:42 PM
To: Hu, Jiayu <[email protected]>; Ananyev, Konstantin

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

<[email protected]>

Quoted 6 lines

Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 3 lines

From: Hu, Jiayu
Sent: Thursday, September 14, 2017 11:01 AM
To: Ananyev, Konstantin <[email protected]>;

Kavanagh,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Mark B

Quoted 4 lines
Quoted 4 lines

<[email protected]>
Cc: [email protected]; Tan, Jianfeng <[email protected]>
Subject: RE: [PATCH v3 2/5] gso: add TCP/IPv4 GSO support

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Hi Konstantin and Mark,

Quoted 5 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 5:36 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B

<[email protected]>;

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Tan,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

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

Quoted 5 lines

-----Original Message-----
From: Hu, Jiayu
Sent: Thursday, September 14, 2017 10:29 AM
To: Ananyev, Konstantin <[email protected]>
Cc: [email protected]; Kavanagh, Mark B

<[email protected]>;

Quoted 23 lines
Quoted 23 lines
Quoted 23 lines

Tan,

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Jianfeng <[email protected]>

Quoted 9 lines

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

Hi Konstantin,

Quoted 5 lines

-----Original Message-----
From: Ananyev, Konstantin
Sent: Thursday, September 14, 2017 4:47 PM
To: Hu, Jiayu <[email protected]>
Cc: [email protected]; Kavanagh, Mark B

<[email protected]>;

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Tan,

Quoted 10 lines
Quoted 10 lines

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

Hi Jiayu,

Quoted 5 lines

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

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

<[email protected]>;

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Tan,

Quoted 6 lines
Quoted 6 lines

Jianfeng <[email protected]>

Quoted 5 lines

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

Hi Konstantin,

On Thu, Sep 14, 2017 at 06:10:37AM +0800, Ananyev,

Konstantin

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines · wrote:
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

Hi Jiayu,

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,

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

Jianfeng

Quoted 2 lines
Quoted 2 lines

<[email protected]>

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

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

support

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

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

packet

Quoted 18 lines
Quoted 18 lines

is

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

freed

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

automatically.
diff --git a/lib/librte_gso/rte_gso.c

b/lib/librte_gso/rte_gso.c

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines

index dda50ee..95f6ea6 100644
--- a/lib/librte_gso/rte_gso.c
+++ b/lib/librte_gso/rte_gso.c
@@ -33,18 +33,53 @@

#include <errno.h>

+#include <rte_log.h>
+
#include "rte_gso.h"
+#include "gso_common.h"
+#include "gso_tcp4.h"

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

int
rte_gso_segment(struct rte_mbuf *pkt,
- struct rte_gso_ctx gso_ctx

__rte_unused,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+ struct rte_gso_ctx gso_ctx,
struct rte_mbuf **pkts_out,
uint16_t nb_pkts_out)
{
+ struct rte_mempool *direct_pool,

*indirect_pool;

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

+ 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

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

< 1)

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

return -EINVAL;

- pkts_out[0] = pkt;
+ if (gso_ctx.gso_size >= pkt->pkt_len ||
+ (pkt->packet_type &

gso_ctx.gso_types) !=

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

+ pkt->packet_type) {
+ 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_INCREASE;

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

+
+ if (is_ipv4_tcp(pkt->packet_type)) {

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

gso_types

Quoted 8 lines
Quoted 8 lines

&

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

DEV_TX_OFFLOAD_TCP_TSO) != 0) {...

Quoted 3 lines
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 2 lines
Quoted 2 lines

&&

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

(gso_ctx->gso_types &

DEV_TX_OFFLOAD_TCP_TSO) != 0)

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

{...

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I don't quite understand why the GSO library should be

aware if

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

the

Quoted 2 lines

TSO

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

flag is set or not. Applications can query device TSO

capability

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

before

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

they call the GSO library. Do I misundertsand anything?

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

TCP/IPv4

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

packet

Quoted 3 lines
Quoted 3 lines

here?

Quoted 2 lines
Quoted 2 lines

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

what

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

type

Quoted 5 lines

of

Quoted 4 lines
Quoted 4 lines

packet and

Quoted 3 lines
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

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

would

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

be

Quoted 3 lines
Quoted 3 lines

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

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

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

same gso_ctx and still

Quoted 1 line
Quoted 1 line

specify what segmentation to perform on a per-packet

basis.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Alternative way is to rely on ptype to distinguish should

segmentation

Quoted 3 lines

be

Quoted 2 lines
Quoted 2 lines

performed on that package or not.

Quoted 1 line
Quoted 1 line

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

to

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

add

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

GSO

Quoted 2 lines
Quoted 2 lines

for some new protocol,

Quoted 1 line
Quoted 1 line

he wouldn't need to introduce new TX flag value for

mbuf.ol_flags.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Though he still would need to update TX_OFFLOAD_*

capabilities

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

and

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

probably packet_type definitions.

Quoted 2 lines
Quoted 2 lines

So from my perspective first variant (use HW TSO API) is

more

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

plausible.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

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

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

specific GSO

Quoted 1 line

segmentation function (e.g. gso_tcp4_segment(),

gso_tunnel_xxx())

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

each input packet.

Quoted 1 line

Applications should parse the packet type, and set an exactly

correct

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

DEV_TX_OFFLOAD_*_TSO

Quoted 1 line

flag to gso_types and ol_flags according to the packet type.

That is,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

value of gso_types

Quoted 1 line

is on a per-packet basis. Using gso_ctx->gso_types and mbuf-

ol_flags

Quoted 3 lines
Quoted 3 lines

at

Quoted 2 lines
Quoted 2 lines

the same time

Quoted 1 line

is because that DEV_TX_OFFLOAD_*_TSO only tells tunnelling

type

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

and

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

the

Quoted 2 lines
Quoted 2 lines

inner L4 type, and

Quoted 1 line

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

segmentation

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

and SW segmentation

Quoted 3 lines

are indeed consistent.

If I understand it correctly, applications need to set 'ol_flags =

PKT_TX_IPV4' and

Quoted 1 line

'gso_types = DEV_TX_OFFLOAD_VXLAN_TNL_TSO' for a

"ether+ipv4+udp+vxlan+ether+ipv4+

Quoted 1 line

tcp+payload" packet. But PKT_TX_IPV4 just present the inner

L3

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

type

Quoted 3 lines
Quoted 3 lines

for

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

tunneled packet.

Quoted 1 line

How about the outer L3 type? Always assume the inner and

the

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

outer L3

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

type are the same?

It think that for that case you'll have to set in ol_flags:

PKT_TX_IPV4 | PKT_TX_OUTER_IPV4 |

PKT_TX_TUNNEL_VXLAN |

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

PKT_TX_TCP_SEG

OK, so it means PKT_TX_TCP_SEG is also used for tunneled TSO.

The

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

GSO library doesn't need gso_types anymore.

You still might need gso_ctx.gso_types to let user limit what types

of

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

segmentation
that particular gso_ctx supports.
An alternative would be to assume that each gso_ctx supports all currently implemented segmentations.
This is possible too, but probably not very convenient to the user.

Hmm, make sense.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
Quoted 1 line

One thing to confirm: the value of gso_types should be

DEV_TX_OFFLOAD_*_TSO,

Quoted 5 lines
Quoted 1 line

or new macros?

Hi Jiayu, Konstantin,

I think that the existing macros are fine, as they provide a consistent

view

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

of segmentation capabilities to the application/user.

+1
I also think it is better to re-use DEV_TX_OFFLOAD_*_TSO.

Quoted 8 lines
Quoted 8 lines

There might be an 'issue', if we use 'PKT_TX_TCP_SEG' to tell the GSO library to segment a packet or not. Given the scenario that an application only wants to do GSO and doesn't want to use TSO. The application sets 'mbuf->ol_flags=PKT_TX_TCP_SEG' and doesn't set mbuf->tso_segsz. Then the GSO library segments the packet, and all output GSO segments have the same ol_flags as the input packet (in current GSO library design). Then the output GSO segments are transmitted to rte_eth_tx_prepare(). If the NIC is i40e, its TX prepare

function,

Quoted 1 line
Quoted 1 line

i40e_prep_pkts, checks if mbuf->tso_segsz is in the range of

I40E_MIN_TSO_MSS

Quoted 1 line
Quoted 1 line

and I40E_MAX_TSO_MSS, when PKT_TX_TCP_SEG is set. So an error

happens in

Quoted 3 lines
Quoted 3 lines

this scenario, since tso_segsz is 0.

In fact, it may confuse the PMD driver when set PKT_TX_TCP_SEG but

don't want

Quoted 8 lines
Quoted 1 line
Quoted 1 line

to do TSO. One solution is that the GSO library removes the

PKT_TX_TCP_SEG flag

Quoted 4 lines
Quoted 1 line

for all GSO segments after finishes segmenting.

Yes, that was my thought too: after successful segmentation we probably need to cleanup related ol_flags.

In fact, we just don't need to set these flags in our newly created segments.

+1. PKT_TX_TCP_SEG is not needed, but others, like PKT_TX_IPV4, should be kept, since they may also be used by other HW offloadings, like csum.

Thanks,
Jiayu

Quoted 43 lines
Quoted 10 lines

Konstantin

Quoted 7 lines

Wonder you and Mark's opinion.

Thanks,
Jiayu

Quoted 3 lines
Quoted 3 lines

I was initially concerned that they might be too coarse-grained (i.e.

only

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

IPv4 is currently supported, and not IPv6), but as per Konstantin's

Quoted 1 line

previous example, the DEV_TX_OFFLOAD_*_TSO macros can be used

in

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

concert with the packet type to determine whether a packet should

Quoted 6 lines

be fragmented or not.

Thanks,
Mark

Quoted 1 line
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Jiayu

Quoted 4 lines

Konstantin

Quoted 2 lines

The first choice makes HW and SW segmentation are totally the

same.

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Applications just need to parse the packet and set proper ol_flags,

and

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

the GSO library uses ol_flags to decide which segmentation

function to

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

use.

Quoted 1 line
Quoted 1 line

I think it's better than the second choice which depending on

ptype to

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

choose segmentation function.

Jiayu

Quoted 6 lines

Konstantin

Quoted 3 lines

Jiayu

Quoted 1 line

Konstantin