thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-vhost-move-descriptor-translation-to-vhost_svq_vring.patch

29b115
From 2bdea90bfbce3b8d5bfa86178a942a470b85b835 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 07/32] vhost: move descriptor translation to
29b115
 vhost_svq_vring_write_descs
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: [7/27] 5533c72065e4ebf8ea7db966c976a3b29bdafb82 (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 009c2549bb9dc7f7061009eb87f2a53d4b364983
29b115
Author: Eugenio Pérez <eperezma@redhat.com>
29b115
Date:   Wed Jul 20 08:59:26 2022 +0200
29b115
29b115
    vhost: move descriptor translation to vhost_svq_vring_write_descs
29b115
29b115
    It's done for both in and out descriptors so it's better placed here.
29b115
29b115
    Acked-by: Jason Wang <jasowang@redhat.com>
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 | 38 +++++++++++++++++++++---------
29b115
 1 file changed, 27 insertions(+), 11 deletions(-)
29b115
29b115
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
29b115
index 06d0bb39d9..3fbda1e3d4 100644
29b115
--- a/hw/virtio/vhost-shadow-virtqueue.c
29b115
+++ b/hw/virtio/vhost-shadow-virtqueue.c
29b115
@@ -122,17 +122,35 @@ static bool vhost_svq_translate_addr(const VhostShadowVirtqueue *svq,
29b115
     return true;
29b115
 }
29b115
 
29b115
-static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
29b115
-                                    const struct iovec *iovec, size_t num,
29b115
-                                    bool more_descs, bool write)
29b115
+/**
29b115
+ * Write descriptors to SVQ vring
29b115
+ *
29b115
+ * @svq: The shadow virtqueue
29b115
+ * @sg: Cache for hwaddr
29b115
+ * @iovec: The iovec from the guest
29b115
+ * @num: iovec length
29b115
+ * @more_descs: True if more descriptors come in the chain
29b115
+ * @write: True if they are writeable descriptors
29b115
+ *
29b115
+ * Return true if success, false otherwise and print error.
29b115
+ */
29b115
+static bool vhost_svq_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
29b115
+                                        const struct iovec *iovec, size_t num,
29b115
+                                        bool more_descs, bool write)
29b115
 {
29b115
     uint16_t i = svq->free_head, last = svq->free_head;
29b115
     unsigned n;
29b115
     uint16_t flags = write ? cpu_to_le16(VRING_DESC_F_WRITE) : 0;
29b115
     vring_desc_t *descs = svq->vring.desc;
29b115
+    bool ok;
29b115
 
29b115
     if (num == 0) {
29b115
-        return;
29b115
+        return true;
29b115
+    }
29b115
+
29b115
+    ok = vhost_svq_translate_addr(svq, sg, iovec, num);
29b115
+    if (unlikely(!ok)) {
29b115
+        return false;
29b115
     }
29b115
 
29b115
     for (n = 0; n < num; n++) {
29b115
@@ -150,6 +168,7 @@ static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, hwaddr *sg,
29b115
     }
29b115
 
29b115
     svq->free_head = le16_to_cpu(svq->desc_next[last]);
29b115
+    return true;
29b115
 }
29b115
 
29b115
 static bool vhost_svq_add_split(VhostShadowVirtqueue *svq,
29b115
@@ -169,21 +188,18 @@ static bool vhost_svq_add_split(VhostShadowVirtqueue *svq,
29b115
         return false;
29b115
     }
29b115
 
29b115
-    ok = vhost_svq_translate_addr(svq, sgs, elem->out_sg, elem->out_num);
29b115
+    ok = vhost_svq_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num,
29b115
+                                     elem->in_num > 0, false);
29b115
     if (unlikely(!ok)) {
29b115
         return false;
29b115
     }
29b115
-    vhost_vring_write_descs(svq, sgs, elem->out_sg, elem->out_num,
29b115
-                            elem->in_num > 0, false);
29b115
-
29b115
 
29b115
-    ok = vhost_svq_translate_addr(svq, sgs, elem->in_sg, elem->in_num);
29b115
+    ok = vhost_svq_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false,
29b115
+                                     true);
29b115
     if (unlikely(!ok)) {
29b115
         return false;
29b115
     }
29b115
 
29b115
-    vhost_vring_write_descs(svq, sgs, elem->in_sg, elem->in_num, false, true);
29b115
-
29b115
     /*
29b115
      * Put the entry in the available array (but don't update avail->idx until
29b115
      * they do sync).
29b115
-- 
29b115
2.31.1
29b115