Commit d6e5165558 for qemu.org

commit d6e516555805b95a7a935c3fd74568dabf7796f2
Author: Marc-André Lureau <marcandre.lureau@redhat.com>
Date:   Mon Aug 31 17:14:44 2026 +0400

    contrib/vhost-user-gpu: disable scanouts on resource unref

    virgl_cmd_resource_unref() destroys the virgl renderer resource without
    first disabling any scanouts that reference it. The QEMU frontend then
    holds a stale DMA-BUF until another DMABUF_SCANOUT message arrives.

    Send a DMABUF_SCANOUT disable message (fd=-1) for each affected scanout
    before destroying the resource.

    Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
    Fixes: d52c454aadcd ("contrib: add vhost-user-gpu")
    Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c
index 20bae57d0f..5a5f9f14c8 100644
--- a/contrib/vhost-user-gpu/virgl.c
+++ b/contrib/vhost-user-gpu/virgl.c
@@ -113,6 +113,18 @@ virgl_cmd_resource_unref(VuGpu *g,

     VUGPU_FILL_CMD(unref);

+    for (int i = 0; i < VIRTIO_GPU_MAX_SCANOUTS; i++) {
+        if (g->scanout[i].resource_id == unref.resource_id) {
+            VhostUserGpuMsg msg = {
+                .request = VHOST_USER_GPU_DMABUF_SCANOUT,
+                .size = sizeof(VhostUserGpuDMABUFScanout),
+                .payload.dmabuf_scanout.scanout_id = i,
+            };
+            vg_send_msg(g, &msg, -1);
+            g->scanout[i].resource_id = 0;
+        }
+    }
+
     virgl_renderer_resource_detach_iov(unref.resource_id,
                                        &res_iovs,
                                        &num_iovs);