* [PATCH] hw/virtio: Fix packed virtqueue flush used_idx
@ 2024-03-27 6:15 Wafer
2024-04-03 5:58 ` Michael S. Tsirkin
0 siblings, 1 reply; 2+ messages in thread
From: Wafer @ 2024-03-27 6:15 UTC (permalink / raw)
To: mst; +Cc: qemu-devel, angus.chen, Wafer
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] hw/virtio: Fix packed virtqueue flush used_idx
2024-03-27 6:15 [PATCH] hw/virtio: Fix packed virtqueue flush used_idx Wafer
@ 2024-04-03 5:58 ` Michael S. Tsirkin
0 siblings, 0 replies; 2+ messages in thread
From: Michael S. Tsirkin @ 2024-04-03 5:58 UTC (permalink / raw)
To: Wafer; +Cc: qemu-devel, angus.chen, Jason Wang
On Wed, Mar 27, 2024 at 02:15:18PM +0800, Wafer wrote:
> 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>
Thanks for the patch.
It's kind of hard to figure out what you are trying to say
with all the typos and grammar errors in the commit log.
What's up with that?
Please describe the following in the commit log:
- current behaviour is abc
- this is wrong because the virtio spec says def
- as a result we observed guest doing pqr and then stu
- to fix do ghi
- with this fix the guest does xyz as expected
- tested by klm
Also I think you might want to add:
Fixes: 86044b24e8 ("virtio: basic packed virtqueue support")
Cc: "Jason Wang" <jasowang@redhat.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.
> + */
There's no such thing as "the flag" - descriptors do have a "flags" field
though. And there's no 'chain' value either.
maybe just "
For indirect elems, ndescs is 1. For all other elems, ndescs is the
number of descriptors chained by NEXT (as set in virtqueue_packed_pop).
> + 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;
The patch itself seems correct to me.
> --
> 2.27.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-03 5:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-27 6:15 [PATCH] hw/virtio: Fix packed virtqueue flush used_idx Wafer
2024-04-03 5:58 ` Michael S. Tsirkin
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).