DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jens Freimann <jfreimann@redhat.com>
To: dev@dpdk.org
Cc: tiwei.bie@intel.com, maxime.coquelin@redhat.com
Subject: [dpdk-dev] [Patch v3 1/2] net/virtio: check head desc with correct wrap counter
Date: Thu, 10 Jan 2019 22:47:26 +0100	[thread overview]
Message-ID: <20190110214727.1142-2-jfreimann@redhat.com> (raw)
In-Reply-To: <20190110214727.1142-1-jfreimann@redhat.com>

In virtio_pq_send_command() we check for a used descriptor
and wait in an idle loop until it becomes used. We can't use
vq->used_wrap_counter here to check for the first descriptor
we made available because the ring could have wrapped. Let's use
the used_wrap_counter that matches the state of the head descriptor.

Fixes: ec194c2 ("net/virtio: support packed queue in send command")

Signed-off-by: Jens Freimann <jfreimann@redhat.com>
---
 drivers/net/virtio/virtio_ethdev.c | 11 ++++++-----
 drivers/net/virtio/virtqueue.h     | 10 ++++++++--
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 6d461180c..ee5a98b7c 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -149,7 +149,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
 	int head;
 	struct vring_packed_desc *desc = vq->ring_packed.desc_packed;
 	struct virtio_pmd_ctrl *result;
-	int wrap_counter;
+	bool avail_wrap_counter, used_wrap_counter;
 	uint16_t flags;
 	int sum = 0;
 	int k;
@@ -161,7 +161,8 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
 	 * One RX packet for ACK.
 	 */
 	head = vq->vq_avail_idx;
-	wrap_counter = vq->avail_wrap_counter;
+	avail_wrap_counter = vq->avail_wrap_counter;
+	used_wrap_counter = vq->used_wrap_counter;
 	desc[head].flags = VRING_DESC_F_NEXT;
 	desc[head].addr = cvq->virtio_net_hdr_mem;
 	desc[head].len = sizeof(struct virtio_net_ctrl_hdr);
@@ -199,8 +200,8 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
 		 VRING_DESC_F_USED(!vq->avail_wrap_counter);
 	desc[vq->vq_avail_idx].flags = flags;
 	flags = VRING_DESC_F_NEXT;
-	flags |= VRING_DESC_F_AVAIL(wrap_counter) |
-		 VRING_DESC_F_USED(!wrap_counter);
+	flags |= VRING_DESC_F_AVAIL(avail_wrap_counter) |
+		 VRING_DESC_F_USED(!avail_wrap_counter);
 	desc[head].flags = flags;
 	rte_smp_wmb();
 
@@ -216,7 +217,7 @@ virtio_pq_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
 	do {
 		rte_rmb();
 		usleep(100);
-	} while (!desc_is_used(&desc[head], vq));
+	} while (!__desc_is_used(&desc[head], used_wrap_counter));
 
 	/* now get used descriptors */
 	while (desc_is_used(&desc[vq->vq_used_cons_idx], vq)) {
diff --git a/drivers/net/virtio/virtqueue.h b/drivers/net/virtio/virtqueue.h
index 123bec34f..7fcde5643 100644
--- a/drivers/net/virtio/virtqueue.h
+++ b/drivers/net/virtio/virtqueue.h
@@ -281,7 +281,7 @@ struct virtio_tx_region {
 };
 
 static inline int
-desc_is_used(struct vring_packed_desc *desc, struct virtqueue *vq)
+__desc_is_used(struct vring_packed_desc *desc, bool wrap_counter)
 {
 	uint16_t used, avail, flags;
 
@@ -289,7 +289,13 @@ desc_is_used(struct vring_packed_desc *desc, struct virtqueue *vq)
 	used = !!(flags & VRING_DESC_F_USED(1));
 	avail = !!(flags & VRING_DESC_F_AVAIL(1));
 
-	return avail == used && used == vq->used_wrap_counter;
+	return avail == used && used == wrap_counter;
+}
+
+static inline int
+desc_is_used(struct vring_packed_desc *desc, struct virtqueue *vq)
+{
+	return __desc_is_used(desc, vq->used_wrap_counter);
 }
 
 
-- 
2.17.2

  reply	other threads:[~2019-01-10 21:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-10 21:47 [dpdk-dev] [PATCH v3 0/2] net/virtio-user: add packed vq support Jens Freimann
2019-01-10 21:47 ` Jens Freimann [this message]
2019-01-11  9:03   ` [dpdk-dev] [Patch v3 1/2] net/virtio: check head desc with correct wrap counter Maxime Coquelin
2019-01-10 21:47 ` [dpdk-dev] [Patch v3 2/2] net/virtio-user: ctrl vq support for packed Jens Freimann
2019-01-11  9:12   ` Maxime Coquelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190110214727.1142-2-jfreimann@redhat.com \
    --to=jfreimann@redhat.com \
    --cc=dev@dpdk.org \
    --cc=maxime.coquelin@redhat.com \
    --cc=tiwei.bie@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).