All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wafer <wafer@jaguarmicro.com>
To: mst@redhat.com
Cc: qemu-devel@nongnu.org, angus.chen@jaguarmicro.com,
	Wafer <wafer@jaguarmicro.com>
Subject: [PATCH] hw/virtio: Fix packed virtqueue flush used_idx
Date: Wed, 27 Mar 2024 14:15:18 +0800	[thread overview]
Message-ID: <20240327061518.13200-1-wafer@jaguarmicro.com> (raw)

For indirect descriptors the elelm->ndescs was one,
For direct descriptors the elele->ndesc was the numbe of entries.
elem->ndescs = (desc_cache == &indirect_desc_cache) ? 1 : elem_entries;

When flushing multiple elemes,
the used_idx should be added to all the privious numeric entry value.

Signed-off-by: Wafer <wafer@jaguarmicro.com>
---
 hw/virtio/virtio.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index d229755eae..44f1d2fcfc 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -957,12 +957,17 @@ static void virtqueue_packed_flush(VirtQueue *vq, unsigned int count)
         return;
     }
 
+    /*
+     * When the descriptor's flag was 'INDIRECT', the value of 'ndescs' is one.
+     * When the descriptor's flag was 'chain', the value of 'ndescs'
+     * is the number of entries.
+     */
+    ndescs += vq->used_elems[0].ndescs;
     for (i = 1; i < count; i++) {
-        virtqueue_packed_fill_desc(vq, &vq->used_elems[i], i, false);
+        virtqueue_packed_fill_desc(vq, &vq->used_elems[i], ndescs, false);
         ndescs += vq->used_elems[i].ndescs;
     }
     virtqueue_packed_fill_desc(vq, &vq->used_elems[0], 0, true);
-    ndescs += vq->used_elems[0].ndescs;
 
     vq->inuse -= ndescs;
     vq->used_idx += ndescs;
-- 
2.27.0



             reply	other threads:[~2024-03-27  6:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27  6:15 Wafer [this message]
2024-04-03  5:58 ` [PATCH] hw/virtio: Fix packed virtqueue flush used_idx Michael S. Tsirkin

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=20240327061518.13200-1-wafer@jaguarmicro.com \
    --to=wafer@jaguarmicro.com \
    --cc=angus.chen@jaguarmicro.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.