* [PATCH v2] hw/virtio: Fix packed virtqueue flush used_idx
@ 2024-04-04 16:57 Wafer
2024-04-05 8:16 ` Eugenio Perez Martin
0 siblings, 1 reply; 2+ messages in thread
From: Wafer @ 2024-04-04 16:57 UTC (permalink / raw)
To: mst, jasowang; +Cc: qemu-devel, angus.chen, Wafer
If a virtio-net device has the VIRTIO_NET_F_MRG_RXBUF feature
but not the VIRTIO_RING_F_INDIRECT_DESC feature,
'VirtIONetQueue->rx_vq' will use the merge feature
to store data in multiple 'elems'.
The 'num_buffers' in the virtio header indicates how many elements are merged.
If the value of 'num_buffers' is greater than 1,
all the merged elements will be filled into the descriptor ring.
The 'idx' of the elements should be the value of 'vq->used_idx' plus 'ndescs'.
Signed-off-by: Wafer <wafer@jaguarmicro.com>
---
Changes in v2:
- Clarify more in commit message;
---
hw/virtio/virtio.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index fb6b4ccd83..cab5832cac 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -957,12 +957,20 @@ static void virtqueue_packed_flush(VirtQueue *vq, unsigned int count)
return;
}
+ /*
+ * For indirect element's 'ndescs' is 1.
+ * For all other elemment's 'ndescs' is the
+ * number of descriptors chained by NEXT (as set in virtqueue_packed_pop).
+ * So When the 'elem' be filled into the descriptor ring,
+ * The 'idx' of this 'elem' shall be
+ * the value of 'vq->used_idx' plus the 'ndescs'.
+ */
+ 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 v2] hw/virtio: Fix packed virtqueue flush used_idx
2024-04-04 16:57 [PATCH v2] hw/virtio: Fix packed virtqueue flush used_idx Wafer
@ 2024-04-05 8:16 ` Eugenio Perez Martin
0 siblings, 0 replies; 2+ messages in thread
From: Eugenio Perez Martin @ 2024-04-05 8:16 UTC (permalink / raw)
To: Wafer; +Cc: mst, jasowang, qemu-devel, angus.chen, Jonah Palmer, Lei Yang
On Thu, Apr 4, 2024 at 7:03 PM Wafer <wafer@jaguarmicro.com> wrote:
>
> If a virtio-net device has the VIRTIO_NET_F_MRG_RXBUF feature
> but not the VIRTIO_RING_F_INDIRECT_DESC feature,
> 'VirtIONetQueue->rx_vq' will use the merge feature
> to store data in multiple 'elems'.
> The 'num_buffers' in the virtio header indicates how many elements are merged.
> If the value of 'num_buffers' is greater than 1,
> all the merged elements will be filled into the descriptor ring.
> The 'idx' of the elements should be the value of 'vq->used_idx' plus 'ndescs'.
>
> Signed-off-by: Wafer <wafer@jaguarmicro.com>
>
Fixes: 86044b24e8 ("virtio: basic packed virtqueue support")
?
> ---
> Changes in v2:
> - Clarify more in commit message;
> ---
> hw/virtio/virtio.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index fb6b4ccd83..cab5832cac 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -957,12 +957,20 @@ static void virtqueue_packed_flush(VirtQueue *vq, unsigned int count)
> return;
> }
>
> + /*
> + * For indirect element's 'ndescs' is 1.
> + * For all other elemment's 'ndescs' is the
> + * number of descriptors chained by NEXT (as set in virtqueue_packed_pop).
> + * So When the 'elem' be filled into the descriptor ring,
> + * The 'idx' of this 'elem' shall be
> + * the value of 'vq->used_idx' plus the 'ndescs'.
> + */
> + 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);
This bugged me recently when I was reviewing it for in_order feature
implementation, thanks for the patch!
Acked-by: Eugenio Pérez <eperezma@redhat.com>
> 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 [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-05 8:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-04 16:57 [PATCH v2] hw/virtio: Fix packed virtqueue flush used_idx Wafer
2024-04-05 8:16 ` Eugenio Perez Martin
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).