Blame SOURCES/0017-net-virtio-user-fix-control-VQ.patch

b91920
From e5ee642672921b9e83aaa558067b6b685a7af0a3 Mon Sep 17 00:00:00 2001
b91920
From: Tiwei Bie <tiwei.bie@intel.com>
b91920
Date: Wed, 23 Jan 2019 01:01:41 +0800
b91920
Subject: [PATCH 17/18] net/virtio-user: fix control VQ
b91920
b91920
[ upstream commit 45c224e73a3057bf62cb04f83fc1e97457a21ffa ]
b91920
b91920
This patch fixed below issues in the packed ring based control
b91920
vq support in virtio user:
b91920
b91920
1. The idx_hdr should be used_idx instead of the id in the desc;
b91920
2. We just need to write out a single used descriptor for each
b91920
   descriptor list;
b91920
3. The avail/used bits should be initialized to 0;
b91920
b91920
Meanwhile, make the function name consistent with other parts.
b91920
b91920
Fixes: 48a4464029a7 ("net/virtio-user: support control VQ for packed")
b91920
b91920
Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
b91920
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
b91920
(cherry picked from commit 45c224e73a3057bf62cb04f83fc1e97457a21ffa)
b91920
Signed-off-by: Jens Freimann <jfreimann@redhat.com>
b91920
---
b91920
 drivers/net/virtio/virtio_ethdev.c            | 11 ++++++
b91920
 .../net/virtio/virtio_user/virtio_user_dev.c  | 37 +++++++++++--------
b91920
 drivers/net/virtio/virtio_user_ethdev.c       |  7 +---
b91920
 3 files changed, 34 insertions(+), 21 deletions(-)
b91920
b91920
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
b91920
index c12fb157e..a31129484 100644
b91920
--- a/drivers/net/virtio/virtio_ethdev.c
b91920
+++ b/drivers/net/virtio/virtio_ethdev.c
b91920
@@ -224,6 +224,17 @@ virtio_send_command_packed(struct virtnet_ctl *cvq,
b91920
 		vq->used_wrap_counter ^= 1;
b91920
 	}
b91920
 
b91920
+	PMD_INIT_LOG(DEBUG, "vq->vq_free_cnt=%d\n"
b91920
+			"vq->vq_avail_idx=%d\n"
b91920
+			"vq->vq_used_cons_idx=%d\n"
b91920
+			"vq->avail_wrap_counter=%d\n"
b91920
+			"vq->used_wrap_counter=%d\n",
b91920
+			vq->vq_free_cnt,
b91920
+			vq->vq_avail_idx,
b91920
+			vq->vq_used_cons_idx,
b91920
+			vq->avail_wrap_counter,
b91920
+			vq->used_wrap_counter);
b91920
+
b91920
 	result = cvq->virtio_net_hdr_mz->addr;
b91920
 	return result;
b91920
 }
b91920
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
b91920
index ea5149929..d1157378d 100644
b91920
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
b91920
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
b91920
@@ -632,9 +632,9 @@ desc_is_avail(struct vring_packed_desc *desc, bool wrap_counter)
b91920
 }
b91920
 
b91920
 static uint32_t
b91920
-virtio_user_handle_ctrl_msg_pq(struct virtio_user_dev *dev,
b91920
-			    struct vring_packed *vring,
b91920
-			    uint16_t idx_hdr)
b91920
+virtio_user_handle_ctrl_msg_packed(struct virtio_user_dev *dev,
b91920
+				   struct vring_packed *vring,
b91920
+				   uint16_t idx_hdr)
b91920
 {
b91920
 	struct virtio_net_ctrl_hdr *hdr;
b91920
 	virtio_net_ctrl_ack status = ~0;
b91920
@@ -671,6 +671,10 @@ virtio_user_handle_ctrl_msg_pq(struct virtio_user_dev *dev,
b91920
 	*(virtio_net_ctrl_ack *)(uintptr_t)
b91920
 		vring->desc_packed[idx_status].addr = status;
b91920
 
b91920
+	/* Update used descriptor */
b91920
+	vring->desc_packed[idx_hdr].id = vring->desc_packed[idx_status].id;
b91920
+	vring->desc_packed[idx_hdr].len = sizeof(status);
b91920
+
b91920
 	return n_descs;
b91920
 }
b91920
 
b91920
@@ -679,24 +683,25 @@ virtio_user_handle_cq_packed(struct virtio_user_dev *dev, uint16_t queue_idx)
b91920
 {
b91920
 	struct virtio_user_queue *vq = &dev->packed_queues[queue_idx];
b91920
 	struct vring_packed *vring = &dev->packed_vrings[queue_idx];
b91920
-	uint16_t id, n_descs;
b91920
+	uint16_t n_descs;
b91920
 
b91920
 	while (desc_is_avail(&vring->desc_packed[vq->used_idx],
b91920
 			     vq->used_wrap_counter)) {
b91920
-		id = vring->desc_packed[vq->used_idx].id;
b91920
 
b91920
-		n_descs = virtio_user_handle_ctrl_msg_pq(dev, vring, id);
b91920
+		n_descs = virtio_user_handle_ctrl_msg_packed(dev, vring,
b91920
+				vq->used_idx);
b91920
 
b91920
-		do {
b91920
-			vring->desc_packed[vq->used_idx].flags =
b91920
-				VRING_DESC_F_AVAIL(vq->used_wrap_counter) |
b91920
-				VRING_DESC_F_USED(vq->used_wrap_counter);
b91920
-			if (++vq->used_idx >= dev->queue_size) {
b91920
-				vq->used_idx -= dev->queue_size;
b91920
-				vq->used_wrap_counter ^= 1;
b91920
-			}
b91920
-			n_descs--;
b91920
-		} while (n_descs);
b91920
+		rte_smp_wmb();
b91920
+		vring->desc_packed[vq->used_idx].flags =
b91920
+			VRING_DESC_F_WRITE |
b91920
+			VRING_DESC_F_AVAIL(vq->used_wrap_counter) |
b91920
+			VRING_DESC_F_USED(vq->used_wrap_counter);
b91920
+
b91920
+		vq->used_idx += n_descs;
b91920
+		if (vq->used_idx >= dev->queue_size) {
b91920
+			vq->used_idx -= dev->queue_size;
b91920
+			vq->used_wrap_counter ^= 1;
b91920
+		}
b91920
 	}
b91920
 }
b91920
 
b91920
diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c
b91920
index c01f45cab..6423e1f61 100644
b91920
--- a/drivers/net/virtio/virtio_user_ethdev.c
b91920
+++ b/drivers/net/virtio/virtio_user_ethdev.c
b91920
@@ -274,7 +274,6 @@ virtio_user_get_queue_num(struct virtio_hw *hw, uint16_t queue_id __rte_unused)
b91920
 static void
b91920
 virtio_user_setup_queue_packed(struct virtqueue *vq,
b91920
 			       struct virtio_user_dev *dev)
b91920
-
b91920
 {
b91920
 	uint16_t queue_idx = vq->vq_queue_index;
b91920
 	struct vring_packed *vring;
b91920
@@ -300,10 +299,8 @@ virtio_user_setup_queue_packed(struct virtqueue *vq,
b91920
 	dev->packed_queues[queue_idx].avail_wrap_counter = true;
b91920
 	dev->packed_queues[queue_idx].used_wrap_counter = true;
b91920
 
b91920
-	for (i = 0; i < vring->num; i++) {
b91920
-		vring->desc_packed[i].flags = VRING_DESC_F_USED(1) |
b91920
-					      VRING_DESC_F_AVAIL(1);
b91920
-	}
b91920
+	for (i = 0; i < vring->num; i++)
b91920
+		vring->desc_packed[i].flags = 0;
b91920
 }
b91920
 
b91920
 static void
b91920
-- 
b91920
2.21.0
b91920