thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 6 months ago
Clone
ed5979
From bffccbd59a2e2c641810cd7362c7b5ecf5989ed8 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:35 +0100
ed5979
Subject: [PATCH 03/14] vhost: allocate SVQ device file descriptors at device
ed5979
 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: [3/13] bab2d43f0fc0d13a4917e706244b37e1a431b082 (eperezmartin/qemu-kvm)
ed5979
ed5979
The next patches will start control SVQ if possible. However, we don't
ed5979
know if that will be possible at qemu boot anymore.
ed5979
ed5979
Delay device file descriptors until we know it at device start. This
ed5979
will avoid to create them 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-4-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 3cfb4d069cd2977b707fb519c455d7d416e1f4b0)
ed5979
---
ed5979
 hw/virtio/vhost-shadow-virtqueue.c | 31 ++------------------------
ed5979
 hw/virtio/vhost-vdpa.c             | 35 ++++++++++++++++++++++++------
ed5979
 2 files changed, 30 insertions(+), 36 deletions(-)
ed5979
ed5979
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
ed5979
index 264ddc166d..3b05bab44d 100644
ed5979
--- a/hw/virtio/vhost-shadow-virtqueue.c
ed5979
+++ b/hw/virtio/vhost-shadow-virtqueue.c
ed5979
@@ -715,43 +715,18 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq)
ed5979
  * @iova_tree: Tree to perform descriptors translations
ed5979
  * @ops: SVQ owner callbacks
ed5979
  * @ops_opaque: ops opaque pointer
ed5979
- *
ed5979
- * Returns the new virtqueue or NULL.
ed5979
- *
ed5979
- * In case of error, reason is reported through error_report.
ed5979
  */
ed5979
 VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree,
ed5979
                                     const VhostShadowVirtqueueOps *ops,
ed5979
                                     void *ops_opaque)
ed5979
 {
ed5979
-    g_autofree VhostShadowVirtqueue *svq = g_new0(VhostShadowVirtqueue, 1);
ed5979
-    int r;
ed5979
-
ed5979
-    r = event_notifier_init(&svq->hdev_kick, 0);
ed5979
-    if (r != 0) {
ed5979
-        error_report("Couldn't create kick event notifier: %s (%d)",
ed5979
-                     g_strerror(errno), errno);
ed5979
-        goto err_init_hdev_kick;
ed5979
-    }
ed5979
-
ed5979
-    r = event_notifier_init(&svq->hdev_call, 0);
ed5979
-    if (r != 0) {
ed5979
-        error_report("Couldn't create call event notifier: %s (%d)",
ed5979
-                     g_strerror(errno), errno);
ed5979
-        goto err_init_hdev_call;
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 g_steal_pointer(&svq);
ed5979
-
ed5979
-err_init_hdev_call:
ed5979
-    event_notifier_cleanup(&svq->hdev_kick);
ed5979
-
ed5979
-err_init_hdev_kick:
ed5979
-    return NULL;
ed5979
+    return svq;
ed5979
 }
ed5979
 
ed5979
 /**
ed5979
@@ -763,7 +738,5 @@ void vhost_svq_free(gpointer pvq)
ed5979
 {
ed5979
     VhostShadowVirtqueue *vq = pvq;
ed5979
     vhost_svq_stop(vq);
ed5979
-    event_notifier_cleanup(&vq->hdev_kick);
ed5979
-    event_notifier_cleanup(&vq->hdev_call);
ed5979
     g_free(vq);
ed5979
 }
ed5979
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
ed5979
index 44e6a9b7b3..530d2ca362 100644
ed5979
--- a/hw/virtio/vhost-vdpa.c
ed5979
+++ b/hw/virtio/vhost-vdpa.c
ed5979
@@ -428,15 +428,11 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v,
ed5979
 
ed5979
     shadow_vqs = g_ptr_array_new_full(hdev->nvqs, vhost_svq_free);
ed5979
     for (unsigned n = 0; n < hdev->nvqs; ++n) {
ed5979
-        g_autoptr(VhostShadowVirtqueue) svq;
ed5979
+        VhostShadowVirtqueue *svq;
ed5979
 
ed5979
         svq = vhost_svq_new(v->iova_tree, v->shadow_vq_ops,
ed5979
                             v->shadow_vq_ops_opaque);
ed5979
-        if (unlikely(!svq)) {
ed5979
-            error_setg(errp, "Cannot create svq %u", n);
ed5979
-            return -1;
ed5979
-        }
ed5979
-        g_ptr_array_add(shadow_vqs, g_steal_pointer(&svq));
ed5979
+        g_ptr_array_add(shadow_vqs, svq);
ed5979
     }
ed5979
 
ed5979
     v->shadow_vqs = g_steal_pointer(&shadow_vqs);
ed5979
@@ -871,11 +867,23 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev,
ed5979
     const EventNotifier *event_notifier = &svq->hdev_kick;
ed5979
     int r;
ed5979
 
ed5979
+    r = event_notifier_init(&svq->hdev_kick, 0);
ed5979
+    if (r != 0) {
ed5979
+        error_setg_errno(errp, -r, "Couldn't create kick event notifier");
ed5979
+        goto err_init_hdev_kick;
ed5979
+    }
ed5979
+
ed5979
+    r = event_notifier_init(&svq->hdev_call, 0);
ed5979
+    if (r != 0) {
ed5979
+        error_setg_errno(errp, -r, "Couldn't create call event notifier");
ed5979
+        goto err_init_hdev_call;
ed5979
+    }
ed5979
+
ed5979
     file.fd = event_notifier_get_fd(event_notifier);
ed5979
     r = vhost_vdpa_set_vring_dev_kick(dev, &file;;
ed5979
     if (unlikely(r != 0)) {
ed5979
         error_setg_errno(errp, -r, "Can't set device kick fd");
ed5979
-        return r;
ed5979
+        goto err_init_set_dev_fd;
ed5979
     }
ed5979
 
ed5979
     event_notifier = &svq->hdev_call;
ed5979
@@ -883,8 +891,18 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev,
ed5979
     r = vhost_vdpa_set_vring_dev_call(dev, &file;;
ed5979
     if (unlikely(r != 0)) {
ed5979
         error_setg_errno(errp, -r, "Can't set device call fd");
ed5979
+        goto err_init_set_dev_fd;
ed5979
     }
ed5979
 
ed5979
+    return 0;
ed5979
+
ed5979
+err_init_set_dev_fd:
ed5979
+    event_notifier_set_handler(&svq->hdev_call, NULL);
ed5979
+
ed5979
+err_init_hdev_call:
ed5979
+    event_notifier_cleanup(&svq->hdev_kick);
ed5979
+
ed5979
+err_init_hdev_kick:
ed5979
     return r;
ed5979
 }
ed5979
 
ed5979
@@ -1096,6 +1114,9 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *dev)
ed5979
     for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
ed5979
         VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
ed5979
         vhost_vdpa_svq_unmap_rings(dev, svq);
ed5979
+
ed5979
+        event_notifier_cleanup(&svq->hdev_kick);
ed5979
+        event_notifier_cleanup(&svq->hdev_call);
ed5979
     }
ed5979
 }
ed5979
 
ed5979
-- 
ed5979
2.31.1
ed5979