DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] vhost: fix invalid use of stored last used index
@ 2021-05-14 16:02 Balazs Nemeth
  2021-05-15  6:10 ` David Marchand
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Balazs Nemeth @ 2021-05-14 16:02 UTC (permalink / raw)
  To: bnemeth, dev, weix.ling

The optimization introduced by commit d18db8049c7c ("vhost: read last
used index once") didn't account for the fact that
vhost_flush_enqueue_shadow_packed increments the last_used_idx. For this
reason, store last_used_idx after the potential call to
vhost_flush_enqueue_shadow_packed.

Fixes: d18db8049c7c ("vhost: read last used index once")
Signed-off-by: Balazs Nemeth <bnemeth@redhat.com>
---
 lib/vhost/virtio_net.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index abfd67d38c..8da8a86a10 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -218,14 +218,17 @@ vhost_flush_enqueue_batch_packed(struct virtio_net *dev,
 {
 	uint16_t i;
 	uint16_t flags;
-	uint16_t last_used_idx = vq->last_used_idx;
-	struct vring_packed_desc *desc_base = &vq->desc_packed[last_used_idx];
+	uint16_t last_used_idx;
+	struct vring_packed_desc *desc_base;
 
 	if (vq->shadow_used_idx) {
 		do_data_copy_enqueue(dev, vq);
 		vhost_flush_enqueue_shadow_packed(dev, vq);
 	}
 
+	last_used_idx = vq->last_used_idx;
+	desc_base = &vq->desc_packed[last_used_idx];
+
 	flags = PACKED_DESC_ENQUEUE_USED_FLAG(vq->used_wrap_counter);
 
 	vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE) {
-- 
2.30.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-05-18  8:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-14 16:02 [dpdk-dev] [PATCH] vhost: fix invalid use of stored last used index Balazs Nemeth
2021-05-15  6:10 ` David Marchand
2021-05-17  7:37 ` Maxime Coquelin
2021-05-17 10:07   ` Ling, WeiX
2021-05-17 10:46     ` Maxime Coquelin
2021-05-18  8:03 ` Xia, Chenbo

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).