Skip to contentSkip to conversation

net/virtio-user: fix packed ring server mode

PATCH Superseded Xuan Ding 5 participants 14 messages Dec 9, 2019 – Jan 16, 2020 Network drivers

lore
Share & tools
lore

Xuan Ding

author
#0 lore raw

PATCH 1/1 net/virtio-user: fix packed ring server mode

This patch fixes the situation where datapath does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of discriptors directly from the available ring and the used ring during reconnection. Therefore, the datapath can continue.

But for packed ring, when reconnecting to virtio, vhost cannot get the status of discriptors only through the descriptor ring. By resetting Tx and Rx queues, the datapath can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")
---
 drivers/net/virtio/virtio_ethdev.c      | 112 +++++++++++++++++++++++-
 drivers/net/virtio/virtio_ethdev.h      |   3 +
 drivers/net/virtio/virtio_user_ethdev.c |   8 ++
 3 files changed, 121 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +110 -2
index 044eb10a7..c0cb0f23c 100644
@@ -433,6 +433,94 @@ virtio_init_vring(struct virtqueue *vq)
 	virtqueue_disable_intr(vq);
 }
 
+static int
+virtio_user_reset_rx_queues(struct rte_eth_dev *dev, uint16_t queue_idx)
+{
+	uint16_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_RQ_QUEUE_IDX;
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+	struct virtnet_rx *rxvq;
+	struct vq_desc_extra *dxp;
+	unsigned int vq_size;
+	uint16_t desc_idx, i;
+
+	vq_size = VTPCI_OPS(hw)->get_queue_num(hw, vtpci_queue_idx);
+
+	vq->vq_packed.used_wrap_counter = 1;
+	vq->vq_packed.cached_flags = VRING_PACKED_DESC_F_AVAIL;
+	vq->vq_packed.event_flags_shadow = 0;
+	vq->vq_packed.cached_flags |= VRING_DESC_F_WRITE;
+
+	rxvq = &vq->rxq;
+	memset(rxvq->mz->addr, 0, rxvq->mz->len);
+
+	for (desc_idx = 0; desc_idx < vq_size; desc_idx++) {
+		dxp = &vq->vq_descx[desc_idx];
+		if (dxp->cookie != NULL) {
+			rte_pktmbuf_free(dxp->cookie);
+			dxp->cookie = NULL;
+		}
+	}
+
+	virtio_init_vring(vq);
+
+	for (i = 0; i < hw->max_queue_pairs; i++)
+		if (rxvq->mpool != NULL)
+			virtio_dev_rx_queue_setup_finish(dev, i);
+
+	return 0;
+}
+
+static int
+virtio_user_reset_tx_queues(struct rte_eth_dev *dev, uint16_t queue_idx)
+{
+	uint8_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_TQ_QUEUE_IDX;
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+	struct virtnet_tx *txvq;
+	struct vq_desc_extra *dxp;
+	unsigned int vq_size;
+	uint16_t desc_idx;
+
+	vq_size = VTPCI_OPS(hw)->get_queue_num(hw, vtpci_queue_idx);
+
+	vq->vq_packed.used_wrap_counter = 1;
+	vq->vq_packed.cached_flags = VRING_PACKED_DESC_F_AVAIL;
+	vq->vq_packed.event_flags_shadow = 0;
+
+	txvq = &vq->txq;
+	memset(txvq->mz->addr, 0, txvq->mz->len);
+	memset(txvq->virtio_net_hdr_mz->addr, 0,
+		txvq->virtio_net_hdr_mz->len);
+
+	for (desc_idx = 0; desc_idx < vq_size; desc_idx++) {
+		dxp = &vq->vq_descx[desc_idx];
+		if (dxp->cookie != NULL) {
+			rte_pktmbuf_free(dxp->cookie);
+			dxp->cookie = NULL;
+		}
+	}
+
+	virtio_init_vring(vq);
+
+	return 0;
+}
+
+static int
+virtio_user_reset_queues(struct rte_eth_dev *eth_dev)
+{
+	uint16_t i;
+
+	/* Vring reset for each Tx queue and Rx queue. */
+	for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
+		virtio_user_reset_rx_queues(eth_dev, i);
+
+	for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
+		virtio_user_reset_tx_queues(eth_dev, i);
+
+	return 0;
+}
+
 static int
 virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 {
@@ -1913,6 +2001,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 			goto err_vtpci_init;
 	}
 
+	rte_spinlock_init(&hw->state_lock);
+
 	/* reset device and negotiate default features */
 	ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
 	if (ret < 0)
@@ -2155,8 +2245,6 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 			return -EBUSY;
 		}
 
-	rte_spinlock_init(&hw->state_lock);
-
 	hw->use_simple_rx = 1;
 
 	if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER)) {
@@ -2421,6 +2509,26 @@ virtio_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
 	return 0;
 }
 
+int
+virtio_user_reset_device(struct rte_eth_dev *eth_dev, struct virtio_hw *hw)
+{
+	/* Add lock to avoid queue contention. */
+	rte_spinlock_lock(&hw->state_lock);
+	hw->started = 0;
+	/*
+	 * Waitting for datapath to complete before resetting queues.
+	 * 1 ms should be enough for the ongoing Tx/Rx function to finish.
+	 */
+	rte_delay_ms(1);
+
+	virtio_user_reset_queues(eth_dev);
+
+	hw->started = 1;
+	rte_spinlock_unlock(&hw->state_lock);
+
+	return 0;
+}
+
 static int
 virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
drivers/net/virtio/virtio_ethdev.h +3 -0
index a10111758..72e9e3ff8 100644
@@ -49,6 +49,9 @@
 
 extern const struct eth_dev_ops virtio_user_secondary_eth_dev_ops;
 
+int virtio_user_reset_device(struct rte_eth_dev *eth_dev,
+		struct virtio_hw *hw);
+
 /*
  * CQ function prototype
  */
drivers/net/virtio/virtio_user_ethdev.c +8 -0
index 3fc172573..49068a578 100644
@@ -31,6 +31,7 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 	int ret;
 	int connectfd;
 	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
+	struct virtio_hw *hw = eth_dev->data->dev_private;
 
 	connectfd = accept(dev->listenfd, NULL, NULL);
 	if (connectfd < 0)
@@ -51,6 +52,13 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 
 	dev->features &= dev->device_features;
 
+	/*
+	 * * For packed ring, resetting queues
+	 * is required in reconnection.
+	 */
+	if (vtpci_packed_queue(hw))
+		virtio_user_reset_device(eth_dev, hw);
+
 	ret = virtio_user_start_device(dev);
 	if (ret < 0)
 		return -1;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 39 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Xuan Ding
Sent: Tuesday, December 10, 2019 12:50 AM
To: [email protected]
Cc: [email protected]; [email protected]; Bie, Tiwei <[email protected]>; Wang, Zhihong <[email protected]>; Ding, Xuan <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH v1] net/virtio-user: fix packed ring server mode

This patch fixes the situation where datapath does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of discriptors directly from the available ring and the used ring during reconnection. Therefore, the datapath can continue.

But for packed ring, when reconnecting to virtio, vhost cannot get the status of discriptors only through the descriptor ring. By resetting Tx and Rx queues, the datapath can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")
---
 drivers/net/virtio/virtio_ethdev.c      | 112 +++++++++++++++++++++++-
 drivers/net/virtio/virtio_ethdev.h      |   3 +
 drivers/net/virtio/virtio_user_ethdev.c |   8 ++
 3 files changed, 121 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +0 -0
index 044eb10a7..c0cb0f23c 100644

drivers/net/virtio/virtio_ethdev.c virtio_init_vring(struct virtqueue *vq) · line 438

Quoted 6 lines
drivers/net/virtio/virtio_ethdev.c +3 -0
@@ -433,6 +433,94 @@ virtio_init_vring(struct virtqueue *vq)
 	virtqueue_disable_intr(vq);
 }
 
+static int
+virtio_user_reset_rx_queues(struct rte_eth_dev *dev, uint16_t queue_idx)
+{

Hi Xuan,
This function named as virtio_user_reset, but look like it has no relationship with virtio_user. Maybe rename this function to virtqueue_reset and move it to virtqueue.c will be more suitable. Please also add suffix _packed as this function only workable for packed ring.

Thanks,
Marvin

drivers/net/virtio/virtio_ethdev.c virtio_init_vring(struct virtqueue *vq) · line 448

Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +10 -0
+	uint16_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_RQ_QUEUE_IDX;
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+	struct virtnet_rx *rxvq;
+	struct vq_desc_extra *dxp;
+	unsigned int vq_size;
+	uint16_t desc_idx, i;
+
+	vq_size = VTPCI_OPS(hw)->get_queue_num(hw, vtpci_queue_idx);
+

Virtqueue size has been set to vq_nentries in virtqueue structure. Do we need to re-catch it?

Quoted 12 lines
drivers/net/virtio/virtio_ethdev.c +12 -0
+	vq->vq_packed.used_wrap_counter = 1;
+	vq->vq_packed.cached_flags = VRING_PACKED_DESC_F_AVAIL;
+	vq->vq_packed.event_flags_shadow = 0;
+	vq->vq_packed.cached_flags |= VRING_DESC_F_WRITE;
+
+	rxvq = &vq->rxq;
+	memset(rxvq->mz->addr, 0, rxvq->mz->len);
+
+	for (desc_idx = 0; desc_idx < vq_size; desc_idx++) {
+		dxp = &vq->vq_descx[desc_idx];
+		if (dxp->cookie != NULL) {
+			rte_pktmbuf_free(dxp->cookie);

drivers/net/virtio/virtio_ethdev.c virtio_init_vring(struct virtqueue *vq) · line 470

Quoted 10 lines
drivers/net/virtio/virtio_ethdev.c +10 -0
+			dxp->cookie = NULL;
+		}
+	}
+
+	virtio_init_vring(vq);
+
+	for (i = 0; i < hw->max_queue_pairs; i++)
+		if (rxvq->mpool != NULL)
+			virtio_dev_rx_queue_setup_finish(dev, i);
+

Please add parentheses for multiple lines loop content.

Quoted 151 lines
drivers/net/virtio/virtio_ethdev.c +55 -0
+	return 0;
+}
+
+static int
+virtio_user_reset_tx_queues(struct rte_eth_dev *dev, uint16_t queue_idx)
+{
+	uint8_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_TQ_QUEUE_IDX;
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+	struct virtnet_tx *txvq;
+	struct vq_desc_extra *dxp;
+	unsigned int vq_size;
+	uint16_t desc_idx;
+
+	vq_size = VTPCI_OPS(hw)->get_queue_num(hw, vtpci_queue_idx);
+
+	vq->vq_packed.used_wrap_counter = 1;
+	vq->vq_packed.cached_flags = VRING_PACKED_DESC_F_AVAIL;
+	vq->vq_packed.event_flags_shadow = 0;
+
+	txvq = &vq->txq;
+	memset(txvq->mz->addr, 0, txvq->mz->len);
+	memset(txvq->virtio_net_hdr_mz->addr, 0,
+		txvq->virtio_net_hdr_mz->len);
+
+	for (desc_idx = 0; desc_idx < vq_size; desc_idx++) {
+		dxp = &vq->vq_descx[desc_idx];
+		if (dxp->cookie != NULL) {
+			rte_pktmbuf_free(dxp->cookie);
+			dxp->cookie = NULL;
+		}
+	}
+
+	virtio_init_vring(vq);
+
+	return 0;
+}
+
+static int
+virtio_user_reset_queues(struct rte_eth_dev *eth_dev)
+{
+	uint16_t i;
+
+	/* Vring reset for each Tx queue and Rx queue. */
+	for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
+		virtio_user_reset_rx_queues(eth_dev, i);
+
+	for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
+		virtio_user_reset_tx_queues(eth_dev, i);
+
+	return 0;
+}
+
 static int
 virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 {
@@ -1913,6 +2001,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 			goto err_vtpci_init;
 	}
 
+	rte_spinlock_init(&hw->state_lock);
+
 	/* reset device and negotiate default features */
 	ret = virtio_init_device(eth_dev,
 VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
drivers/net/virtio/virtio_ethdev.c +20 -2
 	if (ret < 0)
@@ -2155,8 +2245,6 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 			return -EBUSY;
 		}
 
-	rte_spinlock_init(&hw->state_lock);
-
 	hw->use_simple_rx = 1;
 
 	if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER)) {
@@ -2421,6 +2509,26 @@ virtio_dev_vlan_offload_set(struct rte_eth_dev
 *dev, int mask)
 	return 0;
 }
 
+int
+virtio_user_reset_device(struct rte_eth_dev *eth_dev, struct virtio_hw
 *hw)
+{
+	/* Add lock to avoid queue contention. */
+	rte_spinlock_lock(&hw->state_lock);
+	hw->started = 0;
+	/*
+	 * Waitting for datapath to complete before resetting queues.
+	 * 1 ms should be enough for the ongoing Tx/Rx function to finish.
+	 */
+	rte_delay_ms(1);
+
+	virtio_user_reset_queues(eth_dev);
+
+	hw->started = 1;
+	rte_spinlock_unlock(&hw->state_lock);
+
+	return 0;
+}
+
 static int

virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info
*dev_info)
{

drivers/net/virtio/virtio_ethdev.h +3 -0
index a10111758..72e9e3ff8 100644
@@ -49,6 +49,9 @@
 
 extern const struct eth_dev_ops virtio_user_secondary_eth_dev_ops;
 
+int virtio_user_reset_device(struct rte_eth_dev *eth_dev,
+		struct virtio_hw *hw);
+
 /*
  * CQ function prototype
  */
drivers/net/virtio/virtio_user_ethdev.c +1 -0
index 3fc172573..49068a578 100644
@@ -31,6 +31,7 @@ virtio_user_server_reconnect(struct virtio_user_dev
 *dev)
 	int ret;
 	int connectfd;
 	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
+	struct virtio_hw *hw = eth_dev->data->dev_private;
 
 	connectfd = accept(dev->listenfd, NULL, NULL);
drivers/net/virtio/virtio_user_ethdev.c +7 -0
 	if (connectfd < 0)
@@ -51,6 +52,13 @@ virtio_user_server_reconnect(struct virtio_user_dev
 *dev)
 
 	dev->features &= dev->device_features;
 
+	/*
+	 * * For packed ring, resetting queues
+	 * is required in reconnection.
+	 */
+	if (vtpci_packed_queue(hw))
+		virtio_user_reset_device(eth_dev, hw);
+
 	ret = virtio_user_start_device(dev);
 	if (ret < 0)

return -1;
--
2.17.1

author
#2 lore raw
Quoted 65 lines

-----Original Message-----
From: Liu, Yong <[email protected]>
Sent: Monday, December 9, 2019 4:52 PM
To: Ding, Xuan <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; Bie, Tiwei <[email protected]>; Wang, Zhihong <[email protected]>; Ding, Xuan <[email protected]>; [email protected]
Subject: RE: [dpdk-dev] [PATCH v1] net/virtio-user: fix packed ring server mode

Quoted 10 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Xuan Ding
Sent: Tuesday, December 10, 2019 12:50 AM
To: [email protected]
Cc: [email protected]; [email protected]; Bie, Tiwei <[email protected]>; Wang, Zhihong <[email protected]>; Ding, Xuan <[email protected]>; [email protected]
Subject: [dpdk-dev] [PATCH v1] net/virtio-user: fix packed ring server mode

Quoted 6 lines

This patch fixes the situation where datapath does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of discriptors directly from the available ring and the used ring during reconnection. Therefore, the datapath can

continue.

Quoted 21 lines

But for packed ring, when reconnecting to virtio, vhost cannot get the status of discriptors only through the descriptor ring. By resetting Tx and Rx queues, the datapath can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")
---
 drivers/net/virtio/virtio_ethdev.c      | 112 +++++++++++++++++++++++-
 drivers/net/virtio/virtio_ethdev.h      |   3 +
 drivers/net/virtio/virtio_user_ethdev.c |   8 ++
 3 files changed, 121 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +0 -0
index 044eb10a7..c0cb0f23c 100644

drivers/net/virtio/virtio_ethdev.c virtio_init_vring(struct virtqueue *vq) · line 438

Quoted 6 lines
drivers/net/virtio/virtio_ethdev.c +3 -0
@@ -433,6 +433,94 @@ virtio_init_vring(struct virtqueue *vq)
 	virtqueue_disable_intr(vq);
 }
 
+static int
+virtio_user_reset_rx_queues(struct rte_eth_dev *dev, uint16_t
+queue_idx) {

Hi Xuan,
This function named as virtio_user_reset, but look like it has no relationship with virtio_user.
Maybe rename this function to virtqueue_reset and move it to virtqueue.c will be more suitable.
Please also add suffix _packed as this function only workable for packed ring.

Quoted 3 lines

Thanks,
Marvin

Hi Marvin, this function only works for virtqueue, so move it to virtqueue.c is better.
Two functions' name will be changed to virtqueue_rxvq_reset_packed and virtqueue_txvq_reset_packed, respectively.

Thank you for your suggestion.
Xuan

Quoted 4 lines
Quoted 4 lines
drivers/net/virtio/virtio_ethdev.c +4 -0
+	uint16_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_RQ_QUEUE_IDX;
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+	struct virtnet_rx *rxvq;
Quoted 9 lines

drivers/net/virtio/virtio_ethdev.c virtio_init_vring(struct virtqueue *vq) · line 448

Quoted 6 lines
drivers/net/virtio/virtio_ethdev.c +6 -0
+	struct vq_desc_extra *dxp;
+	unsigned int vq_size;
+	uint16_t desc_idx, i;
+
+	vq_size = VTPCI_OPS(hw)->get_queue_num(hw, vtpci_queue_idx);
+

Virtqueue size has been set to vq_nentries in virtqueue structure. Do we need to re-catch it?

Virtqueue size doesn't need to be re-catched, so vq->vq_nentries will be used instead.

Quoted 16 lines
Quoted 16 lines
drivers/net/virtio/virtio_ethdev.c +16 -0
+	vq->vq_packed.used_wrap_counter = 1;
+	vq->vq_packed.cached_flags = VRING_PACKED_DESC_F_AVAIL;
+	vq->vq_packed.event_flags_shadow = 0;
+	vq->vq_packed.cached_flags |= VRING_DESC_F_WRITE;
+
+	rxvq = &vq->rxq;
+	memset(rxvq->mz->addr, 0, rxvq->mz->len);
+
+	for (desc_idx = 0; desc_idx < vq_size; desc_idx++) {
+		dxp = &vq->vq_descx[desc_idx];
+		if (dxp->cookie != NULL) {
+			rte_pktmbuf_free(dxp->cookie);
+			dxp->cookie = NULL;
+		}
+	}
+
Quoted 8 lines

drivers/net/virtio/virtio_ethdev.c virtio_init_vring(struct virtqueue *vq) · line 470

Quoted 6 lines
drivers/net/virtio/virtio_ethdev.c +6 -0
+	virtio_init_vring(vq);
+
+	for (i = 0; i < hw->max_queue_pairs; i++)
+		if (rxvq->mpool != NULL)
+			virtio_dev_rx_queue_setup_finish(dev, i);
+

Please add parentheses for multiple lines loop content.

Thank you for your notice.

Quoted 152 lines
Quoted 67 lines
drivers/net/virtio/virtio_ethdev.c +52 -0
+	return 0;
+}
+
+static int
+virtio_user_reset_tx_queues(struct rte_eth_dev *dev, uint16_t
+queue_idx) {
+	uint8_t vtpci_queue_idx = 2 * queue_idx + VTNET_SQ_TQ_QUEUE_IDX;
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtqueue *vq = hw->vqs[vtpci_queue_idx];
+	struct virtnet_tx *txvq;
+	struct vq_desc_extra *dxp;
+	unsigned int vq_size;
+	uint16_t desc_idx;
+
+	vq_size = VTPCI_OPS(hw)->get_queue_num(hw, vtpci_queue_idx);
+
+	vq->vq_packed.used_wrap_counter = 1;
+	vq->vq_packed.cached_flags = VRING_PACKED_DESC_F_AVAIL;
+	vq->vq_packed.event_flags_shadow = 0;
+
+	txvq = &vq->txq;
+	memset(txvq->mz->addr, 0, txvq->mz->len);
+	memset(txvq->virtio_net_hdr_mz->addr, 0,
+		txvq->virtio_net_hdr_mz->len);
+
+	for (desc_idx = 0; desc_idx < vq_size; desc_idx++) {
+		dxp = &vq->vq_descx[desc_idx];
+		if (dxp->cookie != NULL) {
+			rte_pktmbuf_free(dxp->cookie);
+			dxp->cookie = NULL;
+		}
+	}
+
+	virtio_init_vring(vq);
+
+	return 0;
+}
+
+static int
+virtio_user_reset_queues(struct rte_eth_dev *eth_dev) {
+	uint16_t i;
+
+	/* Vring reset for each Tx queue and Rx queue. */
+	for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
+		virtio_user_reset_rx_queues(eth_dev, i);
+
+	for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
+		virtio_user_reset_tx_queues(eth_dev, i);
+
+	return 0;
+}
+
 static int
 virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)

{ @@ -1913,6 +2001,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)

drivers/net/virtio/virtio_ethdev.c +2 -0
 			goto err_vtpci_init;
 	}
 
+	rte_spinlock_init(&hw->state_lock);
+
 	/* reset device and negotiate default features */
 	ret = virtio_init_device(eth_dev,

VIRTIO_PMD_DEFAULT_GUEST_FEATURES);

drivers/net/virtio/virtio_ethdev.c +0 -0
 	if (ret < 0)

drivers/net/virtio/virtio_ethdev.c virtio_dev_configure(struct rte_eth_dev *dev) · line 2250

Quoted 8 lines
drivers/net/virtio/virtio_ethdev.c +0 -2
@@ -2155,8 +2245,6 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 			return -EBUSY;
 		}
 
-	rte_spinlock_init(&hw->state_lock);
-
 	hw->use_simple_rx = 1;
 
 	if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER)) { @@ -2421,6

+2509,26

Quoted 76 lines

@@ virtio_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)

drivers/net/virtio/virtio_ethdev.c +3 -0
 	return 0;
 }
 
+int
+virtio_user_reset_device(struct rte_eth_dev *eth_dev, struct
+virtio_hw

*hw)

drivers/net/virtio/virtio_ethdev.c +18 -0
+{
+	/* Add lock to avoid queue contention. */
+	rte_spinlock_lock(&hw->state_lock);
+	hw->started = 0;
+	/*
+	 * Waitting for datapath to complete before resetting queues.
+	 * 1 ms should be enough for the ongoing Tx/Rx function to finish.
+	 */
+	rte_delay_ms(1);
+
+	virtio_user_reset_queues(eth_dev);
+
+	hw->started = 1;
+	rte_spinlock_unlock(&hw->state_lock);
+
+	return 0;
+}
+
 static int
 virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info

*dev_info)
{

drivers/net/virtio/virtio_ethdev.h +3 -0
index a10111758..72e9e3ff8 100644
@@ -49,6 +49,9 @@
 
 extern const struct eth_dev_ops virtio_user_secondary_eth_dev_ops;
 
+int virtio_user_reset_device(struct rte_eth_dev *eth_dev,
+		struct virtio_hw *hw);
+
 /*
  * CQ function prototype
  */
drivers/net/virtio/virtio_user_ethdev.c +1 -0
index 3fc172573..49068a578 100644
@@ -31,6 +31,7 @@ virtio_user_server_reconnect(struct virtio_user_dev
 *dev)
 	int ret;
 	int connectfd;
 	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
+	struct virtio_hw *hw = eth_dev->data->dev_private;
 
 	connectfd = accept(dev->listenfd, NULL, NULL);
drivers/net/virtio/virtio_user_ethdev.c +7 -0
 	if (connectfd < 0)
@@ -51,6 +52,13 @@ virtio_user_server_reconnect(struct virtio_user_dev
 *dev)
 
 	dev->features &= dev->device_features;
 
+	/*
+	 * * For packed ring, resetting queues
+	 * is required in reconnection.
+	 */
+	if (vtpci_packed_queue(hw))
+		virtio_user_reset_device(eth_dev, hw);
+
 	ret = virtio_user_start_device(dev);
 	if (ret < 0)

return -1;
--
2.17.1

author
#3 lore raw

PATCH v3 1/1 net/virtio-user: fix packed ring server mode

In reply to Xuan Ding

This patch fixes the situation where datapath does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of discriptors directly from the available ring and the used ring during reconnection. Therefore, the datapath can continue.

But for packed ring, when reconnecting to virtio, vhost cannot get the status of discriptors only through the descriptor ring. By resetting Tx and Rx queues, the datapath can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")

v3:
* Removed an extra asterisk from a comment.
* Renamed device reset function and moved it to virtio_user_ethdev.c.

v2:
* Renamed queue reset functions and moved them to virtqueue.c.

---
 drivers/net/virtio/virtio_ethdev.c      |  4 +-
 drivers/net/virtio/virtio_user_ethdev.c | 40 ++++++++++++++
 drivers/net/virtio/virtqueue.c          | 71 +++++++++++++++++++++++++
 drivers/net/virtio/virtqueue.h          |  4 ++
 4 files changed, 117 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +2 -2
index 044eb10a7..f9d0ea70d 100644
@@ -1913,6 +1913,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 			goto err_vtpci_init;
 	}
 
+	rte_spinlock_init(&hw->state_lock);
+
 	/* reset device and negotiate default features */
 	ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
 	if (ret < 0)
@@ -2155,8 +2157,6 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 			return -EBUSY;
 		}
 
-	rte_spinlock_init(&hw->state_lock);
-
 	hw->use_simple_rx = 1;
 
 	if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER)) {
drivers/net/virtio/virtio_user_ethdev.c +40 -0
index 3fc172573..425f48230 100644
@@ -25,12 +25,48 @@
 #define virtio_user_get_dev(hw) \
 	((struct virtio_user_dev *)(hw)->virtio_user_dev)
 
+static void
+virtio_user_reset_queues_packed(struct rte_eth_dev *dev)
+{
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtnet_rx *rxvq;
+	struct virtnet_tx *txvq;
+	uint16_t i;
+
+	/* Add lock to avoid queue contention. */
+	rte_spinlock_lock(&hw->state_lock);
+	hw->started = 0;
+
+	/*
+	 * Waitting for datapath to complete before resetting queues.
+	 * 1 ms should be enough for the ongoing Tx/Rx function to finish.
+	 */
+	rte_delay_ms(1);
+
+	/* Vring reset for each Tx queue and Rx queue. */
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		rxvq = dev->data->rx_queues[i];
+		virtqueue_rxvq_reset_packed(rxvq->vq);
+		virtio_dev_rx_queue_setup_finish(dev, i);
+	}
+
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		txvq = dev->data->tx_queues[i];
+		virtqueue_txvq_reset_packed(txvq->vq);
+	}
+
+	hw->started = 1;
+	rte_spinlock_unlock(&hw->state_lock);
+}
+
+
 static int
 virtio_user_server_reconnect(struct virtio_user_dev *dev)
 {
 	int ret;
 	int connectfd;
 	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
+	struct virtio_hw *hw = eth_dev->data->dev_private;
 
 	connectfd = accept(dev->listenfd, NULL, NULL);
 	if (connectfd < 0)
@@ -51,6 +87,10 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 
 	dev->features &= dev->device_features;
 
+	/* For packed ring, resetting queues is required in reconnection. */
+	if (vtpci_packed_queue(hw))
+		virtio_user_reset_queues_packed(eth_dev);
+
 	ret = virtio_user_start_device(dev);
 	if (ret < 0)
 		return -1;
drivers/net/virtio/virtqueue.c +71 -0

74 lines not on this page · raw message

drivers/net/virtio/virtqueue.h +4 -0
index 8d7f197b1..58ad7309a 100644
@@ -443,6 +443,10 @@ struct rte_mbuf *virtqueue_detach_unused(struct virtqueue *vq);
 /* Flush the elements in the used ring. */
 void virtqueue_rxvq_flush(struct virtqueue *vq);
 
+int virtqueue_rxvq_reset_packed(struct virtqueue *vq);
+
+int virtqueue_txvq_reset_packed(struct virtqueue *vq);
+
 static inline int
 virtqueue_full(const struct virtqueue *vq)
 {
Signature · 1 line
2.17.1
#4 lore raw

Hi, Xuan

Quoted 14 lines · Xuan Ding

This patch fixes the situation where datapath does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of discriptors directly from the available ring and the used ring during reconnection. Therefore, the datapath can continue.

But for packed ring, when reconnecting to virtio, vhost cannot get the status of discriptors only through the descriptor ring. By resetting Tx and Rx queues, the datapath can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")
Quoted 8 lines

v3:
* Removed an extra asterisk from a comment.
* Renamed device reset function and moved it to virtio_user_ethdev.c.

v2:
* Renamed queue reset functions and moved them to virtqueue.c.

Please put these change log after below '---' marker, then they won't be shown in commit log when you apply the patch by git am.

Thanks,
Xiaolong

Quoted 190 lines

---

drivers/net/virtio/virtio_ethdev.c      |  4 +-
drivers/net/virtio/virtio_user_ethdev.c | 40 ++++++++++++++
drivers/net/virtio/virtqueue.c          | 71 +++++++++++++++++++++++++
drivers/net/virtio/virtqueue.h          |  4 ++
4 files changed, 117 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +2 -2
index 044eb10a7..f9d0ea70d 100644
@@ -1913,6 +1913,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 			goto err_vtpci_init;
 	}
 
+	rte_spinlock_init(&hw->state_lock);
+
 	/* reset device and negotiate default features */
 	ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
 	if (ret < 0)
@@ -2155,8 +2157,6 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 			return -EBUSY;
 		}
 
-	rte_spinlock_init(&hw->state_lock);
-
 	hw->use_simple_rx = 1;
 
 	if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER)) {
drivers/net/virtio/virtio_user_ethdev.c +35 -0
index 3fc172573..425f48230 100644
@@ -25,12 +25,48 @@
 #define virtio_user_get_dev(hw) \
 	((struct virtio_user_dev *)(hw)->virtio_user_dev)
 
+static void
+virtio_user_reset_queues_packed(struct rte_eth_dev *dev)
+{
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtnet_rx *rxvq;
+	struct virtnet_tx *txvq;
+	uint16_t i;
+
+	/* Add lock to avoid queue contention. */
+	rte_spinlock_lock(&hw->state_lock);
+	hw->started = 0;
+
+	/*
+	 * Waitting for datapath to complete before resetting queues.
+	 * 1 ms should be enough for the ongoing Tx/Rx function to finish.
+	 */
+	rte_delay_ms(1);
+
+	/* Vring reset for each Tx queue and Rx queue. */
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		rxvq = dev->data->rx_queues[i];
+		virtqueue_rxvq_reset_packed(rxvq->vq);
+		virtio_dev_rx_queue_setup_finish(dev, i);
+	}
+
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		txvq = dev->data->tx_queues[i];
+		virtqueue_txvq_reset_packed(txvq->vq);
+	}
+
+	hw->started = 1;
+	rte_spinlock_unlock(&hw->state_lock);
+}
+
+

static int
virtio_user_server_reconnect(struct virtio_user_dev *dev)

{
	int ret;
	int connectfd;
	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
drivers/net/virtio/virtio_user_ethdev.c +1 -0
+	struct virtio_hw *hw = eth_dev->data->dev_private;
	connectfd = accept(dev->listenfd, NULL, NULL);
	if (connectfd < 0)
drivers/net/virtio/virtio_user_ethdev.c +4 -0
@@ -51,6 +87,10 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 
 	dev->features &= dev->device_features;
 
+	/* For packed ring, resetting queues is required in reconnection. */
+	if (vtpci_packed_queue(hw))
+		virtio_user_reset_queues_packed(eth_dev);
+
 	ret = virtio_user_start_device(dev);
 	if (ret < 0)
 		return -1;
drivers/net/virtio/virtqueue.c +71 -0
index 5ff1e3587..0b4e3bf3e 100644
@@ -141,3 +141,74 @@ virtqueue_rxvq_flush(struct virtqueue *vq)
 	else
 		virtqueue_rxvq_flush_split(vq);
 }
+
+int
+virtqueue_rxvq_reset_packed(struct virtqueue *vq)
+{
+	int size = vq->vq_nentries;
+	struct vq_desc_extra *dxp;
+	struct virtnet_rx *rxvq;
+	uint16_t desc_idx;
+
+	vq->vq_used_cons_idx = 0;
+	vq->vq_desc_head_idx = 0;
+	vq->vq_avail_idx = 0;
+	vq->vq_desc_tail_idx = (uint16_t)(vq->vq_nentries - 1);
+	vq->vq_free_cnt = vq->vq_nentries;
+
+	vq->vq_packed.used_wrap_counter = 1;
+	vq->vq_packed.cached_flags = VRING_PACKED_DESC_F_AVAIL;
+	vq->vq_packed.event_flags_shadow = 0;
+	vq->vq_packed.cached_flags |= VRING_DESC_F_WRITE;
+
+	rxvq = &vq->rxq;
+	memset(rxvq->mz->addr, 0, rxvq->mz->len);
+
+	for (desc_idx = 0; desc_idx < vq->vq_nentries; desc_idx++) {
+		dxp = &vq->vq_descx[desc_idx];
+		if (dxp->cookie != NULL) {
+			rte_pktmbuf_free(dxp->cookie);
+			dxp->cookie = NULL;
+		}
+	}
+
+	vring_desc_init_packed(vq, size);
+
+	return 0;
+}
+
+int
+virtqueue_txvq_reset_packed(struct virtqueue *vq)
+{
+	int size = vq->vq_nentries;
+	struct vq_desc_extra *dxp;
+	struct virtnet_tx *txvq;
+	uint16_t desc_idx;
+
+	vq->vq_used_cons_idx = 0;
+	vq->vq_desc_head_idx = 0;
+	vq->vq_avail_idx = 0;
+	vq->vq_desc_tail_idx = (uint16_t)(vq->vq_nentries - 1);
+	vq->vq_free_cnt = vq->vq_nentries;
+
+	vq->vq_packed.used_wrap_counter = 1;
+	vq->vq_packed.cached_flags = VRING_PACKED_DESC_F_AVAIL;
+	vq->vq_packed.event_flags_shadow = 0;
+
+	txvq = &vq->txq;
+	memset(txvq->mz->addr, 0, txvq->mz->len);
+	memset(txvq->virtio_net_hdr_mz->addr, 0,
+		txvq->virtio_net_hdr_mz->len);
+
+	for (desc_idx = 0; desc_idx < vq->vq_nentries; desc_idx++) {
+		dxp = &vq->vq_descx[desc_idx];
+		if (dxp->cookie != NULL) {
+			rte_pktmbuf_free(dxp->cookie);
+			dxp->cookie = NULL;
+		}
+	}
+
+	vring_desc_init_packed(vq, size);
+
+	return 0;
+}
drivers/net/virtio/virtqueue.h +4 -0
index 8d7f197b1..58ad7309a 100644
@@ -443,6 +443,10 @@ struct rte_mbuf *virtqueue_detach_unused(struct virtqueue *vq);
 /* Flush the elements in the used ring. */
 void virtqueue_rxvq_flush(struct virtqueue *vq);
 
+int virtqueue_rxvq_reset_packed(struct virtqueue *vq);
+
+int virtqueue_txvq_reset_packed(struct virtqueue *vq);
+

static inline int
virtqueue_full(const struct virtqueue *vq)
{

Signature · 1 line
2.17.1
author
#5 lore raw
Quoted 35 lines

-----Original Message-----
From: Ye, Xiaolong <[email protected]>
Sent: Wednesday, December 18, 2019 10:25 AM
To: Ding, Xuan <[email protected]>
Cc: [email protected]; Bie, Tiwei <[email protected]>; Wang, Zhihong <[email protected]>; Liu, Yong <[email protected]>; [email protected]; [email protected]
Subject: Re: [dpdk-dev] [PATCH v3] net/virtio-user: fix packed ring server mode

Hi, Xuan

Quoted 6 lines · Xuan Ding

This patch fixes the situation where datapath does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of discriptors directly from the available ring and the used ring during reconnection. Therefore, the datapath can

continue.

Quoted 14 lines

But for packed ring, when reconnecting to virtio, vhost cannot get the status of discriptors only through the descriptor ring. By resetting Tx and Rx queues, the datapath can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")

v3:
* Removed an extra asterisk from a comment.
* Renamed device reset function and moved it to virtio_user_ethdev.c.

Quoted 8 lines
Quoted 2 lines

v2:
* Renamed queue reset functions and moved them to virtqueue.c.

Please put these change log after below '---' marker, then they won't be shown in commit log when you apply the patch by git am.

Thanks,
Xiaolong

Hi, Xiaolong,
Thank you for your advice, I will change it in the next version.

Best regards,
Xuan

Quoted 191 lines
Quoted 14 lines

---

drivers/net/virtio/virtio_ethdev.c      |  4 +-
drivers/net/virtio/virtio_user_ethdev.c | 40 ++++++++++++++
drivers/net/virtio/virtqueue.c          | 71 +++++++++++++++++++++++++
drivers/net/virtio/virtqueue.h          |  4 ++
4 files changed, 117 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +0 -0
index 044eb10a7..f9d0ea70d 100644

drivers/net/virtio/virtio_ethdev.c eth_virtio_dev_init(struct rte_eth_dev *eth_dev) · line 1919

Quoted 7 lines
drivers/net/virtio/virtio_ethdev.c +2 -0
@@ -1913,6 +1913,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 			goto err_vtpci_init;
 	}
 
+	rte_spinlock_init(&hw->state_lock);
+
 	/* reset device and negotiate default features */
 	ret = virtio_init_device(eth_dev,

VIRTIO_PMD_DEFAULT_GUEST_FEATURES);

Quoted 169 lines
drivers/net/virtio/virtio_ethdev.c +0 -2
 	if (ret < 0)
@@ -2155,8 +2157,6 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 			return -EBUSY;
 		}
 
-	rte_spinlock_init(&hw->state_lock);
-
 	hw->use_simple_rx = 1;
 
 	if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER)) { diff --git

a/drivers/net/virtio/virtio_user_ethdev.c
b/drivers/net/virtio/virtio_user_ethdev.c
index 3fc172573..425f48230 100644

drivers/net/virtio/virtio_user_ethdev.c +34 -0
@@ -25,12 +25,48 @@
 #define virtio_user_get_dev(hw) \
 	((struct virtio_user_dev *)(hw)->virtio_user_dev)
 
+static void
+virtio_user_reset_queues_packed(struct rte_eth_dev *dev) {
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtnet_rx *rxvq;
+	struct virtnet_tx *txvq;
+	uint16_t i;
+
+	/* Add lock to avoid queue contention. */
+	rte_spinlock_lock(&hw->state_lock);
+	hw->started = 0;
+
+	/*
+	 * Waitting for datapath to complete before resetting queues.
+	 * 1 ms should be enough for the ongoing Tx/Rx function to finish.
+	 */
+	rte_delay_ms(1);
+
+	/* Vring reset for each Tx queue and Rx queue. */
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		rxvq = dev->data->rx_queues[i];
+		virtqueue_rxvq_reset_packed(rxvq->vq);
+		virtio_dev_rx_queue_setup_finish(dev, i);
+	}
+
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		txvq = dev->data->tx_queues[i];
+		virtqueue_txvq_reset_packed(txvq->vq);
+	}
+
+	hw->started = 1;
+	rte_spinlock_unlock(&hw->state_lock);
+}
+
+

static int

virtio_user_server_reconnect(struct virtio_user_dev *dev) {
	int ret;
	int connectfd;
	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
drivers/net/virtio/virtio_user_ethdev.c +1 -0
+	struct virtio_hw *hw = eth_dev->data->dev_private;
	connectfd = accept(dev->listenfd, NULL, NULL);
	if (connectfd < 0)
drivers/net/virtio/virtio_user_ethdev.c +4 -0
@@ -51,6 +87,10 @@ virtio_user_server_reconnect(struct virtio_user_dev
 *dev)
 
 	dev->features &= dev->device_features;
 
+	/* For packed ring, resetting queues is required in reconnection. */
+	if (vtpci_packed_queue(hw))
+		virtio_user_reset_queues_packed(eth_dev);
+
 	ret = virtio_user_start_device(dev);
 	if (ret < 0)
		return -1;
(quoted diff) +0 -0

b/drivers/net/virtio/virtqueue.c index 5ff1e3587..0b4e3bf3e 100644

drivers/net/virtio/virtqueue.c +69 -0
@@ -141,3 +141,74 @@ virtqueue_rxvq_flush(struct virtqueue *vq)
 	else
 		virtqueue_rxvq_flush_split(vq);
 }
+
+int
+virtqueue_rxvq_reset_packed(struct virtqueue *vq) {
+	int size = vq->vq_nentries;
+	struct vq_desc_extra *dxp;
+	struct virtnet_rx *rxvq;
+	uint16_t desc_idx;
+
+	vq->vq_used_cons_idx = 0;
+	vq->vq_desc_head_idx = 0;
+	vq->vq_avail_idx = 0;
+	vq->vq_desc_tail_idx = (uint16_t)(vq->vq_nentries - 1);
+	vq->vq_free_cnt = vq->vq_nentries;
+
+	vq->vq_packed.used_wrap_counter = 1;
+	vq->vq_packed.cached_flags = VRING_PACKED_DESC_F_AVAIL;
+	vq->vq_packed.event_flags_shadow = 0;
+	vq->vq_packed.cached_flags |= VRING_DESC_F_WRITE;
+
+	rxvq = &vq->rxq;
+	memset(rxvq->mz->addr, 0, rxvq->mz->len);
+
+	for (desc_idx = 0; desc_idx < vq->vq_nentries; desc_idx++) {
+		dxp = &vq->vq_descx[desc_idx];
+		if (dxp->cookie != NULL) {
+			rte_pktmbuf_free(dxp->cookie);
+			dxp->cookie = NULL;
+		}
+	}
+
+	vring_desc_init_packed(vq, size);
+
+	return 0;
+}
+
+int
+virtqueue_txvq_reset_packed(struct virtqueue *vq) {
+	int size = vq->vq_nentries;
+	struct vq_desc_extra *dxp;
+	struct virtnet_tx *txvq;
+	uint16_t desc_idx;
+
+	vq->vq_used_cons_idx = 0;
+	vq->vq_desc_head_idx = 0;
+	vq->vq_avail_idx = 0;
+	vq->vq_desc_tail_idx = (uint16_t)(vq->vq_nentries - 1);
+	vq->vq_free_cnt = vq->vq_nentries;
+
+	vq->vq_packed.used_wrap_counter = 1;
+	vq->vq_packed.cached_flags = VRING_PACKED_DESC_F_AVAIL;
+	vq->vq_packed.event_flags_shadow = 0;
+
+	txvq = &vq->txq;
+	memset(txvq->mz->addr, 0, txvq->mz->len);
+	memset(txvq->virtio_net_hdr_mz->addr, 0,
+		txvq->virtio_net_hdr_mz->len);
+
+	for (desc_idx = 0; desc_idx < vq->vq_nentries; desc_idx++) {
+		dxp = &vq->vq_descx[desc_idx];
+		if (dxp->cookie != NULL) {
+			rte_pktmbuf_free(dxp->cookie);
+			dxp->cookie = NULL;
+		}
+	}
+
+	vring_desc_init_packed(vq, size);
+
+	return 0;
+}
(quoted diff) +0 -0

b/drivers/net/virtio/virtqueue.h index 8d7f197b1..58ad7309a 100644

drivers/net/virtio/virtqueue.h +4 -0
@@ -443,6 +443,10 @@ struct rte_mbuf *virtqueue_detach_unused(struct
 virtqueue *vq);
 /* Flush the elements in the used ring. */  void
 virtqueue_rxvq_flush(struct virtqueue *vq);
 
+int virtqueue_rxvq_reset_packed(struct virtqueue *vq);
+
+int virtqueue_txvq_reset_packed(struct virtqueue *vq);
+

static inline int
virtqueue_full(const struct virtqueue *vq) {
--
2.17.1

author
#6 lore raw

PATCH v4 1/1 net/virtio-user: fix packed ring server mode

In reply to Xuan Ding

This patch fixes the situation where datapath does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of discriptors directly from the available ring and the used ring during reconnection. Therefore, the datapath can continue.

But for packed ring, when reconnecting to virtio, vhost cannot get the status of discriptors only through the descriptor ring. By resetting Tx and Rx queues, the datapath can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")

---

v4:
* Moved change log below '---' marker.

v3:
* Removed an extra asterisk from a comment.
* Renamed device reset function and moved it to virtio_user_ethdev.c.

v2:
* Renamed queue reset functions and moved them to virtqueue.c.

 drivers/net/virtio/virtio_ethdev.c      |  4 +-
 drivers/net/virtio/virtio_user_ethdev.c | 40 ++++++++++++++
 drivers/net/virtio/virtqueue.c          | 71 +++++++++++++++++++++++++
 drivers/net/virtio/virtqueue.h          |  4 ++
 4 files changed, 117 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +2 -2
index 044eb10a7..f9d0ea70d 100644
@@ -1913,6 +1913,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 			goto err_vtpci_init;
 	}
 
+	rte_spinlock_init(&hw->state_lock);
+
 	/* reset device and negotiate default features */
 	ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
 	if (ret < 0)
@@ -2155,8 +2157,6 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 			return -EBUSY;
 		}
 
-	rte_spinlock_init(&hw->state_lock);
-
 	hw->use_simple_rx = 1;
 
 	if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER)) {
drivers/net/virtio/virtio_user_ethdev.c +40 -0
index 3fc172573..425f48230 100644
@@ -25,12 +25,48 @@
 #define virtio_user_get_dev(hw) \
 	((struct virtio_user_dev *)(hw)->virtio_user_dev)
 
+static void
+virtio_user_reset_queues_packed(struct rte_eth_dev *dev)
+{
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtnet_rx *rxvq;
+	struct virtnet_tx *txvq;
+	uint16_t i;
+
+	/* Add lock to avoid queue contention. */
+	rte_spinlock_lock(&hw->state_lock);
+	hw->started = 0;
+
+	/*
+	 * Waitting for datapath to complete before resetting queues.
+	 * 1 ms should be enough for the ongoing Tx/Rx function to finish.
+	 */
+	rte_delay_ms(1);
+
+	/* Vring reset for each Tx queue and Rx queue. */
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		rxvq = dev->data->rx_queues[i];
+		virtqueue_rxvq_reset_packed(rxvq->vq);
+		virtio_dev_rx_queue_setup_finish(dev, i);
+	}
+
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		txvq = dev->data->tx_queues[i];
+		virtqueue_txvq_reset_packed(txvq->vq);
+	}
+
+	hw->started = 1;
+	rte_spinlock_unlock(&hw->state_lock);
+}
+
+
 static int
 virtio_user_server_reconnect(struct virtio_user_dev *dev)
 {
 	int ret;
 	int connectfd;
 	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
+	struct virtio_hw *hw = eth_dev->data->dev_private;
 
 	connectfd = accept(dev->listenfd, NULL, NULL);
 	if (connectfd < 0)
@@ -51,6 +87,10 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 
 	dev->features &= dev->device_features;
 
+	/* For packed ring, resetting queues is required in reconnection. */
+	if (vtpci_packed_queue(hw))
+		virtio_user_reset_queues_packed(eth_dev);
+
 	ret = virtio_user_start_device(dev);
 	if (ret < 0)
 		return -1;
drivers/net/virtio/virtqueue.c +71 -0

74 lines not on this page · raw message

drivers/net/virtio/virtqueue.h +4 -0
index 8d7f197b1..58ad7309a 100644
@@ -443,6 +443,10 @@ struct rte_mbuf *virtqueue_detach_unused(struct virtqueue *vq);
 /* Flush the elements in the used ring. */
 void virtqueue_rxvq_flush(struct virtqueue *vq);
 
+int virtqueue_rxvq_reset_packed(struct virtqueue *vq);
+
+int virtqueue_txvq_reset_packed(struct virtqueue *vq);
+
 static inline int
 virtqueue_full(const struct virtqueue *vq)
 {
Signature · 1 line
2.17.1
#7 lore raw
Quoted 5 lines · Xuan Ding

This patch fixes the situation where datapath does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of discriptors directly from the available ring and

s/discriptors/descriptors/

Quoted 4 lines

the used ring during reconnection. Therefore, the datapath can continue.

But for packed ring, when reconnecting to virtio, vhost cannot get the status of discriptors only through the descriptor ring. By resetting Tx

s/discriptor only through/descriptor via/

Quoted 100 lines

and Rx queues, the datapath can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")

---

v4:
* Moved change log below '---' marker.

v3:
* Removed an extra asterisk from a comment.
* Renamed device reset function and moved it to virtio_user_ethdev.c.

v2:
* Renamed queue reset functions and moved them to virtqueue.c.

 drivers/net/virtio/virtio_ethdev.c      |  4 +-
 drivers/net/virtio/virtio_user_ethdev.c | 40 ++++++++++++++
 drivers/net/virtio/virtqueue.c          | 71 +++++++++++++++++++++++++
 drivers/net/virtio/virtqueue.h          |  4 ++
 4 files changed, 117 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +2 -2
index 044eb10a7..f9d0ea70d 100644
@@ -1913,6 +1913,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 			goto err_vtpci_init;
 	}
 
+	rte_spinlock_init(&hw->state_lock);
+
 	/* reset device and negotiate default features */
 	ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
 	if (ret < 0)
@@ -2155,8 +2157,6 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 			return -EBUSY;
 		}
 
-	rte_spinlock_init(&hw->state_lock);
-
 	hw->use_simple_rx = 1;
 
 	if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER)) {
drivers/net/virtio/virtio_user_ethdev.c +36 -0
index 3fc172573..425f48230 100644
@@ -25,12 +25,48 @@
 #define virtio_user_get_dev(hw) \
 	((struct virtio_user_dev *)(hw)->virtio_user_dev)
 
+static void
+virtio_user_reset_queues_packed(struct rte_eth_dev *dev)
+{
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtnet_rx *rxvq;
+	struct virtnet_tx *txvq;
+	uint16_t i;
+
+	/* Add lock to avoid queue contention. */
+	rte_spinlock_lock(&hw->state_lock);
+	hw->started = 0;
+
+	/*
+	 * Waitting for datapath to complete before resetting queues.
+	 * 1 ms should be enough for the ongoing Tx/Rx function to finish.
+	 */
+	rte_delay_ms(1);
+
+	/* Vring reset for each Tx queue and Rx queue. */
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		rxvq = dev->data->rx_queues[i];
+		virtqueue_rxvq_reset_packed(rxvq->vq);
+		virtio_dev_rx_queue_setup_finish(dev, i);
+	}
+
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		txvq = dev->data->tx_queues[i];
+		virtqueue_txvq_reset_packed(txvq->vq);
+	}
+
+	hw->started = 1;
+	rte_spinlock_unlock(&hw->state_lock);
+}
+
+
 static int
 virtio_user_server_reconnect(struct virtio_user_dev *dev)
 {
 	int ret;
 	int connectfd;
 	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
+	struct virtio_hw *hw = eth_dev->data->dev_private;
 
 	connectfd = accept(dev->listenfd, NULL, NULL);
 	if (connectfd < 0)

drivers/net/virtio/virtio_user_ethdev.c virtio_user_server_reconnect(struct virtio_user_dev *dev) · line 92

Quoted 6 lines
drivers/net/virtio/virtio_user_ethdev.c +3 -0
@@ -51,6 +87,10 @@ virtio_user_server_reconnect(struct virtio_user_dev *dev)
 
 	dev->features &= dev->device_features;
 
+	/* For packed ring, resetting queues is required in reconnection. */
+	if (vtpci_packed_queue(hw))
+		virtio_user_reset_queues_packed(eth_dev);

I think we should log an error here to state that some packets are likely to be dropped.

Other than that, I don't think we have other choices than doing that right now, so I'll ack your patch once commit message is fixed and error message is printed on vrings reset.

Thanks,
Maxime

author
#8 lore raw

Hi Maxime,

Replies are inline.

Quoted 21 lines

-----Original Message-----
From: Maxime Coquelin <[email protected]>
Sent: Tuesday, January 14, 2020 11:04 PM
To: Ding, Xuan <[email protected]>; Bie, Tiwei <[email protected]>; Wang, Zhihong <[email protected]>; Liu, Yong <[email protected]>; Ye, Xiaolong <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v4] net/virtio-user: fix packed ring server mode

Quoted 6 lines · Xuan Ding

This patch fixes the situation where datapath does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of discriptors directly from the available ring and

s/discriptors/descriptors/

Quoted 8 lines
Quoted 5 lines

the used ring during reconnection. Therefore, the datapath can continue.

But for packed ring, when reconnecting to virtio, vhost cannot get the status of discriptors only through the descriptor ring. By resetting Tx

s/discriptor only through/descriptor via/

Thanks, this will be corrected in the new version.

Quoted 112 lines
Quoted 30 lines

and Rx queues, the datapath can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")

---

v4:
* Moved change log below '---' marker.

v3:
* Removed an extra asterisk from a comment.
* Renamed device reset function and moved it to virtio_user_ethdev.c.

v2:
* Renamed queue reset functions and moved them to virtqueue.c.

 drivers/net/virtio/virtio_ethdev.c      |  4 +-
 drivers/net/virtio/virtio_user_ethdev.c | 40 ++++++++++++++
 drivers/net/virtio/virtqueue.c          | 71 +++++++++++++++++++++++++
 drivers/net/virtio/virtqueue.h          |  4 ++
 4 files changed, 117 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +0 -0
index 044eb10a7..f9d0ea70d 100644

drivers/net/virtio/virtio_ethdev.c eth_virtio_dev_init(struct rte_eth_dev *eth_dev) · line 1919

Quoted 7 lines
drivers/net/virtio/virtio_ethdev.c +2 -0
@@ -1913,6 +1913,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 			goto err_vtpci_init;
 	}
 
+	rte_spinlock_init(&hw->state_lock);
+
 	/* reset device and negotiate default features */
 	ret = virtio_init_device(eth_dev,

VIRTIO_PMD_DEFAULT_GUEST_FEATURES);

Quoted 63 lines
drivers/net/virtio/virtio_ethdev.c +0 -2
 	if (ret < 0)
@@ -2155,8 +2157,6 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 			return -EBUSY;
 		}
 
-	rte_spinlock_init(&hw->state_lock);
-
 	hw->use_simple_rx = 1;
 
 	if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER)) { diff --git

a/drivers/net/virtio/virtio_user_ethdev.c
b/drivers/net/virtio/virtio_user_ethdev.c
index 3fc172573..425f48230 100644

drivers/net/virtio/virtio_user_ethdev.c +35 -0
@@ -25,12 +25,48 @@
 #define virtio_user_get_dev(hw) \
 	((struct virtio_user_dev *)(hw)->virtio_user_dev)
 
+static void
+virtio_user_reset_queues_packed(struct rte_eth_dev *dev) {
+	struct virtio_hw *hw = dev->data->dev_private;
+	struct virtnet_rx *rxvq;
+	struct virtnet_tx *txvq;
+	uint16_t i;
+
+	/* Add lock to avoid queue contention. */
+	rte_spinlock_lock(&hw->state_lock);
+	hw->started = 0;
+
+	/*
+	 * Waitting for datapath to complete before resetting queues.
+	 * 1 ms should be enough for the ongoing Tx/Rx function to finish.
+	 */
+	rte_delay_ms(1);
+
+	/* Vring reset for each Tx queue and Rx queue. */
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		rxvq = dev->data->rx_queues[i];
+		virtqueue_rxvq_reset_packed(rxvq->vq);
+		virtio_dev_rx_queue_setup_finish(dev, i);
+	}
+
+	for (i = 0; i < dev->data->nb_tx_queues; i++) {
+		txvq = dev->data->tx_queues[i];
+		virtqueue_txvq_reset_packed(txvq->vq);
+	}
+
+	hw->started = 1;
+	rte_spinlock_unlock(&hw->state_lock);
+}
+
+
 static int
 virtio_user_server_reconnect(struct virtio_user_dev *dev)  {
 	int ret;
 	int connectfd;
 	struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
+	struct virtio_hw *hw = eth_dev->data->dev_private;
 
 	connectfd = accept(dev->listenfd, NULL, NULL);
 	if (connectfd < 0)

drivers/net/virtio/virtio_user_ethdev.c virtio_user_server_reconnect(struct virtio_user_dev · line 93

Quoted 7 lines
drivers/net/virtio/virtio_user_ethdev.c +3 -0
@@ -51,6 +87,10 @@ virtio_user_server_reconnect(struct virtio_user_dev
 *dev)
 
 	dev->features &= dev->device_features;
 
+	/* For packed ring, resetting queues is required in reconnection. */
+	if (vtpci_packed_queue(hw))
+		virtio_user_reset_queues_packed(eth_dev);

I think we should log an error here to state that some packets are likely to be dropped.

Quoted 4 lines

Other than that, I don't think we have other choices than doing that right now, so I'll ack your patch once commit message is fixed and error message is printed on vrings reset.

Notice message will be added in the new version. This message will remind user that packets on the fly will be dropped when packed ring reconnecting. Thank you for your comments.

Regards,
Xuan

Quoted 2 lines

Thanks,
Maxime

author
#9 lore raw

PATCH v5 1/1 net/virtio-user: fix packed ring server mode

In reply to Xuan Ding

This patch fixes the situation where data path does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of descriptors directly from the available ring and the used ring during reconnection. Therefore, the data path can continue.

But for packed ring, when reconnecting to virtio, vhost cannot get the status of descriptors via the descriptor ring. By resetting Tx and Rx queues, the data path can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")

---

v5:
* Fixed two spelling mistakes in the commit log.
* Added notice message when resetting vring.

v4:
* Moved change log below '---' marker.

v3:
* Removed an extra asterisk from a comment.
* Renamed device reset function and moved it to virtio_user_ethdev.c.

v2:
* Renamed queue reset functions and moved them to virtqueue.c.

---
 drivers/net/virtio/virtio_ethdev.c      |  4 +-
 drivers/net/virtio/virtio_user_ethdev.c | 42 +++++++++++++++
 drivers/net/virtio/virtqueue.c          | 71 +++++++++++++++++++++++++
 drivers/net/virtio/virtqueue.h          |  4 ++
 4 files changed, 119 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_ethdev.c +2 -2
index 044eb10a7..f9d0ea70d 100644
@@ -1913,6 +1913,8 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 			goto err_vtpci_init;
 	}
 
+	rte_spinlock_init(&hw->state_lock);
+
 	/* reset device and negotiate default features */
 	ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
 	if (ret < 0)
@@ -2155,8 +2157,6 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 			return -EBUSY;
 		}
 
-	rte_spinlock_init(&hw->state_lock);
-
 	hw->use_simple_rx = 1;
 
 	if (vtpci_with_feature(hw, VIRTIO_F_IN_ORDER)) {
drivers/net/virtio/virtio_user_ethdev.c +42 -0

60 lines not on this page · raw message

drivers/net/virtio/virtqueue.c +71 -0

74 lines not on this page · raw message

drivers/net/virtio/virtqueue.h +4 -0
index 8d7f197b1..58ad7309a 100644
@@ -443,6 +443,10 @@ struct rte_mbuf *virtqueue_detach_unused(struct virtqueue *vq);
 /* Flush the elements in the used ring. */
 void virtqueue_rxvq_flush(struct virtqueue *vq);
 
+int virtqueue_rxvq_reset_packed(struct virtqueue *vq);
+
+int virtqueue_txvq_reset_packed(struct virtqueue *vq);
+
 static inline int
 virtqueue_full(const struct virtqueue *vq)
 {
Signature · 1 line
2.17.1
Reviewed-by on v5 1/1
#10 lore raw
Quoted 28 lines · Xuan Ding

This patch fixes the situation where data path does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of descriptors directly from the available ring and the used ring during reconnection. Therefore, the data path can continue.

But for packed ring, when reconnecting to virtio, vhost cannot get the status of descriptors via the descriptor ring. By resetting Tx and Rx queues, the data path can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")

---

v5:
* Fixed two spelling mistakes in the commit log.
* Added notice message when resetting vring.

v4:
* Moved change log below '---' marker.

v3:
* Removed an extra asterisk from a comment.
* Renamed device reset function and moved it to virtio_user_ethdev.c.

Quoted 9 lines

v2:
* Renamed queue reset functions and moved them to virtqueue.c.

---
 drivers/net/virtio/virtio_ethdev.c      |  4 +-
 drivers/net/virtio/virtio_user_ethdev.c | 42 +++++++++++++++
 drivers/net/virtio/virtqueue.c          | 71 +++++++++++++++++++++++++
 drivers/net/virtio/virtqueue.h          |  4 ++
 4 files changed, 119 insertions(+), 2 deletions(-)

Thanks,
Maxime

#11 lore raw
In reply to Xuan Ding
Quoted 28 lines · Xuan Ding

This patch fixes the situation where data path does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of descriptors directly from the available ring and the used ring during reconnection. Therefore, the data path can continue.

But for packed ring, when reconnecting to virtio, vhost cannot get the status of descriptors via the descriptor ring. By resetting Tx and Rx queues, the data path can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")

---

v5:
* Fixed two spelling mistakes in the commit log.
* Added notice message when resetting vring.

v4:
* Moved change log below '---' marker.

v3:
* Removed an extra asterisk from a comment.
* Renamed device reset function and moved it to virtio_user_ethdev.c.

Quoted 8 lines

v2:
* Renamed queue reset functions and moved them to virtqueue.c.

---
 drivers/net/virtio/virtio_ethdev.c      |  4 +-
 drivers/net/virtio/virtio_user_ethdev.c | 42 +++++++++++++++
 drivers/net/virtio/virtqueue.c          | 71 +++++++++++++++++++++++++
 drivers/net/virtio/virtqueue.h          |  4 ++
 4 files changed, 119 insertions(+), 2 deletions(-)

Applied to dpdk-next-virtio/master

Thanks,
Maxime

#12 lore raw
Quoted 40 lines · Maxime Coquelin
Quoted 28 lines · Xuan Ding

This patch fixes the situation where data path does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of descriptors directly from the available ring and the used ring during reconnection. Therefore, the data path can continue.

But for packed ring, when reconnecting to virtio, vhost cannot get the status of descriptors via the descriptor ring. By resetting Tx and Rx queues, the data path can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")

---

v5:
* Fixed two spelling mistakes in the commit log.
* Added notice message when resetting vring.

v4:
* Moved change log below '---' marker.

v3:
* Removed an extra asterisk from a comment.
* Renamed device reset function and moved it to virtio_user_ethdev.c.

Quoted 8 lines

v2:
* Renamed queue reset functions and moved them to virtqueue.c.

---
 drivers/net/virtio/virtio_ethdev.c      |  4 +-
 drivers/net/virtio/virtio_user_ethdev.c | 42 +++++++++++++++
 drivers/net/virtio/virtqueue.c          | 71 +++++++++++++++++++++++++
 drivers/net/virtio/virtqueue.h          |  4 ++
 4 files changed, 119 insertions(+), 2 deletions(-)
Quoted 2 lines

Applied to dpdk-next-virtio/master

This was causing build error [1] on cross compilation [2], I am fixing it while merging [3], please double check in next-net.

[1]
.../drivers/net/virtio/virtio_user_ethdev.c:44:2: error: implicit declaration of function ‘rte_delay_ms’; did you mean ‘rte_realloc’? [-Werror=implicit-function-declaration]

  rte_delay_ms(1);

[2] CROSS=/opt/aarch64/bin/aarch64-buildroot-linux-gnu- make -j64

[3]

(quoted diff) +0 -0

b/drivers/net/virtio/virtio_user_ethdev.c
index 9c9d3407f..f3b35d1bd 100644

drivers/net/virtio/virtio_user_ethdev.c +1 -0
@@ -13,6 +13,7 @@
 #include <rte_ethdev_vdev.h>
 #include <rte_bus_vdev.h>
 #include <rte_alarm.h>
+#include <rte_cycles.h>
 
 #include "virtio_ethdev.h"
 #include "virtio_logs.h"
author
#13 lore raw

Hi Ferruh,

Quoted 78 lines

-----Original Message-----
From: Yigit, Ferruh <[email protected]>
Sent: Wednesday, January 15, 2020 11:41 PM
To: Maxime Coquelin <[email protected]>; Ding, Xuan <[email protected]>; Bie, Tiwei <[email protected]>; Wang, Zhihong <[email protected]>; Liu, Yong <[email protected]>; Ye, Xiaolong <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [dpdk-stable] [PATCH v5] net/virtio-user: fix packed ring server mode

Quoted 9 lines · Maxime Coquelin
Quoted 6 lines · Xuan Ding

This patch fixes the situation where data path does not work properly when vhost reconnects to virtio in server mode with packed ring.

Currently, virtio and vhost share memory of vring. For split ring, vhost can read the status of descriptors directly from the available ring and the used ring during reconnection. Therefore, the data path can

continue.

Quoted 31 lines
Quoted 22 lines

But for packed ring, when reconnecting to virtio, vhost cannot get the status of descriptors via the descriptor ring. By resetting Tx and Rx queues, the data path can restart from the beginning.

Fixes 4c3f5822eb214 ("net/virtio: add packed virtqueue defines")

---

v5:
* Fixed two spelling mistakes in the commit log.
* Added notice message when resetting vring.

v4:
* Moved change log below '---' marker.

v3:
* Removed an extra asterisk from a comment.
* Renamed device reset function and moved it to virtio_user_ethdev.c.

Quoted 8 lines

v2:
* Renamed queue reset functions and moved them to virtqueue.c.

---
 drivers/net/virtio/virtio_ethdev.c      |  4 +-
 drivers/net/virtio/virtio_user_ethdev.c | 42 +++++++++++++++
 drivers/net/virtio/virtqueue.c          | 71 +++++++++++++++++++++++++
 drivers/net/virtio/virtqueue.h          |  4 ++
 4 files changed, 119 insertions(+), 2 deletions(-)
Quoted 2 lines

Applied to dpdk-next-virtio/master

This was causing build error [1] on cross compilation [2], I am fixing it while merging [3], please double check in next-net.

[1]
.../drivers/net/virtio/virtio_user_ethdev.c:44:2: error: implicit declaration of function ‘rte_delay_ms’; did you mean ‘rte_realloc’? [-Werror=implicit-function-declaration]

  rte_delay_ms(1);

[2] CROSS=/opt/aarch64/bin/aarch64-buildroot-linux-gnu- make -j64

[3]

drivers/net/virtio/virtio_user_ethdev.c +0 -0
index 9c9d3407f..f3b35d1bd 100644

drivers/net/virtio/virtio_user_ethdev.c line 19

Quoted 7 lines
drivers/net/virtio/virtio_user_ethdev.c +1 -0
@@ -13,6 +13,7 @@
 #include <rte_ethdev_vdev.h>
 #include <rte_bus_vdev.h>
 #include <rte_alarm.h>
+#include <rte_cycles.h>
 
 #include "virtio_ethdev.h"
 #include "virtio_logs.h"

After my check, the current call path to rte_cycles.h on the x86 platform is virtio_user_ethdev.c -> virtqueue.h -> rte_mempool.h -> rte_spinlock.h -> rte_cycles.h. I find that only rte_spinlock.h on the x86 platform includes the rte_cycles.h, while this file is not included on other platforms, so your fix is right. I also test the new patch(add #include <rte_cycles.h>) on my local, it works fine.

Thank you very much.

Regards,
Xuan