All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/4] add virtio offload support in us-vhost
@ 2015-11-12 12:07 Jijiang Liu
  2015-11-12 12:07 ` [PATCH v5 1/4] vhost/lib: add vhost TX offload capabilities in vhost lib Jijiang Liu
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Jijiang Liu @ 2015-11-12 12:07 UTC (permalink / raw)
  To: dev

Adds virtio offload support in us-vhost.
 
The patch set adds the feature negotiation of checksum and TSO between us-vhost and vanilla Linux virtio guest, and add these offload features support in the vhost lib, and change vhost sample to test them.

v5 changes:
  Add more clear descriptions to explain these changes.
  reset the 'virtio_net_hdr' value in the virtio_enqueue_offload() function.
  reorganize patches. 
  
 
v4 change:
  remove virtio-net change, only keep vhost changes.
  add guest TX offload capabilities to support VM to VM case.
  split the cleanup code as a separate patch.
 
v3 change:
  rebase latest codes.
 
v2 change:
  fill virtio device information for TX offloads.

*** BLURB HERE ***

Jijiang Liu (4):
  add vhost offload capabilities
  remove ipv4_hdr structure from vhost sample.
  add guest offload setting ln the vhost lib.
  change vhost application to test checksum and TSO for VM to NIC case

 examples/vhost/main.c         |  120 ++++++++++++++++++++++++++++-----
 lib/librte_vhost/vhost_rxtx.c |  150 ++++++++++++++++++++++++++++++++++++++++-
 lib/librte_vhost/virtio-net.c |    9 ++-
 3 files changed, 259 insertions(+), 20 deletions(-)

-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v5 1/4] vhost/lib: add vhost TX offload capabilities in vhost lib
  2015-11-12 12:07 [PATCH v5 0/4] add virtio offload support in us-vhost Jijiang Liu
@ 2015-11-12 12:07 ` Jijiang Liu
  2015-11-13  7:01   ` Yuanhan Liu
  2015-11-12 12:07 ` [PATCH v5 2/4] vhost/lib: add guest offload setting Jijiang Liu
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 10+ messages in thread
From: Jijiang Liu @ 2015-11-12 12:07 UTC (permalink / raw)
  To: dev

Add vhost TX offload(CSUM and TSO) support capabilities in vhost lib.

Refer to feature bits in Virtual I/O Device (VIRTIO) Version 1.0 below,

VIRTIO_NET_F_CSUM (0) Device handles packets with partial checksum. This "checksum offload" is a common feature on modern network cards.
VIRTIO_NET_F_HOST_TSO4 (11) Device can receive TSOv4.
VIRTIO_NET_F_HOST_TSO6 (12) Device can receive TSOv6.

In order to support these features, and the following changes are added,

1. Extend 'VHOST_SUPPORTED_FEATURES' macro to add the offload features negotiation.

2. Dequeue TX offload: convert the fileds in virtio_net_hdr to the related fileds in mbuf.


Signed-off-by: Jijiang Liu <jijiang.liu@intel.com>
---
 lib/librte_vhost/vhost_rxtx.c |  103 +++++++++++++++++++++++++++++++++++++++++
 lib/librte_vhost/virtio-net.c |    6 ++-
 2 files changed, 108 insertions(+), 1 deletions(-)

diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 9322ce6..47d5f85 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -37,7 +37,12 @@
 
 #include <rte_mbuf.h>
 #include <rte_memcpy.h>
+#include <rte_ether.h>
+#include <rte_ip.h>
 #include <rte_virtio_net.h>
+#include <rte_tcp.h>
+#include <rte_udp.h>
+#include <rte_sctp.h>
 
 #include "vhost-net.h"
 
@@ -568,6 +573,97 @@ rte_vhost_enqueue_burst(struct virtio_net *dev, uint16_t queue_id,
 		return virtio_dev_rx(dev, queue_id, pkts, count);
 }
 
+static void
+parse_ethernet(struct rte_mbuf *m, uint16_t *l4_proto, void **l4_hdr)
+{
+	struct ipv4_hdr *ipv4_hdr;
+	struct ipv6_hdr *ipv6_hdr;
+	void *l3_hdr = NULL;
+	struct ether_hdr *eth_hdr;
+	uint16_t ethertype;
+
+	eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
+
+	m->l2_len = sizeof(struct ether_hdr);
+	ethertype = rte_be_to_cpu_16(eth_hdr->ether_type);
+
+	if (ethertype == ETHER_TYPE_VLAN) {
+		struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
+
+		m->l2_len += sizeof(struct vlan_hdr);
+		ethertype = rte_be_to_cpu_16(vlan_hdr->eth_proto);
+	}
+
+	l3_hdr = (char *)eth_hdr + m->l2_len;
+
+	switch (ethertype) {
+	case ETHER_TYPE_IPv4:
+		ipv4_hdr = (struct ipv4_hdr *)l3_hdr;
+		*l4_proto = ipv4_hdr->next_proto_id;
+		m->l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4;
+		*l4_hdr = (char *)l3_hdr + m->l3_len;
+		m->ol_flags |= PKT_TX_IPV4;
+		break;
+	case ETHER_TYPE_IPv6:
+		ipv6_hdr = (struct ipv6_hdr *)l3_hdr;
+		*l4_proto = ipv6_hdr->proto;
+		m->l3_len = sizeof(struct ipv6_hdr);
+		*l4_hdr = (char *)l3_hdr + m->l3_len;
+		m->ol_flags |= PKT_TX_IPV6;
+		break;
+	default:
+		m->l3_len = 0;
+		*l4_proto = 0;
+		break;
+	}
+}
+
+static inline void __attribute__((always_inline))
+vhost_dequeue_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *m)
+{
+	uint16_t l4_proto = 0;
+	void *l4_hdr = NULL;
+	struct tcp_hdr *tcp_hdr = NULL;
+
+	parse_ethernet(m, &l4_proto, &l4_hdr);
+	if (hdr->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM) {
+		if (hdr->csum_start == (m->l2_len + m->l3_len)) {
+			switch (hdr->csum_offset) {
+			case (offsetof(struct tcp_hdr, cksum)):
+				if (l4_proto == IPPROTO_TCP)
+					m->ol_flags |= PKT_TX_TCP_CKSUM;
+				break;
+			case (offsetof(struct udp_hdr, dgram_cksum)):
+				if (l4_proto == IPPROTO_UDP)
+					m->ol_flags |= PKT_TX_UDP_CKSUM;
+				break;
+			case (offsetof(struct sctp_hdr, cksum)):
+				if (l4_proto == IPPROTO_SCTP)
+					m->ol_flags |= PKT_TX_SCTP_CKSUM;
+				break;
+			default:
+				break;
+			}
+		}
+	}
+
+	if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
+		switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
+		case VIRTIO_NET_HDR_GSO_TCPV4:
+		case VIRTIO_NET_HDR_GSO_TCPV6:
+			tcp_hdr = (struct tcp_hdr *)l4_hdr;
+			m->ol_flags |= PKT_TX_TCP_SEG;
+			m->tso_segsz = hdr->gso_size;
+			m->l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
+			break;
+		default:
+			RTE_LOG(WARNING, VHOST_DATA,
+				"unsupported gso type %u.\n", hdr->gso_type);
+			break;
+		}
+	}
+}
+
 uint16_t
 rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	struct rte_mempool *mbuf_pool, struct rte_mbuf **pkts, uint16_t count)
@@ -576,11 +672,13 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 	struct vhost_virtqueue *vq;
 	struct vring_desc *desc;
 	uint64_t vb_addr = 0;
+	uint64_t vb_net_hdr_addr = 0;
 	uint32_t head[MAX_PKT_BURST];
 	uint32_t used_idx;
 	uint32_t i;
 	uint16_t free_entries, entry_success = 0;
 	uint16_t avail_idx;
+	struct virtio_net_hdr *hdr = NULL;
 
 	if (unlikely(!is_valid_virt_queue_idx(queue_id, 1, dev->virt_qp_nb))) {
 		RTE_LOG(ERR, VHOST_DATA,
@@ -632,6 +730,9 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 
 		desc = &vq->desc[head[entry_success]];
 
+		vb_net_hdr_addr = gpa_to_vva(dev, desc->addr);
+		hdr = (struct virtio_net_hdr *)((uintptr_t)vb_net_hdr_addr);
+
 		/* Discard first buffer as it is the virtio header */
 		if (desc->flags & VRING_DESC_F_NEXT) {
 			desc = &vq->desc[desc->next];
@@ -770,6 +871,8 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 			break;
 
 		m->nb_segs = seg_num;
+		if ((hdr->flags != 0) || (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE))
+			vhost_dequeue_offload(hdr, m);
 
 		pkts[entry_success] = m;
 		vq->last_used_idx++;
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 14278de..81bd309 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -77,7 +77,11 @@ static struct virtio_net_config_ll *ll_root;
 				(VHOST_SUPPORTS_MQ)            | \
 				(1ULL << VIRTIO_F_VERSION_1)   | \
 				(1ULL << VHOST_F_LOG_ALL)      | \
-				(1ULL << VHOST_USER_F_PROTOCOL_FEATURES))
+				(1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \
+				(1ULL << VIRTIO_NET_F_HOST_TSO4) | \
+				(1ULL << VIRTIO_NET_F_HOST_TSO6) | \
+				(1ULL << VIRTIO_NET_F_CSUM))
+
 static uint64_t VHOST_FEATURES = VHOST_SUPPORTED_FEATURES;
 
 
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v5 2/4] vhost/lib: add guest offload setting
  2015-11-12 12:07 [PATCH v5 0/4] add virtio offload support in us-vhost Jijiang Liu
  2015-11-12 12:07 ` [PATCH v5 1/4] vhost/lib: add vhost TX offload capabilities in vhost lib Jijiang Liu
@ 2015-11-12 12:07 ` Jijiang Liu
  2015-11-12 12:07 ` [PATCH v5 3/4] sample/vhost: remove the ipv4_hdr structure defination Jijiang Liu
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Jijiang Liu @ 2015-11-12 12:07 UTC (permalink / raw)
  To: dev

Add guest offload setting in vhost lib.

Refer to the feature bits description in the Virtual I/O Device (VIRTIO) Version 1.0 below, 

1. VIRTIO_NET_F_GUEST_CSUM (1) Driver handles packets with partial checksum.

2. If the VIRTIO_NET_F_GUEST_CSUM feature was negotiated, the VIRTIO_NET_HDR_F_NEEDS_- CSUM bit in flags MAY be set: if so, the checksum on the packet is incomplete and csum_start and csum_offset indicate how to calculate it (see Packet Transmission point 1).

3. If the VIRTIO_NET_F_GUEST_TSO4, TSO6 or UFO options were negotiated, then gso_type MAY be something other than VIRTIO_NET_HDR_GSO_NONE, and gso_size field indicates the desired MSS (see Packet Transmission point 2).

In order to support these features, the following changes are added,
 
1. Extend 'VHOST_SUPPORTED_FEATURES' macro to add the offload features negotiation.
 
2. Enqueue these offloads: convert some fields in mbuf to the fields in virtio_net_hdr.

There are more explanations for the implementation.

For VM2VM case, there is no need to do checksum, for we
think the data should be reliable enough, and setting VIRTIO_NET_HDR_F_NEEDS_CSUM
at RX side will let the TCP layer to bypass the checksum validation,
so that the RX side could receive the packet in the end.

In terms of us-vhost, at vhost RX side, the offload information is inherited from mbuf, which is
in turn inherited from TX side. If we can still get those info at RX
side, it means the packet is from another VM at same host.  So, it's
safe to set the VIRTIO_NET_HDR_F_NEEDS_CSUM, to skip checksum validation.

Signed-off-by: Jijiang Liu <jijiang.liu@intel.com>
---
 lib/librte_vhost/vhost_rxtx.c |   47 +++++++++++++++++++++++++++++++++++++++-
 lib/librte_vhost/virtio-net.c |    5 +++-
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/lib/librte_vhost/vhost_rxtx.c b/lib/librte_vhost/vhost_rxtx.c
index 47d5f85..9d97e19 100644
--- a/lib/librte_vhost/vhost_rxtx.c
+++ b/lib/librte_vhost/vhost_rxtx.c
@@ -54,6 +54,44 @@ is_valid_virt_queue_idx(uint32_t idx, int is_tx, uint32_t qp_nb)
 	return (is_tx ^ (idx & 1)) == 0 && idx < qp_nb * VIRTIO_QNUM;
 }
 
+static void
+virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)
+{
+	memset(net_hdr, 0, sizeof(struct virtio_net_hdr));
+
+	if (m_buf->ol_flags & PKT_TX_L4_MASK) {
+		net_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
+		net_hdr->csum_start = m_buf->l2_len + m_buf->l3_len;
+
+		switch (m_buf->ol_flags & PKT_TX_L4_MASK) {
+		case PKT_TX_TCP_CKSUM:
+			net_hdr->csum_offset = (offsetof(struct tcp_hdr,
+						cksum));
+			break;
+		case PKT_TX_UDP_CKSUM:
+			net_hdr->csum_offset = (offsetof(struct udp_hdr,
+						dgram_cksum));
+			break;
+		case PKT_TX_SCTP_CKSUM:
+			net_hdr->csum_offset = (offsetof(struct sctp_hdr,
+						cksum));
+			break;
+		}
+	}
+
+	if (m_buf->ol_flags & PKT_TX_TCP_SEG) {
+		if (m_buf->ol_flags & PKT_TX_IPV4)
+			net_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
+		else
+			net_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
+		net_hdr->gso_size = m_buf->tso_segsz;
+		net_hdr->hdr_len = m_buf->l2_len + m_buf->l3_len
+					+ m_buf->l4_len;
+	}
+
+	return;
+}
+
 /**
  * This function adds buffers to the virtio devices RX virtqueue. Buffers can
  * be received from the physical port or from another virtio device. A packet
@@ -67,7 +105,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 {
 	struct vhost_virtqueue *vq;
 	struct vring_desc *desc;
-	struct rte_mbuf *buff;
+	struct rte_mbuf *buff, *first_buff;
 	/* The virtio_hdr is initialised to 0. */
 	struct virtio_net_hdr_mrg_rxbuf virtio_hdr = {{0, 0, 0, 0, 0, 0}, 0};
 	uint64_t buff_addr = 0;
@@ -139,6 +177,7 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 		desc = &vq->desc[head[packet_success]];
 
 		buff = pkts[packet_success];
+		first_buff = buff;
 
 		/* Convert from gpa to vva (guest physical addr -> vhost virtual addr) */
 		buff_addr = gpa_to_vva(dev, desc->addr);
@@ -221,7 +260,9 @@ virtio_dev_rx(struct virtio_net *dev, uint16_t queue_id,
 
 		if (unlikely(uncompleted_pkt == 1))
 			continue;
-
+		
+		virtio_enqueue_offload(first_buff, &virtio_hdr.hdr);
+		
 		rte_memcpy((void *)(uintptr_t)buff_hdr_addr,
 			(const void *)&virtio_hdr, vq->vhost_hlen);
 
@@ -295,6 +336,8 @@ copy_from_mbuf_to_vring(struct virtio_net *dev, uint32_t queue_id,
 	LOG_DEBUG(VHOST_DATA, "(%"PRIu64") RX: Num merge buffers %d\n",
 		dev->device_fh, virtio_hdr.num_buffers);
 
+	virtio_enqueue_offload(pkt, &virtio_hdr.hdr);	
+
 	rte_memcpy((void *)(uintptr_t)vb_hdr_addr,
 		(const void *)&virtio_hdr, vq->vhost_hlen);
 
diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
index 81bd309..839a333 100644
--- a/lib/librte_vhost/virtio-net.c
+++ b/lib/librte_vhost/virtio-net.c
@@ -80,7 +80,10 @@ static struct virtio_net_config_ll *ll_root;
 				(1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \
 				(1ULL << VIRTIO_NET_F_HOST_TSO4) | \
 				(1ULL << VIRTIO_NET_F_HOST_TSO6) | \
-				(1ULL << VIRTIO_NET_F_CSUM))
+				(1ULL << VIRTIO_NET_F_CSUM)    | \
+				(1ULL << VIRTIO_NET_F_GUEST_CSUM) | \
+				(1ULL << VIRTIO_NET_F_GUEST_TSO4) | \
+				(1ULL << VIRTIO_NET_F_GUEST_TSO6))
 
 static uint64_t VHOST_FEATURES = VHOST_SUPPORTED_FEATURES;
 
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v5 3/4] sample/vhost: remove the ipv4_hdr structure defination
  2015-11-12 12:07 [PATCH v5 0/4] add virtio offload support in us-vhost Jijiang Liu
  2015-11-12 12:07 ` [PATCH v5 1/4] vhost/lib: add vhost TX offload capabilities in vhost lib Jijiang Liu
  2015-11-12 12:07 ` [PATCH v5 2/4] vhost/lib: add guest offload setting Jijiang Liu
@ 2015-11-12 12:07 ` Jijiang Liu
  2015-11-12 12:07 ` [PATCH v5 4/4] example/vhost: add virtio offload test in vhost sample Jijiang Liu
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Jijiang Liu @ 2015-11-12 12:07 UTC (permalink / raw)
  To: dev

Remove the ipv4_hdr structure defination in vhost sample.

The same structure has already defined in the rte_ip.h file, so we remove the defination from the sample, and include that header file.

Signed-off-by: Jijiang Liu <jijiang.liu@intel.com>
---
 examples/vhost/main.c |   15 +--------------
 1 files changed, 1 insertions(+), 14 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index c081b18..044c680 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -50,6 +50,7 @@
 #include <rte_string_fns.h>
 #include <rte_malloc.h>
 #include <rte_virtio_net.h>
+#include <rte_ip.h>
 
 #include "main.h"
 
@@ -292,20 +293,6 @@ struct vlan_ethhdr {
 	__be16          h_vlan_encapsulated_proto;
 };
 
-/* IPv4 Header */
-struct ipv4_hdr {
-	uint8_t  version_ihl;		/**< version and header length */
-	uint8_t  type_of_service;	/**< type of service */
-	uint16_t total_length;		/**< length of packet */
-	uint16_t packet_id;		/**< packet ID */
-	uint16_t fragment_offset;	/**< fragmentation offset */
-	uint8_t  time_to_live;		/**< time to live */
-	uint8_t  next_proto_id;		/**< protocol ID */
-	uint16_t hdr_checksum;		/**< header checksum */
-	uint32_t src_addr;		/**< source address */
-	uint32_t dst_addr;		/**< destination address */
-} __attribute__((__packed__));
-
 /* Header lengths. */
 #define VLAN_HLEN       4
 #define VLAN_ETH_HLEN   18
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v5 4/4] example/vhost: add virtio offload test in vhost sample
  2015-11-12 12:07 [PATCH v5 0/4] add virtio offload support in us-vhost Jijiang Liu
                   ` (2 preceding siblings ...)
  2015-11-12 12:07 ` [PATCH v5 3/4] sample/vhost: remove the ipv4_hdr structure defination Jijiang Liu
@ 2015-11-12 12:07 ` Jijiang Liu
  2015-11-13  6:43 ` [PATCH v5 0/4] add virtio offload support in us-vhost Yuanhan Liu
  2015-11-13  7:35 ` Xu, Qian Q
  5 siblings, 0 replies; 10+ messages in thread
From: Jijiang Liu @ 2015-11-12 12:07 UTC (permalink / raw)
  To: dev

Change the codes in vhost sample to test virtio offload feature.

These changes include,

1. add two test options: tx-csum and tso.

2. add virtio_tx_offload() function to test vhost TX offload feature for VM to NIC case; 
however, for VM to VM case, it doesn't need to call this function, the reason is explained in patch 2.
  
Signed-off-by: Jijiang Liu <jijiang.liu@intel.com>
---
 examples/vhost/main.c |  105 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 102 insertions(+), 3 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 044c680..210e631 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -51,6 +51,9 @@
 #include <rte_malloc.h>
 #include <rte_virtio_net.h>
 #include <rte_ip.h>
+#include <rte_tcp.h>
+#include <rte_udp.h>
+#include <rte_sctp.h>
 
 #include "main.h"
 
@@ -198,6 +201,13 @@ typedef enum {
 static uint32_t enable_stats = 0;
 /* Enable retries on RX. */
 static uint32_t enable_retry = 1;
+
+/* Disable TX checksum offload */
+static uint32_t enable_tx_csum;
+
+/* Disable TSO offload */
+static uint32_t enable_tso;
+
 /* Specify timeout (in useconds) between retries on RX. */
 static uint32_t burst_rx_delay_time = BURST_RX_WAIT_US;
 /* Specify the number of retries on RX. */
@@ -428,6 +438,14 @@ port_init(uint8_t port)
 
 	if (port >= rte_eth_dev_count()) return -1;
 
+	if (enable_tx_csum == 0)
+		rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_CSUM);
+
+	if (enable_tso == 0) {
+		rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_HOST_TSO4);
+		rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_HOST_TSO6);
+	}
+
 	rx_rings = (uint16_t)dev_info.max_rx_queues;
 	/* Configure ethernet device. */
 	retval = rte_eth_dev_configure(port, rx_rings, tx_rings, &port_conf);
@@ -563,7 +581,9 @@ us_vhost_usage(const char *prgname)
 	"		--rx-desc-num [0-N]: the number of descriptors on rx, "
 			"used only when zero copy is enabled.\n"
 	"		--tx-desc-num [0-N]: the number of descriptors on tx, "
-			"used only when zero copy is enabled.\n",
+			"used only when zero copy is enabled.\n"
+	"		--tx-csum [0|1] disable/enable TX checksum offload.\n"
+	"		--tso [0|1] disable/enable TCP segement offload.\n",
 	       prgname);
 }
 
@@ -589,6 +609,8 @@ us_vhost_parse_args(int argc, char **argv)
 		{"zero-copy", required_argument, NULL, 0},
 		{"rx-desc-num", required_argument, NULL, 0},
 		{"tx-desc-num", required_argument, NULL, 0},
+		{"tx-csum", required_argument, NULL, 0},
+		{"tso", required_argument, NULL, 0},
 		{NULL, 0, 0, 0},
 	};
 
@@ -643,6 +665,28 @@ us_vhost_parse_args(int argc, char **argv)
 				}
 			}
 
+			/* Enable/disable TX checksum offload. */
+			if (!strncmp(long_option[option_index].name, "tx-csum", MAX_LONG_OPT_SZ)) {
+				ret = parse_num_opt(optarg, 1);
+				if (ret == -1) {
+					RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for tx-csum [0|1]\n");
+					us_vhost_usage(prgname);
+					return -1;
+				} else
+					enable_tx_csum = ret;
+			}
+
+			/* Enable/disable TSO offload. */
+			if (!strncmp(long_option[option_index].name, "tso", MAX_LONG_OPT_SZ)) {
+				ret = parse_num_opt(optarg, 1);
+				if (ret == -1) {
+					RTE_LOG(INFO, VHOST_CONFIG, "Invalid argument for tso [0|1]\n");
+					us_vhost_usage(prgname);
+					return -1;
+				} else
+					enable_tso = ret;
+			}
+
 			/* Specify the retries delay time (in useconds) on RX. */
 			if (!strncmp(long_option[option_index].name, "rx-retry-delay", MAX_LONG_OPT_SZ)) {
 				ret = parse_num_opt(optarg, INT32_MAX);
@@ -1101,6 +1145,58 @@ find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
 	return 0;
 }
 
+static uint16_t
+get_psd_sum(void *l3_hdr, uint64_t ol_flags)
+{
+	if (ol_flags & PKT_TX_IPV4)
+		return rte_ipv4_phdr_cksum(l3_hdr, ol_flags);
+	else /* assume ethertype == ETHER_TYPE_IPv6 */
+		return rte_ipv6_phdr_cksum(l3_hdr, ol_flags);
+}
+
+static void virtio_tx_offload(struct rte_mbuf *m)
+{
+	void *l3_hdr;
+	struct ipv4_hdr *ipv4_hdr = NULL;
+	struct tcp_hdr *tcp_hdr = NULL;
+	struct udp_hdr *udp_hdr = NULL;
+	struct sctp_hdr *sctp_hdr = NULL;
+	struct ether_hdr *eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
+
+	l3_hdr = (char *)eth_hdr + m->l2_len;
+
+	if (m->tso_segsz != 0) {
+		ipv4_hdr = (struct ipv4_hdr *)l3_hdr;
+		tcp_hdr = (struct tcp_hdr *)((char *)l3_hdr + m->l3_len);
+		m->ol_flags |= PKT_TX_IP_CKSUM;
+		ipv4_hdr->hdr_checksum = 0;
+		tcp_hdr->cksum = get_psd_sum(l3_hdr, m->ol_flags);
+		return;
+	}
+
+	if (m->ol_flags & PKT_TX_L4_MASK) {
+		switch (m->ol_flags & PKT_TX_L4_MASK) {
+		case PKT_TX_TCP_CKSUM:
+			tcp_hdr = (struct tcp_hdr *)
+					((char *)l3_hdr + m->l3_len);
+			tcp_hdr->cksum = get_psd_sum(l3_hdr, m->ol_flags);
+			break;
+		case PKT_TX_UDP_CKSUM:
+			udp_hdr = (struct udp_hdr *)
+					((char *)l3_hdr + m->l3_len);
+			udp_hdr->dgram_cksum = get_psd_sum(l3_hdr, m->ol_flags);
+			break;
+		case PKT_TX_SCTP_CKSUM:
+			sctp_hdr = (struct sctp_hdr *)
+					((char *)l3_hdr + m->l3_len);
+			sctp_hdr->cksum = 0;
+			break;
+		default:
+			break;
+		}
+	}
+}
+
 /*
  * This function routes the TX packet to the correct interface. This may be a local device
  * or the physical port.
@@ -1143,7 +1239,7 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 			(vh->vlan_tci != vlan_tag_be))
 			vh->vlan_tci = vlan_tag_be;
 	} else {
-		m->ol_flags = PKT_TX_VLAN_PKT;
+		m->ol_flags |= PKT_TX_VLAN_PKT;
 
 		/*
 		 * Find the right seg to adjust the data len when offset is
@@ -1167,6 +1263,9 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 		m->vlan_tci = vlan_tag;
 	}
 
+	if ((m->ol_flags & PKT_TX_L4_MASK) || (m->ol_flags & PKT_TX_TCP_SEG))
+		virtio_tx_offload(m);
+
 	tx_q->m_table[len] = m;
 	len++;
 	if (enable_stats) {
@@ -1828,7 +1927,7 @@ virtio_tx_route_zcp(struct virtio_net *dev, struct rte_mbuf *m,
 		mbuf->buf_physaddr = m->buf_physaddr;
 		mbuf->buf_addr = m->buf_addr;
 	}
-	mbuf->ol_flags = PKT_TX_VLAN_PKT;
+	mbuf->ol_flags |= PKT_TX_VLAN_PKT;
 	mbuf->vlan_tci = vlan_tag;
 	mbuf->l2_len = sizeof(struct ether_hdr);
 	mbuf->l3_len = sizeof(struct ipv4_hdr);
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 0/4] add virtio offload support in us-vhost
  2015-11-12 12:07 [PATCH v5 0/4] add virtio offload support in us-vhost Jijiang Liu
                   ` (3 preceding siblings ...)
  2015-11-12 12:07 ` [PATCH v5 4/4] example/vhost: add virtio offload test in vhost sample Jijiang Liu
@ 2015-11-13  6:43 ` Yuanhan Liu
  2015-11-13  7:35 ` Xu, Qian Q
  5 siblings, 0 replies; 10+ messages in thread
From: Yuanhan Liu @ 2015-11-13  6:43 UTC (permalink / raw)
  To: Jijiang Liu; +Cc: dev

Series Acked-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>

	--yliu

On Thu, Nov 12, 2015 at 08:07:02PM +0800, Jijiang Liu wrote:
> Adds virtio offload support in us-vhost.
>  
> The patch set adds the feature negotiation of checksum and TSO between us-vhost and vanilla Linux virtio guest, and add these offload features support in the vhost lib, and change vhost sample to test them.
> 
> v5 changes:
>   Add more clear descriptions to explain these changes.
>   reset the 'virtio_net_hdr' value in the virtio_enqueue_offload() function.
>   reorganize patches. 
>   
>  
> v4 change:
>   remove virtio-net change, only keep vhost changes.
>   add guest TX offload capabilities to support VM to VM case.
>   split the cleanup code as a separate patch.
>  
> v3 change:
>   rebase latest codes.
>  
> v2 change:
>   fill virtio device information for TX offloads.
> 
> *** BLURB HERE ***
> 
> Jijiang Liu (4):
>   add vhost offload capabilities
>   remove ipv4_hdr structure from vhost sample.
>   add guest offload setting ln the vhost lib.
>   change vhost application to test checksum and TSO for VM to NIC case
> 
>  examples/vhost/main.c         |  120 ++++++++++++++++++++++++++++-----
>  lib/librte_vhost/vhost_rxtx.c |  150 ++++++++++++++++++++++++++++++++++++++++-
>  lib/librte_vhost/virtio-net.c |    9 ++-
>  3 files changed, 259 insertions(+), 20 deletions(-)
> 
> -- 
> 1.7.7.6

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 1/4] vhost/lib: add vhost TX offload capabilities in vhost lib
  2015-11-12 12:07 ` [PATCH v5 1/4] vhost/lib: add vhost TX offload capabilities in vhost lib Jijiang Liu
@ 2015-11-13  7:01   ` Yuanhan Liu
  2015-11-16  7:56     ` Liu, Jijiang
  0 siblings, 1 reply; 10+ messages in thread
From: Yuanhan Liu @ 2015-11-13  7:01 UTC (permalink / raw)
  To: Jijiang Liu; +Cc: dev

On Thu, Nov 12, 2015 at 08:07:03PM +0800, Jijiang Liu wrote:
> Add vhost TX offload(CSUM and TSO) support capabilities in vhost lib.
> 
> Refer to feature bits in Virtual I/O Device (VIRTIO) Version 1.0 below,
> 
> VIRTIO_NET_F_CSUM (0) Device handles packets with partial checksum. This "checksum offload" is a common feature on modern network cards.
> VIRTIO_NET_F_HOST_TSO4 (11) Device can receive TSOv4.
> VIRTIO_NET_F_HOST_TSO6 (12) Device can receive TSOv6.
> 
> In order to support these features, and the following changes are added,
> 
> 1. Extend 'VHOST_SUPPORTED_FEATURES' macro to add the offload features negotiation.
> 
> 2. Dequeue TX offload: convert the fileds in virtio_net_hdr to the related fileds in mbuf.
> 
> 
> Signed-off-by: Jijiang Liu <jijiang.liu@intel.com>
...
> +static void
> +parse_ethernet(struct rte_mbuf *m, uint16_t *l4_proto, void **l4_hdr)
> +{
> +	struct ipv4_hdr *ipv4_hdr;
> +	struct ipv6_hdr *ipv6_hdr;
> +	void *l3_hdr = NULL;
> +	struct ether_hdr *eth_hdr;
> +	uint16_t ethertype;
> +
> +	eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
> +
> +	m->l2_len = sizeof(struct ether_hdr);
> +	ethertype = rte_be_to_cpu_16(eth_hdr->ether_type);
> +
> +	if (ethertype == ETHER_TYPE_VLAN) {
> +		struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
> +
> +		m->l2_len += sizeof(struct vlan_hdr);
> +		ethertype = rte_be_to_cpu_16(vlan_hdr->eth_proto);
> +	}
> +
> +	l3_hdr = (char *)eth_hdr + m->l2_len;
> +
> +	switch (ethertype) {
> +	case ETHER_TYPE_IPv4:
> +		ipv4_hdr = (struct ipv4_hdr *)l3_hdr;
> +		*l4_proto = ipv4_hdr->next_proto_id;
> +		m->l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4;
> +		*l4_hdr = (char *)l3_hdr + m->l3_len;
> +		m->ol_flags |= PKT_TX_IPV4;
> +		break;
> +	case ETHER_TYPE_IPv6:
> +		ipv6_hdr = (struct ipv6_hdr *)l3_hdr;
> +		*l4_proto = ipv6_hdr->proto;
> +		m->l3_len = sizeof(struct ipv6_hdr);
> +		*l4_hdr = (char *)l3_hdr + m->l3_len;
> +		m->ol_flags |= PKT_TX_IPV6;
> +		break;

Note that I'm still not that satisfied with putting all those kind
of calculation into vhost library.

Every application requesting TSO and CSUM offload features need
setup them, so I'm wondering _if_ we can put them into a libraray,
say lib_ether, and let the application just set few key fields
and left others to that lib.

That could leaves us from touching those chaos, such as TCP and
IP, here and there. And, that, IMO, would be a more elegant way
to leverage hardware TSO and CSUM offload features.

And I guess that might need some efforts and more discussions,
so I'm okay to left that in later versions. (Hence, I gave
my ack).

(I know little about lib_ether and DPDK hardware TSO settings,
so I could be wrong, and sorry for that if so)

	--yliu

> +	default:
> +		m->l3_len = 0;
> +		*l4_proto = 0;
> +		break;
> +	}
> +}
> +
> +static inline void __attribute__((always_inline))
> +vhost_dequeue_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *m)
> +{
> +	uint16_t l4_proto = 0;
> +	void *l4_hdr = NULL;
> +	struct tcp_hdr *tcp_hdr = NULL;
> +
> +	parse_ethernet(m, &l4_proto, &l4_hdr);
> +	if (hdr->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM) {
> +		if (hdr->csum_start == (m->l2_len + m->l3_len)) {
> +			switch (hdr->csum_offset) {
> +			case (offsetof(struct tcp_hdr, cksum)):
> +				if (l4_proto == IPPROTO_TCP)
> +					m->ol_flags |= PKT_TX_TCP_CKSUM;
> +				break;
> +			case (offsetof(struct udp_hdr, dgram_cksum)):
> +				if (l4_proto == IPPROTO_UDP)
> +					m->ol_flags |= PKT_TX_UDP_CKSUM;
> +				break;
> +			case (offsetof(struct sctp_hdr, cksum)):
> +				if (l4_proto == IPPROTO_SCTP)
> +					m->ol_flags |= PKT_TX_SCTP_CKSUM;
> +				break;
> +			default:
> +				break;
> +			}
> +		}
> +	}
> +
> +	if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
> +		switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
> +		case VIRTIO_NET_HDR_GSO_TCPV4:
> +		case VIRTIO_NET_HDR_GSO_TCPV6:
> +			tcp_hdr = (struct tcp_hdr *)l4_hdr;
> +			m->ol_flags |= PKT_TX_TCP_SEG;
> +			m->tso_segsz = hdr->gso_size;
> +			m->l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
> +			break;
> +		default:
> +			RTE_LOG(WARNING, VHOST_DATA,
> +				"unsupported gso type %u.\n", hdr->gso_type);
> +			break;
> +		}
> +	}
> +}

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 0/4] add virtio offload support in us-vhost
  2015-11-12 12:07 [PATCH v5 0/4] add virtio offload support in us-vhost Jijiang Liu
                   ` (4 preceding siblings ...)
  2015-11-13  6:43 ` [PATCH v5 0/4] add virtio offload support in us-vhost Yuanhan Liu
@ 2015-11-13  7:35 ` Xu, Qian Q
  2015-12-18  1:19   ` Liu, Jijiang
  5 siblings, 1 reply; 10+ messages in thread
From: Xu, Qian Q @ 2015-11-13  7:35 UTC (permalink / raw)
  To: Liu, Jijiang, dev

Tested-by: Qian Xu <qian.q.xu@intel.com>

- Test Commit: 6b6a94ee17d246a0078cc83257f522d0a6db5409
- OS/Kernel: Fedora 21/4.1.8
- GCC: gcc (GCC) 4.9.2 20141101 (Red Hat 4.9.2-1)
- CPU: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz
- NIC: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
- Target: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
- Total 2 cases, 2 passed. DPDK vhost + legacy virtio can work well with NIC TSO offload and VM2VM iperf forwards. 

Test Case1: DPDK vhost user + virtio-net one VM fwd tso
=======================================================

HW preparation: Connect 2 ports directly. In our case, connect 81:00.0(port1) and 81:00.1(port2) two ports directly. Port1 is binded to igb_uio for vhost-sample to use, while port2 is in kernel driver. 

SW preparation: Change one line of the vhost sample and rebuild::

    #In function virtio_tx_route(xxx)
    m->vlan_tci = vlan_tag; 
    #changed to 
    m->vlan_tci = 1000;

1. Launch the Vhost sample by below commands, socket-mem is set for the vhost sample to use, need ensure that the PCI port located socket has the memory. In our case, the PCI BDF is 81:00.0, so we need assign memory for socket1. For TSO/CSUM test, we need set "--mergeable 1--tso 1 --csum 1".::

    taskset -c 18-20 ./examples/vhost/build/vhost-switch -c 0x1c0000 -n 4 --huge-dir /mnt/huge --socket-mem 0,2048 -- -p 1 --mergeable 1 --zero-copy 0 --vm2vm 0 --tso 1 --csum 1

2. Launch VM1

    taskset -c 21-22 \
    qemu-system-x86_64 -name us-vhost-vm1 \
     -cpu host -enable-kvm -m 1024 -object memory-backend-file,id=mem,size=1024M,mem-path=/mnt/huge,share=on -numa node,memdev=mem -mem-prealloc \
     -smp cores=2,sockets=1 -drive file=/home/img/dpdk-vm1.img  \
     -chardev socket,id=char0,path=/home/qxu10/vhost-tso-test/dpdk/vhost-net -netdev type=vhost-user,id=mynet1,chardev=char0,vhostforce \
     -device virtio-net-pci,mac=52:54:00:00:00:01,netdev=mynet1,csum=on,gso=on,guest_csum=on,guest_tso4=on,guest_tso6=on,guest_ecn=on  \
     -netdev tap,id=ipvm1,ifname=tap3,script=/etc/qemu-ifup -device rtl8139,netdev=ipvm1,id=net0,mac=00:10:00:00:11:01 -nographic

3. On host,configure port2, then you can see there is a interface called ens260f1.1000.::
   
    ifconfig ens260f1
    vconfig add ens260f1 1000
    ifconfig ens260f1.1000 1.1.1.8

4. On the VM1, set the virtio IP and run iperf

    ifconfig ethX 1.1.1.2
    ping 1.1.1.8 # let virtio and port2 can ping each other successfully, then the arp table will be set up automatically. 
    
5. In host, run : `iperf -s -i 1` ; In guest, run `iperf -c 1.1.1.4 -i 1 -t 60`, check all the tcpdump packet has 65160 length packet. 

6. The iperf performance could be relatively stable at ~9.4Gbits/s. 

Test Case2: DPDK vhost user + virtio-net VM2VM=1 fwd tso
========================================================

HW preparation: No special setup needed. 

1. Launch the Vhost sample by below commands, socket-mem is set for the vhost sample to use, need ensure that the PCI port located socket has the memory. In our case, the PCI BDF is 81:00.0, so we need assign memory for socket1. For TSO/CSUM test, we need set "--mergeable 1--tso 1 --csum 1 --vm2vm 1".::

    taskset -c 18-20 ./examples/vhost/build/vhost-switch -c 0x1c0000 -n 4 --huge-dir /mnt/huge --socket-mem 0,2048 -- -p 1 --mergeable 1 --zero-copy 0 --vm2vm 1 --tso 1 --csum 1

2. Launch VM1 and VM2. ::

    taskset -c 21-22 \
    qemu-system-x86_64 -name us-vhost-vm1 \
     -cpu host -enable-kvm -m 1024 -object memory-backend-file,id=mem,size=1024M,mem-path=/mnt/huge,share=on -numa node,memdev=mem -mem-prealloc \
     -smp cores=2,sockets=1 -drive file=/home/img/dpdk-vm1.img  \
     -chardev socket,id=char0,path=/home/qxu10/vhost-tso-test/dpdk/vhost-net -netdev type=vhost-user,id=mynet1,chardev=char0,vhostforce \
     -device virtio-net-pci,mac=52:54:00:00:00:01,netdev=mynet1,csum=on,gso=on,guest_csum=on,guest_tso4=on,guest_tso6=on,guest_ecn=on  \
     -netdev tap,id=ipvm1,ifname=tap3,script=/etc/qemu-ifup -device rtl8139,netdev=ipvm1,id=net0,mac=00:10:00:00:11:01 -nographic

    taskset -c 23-24 \
    qemu-system-x86_64 -name us-vhost-vm1 \
     -cpu host -enable-kvm -m 1024 -object memory-backend-file,id=mem,size=1024M,mem-path=/mnt/huge,share=on -numa node,memdev=mem -mem-prealloc \
     -smp cores=2,sockets=1 -drive file=/home/img/vm1.img  \
     -chardev socket,id=char1,path=/home/qxu10/vhost-tso-test/dpdk/vhost-net -netdev type=vhost-user,id=mynet2,chardev=char1,vhostforce \
     -device virtio-net-pci,mac=52:54:00:00:00:02,netdev=mynet2  \
     -netdev tap,id=ipvm1,ifname=tap4,script=/etc/qemu-ifup -device rtl8139,netdev=ipvm1,id=net0,mac=00:10:00:00:11:02 -nographic

3. On VM1, set the virtio IP and run iperf

    ifconfig ethX 1.1.1.2
    arp -s 1.1.1.8 52:54:00:00:00:02
    arp # to check the arp table is complete and correct. 

4. On VM2, set the virtio IP and run iperf

    ifconfig ethX 1.1.1.8
    arp -s 1.1.1.2 52:54:00:00:00:01
    arp # to check the arp table is complete and correct. 
 
5. Ensure virtio1 can ping virtio2. Then in VM1, run : `iperf -s -i 1` ; In VM2, run `iperf -c 1.1.1.4 -i 1 -t 60`, check all the tcpdump packet has 65160 length packet.

Thanks
Qian


-----Original Message-----
From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Jijiang Liu
Sent: Thursday, November 12, 2015 8:07 PM
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v5 0/4] add virtio offload support in us-vhost

Adds virtio offload support in us-vhost.
 
The patch set adds the feature negotiation of checksum and TSO between us-vhost and vanilla Linux virtio guest, and add these offload features support in the vhost lib, and change vhost sample to test them.

v5 changes:
  Add more clear descriptions to explain these changes.
  reset the 'virtio_net_hdr' value in the virtio_enqueue_offload() function.
  reorganize patches. 
  
 
v4 change:
  remove virtio-net change, only keep vhost changes.
  add guest TX offload capabilities to support VM to VM case.
  split the cleanup code as a separate patch.
 
v3 change:
  rebase latest codes.
 
v2 change:
  fill virtio device information for TX offloads.

*** BLURB HERE ***

Jijiang Liu (4):
  add vhost offload capabilities
  remove ipv4_hdr structure from vhost sample.
  add guest offload setting ln the vhost lib.
  change vhost application to test checksum and TSO for VM to NIC case

 examples/vhost/main.c         |  120 ++++++++++++++++++++++++++++-----
 lib/librte_vhost/vhost_rxtx.c |  150 ++++++++++++++++++++++++++++++++++++++++-
 lib/librte_vhost/virtio-net.c |    9 ++-
 3 files changed, 259 insertions(+), 20 deletions(-)

-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 1/4] vhost/lib: add vhost TX offload capabilities in vhost lib
  2015-11-13  7:01   ` Yuanhan Liu
@ 2015-11-16  7:56     ` Liu, Jijiang
  0 siblings, 0 replies; 10+ messages in thread
From: Liu, Jijiang @ 2015-11-16  7:56 UTC (permalink / raw)
  To: 'Yuanhan Liu'; +Cc: dev

Hi Yunhan,

> -----Original Message-----
> From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com]
> Sent: Friday, November 13, 2015 3:02 PM
> To: Liu, Jijiang
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v5 1/4] vhost/lib: add vhost TX offload
> capabilities in vhost lib
> 
> On Thu, Nov 12, 2015 at 08:07:03PM +0800, Jijiang Liu wrote:
> > Add vhost TX offload(CSUM and TSO) support capabilities in vhost lib.
> >
> > Refer to feature bits in Virtual I/O Device (VIRTIO) Version 1.0
> > below,
> >
> > VIRTIO_NET_F_CSUM (0) Device handles packets with partial checksum.
> This "checksum offload" is a common feature on modern network cards.
> > VIRTIO_NET_F_HOST_TSO4 (11) Device can receive TSOv4.
> > VIRTIO_NET_F_HOST_TSO6 (12) Device can receive TSOv6.
> >
> > In order to support these features, and the following changes are
> > added,
> >
> > 1. Extend 'VHOST_SUPPORTED_FEATURES' macro to add the offload
> features negotiation.
> >
> > 2. Dequeue TX offload: convert the fileds in virtio_net_hdr to the related
> fileds in mbuf.
> >
> >
> > Signed-off-by: Jijiang Liu <jijiang.liu@intel.com>
> ...
> > +static void
> > +parse_ethernet(struct rte_mbuf *m, uint16_t *l4_proto, void **l4_hdr)
> > +{
> > +	struct ipv4_hdr *ipv4_hdr;
> > +	struct ipv6_hdr *ipv6_hdr;
> > +	void *l3_hdr = NULL;
> > +	struct ether_hdr *eth_hdr;
> > +	uint16_t ethertype;
> > +
> > +	eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
> > +
> > +	m->l2_len = sizeof(struct ether_hdr);
> > +	ethertype = rte_be_to_cpu_16(eth_hdr->ether_type);
> > +
> > +	if (ethertype == ETHER_TYPE_VLAN) {
> > +		struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
> > +
> > +		m->l2_len += sizeof(struct vlan_hdr);
> > +		ethertype = rte_be_to_cpu_16(vlan_hdr->eth_proto);
> > +	}
> > +
> > +	l3_hdr = (char *)eth_hdr + m->l2_len;
> > +
> > +	switch (ethertype) {
> > +	case ETHER_TYPE_IPv4:
> > +		ipv4_hdr = (struct ipv4_hdr *)l3_hdr;
> > +		*l4_proto = ipv4_hdr->next_proto_id;
> > +		m->l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4;
> > +		*l4_hdr = (char *)l3_hdr + m->l3_len;
> > +		m->ol_flags |= PKT_TX_IPV4;
> > +		break;
> > +	case ETHER_TYPE_IPv6:
> > +		ipv6_hdr = (struct ipv6_hdr *)l3_hdr;
> > +		*l4_proto = ipv6_hdr->proto;
> > +		m->l3_len = sizeof(struct ipv6_hdr);
> > +		*l4_hdr = (char *)l3_hdr + m->l3_len;
> > +		m->ol_flags |= PKT_TX_IPV6;
> > +		break;
> 
> Note that I'm still not that satisfied with putting all those kind of calculation
> into vhost library.
> 
> Every application requesting TSO and CSUM offload features need setup
> them, so I'm wondering _if_ we can put them into a libraray, say lib_ether,
> and let the application just set few key fields and left others to that lib.
> 
> That could leaves us from touching those chaos, such as TCP and IP, here and
> there. And, that, IMO, would be a more elegant way to leverage hardware
> TSO and CSUM offload features.
> 
> And I guess that might need some efforts and more discussions, so I'm okay
> to left that in later versions. (Hence, I gave my ack).
> 
> (I know little about lib_ether and DPDK hardware TSO settings, so I could be
> wrong, and sorry for that if so)

You suggestion is good, I also think we should add some L2/L3 protocols parse into DPDK libs.
as you said, there need more discussions for this, maybe we can do this in the future.

But now, it is necessary to add parse_ethernet() function here to get the essential information.

> 
> 	--yliu
> 
> > +	default:
> > +		m->l3_len = 0;
> > +		*l4_proto = 0;
> > +		break;
> > +	}
> > +}
> > +
> > +static inline void __attribute__((always_inline))
> > +vhost_dequeue_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *m)
> > +{
> > +	uint16_t l4_proto = 0;
> > +	void *l4_hdr = NULL;
> > +	struct tcp_hdr *tcp_hdr = NULL;
> > +
> > +	parse_ethernet(m, &l4_proto, &l4_hdr);
> > +	if (hdr->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM) {
> > +		if (hdr->csum_start == (m->l2_len + m->l3_len)) {
> > +			switch (hdr->csum_offset) {
> > +			case (offsetof(struct tcp_hdr, cksum)):
> > +				if (l4_proto == IPPROTO_TCP)
> > +					m->ol_flags |= PKT_TX_TCP_CKSUM;
> > +				break;
> > +			case (offsetof(struct udp_hdr, dgram_cksum)):
> > +				if (l4_proto == IPPROTO_UDP)
> > +					m->ol_flags |= PKT_TX_UDP_CKSUM;
> > +				break;
> > +			case (offsetof(struct sctp_hdr, cksum)):
> > +				if (l4_proto == IPPROTO_SCTP)
> > +					m->ol_flags |=
> PKT_TX_SCTP_CKSUM;
> > +				break;
> > +			default:
> > +				break;
> > +			}
> > +		}
> > +	}
> > +
> > +	if (hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE) {
> > +		switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) {
> > +		case VIRTIO_NET_HDR_GSO_TCPV4:
> > +		case VIRTIO_NET_HDR_GSO_TCPV6:
> > +			tcp_hdr = (struct tcp_hdr *)l4_hdr;
> > +			m->ol_flags |= PKT_TX_TCP_SEG;
> > +			m->tso_segsz = hdr->gso_size;
> > +			m->l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
> > +			break;
> > +		default:
> > +			RTE_LOG(WARNING, VHOST_DATA,
> > +				"unsupported gso type %u.\n", hdr-
> >gso_type);
> > +			break;
> > +		}
> > +	}
> > +}

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v5 0/4] add virtio offload support in us-vhost
  2015-11-13  7:35 ` Xu, Qian Q
@ 2015-12-18  1:19   ` Liu, Jijiang
  0 siblings, 0 replies; 10+ messages in thread
From: Liu, Jijiang @ 2015-12-18  1:19 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev, Liu, Yuanhan

Hi Thomas,

Any comments on this patch set?

This patch set have been fully reviewed and tested, but it has not applied in DPDK2.2.

Let me know if you still have some concerns, if not, I will rebased it and send a version.

--Jijiang 

> -----Original Message-----
> From: Xu, Qian Q
> Sent: Friday, November 13, 2015 3:36 PM
> To: Liu, Jijiang; dev@dpdk.org
> Cc: Xu, Qian Q
> Subject: RE: [dpdk-dev] [PATCH v5 0/4] add virtio offload support in us-vhost
> 
> Tested-by: Qian Xu <qian.q.xu@intel.com>
> 
> 
> Thanks
> Qian
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Jijiang Liu
> Sent: Thursday, November 12, 2015 8:07 PM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH v5 0/4] add virtio offload support in us-vhost
> 
> Adds virtio offload support in us-vhost.
> 
> The patch set adds the feature negotiation of checksum and TSO between
> us-vhost and vanilla Linux virtio guest, and add these offload features
> support in the vhost lib, and change vhost sample to test them.
> 
> v5 changes:
>   Add more clear descriptions to explain these changes.
>   reset the 'virtio_net_hdr' value in the virtio_enqueue_offload() function.
>   reorganize patches.
> 
> 
> v4 change:
>   remove virtio-net change, only keep vhost changes.
>   add guest TX offload capabilities to support VM to VM case.
>   split the cleanup code as a separate patch.
> 
> v3 change:
>   rebase latest codes.
> 
> v2 change:
>   fill virtio device information for TX offloads.
> 
> *** BLURB HERE ***
> 
> Jijiang Liu (4):
>   add vhost offload capabilities
>   remove ipv4_hdr structure from vhost sample.
>   add guest offload setting ln the vhost lib.
>   change vhost application to test checksum and TSO for VM to NIC case
> 
>  examples/vhost/main.c         |  120 ++++++++++++++++++++++++++++-----
>  lib/librte_vhost/vhost_rxtx.c |  150
> ++++++++++++++++++++++++++++++++++++++++-
>  lib/librte_vhost/virtio-net.c |    9 ++-
>  3 files changed, 259 insertions(+), 20 deletions(-)
> 
> --
> 1.7.7.6

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-12-18  1:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-12 12:07 [PATCH v5 0/4] add virtio offload support in us-vhost Jijiang Liu
2015-11-12 12:07 ` [PATCH v5 1/4] vhost/lib: add vhost TX offload capabilities in vhost lib Jijiang Liu
2015-11-13  7:01   ` Yuanhan Liu
2015-11-16  7:56     ` Liu, Jijiang
2015-11-12 12:07 ` [PATCH v5 2/4] vhost/lib: add guest offload setting Jijiang Liu
2015-11-12 12:07 ` [PATCH v5 3/4] sample/vhost: remove the ipv4_hdr structure defination Jijiang Liu
2015-11-12 12:07 ` [PATCH v5 4/4] example/vhost: add virtio offload test in vhost sample Jijiang Liu
2015-11-13  6:43 ` [PATCH v5 0/4] add virtio offload support in us-vhost Yuanhan Liu
2015-11-13  7:35 ` Xu, Qian Q
2015-12-18  1:19   ` Liu, Jijiang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.