[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v9 04/23] vhost: Get vring base from vq, not svq
From: |
Eugenio Pérez |
Subject: |
[RFC PATCH v9 04/23] vhost: Get vring base from vq, not svq |
Date: |
Wed, 6 Jul 2022 20:39:49 +0200 |
The used idx used to match with this, but it will not match from the
moment we introduce svq_inject. Rewind all the descriptors not used by
vdpa device and get the vq state properly.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
include/hw/virtio/virtio.h | 1 +
hw/virtio/vhost-vdpa.c | 7 +++----
hw/virtio/virtio.c | 5 +++++
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index db1c0ddf6b..4b51ab9d06 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -302,6 +302,7 @@ hwaddr virtio_queue_get_desc_size(VirtIODevice *vdev, int
n);
hwaddr virtio_queue_get_avail_size(VirtIODevice *vdev, int n);
hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n);
unsigned int virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n);
+unsigned int virtio_queue_get_in_use(const VirtQueue *vq);
void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n,
unsigned int idx);
void virtio_queue_restore_last_avail_idx(VirtIODevice *vdev, int n);
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 2ee8009594..de76128030 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -1189,12 +1189,10 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev
*dev,
struct vhost_vring_state *ring)
{
struct vhost_vdpa *v = dev->opaque;
- int vdpa_idx = ring->index - dev->vq_index;
int ret;
if (v->shadow_vqs_enabled) {
- VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, vdpa_idx);
-
+ const VirtQueue *vq = virtio_get_queue(dev->vdev, ring->index);
/*
* Setting base as last used idx, so destination will see as available
* all the entries that the device did not use, including the in-flight
@@ -1203,7 +1201,8 @@ static int vhost_vdpa_get_vring_base(struct vhost_dev
*dev,
* TODO: This is ok for networking, but other kinds of devices might
* have problems with these retransmissions.
*/
- ring->num = svq->last_used_idx;
+ ring->num = virtio_queue_get_last_avail_idx(dev->vdev, ring->index) -
+ virtio_queue_get_in_use(vq);
return 0;
}
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 5d607aeaa0..e02656f7a2 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -3420,6 +3420,11 @@ unsigned int
virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n)
}
}
+unsigned int virtio_queue_get_in_use(const VirtQueue *vq)
+{
+ return vq->inuse;
+}
+
static void virtio_queue_packed_set_last_avail_idx(VirtIODevice *vdev,
int n, unsigned int idx)
{
--
2.31.1
[RFC PATCH v9 06/23] virtio-net: Expose ctrl virtqueue logic, Eugenio Pérez, 2022/07/06
[RFC PATCH v9 02/23] vhost: move descriptor translation to vhost_svq_vring_write_descs, Eugenio Pérez, 2022/07/06
[RFC PATCH v9 07/23] vhost: add vhost_svq_push_elem, Eugenio Pérez, 2022/07/06
[RFC PATCH v9 08/23] vhost: Decouple vhost_svq_add_split from VirtQueueElement, Eugenio Pérez, 2022/07/06