vhost_user_gpu_reset() runs on the vCPU thread when the guest writes the device status. Installing the placeholder surface there calls the display listener without the EGL context being current, so the D-Bus listener receives a surface without a texture and aborts on the tex_id assertion.
Defer the display cleanup to a bottom half, as virtio_gpu_reset() does, and wait for it when reset is triggered from a vCPU thread. Reported-by: Dmitry R <[email protected]> Signed-off-by: Marc-André Lureau <[email protected]> --- hw/display/vhost-user-gpu.c | 30 ++++++++++++++++++++++++++++-- include/hw/virtio/virtio-gpu.h | 4 ++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index d3b720d08a73..78df9abd3d0b 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -18,6 +18,7 @@ #include "chardev/char-fe.h" #include "qapi/error.h" #include "migration/blocker.h" +#include "system/cpus.h" #include "standard-headers/drm/drm_fourcc.h" typedef enum VhostUserGpuRequest { @@ -631,13 +632,16 @@ vhost_user_gpu_instance_finalize(Object *obj) { VhostUserGPU *g = VHOST_USER_GPU(obj); + g_clear_pointer(&g->reset_bh, qemu_bh_delete); + qemu_cond_destroy(&g->reset_cond); + object_unref(OBJECT(g->vhost)); } static void -vhost_user_gpu_reset(VirtIODevice *vdev) +vhost_user_gpu_reset_bh(void *opaque) { - VhostUserGPU *g = VHOST_USER_GPU(vdev); + VhostUserGPU *g = VHOST_USER_GPU(opaque); int i; /* release the scanouts before virtio_gpu_base_reset() drops ds */ @@ -653,6 +657,25 @@ vhost_user_gpu_reset(VirtIODevice *vdev) qemu_console_set_surface(scanout->con, NULL); } + g->reset_finished = true; + qemu_cond_signal(&g->reset_cond); +} + +static void +vhost_user_gpu_reset(VirtIODevice *vdev) +{ + VhostUserGPU *g = VHOST_USER_GPU(vdev); + + if (qemu_in_vcpu_thread()) { + g->reset_finished = false; + qemu_bh_schedule(g->reset_bh); + while (!g->reset_finished) { + qemu_cond_wait_bql(&g->reset_cond); + } + } else { + aio_bh_call(g->reset_bh); + } + virtio_gpu_base_reset(VIRTIO_GPU_BASE(vdev)); vhost_user_backend_stop(g->vhost); @@ -699,6 +722,9 @@ vhost_user_gpu_device_realize(DeviceState *qdev, Error **errp) return; } + g->reset_bh = virtio_bh_io_new_guarded(qdev, vhost_user_gpu_reset_bh, g); + qemu_cond_init(&g->reset_cond); + g->vhost_gpu_fd = -1; } diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 631dfc63a4d4..c8cb91032968 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -276,6 +276,10 @@ struct VhostUserGPU { CharFrontend vhost_chr; QemuDmaBuf *dmabuf[VIRTIO_GPU_MAX_SCANOUTS]; bool backend_blocked; + + QEMUBH *reset_bh; + QemuCond reset_cond; + bool reset_finished; }; #define MAX_SLOTS 4096 -- 2.56.0.116.g6de20f6092dc
