diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2021-02-04 14:52:16 +0400 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2021-02-04 15:58:54 +0100 |
commit | bd690feb155416defd1119aaad1c9fbe623c865f (patch) | |
tree | 85b9da9e2827a2db4fba624a512b740fcc339867 | |
parent | 72e631c6ac72363924f6c7030a99a7900d15451e (diff) |
vhost-user-gpu: handle display-info 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-5-marcandre.lureau@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
-rw-r--r-- | contrib/vhost-user-gpu/vhost-user-gpu.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-gpu/vhost-user-gpu.c index 7dcc02966c..b27990ffdb 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -261,10 +261,33 @@ vg_ctrl_response_nodata(VuGpu *g, vg_ctrl_response(g, cmd, &resp, sizeof(resp)); } + +static gboolean +get_display_info_cb(gint fd, GIOCondition condition, gpointer user_data) +{ + struct virtio_gpu_resp_display_info dpy_info = { {} }; + VuGpu *vg = user_data; + struct virtio_gpu_ctrl_command *cmd = QTAILQ_LAST(&vg->fenceq); + + g_debug("disp info cb"); + assert(cmd->cmd_hdr.type == VIRTIO_GPU_CMD_GET_DISPLAY_INFO); + if (!vg_recv_msg(vg, VHOST_USER_GPU_GET_DISPLAY_INFO, + sizeof(dpy_info), &dpy_info)) { + return G_SOURCE_CONTINUE; + } + + QTAILQ_REMOVE(&vg->fenceq, cmd, next); + vg_ctrl_response(vg, cmd, &dpy_info.hdr, sizeof(dpy_info)); + + vg->wait_in = 0; + vg_handle_ctrl(&vg->dev.parent, 0); + + return G_SOURCE_REMOVE; +} + void vg_get_display_info(VuGpu *vg, struct virtio_gpu_ctrl_command *cmd) { - struct virtio_gpu_resp_display_info dpy_info = { {} }; VhostUserGpuMsg msg = { .request = VHOST_USER_GPU_GET_DISPLAY_INFO, .size = 0, @@ -273,11 +296,9 @@ vg_get_display_info(VuGpu *vg, struct virtio_gpu_ctrl_command *cmd) assert(vg->wait_in == 0); vg_send_msg(vg, &msg, -1); - if (!vg_recv_msg(vg, msg.request, sizeof(dpy_info), &dpy_info)) { - return; - } - - vg_ctrl_response(vg, cmd, &dpy_info.hdr, sizeof(dpy_info)); + vg->wait_in = g_unix_fd_add(vg->sock_fd, G_IO_IN | G_IO_HUP, + get_display_info_cb, vg); + cmd->state = VG_CMD_STATE_PENDING; } static void |