thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ed5979
From 6584478deca49d0ea20add588e4fdb51cdc26f1d Mon Sep 17 00:00:00 2001
ed5979
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
ed5979
Date: Thu, 15 Dec 2022 12:31:36 +0100
ed5979
Subject: [PATCH 04/14] vhost: move iova_tree set to vhost_svq_start
ed5979
MIME-Version: 1.0
ed5979
Content-Type: text/plain; charset=UTF-8
ed5979
Content-Transfer-Encoding: 8bit
ed5979
ed5979
RH-Author: Eugenio Pérez <eperezma@redhat.com>
ed5979
RH-MergeRequest: 136: vDPA ASID support in Qemu
ed5979
RH-Bugzilla: 2104412
ed5979
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
ed5979
RH-Acked-by: Cindy Lu <lulu@redhat.com>
ed5979
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
ed5979
RH-Commit: [4/13] 200d8e9b58e258a6e301430debc73ef7d962b732 (eperezmartin/qemu-kvm)
ed5979
ed5979
Since we don't know if we will use SVQ at qemu initialization, let's
ed5979
allocate iova_tree only if needed. To do so, accept it at SVQ start, not
ed5979
at initialization.
ed5979
ed5979
This will avoid to create it if the device does not support SVQ.
ed5979
ed5979
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
ed5979
Acked-by: Jason Wang <jasowang@redhat.com>
ed5979
Message-Id: <20221215113144.322011-5-eperezma@redhat.com>
ed5979
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
ed5979
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
ed5979
(cherry picked from commit 5fde952bbdd521c10fc018ee04f922a7dca5f663)
ed5979
---
ed5979
 hw/virtio/vhost-shadow-virtqueue.c | 9 ++++-----
ed5979
 hw/virtio/vhost-shadow-virtqueue.h | 5 ++---
ed5979
 hw/virtio/vhost-vdpa.c             | 5 ++---
ed5979
 3 files changed, 8 insertions(+), 11 deletions(-)
ed5979
ed5979
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
ed5979
index 3b05bab44d..4307296358 100644
ed5979
--- a/hw/virtio/vhost-shadow-virtqueue.c
ed5979
+++ b/hw/virtio/vhost-shadow-virtqueue.c
ed5979
@@ -642,9 +642,10 @@ void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd)
ed5979
  * @svq: Shadow Virtqueue
ed5979
  * @vdev: VirtIO device
ed5979
  * @vq: Virtqueue to shadow
ed5979
+ * @iova_tree: Tree to perform descriptors translations
ed5979
  */
ed5979
 void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev,
ed5979
-                     VirtQueue *vq)
ed5979
+                     VirtQueue *vq, VhostIOVATree *iova_tree)
ed5979
 {
ed5979
     size_t desc_size, driver_size, device_size;
ed5979
 
ed5979
@@ -655,6 +656,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev,
ed5979
     svq->last_used_idx = 0;
ed5979
     svq->vdev = vdev;
ed5979
     svq->vq = vq;
ed5979
+    svq->iova_tree = iova_tree;
ed5979
 
ed5979
     svq->vring.num = virtio_queue_get_num(vdev, virtio_get_queue_index(vq));
ed5979
     driver_size = vhost_svq_driver_area_size(svq);
ed5979
@@ -712,18 +714,15 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq)
ed5979
  * Creates vhost shadow virtqueue, and instructs the vhost device to use the
ed5979
  * shadow methods and file descriptors.
ed5979
  *
ed5979
- * @iova_tree: Tree to perform descriptors translations
ed5979
  * @ops: SVQ owner callbacks
ed5979
  * @ops_opaque: ops opaque pointer
ed5979
  */
ed5979
-VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree,
ed5979
-                                    const VhostShadowVirtqueueOps *ops,
ed5979
+VhostShadowVirtqueue *vhost_svq_new(const VhostShadowVirtqueueOps *ops,
ed5979
                                     void *ops_opaque)
ed5979
 {
ed5979
     VhostShadowVirtqueue *svq = g_new0(VhostShadowVirtqueue, 1);
ed5979
 
ed5979
     event_notifier_init_fd(&svq->svq_kick, VHOST_FILE_UNBIND);
ed5979
-    svq->iova_tree = iova_tree;
ed5979
     svq->ops = ops;
ed5979
     svq->ops_opaque = ops_opaque;
ed5979
     return svq;
ed5979
diff --git a/hw/virtio/vhost-shadow-virtqueue.h b/hw/virtio/vhost-shadow-virtqueue.h
ed5979
index d04c34a589..926a4897b1 100644
ed5979
--- a/hw/virtio/vhost-shadow-virtqueue.h
ed5979
+++ b/hw/virtio/vhost-shadow-virtqueue.h
ed5979
@@ -126,11 +126,10 @@ size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq);
ed5979
 size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq);
ed5979
 
ed5979
 void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev,
ed5979
-                     VirtQueue *vq);
ed5979
+                     VirtQueue *vq, VhostIOVATree *iova_tree);
ed5979
 void vhost_svq_stop(VhostShadowVirtqueue *svq);
ed5979
 
ed5979
-VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree,
ed5979
-                                    const VhostShadowVirtqueueOps *ops,
ed5979
+VhostShadowVirtqueue *vhost_svq_new(const VhostShadowVirtqueueOps *ops,
ed5979
                                     void *ops_opaque);
ed5979
 
ed5979
 void vhost_svq_free(gpointer vq);
ed5979
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
ed5979
index 530d2ca362..e65603022f 100644
ed5979
--- a/hw/virtio/vhost-vdpa.c
ed5979
+++ b/hw/virtio/vhost-vdpa.c
ed5979
@@ -430,8 +430,7 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v,
ed5979
     for (unsigned n = 0; n < hdev->nvqs; ++n) {
ed5979
         VhostShadowVirtqueue *svq;
ed5979
 
ed5979
-        svq = vhost_svq_new(v->iova_tree, v->shadow_vq_ops,
ed5979
-                            v->shadow_vq_ops_opaque);
ed5979
+        svq = vhost_svq_new(v->shadow_vq_ops, v->shadow_vq_ops_opaque);
ed5979
         g_ptr_array_add(shadow_vqs, svq);
ed5979
     }
ed5979
 
ed5979
@@ -1070,7 +1069,7 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev)
ed5979
             goto err;
ed5979
         }
ed5979
 
ed5979
-        vhost_svq_start(svq, dev->vdev, vq);
ed5979
+        vhost_svq_start(svq, dev->vdev, vq, v->iova_tree);
ed5979
         ok = vhost_vdpa_svq_map_rings(dev, svq, &addr, &err;;
ed5979
         if (unlikely(!ok)) {
ed5979
             goto err_map;
ed5979
-- 
ed5979
2.31.1
ed5979