From: Jagannathan Raman <jag.raman@oracle.com>
To: qemu-devel@nongnu.org
Cc: stefanha@redhat.com, mst@redhat.com, alex.williamson@redhat.com,
f4bug@amsat.org, pbonzini@redhat.com,
marcandre.lureau@redhat.com, thuth@redhat.com, bleal@redhat.com,
berrange@redhat.com, peter.maydell@linaro.org,
eduardo@habkost.net, marcel.apfelbaum@gmail.com,
eblake@redhat.com, armbru@redhat.com, quintela@redhat.com,
dgilbert@redhat.com, imammedo@redhat.com, peterx@redhat.com,
john.levon@nutanix.com, thanos.makatos@nutanix.com,
elena.ufimtseva@oracle.com, john.g.johnson@oracle.com,
kanth.ghatraju@oracle.com, jag.raman@oracle.com
Subject: [PATCH v11 06/14] vfio-user: instantiate vfio-user context
Date: Fri, 10 Jun 2022 15:50:33 -0400 [thread overview]
Message-ID: <1e6e6d54e8f84144da6f02497f9e6d3b30c3488a.1654889541.git.jag.raman@oracle.com> (raw)
In-Reply-To: <cover.1654889541.git.jag.raman@oracle.com>
create a context with the vfio-user library to run a PCI device
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: John G Johnson <john.g.johnson@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@oracle.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/remote/vfio-user-obj.c | 82 +++++++++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/hw/remote/vfio-user-obj.c b/hw/remote/vfio-user-obj.c
index bc49adcc27..68f8a9dfa9 100644
--- a/hw/remote/vfio-user-obj.c
+++ b/hw/remote/vfio-user-obj.c
@@ -40,6 +40,9 @@
#include "hw/remote/machine.h"
#include "qapi/error.h"
#include "qapi/qapi-visit-sockets.h"
+#include "qemu/notify.h"
+#include "sysemu/sysemu.h"
+#include "libvfio-user.h"
#define TYPE_VFU_OBJECT "x-vfio-user-server"
OBJECT_DECLARE_TYPE(VfuObject, VfuObjectClass, VFU_OBJECT)
@@ -73,8 +76,14 @@ struct VfuObject {
char *device;
Error *err;
+
+ Notifier machine_done;
+
+ vfu_ctx_t *vfu_ctx;
};
+static void vfu_object_init_ctx(VfuObject *o, Error **errp);
+
static bool vfu_object_auto_shutdown(void)
{
bool auto_shutdown = true;
@@ -107,6 +116,11 @@ static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name,
{
VfuObject *o = VFU_OBJECT(obj);
+ if (o->vfu_ctx) {
+ error_setg(errp, "vfu: Unable to set socket property - server busy");
+ return;
+ }
+
qapi_free_SocketAddress(o->socket);
o->socket = NULL;
@@ -122,17 +136,69 @@ static void vfu_object_set_socket(Object *obj, Visitor *v, const char *name,
}
trace_vfu_prop("socket", o->socket->u.q_unix.path);
+
+ vfu_object_init_ctx(o, errp);
}
static void vfu_object_set_device(Object *obj, const char *str, Error **errp)
{
VfuObject *o = VFU_OBJECT(obj);
+ if (o->vfu_ctx) {
+ error_setg(errp, "vfu: Unable to set device property - server busy");
+ return;
+ }
+
g_free(o->device);
o->device = g_strdup(str);
trace_vfu_prop("device", str);
+
+ vfu_object_init_ctx(o, errp);
+}
+
+/*
+ * TYPE_VFU_OBJECT depends on the availability of the 'socket' and 'device'
+ * properties. It also depends on devices instantiated in QEMU. These
+ * dependencies are not available during the instance_init phase of this
+ * object's life-cycle. As such, the server is initialized after the
+ * machine is setup. machine_init_done_notifier notifies TYPE_VFU_OBJECT
+ * when the machine is setup, and the dependencies are available.
+ */
+static void vfu_object_machine_done(Notifier *notifier, void *data)
+{
+ VfuObject *o = container_of(notifier, VfuObject, machine_done);
+ Error *err = NULL;
+
+ vfu_object_init_ctx(o, &err);
+
+ if (err) {
+ error_propagate(&error_abort, err);
+ }
+}
+
+static void vfu_object_init_ctx(VfuObject *o, Error **errp)
+{
+ ERRP_GUARD();
+
+ if (o->vfu_ctx || !o->socket || !o->device ||
+ !phase_check(PHASE_MACHINE_READY)) {
+ return;
+ }
+
+ if (o->err) {
+ error_propagate(errp, o->err);
+ o->err = NULL;
+ return;
+ }
+
+ o->vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, o->socket->u.q_unix.path, 0,
+ o, VFU_DEV_TYPE_PCI);
+ if (o->vfu_ctx == NULL) {
+ error_setg(errp, "vfu: Failed to create context - %s", strerror(errno));
+ return;
+ }
}
static void vfu_object_init(Object *obj)
@@ -147,6 +213,12 @@ static void vfu_object_init(Object *obj)
TYPE_VFU_OBJECT, TYPE_REMOTE_MACHINE);
return;
}
+
+ if (!phase_check(PHASE_MACHINE_READY)) {
+ o->machine_done.notify = vfu_object_machine_done;
+ qemu_add_machine_init_done_notifier(&o->machine_done);
+ }
+
}
static void vfu_object_finalize(Object *obj)
@@ -160,6 +232,11 @@ static void vfu_object_finalize(Object *obj)
o->socket = NULL;
+ if (o->vfu_ctx) {
+ vfu_destroy_ctx(o->vfu_ctx);
+ o->vfu_ctx = NULL;
+ }
+
g_free(o->device);
o->device = NULL;
@@ -167,6 +244,11 @@ static void vfu_object_finalize(Object *obj)
if (!k->nr_devs && vfu_object_auto_shutdown()) {
qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN);
}
+
+ if (o->machine_done.notify) {
+ qemu_remove_machine_init_done_notifier(&o->machine_done);
+ o->machine_done.notify = NULL;
+ }
}
static void vfu_object_class_init(ObjectClass *klass, void *data)
--
2.20.1
next prev parent reply other threads:[~2022-06-10 19:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-10 19:50 [PATCH v11 00/14] vfio-user server in QEMU Jagannathan Raman
2022-06-10 19:50 ` [PATCH v11 01/14] qdev: unplug blocker for devices Jagannathan Raman
2022-06-10 19:50 ` [PATCH v11 02/14] remote/machine: add HotplugHandler for remote machine Jagannathan Raman
2022-06-10 19:50 ` [PATCH v11 03/14] remote/machine: add vfio-user property Jagannathan Raman
2022-06-10 19:50 ` [PATCH v11 04/14] vfio-user: build library Jagannathan Raman
2022-06-10 19:50 ` [PATCH v11 05/14] vfio-user: define vfio-user-server object Jagannathan Raman
2022-06-10 19:50 ` Jagannathan Raman [this message]
2022-06-10 19:50 ` [PATCH v11 07/14] vfio-user: find and init PCI device Jagannathan Raman
2022-06-10 19:50 ` [PATCH v11 08/14] vfio-user: run vfio-user context Jagannathan Raman
2022-06-10 19:50 ` [PATCH v11 09/14] vfio-user: handle PCI config space accesses Jagannathan Raman
2022-06-10 19:50 ` [PATCH v11 10/14] vfio-user: IOMMU support for remote device Jagannathan Raman
2022-06-10 19:50 ` [PATCH v11 11/14] vfio-user: handle DMA mappings Jagannathan Raman
2022-06-10 19:50 ` [PATCH v11 12/14] vfio-user: handle PCI BAR accesses Jagannathan Raman
2022-06-10 19:50 ` [PATCH v11 13/14] vfio-user: handle device interrupts Jagannathan Raman
2022-06-13 15:30 ` Stefan Hajnoczi
2022-06-10 19:50 ` [PATCH v11 14/14] vfio-user: handle reset of remote device Jagannathan Raman
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=1e6e6d54e8f84144da6f02497f9e6d3b30c3488a.1654889541.git.jag.raman@oracle.com \
--to=jag.raman@oracle.com \
--cc=alex.williamson@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=bleal@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=eduardo@habkost.net \
--cc=elena.ufimtseva@oracle.com \
--cc=f4bug@amsat.org \
--cc=imammedo@redhat.com \
--cc=john.g.johnson@oracle.com \
--cc=john.levon@nutanix.com \
--cc=kanth.ghatraju@oracle.com \
--cc=marcandre.lureau@redhat.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanha@redhat.com \
--cc=thanos.makatos@nutanix.com \
--cc=thuth@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).