|
|
2c1bf6 |
From 82b43dd199d5492527b73002d4c3b009a98ca7a0 Mon Sep 17 00:00:00 2001
|
|
|
2c1bf6 |
From: Jens Freimann <jfreimann@redhat.com>
|
|
|
2c1bf6 |
Date: Fri, 11 Jan 2019 10:39:28 +0100
|
|
|
2c1bf6 |
Subject: [PATCH 14/18] net/virtio: check head desc with correct wrap counter
|
|
|
2c1bf6 |
|
|
|
2c1bf6 |
[ upstream commit a4270ea4ff79b46280dd542f4ab3eb45f8c9685a ]
|
|
|
2c1bf6 |
|
|
|
2c1bf6 |
In virtio_pq_send_command() we check for a used descriptor
|
|
|
2c1bf6 |
and wait in an idle loop until it becomes used. We can't use
|
|
|
2c1bf6 |
vq->used_wrap_counter here to check for the first descriptor
|
|
|
2c1bf6 |
we made available because the ring could have wrapped. Let's use
|
|
|
2c1bf6 |
the used_wrap_counter that matches the state of the head descriptor.
|
|
|
2c1bf6 |
|
|
|
2c1bf6 |
Fixes: ec194c2f1895 ("net/virtio: support packed queue in send command")
|
|
|
2c1bf6 |
|
|
|
2c1bf6 |
Signed-off-by: Jens Freimann <jfreimann@redhat.com>
|
|
|
2c1bf6 |
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
|
|
|
2c1bf6 |
(cherry picked from commit a4270ea4ff79b46280dd542f4ab3eb45f8c9685a)
|
|
|
2c1bf6 |
Signed-off-by: Jens Freimann <jfreimann@redhat.com>
|
|
|
2c1bf6 |
---
|
|
|
2c1bf6 |
drivers/net/virtio/virtio_ethdev.c | 11 ++++++-----
|
|
|
2c1bf6 |
drivers/net/virtio/virtqueue.h | 10 ++++++++--
|
|
|
2c1bf6 |
2 files changed, 14 insertions(+), 7 deletions(-)
|
|
|
2c1bf6 |
|
|
|
2c1bf6 |
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
|
|
|
2c1bf6 |
index 53773445b..7bd38a292 100644
|
|
|
2c1bf6 |
--- a/drivers/net/virtio/virtio_ethdev.c
|
|
|
2c1bf6 |
+++ b/drivers/net/virtio/virtio_ethdev.c
|
|
|
2c1bf6 |
@@ -149,7 +149,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
|
|
|
2c1bf6 |
int head;
|
|
|
2c1bf6 |
struct vring_packed_desc *desc = vq->ring_packed.desc_packed;
|
|
|
2c1bf6 |
struct virtio_pmd_ctrl *result;
|
|
|
2c1bf6 |
- int wrap_counter;
|
|
|
2c1bf6 |
+ bool avail_wrap_counter, used_wrap_counter;
|
|
|
2c1bf6 |
uint16_t flags;
|
|
|
2c1bf6 |
int sum = 0;
|
|
|
2c1bf6 |
int k;
|
|
|
2c1bf6 |
@@ -161,7 +161,8 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
|
|
|
2c1bf6 |
* One RX packet for ACK.
|
|
|
2c1bf6 |
*/
|
|
|
2c1bf6 |
head = vq->vq_avail_idx;
|
|
|
2c1bf6 |
- wrap_counter = vq->avail_wrap_counter;
|
|
|
2c1bf6 |
+ avail_wrap_counter = vq->avail_wrap_counter;
|
|
|
2c1bf6 |
+ used_wrap_counter = vq->used_wrap_counter;
|
|
|
2c1bf6 |
desc[head].flags = VRING_DESC_F_NEXT;
|
|
|
2c1bf6 |
desc[head].addr = cvq->virtio_net_hdr_mem;
|
|
|
2c1bf6 |
desc[head].len = sizeof(struct virtio_net_ctrl_hdr);
|
|
|
2c1bf6 |
@@ -199,8 +200,8 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
|
|
|
2c1bf6 |
VRING_DESC_F_USED(!vq->avail_wrap_counter);
|
|
|
2c1bf6 |
desc[vq->vq_avail_idx].flags = flags;
|
|
|
2c1bf6 |
flags = VRING_DESC_F_NEXT;
|
|
|
2c1bf6 |
- flags |= VRING_DESC_F_AVAIL(wrap_counter) |
|
|
|
2c1bf6 |
- VRING_DESC_F_USED(!wrap_counter);
|
|
|
2c1bf6 |
+ flags |= VRING_DESC_F_AVAIL(avail_wrap_counter) |
|
|
|
2c1bf6 |
+ VRING_DESC_F_USED(!avail_wrap_counter);
|
|
|
2c1bf6 |
desc[head].flags = flags;
|
|
|
2c1bf6 |
rte_smp_wmb();
|
|
|
2c1bf6 |
|
|
|
2c1bf6 |
@@ -216,7 +217,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
|
|
|
2c1bf6 |
do {
|
|
|
2c1bf6 |
rte_rmb();
|
|
|
2c1bf6 |
usleep(100);
|
|
|
2c1bf6 |
- } while (!desc_is_used(&desc[head], vq));
|
|
|
2c1bf6 |
+ } while (!__desc_is_used(&desc[head], used_wrap_counter));
|
|
|
2c1bf6 |
|
|
|
2c1bf6 |
/* now get used descriptors */
|
|
|
2c1bf6 |
while (desc_is_used(&desc[vq->vq_used_cons_idx], vq)) {
|
|
|
2c1bf6 |
diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
|
|
|
2c1bf6 |
index b142fd488..75f5782bc 100644
|
|
|
2c1bf6 |
--- a/drivers/net/virtio/virtqueue.h
|
|
|
2c1bf6 |
+++ b/drivers/net/virtio/virtqueue.h
|
|
|
2c1bf6 |
@@ -256,7 +256,7 @@ struct virtio_tx_region {
|
|
|
2c1bf6 |
};
|
|
|
2c1bf6 |
|
|
|
2c1bf6 |
static inline int
|
|
|
2c1bf6 |
-desc_is_used(struct vring_packed_desc *desc, struct virtqueue *vq)
|
|
|
2c1bf6 |
+__desc_is_used(struct vring_packed_desc *desc, bool wrap_counter)
|
|
|
2c1bf6 |
{
|
|
|
2c1bf6 |
uint16_t used, avail, flags;
|
|
|
2c1bf6 |
|
|
|
2c1bf6 |
@@ -264,7 +264,13 @@ desc_is_used(struct vring_packed_desc *desc, struct virtqueue *vq)
|
|
|
2c1bf6 |
used = !!(flags & VRING_DESC_F_USED(1));
|
|
|
2c1bf6 |
avail = !!(flags & VRING_DESC_F_AVAIL(1));
|
|
|
2c1bf6 |
|
|
|
2c1bf6 |
- return avail == used && used == vq->used_wrap_counter;
|
|
|
2c1bf6 |
+ return avail == used && used == wrap_counter;
|
|
|
2c1bf6 |
+}
|
|
|
2c1bf6 |
+
|
|
|
2c1bf6 |
+static inline int
|
|
|
2c1bf6 |
+desc_is_used(struct vring_packed_desc *desc, struct virtqueue *vq)
|
|
|
2c1bf6 |
+{
|
|
|
2c1bf6 |
+ return __desc_is_used(desc, vq->used_wrap_counter);
|
|
|
2c1bf6 |
}
|
|
|
2c1bf6 |
|
|
|
2c1bf6 |
|
|
|
2c1bf6 |
--
|
|
|
2c1bf6 |
2.21.0
|
|
|
2c1bf6 |
|