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