All of lore.kernel.org
 help / color / mirror / Atom feed
From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>, kraxel@redhat.com
Subject: [PATCH v2 02/20] vhost-user-gpu: handle vhost-user-gpu features in a callback
Date: Thu,  4 Feb 2021 14:52:14 +0400	[thread overview]
Message-ID: <20210204105232.834642-3-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20210204105232.834642-1-marcandre.lureau@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Fixes a deadlock where the backend calls QEMU, while QEMU also calls the
backend simultaneously, both ends waiting for each other.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 contrib/vhost-user-gpu/vugpu.h          |  2 +-
 contrib/vhost-user-gpu/vhost-user-gpu.c | 37 ++++++++++++++++++-------
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/contrib/vhost-user-gpu/vugpu.h b/contrib/vhost-user-gpu/vugpu.h
index ad664c4df8..86f3ac86aa 100644
--- a/contrib/vhost-user-gpu/vugpu.h
+++ b/contrib/vhost-user-gpu/vugpu.h
@@ -118,7 +118,7 @@ typedef struct VuGpu {
     int sock_fd;
     int drm_rnode_fd;
     GSource *renderer_source;
-    guint wait_ok;
+    guint wait_in;
 
     bool virgl;
     bool virgl_inited;
diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-gpu/vhost-user-gpu.c
index f445ef28ec..85c16404fb 100644
--- a/contrib/vhost-user-gpu/vhost-user-gpu.c
+++ b/contrib/vhost-user-gpu/vhost-user-gpu.c
@@ -124,7 +124,7 @@ source_wait_cb(gint fd, GIOCondition condition, gpointer user_data)
     }
 
     /* resume */
-    g->wait_ok = 0;
+    g->wait_in = 0;
     vg_handle_ctrl(&g->dev.parent, 0);
 
     return G_SOURCE_REMOVE;
@@ -133,8 +133,8 @@ source_wait_cb(gint fd, GIOCondition condition, gpointer user_data)
 void
 vg_wait_ok(VuGpu *g)
 {
-    assert(g->wait_ok == 0);
-    g->wait_ok = g_unix_fd_add(g->sock_fd, G_IO_IN | G_IO_HUP,
+    assert(g->wait_in == 0);
+    g->wait_in = g_unix_fd_add(g->sock_fd, G_IO_IN | G_IO_HUP,
                                source_wait_cb, g);
 }
 
@@ -270,7 +270,7 @@ vg_get_display_info(VuGpu *vg, struct virtio_gpu_ctrl_command *cmd)
         .size = 0,
     };
 
-    assert(vg->wait_ok == 0);
+    assert(vg->wait_in == 0);
 
     vg_send_msg(vg, &msg, -1);
     if (!vg_recv_msg(vg, msg.request, sizeof(dpy_info), &dpy_info)) {
@@ -815,7 +815,7 @@ vg_handle_ctrl(VuDev *dev, int qidx)
     size_t len;
 
     for (;;) {
-        if (vg->wait_ok != 0) {
+        if (vg->wait_in != 0) {
             return;
         }
 
@@ -969,18 +969,17 @@ vg_queue_set_started(VuDev *dev, int qidx, bool started)
     }
 }
 
-static void
-set_gpu_protocol_features(VuGpu *g)
+static gboolean
+protocol_features_cb(gint fd, GIOCondition condition, gpointer user_data)
 {
+    VuGpu *g = user_data;
     uint64_t u64;
     VhostUserGpuMsg msg = {
         .request = VHOST_USER_GPU_GET_PROTOCOL_FEATURES
     };
 
-    assert(g->wait_ok == 0);
-    vg_send_msg(g, &msg, -1);
     if (!vg_recv_msg(g, msg.request, sizeof(u64), &u64)) {
-        return;
+        return G_SOURCE_CONTINUE;
     }
 
     msg = (VhostUserGpuMsg) {
@@ -989,6 +988,24 @@ set_gpu_protocol_features(VuGpu *g)
         .payload.u64 = 0
     };
     vg_send_msg(g, &msg, -1);
+
+    g->wait_in = 0;
+    vg_handle_ctrl(&g->dev.parent, 0);
+
+    return G_SOURCE_REMOVE;
+}
+
+static void
+set_gpu_protocol_features(VuGpu *g)
+{
+    VhostUserGpuMsg msg = {
+        .request = VHOST_USER_GPU_GET_PROTOCOL_FEATURES
+    };
+
+    vg_send_msg(g, &msg, -1);
+    assert(g->wait_in == 0);
+    g->wait_in = g_unix_fd_add(g->sock_fd, G_IO_IN | G_IO_HUP,
+                               protocol_features_cb, g);
 }
 
 static int
-- 
2.29.0



  parent reply	other threads:[~2021-02-04 10:54 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-04 10:52 [PATCH v2 00/20] Various vhost-user-gpu & UI fixes marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 01/20] vhost-user-gpu: check backend for EDID support marcandre.lureau
2021-02-04 10:52 ` marcandre.lureau [this message]
2021-02-04 10:52 ` [PATCH v2 03/20] vhost-user-gpu: use an extandable state enum for commands marcandre.lureau
2021-02-04 11:26   ` Philippe Mathieu-Daudé
2021-02-04 13:43     ` Philippe Mathieu-Daudé
2021-02-04 10:52 ` [PATCH v2 04/20] vhost-user-gpu: handle display-info in a callback marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 05/20] ui: remove extra #ifdef CONFIG_OPENGL marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 06/20] ui: remove gl_ctx_get_current marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 07/20] ui: add gd_gl_area_scanout_disable marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 08/20] ui: annotate DCLOps callback requirements marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 09/20] ui: remove console_has_gl_dmabuf() marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 10/20] vhost-user-gpu: add a configuration flag for dmabuf usage marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 11/20] ui: add an optional get_flags callback to GraphicHwOps marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 12/20] ui: add a DCLOps callback to check dmabuf support marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 13/20] ui: check hw requirements during DCL registration marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 14/20] ui: add qemu_egl_has_dmabuf helper marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 15/20] ui: check gtk-egl dmabuf support marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 16/20] ui: add egl dmabuf import to gtkglarea marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 17/20] virtio-gpu: avoid re-entering cmdq processing marcandre.lureau
2021-02-05  8:09   ` Alexander Bulekov
2021-02-04 10:52 ` [PATCH v2 18/20] display/ui: add a callback to indicate GL state is flushed marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 19/20] chardev: check if the chardev is registered for yanking marcandre.lureau
2021-02-04 10:52 ` [PATCH v2 20/20] tests: add some virtio-gpu & vhost-user-gpu acceptance test marcandre.lureau
2021-02-16 16:34   ` Alex Bennée
2021-02-16 17:43     ` Cleber Rosa
2021-02-17  8:27       ` Marc-André Lureau
2021-02-17 12:12         ` Alex Bennée

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=20210204105232.834642-3-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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.