thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 6 months ago
Clone
29b115
From 14200f493243f73152ea4a4b97274f0ec4fb36fa Mon Sep 17 00:00:00 2001
29b115
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
29b115
Date: Thu, 21 Jul 2022 15:38:55 +0200
29b115
Subject: [PATCH 15/32] vhost: Add SVQDescState
29b115
MIME-Version: 1.0
29b115
Content-Type: text/plain; charset=UTF-8
29b115
Content-Transfer-Encoding: 8bit
29b115
29b115
RH-Author: Eugenio Pérez <eperezma@redhat.com>
29b115
RH-MergeRequest: 108: Net Control Virtqueue shadow Support
29b115
RH-Commit: [15/27] 2e2866f22e37cace8598ff44dfcdc07fcc915d6d (eperezmartin/qemu-kvm)
29b115
RH-Bugzilla: 1939363
29b115
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
29b115
RH-Acked-by: Cindy Lu <lulu@redhat.com>
29b115
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
29b115
29b115
Bugzilla: https://bugzilla.redhat.com/1939363
29b115
29b115
Upstream Status: git://git.qemu.org/qemu.git
29b115
29b115
commit 9e87868fcaf5785c8e1490c290505fa32305ff91
29b115
Author: Eugenio Pérez <eperezma@redhat.com>
29b115
Date:   Wed Jul 20 08:59:34 2022 +0200
29b115
29b115
    vhost: Add SVQDescState
29b115
29b115
    This will allow SVQ to add context to the different queue elements.
29b115
29b115
    This patch only store the actual element, no functional change intended.
29b115
29b115
    Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
29b115
    Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
29b115
    Signed-off-by: Jason Wang <jasowang@redhat.com>
29b115
29b115
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
29b115
---
29b115
 hw/virtio/vhost-shadow-virtqueue.c | 16 ++++++++--------
29b115
 hw/virtio/vhost-shadow-virtqueue.h |  8 ++++++--
29b115
 2 files changed, 14 insertions(+), 10 deletions(-)
29b115
29b115
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
29b115
index 3cec03d709..a08e3d4025 100644
29b115
--- a/hw/virtio/vhost-shadow-virtqueue.c
29b115
+++ b/hw/virtio/vhost-shadow-virtqueue.c
29b115
@@ -256,7 +256,7 @@ static int vhost_svq_add(VhostShadowVirtqueue *svq, const struct iovec *out_sg,
29b115
         return -EINVAL;
29b115
     }
29b115
 
29b115
-    svq->ring_id_maps[qemu_head] = elem;
29b115
+    svq->desc_state[qemu_head].elem = elem;
29b115
     vhost_svq_kick(svq);
29b115
     return 0;
29b115
 }
29b115
@@ -411,21 +411,21 @@ static VirtQueueElement *vhost_svq_get_buf(VhostShadowVirtqueue *svq,
29b115
         return NULL;
29b115
     }
29b115
 
29b115
-    if (unlikely(!svq->ring_id_maps[used_elem.id])) {
29b115
+    if (unlikely(!svq->desc_state[used_elem.id].elem)) {
29b115
         qemu_log_mask(LOG_GUEST_ERROR,
29b115
             "Device %s says index %u is used, but it was not available",
29b115
             svq->vdev->name, used_elem.id);
29b115
         return NULL;
29b115
     }
29b115
 
29b115
-    num = svq->ring_id_maps[used_elem.id]->in_num +
29b115
-          svq->ring_id_maps[used_elem.id]->out_num;
29b115
+    num = svq->desc_state[used_elem.id].elem->in_num +
29b115
+          svq->desc_state[used_elem.id].elem->out_num;
29b115
     last_used_chain = vhost_svq_last_desc_of_chain(svq, num, used_elem.id);
29b115
     svq->desc_next[last_used_chain] = svq->free_head;
29b115
     svq->free_head = used_elem.id;
29b115
 
29b115
     *len = used_elem.len;
29b115
-    return g_steal_pointer(&svq->ring_id_maps[used_elem.id]);
29b115
+    return g_steal_pointer(&svq->desc_state[used_elem.id].elem);
29b115
 }
29b115
 
29b115
 static void vhost_svq_flush(VhostShadowVirtqueue *svq,
29b115
@@ -595,7 +595,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev,
29b115
     memset(svq->vring.desc, 0, driver_size);
29b115
     svq->vring.used = qemu_memalign(qemu_real_host_page_size, device_size);
29b115
     memset(svq->vring.used, 0, device_size);
29b115
-    svq->ring_id_maps = g_new0(VirtQueueElement *, svq->vring.num);
29b115
+    svq->desc_state = g_new0(SVQDescState, svq->vring.num);
29b115
     svq->desc_next = g_new0(uint16_t, svq->vring.num);
29b115
     for (unsigned i = 0; i < svq->vring.num - 1; i++) {
29b115
         svq->desc_next[i] = cpu_to_le16(i + 1);
29b115
@@ -620,7 +620,7 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq)
29b115
 
29b115
     for (unsigned i = 0; i < svq->vring.num; ++i) {
29b115
         g_autofree VirtQueueElement *elem = NULL;
29b115
-        elem = g_steal_pointer(&svq->ring_id_maps[i]);
29b115
+        elem = g_steal_pointer(&svq->desc_state[i].elem);
29b115
         if (elem) {
29b115
             virtqueue_detach_element(svq->vq, elem, 0);
29b115
         }
29b115
@@ -632,7 +632,7 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq)
29b115
     }
29b115
     svq->vq = NULL;
29b115
     g_free(svq->desc_next);
29b115
-    g_free(svq->ring_id_maps);
29b115
+    g_free(svq->desc_state);
29b115
     qemu_vfree(svq->vring.desc);
29b115
     qemu_vfree(svq->vring.used);
29b115
 }
29b115
diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h
29b115
index c132c994e9..d646c35054 100644
29b115
--- a/hw/virtio/vhost-shadow-virtqueue.h
29b115
+++ b/hw/virtio/vhost-shadow-virtqueue.h
29b115
@@ -15,6 +15,10 @@
29b115
 #include "standard-headers/linux/vhost_types.h"
29b115
 #include "hw/virtio/vhost-iova-tree.h"
29b115
 
29b115
+typedef struct SVQDescState {
29b115
+    VirtQueueElement *elem;
29b115
+} SVQDescState;
29b115
+
29b115
 /* Shadow virtqueue to relay notifications */
29b115
 typedef struct VhostShadowVirtqueue {
29b115
     /* Shadow vring */
29b115
@@ -47,8 +51,8 @@ typedef struct VhostShadowVirtqueue {
29b115
     /* IOVA mapping */
29b115
     VhostIOVATree *iova_tree;
29b115
 
29b115
-    /* Map for use the guest's descriptors */
29b115
-    VirtQueueElement **ring_id_maps;
29b115
+    /* SVQ vring descriptors state */
29b115
+    SVQDescState *desc_state;
29b115
 
29b115
     /* Next VirtQueue element that guest made available */
29b115
     VirtQueueElement *next_guest_avail_elem;
29b115
-- 
29b115
2.31.1
29b115