Skip to contentSkip to conversation

vhost: Fix packet length issue

PATCH Superseded Ouyang Changchun 4 participants 16 messages Oct 30, 2014 – Nov 6, 2014 8 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 examples/vhost/main.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
examples/vhost/main.c +14 -3
index 0566124..dc32fa9 100644
@@ -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;
Signature · 1 line
1.8.4.2
#2 lore raw

PATCH v2 1/1 vhost: Fix packet length issue

In reply to a message not in the archive

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.

---
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(-)
examples/vhost/main.c +10 -2
index 0566124..9ed48fc 100644
@@ -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;
Signature · 1 line
1.8.4.2
#4 lore raw

v3 cover Fix packet length issue

In reply to a message not in the archive

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(-)
Signature · 1 line
1.8.4.2
#6 lore raw

PATCH v3 1/2 vhost: Fix packet length issue

In reply to a message not in the archive

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.

---
 examples/vhost/main.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
examples/vhost/main.c +10 -2
index 57ef464..5ca8dce 100644
@@ -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;
Signature · 1 line
1.8.4.2
#7 lore raw

PATCH v3 2/2 vhost: Remove duplicated codes

In reply to a message not in the archive

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

---
 examples/vhost/main.c | 139 +++++++++++++++++++++-----------------------------
 1 file changed, 58 insertions(+), 81 deletions(-)
examples/vhost/main.c +58 -81
index 5ca8dce..2916313 100644
@@ -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;
 		}
 	}
 
Signature · 1 line
1.8.4.2
#8 lore raw

v4 cover Fix packet length issue

In reply to a message not in the archive

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(-)
Signature · 1 line
1.8.4.2
#10 lore raw

PATCH v4 1/3 vhost: Fix packet length issue

In reply to a message not in the archive

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.

---
 examples/vhost/main.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
examples/vhost/main.c +10 -2
index 57ef464..5ca8dce 100644
@@ -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;
Signature · 1 line
1.8.4.2
#13 lore raw

PATCH v4 2/3 vhost: Remove duplicated codes

In reply to a message not in the archive

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

---
 examples/vhost/main.c | 139 +++++++++++++++++++++-----------------------------
 1 file changed, 58 insertions(+), 81 deletions(-)
examples/vhost/main.c +58 -81
index 5ca8dce..2916313 100644
@@ -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;
 		}
 	}
 
Signature · 1 line
1.8.4.2
#14 lore raw

PATCH v4 3/3 vhost: Check offset value

In reply to a message not in the archive

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

---
 examples/vhost/main.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
examples/vhost/main.c +5 -2
index 2916313..a93f7a0 100644
@@ -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. */
Signature · 1 line
1.8.4.2
#21 lore raw

Re: [PATCH v4 0/3] Fix packet length issue

In reply to a message not in the archive
Quoted 28 lines

From: Ouyang, Changchun
Sent: Wednesday, November 05, 2014 7:11 AM
To: [email protected]
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.

(quoted diff) +0 -4
-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

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

--
1.8.4.2

Acked-by
#12 lore raw
In reply to a message not in the archive
Quoted 48 lines

-----Original Message-----
From: Ouyang, Changchun
Sent: Wednesday, November 05, 2014 12:11 AM
To: [email protected]
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.

---
 examples/vhost/main.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
examples/vhost/main.c +7 -1
index 57ef464..5ca8dce 100644
@@ -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-

Quoted 1 line

device_fh];

examples/vhost/main.c +3 -1
@@ -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;
 
Quoted 3 lines

tx_q->m_table[len] = m;
--
1.8.4.2

Only one thing, I feel "by minus/plus" has grammar problem. :).

#16 lore raw

Re: [PATCH v4 3/3] vhost: Check offset value

In reply to a message not in the archive
Quoted 47 lines

-----Original Message-----
From: Ouyang, Changchun
Sent: Wednesday, November 05, 2014 12:11 AM
To: [email protected]
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.

---
 examples/vhost/main.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
examples/vhost/main.c +2 -1
index 2916313..a93f7a0 100644
@@ -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;
examples/vhost/main.c +3 -1
 		}
@@ -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);
 
examples/vhost/main.c +0 -1
 		if (likely(packet_success < (free_entries - 1)))
 			/* Prefetch descriptor index. */
--
Quoted 1 line

1.8.4.2

Why don't we merge 1,2,3 patches?

#18 lore raw

Re: [PATCH v4 3/3] vhost: Check offset value

In reply to a message not in the archive

2014-11-05 16:52, Xie, Huawei:

Quoted 1 line

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?

Signature · 1 line
Thomas
#19 lore raw

Re: [PATCH v4 3/3] vhost: Check offset value

Quoted 10 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, November 05, 2014 10:01 AM
To: Xie, Huawei
Cc: [email protected]; Ouyang, Changchun
Subject: Re: [dpdk-dev] [PATCH v4 3/3] vhost: Check offset value

2014-11-05 16:52, Xie, Huawei:

Quoted 8 lines
Quoted 1 line

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.

#23 lore raw

Re: [PATCH v4 0/3] Fix packet length issue

In reply to a message not in the archive
Quoted 22 lines
Quoted 22 lines

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.

(quoted diff) +0 -4
-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

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

--
1.8.4.2

Applied

Thanks

Signature · 1 line
Thomas
#20 lore raw

Re: [PATCH v4 3/3] vhost: Check offset value

In reply to Thomas Monjalon

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

Changchun

Quoted 16 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Thursday, November 6, 2014 1:01 AM
To: Xie, Huawei
Cc: [email protected]; Ouyang, Changchun
Subject: Re: [dpdk-dev] [PATCH v4 3/3] vhost: Check offset value

2014-11-05 16:52, Xie, Huawei:

Quoted 1 line

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