DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] vhost: Fix packet length issue
@ 2014-10-30  9:00 Ouyang Changchun
  2014-10-30 14:59 ` [dpdk-dev] [PATCH v2] " Ouyang Changchun
  0 siblings, 1 reply; 16+ messages in thread
From: Ouyang Changchun @ 2014-10-30  9:00 UTC (permalink / raw)
  To: dev

As HW vlan strip will reduce the packet length by minus length of vlan tag,
so it need restore the packet length by plus it.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
 examples/vhost/main.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 0566124..dc32fa9 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1067,6 +1067,7 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 {
 	struct mbuf_table *tx_q;
 	struct rte_mbuf **m_table;
+	struct rte_mbuf *last_seg = m;
 	unsigned len, ret, offset = 0;
 	const uint16_t lcore_id = rte_lcore_id();
 	struct virtio_net_data_ll *dev_ll = ll_root_used;
@@ -1097,7 +1098,13 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 					rte_pktmbuf_free(m);
 					return;
 				}
-				offset = 4;
+
+				/*
+				 * HW vlan strip will reduce the packet length
+				 * by minus length of vlan tag, so need restore
+				 * the packet length by plus it.
+				 */
+				offset = VLAN_HLEN;
 				vlan_tag =
 				(uint16_t)
 				vlan_tags[(uint16_t)dev_ll->vdev->dev->device_fh];
@@ -1121,8 +1128,12 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	len = tx_q->len;
 
 	m->ol_flags = PKT_TX_VLAN_PKT;
-	/*FIXME: offset*/
-	m->data_len += offset;
+
+	while (last_seg->next)
+		last_seg = last_seg->next;
+	last_seg->data_len += offset;
+	m->pkt_len += offset;
+
 	m->vlan_tci = vlan_tag;
 
 	tx_q->m_table[len] = m;
-- 
1.8.4.2

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

* [dpdk-dev] [PATCH v2] vhost: Fix packet length issue
  2014-10-30  9:00 [dpdk-dev] [PATCH] vhost: Fix packet length issue Ouyang Changchun
@ 2014-10-30 14:59 ` Ouyang Changchun
  2014-11-04  7:05   ` [dpdk-dev] [PATCH v3 0/2] " Ouyang Changchun
  0 siblings, 1 reply; 16+ messages in thread
From: Ouyang Changchun @ 2014-10-30 14:59 UTC (permalink / raw)
  To: dev

As HW vlan strip will reduce the packet length by minus length of vlan tag,
so it need restore the packet length by plus it.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
v2 change:
 Update data length by plus offset in first segment instead of last segment.

v1 change:
 Update the packet length by plus offset.
 Use macro to replace constant; 

 examples/vhost/main.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 0566124..9ed48fc 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1097,7 +1097,13 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 					rte_pktmbuf_free(m);
 					return;
 				}
-				offset = 4;
+
+				/*
+				 * HW vlan strip will reduce the packet length
+				 * by minus length of vlan tag, so need restore
+				 * the packet length by plus it.
+				 */
+				offset = VLAN_HLEN;
 				vlan_tag =
 				(uint16_t)
 				vlan_tags[(uint16_t)dev_ll->vdev->dev->device_fh];
@@ -1121,8 +1127,10 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	len = tx_q->len;
 
 	m->ol_flags = PKT_TX_VLAN_PKT;
-	/*FIXME: offset*/
+
 	m->data_len += offset;
+	m->pkt_len += offset;
+
 	m->vlan_tci = vlan_tag;
 
 	tx_q->m_table[len] = m;
-- 
1.8.4.2

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

* [dpdk-dev] [PATCH v3 0/2] Fix packet length issue
  2014-10-30 14:59 ` [dpdk-dev] [PATCH v2] " Ouyang Changchun
@ 2014-11-04  7:05   ` Ouyang Changchun
  2014-11-04  7:05     ` [dpdk-dev] [PATCH v3 1/2] vhost: " Ouyang Changchun
                       ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Ouyang Changchun @ 2014-11-04  7:05 UTC (permalink / raw)
  To: dev

This patch set fix packet length issue in vhost app, and enhance code by
extracting a function to replace duplicated codes in one copy and zero copy
TX function.
 
-v3 change:
 Extract a function to replace duplicated codes in one copy and zero copy TX function
 
-v2 change:
 Update data length by plus offset in first segment instead of last segment.
 
-v1 change:
 Update the packet length by plus offset;
 Use macro to replace constant.

Changchun Ouyang (2):
  Fix packet length issue in vhost.
  Extract a function to replace duplicated codes in vhost.

 examples/vhost/main.c | 137 ++++++++++++++++++++++----------------------------
 1 file changed, 61 insertions(+), 76 deletions(-)

-- 
1.8.4.2

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

* [dpdk-dev] [PATCH v3 1/2] vhost: Fix packet length issue
  2014-11-04  7:05   ` [dpdk-dev] [PATCH v3 0/2] " Ouyang Changchun
@ 2014-11-04  7:05     ` Ouyang Changchun
  2014-11-04  7:05     ` [dpdk-dev] [PATCH v3 2/2] vhost: Remove duplicated codes Ouyang Changchun
  2014-11-05  7:10     ` [dpdk-dev] [PATCH v4 0/3] Fix packet length issue Ouyang Changchun
  2 siblings, 0 replies; 16+ messages in thread
From: Ouyang Changchun @ 2014-11-04  7:05 UTC (permalink / raw)
  To: dev

As HW vlan strip will reduce the packet length by minus length of vlan tag,
so it need restore the packet length by plus it.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
 examples/vhost/main.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 57ef464..5ca8dce 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1078,7 +1078,13 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 					rte_pktmbuf_free(m);
 					return;
 				}
-				offset = 4;
+
+				/*
+				 * HW vlan strip will reduce the packet length
+				 * by minus length of vlan tag, so need restore
+				 * the packet length by plus it.
+				 */
+				offset = VLAN_HLEN;
 				vlan_tag =
 				(uint16_t)
 				vlan_tags[(uint16_t)dev_ll->vdev->dev->device_fh];
@@ -1102,8 +1108,10 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	len = tx_q->len;
 
 	m->ol_flags = PKT_TX_VLAN_PKT;
-	/*FIXME: offset*/
+
 	m->data_len += offset;
+	m->pkt_len += offset;
+
 	m->vlan_tci = vlan_tag;
 
 	tx_q->m_table[len] = m;
-- 
1.8.4.2

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

* [dpdk-dev] [PATCH v3 2/2] vhost: Remove duplicated codes
  2014-11-04  7:05   ` [dpdk-dev] [PATCH v3 0/2] " Ouyang Changchun
  2014-11-04  7:05     ` [dpdk-dev] [PATCH v3 1/2] vhost: " Ouyang Changchun
@ 2014-11-04  7:05     ` Ouyang Changchun
  2014-11-05  7:10     ` [dpdk-dev] [PATCH v4 0/3] Fix packet length issue Ouyang Changchun
  2 siblings, 0 replies; 16+ messages in thread
From: Ouyang Changchun @ 2014-11-04  7:05 UTC (permalink / raw)
  To: dev

Extract a function to replace duplicated codes in one copy and zero copy TX function.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
 examples/vhost/main.c | 139 +++++++++++++++++++++-----------------------------
 1 file changed, 58 insertions(+), 81 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 5ca8dce..2916313 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1040,6 +1040,57 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 }
 
 /*
+ * Check if the destination MAC of a packet is one local VM,
+ * and get its vlan tag, and offset if it is.
+ */
+static inline int __attribute__((always_inline))
+find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
+	uint32_t *offset, uint16_t *vlan_tag)
+{
+	struct virtio_net_data_ll *dev_ll = ll_root_used;
+	struct ether_hdr *pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
+
+	while (dev_ll != NULL) {
+		if ((dev_ll->vdev->ready == DEVICE_RX)
+			&& ether_addr_cmp(&(pkt_hdr->d_addr),
+		&dev_ll->vdev->mac_address)) {
+			/*
+			 * Drop the packet if the TX packet is
+			 * destined for the TX device.
+			 */
+			if (dev_ll->vdev->dev->device_fh == dev->device_fh) {
+				LOG_DEBUG(VHOST_DATA,
+				"(%"PRIu64") TX: Source and destination"
+				" MAC addresses are the same. Dropping "
+				"packet.\n",
+				dev_ll->vdev->dev->device_fh);
+				return -1;
+			}
+
+			/*
+			 * HW vlan strip will reduce the packet length
+			 * by minus length of vlan tag, so need restore
+			 * the packet length by plus it.
+			 */
+			*offset = VLAN_HLEN;
+			*vlan_tag =
+			(uint16_t)
+			vlan_tags[(uint16_t)dev_ll->vdev->dev->device_fh];
+
+			LOG_DEBUG(VHOST_DATA,
+			"(%"PRIu64") TX: pkt to local VM device id:"
+			"(%"PRIu64") vlan tag: %d.\n",
+			dev->device_fh, dev_ll->vdev->dev->device_fh,
+			vlan_tag);
+
+			break;
+		}
+		dev_ll = dev_ll->next;
+	}
+	return 0;
+}
+
+/*
  * This function routes the TX packet to the correct interface. This may be a local device
  * or the physical port.
  */
@@ -1050,8 +1101,6 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	struct rte_mbuf **m_table;
 	unsigned len, ret, offset = 0;
 	const uint16_t lcore_id = rte_lcore_id();
-	struct virtio_net_data_ll *dev_ll = ll_root_used;
-	struct ether_hdr *pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 	struct virtio_net *dev = vdev->dev;
 
 	/*check if destination is local VM*/
@@ -1061,43 +1110,9 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	}
 
 	if (vm2vm_mode == VM2VM_HARDWARE) {
-		while (dev_ll != NULL) {
-			if ((dev_ll->vdev->ready == DEVICE_RX)
-				&& ether_addr_cmp(&(pkt_hdr->d_addr),
-				&dev_ll->vdev->mac_address)) {
-				/*
-				 * Drop the packet if the TX packet is
-				 * destined for the TX device.
-				 */
-				if (dev_ll->vdev->dev->device_fh == dev->device_fh) {
-					LOG_DEBUG(VHOST_DATA,
-					"(%"PRIu64") TX: Source and destination"
-					" MAC addresses are the same. Dropping "
-					"packet.\n",
-					dev_ll->vdev->dev->device_fh);
-					rte_pktmbuf_free(m);
-					return;
-				}
-
-				/*
-				 * HW vlan strip will reduce the packet length
-				 * by minus length of vlan tag, so need restore
-				 * the packet length by plus it.
-				 */
-				offset = VLAN_HLEN;
-				vlan_tag =
-				(uint16_t)
-				vlan_tags[(uint16_t)dev_ll->vdev->dev->device_fh];
-
-				LOG_DEBUG(VHOST_DATA,
-				"(%"PRIu64") TX: pkt to local VM device id:"
-				"(%"PRIu64") vlan tag: %d.\n",
-				dev->device_fh, dev_ll->vdev->dev->device_fh,
-				vlan_tag);
-
-				break;
-			}
-			dev_ll = dev_ll->next;
+		if (find_local_dest(dev, m, &offset, &vlan_tag) != 0) {
+			rte_pktmbuf_free(m);
+			return;
 		}
 	}
 
@@ -1726,8 +1741,6 @@ virtio_tx_route_zcp(struct virtio_net *dev, struct rte_mbuf *m,
 	struct rte_mbuf *mbuf = NULL;
 	unsigned len, ret, offset = 0;
 	struct vpool *vpool;
-	struct virtio_net_data_ll *dev_ll = ll_root_used;
-	struct ether_hdr *pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 	uint16_t vlan_tag = (uint16_t)vlan_tags[(uint16_t)dev->device_fh];
 	uint16_t vmdq_rx_q = ((struct vhost_dev *)dev->priv)->vmdq_rx_q;
 
@@ -1756,46 +1769,10 @@ virtio_tx_route_zcp(struct virtio_net *dev, struct rte_mbuf *m,
 		 * such a ambiguous situation, so pkt will lost.
 		 */
 		vlan_tag = external_pkt_default_vlan_tag;
-		while (dev_ll != NULL) {
-			if (likely(dev_ll->vdev->ready == DEVICE_RX) &&
-				ether_addr_cmp(&(pkt_hdr->d_addr),
-				&dev_ll->vdev->mac_address)) {
-
-				/*
-				 * Drop the packet if the TX packet is destined
-				 * for the TX device.
-				 */
-				if (unlikely(dev_ll->vdev->dev->device_fh
-					== dev->device_fh)) {
-					LOG_DEBUG(VHOST_DATA,
-					"(%"PRIu64") TX: Source and destination"
-					"MAC addresses are the same. Dropping "
-					"packet.\n",
-					dev_ll->vdev->dev->device_fh);
-					MBUF_HEADROOM_UINT32(mbuf)
-						= (uint32_t)desc_idx;
-					__rte_mbuf_raw_free(mbuf);
-					return;
-				}
-
-				/*
-				 * Packet length offset 4 bytes for HW vlan
-				 * strip when L2 switch back.
-				 */
-				offset = 4;
-				vlan_tag =
-				(uint16_t)
-				vlan_tags[(uint16_t)dev_ll->vdev->dev->device_fh];
-
-				LOG_DEBUG(VHOST_DATA,
-				"(%"PRIu64") TX: pkt to local VM device id:"
-				"(%"PRIu64") vlan tag: %d.\n",
-				dev->device_fh, dev_ll->vdev->dev->device_fh,
-				vlan_tag);
-
-				break;
-			}
-			dev_ll = dev_ll->next;
+		if (find_local_dest(dev, m, &offset, &vlan_tag) != 0) {
+			MBUF_HEADROOM_UINT32(mbuf) = (uint32_t)desc_idx;
+			__rte_mbuf_raw_free(mbuf);
+			return;
 		}
 	}
 
-- 
1.8.4.2

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

* [dpdk-dev] [PATCH v4 0/3] Fix packet length issue
  2014-11-04  7:05   ` [dpdk-dev] [PATCH v3 0/2] " Ouyang Changchun
  2014-11-04  7:05     ` [dpdk-dev] [PATCH v3 1/2] vhost: " Ouyang Changchun
  2014-11-04  7:05     ` [dpdk-dev] [PATCH v3 2/2] vhost: Remove duplicated codes Ouyang Changchun
@ 2014-11-05  7:10     ` Ouyang Changchun
  2014-11-05  7:10       ` [dpdk-dev] [PATCH v4 1/3] vhost: " Ouyang Changchun
                         ` (3 more replies)
  2 siblings, 4 replies; 16+ messages in thread
From: Ouyang Changchun @ 2014-11-05  7:10 UTC (permalink / raw)
  To: dev

This patch set fix packet length issue in vhost app, and enhance code by
extracting a function to replace duplicated codes in one copy and zero copy
TX function.

-v4 chang:
 Check offset value and extra bytes inside packet buffer cross page boundary.
 
-v3 change:
 Extract a function to replace duplicated codes in one copy and zero copy TX function.
 
-v2 change:
 Update data length by plus offset in first segment instead of last segment.
 
-v1 change:
 Update the packet length by plus offset;
 Use macro to replace constant.

Changchun Ouyang (3):
  Fix packet length issue in vhost.
  Extract a function to replace duplicated codes in vhost.
  Check offset value in vhost

 examples/vhost/main.c | 142 +++++++++++++++++++++++---------------------------
 1 file changed, 65 insertions(+), 77 deletions(-)

-- 
1.8.4.2

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

* [dpdk-dev] [PATCH v4 1/3] vhost: Fix packet length issue
  2014-11-05  7:10     ` [dpdk-dev] [PATCH v4 0/3] Fix packet length issue Ouyang Changchun
@ 2014-11-05  7:10       ` Ouyang Changchun
  2014-11-05 16:46         ` Xie, Huawei
  2014-11-05  7:10       ` [dpdk-dev] [PATCH v4 2/3] vhost: Remove duplicated codes Ouyang Changchun
                         ` (2 subsequent siblings)
  3 siblings, 1 reply; 16+ messages in thread
From: Ouyang Changchun @ 2014-11-05  7:10 UTC (permalink / raw)
  To: dev

As HW vlan strip will reduce the packet length by minus length of vlan tag,
so it need restore the packet length by plus it.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
 examples/vhost/main.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 57ef464..5ca8dce 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1078,7 +1078,13 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 					rte_pktmbuf_free(m);
 					return;
 				}
-				offset = 4;
+
+				/*
+				 * HW vlan strip will reduce the packet length
+				 * by minus length of vlan tag, so need restore
+				 * the packet length by plus it.
+				 */
+				offset = VLAN_HLEN;
 				vlan_tag =
 				(uint16_t)
 				vlan_tags[(uint16_t)dev_ll->vdev->dev->device_fh];
@@ -1102,8 +1108,10 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	len = tx_q->len;
 
 	m->ol_flags = PKT_TX_VLAN_PKT;
-	/*FIXME: offset*/
+
 	m->data_len += offset;
+	m->pkt_len += offset;
+
 	m->vlan_tci = vlan_tag;
 
 	tx_q->m_table[len] = m;
-- 
1.8.4.2

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

* [dpdk-dev] [PATCH v4 2/3] vhost: Remove duplicated codes
  2014-11-05  7:10     ` [dpdk-dev] [PATCH v4 0/3] Fix packet length issue Ouyang Changchun
  2014-11-05  7:10       ` [dpdk-dev] [PATCH v4 1/3] vhost: " Ouyang Changchun
@ 2014-11-05  7:10       ` Ouyang Changchun
  2014-11-05  7:10       ` [dpdk-dev] [PATCH v4 3/3] vhost: Check offset value Ouyang Changchun
  2014-11-05  9:28       ` [dpdk-dev] [PATCH v4 0/3] Fix packet length issue Ananyev, Konstantin
  3 siblings, 0 replies; 16+ messages in thread
From: Ouyang Changchun @ 2014-11-05  7:10 UTC (permalink / raw)
  To: dev

Extract a function to replace duplicated codes in one copy and zero copy TX function.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
 examples/vhost/main.c | 139 +++++++++++++++++++++-----------------------------
 1 file changed, 58 insertions(+), 81 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 5ca8dce..2916313 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1040,6 +1040,57 @@ virtio_tx_local(struct vhost_dev *vdev, struct rte_mbuf *m)
 }
 
 /*
+ * Check if the destination MAC of a packet is one local VM,
+ * and get its vlan tag, and offset if it is.
+ */
+static inline int __attribute__((always_inline))
+find_local_dest(struct virtio_net *dev, struct rte_mbuf *m,
+	uint32_t *offset, uint16_t *vlan_tag)
+{
+	struct virtio_net_data_ll *dev_ll = ll_root_used;
+	struct ether_hdr *pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
+
+	while (dev_ll != NULL) {
+		if ((dev_ll->vdev->ready == DEVICE_RX)
+			&& ether_addr_cmp(&(pkt_hdr->d_addr),
+		&dev_ll->vdev->mac_address)) {
+			/*
+			 * Drop the packet if the TX packet is
+			 * destined for the TX device.
+			 */
+			if (dev_ll->vdev->dev->device_fh == dev->device_fh) {
+				LOG_DEBUG(VHOST_DATA,
+				"(%"PRIu64") TX: Source and destination"
+				" MAC addresses are the same. Dropping "
+				"packet.\n",
+				dev_ll->vdev->dev->device_fh);
+				return -1;
+			}
+
+			/*
+			 * HW vlan strip will reduce the packet length
+			 * by minus length of vlan tag, so need restore
+			 * the packet length by plus it.
+			 */
+			*offset = VLAN_HLEN;
+			*vlan_tag =
+			(uint16_t)
+			vlan_tags[(uint16_t)dev_ll->vdev->dev->device_fh];
+
+			LOG_DEBUG(VHOST_DATA,
+			"(%"PRIu64") TX: pkt to local VM device id:"
+			"(%"PRIu64") vlan tag: %d.\n",
+			dev->device_fh, dev_ll->vdev->dev->device_fh,
+			vlan_tag);
+
+			break;
+		}
+		dev_ll = dev_ll->next;
+	}
+	return 0;
+}
+
+/*
  * This function routes the TX packet to the correct interface. This may be a local device
  * or the physical port.
  */
@@ -1050,8 +1101,6 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	struct rte_mbuf **m_table;
 	unsigned len, ret, offset = 0;
 	const uint16_t lcore_id = rte_lcore_id();
-	struct virtio_net_data_ll *dev_ll = ll_root_used;
-	struct ether_hdr *pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 	struct virtio_net *dev = vdev->dev;
 
 	/*check if destination is local VM*/
@@ -1061,43 +1110,9 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	}
 
 	if (vm2vm_mode == VM2VM_HARDWARE) {
-		while (dev_ll != NULL) {
-			if ((dev_ll->vdev->ready == DEVICE_RX)
-				&& ether_addr_cmp(&(pkt_hdr->d_addr),
-				&dev_ll->vdev->mac_address)) {
-				/*
-				 * Drop the packet if the TX packet is
-				 * destined for the TX device.
-				 */
-				if (dev_ll->vdev->dev->device_fh == dev->device_fh) {
-					LOG_DEBUG(VHOST_DATA,
-					"(%"PRIu64") TX: Source and destination"
-					" MAC addresses are the same. Dropping "
-					"packet.\n",
-					dev_ll->vdev->dev->device_fh);
-					rte_pktmbuf_free(m);
-					return;
-				}
-
-				/*
-				 * HW vlan strip will reduce the packet length
-				 * by minus length of vlan tag, so need restore
-				 * the packet length by plus it.
-				 */
-				offset = VLAN_HLEN;
-				vlan_tag =
-				(uint16_t)
-				vlan_tags[(uint16_t)dev_ll->vdev->dev->device_fh];
-
-				LOG_DEBUG(VHOST_DATA,
-				"(%"PRIu64") TX: pkt to local VM device id:"
-				"(%"PRIu64") vlan tag: %d.\n",
-				dev->device_fh, dev_ll->vdev->dev->device_fh,
-				vlan_tag);
-
-				break;
-			}
-			dev_ll = dev_ll->next;
+		if (find_local_dest(dev, m, &offset, &vlan_tag) != 0) {
+			rte_pktmbuf_free(m);
+			return;
 		}
 	}
 
@@ -1726,8 +1741,6 @@ virtio_tx_route_zcp(struct virtio_net *dev, struct rte_mbuf *m,
 	struct rte_mbuf *mbuf = NULL;
 	unsigned len, ret, offset = 0;
 	struct vpool *vpool;
-	struct virtio_net_data_ll *dev_ll = ll_root_used;
-	struct ether_hdr *pkt_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
 	uint16_t vlan_tag = (uint16_t)vlan_tags[(uint16_t)dev->device_fh];
 	uint16_t vmdq_rx_q = ((struct vhost_dev *)dev->priv)->vmdq_rx_q;
 
@@ -1756,46 +1769,10 @@ virtio_tx_route_zcp(struct virtio_net *dev, struct rte_mbuf *m,
 		 * such a ambiguous situation, so pkt will lost.
 		 */
 		vlan_tag = external_pkt_default_vlan_tag;
-		while (dev_ll != NULL) {
-			if (likely(dev_ll->vdev->ready == DEVICE_RX) &&
-				ether_addr_cmp(&(pkt_hdr->d_addr),
-				&dev_ll->vdev->mac_address)) {
-
-				/*
-				 * Drop the packet if the TX packet is destined
-				 * for the TX device.
-				 */
-				if (unlikely(dev_ll->vdev->dev->device_fh
-					== dev->device_fh)) {
-					LOG_DEBUG(VHOST_DATA,
-					"(%"PRIu64") TX: Source and destination"
-					"MAC addresses are the same. Dropping "
-					"packet.\n",
-					dev_ll->vdev->dev->device_fh);
-					MBUF_HEADROOM_UINT32(mbuf)
-						= (uint32_t)desc_idx;
-					__rte_mbuf_raw_free(mbuf);
-					return;
-				}
-
-				/*
-				 * Packet length offset 4 bytes for HW vlan
-				 * strip when L2 switch back.
-				 */
-				offset = 4;
-				vlan_tag =
-				(uint16_t)
-				vlan_tags[(uint16_t)dev_ll->vdev->dev->device_fh];
-
-				LOG_DEBUG(VHOST_DATA,
-				"(%"PRIu64") TX: pkt to local VM device id:"
-				"(%"PRIu64") vlan tag: %d.\n",
-				dev->device_fh, dev_ll->vdev->dev->device_fh,
-				vlan_tag);
-
-				break;
-			}
-			dev_ll = dev_ll->next;
+		if (find_local_dest(dev, m, &offset, &vlan_tag) != 0) {
+			MBUF_HEADROOM_UINT32(mbuf) = (uint32_t)desc_idx;
+			__rte_mbuf_raw_free(mbuf);
+			return;
 		}
 	}
 
-- 
1.8.4.2

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

* [dpdk-dev] [PATCH v4 3/3] vhost: Check offset value
  2014-11-05  7:10     ` [dpdk-dev] [PATCH v4 0/3] Fix packet length issue Ouyang Changchun
  2014-11-05  7:10       ` [dpdk-dev] [PATCH v4 1/3] vhost: " Ouyang Changchun
  2014-11-05  7:10       ` [dpdk-dev] [PATCH v4 2/3] vhost: Remove duplicated codes Ouyang Changchun
@ 2014-11-05  7:10       ` Ouyang Changchun
  2014-11-05 16:52         ` Xie, Huawei
  2014-11-05  9:28       ` [dpdk-dev] [PATCH v4 0/3] Fix packet length issue Ananyev, Konstantin
  3 siblings, 1 reply; 16+ messages in thread
From: Ouyang Changchun @ 2014-11-05  7:10 UTC (permalink / raw)
  To: dev

This patch checks the packet length offset value, and checks if the extra bytes inside buffer
cross page boundary.

Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
---
 examples/vhost/main.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 2916313..a93f7a0 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1110,7 +1110,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct rte_mbuf *m, uint16_t vlan_tag)
 	}
 
 	if (vm2vm_mode == VM2VM_HARDWARE) {
-		if (find_local_dest(dev, m, &offset, &vlan_tag) != 0) {
+		if (find_local_dest(dev, m, &offset, &vlan_tag) != 0 ||
+			offset > rte_pktmbuf_tailroom(m)) {
 			rte_pktmbuf_free(m);
 			return;
 		}
@@ -1896,7 +1897,9 @@ virtio_dev_tx_zcp(struct virtio_net *dev)
 
 		/* Buffer address translation. */
 		buff_addr = gpa_to_vva(dev, desc->addr);
-		phys_addr = gpa_to_hpa(vdev, desc->addr, desc->len, &addr_type);
+		/* Need check extra VLAN_HLEN size for inserting VLAN tag */
+		phys_addr = gpa_to_hpa(vdev, desc->addr, desc->len + VLAN_HLEN,
+			&addr_type);
 
 		if (likely(packet_success < (free_entries - 1)))
 			/* Prefetch descriptor index. */
-- 
1.8.4.2

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

* Re: [dpdk-dev] [PATCH v4 0/3] Fix packet length issue
  2014-11-05  7:10     ` [dpdk-dev] [PATCH v4 0/3] Fix packet length issue Ouyang Changchun
                         ` (2 preceding siblings ...)
  2014-11-05  7:10       ` [dpdk-dev] [PATCH v4 3/3] vhost: Check offset value Ouyang Changchun
@ 2014-11-05  9:28       ` Ananyev, Konstantin
  2014-11-05 22:07         ` Thomas Monjalon
  3 siblings, 1 reply; 16+ messages in thread
From: Ananyev, Konstantin @ 2014-11-05  9:28 UTC (permalink / raw)
  To: Ouyang, Changchun, dev

> From: Ouyang, Changchun
> Sent: Wednesday, November 05, 2014 7:11 AM
> To: dev@dpdk.org
> Cc: Xie, Huawei; Ananyev, Konstantin; Cao, Waterman; Ouyang, Changchun
> Subject: [PATCH v4 0/3] Fix packet length issue
> 
> This patch set fix packet length issue in vhost app, and enhance code by
> extracting a function to replace duplicated codes in one copy and zero copy
> TX function.
> 
> -v4 chang:
>  Check offset value and extra bytes inside packet buffer cross page boundary.
> 
> -v3 change:
>  Extract a function to replace duplicated codes in one copy and zero copy TX function.
> 
> -v2 change:
>  Update data length by plus offset in first segment instead of last segment.
> 
> -v1 change:
>  Update the packet length by plus offset;
>  Use macro to replace constant.
> 
> Changchun Ouyang (3):
>   Fix packet length issue in vhost.
>   Extract a function to replace duplicated codes in vhost.
>   Check offset value in vhost
> 
>  examples/vhost/main.c | 142 +++++++++++++++++++++++---------------------------
>  1 file changed, 65 insertions(+), 77 deletions(-)
> 
> --
> 1.8.4.2

Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

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

* Re: [dpdk-dev] [PATCH v4 1/3] vhost: Fix packet length issue
  2014-11-05  7:10       ` [dpdk-dev] [PATCH v4 1/3] vhost: " Ouyang Changchun
@ 2014-11-05 16:46         ` Xie, Huawei
  0 siblings, 0 replies; 16+ messages in thread
From: Xie, Huawei @ 2014-11-05 16:46 UTC (permalink / raw)
  To: Ouyang, Changchun, dev

> -----Original Message-----
> From: Ouyang, Changchun
> Sent: Wednesday, November 05, 2014 12:11 AM
> To: dev@dpdk.org
> Cc: Xie, Huawei; Ananyev, Konstantin; Cao, Waterman; Ouyang, Changchun
> Subject: [PATCH v4 1/3] vhost: Fix packet length issue
> 
> As HW vlan strip will reduce the packet length by minus length of vlan tag,
> so it need restore the packet length by plus it.
> 
> Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
> ---
>  examples/vhost/main.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/examples/vhost/main.c b/examples/vhost/main.c
> index 57ef464..5ca8dce 100644
> --- a/examples/vhost/main.c
> +++ b/examples/vhost/main.c
> @@ -1078,7 +1078,13 @@ virtio_tx_route(struct vhost_dev *vdev, struct
> rte_mbuf *m, uint16_t vlan_tag)
>  					rte_pktmbuf_free(m);
>  					return;
>  				}
> -				offset = 4;
> +
> +				/*
> +				 * HW vlan strip will reduce the packet length
> +				 * by minus length of vlan tag, so need restore
> +				 * the packet length by plus it.
> +				 */
> +				offset = VLAN_HLEN;
>  				vlan_tag =
>  				(uint16_t)
>  				vlan_tags[(uint16_t)dev_ll->vdev->dev-
> >device_fh];
> @@ -1102,8 +1108,10 @@ virtio_tx_route(struct vhost_dev *vdev, struct
> rte_mbuf *m, uint16_t vlan_tag)
>  	len = tx_q->len;
> 
>  	m->ol_flags = PKT_TX_VLAN_PKT;
> -	/*FIXME: offset*/
> +
>  	m->data_len += offset;
> +	m->pkt_len += offset;
> +
>  	m->vlan_tci = vlan_tag;
> 
>  	tx_q->m_table[len] = m;
> --
> 1.8.4.2
Only one thing, I feel "by minus/plus" has grammar problem. :).
Acked-by: Huawei Xie <huawei.xie@intel.com>.

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

* Re: [dpdk-dev] [PATCH v4 3/3] vhost: Check offset value
  2014-11-05  7:10       ` [dpdk-dev] [PATCH v4 3/3] vhost: Check offset value Ouyang Changchun
@ 2014-11-05 16:52         ` Xie, Huawei
  2014-11-05 17:00           ` Thomas Monjalon
  0 siblings, 1 reply; 16+ messages in thread
From: Xie, Huawei @ 2014-11-05 16:52 UTC (permalink / raw)
  To: Ouyang, Changchun, dev



> -----Original Message-----
> From: Ouyang, Changchun
> Sent: Wednesday, November 05, 2014 12:11 AM
> To: dev@dpdk.org
> Cc: Xie, Huawei; Ananyev, Konstantin; Cao, Waterman; Ouyang, Changchun
> Subject: [PATCH v4 3/3] vhost: Check offset value
> 
> This patch checks the packet length offset value, and checks if the extra bytes
> inside buffer
> cross page boundary.
> 
> Signed-off-by: Changchun Ouyang <changchun.ouyang@intel.com>
> ---
>  examples/vhost/main.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/examples/vhost/main.c b/examples/vhost/main.c
> index 2916313..a93f7a0 100644
> --- a/examples/vhost/main.c
> +++ b/examples/vhost/main.c
> @@ -1110,7 +1110,8 @@ virtio_tx_route(struct vhost_dev *vdev, struct
> rte_mbuf *m, uint16_t vlan_tag)
>  	}
> 
>  	if (vm2vm_mode == VM2VM_HARDWARE) {
> -		if (find_local_dest(dev, m, &offset, &vlan_tag) != 0) {
> +		if (find_local_dest(dev, m, &offset, &vlan_tag) != 0 ||
> +			offset > rte_pktmbuf_tailroom(m)) {
>  			rte_pktmbuf_free(m);
>  			return;
>  		}
> @@ -1896,7 +1897,9 @@ virtio_dev_tx_zcp(struct virtio_net *dev)
> 
>  		/* Buffer address translation. */
>  		buff_addr = gpa_to_vva(dev, desc->addr);
> -		phys_addr = gpa_to_hpa(vdev, desc->addr, desc->len,
> &addr_type);
> +		/* Need check extra VLAN_HLEN size for inserting VLAN tag */
> +		phys_addr = gpa_to_hpa(vdev, desc->addr, desc->len +
> VLAN_HLEN,
> +			&addr_type);
> 
>  		if (likely(packet_success < (free_entries - 1)))
>  			/* Prefetch descriptor index. */
> --
> 1.8.4.2
Why don't we merge 1,2,3 patches?

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

* Re: [dpdk-dev] [PATCH v4 3/3] vhost: Check offset value
  2014-11-05 16:52         ` Xie, Huawei
@ 2014-11-05 17:00           ` Thomas Monjalon
  2014-11-05 17:05             ` Xie, Huawei
  2014-11-06  0:44             ` Ouyang, Changchun
  0 siblings, 2 replies; 16+ messages in thread
From: Thomas Monjalon @ 2014-11-05 17:00 UTC (permalink / raw)
  To: Xie, Huawei; +Cc: dev

2014-11-05 16:52, Xie, Huawei:
> Why don't we merge 1,2,3 patches?

Because it's simpler to understand small patches with a dedicated
explanation in the commit log of each patch.
Why do you want to merge them?

-- 
Thomas

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

* Re: [dpdk-dev] [PATCH v4 3/3] vhost: Check offset value
  2014-11-05 17:00           ` Thomas Monjalon
@ 2014-11-05 17:05             ` Xie, Huawei
  2014-11-06  0:44             ` Ouyang, Changchun
  1 sibling, 0 replies; 16+ messages in thread
From: Xie, Huawei @ 2014-11-05 17:05 UTC (permalink / raw)
  To: Thomas Monjalon; +Cc: dev



> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> Sent: Wednesday, November 05, 2014 10:01 AM
> To: Xie, Huawei
> Cc: dev@dpdk.org; Ouyang, Changchun
> Subject: Re: [dpdk-dev] [PATCH v4 3/3] vhost: Check offset value
> 
> 2014-11-05 16:52, Xie, Huawei:
> > Why don't we merge 1,2,3 patches?
> 
> Because it's simpler to understand small patches with a dedicated
> explanation in the commit log of each patch.
> Why do you want to merge them?
> 
> --
> Thomas
Got it, so we prefer each patch fixes one dedicated thing.

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

* Re: [dpdk-dev] [PATCH v4 0/3] Fix packet length issue
  2014-11-05  9:28       ` [dpdk-dev] [PATCH v4 0/3] Fix packet length issue Ananyev, Konstantin
@ 2014-11-05 22:07         ` Thomas Monjalon
  0 siblings, 0 replies; 16+ messages in thread
From: Thomas Monjalon @ 2014-11-05 22:07 UTC (permalink / raw)
  To: Ouyang, Changchun; +Cc: dev

> > This patch set fix packet length issue in vhost app, and enhance code by
> > extracting a function to replace duplicated codes in one copy and zero copy
> > TX function.
> > 
> > -v4 chang:
> >  Check offset value and extra bytes inside packet buffer cross page boundary.
> > 
> > -v3 change:
> >  Extract a function to replace duplicated codes in one copy and zero copy TX function.
> > 
> > -v2 change:
> >  Update data length by plus offset in first segment instead of last segment.
> > 
> > -v1 change:
> >  Update the packet length by plus offset;
> >  Use macro to replace constant.
> > 
> > Changchun Ouyang (3):
> >   Fix packet length issue in vhost.
> >   Extract a function to replace duplicated codes in vhost.
> >   Check offset value in vhost
> > 
> >  examples/vhost/main.c | 142 +++++++++++++++++++++++---------------------------
> >  1 file changed, 65 insertions(+), 77 deletions(-)
> > 
> > --
> > 1.8.4.2
> 
> Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>

Applied

Thanks
-- 
Thomas

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

* Re: [dpdk-dev] [PATCH v4 3/3] vhost: Check offset value
  2014-11-05 17:00           ` Thomas Monjalon
  2014-11-05 17:05             ` Xie, Huawei
@ 2014-11-06  0:44             ` Ouyang, Changchun
  1 sibling, 0 replies; 16+ messages in thread
From: Ouyang, Changchun @ 2014-11-06  0:44 UTC (permalink / raw)
  To: Thomas Monjalon, Xie, Huawei; +Cc: dev

Agree with Thomas! using small patches is for easily understanding. 
Merging and mixing things together is not a good thing.

Changchun

> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> Sent: Thursday, November 6, 2014 1:01 AM
> To: Xie, Huawei
> Cc: dev@dpdk.org; Ouyang, Changchun
> Subject: Re: [dpdk-dev] [PATCH v4 3/3] vhost: Check offset value
> 
> 2014-11-05 16:52, Xie, Huawei:
> > Why don't we merge 1,2,3 patches?
> 
> Because it's simpler to understand small patches with a dedicated
> explanation in the commit log of each patch.
> Why do you want to merge them?
> 
> --
> Thomas

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

end of thread, other threads:[~2014-11-06  0:37 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-30  9:00 [dpdk-dev] [PATCH] vhost: Fix packet length issue Ouyang Changchun
2014-10-30 14:59 ` [dpdk-dev] [PATCH v2] " Ouyang Changchun
2014-11-04  7:05   ` [dpdk-dev] [PATCH v3 0/2] " Ouyang Changchun
2014-11-04  7:05     ` [dpdk-dev] [PATCH v3 1/2] vhost: " Ouyang Changchun
2014-11-04  7:05     ` [dpdk-dev] [PATCH v3 2/2] vhost: Remove duplicated codes Ouyang Changchun
2014-11-05  7:10     ` [dpdk-dev] [PATCH v4 0/3] Fix packet length issue Ouyang Changchun
2014-11-05  7:10       ` [dpdk-dev] [PATCH v4 1/3] vhost: " Ouyang Changchun
2014-11-05 16:46         ` Xie, Huawei
2014-11-05  7:10       ` [dpdk-dev] [PATCH v4 2/3] vhost: Remove duplicated codes Ouyang Changchun
2014-11-05  7:10       ` [dpdk-dev] [PATCH v4 3/3] vhost: Check offset value Ouyang Changchun
2014-11-05 16:52         ` Xie, Huawei
2014-11-05 17:00           ` Thomas Monjalon
2014-11-05 17:05             ` Xie, Huawei
2014-11-06  0:44             ` Ouyang, Changchun
2014-11-05  9:28       ` [dpdk-dev] [PATCH v4 0/3] Fix packet length issue Ananyev, Konstantin
2014-11-05 22:07         ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).