vhost_user_gpu_reset() clears VirtIOGPUBase::enable, which makes the
virtio-vga wrapper fall back to the legacy VGA display. The console is
left in a GL scanout though, so qemu_console_surface() returns NULL and
vga_update_display() dereferences it when the display refreshes: the
host crashes on guest reboot or driver reload with a GL display.

Release the frontend dmabufs, disable the GL scanout and install a
placeholder surface for each output, as virtio_gpu_reset() does for the
non vhost-user device.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/4846
Reported-by: Dmitry R <[email protected]>
Tested-by: Dmitry R <[email protected]>
Signed-off-by: Marc-André Lureau <[email protected]>
---
 hw/display/vhost-user-gpu.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index c09aca041135..d3b720d08a73 100644
--- a/hw/display/vhost-user-gpu.c
+++ b/hw/display/vhost-user-gpu.c
@@ -638,6 +638,20 @@ static void
 vhost_user_gpu_reset(VirtIODevice *vdev)
 {
     VhostUserGPU *g = VHOST_USER_GPU(vdev);
+    int i;
+
+    /* release the scanouts before virtio_gpu_base_reset() drops ds */
+    for (i = 0; i < g->parent_obj.conf.max_outputs; i++) {
+        struct virtio_gpu_scanout *scanout = &g->parent_obj.scanout[i];
+
+        /* the guest may have left a GL scanout behind */
+        if (g->dmabuf[i]) {
+            qemu_console_gl_release_dmabuf(scanout->con, g->dmabuf[i]);
+            g_clear_pointer(&g->dmabuf[i], qemu_dmabuf_free);
+        }
+        qemu_console_gl_scanout_disable(scanout->con);
+        qemu_console_set_surface(scanout->con, NULL);
+    }
 
     virtio_gpu_base_reset(VIRTIO_GPU_BASE(vdev));
 

-- 
2.56.0.116.g6de20f6092dc


Reply via email to