On 2026/11/13 9:29, Marc-André Lureau wrote:
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.
This suffers from the same issue the following patch series addresses:
https://lore.kernel.org/qemu-devel/[email protected]/
("[PATCH v3 0/9] virtio-gpu: Do not wait for the main thread during reset")
Regards,
Akihiko Odaki
Reported-by: Dmitry R <[email protected]>
Signed-off-by: Marc-André Lureau <[email protected]>
---
hw/display/vhost-user-gpu.c | 39 +++++++++++++++++++++++++++++++++++++--
include/hw/virtio/virtio-gpu.h | 4 ++++
2 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index d3b720d08a73..46e7fc136583 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 {
@@ -635,9 +636,9 @@ vhost_user_gpu_instance_finalize(Object *obj)
}
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 +654,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,9 +719,23 @@ 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;
}
+static void
+vhost_user_gpu_device_unrealize(DeviceState *qdev)
+{
+ VhostUserGPU *g = VHOST_USER_GPU(qdev);
+
+ g_clear_pointer(&g->reset_bh, qemu_bh_delete);
+ qemu_cond_destroy(&g->reset_cond);
+
+ virtio_gpu_base_device_unrealize(qdev);
+}
+
static struct vhost_dev *vhost_user_gpu_get_vhost(VirtIODevice *vdev)
{
VhostUserGPU *g = VHOST_USER_GPU(vdev);
@@ -722,6 +756,7 @@ vhost_user_gpu_class_init(ObjectClass *klass, const void
*data)
vgc->gl_flushed = vhost_user_gpu_gl_flushed;
vdc->realize = vhost_user_gpu_device_realize;
+ vdc->unrealize = vhost_user_gpu_device_unrealize;
vdc->reset = vhost_user_gpu_reset;
vdc->set_status = vhost_user_gpu_set_status;
vdc->guest_notifier_mask = vhost_user_gpu_guest_notifier_mask;
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