vhost-user-gpu: handle vhost-user-gpu features in a callback

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>
Message-Id: <20210204105232.834642-3-marcandre.lureau@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Marc-André Lureau 2021-02-04 14:52:14 +04:00 committed by Gerd Hoffmann
parent 326a51f32d
commit 1f83ea8dbd
2 changed files with 28 additions and 11 deletions

View file

@ -124,7 +124,7 @@ source_wait_cb(gint fd, GIOCondition condition, gpointer user_data)
} }
/* resume */ /* resume */
g->wait_ok = 0; g->wait_in = 0;
vg_handle_ctrl(&g->dev.parent, 0); vg_handle_ctrl(&g->dev.parent, 0);
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
@ -133,8 +133,8 @@ source_wait_cb(gint fd, GIOCondition condition, gpointer user_data)
void void
vg_wait_ok(VuGpu *g) vg_wait_ok(VuGpu *g)
{ {
assert(g->wait_ok == 0); assert(g->wait_in == 0);
g->wait_ok = g_unix_fd_add(g->sock_fd, G_IO_IN | G_IO_HUP, g->wait_in = g_unix_fd_add(g->sock_fd, G_IO_IN | G_IO_HUP,
source_wait_cb, g); source_wait_cb, g);
} }
@ -270,7 +270,7 @@ vg_get_display_info(VuGpu *vg, struct virtio_gpu_ctrl_command *cmd)
.size = 0, .size = 0,
}; };
assert(vg->wait_ok == 0); assert(vg->wait_in == 0);
vg_send_msg(vg, &msg, -1); vg_send_msg(vg, &msg, -1);
if (!vg_recv_msg(vg, msg.request, sizeof(dpy_info), &dpy_info)) { 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; size_t len;
for (;;) { for (;;) {
if (vg->wait_ok != 0) { if (vg->wait_in != 0) {
return; return;
} }
@ -969,18 +969,17 @@ vg_queue_set_started(VuDev *dev, int qidx, bool started)
} }
} }
static void static gboolean
set_gpu_protocol_features(VuGpu *g) protocol_features_cb(gint fd, GIOCondition condition, gpointer user_data)
{ {
VuGpu *g = user_data;
uint64_t u64; uint64_t u64;
VhostUserGpuMsg msg = { VhostUserGpuMsg msg = {
.request = VHOST_USER_GPU_GET_PROTOCOL_FEATURES .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)) { if (!vg_recv_msg(g, msg.request, sizeof(u64), &u64)) {
return; return G_SOURCE_CONTINUE;
} }
msg = (VhostUserGpuMsg) { msg = (VhostUserGpuMsg) {
@ -989,6 +988,24 @@ set_gpu_protocol_features(VuGpu *g)
.payload.u64 = 0 .payload.u64 = 0
}; };
vg_send_msg(g, &msg, -1); 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 static int

View file

@ -118,7 +118,7 @@ typedef struct VuGpu {
int sock_fd; int sock_fd;
int drm_rnode_fd; int drm_rnode_fd;
GSource *renderer_source; GSource *renderer_source;
guint wait_ok; guint wait_in;
bool virgl; bool virgl;
bool virgl_inited; bool virgl_inited;