From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653352; cv=none; d=zohomail.com; s=zohoarc; b=UNn+FX2sgC2e5Nr/FclJ86tzJkKI96s+g7+sbAd5nkVpri5xy1apZMZvK/iecCLEYyZyrTyqCr4yHof7JIT9d44bomSlOwg/HZEh2F96Zc5l7WnLDY5hH/4alPAdYxV5FmM4e9PC7QTJrob3xDHnRX4Qj0CcXvTngBa0KXFGaBg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653352; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=m+xgntv80vPWN2sXFMW9Q2X+T+pL6meD9PD/ScowyWs=; b=GLK2mvW0GgU8WiAylf1ESp/Jt+8MxlXgP7+vPvRT7S5m2IqrqwfIjHJwwVtYHwUnaz4fdcksI1QQB6iYCx+82f8qMte745ZhEhue160T7o6pxB3m2YrZrZZhpKrVeh2BEf733El1sr1eYvP14iBgFePKv82BUfCsVxylC89erHs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653352064199.75128687185043; Tue, 25 Aug 2026 03:22:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoIH-0005rn-Ol; Tue, 25 Aug 2026 06:22:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoIG-0005rb-Ji for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:22:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoIE-0005dQ-K1 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:22:12 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-646-wf5infppOayN8zflzJ1EKA-1; Tue, 25 Aug 2026 06:22:06 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BE742191FCE6; Tue, 25 Aug 2026 10:22:04 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 70B9F30002EE; Tue, 25 Aug 2026 10:21:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m+xgntv80vPWN2sXFMW9Q2X+T+pL6meD9PD/ScowyWs=; b=ZygmIrYIAkbne7fcF4qSnE5C58J4uv0YmepjQKjkI/Uf9d/haCWHuiSnoFG2DZBcxlNTF8 FDGzc6M16fRq2aI5wEWk7Z6+q+fbAw9lxu4sUO1nTTWTeEhlMIfA8rB0cA/Tg4I0qK8VA7 W3+uAd3M46WKaWFv7xo0H8vxs7x1drw= X-MC-Unique: wf5infppOayN8zflzJ1EKA-1 X-Mimecast-MFC-AGG-ID: wf5infppOayN8zflzJ1EKA_1787653325 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:38 +0400 Subject: [PATCH 01/18] ui/gtk: move GL fence tracking from QemuDmaBuf to VirtualGfxConsole MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-1-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=12691; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=bqrKK0ekdQuah4t//r7lwritNgUHmLjRXaltcOjXTdg=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyXuaTvqz3z+SEuiHP3leqYBes/n+R1XYs7h 6BtO4z8HPCJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1slwAKCRDa6OEJdZac 5dkPD/4hrzd5XP/9e1Am4jXjkL7jgmY+GswxZ/qixIiTwOKuu7fqswzNnk/L8A4ncD1FcQLol// D6RBYriN+c/K5icWplofoOyJtnaqBzpLf0PPVLzgytbNdSOFeAuc4iy678X7Wpi4Hu7awrjofVe WE1tPaR8tnygdmMfRyM7s2JxMyWaXei2UTNwznMKW81XY13p9fZzu4oueckFCWm/uRcBuADznwL Nu7QMc8crWaBpwuMsGOjQLVAiuHj7zwjz/LJsv0JM82Dt3fDP/fD0YjrF7yseO0iNThSE24QimB SWWlc8//1JjJUN/cnLvgIRn+D/i9Pt8A8sfx/an9aSO1/UVUMLW8Mtrcpufcb3UFoVYDXgL1PUd 3JNxFGAu19zXhNmwwoSYLTFFSUqFNJj6+mtBHlbbFsIav0GH9EUyiq2nPg43oLJnnrtouaMkwOV 0YG2memTUDMoA4kB1Lqf1WINxKr+DL2c1QG4n21LLGv2SjCiUcIMqJbCljjHHAYV8wFlBT6A9uJ k81N/w1RhDC37PS6dIyVSQBnQYL2GG/WNX1k3HRoZrNRIPuUt3F6S9fOnFaQHymRs540duHLUfu ljenG1Ofkh8yAjt5SoY7KoTMvMaJ/1uiLmMfjvGsfUAvtXf0KZqa0gVuWtJnIdvFg/3GDkvigB2 qHmsh6xpLP4hsTQ== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653354843158500 The sync and fence_fd fields on QemuDmaBuf are only used by the GTK display backend for GPU fence synchronization during draw. They are not intrinsic properties of the DMA-BUF itself but transient GL state tied to the display listener. Move fence_fd to VirtualGfxConsole and keep the EGL sync local to the draw operation. Change egl_dmabuf_create_sync() and egl_dmabuf_create_fence() to return values instead of storing them on the dmabuf. This makes the fence lifecycle independent of the dmabuf lifetime. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/ui/dmabuf.h | 4 ---- include/ui/egl-helpers.h | 4 ++-- include/ui/gtk.h | 8 +++++--- ui/dmabuf.c | 29 ----------------------------- ui/egl-helpers.c | 15 ++++++++------- ui/gtk-egl.c | 30 ++++++++++++++++-------------- ui/gtk-gl-area.c | 12 +++--------- ui/gtk.c | 31 +++++++++++++++++++++++-------- 8 files changed, 57 insertions(+), 76 deletions(-) diff --git a/include/ui/dmabuf.h b/include/ui/dmabuf.h index 3decdca4979c..381583bd536c 100644 --- a/include/ui/dmabuf.h +++ b/include/ui/dmabuf.h @@ -41,13 +41,9 @@ uint32_t qemu_dmabuf_get_y(QemuDmaBuf *dmabuf); uint32_t qemu_dmabuf_get_backing_width(QemuDmaBuf *dmabuf); uint32_t qemu_dmabuf_get_backing_height(QemuDmaBuf *dmabuf); bool qemu_dmabuf_get_y0_top(QemuDmaBuf *dmabuf); -void *qemu_dmabuf_get_sync(QemuDmaBuf *dmabuf); -int32_t qemu_dmabuf_get_fence_fd(QemuDmaBuf *dmabuf); bool qemu_dmabuf_get_allow_fences(QemuDmaBuf *dmabuf); bool qemu_dmabuf_get_draw_submitted(QemuDmaBuf *dmabuf); void qemu_dmabuf_set_texture(QemuDmaBuf *dmabuf, uint32_t texture); -void qemu_dmabuf_set_fence_fd(QemuDmaBuf *dmabuf, int32_t fence_fd); -void qemu_dmabuf_set_sync(QemuDmaBuf *dmabuf, void *sync); void qemu_dmabuf_set_draw_submitted(QemuDmaBuf *dmabuf, bool draw_submitte= d); =20 #endif diff --git a/include/ui/egl-helpers.h b/include/ui/egl-helpers.h index 405ddd912591..023427b505ed 100644 --- a/include/ui/egl-helpers.h +++ b/include/ui/egl-helpers.h @@ -54,8 +54,8 @@ bool egl_dmabuf_export_texture(uint32_t tex_id, int *fd, = EGLint *offset, =20 void egl_dmabuf_import_texture(QemuDmaBuf *dmabuf); void egl_dmabuf_release_texture(QemuDmaBuf *dmabuf); -void egl_dmabuf_create_sync(QemuDmaBuf *dmabuf); -void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf); +EGLSyncKHR egl_create_sync(void); +int egl_create_fence(EGLSyncKHR sync); =20 #endif =20 diff --git a/include/ui/gtk.h b/include/ui/gtk.h index 5c9c34a069ea..4b4ef50e3701 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -58,6 +58,7 @@ typedef struct VirtualGfxConsole { bool y0_top; bool scanout_mode; bool has_dmabuf; + int gl_fence_fd; #endif } VirtualGfxConsole; =20 @@ -160,7 +161,7 @@ extern bool gtk_use_gl_area; /* ui/gtk.c */ void gd_update_windowsize(VirtualConsole *vc); void gd_update_monitor_refresh_rate(VirtualConsole *vc, GtkWidget *widget); -void gd_hw_gl_flushed(void *vc); +void gd_gl_wait_sync(VirtualConsole *vc, void *sync); =20 /* ui/gtk-egl.c */ void gd_egl_init(VirtualConsole *vc); @@ -190,8 +191,9 @@ void gd_egl_cursor_position(DisplayChangeListener *dcl, uint32_t pos_x, uint32_t pos_y); void gd_egl_flush(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h); -void gd_egl_scanout_flush(DisplayChangeListener *dcl, - uint32_t x, uint32_t y, uint32_t w, uint32_t h); +void *gd_egl_scanout_flush(DisplayChangeListener *dcl, + uint32_t x, uint32_t y, + uint32_t w, uint32_t h); void gtk_egl_init(DisplayGLMode mode); int gd_egl_make_current(DisplayGLCtx *dgc, QEMUGLContext ctx); diff --git a/ui/dmabuf.c b/ui/dmabuf.c index 7433a268f0df..b61dc7ad2783 100644 --- a/ui/dmabuf.c +++ b/ui/dmabuf.c @@ -25,8 +25,6 @@ struct QemuDmaBuf { uint32_t backing_width; uint32_t backing_height; bool y0_top; - void *sync; - int fence_fd; bool allow_fences; bool draw_submitted; }; @@ -57,7 +55,6 @@ QemuDmaBuf *qemu_dmabuf_new(uint32_t width, uint32_t heig= ht, memcpy(dmabuf->fd, dmabuf_fd, num_planes * sizeof(*dmabuf_fd)); dmabuf->allow_fences =3D allow_fences; dmabuf->y0_top =3D y0_top; - dmabuf->fence_fd =3D -1; dmabuf->num_planes =3D num_planes; =20 return dmabuf; @@ -208,20 +205,6 @@ bool qemu_dmabuf_get_y0_top(QemuDmaBuf *dmabuf) return dmabuf->y0_top; } =20 -void *qemu_dmabuf_get_sync(QemuDmaBuf *dmabuf) -{ - assert(dmabuf !=3D NULL); - - return dmabuf->sync; -} - -int32_t qemu_dmabuf_get_fence_fd(QemuDmaBuf *dmabuf) -{ - assert(dmabuf !=3D NULL); - - return dmabuf->fence_fd; -} - bool qemu_dmabuf_get_allow_fences(QemuDmaBuf *dmabuf) { assert(dmabuf !=3D NULL); @@ -242,18 +225,6 @@ void qemu_dmabuf_set_texture(QemuDmaBuf *dmabuf, uint3= 2_t texture) dmabuf->texture =3D texture; } =20 -void qemu_dmabuf_set_fence_fd(QemuDmaBuf *dmabuf, int32_t fence_fd) -{ - assert(dmabuf !=3D NULL); - dmabuf->fence_fd =3D fence_fd; -} - -void qemu_dmabuf_set_sync(QemuDmaBuf *dmabuf, void *sync) -{ - assert(dmabuf !=3D NULL); - dmabuf->sync =3D sync; -} - void qemu_dmabuf_set_draw_submitted(QemuDmaBuf *dmabuf, bool draw_submitte= d) { assert(dmabuf !=3D NULL); diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c index d689f187c4e5..54b4aa6e9fcb 100644 --- a/ui/egl-helpers.c +++ b/ui/egl-helpers.c @@ -432,7 +432,7 @@ void egl_dmabuf_release_texture(QemuDmaBuf *dmabuf) qemu_dmabuf_set_texture(dmabuf, 0); } =20 -void egl_dmabuf_create_sync(QemuDmaBuf *dmabuf) +EGLSyncKHR egl_create_sync(void) { EGLSyncKHR sync; =20 @@ -443,23 +443,24 @@ void egl_dmabuf_create_sync(QemuDmaBuf *dmabuf) sync =3D eglCreateSyncKHR(qemu_egl_display, EGL_SYNC_NATIVE_FENCE_ANDROID, NULL); if (sync !=3D EGL_NO_SYNC_KHR) { - qemu_dmabuf_set_sync(dmabuf, sync); + return sync; } } + + return NULL; } =20 -void egl_dmabuf_create_fence(QemuDmaBuf *dmabuf) +int egl_create_fence(EGLSyncKHR sync) { - void *sync =3D qemu_dmabuf_get_sync(dmabuf); - int fence_fd; + int fence_fd =3D -1; =20 if (sync) { fence_fd =3D eglDupNativeFenceFDANDROID(qemu_egl_display, sync); - qemu_dmabuf_set_fence_fd(dmabuf, fence_fd); eglDestroySyncKHR(qemu_egl_display, sync); - qemu_dmabuf_set_sync(dmabuf, NULL); } + + return fence_fd; } =20 #endif /* CONFIG_GBM */ diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index adc81f34b1c8..c671aabd11b3 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -68,7 +68,7 @@ void gd_egl_draw(VirtualConsole *vc) GdkWindow *window; #ifdef CONFIG_GBM QemuDmaBuf *dmabuf =3D vc->gfx.guest_fb.dmabuf; - int fence_fd; + EGLSyncKHR sync; #endif int ww, wh, pw, ph, gs; =20 @@ -94,7 +94,11 @@ void gd_egl_draw(VirtualConsole *vc) qemu_console_hw_gl_block(vc->gfx.dcl.con, true); } #endif - gd_egl_scanout_flush(&vc->gfx.dcl, 0, 0, vc->gfx.w, vc->gfx.h); +#ifdef CONFIG_GBM + sync =3D +#endif + gd_egl_scanout_flush(&vc->gfx.dcl, 0, 0, + vc->gfx.w, vc->gfx.h); =20 gd_update_scale(vc, ww, wh, surface_width(vc->gfx.ds), @@ -103,13 +107,7 @@ void gd_egl_draw(VirtualConsole *vc) glFlush(); #ifdef CONFIG_GBM if (dmabuf) { - egl_dmabuf_create_fence(dmabuf); - fence_fd =3D qemu_dmabuf_get_fence_fd(dmabuf); - if (fence_fd >=3D 0) { - qemu_set_fd_handler(fence_fd, gd_hw_gl_flushed, NULL, vc); - return; - } - qemu_console_hw_gl_block(vc->gfx.dcl.con, false); + gd_gl_wait_sync(vc, sync); } #endif } else { @@ -330,10 +328,12 @@ void gd_egl_cursor_position(DisplayChangeListener *dc= l, vc->gfx.cursor_y =3D pos_y * vc->gfx.scale_y; } =20 -void gd_egl_scanout_flush(DisplayChangeListener *dcl, - uint32_t x, uint32_t y, uint32_t w, uint32_t h) +EGLSyncKHR gd_egl_scanout_flush(DisplayChangeListener *dcl, + uint32_t x, uint32_t y, + uint32_t w, uint32_t h) { VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); + EGLSyncKHR sync =3D EGL_NO_SYNC_KHR; GdkWindow *window; int px_offset, py_offset; int gs; @@ -342,10 +342,10 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl, int fbw, fbh; =20 if (!vc->gfx.scanout_mode) { - return; + return sync; } if (!vc->gfx.guest_fb.framebuffer) { - return; + return sync; } =20 eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, @@ -391,11 +391,13 @@ void gd_egl_scanout_flush(DisplayChangeListener *dcl, =20 #ifdef CONFIG_GBM if (vc->gfx.guest_fb.dmabuf) { - egl_dmabuf_create_sync(vc->gfx.guest_fb.dmabuf); + sync =3D egl_create_sync(); } #endif =20 eglSwapBuffers(qemu_egl_display, vc->gfx.esurface); + + return sync; } =20 void gd_egl_flush(DisplayChangeListener *dcl, diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c index 29497019ee46..29d1b1e4116f 100644 --- a/ui/gtk-gl-area.c +++ b/ui/gtk-gl-area.c @@ -41,6 +41,7 @@ void gd_gl_area_draw(VirtualConsole *vc) { #ifdef CONFIG_GBM QemuDmaBuf *dmabuf =3D vc->gfx.guest_fb.dmabuf; + EGLSyncKHR sync =3D EGL_NO_SYNC_KHR; #endif int pw, ph, gs, y1, y2; int ww, wh; @@ -119,20 +120,13 @@ void gd_gl_area_draw(VirtualConsole *vc) GL_COLOR_BUFFER_BIT, GL_NEAREST); #ifdef CONFIG_GBM if (dmabuf) { - egl_dmabuf_create_sync(dmabuf); + sync =3D egl_create_sync(); } #endif glFlush(); #ifdef CONFIG_GBM if (dmabuf) { - int fence_fd; - egl_dmabuf_create_fence(dmabuf); - fence_fd =3D qemu_dmabuf_get_fence_fd(dmabuf); - if (fence_fd >=3D 0) { - qemu_set_fd_handler(fence_fd, gd_hw_gl_flushed, NULL, vc); - return; - } - qemu_console_hw_gl_block(vc->gfx.dcl.con, false); + gd_gl_wait_sync(vc, sync); } #endif } else { diff --git a/ui/gtk.c b/ui/gtk.c index 7078d89d6797..1c75b9ea3c4d 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -597,21 +597,32 @@ static void gd_gl_release_dmabuf(DisplayChangeListene= r *dcl, #endif } =20 -void gd_hw_gl_flushed(void *vcon) +#ifdef CONFIG_GBM +static void gd_gl_fence_cb(void *vcon) { VirtualConsole *vc =3D vcon; - QemuDmaBuf *dmabuf =3D vc->gfx.guest_fb.dmabuf; - int fence_fd; =20 - fence_fd =3D qemu_dmabuf_get_fence_fd(dmabuf); - if (fence_fd >=3D 0) { - qemu_set_fd_handler(fence_fd, NULL, NULL, NULL); - close(fence_fd); - qemu_dmabuf_set_fence_fd(dmabuf, -1); + if (vc->gfx.gl_fence_fd >=3D 0) { + qemu_set_fd_handler(vc->gfx.gl_fence_fd, NULL, NULL, NULL); + g_clear_fd(&vc->gfx.gl_fence_fd, NULL); qemu_console_hw_gl_block(vc->gfx.dcl.con, false); } } =20 +void gd_gl_wait_sync(VirtualConsole *vc, EGLSyncKHR sync) +{ + assert(vc->gfx.gl_fence_fd < 0); + + vc->gfx.gl_fence_fd =3D egl_create_fence(sync); + if (vc->gfx.gl_fence_fd >=3D 0) { + qemu_set_fd_handler(vc->gfx.gl_fence_fd, + gd_gl_fence_cb, NULL, vc); + } else { + qemu_console_hw_gl_block(vc->gfx.dcl.con, false); + } +} +#endif + /** DisplayState Callbacks (opengl version) **/ =20 static const DisplayChangeListenerOps dcl_gl_area_ops =3D { @@ -2355,6 +2366,7 @@ add_gfx_console(GtkDisplayState *s, QemuConsole *con) vc->gfx.scale_y =3D vc->gfx.preferred_scale; =20 #if defined(CONFIG_OPENGL) + vc->gfx.gl_fence_fd =3D -1; if (display_opengl) { if (gtk_use_gl_area) { vc->gfx.drawing_area =3D gtk_gl_area_new(); @@ -2647,6 +2659,9 @@ static void gd_vc_free(void *p) =20 switch (vc->type) { case GD_VC_GFX: +#if defined(CONFIG_OPENGL) && defined(CONFIG_GBM) + gd_gl_fence_cb(vc); +#endif qemu_console_unregister_listener(&vc->gfx.dcl); #if defined(CONFIG_OPENGL) if (display_opengl) { --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653368; cv=none; d=zohomail.com; s=zohoarc; b=mm8XewxPIn97PMz6ro716GGkdHPeYLUF0Ijn9zzpQ4qvDxKnkcRqnpes7MJ6eTNVtOvLRee0Dg7pk+pa3/Qzq7vMKK+p6RUX+T1o1csXKobEv4ZveyfhiQEDHbxdTBOerTF/kfsuhLg9T9NIkykh/E/0lV7X6YgIV+y2yJBREn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653368; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KRInEMHq3qCYs27hdoMN+FKb7VskfV2CZFNqIBjNKpE=; b=H7Jji5xKtuWy5sptdT8uvAw2Ycnmv2gFYM7KRL4cqJJLPGf8szKKdxjV5nl1E/M6Dw6AOe4XR1/CijivGZqw03jtiV+9fLxnDNHGqXafloz6WVs6khkNjUNM3CiGfsLm+SdVHPDxJSa7gc0eeArYhS3m8S8hHEM9InQf6ytAdaA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178765336887265.92051701253013; Tue, 25 Aug 2026 03:22:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoIZ-0005xa-OI; Tue, 25 Aug 2026 06:22:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoIY-0005tI-8z for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:22:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoIW-0005gb-Mq for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:22:30 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-u5dyWZAHNP6OArLb5Kx6fA-1; Tue, 25 Aug 2026 06:22:24 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 95F51195422D; Tue, 25 Aug 2026 10:22:23 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D5CDB1800642; Tue, 25 Aug 2026 10:22:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653348; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KRInEMHq3qCYs27hdoMN+FKb7VskfV2CZFNqIBjNKpE=; b=EKi6ZFERznOfNeQQTIdqeCHnyTqVacThgV6cydxLjp1LKJ1TX2rZzHOX/pvJzehB8fu2lF JnGAHmJvb2JsPaTBHjB153flxFdm7KqzKa2WsXw1nEkByBqNuhpEeNpexf9AwwtByCQHOS H/JW+8d0qga81sCQcd+nl22QZRbtrKk= X-MC-Unique: u5dyWZAHNP6OArLb5Kx6fA-1 X-Mimecast-MFC-AGG-ID: u5dyWZAHNP6OArLb5Kx6fA_1787653343 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:39 +0400 Subject: [PATCH 02/18] ui/dbus: disable scanout iff dmabuf is current MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-2-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=5990; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=SewAVNZd0/0MR4x3m27bnrbQErWKCD9bWw9XzyE3Keg=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyXXCrjm+Uoai3uc5vCvAoUlO+yxGUvdFiOL 3/krmwu0LOJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1slwAKCRDa6OEJdZac 5Td9EACSOpaRk0Cc/cGtc5/f/hbr0E9XUstmKEyJapQRFtJkwpEbu5oq4YV37jLmu+nVnYyGl9r n2iZ5HQ/ONlvcnEradHNPvj2grcv3RTRf6hS3VPsL4bM9B39osFqq+9fsZ/TfNnTS3SWIoO1m2p KZL4D8NSqhj8owZuSek2Ul/3Tw0E6sJQut20MLmeKvP2jI6p3C/nae2eX4j8notK9TawdjOPxmX ziwYpFh5ABRbz6Ujf3HE8bcKFYNvXdruOVDS7C9L+HNxM9RcuWicFmebVC6+Kfdn1W1MWOb1ghR kL/3jZ/Jl0F9mTTk3h7RQO00/WJ4rRb/BvoQFvRE9O6qy4vFib9WLPZqPhXM288SjEqlAcZe7yu TyMzT0lTtEgx5RoQnEje9esPTzPhGQGxCYTwju31g+M7YFpNuvaLz5O0mFvlPlbhNeTVGfsQTaV iz/CEzQdMmOi7O/JdlXUZCdhb+doYSfO0pYu2JatHPqSOQQSu0zTZI5aN26dw3Tz0Xq5pQfv3bP Ra6Hc0WQ+7kWy9BazEwCiIZe2+w0uieHp0fJ8JFZic7FL+9AJSsP6JrC3O8xnCNhaPAw9dMge4k hKjm1USwU066oUVht7r+oqdHvMbLA/LQlcUl0nVZ3hf8z6gVIAisq/BJd1MlMKDUZr/huinsPxa 8LpUSfrCJ18mgOg== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653370865158500 Narrows release_dmabuf to the active scanout, as the device & console may interleave new scanouts before releasing old ones. Signed-off-by: Marc-Andr=C3=A9 Lureau --- ui/dbus-listener.c | 68 ++++++++++++++++++++++++++++++++++++++------------= ---- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/ui/dbus-listener.c b/ui/dbus-listener.c index 2e2f6ba4183a..5a72c7eeae59 100644 --- a/ui/dbus-listener.c +++ b/ui/dbus-listener.c @@ -91,6 +91,8 @@ struct _DBusDisplayListener { guint dbus_filter; guint32 display_serial_to_discard; guint32 cursor_serial_to_discard; + + QemuDmaBuf *scanout_dmabuf; }; =20 G_DEFINE_TYPE(DBusDisplayListener, dbus_display_listener, G_TYPE_OBJECT) @@ -119,6 +121,7 @@ static void dbus_scanout_disable(DisplayChangeListener = *dcl) { DBusDisplayListener *ddl =3D container_of(dcl, DBusDisplayListener, dc= l); =20 + ddl->scanout_dmabuf =3D NULL; ddl_discard_display_messages(ddl); =20 qemu_dbus_display1_listener_call_disable( @@ -298,9 +301,9 @@ static void dbus_call_update_gl(DisplayChangeListener *= dcl, =20 #ifdef CONFIG_GBM static void dbus_scanout_dmabuf_v1(DBusDisplayListener *ddl, - QemuDmaBuf *dmabuf) + QemuDmaBuf *dmabuf, + GError **err) { - g_autoptr(GError) err =3D NULL; g_autoptr(GUnixFDList) fd_list =3D NULL; int fd; uint32_t width, height, stride, fourcc; @@ -309,8 +312,7 @@ static void dbus_scanout_dmabuf_v1(DBusDisplayListener = *ddl, =20 fd =3D qemu_dmabuf_get_fds(dmabuf, NULL)[0]; fd_list =3D g_unix_fd_list_new(); - if (g_unix_fd_list_append(fd_list, fd, &err) !=3D 0) { - error_report("Failed to setup dmabuf fdlist: %s", err->message); + if (g_unix_fd_list_append(fd_list, fd, err) !=3D 0) { return; } =20 @@ -332,9 +334,9 @@ static void dbus_scanout_dmabuf_v1(DBusDisplayListener = *ddl, } =20 static void dbus_scanout_dmabuf_v2(DBusDisplayListener *ddl, - QemuDmaBuf *dmabuf) + QemuDmaBuf *dmabuf, + GError **err) { - g_autoptr(GError) err =3D NULL; g_autoptr(GUnixFDList) fd_list =3D NULL; int i, fd_index[DMABUF_MAX_PLANES], num_fds; uint32_t x, y, width, height, fourcc, backing_width, backing_height; @@ -360,9 +362,8 @@ static void dbus_scanout_dmabuf_v2(DBusDisplayListener = *ddl, break; } =20 - fd_index[num_fds] =3D g_unix_fd_list_append(fd_list, plane_fd, &er= r); + fd_index[num_fds] =3D g_unix_fd_list_append(fd_list, plane_fd, err= ); if (fd_index[num_fds] < 0) { - error_report("Failed to setup dmabuf fdlist: %s", err->message= ); return; } } @@ -395,20 +396,36 @@ static void dbus_scanout_dmabuf_v2(DBusDisplayListene= r *ddl, G_DBUS_CALL_FLAGS_NONE, -1, fd_list, NULL, NULL, NULL); } =20 +static bool dbus_call_scanout_dmabuf(DBusDisplayListener *ddl, + QemuDmaBuf *dmabuf) +{ + g_autoptr(GError) err =3D NULL; + + if (ddl->scanout_dmabuf_v2_proxy) { + dbus_scanout_dmabuf_v2(ddl, dmabuf, &err); + } else { + if (qemu_dmabuf_get_num_planes(dmabuf) > 1) { + error_report("Peer does not support multi plane dmabuf"); + return false; + } + dbus_scanout_dmabuf_v1(ddl, dmabuf, &err); + } + + if (err) { + error_report("Failed to scanout dmabuf: %s", err->message); + return false; + } + + return true; +} + static void dbus_scanout_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf) { DBusDisplayListener *ddl =3D container_of(dcl, DBusDisplayListener, dc= l); =20 - if (ddl->scanout_dmabuf_v2_proxy) { - dbus_scanout_dmabuf_v2(ddl, dmabuf); - } else { - if (qemu_dmabuf_get_num_planes(dmabuf) > 1) { - g_debug("org.qemu.Display1.Listener.ScanoutDMABUF " - "does not support mutli plane"); - return; - } - dbus_scanout_dmabuf_v1(ddl, dmabuf); + if (dbus_call_scanout_dmabuf(ddl, dmabuf)) { + ddl->scanout_dmabuf =3D dmabuf; } } #endif /* GBM */ @@ -589,6 +606,10 @@ static void dbus_scanout_texture(DisplayChangeListener= *dcl, uint32_t w, uint32_t h, void *d3d_tex2d) { +#if defined(CONFIG_GBM) || defined(WIN32) + DBusDisplayListener *ddl =3D container_of(dcl, DBusDisplayListener, dc= l); +#endif + trace_dbus_scanout_texture(tex_id, backing_y_0_top, backing_width, backing_height, x, y, w, h); #ifdef CONFIG_GBM @@ -607,13 +628,13 @@ static void dbus_scanout_texture(DisplayChangeListene= r *dcl, backing_height, fourcc, modifier, fd, num_pla= nes, false, backing_y_0_top); =20 - dbus_scanout_dmabuf(dcl, dmabuf); + if (dbus_call_scanout_dmabuf(ddl, dmabuf)) { + ddl->scanout_dmabuf =3D NULL; + } qemu_dmabuf_close(dmabuf); #endif =20 #ifdef WIN32 - DBusDisplayListener *ddl =3D container_of(dcl, DBusDisplayListener, dc= l); - /* there must be a matching gfx_switch before */ assert(surface_width(ddl->ds) =3D=3D w); assert(surface_height(ddl->ds) =3D=3D h); @@ -686,7 +707,14 @@ static void dbus_cursor_dmabuf(DisplayChangeListener *= dcl, static void dbus_release_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf) { + DBusDisplayListener *ddl =3D container_of(dcl, DBusDisplayListener, dc= l); + + if (ddl->scanout_dmabuf !=3D dmabuf) { + return; + } + dbus_scanout_disable(dcl); + ddl->scanout_dmabuf =3D NULL; } #endif /* GBM */ =20 --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653396; cv=none; d=zohomail.com; s=zohoarc; b=K7hLO+0SrR6Inrysiu5OXPGPAnnROy0Ex6WuixZfBwMGPgS9jqXjiCt7wzpGvK+Y6Cjb6tKvf9dzQkR7wAn2ooCJCbKpKSskkeK8TC07ZTP+lf7fICtmthoC+GCZnmdzmfHGLReO7C68WJ3hIRetbGRRURBids9Lmlvm/PyxiIs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653396; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=C/kbWGkD8OclQC6Wy3+TEi46VsHGuj2Fi8YKSYeaCxM=; b=aO3JrayPyj9YyI4Zn8j9ZFZ9ZyPcaNtOOdQQ1rYsO/fV2zNKNriz8yNuSK0hh2mbh08SaFyJ24bHtLB9/F0/Gj9ToIzaNPdaGbd8p3+FozpkEwqXiQ9faBWXSxzJUT7+IqdrVKNghniBuUSzUJLbk86q92Me2Fil1e9yU3+h35E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653396697768.2741225732318; Tue, 25 Aug 2026 03:23:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoIx-0006LV-3x; Tue, 25 Aug 2026 06:22:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoIn-0006A9-Tz for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:22:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoIl-0005im-37 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:22:45 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-8-u-lUgWKWMk2IQqRTGYpXaA-1; Tue, 25 Aug 2026 06:22:38 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1A8CA19539BB; Tue, 25 Aug 2026 10:22:37 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D732718005B6; Tue, 25 Aug 2026 10:22:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653361; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C/kbWGkD8OclQC6Wy3+TEi46VsHGuj2Fi8YKSYeaCxM=; b=Zgm+isBLRvqtpIGggRYXIw3KDszW1prJbNbnozMajqIHCHsqyOp4vs6y+XZF4libwJHfqy kRAQhi85J1jYxdg+C/Ez7TuqgATINZgLZaY9/GjkiKdxXYHoQdbmiC2th5/+zp3tyCTVlJ oNfWxh4Zx+nS1+1Wl7JlNL6r93yuN1s= X-MC-Unique: u-lUgWKWMk2IQqRTGYpXaA-1 X-Mimecast-MFC-AGG-ID: u-lUgWKWMk2IQqRTGYpXaA_1787653357 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:40 +0400 Subject: [PATCH 03/18] virtio-gpu: store the scanout DMABUF in virtio_gpu_scanout MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-3-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=6500; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=v5VqcSoCRr5hkc9VZnbhixvj5fVuV6rQTOm52ZE4T68=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyX182QW9SXjqOHgbamGZ3cyTtB/CrfXELQH 4dfT9Y0NmGJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1slwAKCRDa6OEJdZac 5f77D/9H42hKCZYMZHxEiZfuhe4pjJyeYaEdW16mHEdaLN8NBhX9LCpqkvWZu1l8wwD8FgnQ9Zq rty+g6GGrpZPge7tDdUg9smOlsmpioOXIlvIuoQUMA5WfbZcAhKjyV2glB1Kzv+O3enuE2MpiB5 g9JRdgBV2npXYOdo07mczd9OoI1YV6bx6BBRfMsMfRFQ2kIFS6+cORmKa6TLM8d+yEtTsoucqa4 /ih7prVwOla0UdShVgNbe2MSC/tG6W4J7W36+w+eFz9fgj8Jkb7veM1SRy6o3W2tbHzyM0/wbcT rcoJjkB6Gk3T4nL4ogS81SjRkyB32nhjj6tZa6V2QXa7uiYerTxPnhaUWCCJG7069XGvBDSIFrc CD/3A407WwxCHXwsDNoIGlCP6c9r0P2RRugRq4tOuLzZ6NcFy77d9aqqtFBCYJ4F2rCnphQhCjK IPHcwMwgkYSw0KsE35DsWMAnk8Fa2pLndEBpwdGnGmk1H1ndQOpTGL/+o0Ic4M1W1/rkNH2Uhh6 5R7v+FKkF2vN98p6z3WrvIqJcc7T4SQU8EZfx4RMO459alVMqwatqfwVQu0AQtN/n6i1ITYe7af EPXmMQ/5N/93JwLpTHI6pbJthqSDSc78F1hD6HWQF4ZkIuu6jYwuyLuvvwlLfK1bEFu6XAGrYUm E2b7pbC1qPcIBEg== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653398038158500 VirtIOGPU tracks presented dmabufs both through a per-scanout primary pointer and a device-wide list of VGPUDMABuf wrappers. Only the current DMA-BUF for a scanout can ever be presented, so the list and the wrapper struct are redundant bookkeeping. Store the QemuDmaBuf directly in virtio_gpu_scanout and drop VGPUDMABuf and the device-wide list. The wrapper only carried the buffer and its scanout id; the id is now implicit in the owning scanout. No functional change intended. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-udmabuf.c | 68 +++++++++++++++----------------------= ---- include/hw/virtio/virtio-gpu.h | 12 +------- 2 files changed, 25 insertions(+), 55 deletions(-) diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabu= f.c index 5f08c855dde1..fd47028a1189 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-udmabuf.c @@ -152,30 +152,19 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple= _resource *res) res->blob =3D pdata; } =20 -static void virtio_gpu_free_dmabuf(VirtIOGPU *g, VGPUDMABuf *dmabuf) -{ - struct virtio_gpu_scanout *scanout; - - scanout =3D &g->parent_obj.scanout[dmabuf->scanout_id]; - qemu_console_gl_release_dmabuf(scanout->con, dmabuf->buf); - g_clear_pointer(&dmabuf->buf, qemu_dmabuf_free); - QTAILQ_REMOVE(&g->dmabuf.bufs, dmabuf, next); - g_free(dmabuf); -} - void virtio_gpu_fini_udmabuf(VirtIOGPU *g, struct virtio_gpu_simple_resour= ce *res) { int max_outputs =3D g->parent_obj.conf.max_outputs; int i; =20 for (i =3D 0; i < max_outputs; i++) { - VGPUDMABuf *dmabuf =3D g->dmabuf.primary[i]; + struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[i]; =20 - if (dmabuf && - qemu_dmabuf_get_num_planes(dmabuf->buf) > 0 && - qemu_dmabuf_get_fds(dmabuf->buf, NULL)[0] =3D=3D res->dmabuf_f= d && + if (scanout->dmabuf && + qemu_dmabuf_get_num_planes(scanout->dmabuf) > 0 && + qemu_dmabuf_get_fds(scanout->dmabuf, NULL)[0] =3D=3D res->dmab= uf_fd && res->dmabuf_fd !=3D -1) { - qemu_dmabuf_close(dmabuf->buf); + qemu_dmabuf_close(scanout->dmabuf); res->dmabuf_fd =3D -1; } } @@ -183,31 +172,23 @@ void virtio_gpu_fini_udmabuf(VirtIOGPU *g, struct vir= tio_gpu_simple_resource *re virtio_gpu_destroy_udmabuf(res); } =20 -static VGPUDMABuf -*virtio_gpu_create_dmabuf(VirtIOGPU *g, - uint32_t scanout_id, - struct virtio_gpu_simple_resource *res, - struct virtio_gpu_framebuffer *fb, - struct virtio_gpu_rect *r) +static QemuDmaBuf * +virtio_gpu_create_dmabuf(struct virtio_gpu_simple_resource *res, + struct virtio_gpu_framebuffer *fb, + struct virtio_gpu_rect *r) { - VGPUDMABuf *dmabuf; uint32_t offset =3D 0; =20 if (res->dmabuf_fd < 0) { return NULL; } =20 - dmabuf =3D g_new0(VGPUDMABuf, 1); - dmabuf->buf =3D qemu_dmabuf_new(r->width, r->height, - &offset, &fb->stride, - r->x, r->y, fb->width, fb->height, - qemu_pixman_to_drm_format(fb->format), - DRM_FORMAT_MOD_INVALID, &res->dmabuf_fd, - 1, true, false); - dmabuf->scanout_id =3D scanout_id; - QTAILQ_INSERT_HEAD(&g->dmabuf.bufs, dmabuf, next); - - return dmabuf; + return qemu_dmabuf_new(r->width, r->height, + &offset, &fb->stride, + r->x, r->y, fb->width, fb->height, + qemu_pixman_to_drm_format(fb->format), + DRM_FORMAT_MOD_INVALID, &res->dmabuf_fd, + 1, true, false); } =20 int virtio_gpu_update_dmabuf(VirtIOGPU *g, @@ -217,26 +198,25 @@ int virtio_gpu_update_dmabuf(VirtIOGPU *g, struct virtio_gpu_rect *r) { struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[scanout_= id]; - VGPUDMABuf *new_primary, *old_primary =3D NULL; + QemuDmaBuf *new_primary, *old_primary; uint32_t width, height; =20 - new_primary =3D virtio_gpu_create_dmabuf(g, scanout_id, res, fb, r); + new_primary =3D virtio_gpu_create_dmabuf(res, fb, r); if (!new_primary) { return -EINVAL; } =20 - if (g->dmabuf.primary[scanout_id]) { - old_primary =3D g->dmabuf.primary[scanout_id]; - } + old_primary =3D scanout->dmabuf; =20 - width =3D qemu_dmabuf_get_width(new_primary->buf); - height =3D qemu_dmabuf_get_height(new_primary->buf); - g->dmabuf.primary[scanout_id] =3D new_primary; + width =3D qemu_dmabuf_get_width(new_primary); + height =3D qemu_dmabuf_get_height(new_primary); + scanout->dmabuf =3D new_primary; qemu_console_resize(scanout->con, width, height); - qemu_console_gl_scanout_dmabuf(scanout->con, new_primary->buf); + qemu_console_gl_scanout_dmabuf(scanout->con, new_primary); =20 if (old_primary) { - virtio_gpu_free_dmabuf(g, old_primary); + qemu_console_gl_release_dmabuf(scanout->con, old_primary); + qemu_dmabuf_free(old_primary); } =20 return 0; diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 220231ec9d43..79eb4b1b8cec 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -74,6 +74,7 @@ struct virtio_gpu_framebuffer { struct virtio_gpu_scanout { QemuConsole *con; DisplaySurface *ds; + QemuDmaBuf *dmabuf; uint32_t width, height; int x, y; int invalidate; @@ -178,12 +179,6 @@ struct VirtIOGPUBaseClass { DEFINE_PROP_UINT32("xres", _state, _conf.xres, 1280), \ DEFINE_PROP_UINT32("yres", _state, _conf.yres, 800) =20 -typedef struct VGPUDMABuf { - QemuDmaBuf *buf; - uint32_t scanout_id; - QTAILQ_ENTRY(VGPUDMABuf) next; -} VGPUDMABuf; - struct VirtIOGPU { VirtIOGPUBase parent_obj; =20 @@ -215,11 +210,6 @@ struct VirtIOGPU { uint32_t bytes_3d; } stats; =20 - struct { - QTAILQ_HEAD(, VGPUDMABuf) bufs; - VGPUDMABuf *primary[VIRTIO_GPU_MAX_SCANOUTS]; - } dmabuf; - GArray *capset_ids; }; =20 --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653392; cv=none; d=zohomail.com; s=zohoarc; b=Q/xZtdYECowSybtEEfBxlmEWvdA913UjpAnYi1s39+9Mic+nVoNXYDlgSA1ZsPIL32w2fxeLEYdGBqgaAluAEEAgPtFI0A1oUy6gklzjnEXOooK87yszNtHcs0VLQjVIAe8yBDoI9OxIbmN+rVxjsEFLwNBYmXC1qHs1kMUYlPs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653392; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=s3jdVHOIZg28x5tTLfcSDchrSqvF3pRSYXnZWucboy8=; b=MuZA6CIRuD+DjotJEiMaXweXYzp7kn4ap7o/ugL7IlJt8WPn9kdLCD5hWH/56tzPzn6U4FRRAbIGfNwfYw1eJb4o8dE3jw7PkYXeTmS2x27A0ajTlRT7j40oElnRXJUjiNTQXw4CuPtjwhR2iidLZe7KBmZJfUUvUSpbh/e78PM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653392740997.5307210290279; Tue, 25 Aug 2026 03:23:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoJ9-0006lH-QI; Tue, 25 Aug 2026 06:23:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoJ3-0006Xw-FG for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:23:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoJ2-0005mH-5C for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:23:01 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-kEOA9o1XM4y96zvWJdIOgw-1; Tue, 25 Aug 2026 06:22:56 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8999A187E5C2; Tue, 25 Aug 2026 10:22:54 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 824D430002EE; Tue, 25 Aug 2026 10:22:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s3jdVHOIZg28x5tTLfcSDchrSqvF3pRSYXnZWucboy8=; b=Y7bTqmF/VepSXyusW6Dj4Ec05Dno2wP66g2b86fayYfjyIjCMBLKFZFuL5cqlPM8KVKwPn /d7/kaMcp/X8yP9DVoIoXznMfj/Dl74/GA+MsgkiB7vvg2eA3nSpigd0XzZsoQApZP2PGK obec5lJgHx/yC3mHekFEL7Ci17uEMSs= X-MC-Unique: kEOA9o1XM4y96zvWJdIOgw-1 X-Mimecast-MFC-AGG-ID: kEOA9o1XM4y96zvWJdIOgw_1787653375 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:41 +0400 Subject: [PATCH 04/18] ui/console: disable GL scanout when dmabuf is the active one MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-4-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=760; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=fVbPh6f+y71tIi92bbLnTHXtgYVyIThG/fKNesPGhOU=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyXdtrhiW4XBGLz6cbvMMzA8tuxLmMytHQJ8 Cw3BW9j/q6JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1slwAKCRDa6OEJdZac 5UgJD/9Q1fiWFu6X3vEcVgbwPI9Plm1RCeBoKdP8zP8p8TI2ki3rohKZlkAeIcClipNce36v1sS 0IrY3yy1T1kgF5YPyVUzFXuCqSH1H3DuWFL6yIFIRboGsntijWN9ljJYwDmclORZgVngzIb8wls tBc/+0+q//DFgaWzMFvmOd9A9G30a6GvBUG055TPAANBN7wkDiqMDHLgvFqHKg7tSB6Vd9jE+4U DIAfzyM0/hU+wG5xcFoByynL2ywrkwQw2t/4DGCK28EFXLsHVKIACIBFpi46mYHYm5jSVrBvDkg XbhOzNRjIA34Kn/DqXgprBev0tBr3Uk5zBTuMJwWvTUteTpA9dsCOXsduWIsTMJ9ugFsQZPTiYy eXphQB/sFsKczH/JI30tWA9h/9r7H9SyXp4Fl/veb9/b7ASSEyRzXv+Np0+jcemDKPZ9kAhAMCV peG7RIBd8uzwvn3ohUzPYSSIoR64nnh6YU255fcDaZXciqUl7JPP8aKS8qwXlpVFiktwBBsNzqS uJP6yZ0B0e8mILGraD2Kk1n2M20hBaV99TK3E82cHe+MIrznt4nBJOsxsqY0K4PFfOjc2f4I8Xt HnPi0+5fVjiiULag1UW+LcbXuO9wZfoRLmKhoHFmZkgD7pSIWGcNws9IAOh+GV6vz3+Rb3PC+cL Kl5m4Dff46sFyjg== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653394444158500 Disable the GL scanout when the actively-displayed dmabuf is released, so the console does not retain a stale reference. Signed-off-by: Marc-Andr=C3=A9 Lureau --- ui/console.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ui/console.c b/ui/console.c index a8a2a247d8f4..14f148118e37 100644 --- a/ui/console.c +++ b/ui/console.c @@ -1049,6 +1049,9 @@ void qemu_console_gl_release_dmabuf(QemuConsole *con, dcl->ops->dpy_gl_release_dmabuf(dcl, dmabuf); } } + if (con->scanout.kind =3D=3D SCANOUT_DMABUF && dmabuf =3D=3D con->scan= out.dmabuf) { + qemu_console_gl_scanout_disable(con); + } } =20 void qemu_console_gl_update(QemuConsole *con, --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653401; cv=none; d=zohomail.com; s=zohoarc; b=RCj38NKuPPOAN/mADfOx3Mk9fQF10Pk/VGdIefQXQh2s0qnC3P+GB5pEak2LgIDMFQldyFulQDcPLVta6lqU0cafYfcSsoK/iV8MLVlpEgK32q8Z/Nx3HJrOE4n+QXttZdSMIwLHIACqgFNw3bX5HrWHvubrBitrmvz9ilDx/0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653401; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BfqhV0k2wnTQNP/8Pi8Tj3/PSKa/COTcPUpKOxqHnxc=; b=VrptL3FXBBU5yBJz+TJrF5tU88jCEaFB3V0tHi3vWrhJQkOi4cPQrtRyJu8/AZagj5efpLo8eUGvDlWfebB+SYO/y/RazXXCG1J4kSw/Lw4cZDN0gYPd1+lDrwcn0OmQk++nkVauGY0wnfxY/3DEk+eb/LPAT6h5YqzTLY5Ilj8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653401175906.8794189728177; Tue, 25 Aug 2026 03:23:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoJD-00079j-Ak; Tue, 25 Aug 2026 06:23:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoJB-0006ze-H4 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:23:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoJA-0005nN-5Z for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:23:09 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-682-VMg6GO1nPVi_dPjlpLYtrw-1; Tue, 25 Aug 2026 06:23:04 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DA5D919540C8; Tue, 25 Aug 2026 10:23:02 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 533DA30002EF; Tue, 25 Aug 2026 10:22:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653387; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BfqhV0k2wnTQNP/8Pi8Tj3/PSKa/COTcPUpKOxqHnxc=; b=cYe5cyTQPGuBZ4nW48Tav9OZkq7N8A+L2ng6yB/C2s9Cz8oYw5+pRVqZsy52VI5H9q0rmA y7PEezQD86qEPXlAZ1Y5w6LTXcHFDz7I6jMdByzVv+YK2So0ba1y6U/ewnrJ+ekTDiGZ/v gKeJWt9dOv2bAGGbenDzyv6PTXVPwZA= X-MC-Unique: VMg6GO1nPVi_dPjlpLYtrw-1 X-Mimecast-MFC-AGG-ID: VMg6GO1nPVi_dPjlpLYtrw_1787653383 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:42 +0400 Subject: [PATCH 05/18] ui/sdl2: clear guest_fb.dmabuf on release MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-5-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=984; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=soqzgd5o5ILBeI69vpRutTaDwn5XU9TT0gvi1GNhfSg=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyXz2Yn2vDtuvnl7ZvBDMvfVlySKWyA9IVmA afu1ql6TTmJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1slwAKCRDa6OEJdZac 5a5oD/9ixoDpBY/8Ky0Fbb3i230pOCVKLrkF5rRA8fwb+knlGPb4DG5yo/IOyPAgrAnWh5EAj9u abuSq0AX37T6pbFGygRA+PVgDX5K7YtADvUQ8hlTITh+FGrXNgnHGzK9gXNKYWGuBRDOyTNvFV9 OWGdiJdGKmPhxwHWD05Ckha/T7JM3VwleVJU8tvhDFQBwfSr7Op5nfKo9N9Q1inBey/hR4vUSBa rf1GU9rdRu+zyUBG0zyXxKBYzM6VUQgx7TWZKM0nqyUDpXPlNM2D1Aw36Q3+F4tLC8AsJMSJ6eX jVRNVlbaXEMQuE5Z0NJ3xPEz+tDjXYtswcqTKtz4hLxda0riqZcRkTm8Mjw0HDUfqDgIX3YJMUm NB87n59hJ53gmfXP/V8ypYk94ZgN61T2Ts6GSoV+tgtt/lCrQ12fnk6JkKeGIBvewNmY5UpZgMk RGGO8CYLc/fmtjs4P5IEbXnMszf94Yfn66/5CR5N2eLFturuFHuo/xijPLGSp+/QpV8VUhAqca8 RuojKbMf+XN0Grd27ToDvVasLrDjU5iyseuqm949m7M4TVjXqL4mRWbdaqMckqomVKUtojzxMOZ ElIaDHb+fdYshCbi/OVwFvU0AWUO+yav23wgwbkgSTNpqDgEP0dE7xdAn/d942GNQlZ15jyYPvC tMuxibsClw9aa7Q== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653401988158500 sdl2_gl_release_dmabuf() releases the texture but leaves the guest_fb.dmabuf pointer dangling. Clear it to prevent stale references after the dmabuf is freed. Fixes: 52053b7e0a0e ("ui/sdl2: Implement dpy dmabuf functions") Signed-off-by: Marc-Andr=C3=A9 Lureau --- ui/sdl2-gl.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c index 1547ad2f6f80..46eff768c968 100644 --- a/ui/sdl2-gl.c +++ b/ui/sdl2-gl.c @@ -286,7 +286,12 @@ void sdl2_gl_scanout_dmabuf(DisplayChangeListener *dcl, void sdl2_gl_release_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf) { + struct sdl2_console *scon =3D container_of(dcl, struct sdl2_console, d= cl); + egl_dmabuf_release_texture(dmabuf); + if (scon->guest_fb.dmabuf =3D=3D dmabuf) { + scon->guest_fb.dmabuf =3D NULL; + } } =20 bool sdl2_gl_has_dmabuf(DisplayChangeListener *dcl) --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653411; cv=none; d=zohomail.com; s=zohoarc; b=MeThVhgECKNfvhuuviBjTUAekD/NE4zEp0Bb/v6jie7HHtbRiS+7x6G4OWN1+a/VC80us1AIyJP0qoSt0C9FvbINx/3HCVrJ1liLsH18VGVNTJUSsnIi8ZjEorST69267S6zNBNvbifiGYjMb/3dP9oq/tEGwupnSCMbZi8wbxg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653411; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BmwS7U+IclWyeDO7uf8KVf+NlRBoCNQg+dAII7UOZAs=; b=ZxeFZgDDm7/kb7S2v/aTjOPgAKczVfaE6nLpvJjjW1h3uPQ+TD/fmYWvW5KYMQuvRKQyACp772st8CpZ4W13fifgJC1oQ0MEmnDhpU6fEmp85YTLgNAMyWXXuOukvAdf20t81B7hnHlUzHtC3c7oUehkh1++6VuDNrB5gujMsXo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653411295760.7466315290986; Tue, 25 Aug 2026 03:23:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoJP-0007R7-Oc; Tue, 25 Aug 2026 06:23:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoJO-0007QJ-E9 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:23:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoJM-0005p9-Ir for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:23:22 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-362-zRl4fgjhOWaLlII6WWpl_w-1; Tue, 25 Aug 2026 06:23:16 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2A0A3187BE2A; Tue, 25 Aug 2026 10:23:15 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 065D819560AB; Tue, 25 Aug 2026 10:23:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653400; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BmwS7U+IclWyeDO7uf8KVf+NlRBoCNQg+dAII7UOZAs=; b=FXAQ8zYJdkq+thswlqrZqRDrmZz4bQue8vzPSOiHbjtpLUDoFGkL1i3yx0jAIjKRNda0/m 4RyaC9xEekViuJJbpj8q3qn+uvlFNue/H7IE0IcZ2Rk8BT8l2Kqs7LCQonwtMQk7tufhK8 CX6gOMppjrEC5GbGHlg5GCK2DBsN+Qs= X-MC-Unique: zRl4fgjhOWaLlII6WWpl_w-1 X-Mimecast-MFC-AGG-ID: zRl4fgjhOWaLlII6WWpl_w_1787653395 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:43 +0400 Subject: [PATCH 06/18] ui/dmabuf: own and close fds on free MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-6-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=8198; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=LnYsn1AJWCMaPoZ07U+15aQlW4qWLu003IRLniecQv8=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyX0wopJDSSma12WvKXx6Svum5mwjRFSIqeD zvMQ6JiNxSJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1slwAKCRDa6OEJdZac 5YqgD/4+S7OLQtv0uGunEJ+PPuIaidJn9oEAofwtI8KXTMsY6gnhwt4/rc+4G9a9Bsc/Z39+BXY QJRugs7IftPZxfx0E+ogN+Ayw4I2xj6jJEtKB72AjBNTs12s1WgJ9bkz0jlsN66XkL837zkI3EN HA2IXeMJtGIXITFJnV1DYQgFpwJPXsSDDCegkjXv7T3m5cmUHolK+H9nE0N5lBsZWKJyFC0i2HN QJBVyfzkmXZ3m7e5WJhqr/s7TA0x1qwCkB9b8sLT3S2PyohOlFg/QwaqEzc5JFhfEJmNx25pDbl vEJbgC1xj/yaP+j8D4UAKv6sV0JYVVfr0QFv8FF8mqAnRqI/dqzVnG8tJFxGVgssdMpRLDDx0C+ 0tAZ0e4yJZGFKHMZjAvMQ44AnDAsyDvxbG44NX1lY4g9tzJgOVbMZa4eKV61oxS4DnYtA/lFIOV 9jx8NgA41Eiwr96hKS10ScjVeRO6zSj5qdf20Pfm5ZaEduvQTYSbl8KpQRMvJAg0X67kyzKMR10 O6OGnWvYBaPDyFlnk9+Ll+uqKKDBZxI2s7x9Em+MNkXhGm7113b/DWL+akgjvWAGzN/EprLjcaA y1oDKKNkAgY1togJNo8FvCE+u7voLgeOoquK1aUomKzb7+9WEYpdM2tWOYazelYRcJoDaQPrtdl QsBp6syOIyIBLJw== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653412159158500 Make qemu_dmabuf_free() call qemu_dmabuf_close(), so the dmabuf always owns and closes its fds. This removes the need for callers to explicitly close fds before freeing and simplify the code. To support this, virtio_gpu_create_dmabuf() now dup()s the resource fd so each QemuDmaBuf has an independent copy. The scanout-matching loop in virtio_gpu_fini_udmabuf() is no longer needed and is removed. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/vhost-user-gpu.c | 1 - hw/display/virtio-gpu-udmabuf-stubs.c | 2 +- hw/display/virtio-gpu-udmabuf.c | 32 +++++++++----------------------- hw/display/virtio-gpu.c | 2 +- hw/vfio/display.c | 1 - include/hw/virtio/virtio-gpu.h | 3 +-- include/ui/dmabuf.h | 1 - ui/dbus-listener.c | 1 - ui/dmabuf.c | 22 ++++++++-------------- 9 files changed, 20 insertions(+), 45 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index cd684d63639e..c09aca041135 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -293,7 +293,6 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUse= rGpuMsg *msg) dmabuf =3D g->dmabuf[m->scanout_id]; =20 if (dmabuf) { - qemu_dmabuf_close(dmabuf); qemu_console_gl_release_dmabuf(con, dmabuf); g_clear_pointer(&dmabuf, qemu_dmabuf_free); } diff --git a/hw/display/virtio-gpu-udmabuf-stubs.c b/hw/display/virtio-gpu-= udmabuf-stubs.c index 85d03935a332..f692e1351034 100644 --- a/hw/display/virtio-gpu-udmabuf-stubs.c +++ b/hw/display/virtio-gpu-udmabuf-stubs.c @@ -12,7 +12,7 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_res= ource *res) /* nothing (stub) */ } =20 -void virtio_gpu_fini_udmabuf(VirtIOGPU *g, struct virtio_gpu_simple_resour= ce *res) +void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res) { /* nothing (stub) */ } diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabu= f.c index fd47028a1189..094646af8636 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-udmabuf.c @@ -79,7 +79,7 @@ static void virtio_gpu_remap_udmabuf(struct virtio_gpu_si= mple_resource *res) } } =20 -static void virtio_gpu_destroy_udmabuf(struct virtio_gpu_simple_resource *= res) +void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res) { if (res->remapped) { munmap(res->remapped, res->blob_size); @@ -143,7 +143,7 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_r= esource *res) } virtio_gpu_remap_udmabuf(res); if (!res->remapped) { - virtio_gpu_destroy_udmabuf(res); + virtio_gpu_fini_udmabuf(res); return; } pdata =3D res->remapped; @@ -152,42 +152,28 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple= _resource *res) res->blob =3D pdata; } =20 -void virtio_gpu_fini_udmabuf(VirtIOGPU *g, struct virtio_gpu_simple_resour= ce *res) -{ - int max_outputs =3D g->parent_obj.conf.max_outputs; - int i; - - for (i =3D 0; i < max_outputs; i++) { - struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[i]; - - if (scanout->dmabuf && - qemu_dmabuf_get_num_planes(scanout->dmabuf) > 0 && - qemu_dmabuf_get_fds(scanout->dmabuf, NULL)[0] =3D=3D res->dmab= uf_fd && - res->dmabuf_fd !=3D -1) { - qemu_dmabuf_close(scanout->dmabuf); - res->dmabuf_fd =3D -1; - } - } - - virtio_gpu_destroy_udmabuf(res); -} - static QemuDmaBuf * virtio_gpu_create_dmabuf(struct virtio_gpu_simple_resource *res, struct virtio_gpu_framebuffer *fb, struct virtio_gpu_rect *r) { uint32_t offset =3D 0; + int fd; =20 if (res->dmabuf_fd < 0) { return NULL; } =20 + fd =3D qemu_dup(res->dmabuf_fd); + if (fd < 0) { + return NULL; + } + return qemu_dmabuf_new(r->width, r->height, &offset, &fb->stride, r->x, r->y, fb->width, fb->height, qemu_pixman_to_drm_format(fb->format), - DRM_FORMAT_MOD_INVALID, &res->dmabuf_fd, + DRM_FORMAT_MOD_INVALID, &fd, 1, true, false); } =20 diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index fbb6fec7a0ad..0335b636068d 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -978,7 +978,7 @@ void virtio_gpu_cleanup_mapping(VirtIOGPU *g, res->addrs =3D NULL; =20 if (res->blob) { - virtio_gpu_fini_udmabuf(g, res); + virtio_gpu_fini_udmabuf(res); } } =20 diff --git a/hw/vfio/display.c b/hw/vfio/display.c index cb83d98e9af6..89854eceb43c 100644 --- a/hw/vfio/display.c +++ b/hw/vfio/display.c @@ -263,7 +263,6 @@ static void vfio_display_free_one_dmabuf(VFIODisplay *d= py, VFIODMABuf *dmabuf) { QTAILQ_REMOVE(&dpy->dmabuf.bufs, dmabuf, next); =20 - qemu_dmabuf_close(dmabuf->buf); qemu_console_gl_release_dmabuf(dpy->con, dmabuf->buf); g_clear_pointer(&dmabuf->buf, qemu_dmabuf_free); g_free(dmabuf); diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 79eb4b1b8cec..d3ca8d82586b 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -379,8 +379,7 @@ bool virtio_gpu_scanout_blob_to_fb(struct virtio_gpu_fr= amebuffer *fb, /* virtio-gpu-udmabuf.c */ bool virtio_gpu_have_udmabuf(void); void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res); -void virtio_gpu_fini_udmabuf(VirtIOGPU *g, - struct virtio_gpu_simple_resource *res); +void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res); int virtio_gpu_update_dmabuf(VirtIOGPU *g, uint32_t scanout_id, struct virtio_gpu_simple_resource *res, diff --git a/include/ui/dmabuf.h b/include/ui/dmabuf.h index 381583bd536c..e47b96b454dd 100644 --- a/include/ui/dmabuf.h +++ b/include/ui/dmabuf.h @@ -27,7 +27,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuDmaBuf, qemu_dmabuf_fre= e); =20 const int *qemu_dmabuf_get_fds(QemuDmaBuf *dmabuf, int *nfds); void qemu_dmabuf_dup_fds(QemuDmaBuf *dmabuf, int *fds, int nfds); -void qemu_dmabuf_close(QemuDmaBuf *dmabuf); uint32_t qemu_dmabuf_get_width(QemuDmaBuf *dmabuf); uint32_t qemu_dmabuf_get_height(QemuDmaBuf *dmabuf); const uint32_t *qemu_dmabuf_get_offsets(QemuDmaBuf *dmabuf, int *noffsets); diff --git a/ui/dbus-listener.c b/ui/dbus-listener.c index 5a72c7eeae59..c1e86648384c 100644 --- a/ui/dbus-listener.c +++ b/ui/dbus-listener.c @@ -631,7 +631,6 @@ static void dbus_scanout_texture(DisplayChangeListener = *dcl, if (dbus_call_scanout_dmabuf(ddl, dmabuf)) { ddl->scanout_dmabuf =3D NULL; } - qemu_dmabuf_close(dmabuf); #endif =20 #ifdef WIN32 diff --git a/ui/dmabuf.c b/ui/dmabuf.c index b61dc7ad2783..3651f784bd14 100644 --- a/ui/dmabuf.c +++ b/ui/dmabuf.c @@ -62,10 +62,18 @@ QemuDmaBuf *qemu_dmabuf_new(uint32_t width, uint32_t he= ight, =20 void qemu_dmabuf_free(QemuDmaBuf *dmabuf) { + int i; + if (dmabuf =3D=3D NULL) { return; } =20 + for (i =3D 0; i < dmabuf->num_planes; i++) { + if (dmabuf->fd[i] >=3D 0) { + close(dmabuf->fd[i]); + dmabuf->fd[i] =3D -1; + } + } g_free(dmabuf); } =20 @@ -92,20 +100,6 @@ void qemu_dmabuf_dup_fds(QemuDmaBuf *dmabuf, int *fds, = int nfds) } } =20 -void qemu_dmabuf_close(QemuDmaBuf *dmabuf) -{ - int i; - - assert(dmabuf !=3D NULL); - - for (i =3D 0; i < dmabuf->num_planes; i++) { - if (dmabuf->fd[i] >=3D 0) { - close(dmabuf->fd[i]); - dmabuf->fd[i] =3D -1; - } - } -} - uint32_t qemu_dmabuf_get_width(QemuDmaBuf *dmabuf) { assert(dmabuf !=3D NULL); --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653423; cv=none; d=zohomail.com; s=zohoarc; b=dqhn3dxpd3fdhhPlpvG50zOv+k8PYHZm7bSlemr0KxstBvNDxEr59sXCxaEnotLGa2pabPfvswZN+w0FmAh4CssP6lyH4erqlfj61Q7Z8eTnj/lQR3gXJeKe8B0UFQUE/cafobqDAiXPL7k0wiaMMei9HoNL4+c0bDLm8f1p4uI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653423; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Bfyr6qBs5Y+Qx1HUq/BkQtgFDr/r2UlyOodG7Hq24vw=; b=TCojlTr8M0f6FTKKsgneB8qvGbbbj2xGRauKl48p7eHiCavQYC97wLOQh7ImzdIXnFpGLSd8SqX366lt+UscKsRNoIdmlJ2RolPa4F+dJbclVkaQhkoZQ2nD2WW7toSwQp0tSMCzU5u//0JKKrBoscxzb2wnAMKrCs1yVC1CwEs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653423081703.699052713537; Tue, 25 Aug 2026 03:23:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoJa-00083Z-IF; Tue, 25 Aug 2026 06:23:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoJY-0007sK-S8 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:23:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoJX-0005rB-5k for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:23:32 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-614-0eEqwPbxNAOO5jhV0f_EOg-1; Tue, 25 Aug 2026 06:23:26 -0400 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1C78E1956050; Tue, 25 Aug 2026 10:23:25 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 540A85B1; Tue, 25 Aug 2026 10:23:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653410; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Bfyr6qBs5Y+Qx1HUq/BkQtgFDr/r2UlyOodG7Hq24vw=; b=JbHUid8n1M1urrOfAhV6CjAUT2Howaw/dxJRQb+zCoyLt04MUYvQ4LbF7+dFsHYwqS/RGt RbJDbTaXjD/q54DeVi2KOSYx5e36yUt7tGXCtC8wBZ9r/XD0H04cYbw0rwvApzrT2+w8ts VJIPFTA2u2Juk3yBdm/sLSO15zRTYME= X-MC-Unique: 0eEqwPbxNAOO5jhV0f_EOg-1 X-Mimecast-MFC-AGG-ID: 0eEqwPbxNAOO5jhV0f_EOg_1787653405 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:44 +0400 Subject: [PATCH 07/18] virtio-gpu: release the dmabuf when a scanout is disabled MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-7-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=1537; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=67Z0bv6AuE+gCsBGjRcXahvYiTOpF6YGA9WrwezNoqA=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyYIE5TS+/hczyJj42v6TlP+2n594o37NeMu dRkVJ0dJXaJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1smAAKCRDa6OEJdZac 5fW3EAC0meK5cXI5jv45jDhZJAHjd8aBEBc0iXejfxJdBYQQH9wEp/Fs2Vw00BsjMoT7/1dVX/i +aJGeLC9sRmwGeCx6eY5mgIzNSjuGAUb7zglYkbp5klEpb2HneYphOf9CbpLp970mByJm9e1UKy CfPbM35+5p/gjAHuj1XX69IxD1/RLrbP7jGmrmdYngBjc/56Bhe+DJ7T24Hir4TaceEbDvfLFXX qgUV8QX0d0WShc2D44RoTKXyOEY3MkC3cP58H1cuukaBudChdnGc1sgqrva1qRUzV2qyViv/wj5 woB3c5ZSEhSsSGjqBlUyXaqWm0PwLWdwm5RD+cEBTiK8BjpvCJvKqZDbL+D9uq06h/UHejWgweO aQk/ccl9TvCHuI6db2+EBL4Nqf4kMCfkzu+PelmE1cN4uquvIHPpgKDdDJlFwh2FZLtaBhLagm7 OgZhLmkxQitmN0frjxaY5pCruPla2fg5SM1cbdiIxTczXftgEE9UIZOETXymwMlGyjKV6r3GiMH r+PKoDJe3tX8H71L/2qjI2fL+LEwGewc3GPz3mWE8jUV3vMYVrKj7x6hE4O8feRpjKz4F2VFdVZ r46rHHLNLTXbM341IsOCv7ga5R+HHaueqx85otyfbKCNII9Qg/5yYgnA1AM7xGXz7/DV5Y1AOaT LdtBYUyjxW2TntA== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653424280158500 Rather than waiting for the next set_scanout()/update_dmabuf() to replace it. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 0335b636068d..46ddfeeaba87 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -387,20 +387,31 @@ static void virtio_gpu_resource_create_blob(VirtIOGPU= *g, QTAILQ_INSERT_HEAD(&g->reslist, res, next); } =20 +static void virtio_gpu_release_scanout_dmabuf(VirtIOGPU *g, int scanout_id) +{ + struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[scanout_= id]; + g_autoptr(QemuDmaBuf) dmabuf =3D scanout->dmabuf; + + if (!dmabuf) { + return; + } + + scanout->dmabuf =3D NULL; + qemu_console_gl_release_dmabuf(scanout->con, dmabuf); +} + void virtio_gpu_disable_scanout(VirtIOGPU *g, int scanout_id) { struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[scanout_= id]; struct virtio_gpu_simple_resource *res; =20 - if (scanout->resource_id =3D=3D 0) { - return; - } - res =3D virtio_gpu_find_resource(g, scanout->resource_id); if (res) { res->scanout_bitmask &=3D ~(1 << scanout_id); } =20 + virtio_gpu_release_scanout_dmabuf(g, scanout_id); + qemu_console_set_surface(scanout->con, NULL); scanout->resource_id =3D 0; scanout->ds =3D NULL; --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653437; cv=none; d=zohomail.com; s=zohoarc; b=i0lPVP474Cc5TdvfDsP1kKem7FqHAKyWPjv2eg+KuAsRY+iFrr5lJ77d/Ez1FMzNRroMw0jk+G0vruJUtdJG2QBuLNm5IzhhSjMzPTMTCNW8QMGsIHHGsMz9jxwd7B0+qByJSPVaTObJrqHcHG0BHcWDDwJkEToRjrVdxPLiiJo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653437; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=iT6mMAqRVTImBEC5rWFg6Vqv7O4bjpezCBBc6+Q+QGQ=; b=csJ+HL9NSy79uPAQT95fxMNiW/WhvZ9EhRMWJ8iUAjlntrO61FZvO2NTxOkkiXt5xa+BBnioe3bwm9qI6zngwOqoBWF4M+vrEBppZCiip/MWH2wGj5fd23xRpH+XiSsCgp8bT8R+xmsGo85Dqd7+ixHRSXXHw0NAZe0Jk8yGgaM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653437127319.97520613276834; Tue, 25 Aug 2026 03:23:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoJk-0008S7-Cb; Tue, 25 Aug 2026 06:23:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoJi-0008Pp-CK for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:23:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoJg-0005tj-Qe for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:23:42 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-635-8Y2hZyjhMRKX4nKucZJ6Ew-1; Tue, 25 Aug 2026 06:23:36 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BE1471921EF1; Tue, 25 Aug 2026 10:23:35 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D6A1C18005B6; Tue, 25 Aug 2026 10:23:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653420; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iT6mMAqRVTImBEC5rWFg6Vqv7O4bjpezCBBc6+Q+QGQ=; b=Ryacnbjg/uXs13Aoh8+1v9K1I67srT1L4ncdwn+JFSLYjuD/cpzt5AmBP2rqpT8Cqa47bC I9ddWqdmMy8ezoVsiU240rZ+BZfyZYf/PGCipAchx6WuzjxEjMcG+XB5WU8tfnj+pnu4/d woSNDGaJP5QlIL/f+hSKnJ1TgzudTEM= X-MC-Unique: 8Y2hZyjhMRKX4nKucZJ6Ew-1 X-Mimecast-MFC-AGG-ID: 8Y2hZyjhMRKX4nKucZJ6Ew_1787653415 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:45 +0400 Subject: [PATCH 08/18] contrib/vhost-user-gpu: drop scanout_bitmask bookkeeping MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-8-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=3094; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=VIpypVrDVyq+4VlT7777jceHg8bPRbzJ/nlJeIOylXM=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyY86Pt/JkXRLKR3jwksx1qOvHXZ+wSIWmes KG8gbgTqJGJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1smAAKCRDa6OEJdZac 5bQ1D/9Y6msJqAdHKh3GZRzZQ2zLs0ouQIZ2RYi2AMWAMzKGO8vvIEUiQKIjb20fn0zmB5+JGHl 6t5UBsV6qv0LTl4oKgn6GY2GY97MQt7NjIBUpWzAxMrUvV81F4hBqJ05o5dhKBecHWpxhgoXGmF KndzIfZlPGg8hnEiFQsYPj+ZB7a81+uPX5cNAksqIbE3Co7VX7W/J7+FNz9tAPVOets1wV3L/hn +aryGRgZ2AGEE64HiqE8utUP4y17vJgr7/PHtWwr/QoqKiNZjLfLGQzXCDiJebtBJE5ASC2B12T OpIh9cUvlpIAQ/8Ut67Nyg+4jtwJMG5HisvQ7UF++61/ZpkOdDyMaHRBmFiUQmtaP2ebwHkP4aj cQYoGX7j3ny9ViT+JcbblDu6Pe9iVsTEY568H9wUKTXlqAo5tjdHCDIYCj/YkljdmYlHtJ642YQ N5zFX788J/RuYxWLc7CEi2FlyVuezwZhhSBeR1+myb5O/bkLmwcHrHb5nExkAaQgD4lxdHe0xSv ETCHUqf46/dfuKhFdR0Z94bfGOyr5wE0a6vVLuiGnkhkHJugx2ycK7yNe0V1RAtQdt2rqnsLCBC qmy/guMhUaB7H1QXkFAFCNm801lJVJWlmJqz71gcwN4jJmFUwuJt4JSCwcddDFGCIY83SrJ0I27 PVmfnCpy/dfNBIg== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653438261158500 The per-resource scanout_bitmask is a reverse index of which scanouts reference a given resource. The information is already available from scanout->resource_id. Performance impact should be negligible. Signed-off-by: Marc-Andr=C3=A9 Lureau --- contrib/vhost-user-gpu/vhost-user-gpu.c | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/contrib/vhost-user-gpu/vhost-user-gpu.c b/contrib/vhost-user-g= pu/vhost-user-gpu.c index 786488150932..cd4e6b60cc13 100644 --- a/contrib/vhost-user-gpu/vhost-user-gpu.c +++ b/contrib/vhost-user-gpu/vhost-user-gpu.c @@ -36,7 +36,6 @@ struct virtio_gpu_simple_resource { uint32_t format; struct iovec *iov; unsigned int iov_cnt; - uint32_t scanout_bitmask; pixman_image_t *image; struct vugbm_buffer buffer; QTAILQ_ENTRY(virtio_gpu_simple_resource) next; @@ -416,17 +415,12 @@ static void vg_disable_scanout(VuGpu *g, int scanout_id) { struct virtio_gpu_scanout *scanout =3D &g->scanout[scanout_id]; - struct virtio_gpu_simple_resource *res; =20 if (scanout->resource_id =3D=3D 0) { return; } =20 - res =3D virtio_gpu_find_resource(g, scanout->resource_id); - if (res) { - res->scanout_bitmask &=3D ~(1 << scanout_id); - } - + scanout->resource_id =3D 0; scanout->width =3D 0; scanout->height =3D 0; =20 @@ -446,11 +440,9 @@ vg_resource_destroy(VuGpu *g, { int i; =20 - if (res->scanout_bitmask) { - for (i =3D 0; i < VIRTIO_GPU_MAX_SCANOUTS; i++) { - if (res->scanout_bitmask & (1 << i)) { - vg_disable_scanout(g, i); - } + for (i =3D 0; i < VIRTIO_GPU_MAX_SCANOUTS; i++) { + if (g->scanout[i].resource_id =3D=3D res->resource_id) { + vg_disable_scanout(g, i); } } =20 @@ -659,7 +651,7 @@ static void vg_set_scanout(VuGpu *g, struct virtio_gpu_ctrl_command *cmd) { - struct virtio_gpu_simple_resource *res, *ores; + struct virtio_gpu_simple_resource *res; struct virtio_gpu_scanout *scanout; struct virtio_gpu_set_scanout ss; int fd; @@ -704,12 +696,6 @@ vg_set_scanout(VuGpu *g, =20 scanout =3D &g->scanout[ss.scanout_id]; =20 - ores =3D virtio_gpu_find_resource(g, scanout->resource_id); - if (ores) { - ores->scanout_bitmask &=3D ~(1 << ss.scanout_id); - } - - res->scanout_bitmask |=3D (1 << ss.scanout_id); scanout->resource_id =3D ss.resource_id; scanout->x =3D ss.r.x; scanout->y =3D ss.r.y; @@ -794,10 +780,10 @@ vg_resource_flush(VuGpu *g, pixman_region16_t region, finalregion; pixman_box16_t *extents; =20 - if (!(res->scanout_bitmask & (1 << i))) { + scanout =3D &g->scanout[i]; + if (scanout->resource_id !=3D res->resource_id) { continue; } - scanout =3D &g->scanout[i]; =20 pixman_region_init(&finalregion); pixman_region_init_rect(®ion, scanout->x, scanout->y, --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653443; cv=none; d=zohomail.com; s=zohoarc; b=atFuFIOuoeXZH+0dt55uAP9DU6OHNylQKLYmuqVM489m7IEOUFLyfcQVmyW/4XHjNPXao24nc6uAzQ8A0a6z2Lzwf3LKHJk2LHTxSxiBrOpOTKhbRhdUls0WM+5aQkP2RFK2uTura2/xxOFjYaTBH84GMF07okOA1BnEMsGbxFM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653443; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eGC3ZtTD0o/8b0IH0Neq58h30rThv29Te40Za8zKIHA=; b=JGNQrMdijUgccT0CfMPjW7bEhimGq8QM4mnKbJk71GKjJyfn+5Yiku90ByAcRjit4myNyPBAOPbgxAWL557oXJY4WPXiR59wLEmBdqs98vWG6B/+zNGjmov4RRzwUo2BK4WFlXcxIHXjzMWmU97e7xZNDEgkAeHF8z0J8QTD5xk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653443636183.65655030107155; Tue, 25 Aug 2026 03:24:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoK0-0000ak-RZ; Tue, 25 Aug 2026 06:24:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoJw-0000PJ-9M for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:23:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoJu-0005vj-Jn for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:23:56 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-496-7RDxwXxcMA6-Y48T5Ij6uQ-1; Tue, 25 Aug 2026 06:23:49 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C6D5A195607B; Tue, 25 Aug 2026 10:23:47 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7D8CD30002EE; Tue, 25 Aug 2026 10:23:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eGC3ZtTD0o/8b0IH0Neq58h30rThv29Te40Za8zKIHA=; b=NVYh9eHwx2yPpf2UCKdy0tbHRw2yj/0IEXyqDiukQk/eOopsw/EKDdrR4Kqp8v02PRzOaC pypiGKRzsBexvcK6oDFzRPoyFr5tZYNGhuqbRR18FGDA6SepTaNLAnyd3CAnsCmdkShP+5 aGKoLGajeGPKYxy/QigzRJQc6JWPV3A= X-MC-Unique: 7RDxwXxcMA6-Y48T5Ij6uQ-1 X-Mimecast-MFC-AGG-ID: 7RDxwXxcMA6-Y48T5Ij6uQ_1787653427 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:46 +0400 Subject: [PATCH 09/18] virtio-gpu-rutabaga: fix scanout handling MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-9-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=2911; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=gi3nzR563umttu9ZHW8uYx324CNeZof5aiVhz7+8Tyc=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyYNUBKeDrbaWP8yEQSKMpUQndMIX3Zyt9Uj g2ZNz8CdUmJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1smAAKCRDa6OEJdZac 5TxZD/0fZzrbIr21zOXPxkkVs+9hHkwAZ7uFtcZ5Wnoefa7BJSCecKoYidG8HwxUkHQqBV68zhh 7sOBspakhzw6hhwD92F4GPyPkku4b1/T4HY/bhVpBQ1ncftKGoQ2YLZ9fH0I7XB4wFXWLxTkyFx PgUnaM84x1jeEke5CEPJdR/itzHhJPfi7UJHYFxqDQ3ISwfCCA7ZpvJW81nX8NUczgYVKlA8mys xsFtDEajKx1f6h5BahrFtaDSJx70k6H/G4pvG0oYMxHGD/YMz9+y9HZ3pMV2nS/W+dQncTPWVcz 5pliwSzrQ2M8Hftntkxc2yVDL3XN8UyU+dr0y+LrZcCXkXg8FZe53vsbHoi2UZ2BMfc6n9tb8Ro mSAoYG5oYcfvBdYOp9+FVcBJzkomDmMQqRF4bZbH3vwlK8DMSDE0UoTYtDmG1MxVCNKtKzU8CHL wzGURmgMWxd5hlz4+KahzUQwdgXf42JUlZX+r/T+rJsTRcesgmViFYR8YdA1LHaUvW5FzfINOkw 2o4EhUWHhxXATySNBTmJbGKzjBK9TH6Atp443T2TG0CD52a99Ax9pkcr/hHpQmLvQESHoVPc0VT nNSV0/biXoB4mwHpRbV8epFKZCf1aSxGvUggOPH6z1AdCL2t66SL8uXeF0RBVgCRu4ezoc5I5IE lP4b8l60TqHw/nQ== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653444280158500 The rutabaga backend was misusing the scanout_bitmask field as a plain scanout ID instead of a bitmask. Fix the scanout lookup to use scanout->resource_id directly. Also fix the missing resource_id clear when disabling a scanout, and flush all matching scanouts instead of just the first one. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-rutabaga.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutab= aga.c index a054f8117f14..fcd9c94d580c 100644 --- a/hw/display/virtio-gpu-rutabaga.c +++ b/hw/display/virtio-gpu-rutabaga.c @@ -154,8 +154,15 @@ virtio_gpu_rutabaga_resource_unref(VirtIOGPU *g, Error **errp) { int32_t result; + int i; VirtIOGPURutabaga *vr =3D VIRTIO_GPU_RUTABAGA(g); =20 + for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { + if (g->parent_obj.scanout[i].resource_id =3D=3D res->resource_id) { + virtio_gpu_disable_scanout(g, i); + } + } + result =3D rutabaga_resource_unref(vr->rutabaga, res->resource_id); if (result) { error_setg_errno(errp, @@ -259,7 +266,7 @@ rutabaga_cmd_resource_flush(VirtIOGPU *g, struct virtio= _gpu_ctrl_command *cmd) =20 for (i =3D 0; i < vb->conf.max_outputs; i++) { scanout =3D &vb->scanout[i]; - if (i =3D=3D res->scanout_bitmask) { + if (scanout->resource_id =3D=3D res->resource_id) { found =3D true; break; } @@ -283,7 +290,13 @@ rutabaga_cmd_resource_flush(VirtIOGPU *g, struct virti= o_gpu_ctrl_command *cmd) rf.resource_id, &transfer, &transfer_iovec); CHECK(!result, cmd); - qemu_console_update_full(scanout->con); + + for (i =3D 0; i < vb->conf.max_outputs; i++) { + scanout =3D &vb->scanout[i]; + if (scanout->resource_id =3D=3D res->resource_id) { + qemu_console_update_full(scanout->con); + } + } } =20 static void @@ -307,6 +320,7 @@ rutabaga_cmd_set_scanout(VirtIOGPU *g, struct virtio_gp= u_ctrl_command *cmd) scanout =3D &vb->scanout[ss.scanout_id]; =20 if (ss.resource_id =3D=3D 0) { + scanout->resource_id =3D 0; qemu_console_set_surface(scanout->con, NULL); qemu_console_gl_scanout_disable(scanout->con); return; @@ -340,7 +354,7 @@ rutabaga_cmd_set_scanout(VirtIOGPU *g, struct virtio_gp= u_ctrl_command *cmd) scanout->ds =3D qemu_create_displaysurface_pixman(res->image); qemu_console_set_surface(scanout->con, NULL); qemu_console_set_surface(scanout->con, scanout->ds); - res->scanout_bitmask =3D ss.scanout_id; + scanout->resource_id =3D ss.resource_id; } =20 static void --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653455; cv=none; d=zohomail.com; s=zohoarc; b=irpQs13V6QAfyLBYsvQRi+7i92xmo+SIdithU5nHaabjNjdxnNAff6nYMRpuBGG2ufFWR9YceNzLb5Jbhl3iNsm9eWYEEB8IVGJWVY94i56c9VcBiIwn7JRRrRXbALSMZ7X7LXgRqNhqq49OgtuZQQRxuGzNu7BXptTZweKkTYU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653455; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4pmvqw1aKk5g+JiW9PtA2fMchRrT4yhQbzxGgZTS1M0=; b=YDmkOdznK7OAYMbjWMZ7gj94dpGII3kA+tlz6Q4z9T+s9ojKpjK3m2wAgZary2BZaRM8zNQHyxUicEVx0ddubazZhWgDeiNZ/BDRM2dd1uiAgCETNQFtCr91pNxsLd7qozcqZGCawylMZrPMzaxPWcYqt9P9rjo5GOLvmCZH0Ks= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653455607871.4897308939481; Tue, 25 Aug 2026 03:24:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoKC-0000xo-5H; Tue, 25 Aug 2026 06:24:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoK9-0000nn-8E for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:24:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoK6-0005xo-Fp for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:24:07 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678-rceEsJQBM0W9td6duwfccg-1; Tue, 25 Aug 2026 06:24:00 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A8C13186A70B; Tue, 25 Aug 2026 10:23:58 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1446630002EF; Tue, 25 Aug 2026 10:23:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653443; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4pmvqw1aKk5g+JiW9PtA2fMchRrT4yhQbzxGgZTS1M0=; b=VGRQavLaEbXfjv0Bc/AIXqdhOssQImHI0IMe8a0naric/LjsIKlmdUUEHeHz5DGG24U4a+ VpqATI/EnQY8+X0wAaqyiOChImFGjLZ7UVGgxWEg5plYSHgCuvld0/EDjGF10Kh5mtFBCy 1xhGAQN+dlE+qFFWigeGgcLfqpyOJyo= X-MC-Unique: rceEsJQBM0W9td6duwfccg-1 X-Mimecast-MFC-AGG-ID: rceEsJQBM0W9td6duwfccg_1787653439 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:47 +0400 Subject: [PATCH 10/18] virtio-gpu: disable blob scanouts on mapping cleanup MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-10-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=1230; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=iLL5NIMdfsWGthlPU0qlwz/om0MvFo9XZbTOmTWt2Vg=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyYL4YSP2drwu8/FHWUiriQ8VP2mY97HLZfj qi9UawuyeWJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1smAAKCRDa6OEJdZac 5bHzD/9d+pqJJ3xpiXlc6BvIknepaHuiFk/28Dp6jCMVfXqq54I0Wj6oOKUEwzsyLda5tvjYE4W /6MaTH4a9EhCl5sZ1fv63CXj3tW55UmGhmv56lhT4MeURyvEM5Vkaxf5H3dnHHQ6jyRlwxXRY7M iFMcabRDNPdsfwYRfMgPOZwEXoCkzX6VYnh5cCd45MNY4zqbJG0+5LTlg/D0zepNJIhPs1yEFl8 bdYTKFPG1AK2XQnEUe5BvQA2jAhExkXVKb39BQ++R0pF//Xq2BIFrT/fJeP1Dvfe+/OEhyhOLY0 BPhYqCBDF7nIRoH09J3pKK2olCPwjyqGYL06wmJFHSr0Dw5DKCdrdyYLiokQDneUWfaekqva3L3 v/Sdov/ph3+p5uLp0JNHUVQ4bBSi5xuxr3DIXObZjdBdMeSQDYE0I6DnWR5/3PTaqQgn3jvw3qA t6W1nUsENOhFu+J5qD7SyAqnSh4EDQxySzjky2MPDtQkkADXV0f8Mp4Nns80I4bOE0fo6lQpajF TdS8NA7jHRCFmmutyJs2qkjOuazpydsPFP38GMIy7QkmVv3ZGNH+CMbnWNT6sv4noNwVxRrbxkB +rgprKDvnpwT9/OdldNmLMP0M5DV1kP1nPm1fKb0lDy9mP09G92146HiN6EKyj+UMzWBAiRybZW wSvgSwuBmlvB2yw== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653456761158500 When a blob resource backing is cleaned up (for ex via detach_backing), any scanouts referencing it must be disabled first to prevent the dmabuf from outliving its backing memory. Fixes: CVE-2026-66020 Reported-by: Akihiko Odaki Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 46ddfeeaba87..e547cac60398 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -982,6 +982,16 @@ void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g, void virtio_gpu_cleanup_mapping(VirtIOGPU *g, struct virtio_gpu_simple_resource *res) { + if (res->blob) { + int i, max_outputs =3D g->parent_obj.conf.max_outputs; + + for (i =3D 0; i < max_outputs; i++) { + if (g->parent_obj.scanout[i].resource_id =3D=3D res->resource_= id) { + virtio_gpu_disable_scanout(g, i); + } + } + } + virtio_gpu_cleanup_mapping_iov(g, res->iov, res->iov_cnt); res->iov =3D NULL; res->iov_cnt =3D 0; --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653481; cv=none; d=zohomail.com; s=zohoarc; b=jMhTooJA7lmaPFquqi2HJ4pDoiroeciYV/RZt6eXv7Pl90o8YFFBrccjzdKH/RzOjafJOdZ8po559ezgfGUCjwgk4KJ1SPT4vfLglMI7hogxCW4iOei/WTMJhRIH4dEhxKGDXLBryJoy/qjwM4ZICxewZcdZK7Preoh8P9uzgnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653481; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=GSmR9dNgcxhkW1f0xItF+J03z6SZAA/S+RHpdsCIeP8=; b=esVU/vKYzfg3EhVZ5ennKAgviRjvmlhqdHMBD8EI2gy4JM5+JAmQw9H5fgVi2/PH7itBSeoYYkpiOSafzZYsWBqC5KwD2QWH+3WXkEH/3dTHAGlkKuc2fF+HTRQaLtiPszxUrpP13+MpS1UV8sJwiFRlMnHQWdbPIdFiVgs4zyU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653481879994.9874963279193; Tue, 25 Aug 2026 03:24:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoKU-0001S6-7l; Tue, 25 Aug 2026 06:24:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoKS-0001Ra-EB for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:24:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoKQ-00061o-VJ for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:24:28 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-255-87Bv7DvKPN-i4kfN-BZhGA-1; Tue, 25 Aug 2026 06:24:21 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BCC11180883E; Tue, 25 Aug 2026 10:24:20 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3F642195604A; Tue, 25 Aug 2026 10:24:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653466; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GSmR9dNgcxhkW1f0xItF+J03z6SZAA/S+RHpdsCIeP8=; b=WrsgNj2yBMNu2QqkNxVnpXL50o0s30WkQLt+ZuFW3KqIpb9ou1K8+Sre9LcGzGUi3CkoAA 5Rb5QQNTo0wgEkPNwLF45ffkIt01GzFEGyFM8ETKADXijPQJzS9HEgtOlKjiRmIBGRLHXQ 1surOLo+16NfJiasG7GgkvCQh3O2clE= X-MC-Unique: 87Bv7DvKPN-i4kfN-BZhGA-1 X-Mimecast-MFC-AGG-ID: 87Bv7DvKPN-i4kfN-BZhGA_1787653460 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:48 +0400 Subject: [PATCH 11/18] virtio-gpu: drop scanout_bitmask bookkeeping MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-11-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=3533; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=RUnzO1ES/piqV0h109hympaotXHFUXO2eIbxaiKafMM=; b=kA0DAAoB2ujhCXWWnOUByyZiAGqNbJihLPzBUjZih1gCJqpGNTCq/BfrQGkYSYV2+8Y0Hc5S4 4kCMwQAAQoAHRYhBIepvZM/h8YG0nb2Ldro4Ql1lpzlBQJqjWyYAAoJENro4Ql1lpzl1lcQAIU2 z2kJXjajLXcWhocgfq5lw7nsDsIQSG1W4brDwMt/WUJQwjDE2fP7l+uUU1nVVWdIbyXH/POCC4f vlG/xq/xA08w2X6RXmYxdCyy510Wy2l6dBzGjV4o1aCH9iRoJPSx8z0SeoqvJ4Qll80rCVS4pj7 FVib3kUc0gdbJ0aBlASPmOJKEMoZG7Ma8IxPJTseMYil6rOvKvl6nVAhra2K+tm7mjnROqHwZax pMZPRccFlkYusug635mQIkAb9F0DhFu6BVUQ0/wPgnxVEdmHG6tLsky1agEqd8RXDFTzleuwLPT OYwr99mWJabSvYG0UdVanLHpPkVi0CEDgMXaao8znM4JU0WWxXz2Nja3nfiz1DhTtqdm0Pko62q 7d7tW0EKziTEsBay47c0L9gY4Erj6fZvLMwHlTDsLcafyTAtsExRW2h+Sqw+DCDUNSvC7A5NFpD 394/oQPDMPYxP9eyE+GeBllGAEav0iOiPV3Fntv9J+5MNrQY99OTxvTJcqlWLHAqeJpzVu+eEVL /nGuDaZT6X9UaAif9O7oPGYBFtu+ut+yDMvfh5vNGnM0DPgDYZi6o3vHAofFYs7F8u29nkM/l3G xCLuS2NPR86Nl/plui9qhSuQmMbV23oCjkyeIMWhBP2v6TXAJ5p0VyCD0ZpBB42MSYgd17uXiuM i1v37 X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653484435158500 The per-resource scanout_bitmask is a reverse index of which scanouts reference a given resource. The information is already available from scanout->resource_id. Performance impact should be negligible. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu.c | 26 +++++--------------------- include/hw/virtio/virtio-gpu.h | 1 - 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index e547cac60398..5362f7a4c269 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -403,12 +403,6 @@ static void virtio_gpu_release_scanout_dmabuf(VirtIOGP= U *g, int scanout_id) void virtio_gpu_disable_scanout(VirtIOGPU *g, int scanout_id) { struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[scanout_= id]; - struct virtio_gpu_simple_resource *res; - - res =3D virtio_gpu_find_resource(g, scanout->resource_id); - if (res) { - res->scanout_bitmask &=3D ~(1 << scanout_id); - } =20 virtio_gpu_release_scanout_dmabuf(g, scanout_id); =20 @@ -425,11 +419,9 @@ static void virtio_gpu_resource_destroy(VirtIOGPU *g, { int i; =20 - if (res->scanout_bitmask) { - for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { - if (res->scanout_bitmask & (1 << i)) { - virtio_gpu_disable_scanout(g, i); - } + for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { + if (g->parent_obj.scanout[i].resource_id =3D=3D res->resource_id) { + virtio_gpu_disable_scanout(g, i); } } =20 @@ -593,10 +585,10 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g, for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { QemuRect rect; =20 - if (!(res->scanout_bitmask & (1 << i))) { + scanout =3D &g->parent_obj.scanout[i]; + if (scanout->resource_id !=3D res->resource_id) { continue; } - scanout =3D &g->parent_obj.scanout[i]; =20 qemu_rect_init(&rect, scanout->x, scanout->y, scanout->width, scanout->height); @@ -621,16 +613,9 @@ void virtio_gpu_update_scanout(VirtIOGPU *g, struct virtio_gpu_framebuffer *fb, struct virtio_gpu_rect *r) { - struct virtio_gpu_simple_resource *ores; struct virtio_gpu_scanout *scanout; =20 scanout =3D &g->parent_obj.scanout[scanout_id]; - ores =3D virtio_gpu_find_resource(g, scanout->resource_id); - if (ores) { - ores->scanout_bitmask &=3D ~(1 << scanout_id); - } - - res->scanout_bitmask |=3D (1 << scanout_id); scanout->resource_id =3D res->resource_id; scanout->x =3D r->x; scanout->y =3D r->y; @@ -1609,7 +1594,6 @@ static int virtio_gpu_post_load(void *opaque, int ver= sion_id) if (scanout->cursor.resource_id) { update_cursor(g, &scanout->cursor); } - res->scanout_bitmask |=3D (1 << i); } =20 return 0; diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index d3ca8d82586b..1816cb21de76 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -51,7 +51,6 @@ struct virtio_gpu_simple_resource { uint64_t *addrs; struct iovec *iov; unsigned int iov_cnt; - uint32_t scanout_bitmask; pixman_image_t *image; qemu_pixman_shareable share_handle; uint64_t hostmem; --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653498; cv=none; d=zohomail.com; s=zohoarc; b=l1fyACToO9Dkr9EiGk6DKOzPOc0Hj7Gdvb2sOwzhQNOaM+/rWFw0iVV4sRHqn+h2LZcTeACUqFn6ILiZv30HgxxyKO3mimkh89ChyAU21itLY4hmWRfPVjq2ibQPSGdShBDHYpjWYoksBUM0OlH99bemifMDlj6FOi3sj/dI0Ow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653498; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KbaR4QkgMrsVs3OGLnUUQ0qiQDBQJLZcAZ2qUTgcZ04=; b=JBOqvhKAVsnHvsUwF9ly4iOW+zr0bV/t6RV8iCYfUWVZ8Pe7/MgNlPQs/iec52CZW3WTCQ6F+H2sjUp5gBUtdcbzN7KfRUtTk5pRnxTBTHD+pZrKNFG2qPzfjEab7UBQpEC5nsKLNOtUGG5FX6jf3oGfIcVqKmLm4xGRHMHg1nk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653498041601.4515115201842; Tue, 25 Aug 2026 03:24:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoKe-0001fV-P1; Tue, 25 Aug 2026 06:24:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoKc-0001Wp-Jv for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:24:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoKa-00063H-Vz for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:24:38 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-340-vHybqtKwMSaEwJp-egGw_A-1; Tue, 25 Aug 2026 06:24:33 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B82AF1955F13; Tue, 25 Aug 2026 10:24:30 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7B38E18005B6; Tue, 25 Aug 2026 10:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653476; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KbaR4QkgMrsVs3OGLnUUQ0qiQDBQJLZcAZ2qUTgcZ04=; b=iZmx1PPt4FA4YtuH6JdyqtVnKVBa/c80uLMLKExa+orJWpNNvcGv8/TaDRIuDxHYg5J+Sn FZ7Bp8pB2tguBcsTsjTa2ZQW4VgyaW76ZK+DIl/Ha6zO8EGTXeHExequvTLEqqhFZboW3O j3sblZmZPCko9DjuUPv6aoqkZIVgLG8= X-MC-Unique: vHybqtKwMSaEwJp-egGw_A-1 X-Mimecast-MFC-AGG-ID: vHybqtKwMSaEwJp-egGw_A_1787653470 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:49 +0400 Subject: [PATCH 12/18] virtio-gpu: release dmabuf when switching to a surface MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-12-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=2476; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=W53mgQKDGqy47NLllukf15/S0W1UBuWpMAiQFTp1I90=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyYN33CIQ+ydzX6ITmlkVGe683PDOUl/ga4v A6g0BjjjpSJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1smAAKCRDa6OEJdZac 5Xu/D/4363qj79O63y2zooQrh2bf4Stna8w96yLUS8NwV3stxItwzmLmGOXWq4Tyxh98Kv+qKYL IE7pPWWtVCfoAj4pdqT8iq2MOY1AP1Ehx7yrf+nI9COQjwysNGRmRV9ZdKy4eOPW+FfubG78NSt Y2YTb/LqOv4rLdygLbIcs1g+VXoQZuUtgQ/QOY9FvTRrDuBuNJDTRqqheS3VDdyySZdq2/zCVDZ rDj7E0qr8/MHprsUQtnr2y3lLKLooSgW5S29WzRVTPx+LFMW8df0bHcY5GfZ6VttrZx9y4xsSNT M4kox8ExqVuytAY4B5F4VgpSRvYVcl5CYMpJV2i7wew/FQIgugwfV+FwAc9rmTsOY9utQ0d/+Ne EZZHOGkLw0I4xVG+kl66V8cKLWzl6is6KohqXH/4QUMrjyICfJk+MgZjxFlebeqpPyUjofZhJsO oASR8+ip97YLRe+JO0mllzxLBFdt4aHKIGpfu41BN7kJIBCzmsVdpcl8HoII6ZDvsxzek0MGJoT Ue/z3rNzn22RhE0W4B/XCF/c/VssF8dzXXnM6gsGG678aYvyWJMCXmqHQEMcnVyd99/OfTFxbex Jizd0Y3xw4NpAuUYoUE61YEirImiJfO//y5wQ6OxUNm+sM9n71hFMC2RSI0c4NAVIFPWrRTEEAE Gh6Q5UcwRPZ0wAg== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653498529158500 A scanout may hold an active QemuDmaBuf when a SET_SCANOUT switches to CPU-backed display data. Force surface recreation and release the old buffer in this case. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 5362f7a4c269..a74475dc6741 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -658,9 +658,11 @@ static bool virtio_gpu_do_set_scanout(VirtIOGPU *g, { struct virtio_gpu_scanout *scanout; uint32_t bytes_pp =3D virtio_gpu_format_bytes_pp(fb->format); + bool was_dmabuf; uint8_t *data; =20 scanout =3D &g->parent_obj.scanout[scanout_id]; + was_dmabuf =3D scanout->dmabuf !=3D NULL; =20 if (!virtio_gpu_check_scanout_bounds(scanout_id, res->resource_id, fb->width, fb->height, r, error))= { @@ -687,12 +689,11 @@ static bool virtio_gpu_do_set_scanout(VirtIOGPU *g, =20 if (res->blob) { if (qemu_console_has_gl(scanout->con)) { - if (!virtio_gpu_update_dmabuf(g, scanout_id, res, fb, r)) { - virtio_gpu_update_scanout(g, scanout_id, res, fb, r); - } else { + if (virtio_gpu_update_dmabuf(g, scanout_id, res, fb, r)) { *error =3D VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY; return false; } + virtio_gpu_update_scanout(g, scanout_id, res, fb, r); return true; } =20 @@ -702,7 +703,8 @@ static bool virtio_gpu_do_set_scanout(VirtIOGPU *g, } =20 /* create a surface for this scanout */ - if ((res->blob && !qemu_console_has_gl(scanout->con)) || + if (was_dmabuf || + (res->blob && !qemu_console_has_gl(scanout->con)) || !scanout->ds || surface_data(scanout->ds) !=3D data + fb->offset || scanout->width !=3D r->width || @@ -727,6 +729,9 @@ static bool virtio_gpu_do_set_scanout(VirtIOGPU *g, qemu_displaysurface_set_share_handle(scanout->ds, res->share_handl= e, fb->offset); =20 pixman_image_unref(rect); + if (was_dmabuf) { + virtio_gpu_release_scanout_dmabuf(g, scanout_id); + } qemu_console_set_surface(g->parent_obj.scanout[scanout_id].con, scanout->ds); } --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653491; cv=none; d=zohomail.com; s=zohoarc; b=TaQQ1CkOGnnW7dV37fhrwx2Ne578B8MCdVu5Ats+Nb1hj0hfDCArfworNzTISYccd1dMZyhKaT2AzqYPzAyRQSmktb7H2ZY6aL0rfu7VeZ7AzTqitwSRJNqIDf/3I1K6zsutLfYl1/NJbFnQ0/7t2Yj7pbP7ZY28JtSOpnnfVBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653491; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8tW+ZtXYwMHJzhR2UUaGK0H3jUg7Q78i83iuCfaafjM=; b=HATGEKfNMRt9kNABG6XtooJN3Uxel8YMBvwUNgv95umg+5+17o9ssmIkAFf937MPDJNRp5TzxRaspbS3kYy/ICTJveEsT09SeZVKVzh55G7zVrMYmUPb9h0cL0orvCaSsjiw6xF7EdYE17Zh0gAQLcaVAeZciADeJzF5Cyk2/SU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653491744788.3503252155642; Tue, 25 Aug 2026 03:24:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoKk-0001jh-H3; Tue, 25 Aug 2026 06:24:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoKj-0001jV-I5 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:24:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoKi-00064L-4a for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:24:45 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-354-PpwB_-N5NGyp1atv4TIk6Q-1; Tue, 25 Aug 2026 06:24:39 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EABCB1977667; Tue, 25 Aug 2026 10:24:37 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B9DD118005B6; Tue, 25 Aug 2026 10:24:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653483; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8tW+ZtXYwMHJzhR2UUaGK0H3jUg7Q78i83iuCfaafjM=; b=ABzfV3zDN6EIofrC7sPxXvoWRiCNpYZ57DM11qZHx7FfHKNlV0t5sixUbsQPLUaahKax5y Swxvb5/roBWSZfeVNWdqhFEfM+J33ksv5phtPItmWpU88MZT0qiWLZ0R05APwOavVXdugh VhdLs0IZRuhfOTEMf5D4MmgNoZAjtM4= X-MC-Unique: PpwB_-N5NGyp1atv4TIk6Q-1 X-Mimecast-MFC-AGG-ID: PpwB_-N5NGyp1atv4TIk6Q_1787653478 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:50 +0400 Subject: [PATCH 13/18] virtio-gpu/virgl: release dmabuf when a texture replaces a scanout MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-13-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=2259; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=LHNnFxC4pjL/D6mhLfKD2xVRaY/Sv4yHWpNX6gamutU=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyYOMHezjh83J25O5t3FSGUuJ3kB50cql/wQ 7EcL0OsV9uJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1smAAKCRDa6OEJdZac 5fPqEACU7c6yokFqB/riklC9HWJm3FajRqeKepijn1HGceQt19QL8MxVole/UkC1pqAqzGfclFn LnrBUx0DctAMkaa5+uo3uBciKem411miPd81vHdWuZ/78uiRB1E/YWI3Gygz2uVqRJbfNHPgX/v 6Mo5x8e59MPD/hJVykrEAMUWFOXXTTZSgWATCUdmad/n10DBUL+1jMnqVq54VGdydat8Qm9jU3F d8Ga3P+hiuQRvXGRcFILHLkElkJC2Ei9TFSzmPwyxkHGYB3575s2mkDHvnloAAlPhfJrcPaZ62a 4nRd7PrijnnE0GASf4Ouh5JtriD26HyUzXic/OAjJ47sAsv70ubrfWvZ784bFKzyjUHc5wkUO6t aqFFJ7WP/dcRRp9tpdpBTfE7LL+WXAYcviAp7HXhM5WG1Gzz1wQAnOEfD1+fmoIbUSb5Rb3yEHl zbp+kRm9jv2JGyQEuPFglP4STVgTZZJiu6duJOi5mMiqyaS0P53C6fkCege7vL4QTsyC5rTHhic QbPqEQinDttQDu728p/use5/7siGnLkDCnUh92js8Q5ck936QiSoS5dukbzFdRJYoC+Uxns0bzk 9CpRZ8nt/Gx4Ts/VQKIQ4He8muuygZ6ZVA+YUa1wxBe+bsO2wrRFOa/TQOcfWlo0ykAyjwnnilv 7YZak6dQ8Kf4/pg== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653492510158500 Release the scanout dmabuf before installing the texture. A full virtio_gpu_disable_scanout() is not used because the scanout is reassigned immediately afterwards. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-virgl.c | 3 +++ hw/display/virtio-gpu.c | 2 +- include/hw/virtio/virtio-gpu.h | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 6e298f997d66..532132e46031 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -586,6 +586,9 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, &cmd->error)) { return; } + + virtio_gpu_release_scanout_dmabuf(g, ss.scanout_id); + qemu_console_resize(g->parent_obj.scanout[ss.scanout_id].con, ss.r.width, ss.r.height); virgl_renderer_force_ctx_0(); diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index a74475dc6741..c50eb58917e8 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -387,7 +387,7 @@ static void virtio_gpu_resource_create_blob(VirtIOGPU *= g, QTAILQ_INSERT_HEAD(&g->reslist, res, next); } =20 -static void virtio_gpu_release_scanout_dmabuf(VirtIOGPU *g, int scanout_id) +void virtio_gpu_release_scanout_dmabuf(VirtIOGPU *g, int scanout_id) { struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[scanout_= id]; g_autoptr(QemuDmaBuf) dmabuf =3D scanout->dmabuf; diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 1816cb21de76..22a38589d63d 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -360,6 +360,8 @@ bool virtio_gpu_check_scanout_bounds(uint32_t scanout_i= d, uint32_t resource_id, const struct virtio_gpu_rect *r, uint32_t *error); =20 +void virtio_gpu_release_scanout_dmabuf(VirtIOGPU *g, int scanout_id); + /** * virtio_gpu_scanout_blob_to_fb() - fill out fb based on scanout data * fb: the frame-buffer descriptor to fill out --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653532; cv=none; d=zohomail.com; s=zohoarc; b=aR93biHBaIKvrIlwnVMS8QNk9LgA3zPfhAF7oMbMsUQcn53uBj5fzR6H8jHj25B+kUJd+NQnK+ttqVOQ8VAkvR3vfnOc2pTU+kEN25LBV3sX7EXnkbvuu6ZL684sfFQv9buhF5u1A7IA9p8umLy9R1HLaSltZ3M/rpwOTlOK+zY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653532; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HAIQDMbjocaIxfDEh0+ahshbil+tSNFXN95NHjHpi2E=; b=lTK8pr1HGhiJOddoYuapf4VI39oqDi8foq461v3fV8iRsZQcxBE6rSRtc2DK8F3bT6H1R+6S9bVYC20ujaUnJ2/0HJyjJT8rFBGJui8VsDELfi/jwHAeA+xuh55BDBZNXvGRuhTDfGBf7DBthGejidWUuXZGz88rep1W/kCIMbc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653532424398.0547698254753; Tue, 25 Aug 2026 03:25:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoKv-0001un-Op; Tue, 25 Aug 2026 06:24:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoKu-0001sW-It for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:24:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoKs-00065W-V2 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:24:56 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-167-p45qpAx6M1atLa65EE8Kzg-1; Tue, 25 Aug 2026 06:24:52 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BEC97185BE9A; Tue, 25 Aug 2026 10:24:51 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 45EAD180034C; Tue, 25 Aug 2026 10:24:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HAIQDMbjocaIxfDEh0+ahshbil+tSNFXN95NHjHpi2E=; b=CV3wbNM9C7Yl889ajMQcxC7//YuMJAtjATmIT81D0w1/+gkpPkbH/gSbJS2iz2vr4avY4b v2h48b50COO5Q4EI+6HqiCDb4tfc3uAYumWlS3semowvlCoMyFghq87OASp6KofgTYuuPq iTeDCami/VR98eQrJ8W6Fpd4xd2GqfA= X-MC-Unique: p45qpAx6M1atLa65EE8Kzg-1 X-Mimecast-MFC-AGG-ID: p45qpAx6M1atLa65EE8Kzg_1787653491 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:51 +0400 Subject: [PATCH 14/18] virtio-gpu: consolidate disabling scanout MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-14-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=2706; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=KNVZEsKUGlUk+zR5a5jT0oXvtxDURe7kh0rb7LxAr/E=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyYt3lynNO2v0uz5SujX9KGiL/rjnOmtbPtf KZPmrcMQKSJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1smAAKCRDa6OEJdZac 5aIoEACFsCI5r+m+99IcZ1YFKEYTI317mQgp9x2+KXTUND1RN84GGbP4G4L5GPutdmoaT7BijFm rXQz1vARpEt+k2iUuEBZx06ClzldQZAlfAEVsxwf5JAC/NoUe6+0rT924FDDIOfHKb9gJBETmcC dcvgO0R8TfaZcTH/3zwjGAC8/IEBFortzZb2i++9c8O63dVAUEZDPLjeDWk4UO90wuE3TFRTlhe JqYH0DOSzTHFucfVk41GXm94tR8L7AGKsVxoYwrCEePJ6H8yoz4usX4O1J/r09bMh4/dfkarQ4N RleKx7K2DkYqJ0IqOKSLxHvySext7j+ohQ9pw4VmGz5H2I3AlAEEmRTTxDOWiXWEV48ThQUpUHC LN10m/2g/AUIgxfjbRjEjpRI2sIsz+mUx0PCFOi8MxcwOUYdBmByihVrpi2lp5JRuAmTAFuyN2m Ki3dXpnMWQN+RKdrEhP/Fa1ELUJe+rvr1PF56SLSNu3B3xF2mwa+St+Hf6ynDA6O5etEJYnTSdw kcBHgDiUz+y/478frIMorG9WnD30molipyJNEmk/HiyJanKnX1B0cx1UaCIEgO/cw4JNZ+sMiwN g6ekN60yGdeChNpLpTnxGUbKrp8JTYhL/A0bLWemEEqUkUqQw8Wl1Lr92AFQlklMvEJzBVu+6XY Q9l1o/naubVCekg== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653534674158500 Use the common virtio_gpu_disable_scanout() to reset the scanout state, including GL state if any. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-rutabaga.c | 4 +--- hw/display/virtio-gpu-virgl.c | 6 ++---- hw/display/virtio-gpu.c | 7 +++++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutab= aga.c index fcd9c94d580c..5344a5f9e26a 100644 --- a/hw/display/virtio-gpu-rutabaga.c +++ b/hw/display/virtio-gpu-rutabaga.c @@ -320,9 +320,7 @@ rutabaga_cmd_set_scanout(VirtIOGPU *g, struct virtio_gp= u_ctrl_command *cmd) scanout =3D &vb->scanout[ss.scanout_id]; =20 if (ss.resource_id =3D=3D 0) { - scanout->resource_id =3D 0; - qemu_console_set_surface(scanout->con, NULL); - qemu_console_gl_scanout_disable(scanout->con); + virtio_gpu_disable_scanout(g, ss.scanout_id); return; } =20 diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 532132e46031..6cb9365a714f 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -599,8 +599,7 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, ss.r.x, ss.r.y, ss.r.width, ss.r.height, d3d_tex2d); } else { - qemu_console_set_surface(g->parent_obj.scanout[ss.scanout_id].con,= NULL); - qemu_console_gl_scanout_disable(g->parent_obj.scanout[ss.scanout_i= d].con); + virtio_gpu_disable_scanout(g, ss.scanout_id); } g->parent_obj.scanout[ss.scanout_id].resource_id =3D ss.resource_id; } @@ -1406,8 +1405,7 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g) int i; =20 for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { - qemu_console_set_surface(g->parent_obj.scanout[i].con, NULL); - qemu_console_gl_scanout_disable(g->parent_obj.scanout[i].con); + virtio_gpu_disable_scanout(g, i); } } =20 diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index c50eb58917e8..a7f549a6a8b9 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -404,8 +404,11 @@ void virtio_gpu_disable_scanout(VirtIOGPU *g, int scan= out_id) { struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[scanout_= id]; =20 - virtio_gpu_release_scanout_dmabuf(g, scanout_id); - + if (scanout->dmabuf) { + virtio_gpu_release_scanout_dmabuf(g, scanout_id); + } else { + qemu_console_gl_scanout_disable(scanout->con); + } qemu_console_set_surface(scanout->con, NULL); scanout->resource_id =3D 0; scanout->ds =3D NULL; --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653527; cv=none; d=zohomail.com; s=zohoarc; b=mV4LLy4uuYvhiCWxBeoD8lq1qSEnoKVg1pKbMnhNzDH/OMgk4PWMO+rW4c4k1QKNHEPzkcBAVT+3F1fr+WwMCGip83AgOHCbPaa84neuI4gwAessC9fKUXdZTb1FWMttSoWVEZvNqtqBjEXPoKJaWgwfr2pi/h48B0WDjcG4zJA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653527; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5MJrzXyFMbPp4Y4K5SAU9Emf58IWqZfzzL0ndx68q+U=; b=CrVvjGceBtkpmTiLyZbQ7N2B/gfXid4wFqJervY/0SS/RUkV/POO0958ubrbvf3+0aPEDBuM3Bdgazaoi6B0ShC9IeUuMbU1LQgOtyUqmi4NFaxbK8QHrsLGp+Z6birathfeCi3Oz1TavLQaShP/g6z1FdrHrvlrhEQq6EFF2ZY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653527467389.67507069262035; Tue, 25 Aug 2026 03:25:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoLA-0002Jj-D4; Tue, 25 Aug 2026 06:25:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoL9-0002DQ-5C for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:25:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoL6-0006PN-2O for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:25:10 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-136-o45GIaTiPeWTI2G5ASG9Jw-1; Tue, 25 Aug 2026 06:25:04 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A7D15186A726; Tue, 25 Aug 2026 10:25:02 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 75A6C18005B7; Tue, 25 Aug 2026 10:24:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5MJrzXyFMbPp4Y4K5SAU9Emf58IWqZfzzL0ndx68q+U=; b=WBXnbosOqnuhCWZjsNPfZiOeEcOMwHBL4Khg8Pg3Gt6V/drabwGl9cQRJ9aV+kesqAmAJO 1I7A78Y8Q/MU4n53o0b57gMlwXh+tYI/MTi8PHY4o/2JYKWR9QSi0zpvYBA6yiTJLjeEKL JDZfbID7yV92gXnOnyuihfhEipbWmus= X-MC-Unique: o45GIaTiPeWTI2G5ASG9Jw-1 X-Mimecast-MFC-AGG-ID: o45GIaTiPeWTI2G5ASG9Jw_1787653502 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:52 +0400 Subject: [PATCH 15/18] virtio-gpu: minor refactoring MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-15-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=3742; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=M+DsU7i5OHamO9hpXgnfHT8LBl3WTiNZ0wK3pgCSQJ0=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyYdPA7Pq5KyHtvAtQhI9LJqn6WbSpG5kUA0 zTQnDz1R9GJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1smAAKCRDa6OEJdZac 5abaD/9v5bYiBxoepkOLHSjSn+8G3TDaCoIqUfxuxAjZOsNg5W7iXbz9kXk/whRoufUYc8HW49g eyCZe9M5xZWdevOe6WW5O46eqnB6J5j/EMiF1L7iMiRMsUDuWSFUtlGqaAs7giDP3VIbMemtJJg O0xQ5Ee7lWNPf+iEZ1bUxo1g3VswU/HBVHVxkkaXLVsuXXWqnj0SD0KOTyLPXapA16M/81ubg1D zYGnyPktBqm7jhcVbLCESszSsMAJc2xHIXM9/abfzFEORF6RbTqqDZumprTcGe9YoaiAqB4D3VZ Fzkyyi/iN+b+RdJ0S6ujn8q1d+tVOgrGLf4Ae/yg5SzMG0K3m6ntq0YVcyBXxgLtyZ4lIUuqXZz JhvqXys+YoSPVBjE9BFBZJZaOGo7mdljX7HFM5DTcGsrUM5Xf545/+Nt+ZLZpYGGAeKWBQPwd+1 UlD3Ef5QB19Wm1OmMNqHKH9y9f+O0kTUWotq2zBAwj6Xff5HDBD2lORe+ONnBrM8+u5XpNLFhTI BZ3j1lmw7SgSWBksesPPIl/W5EKvO14KDAmJfjb2Wesp+O88OBrdpepL5amNGhYBlCwrgvI8Z8S J+heuDNbGXagSnO1CsUSEvrv1jY2aGyQKRKF7g5w/PbZnb+j3OitLlY+jdGDtPiRIYa7r0/lYvV oPPzjEGptiWT8zA== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653528647158500 Move disable_scanout() branch earlier, return early. (scanout->resource_id is cleared there) Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-virgl.c | 61 +++++++++++++++++++++++----------------= ---- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 6cb9365a714f..e2ad27343da5 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -546,6 +546,8 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { struct virtio_gpu_set_scanout ss; + struct virgl_renderer_resource_info info; + void *d3d_tex2d =3D NULL; int ret; =20 VIRTIO_GPU_FILL_CMD(ss); @@ -560,10 +562,12 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, } g->parent_obj.enable =3D 1; =20 - if (ss.resource_id) { - struct virgl_renderer_resource_info info; - void *d3d_tex2d =3D NULL; + if (!ss.resource_id) { + virtio_gpu_disable_scanout(g, ss.scanout_id); + return; + } =20 + { #if VIRGL_VERSION_MAJOR >=3D 1 struct virgl_renderer_resource_info_ext ext; memset(&ext, 0, sizeof(ext)); @@ -574,33 +578,32 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, memset(&info, 0, sizeof(info)); ret =3D virgl_renderer_resource_get_info(ss.resource_id, &info); #endif - if (ret) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: illegal resource specified %d\n", - __func__, ss.resource_id); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; - return; - } - if (!virtio_gpu_check_scanout_bounds(ss.scanout_id, ss.resource_id, - info.width, info.height, &ss.= r, - &cmd->error)) { - return; - } - - virtio_gpu_release_scanout_dmabuf(g, ss.scanout_id); - - qemu_console_resize(g->parent_obj.scanout[ss.scanout_id].con, - ss.r.width, ss.r.height); - virgl_renderer_force_ctx_0(); - qemu_console_gl_scanout_texture( - g->parent_obj.scanout[ss.scanout_id].con, info.tex_id, - info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP, - info.width, info.height, - ss.r.x, ss.r.y, ss.r.width, ss.r.height, - d3d_tex2d); - } else { - virtio_gpu_disable_scanout(g, ss.scanout_id); } + + if (ret) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: illegal resource specified %d\n", + __func__, ss.resource_id); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + return; + } + if (!virtio_gpu_check_scanout_bounds(ss.scanout_id, ss.resource_id, + info.width, info.height, &ss.r, + &cmd->error)) { + return; + } + + virtio_gpu_release_scanout_dmabuf(g, ss.scanout_id); + + qemu_console_resize(g->parent_obj.scanout[ss.scanout_id].con, + ss.r.width, ss.r.height); + virgl_renderer_force_ctx_0(); + qemu_console_gl_scanout_texture( + g->parent_obj.scanout[ss.scanout_id].con, info.tex_id, + info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP, + info.width, info.height, + ss.r.x, ss.r.y, ss.r.width, ss.r.height, + d3d_tex2d); g->parent_obj.scanout[ss.scanout_id].resource_id =3D ss.resource_id; } =20 --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653526; cv=none; d=zohomail.com; s=zohoarc; b=ZvEzLzKCwsZK1GCLa4rnQK0bFBetbS6R0uLdFSqD8o9dEUw7GTdFd0+J6f7+ha7XINEbWQQxyPERMpfx4ZXWsDa7WEyfIU/hmYPfiSiOyPVfUQrSUY806OGvSmktQw27ckP4xPyltcaEZuIdT3lrIMlEEIrDKxPkmF+Ztqco5fw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653526; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Iles9kpKBJi7ke6NFfqbSL3la7rXi36pHcWAFP5A89k=; b=Horjne/SwShgmpXPpom/dEJdGnqMTFhFX6QBo0mm7udNTWbMZXKT+6THy8pzj3Qphyzqsy6k3Z2UG2i5Z+mATbKpTpT2Fwrlu0JoNZQdfxU5Gx9N8+c0Acuf6vZpSXElDOwk9SyfHVEQwscL1NpOvbjojVisvaj0oKmDXuTuKZ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178765352678175.68923750544911; Tue, 25 Aug 2026 03:25:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoLI-0002aY-Uf; Tue, 25 Aug 2026 06:25:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoLG-0002Ws-NG for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:25:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoLF-0006Td-By for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:25:18 -0400 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-241-riBmDOT3P8KigrYGOn4eoQ-1; Tue, 25 Aug 2026 06:25:13 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EE763195411C; Tue, 25 Aug 2026 10:25:11 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 466731955F08; Tue, 25 Aug 2026 10:25:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653516; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Iles9kpKBJi7ke6NFfqbSL3la7rXi36pHcWAFP5A89k=; b=YuqDKL97qRS6YoqB4FdacJF6Njp3UpHrRHw9vGogbdlGHSvIRcmCFSUGOpI5dxTSjwbApB cKoM8TKChMHwhqyQUPIE2QKREKDtCbXx9zkX1jQJeyFNdYP16EGpD/VtbYmIIFhO0Ry8ax tZ/iw1dZnb5X+BNdg1bkZ+bPnFBsFos= X-MC-Unique: riBmDOT3P8KigrYGOn4eoQ-1 X-Mimecast-MFC-AGG-ID: riBmDOT3P8KigrYGOn4eoQ_1787653512 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:53 +0400 Subject: [PATCH 16/18] virtio-gpu/virgl: disable scanouts on resource unref MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-16-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=1099; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=Y0tBxOCRhZ4/rYS0r3lXS7G/w7edV54bjwQPuP6dIb0=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyY8AwaBR8KmCakQbp3wxyxK3UXDtlXCaeGy 2may6utWYqJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1smAAKCRDa6OEJdZac 5Q6hD/422+BCA8YCUnNDxnIS2elAytfZrEPp+tgQMh9VkFl63LCKm+h91UyH40tvgVbb1Nb7Pdd dNeSgt4HLl6GiD5yslF+VvEkaCdK4wOd7GmppHTTNBOwjwwzQK4XcttZhnAqnuBtDZhQC7eUm2E Daw0XZWpjdybeFoRCVfbj9KSrT+l9VRWEIZRf3Lmz9ghIHKg9eJ7iesYq/GAiZPO8Z/E12K1nEk 9ikUKWyrnXPGR10L4nsyOlmgyasny/rPQkunRIifvWNZSUaBs2kDgGjLflWUqKWhYLq19Sor6PM VzULKlUBsMwqh2Kji687hPsXfX6bnh9mVSkmL4EtWs9bgvESrSkOTQgKsI0VyNIL7FgM2YBweu8 iQ9ABCCUX5ZjRGr9E07nevkK2v6OUBaPMhO1jnmbgaeHb44r5zdq0LqVio7oeOV3+sAs5wZndii bVrotTPtF5to10Qfoep3RLULxaPQ1VhRnvzASER58kewyBJWBaCbL2w6TE12yWFgFj4PKe0So2B E2vWPJRVGYwp+wLLJ/wMBsGtW6voiMyeuGotEIFCRMFP548sJEgygD6xtcjKvKkfNEFUqFoi6Ps D2yc4DvfqhqQI7K0u02/21Kiaw//4PpwVh7LDgjfqFiya0M8ux8e632JZurOlB2vjG5AWWVS7qB SCBmPogYaOtLyGQ== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653528672158500 Disable scanouts referencing a resource being unreferenced. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-virgl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index e2ad27343da5..8b27fe3980d6 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -412,6 +412,7 @@ virtio_gpu_virgl_resource_unref(VirtIOGPU *g, { struct iovec *res_iovs =3D NULL; int num_iovs =3D 0; + int i; #if VIRGL_VERSION_MAJOR >=3D 1 int ret; =20 @@ -424,6 +425,12 @@ virtio_gpu_virgl_resource_unref(VirtIOGPU *g, } #endif =20 + for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { + if (g->parent_obj.scanout[i].resource_id =3D=3D res->base.resource= _id) { + virtio_gpu_disable_scanout(g, i); + } + } + virgl_renderer_resource_detach_iov(res->base.resource_id, &res_iovs, &num_iovs); --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653535; cv=none; d=zohomail.com; s=zohoarc; b=oCX3+z1wMYmjaHDT8lK8e3WaO156k1PqqhW9/jNVdCTchYIL/lvpunuOyUy+D33oL9CFTzB5MYOgzhsOvoXgzEonIux+rTN2Hmpig6VEw5rbb1NLc+YdeXr421YmHm0EPXxMX/LMcisDxY6l2W2q+0ZVQfMpNVk/dVmotNKytnc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653535; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=YwVqFklkTq51UFas2WYSPaXcHAFfeT0z9bfzAzXafOE=; b=erLvMpOut9B+1xcfTDN8SNPSeRKLWM8Qi3j5tHYyPclHT85f7l8wnp6515x7+ct5hCGas8gBeVOmtvzzzlyOA1xd2ltJBXA0vFIn4HngB9WDLFE7wbDtANwz1FdrEnxLYCSFo4/VzSn22kDxbW8d4ZEnUC6ijPIJl2p8654zVeo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653535946888.18763537565; Tue, 25 Aug 2026 03:25:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoLQ-0002y7-4E; Tue, 25 Aug 2026 06:25:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoLO-0002sa-6U for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:25:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoLM-0006Wk-76 for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:25:25 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-55-sQEeRhHANC2igCYV-GKRtw-1; Tue, 25 Aug 2026 06:25:21 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 565911921EC5; Tue, 25 Aug 2026 10:25:20 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C72BB18005B6; Tue, 25 Aug 2026 10:25:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YwVqFklkTq51UFas2WYSPaXcHAFfeT0z9bfzAzXafOE=; b=eRcSq/6ObMM+r/UivZPQtlTDbQc6yK6pkGOauaZDQebYe7QCuEj8KBJcPFXEe7hJMOBl+s mwcGuKK9Zn0qERsM+0PvuUubJeAraYL/9MYqiE4tqrkq2RkQRQK8MnYCFnOnanfbizaTXO iTPl0eaNNDzjc9siGASMBpGdNO6JkTY= X-MC-Unique: sQEeRhHANC2igCYV-GKRtw-1 X-Mimecast-MFC-AGG-ID: sQEeRhHANC2igCYV-GKRtw_1787653520 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:54 +0400 Subject: [PATCH 17/18] virtio-gpu: initialize dmabuf_fd to -1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-17-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=4993; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=88hblmgOwlmVboP78rda7W48EMecEATnLDYPHwuMxY4=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyZ/gQTVWF2BXVDicar+COhg8xIFIoxsaM7z YVFAHElFeaJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1smQAKCRDa6OEJdZac 5d7eEACxlSrLNTafv4+FYVrX8RLjKd4ctIjhmzYOXk1SHKHy3ByQOqcHwMkH0dKn0lkJdiETD+x SzIdJ6V5Nin6Hg/o64ikOGYhhSX8g3wOC8YU0et2dW1/ewoB+G+4MVWD3XnGLKfgK+FAULPNAtE 3svRYGemZerifAP/f2Jt78M2oM4gKAN5myELIW5zr22zHOsNOgXylSU+MU9VI+HwE0DzDME4cIL tBx+tfGfn1qwQ16KQNMiHkH2PINp+9utoPCQrJBsWLQ9TtImYIAB66gnuP6TZCzEamULzFljXYJ PNVO9Wg5MU33gsWVp63K8lHajJXvnPNPkz77g+GiPnCq3Gc6Era46HwcS2z0R/ah9amEl65d1HP E63UzcOZhfQ4r/5dOEJISnNNJwGquUfAPLh6FtLtCKk3B99Gabi3RI5orphxsXR5Js4ZWz27iCB hCGOYL/ZyPwjb4LsKFuV9n4ehvDmewiKIYhM3jWvoVWeSS/QMCCedXz/kaNEF4710LU+J828bRj hf+0j0kX32o2DPax0fhcVO6KJySgU26S+2HSIb9qztIelyBXYRcZhgHaOW5aToa4GglTx9TcUh9 ZCCb2N5SIyr34IeGL6MpRPoy6XHAUYrNuqxMwJtr6fJbUf+9Z4olhBnfYeCwovLM5CRNazgp9ux T9jSpHHp92iYSfg== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653536759158500 FD fields should be initialized to a non-fd value to avoid confusion and potential invalid closes. The following patch will change the guard to finish/close dmabuf and rely on fd being initialized instead. Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-rutabaga.c | 4 +++- hw/display/virtio-gpu-udmabuf.c | 3 ++- hw/display/virtio-gpu-virgl.c | 6 +++--- hw/display/virtio-gpu.c | 5 ++++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutab= aga.c index 5344a5f9e26a..ae158de480f5 100644 --- a/hw/display/virtio-gpu-rutabaga.c +++ b/hw/display/virtio-gpu-rutabaga.c @@ -101,6 +101,7 @@ rutabaga_cmd_create_resource_2d(VirtIOGPU *g, CHECK(!result, cmd); =20 res =3D g_new0(struct virtio_gpu_simple_resource, 1); + res->dmabuf_fd =3D -1; res->width =3D c2d.width; res->height =3D c2d.height; res->format =3D c2d.format; @@ -140,6 +141,7 @@ rutabaga_cmd_create_resource_3d(VirtIOGPU *g, CHECK(!result, cmd); =20 res =3D g_new0(struct virtio_gpu_simple_resource, 1); + res->dmabuf_fd =3D -1; res->width =3D c3d.width; res->height =3D c3d.height; res->format =3D c3d.format; @@ -637,7 +639,7 @@ rutabaga_cmd_resource_create_blob(VirtIOGPU *g, CHECK(cblob.resource_id !=3D 0, cmd); =20 res =3D g_new0(struct virtio_gpu_simple_resource, 1); - + res->dmabuf_fd =3D -1; res->resource_id =3D cblob.resource_id; res->blob_size =3D cblob.size; =20 diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabu= f.c index 094646af8636..4e9806f82144 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-udmabuf.c @@ -132,7 +132,8 @@ void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_r= esource *res) { void *pdata =3D NULL; =20 - res->dmabuf_fd =3D -1; + assert(res->dmabuf_fd =3D=3D -1); + if (res->iov_cnt =3D=3D 1 && res->iov[0].iov_len < 4096) { pdata =3D res->iov[0].iov_base; diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 8b27fe3980d6..291373274dee 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -336,11 +336,11 @@ static void virgl_cmd_create_resource_2d(VirtIOGPU *g, } =20 res =3D g_new0(struct virtio_gpu_virgl_resource, 1); + res->base.dmabuf_fd =3D -1; res->base.width =3D c2d.width; res->base.height =3D c2d.height; res->base.format =3D c2d.format; res->base.resource_id =3D c2d.resource_id; - res->base.dmabuf_fd =3D -1; QTAILQ_INSERT_HEAD(&g->reslist, &res->base, next); =20 args.handle =3D c2d.resource_id; @@ -384,11 +384,11 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g, } =20 res =3D g_new0(struct virtio_gpu_virgl_resource, 1); + res->base.dmabuf_fd =3D -1; res->base.width =3D c3d.width; res->base.height =3D c3d.height; res->base.format =3D c3d.format; res->base.resource_id =3D c3d.resource_id; - res->base.dmabuf_fd =3D -1; QTAILQ_INSERT_HEAD(&g->reslist, &res->base, next); =20 args.handle =3D c3d.resource_id; @@ -862,9 +862,9 @@ static void virgl_cmd_resource_create_blob(VirtIOGPU *g, } =20 res =3D g_new0(struct virtio_gpu_virgl_resource, 1); + res->base.dmabuf_fd =3D -1; res->base.resource_id =3D cblob.resource_id; res->base.blob_size =3D cblob.size; - res->base.dmabuf_fd =3D -1; =20 if (cblob.blob_mem !=3D VIRTIO_GPU_BLOB_MEM_HOST3D) { ret =3D virtio_gpu_create_mapping_iov(g, cblob.nr_entries, sizeof(= cblob), diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index a7f549a6a8b9..521d4800d872 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -274,7 +274,7 @@ static void virtio_gpu_resource_create_2d(VirtIOGPU *g, } =20 res =3D g_new0(struct virtio_gpu_simple_resource, 1); - + res->dmabuf_fd =3D -1; res->width =3D c2d.width; res->height =3D c2d.height; res->format =3D c2d.format; @@ -360,6 +360,7 @@ static void virtio_gpu_resource_create_blob(VirtIOGPU *= g, } =20 res =3D g_new0(struct virtio_gpu_simple_resource, 1); + res->dmabuf_fd =3D -1; res->resource_id =3D cblob.resource_id; res->blob_size =3D cblob.size; =20 @@ -1407,6 +1408,7 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque,= size_t size, } =20 res =3D g_new0(struct virtio_gpu_simple_resource, 1); + res->dmabuf_fd =3D -1; res->resource_id =3D resource_id; res->width =3D qemu_get_be32(f); res->height =3D qemu_get_be32(f); @@ -1518,6 +1520,7 @@ static int virtio_gpu_blob_load(QEMUFile *f, void *op= aque, size_t size, } =20 res =3D g_new0(struct virtio_gpu_simple_resource, 1); + res->dmabuf_fd =3D -1; res->resource_id =3D resource_id; res->blob_size =3D qemu_get_be32(f); res->iov_cnt =3D qemu_get_be32(f); --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sun Sep 27 23:49:57 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1787653546; cv=none; d=zohomail.com; s=zohoarc; b=UngxWn9Uyq+wRypfrJTOgQY3dnNXuqGTz97EWJ7FY/k9qoJyQhi6puY1wtO4c6Gmo0sGpYXY3JDGHfSGyA0jvQiaANlfh7s6aBSDyWtvGoxzy1QAxh2kOkHwwu/UOOS1lc50/Mh4vtyv8U8tZbHxLHEKf/2PNMUCINfQQ1qgC/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1787653546; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BMfBJFqDWXEV2/l2gMeGl2Po7R746yvHs4Ale2Jl22Q=; b=Ug+T3IqpggYqAoQWjLc9qkZdBqgBI9sN8iUYWvHpCJ3dzND98ivBQzpbFlHs9gzNkFGAAhT2IaBpVwqGhZ9qxbGKsCJ/9a5PSU+wvr2b6unpWNh2UBrvXlB1IJOotqVYXBzcZtq5qLtMM7U4R0tFM/8sFs2OgiINw0cnTb6DPMc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1787653546578692.062452463077; Tue, 25 Aug 2026 03:25:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wyoLf-0003VI-1m; Tue, 25 Aug 2026 06:25:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoLZ-0003MR-DW for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:25:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wyoLX-0006a4-6m for qemu-devel@nongnu.org; Tue, 25 Aug 2026 06:25:36 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-118-ybHGQDZHOeKJECkOlmUd2A-1; Tue, 25 Aug 2026 06:25:31 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 684051955BDC; Tue, 25 Aug 2026 10:25:29 +0000 (UTC) Received: from localhost (headnet03.pony-001.prod.iad2.dc.redhat.com [10.2.32.114]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3AAEF19560AB; Tue, 25 Aug 2026 10:25:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787653534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BMfBJFqDWXEV2/l2gMeGl2Po7R746yvHs4Ale2Jl22Q=; b=c0/AuVs9lWiZEyjB9BZuQbpWsHUZuaPkdWKrOFdHWlbilExQbHXuLUhNTI/F2FP1wtmFHG JxHV9/7jWCeHts2J+WlT5NB/CFI4VPHnJADDMOu2Iva424uEIpemwPkVuKs7OIsQ/CM+qU u7HwYKHzpa9Ia3j8IkgasrVzMHKnLPU= X-MC-Unique: ybHGQDZHOeKJECkOlmUd2A-1 X-Mimecast-MFC-AGG-ID: ybHGQDZHOeKJECkOlmUd2A_1787653529 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Tue, 25 Aug 2026 14:20:55 +0400 Subject: [PATCH 18/18] virtio-gpu: fix use-after-free on blob cursor after detach MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260825-virtio-gpu-cleanup-v1-18-d3bb612b9975@redhat.com> References: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> In-Reply-To: <20260825-virtio-gpu-cleanup-v1-0-d3bb612b9975@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , swing X-Developer-Signature: v=1; a=openpgp-sha256; l=2741; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=Zr8g1ctz3quUiR2sNqkEx836TbwwFf/BJ00Qv1bzHR8=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqjWyZl3RaO1dTKKRZ2NE2xWaOZv0h6Ntgb/5/Q kLRHCg9Xf+JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCao1smQAKCRDa6OEJdZac 5R7LEACcIBFvhJgZCFrkf6ECujINT4JpiitzywOciHCWyeikhk5iP7uuipSRaJzeGvV4+snTyAF xJK1Ptz0Zd9LeLtrEzvQ8/0/IP5m/Ro9+XCrw/xz5cRJyHZc2CpUby+eAvnXoYCldqaZyjQNP+M 9EH7r7OnjmQj3NOphiWcKhoE0RGwUbNZGmOYPj+1FViWEutTKzFHQid2vlOI7ec+fM+qs7Y/rYp LTOXHLTc9/JUf9KFL4f0uNKBSEJzZEU7O1/hRE8KDrVwvZqa6coq4IakFkFP6687Cc1Fq7EoSEh PxZk341wKiQ0M2fXV9nHYXeWoypYR+GSZQUItFxhMOfqKtRXfbND7CR4Iai6nsfvGpEyxDPPrHW O/WqHNT7VpaPu46hA7GR6ji27oif8yBQLqKZOMt2QpjRLQ2j6RUf02vRiHEJ6nqpet+qg9iBWfe 169edY8nHEjj8w5ZRApLKJ+4QxOVbX9PCdgv5Q3CGMaZnKx/cPKqUuAn6nA6ZW625t72CeRJr/1 6MyQkudKtZmVdyNez/8u9pKCh86jaL3iYx50I5557tHspJf9wt1N9YZ01niFFWc78XfG5zMxS+x v3jsVta+jU96cP3HnwaBPuobaLRnJ2IBgI3SG3J18QIvBNjjyo/UOw2zTIcY7CbzDKW0AWFf8he AtKBx/34YhCL9rA== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1787653548802158500 virtio_gpu_cleanup_mapping() unmaps the guest IOVs and tears down any udmabuf mapping, but leaves res->blob pointing at the freed memory. Once a blob resource goes through RESOURCE_DETACH_BACKING, res->blob is left dangling while res->blob_size is still non-zero. virtio_gpu_update_cursor_data() only checks res->blob_size before copying from res->blob, so an UPDATE_CURSOR on a detached blob resource makes QEMU memcpy from freed memory. Clear res->blob after tearing down its backing, keeping init/fini symmetric, and check it before dereferencing in virtio_gpu_update_cursor_data(). Simplify code by dropping a needless condition for calling fini_udmabuf(). Fixes: CVE-2026-66020 Fixes: bdd53f739273 ("virtio-gpu: Update cursor data using blob") Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3881 Reported-by: =E7=AB=A0=E9=B1=BC=E5=93=A5@aipy (www.aipyaipy.com) Reported-by: swing Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-udmabuf.c | 1 + hw/display/virtio-gpu.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabu= f.c index 4e9806f82144..3bd6a77730cd 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-udmabuf.c @@ -89,6 +89,7 @@ void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_res= ource *res) close(res->dmabuf_fd); res->dmabuf_fd =3D -1; } + res->blob =3D NULL; } =20 static int find_memory_backend_type(Object *obj, void *opaque) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 521d4800d872..87823b2cd5af 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -63,8 +63,16 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, } data =3D pixman_image_get_data(res->image); } else { + if (!res->blob) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: resource %d has no blob\n", + __func__, resource_id); + return; + } if (res->blob_size < (s->current_cursor->width * s->current_cursor->height * 4)) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: blob size too small for resource %d\n", + __func__, resource_id); return; } data =3D res->blob; @@ -992,9 +1000,7 @@ void virtio_gpu_cleanup_mapping(VirtIOGPU *g, g_free(res->addrs); res->addrs =3D NULL; =20 - if (res->blob) { - virtio_gpu_fini_udmabuf(res); - } + virtio_gpu_fini_udmabuf(res); } =20 static void --=20 2.55.0.543.g5ebe2ebe4ea8