Commit 94ebf42381 for qemu.org

commit 94ebf423816fa9ec7085f77876753096f0abcac4
Author: Marc-André Lureau <marcandre.lureau@redhat.com>
Date:   Fri Aug 21 19:27:28 2026 +0400

    virtio-gpu/virgl: disable scanouts on resource unref

    Disable scanouts referencing a resource being unreferenced.

    The scanout disable callbacks may change the current GL context, so
    restore the renderer context before detaching and unreferencing the
    resource.

    Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
    Fixes: 9d9e152136bd ("virtio-gpu: add 3d mode and virgl rendering support.")
    Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 439a6e1c1c..494be3fb4f 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -431,6 +431,7 @@ virtio_gpu_virgl_resource_unref(VirtIOGPU *g,
 {
     struct iovec *res_iovs = NULL;
     int num_iovs = 0;
+    int i;
 #if VIRGL_VERSION_MAJOR >= 1
     int ret;

@@ -443,6 +444,13 @@ virtio_gpu_virgl_resource_unref(VirtIOGPU *g,
     }
 #endif

+    for (i = 0; i < g->parent_obj.conf.max_outputs; i++) {
+        if (g->parent_obj.scanout[i].resource_id == res->base.resource_id) {
+            virtio_gpu_disable_scanout(g, i);
+        }
+    }
+
+    virgl_renderer_force_ctx_0();
     virgl_renderer_resource_detach_iov(res->base.resource_id,
                                        &res_iovs,
                                        &num_iovs);