All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Eugenio Pérez" <eperezma@redhat.com>
To: qemu-devel@nongnu.org
Cc: Parav Pandit <parav@mellanox.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Si-Wei Liu <si-wei.liu@oracle.com>,
	Laurent Vivier <lvivier@redhat.com>,
	Harpreet Singh Anand <hanand@xilinx.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Gautam Dawar <gdawar@xilinx.com>,
	Liuxiangdong <liuxiangdong5@huawei.com>,
	Stefano Garzarella <sgarzare@redhat.com>,
	Jason Wang <jasowang@redhat.com>, Cindy Lu <lulu@redhat.com>,
	Eli Cohen <eli@mellanox.com>, Cornelia Huck <cohuck@redhat.com>,
	Zhu Lingshan <lingshan.zhu@intel.com>,
	kvm@vger.kernel.org, "Gonglei (Arei)" <arei.gonglei@huawei.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH v6 03/10] vhost: Allocate SVQ device file descriptors at device start
Date: Tue,  8 Nov 2022 18:07:48 +0100	[thread overview]
Message-ID: <20221108170755.92768-4-eperezma@redhat.com> (raw)
In-Reply-To: <20221108170755.92768-1-eperezma@redhat.com>

The next patches will start control SVQ if possible. However, we don't
know if that will be possible at qemu boot anymore.

Delay device file descriptors until we know it at device start.

Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
---
 hw/virtio/vhost-shadow-virtqueue.c | 31 ++------------------------
 hw/virtio/vhost-vdpa.c             | 35 ++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 36 deletions(-)

diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
index 264ddc166d..3b05bab44d 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -715,43 +715,18 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq)
  * @iova_tree: Tree to perform descriptors translations
  * @ops: SVQ owner callbacks
  * @ops_opaque: ops opaque pointer
- *
- * Returns the new virtqueue or NULL.
- *
- * In case of error, reason is reported through error_report.
  */
 VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree,
                                     const VhostShadowVirtqueueOps *ops,
                                     void *ops_opaque)
 {
-    g_autofree VhostShadowVirtqueue *svq = g_new0(VhostShadowVirtqueue, 1);
-    int r;
-
-    r = event_notifier_init(&svq->hdev_kick, 0);
-    if (r != 0) {
-        error_report("Couldn't create kick event notifier: %s (%d)",
-                     g_strerror(errno), errno);
-        goto err_init_hdev_kick;
-    }
-
-    r = event_notifier_init(&svq->hdev_call, 0);
-    if (r != 0) {
-        error_report("Couldn't create call event notifier: %s (%d)",
-                     g_strerror(errno), errno);
-        goto err_init_hdev_call;
-    }
+    VhostShadowVirtqueue *svq = g_new0(VhostShadowVirtqueue, 1);
 
     event_notifier_init_fd(&svq->svq_kick, VHOST_FILE_UNBIND);
     svq->iova_tree = iova_tree;
     svq->ops = ops;
     svq->ops_opaque = ops_opaque;
-    return g_steal_pointer(&svq);
-
-err_init_hdev_call:
-    event_notifier_cleanup(&svq->hdev_kick);
-
-err_init_hdev_kick:
-    return NULL;
+    return svq;
 }
 
 /**
@@ -763,7 +738,5 @@ void vhost_svq_free(gpointer pvq)
 {
     VhostShadowVirtqueue *vq = pvq;
     vhost_svq_stop(vq);
-    event_notifier_cleanup(&vq->hdev_kick);
-    event_notifier_cleanup(&vq->hdev_call);
     g_free(vq);
 }
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index 7f0ff4df5b..3df2775760 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -428,15 +428,11 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v,
 
     shadow_vqs = g_ptr_array_new_full(hdev->nvqs, vhost_svq_free);
     for (unsigned n = 0; n < hdev->nvqs; ++n) {
-        g_autoptr(VhostShadowVirtqueue) svq;
+        VhostShadowVirtqueue *svq;
 
         svq = vhost_svq_new(v->iova_tree, v->shadow_vq_ops,
                             v->shadow_vq_ops_opaque);
-        if (unlikely(!svq)) {
-            error_setg(errp, "Cannot create svq %u", n);
-            return -1;
-        }
-        g_ptr_array_add(shadow_vqs, g_steal_pointer(&svq));
+        g_ptr_array_add(shadow_vqs, svq);
     }
 
     v->shadow_vqs = g_steal_pointer(&shadow_vqs);
@@ -864,11 +860,23 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev,
     const EventNotifier *event_notifier = &svq->hdev_kick;
     int r;
 
+    r = event_notifier_init(&svq->hdev_kick, 0);
+    if (r != 0) {
+        error_setg_errno(errp, -r, "Couldn't create kick event notifier");
+        goto err_init_hdev_kick;
+    }
+
+    r = event_notifier_init(&svq->hdev_call, 0);
+    if (r != 0) {
+        error_setg_errno(errp, -r, "Couldn't create call event notifier");
+        goto err_init_hdev_call;
+    }
+
     file.fd = event_notifier_get_fd(event_notifier);
     r = vhost_vdpa_set_vring_dev_kick(dev, &file);
     if (unlikely(r != 0)) {
         error_setg_errno(errp, -r, "Can't set device kick fd");
-        return r;
+        goto err_init_set_dev_fd;
     }
 
     event_notifier = &svq->hdev_call;
@@ -876,8 +884,18 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev,
     r = vhost_vdpa_set_vring_dev_call(dev, &file);
     if (unlikely(r != 0)) {
         error_setg_errno(errp, -r, "Can't set device call fd");
+        goto err_init_set_dev_fd;
     }
 
+    return 0;
+
+err_init_set_dev_fd:
+    event_notifier_set_handler(&svq->hdev_call, NULL);
+
+err_init_hdev_call:
+    event_notifier_cleanup(&svq->hdev_kick);
+
+err_init_hdev_kick:
     return r;
 }
 
@@ -1089,6 +1107,9 @@ static void vhost_vdpa_svqs_stop(struct vhost_dev *dev)
     for (unsigned i = 0; i < v->shadow_vqs->len; ++i) {
         VhostShadowVirtqueue *svq = g_ptr_array_index(v->shadow_vqs, i);
         vhost_vdpa_svq_unmap_rings(dev, svq);
+
+        event_notifier_cleanup(&svq->hdev_kick);
+        event_notifier_cleanup(&svq->hdev_call);
     }
 }
 
-- 
2.31.1


  parent reply	other threads:[~2022-11-08 17:09 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-08 17:07 [PATCH v6 00/10] ASID support in vhost-vdpa net Eugenio Pérez
2022-11-08 17:07 ` [PATCH v6 01/10] vdpa: Use v->shadow_vqs_enabled in vhost_vdpa_svqs_start & stop Eugenio Pérez
2022-11-10  5:21   ` Jason Wang
2022-11-10 12:54     ` Eugenio Perez Martin
2022-11-11  7:24       ` Jason Wang
2022-11-08 17:07 ` [PATCH v6 02/10] vhost: set SVQ device call handler at SVQ start Eugenio Pérez
2022-11-10  5:22   ` Jason Wang
2022-11-08 17:07 ` Eugenio Pérez [this message]
2022-11-10  5:28   ` [PATCH v6 03/10] vhost: Allocate SVQ device file descriptors at device start Jason Wang
2022-11-08 17:07 ` [PATCH v6 04/10] vdpa: add vhost_vdpa_net_valid_svq_features Eugenio Pérez
2022-11-10  5:29   ` Jason Wang
2022-11-08 17:07 ` [PATCH v6 05/10] vdpa: move SVQ vring features check to net/ Eugenio Pérez
2022-11-10  5:40   ` Jason Wang
2022-11-10 13:09     ` Eugenio Perez Martin
2022-11-11  7:34       ` Jason Wang
2022-11-11  7:55         ` Eugenio Perez Martin
2022-11-11  8:07           ` Jason Wang
2022-11-11 12:58             ` Eugenio Perez Martin
2022-11-14  4:26               ` Jason Wang
2022-11-14 10:10                 ` Eugenio Perez Martin
2022-11-08 17:07 ` [PATCH v6 06/10] vdpa: Allocate SVQ unconditionally Eugenio Pérez
2022-11-08 17:07 ` [PATCH v6 07/10] vdpa: Add asid parameter to vhost_vdpa_dma_map/unmap Eugenio Pérez
2022-11-10  5:50   ` Jason Wang
2022-11-10 13:22     ` Eugenio Perez Martin
2022-11-11  7:41       ` Jason Wang
2022-11-11 13:02         ` Eugenio Perez Martin
2022-11-14  4:27           ` Jason Wang
2022-11-08 17:07 ` [PATCH v6 08/10] vdpa: Store x-svq parameter in VhostVDPAState Eugenio Pérez
2022-11-08 17:07 ` [PATCH v6 09/10] vdpa: Add listener_shadow_vq to vhost_vdpa Eugenio Pérez
2022-11-10  6:00   ` Jason Wang
2022-11-10 13:47     ` Eugenio Perez Martin
2022-11-11  7:48       ` Jason Wang
2022-11-11 13:12         ` Eugenio Perez Martin
2022-11-14  4:30           ` Jason Wang
2022-11-14 16:30             ` Eugenio Perez Martin
2022-11-15  3:04               ` Jason Wang
2022-11-15 11:24                 ` Eugenio Perez Martin
2022-11-16  3:33                   ` Jason Wang
2022-11-08 17:07 ` [PATCH v6 10/10] vdpa: Always start CVQ in SVQ mode Eugenio Pérez
2022-11-10  6:24   ` Jason Wang
2022-11-10 16:07     ` Eugenio Perez Martin
2022-11-11  8:02       ` Jason Wang
2022-11-11 14:38         ` Eugenio Perez Martin
2022-11-14  4:36           ` Jason Wang
2022-11-10 12:25 ` [PATCH v6 00/10] ASID support in vhost-vdpa net Michael S. Tsirkin
2022-11-10 12:56   ` Eugenio Perez Martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221108170755.92768-4-eperezma@redhat.com \
    --to=eperezma@redhat.com \
    --cc=arei.gonglei@huawei.com \
    --cc=cohuck@redhat.com \
    --cc=eli@mellanox.com \
    --cc=gdawar@xilinx.com \
    --cc=hanand@xilinx.com \
    --cc=jasowang@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=lingshan.zhu@intel.com \
    --cc=liuxiangdong5@huawei.com \
    --cc=lulu@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mst@redhat.com \
    --cc=parav@mellanox.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sgarzare@redhat.com \
    --cc=si-wei.liu@oracle.com \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.