From nobody Sat Sep 26 20:00:45 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=1788951831; cv=none; d=zohomail.com; s=zohoarc; b=j5cG9mZYHMUMQm+mv6OVcBB8wgy5NWjVPJWSwvxb1ezf38RMsSb3XZbyc+GIIvMQIXyotCixX2gLFEavXK+MYgaol7bvXDHg+B5Atap2C4oWkObU6ro+CydsYyg8M/jADAdlGkdV2BSXDMqF7ybcw5/tIBFzuBGguWaJpFu0IRw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951831; 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=b+HQTuN6Q4eCJXLMuX75gYL+WGKDMaLS7r6L7oKslj8=; b=EpFP+OSGcaMxg5T/LZ5NXxNZmv8RHhYTk3Rnxo6HSvfXKTXYO8TeXSUmEN2Oz3S3HwRVuNdTa4+WS3XCwp3U325kUsua004e7QGYhLh1aU2P64DMwz95xulLkt3KFPttu3RcQOQsrndxPJvHAcZaIDnAgzzCaXPtzd7yOX50Z3c= 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 1788951831926197.59330879056665; Wed, 9 Sep 2026 04:03:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G5a-00029V-TQ; Wed, 09 Sep 2026 07:03:39 -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 1x4G5X-00028o-EL for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:03:36 -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 1x4G5V-0005CO-Qb for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:03:35 -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-696-CS1XQ6mlPsahk7DXfouHQg-1; Wed, 09 Sep 2026 07:03:29 -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 4584518007F6; Wed, 9 Sep 2026 11:03:28 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 137D130002DB; Wed, 9 Sep 2026 11:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951813; 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=b+HQTuN6Q4eCJXLMuX75gYL+WGKDMaLS7r6L7oKslj8=; b=QVWS51FdRYrhzQu3wbZAGJOuJMkuErYyxl4yy0+jZJ9I/SpBk1EkXEf4qkfPhMR6IJrFKe zAg1MvkB/jjjnpB2McCSoTDmAwiufiEx+gWQNCJWlEn2p4hntfdDajmcwbE3BOYT9yx7qw PzokF6lNz+8QO0w99XiOP6MfF8bjiGA= X-MC-Unique: CS1XQ6mlPsahk7DXfouHQg-1 X-Mimecast-MFC-AGG-ID: CS1XQ6mlPsahk7DXfouHQg_1788951808 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:06 +0400 Subject: [PATCH v3 01/24] 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: <20260909-virtio-gpu-cleanup-v3-1-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=1360; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=R9p5LQIIzRohkvwfRNtuO/PatWCNeFmPWXK+hMXTuqM=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzytK6kjQ25VQUWY2cRA1L47LoKrPhjyaa6c 0oleP8UwMCJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88gAKCRDa6OEJdZac 5Ye8D/9JeN1DVdDDz5O1EAJhub9Vwlqwz0WesNp7M/o2cCEsvEvrHSmhoBtlVwaqG2xTNrdA1F/ c3PfzKoiPDI1x0nyAX5Px4xRsUlK9NptedO5vvUQVdOOmUk3ccOHZmu0SYOYLxXD9Ic+WDlxT7q GpkmFK0+ySIo3x9+dP8mjOwhfD1vRyyl75QmBpPyjY6V6Tkba2MwsBTQFyBR5RjOcuZTetURI9v D7D9/bmiTx65MQ54INkgmPKiXJ3Ok2JuFPQANJ3XA3OFCqQwpZnBw6lj1YfbqW13rJ86cylASJJ S2dGK5sCLhkB+e/U3GEs1xuI57SkoINBbjTaq8EVNoPHWDj0fsjzv+NJjvUTr20FJljp4zwbnwA TgtGQ/ClDJp+ACSd30z73ZDgs9YE4enTsMrk1w7WEyyTcQdiWFgw2oPibaO1zw/w4pVTGgqz/tS KDRSNRNYOY844Y1jbBI/CcEH+Bll1Y9rTk6ZbIdJzdfaQ7GR3s/tyfZJBFSrUwK/3FAXgJvUlj6 FcJX+P9ULZqnaMuB56xuAfckpr6obiblcE6ulUlTNV5jZWkUymhYn1EhWTYiKAr9DtfZbl6DUHF Rp6nxoC9oMC490EbGsuvmwNfqtMVITWCPGcNwqiAf6W8leIfdNhZOD0HA3lo7hU0S6uCh7Uguwo cF/coCEq8St16EA== 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: 1788951833989158500 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 Fixes: 32db3c63ae11 ("virtio-gpu: Add virtio_gpu_set_scanout_blob") Reported-by: Akihiko Odaki Reviewed-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 55a1c7f80fb8..5b63a292933a 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1022,6 +1022,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 Sat Sep 26 20:00:45 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=1788951881; cv=none; d=zohomail.com; s=zohoarc; b=fzQqwCDbipiWLgrLRvxjjLPNCBkQ75EymFoPSvFzFV9WlfJ54CcBBmJftslS0fHtr9UtMQTPMQ0EmJX4z7icAGQmbik0ER3OEVHwDF/K/LB/Zo1ut/T/zE1pUuQZznH9SkxgHjobI+GpbBjvYIKWMSbP4pROdEJG8pjKUzjOhvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951881; 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=tF51iQuKyCtzxR4CFcyzcB5//b1e4p9OFPHc6AsF1YU=; b=YqNCdwZ0kx71EOL3c0r8j1ygHf+e1C5NHuDHUTaGLKaPLcxXj9IQsLyKMtUVTUM7JsVgMXht1mZ6xVQJgDmxHbWfK8wFzvIDZO9p16Rp0EWcgChWqtj08hZIkrRV5UTTaX7XIDsx6gjtwL24UUQixX6UhjPQZTtKouAnflv/o68= 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 178895188166882.68536455299545; Wed, 9 Sep 2026 04:04:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G5d-0002BU-Gi; Wed, 09 Sep 2026 07:03:41 -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 1x4G5c-0002Av-Op for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:03:40 -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 1x4G5a-0005Cb-Ug for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:03:40 -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-202-V8padgqOPyi1JsN7_hmiYg-1; Wed, 09 Sep 2026 07:03:34 -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 29D5C19560A2; Wed, 9 Sep 2026 11:03:33 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 289ED426; Wed, 9 Sep 2026 11:03:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951817; 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=tF51iQuKyCtzxR4CFcyzcB5//b1e4p9OFPHc6AsF1YU=; b=jWcGqe4CzXiVqyabyzipys8SgWPlZAuVhi+ZeQaUgjKAMIgm59QjvLKmUQL27azy1qb58e Nk0qOjOmPvsnnS0ynBzKoxpriT/NiQYo3+QGGPCpzJSu2ObWczYAto11lzaHs5wiBLWj0n 392U+CZ1fBQeKjdyWVi6Llke35zfhjw= X-MC-Unique: V8padgqOPyi1JsN7_hmiYg-1 X-Mimecast-MFC-AGG-ID: V8padgqOPyi1JsN7_hmiYg_1788951813 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:07 +0400 Subject: [PATCH v3 02/24] virtio-gpu: clear res->blob on mapping cleanup MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-virtio-gpu-cleanup-v3-2-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=2270; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=luzyErG9TiOsTFI87w4hwoO+m7D7/lId9IrIyCVMmeA=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzynhOZYv2YBbsIOpo95yl91m9EYtsCQcXx1 V1C4znMeW+JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88gAKCRDa6OEJdZac 5YF8D/4wHXGUWCaLAHpr/V+PFs569SWaslePsA60mh3g5n5OuYlSnTYEDJFrJ/ozvnCWc6UgoKO zR02JtKI4pbc7kXdS6gjv76xRZDHQ/RKKXiX/XNRSxKepfI5BiXpo33MKs+q2Q38dcNvBQHxwTC C1k6rPVyVUT7AaFEpOsZJKe2qGRW+7huD3rU56I2l59i760XmHLtTO4lC24Pl1H3raKKouXZJCP v/lVxSo6t6fqzoZ1ScvJDgU6dS5Jn9HZAAidOKMsodvO6XG3lb9aXfxJtmp6574Rhepa05B9gQE 7mmBLu9pWmIKMHQvfl8mmGxeqRZbhdU9wYr7FDgh0GcvauqX4lplnxcdJtpteMF+BJV7m4UWGDF y/gEnVVrXUlOf3cpCKHxzntnCIxi//BWVaUEfq2nOCJWiZkP/la46Lj55PMGZjU1ofit32oS0I/ 8QFTzuYzRslRvGLGywE96X3k8T84fXJ6qcw+25uSs+F9BHhT6eGfDBt7mGvXzyTbO17EfZaRvMy jNdMQbIExDtL9XDsYgQzWNpqUIsfsvNq2a+EkLSf92swrQIi7RHdY9oQ1kaESHRm7OoIoKPN8RS C4huMSSG5oAf53yBqyc9q/dgIHvR1vpCYrxLz2vaDvFS+fkXCMyr8g88T92PbeLwReKdyJBq/mW LOLIw6rBALFcJWQ== 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: 1788951884051158500 d3c2da174ca6 ("hw/display/virtio-gpu: Check cursor data presence") already prevents the use-after-free on blob cursor after detach. Clear res->blob in virtio_gpu_destroy_udmabuf() to keep init/fini symmetric, and add LOG_GUEST_ERROR messages in virtio_gpu_update_cursor_data() for missing or undersized blobs. 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 Reviewed-by: Akihiko Odaki --- hw/display/virtio-gpu-udmabuf.c | 1 + hw/display/virtio-gpu.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabu= f.c index c230509852ff..03f0b29754e1 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-udmabuf.c @@ -92,6 +92,7 @@ static void virtio_gpu_destroy_udmabuf(struct virtio_gpu_= simple_resource *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 5b63a292933a..3c3539e337fb 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -61,8 +61,16 @@ void virtio_gpu_update_cursor_data(VirtIOGPU *g, } data =3D pixman_image_get_data(res->image); } else { - if (!res->iov || res->blob_size < (s->current_cursor->width * - s->current_cursor->height * 4))= { + 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; --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:00:45 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=1788951848; cv=none; d=zohomail.com; s=zohoarc; b=XK+2k43s+BEqbOFRacnnv+mqImT6SW26RqkjAnfJ3moI6xtjAIqTYSgYEK3UyTK8e+YnOl8Uj3ijYvwNgAaPSJ8l9gq8/wClRkKjSR4RVPOU45jBBEmvFheVjgw+RXgcDB7Sdw9Z41yqEEFNz1qr4rcxR1IsBkNSSluOsmB27zs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951848; 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=0ngT2cCLD1QZ+H2eW9Nvud+V6k97Yyz3vx5HyUPP+dw=; b=Qm8omTRr0wRu4gZ+6xnbzpPHmg0bjcCJLGCRuQkNsWql7o+rX8oMYoZx/S77L79ctdxLIwhTT0/JZ46icT7KlfEBPnQFxUpabPF8w6NTQhrAER1JQ+/lsEThRAkbnUShgjASZ+AFLMGVzQa0m1VdAZk3ecCrYe4jRhfi60tYNCw= 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 1788951848488364.62363434472684; Wed, 9 Sep 2026 04:04:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G5h-0002Eo-SX; Wed, 09 Sep 2026 07:03:45 -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 1x4G5g-0002EU-I4 for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:03:44 -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 1x4G5e-0005Ec-HX for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:03:44 -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-634-umZxSPvaOBa_Rdd84PC_qg-1; Wed, 09 Sep 2026 07:03:38 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 165EC1956095; Wed, 9 Sep 2026 11:03:37 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8D1E81955F19; Wed, 9 Sep 2026 11:03:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951822; 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=0ngT2cCLD1QZ+H2eW9Nvud+V6k97Yyz3vx5HyUPP+dw=; b=HfUQGFAUfBAXSLiz1PpI8co1OciZeN0hspq6CTuL7lcQ7wKP23dwUbDIMM338i4YzaslGx iVNcRF2VhM6QzXuMXQ8rF7zYW23jXIqKF6dNi+XHMm0PgmuAstuFZ7Z8JcD+ooKZgd16L2 JaquBxKC7C27Ov7HSwJuG/fRW8nq1EM= X-MC-Unique: umZxSPvaOBa_Rdd84PC_qg-1 X-Mimecast-MFC-AGG-ID: umZxSPvaOBa_Rdd84PC_qg_1788951817 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:08 +0400 Subject: [PATCH v3 03/24] hw/display/virtio-gpu: introduce virtio_gpu_{simple,virgl}_resource_new() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-virtio-gpu-cleanup-v3-3-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=10567; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=w3w7Q50Jg6Ng9Xo0v3C94n/99pxWsT7TSnCepItsbx4=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzyr0j7xAITq4NjP22t/qEVqqiFEcnVWKuc/ dRNv74LHTaJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88gAKCRDa6OEJdZac 5eO2EACs2Vavq6JOtXZOs5XcOqJLyWbBpAdvwR9qU3qLtw0zuYRbNKQre52D7p1xOVd7b04Wp0z CE9aPmwDFxOBrHMP9r4YrRqWtwXJLy8vs26daxlc7UDx/i0sThJXY9cmumW3BgsUNzbS/SvLaN9 nsV+H1WzIcRfi6R5eb5QAk5fpOREFHPCO3zciPi1RyFuaNWlUpzmQeMR8w1QK5542UQ7lmW//eY qkVggve6vCgbxgn/oOWZ5/J6r7NGnapv1AR5Pi7Gdbo5ehVPcnCfATHPtlEC4uSLkf6asnrobqV M27t2TBwYRDIxv+FxQFUbgJVDQiI6LzmDu0t+m84ZnkdjxAlXHCchy06aPnblVZnycAn+tZRFtO 6UraTyCdYEnQ1DpxqtP+dpabg+DWnEcyrqL4HlbvvmttRkdGTIzbA2a9I+tzfcKFOyGsNmXayh+ xXMfZHXbaB5WKhPk+eJNRi6mhiW4F2e46qg+VzWyNX3ZIXsigu7KzE6sima4oYymZ7+WzFOzvea 59ff8SzvUMeio3/Efvfj8UnCMYg1Nf1BbFVGh0FcCpOGfAJKHaxnAtRF92MOdbbdUArkdFbpMf1 bo5N37SQuEc6VOU5xQPYZPe70E/OkDTS5q5AfzCi40Yxa1wMtB0Q1jHXQRdgWjMQgjy4zRVV1SC 6dSaJHvpbCSsWCg== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 127.0.0.2 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: 1788951849873158500 All allocation sites used g_new0() which zero-initializes fields. However share_handle must be SHAREABLE_NONE (-1 on Unix, NULL on Windows) and dmabuf_fd must be -1, not 0. Centralize allocation and field initialization in new constructors fix this and reduce code duplication. This fixes -display dbus with virtio-gpu blob resources. The other end is currently receiving qemu fd 0. Fixes: 5f899c34af1d (=E2=80=9Cvirtio-gpu: allocate shareable 2d resources o= n !win32=E2=80=9D) Reviewed-by: Akihiko Odaki Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-rutabaga.c | 21 +++---------- hw/display/virtio-gpu-virgl.c | 48 +++++++++++++++++++---------- hw/display/virtio-gpu.c | 66 +++++++++++++++++++++++++++++-------= ---- include/hw/virtio/virtio-gpu.h | 11 +++++++ 4 files changed, 97 insertions(+), 49 deletions(-) diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutab= aga.c index 041216a10d04..b8f8a2068d0b 100644 --- a/hw/display/virtio-gpu-rutabaga.c +++ b/hw/display/virtio-gpu-rutabaga.c @@ -100,12 +100,8 @@ rutabaga_cmd_create_resource_2d(VirtIOGPU *g, result =3D rutabaga_resource_create_3d(vr->rutabaga, c2d.resource_id, = &rc_3d); CHECK(!result, cmd); =20 - res =3D g_new0(struct virtio_gpu_simple_resource, 1); - res->width =3D c2d.width; - res->height =3D c2d.height; - res->format =3D c2d.format; - res->resource_id =3D c2d.resource_id; - + res =3D virtio_gpu_simple_resource_new(c2d.resource_id, c2d.width, + c2d.height, c2d.format); QTAILQ_INSERT_HEAD(&g->reslist, res, next); } =20 @@ -139,12 +135,8 @@ rutabaga_cmd_create_resource_3d(VirtIOGPU *g, result =3D rutabaga_resource_create_3d(vr->rutabaga, c3d.resource_id, = &rc_3d); CHECK(!result, cmd); =20 - res =3D g_new0(struct virtio_gpu_simple_resource, 1); - res->width =3D c3d.width; - res->height =3D c3d.height; - res->format =3D c3d.format; - res->resource_id =3D c3d.resource_id; - + res =3D virtio_gpu_simple_resource_new(c3d.resource_id, c3d.width, + c3d.height, c3d.format); QTAILQ_INSERT_HEAD(&g->reslist, res, next); } =20 @@ -634,10 +626,7 @@ rutabaga_cmd_resource_create_blob(VirtIOGPU *g, =20 CHECK(cblob.resource_id !=3D 0, cmd); =20 - res =3D g_new0(struct virtio_gpu_simple_resource, 1); - - res->resource_id =3D cblob.resource_id; - res->blob_size =3D cblob.size; + res =3D virtio_gpu_simple_resource_new_blob(cblob.resource_id, cblob.s= ize); =20 if (cblob.blob_mem !=3D VIRTIO_GPU_BLOB_MEM_HOST3D) { result =3D virtio_gpu_create_mapping_iov(g, cblob.nr_entries, diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 9bda572426b2..742d9dde4a32 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -309,6 +309,33 @@ virtio_gpu_virgl_unmap_resource_blob(VirtIOGPU *g, } #endif =20 +static struct virtio_gpu_virgl_resource * +virtio_gpu_virgl_resource_new(uint32_t resource_id, uint32_t width, + uint32_t height, uint32_t format) +{ + struct virtio_gpu_virgl_resource *res; + + res =3D g_new0(struct virtio_gpu_virgl_resource, 1); + virtio_gpu_simple_resource_init(&res->base, resource_id); + res->base.width =3D width; + res->base.height =3D height; + res->base.format =3D format; + + return res; +} + +static struct virtio_gpu_virgl_resource * +virtio_gpu_virgl_resource_new_blob(uint32_t resource_id, uint64_t blob_siz= e) +{ + struct virtio_gpu_virgl_resource *res; + + res =3D g_new0(struct virtio_gpu_virgl_resource, 1); + virtio_gpu_simple_resource_init(&res->base, resource_id); + res->base.blob_size =3D blob_size; + + return res; +} + static void virgl_cmd_create_resource_2d(VirtIOGPU *g, struct virtio_gpu_ctrl_command *c= md) { @@ -335,12 +362,8 @@ static void virgl_cmd_create_resource_2d(VirtIOGPU *g, return; } =20 - res =3D g_new0(struct virtio_gpu_virgl_resource, 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; + res =3D virtio_gpu_virgl_resource_new(c2d.resource_id, c2d.width, + c2d.height, c2d.format); QTAILQ_INSERT_HEAD(&g->reslist, &res->base, next); =20 args.handle =3D c2d.resource_id; @@ -383,12 +406,8 @@ static void virgl_cmd_create_resource_3d(VirtIOGPU *g, return; } =20 - res =3D g_new0(struct virtio_gpu_virgl_resource, 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; + res =3D virtio_gpu_virgl_resource_new(c3d.resource_id, c3d.width, + c3d.height, c3d.format); QTAILQ_INSERT_HEAD(&g->reslist, &res->base, next); =20 args.handle =3D c3d.resource_id; @@ -853,10 +872,7 @@ static void virgl_cmd_resource_create_blob(VirtIOGPU *= g, return; } =20 - res =3D g_new0(struct virtio_gpu_virgl_resource, 1); - res->base.resource_id =3D cblob.resource_id; - res->base.blob_size =3D cblob.size; - res->base.dmabuf_fd =3D -1; + res =3D virtio_gpu_virgl_resource_new_blob(cblob.resource_id, cblob.si= ze); =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 3c3539e337fb..cb45360e769e 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -41,6 +41,42 @@ virtio_gpu_find_check_resource(VirtIOGPU *g, uint32_t re= source_id, =20 static void virtio_gpu_reset_bh(void *opaque); =20 +void +virtio_gpu_simple_resource_init(struct virtio_gpu_simple_resource *res, + uint32_t resource_id) +{ + res->share_handle =3D SHAREABLE_NONE; + res->dmabuf_fd =3D -1; + res->resource_id =3D resource_id; +} + +struct virtio_gpu_simple_resource * +virtio_gpu_simple_resource_new(uint32_t resource_id, uint32_t width, + uint32_t height, uint32_t format) +{ + struct virtio_gpu_simple_resource *res; + + res =3D g_new0(struct virtio_gpu_simple_resource, 1); + virtio_gpu_simple_resource_init(res, resource_id); + res->width =3D width; + res->height =3D height; + res->format =3D format; + + return res; +} + +struct virtio_gpu_simple_resource * +virtio_gpu_simple_resource_new_blob(uint32_t resource_id, uint64_t blob_si= ze) +{ + struct virtio_gpu_simple_resource *res; + + res =3D g_new0(struct virtio_gpu_simple_resource, 1); + virtio_gpu_simple_resource_init(res, resource_id); + res->blob_size =3D blob_size; + + return res; +} + void virtio_gpu_update_cursor_data(VirtIOGPU *g, struct virtio_gpu_scanout *s, uint32_t resource_id) @@ -267,12 +303,8 @@ static void virtio_gpu_resource_create_2d(VirtIOGPU *g, return; } =20 - res =3D g_new0(struct virtio_gpu_simple_resource, 1); - - res->width =3D c2d.width; - res->height =3D c2d.height; - res->format =3D c2d.format; - res->resource_id =3D c2d.resource_id; + res =3D virtio_gpu_simple_resource_new(c2d.resource_id, c2d.width, + c2d.height, c2d.format); =20 pformat =3D virtio_gpu_get_pixman_format(c2d.format); if (!pformat) { @@ -353,9 +385,7 @@ static void virtio_gpu_resource_create_blob(VirtIOGPU *= g, return; } =20 - res =3D g_new0(struct virtio_gpu_simple_resource, 1); - res->resource_id =3D cblob.resource_id; - res->blob_size =3D cblob.size; + res =3D virtio_gpu_simple_resource_new_blob(cblob.resource_id, cblob.s= ize); =20 if (cblob.nr_entries) { ret =3D virtio_gpu_create_mapping_iov(g, cblob.nr_entries, sizeof(= cblob), @@ -1455,16 +1485,17 @@ static int virtio_gpu_load(QEMUFile *f, void *opaqu= e, size_t size, =20 resource_id =3D qemu_get_be32(f); while (resource_id !=3D 0) { + uint32_t width, height, format; + res =3D virtio_gpu_find_resource(g, resource_id); if (res) { return -EINVAL; } =20 - res =3D g_new0(struct virtio_gpu_simple_resource, 1); - res->resource_id =3D resource_id; - res->width =3D qemu_get_be32(f); - res->height =3D qemu_get_be32(f); - res->format =3D qemu_get_be32(f); + width =3D qemu_get_be32(f); + height =3D qemu_get_be32(f); + format =3D qemu_get_be32(f); + res =3D virtio_gpu_simple_resource_new(resource_id, width, height,= format); res->iov_cnt =3D qemu_get_be32(f); =20 /* allocate */ @@ -1568,14 +1599,15 @@ static int virtio_gpu_blob_load(QEMUFile *f, void *= opaque, size_t size, =20 resource_id =3D qemu_get_be32(f); while (resource_id !=3D 0) { + uint32_t blob_size; + res =3D virtio_gpu_find_resource(g, resource_id); if (res) { return -EINVAL; } =20 - res =3D g_new0(struct virtio_gpu_simple_resource, 1); - res->resource_id =3D resource_id; - res->blob_size =3D qemu_get_be32(f); + blob_size =3D qemu_get_be32(f); + res =3D virtio_gpu_simple_resource_new_blob(resource_id, blob_size= ); res->iov_cnt =3D qemu_get_be32(f); =20 if (res->iov_cnt) { diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 69b5ee2e382f..8c0df60b3b7e 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -64,6 +64,17 @@ struct virtio_gpu_simple_resource { QTAILQ_ENTRY(virtio_gpu_simple_resource) next; }; =20 +void +virtio_gpu_simple_resource_init(struct virtio_gpu_simple_resource *res, + uint32_t resource_id); + +struct virtio_gpu_simple_resource * +virtio_gpu_simple_resource_new(uint32_t resource_id, uint32_t width, + uint32_t height, uint32_t format); + +struct virtio_gpu_simple_resource * +virtio_gpu_simple_resource_new_blob(uint32_t resource_id, uint64_t blob_si= ze); + struct virtio_gpu_framebuffer { pixman_format_code_t format; uint32_t width, height; --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:00:45 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=1788951839; cv=none; d=zohomail.com; s=zohoarc; b=TyXQpC2mxipwTum5BF9hlHtytIbS5jq4HBSZg2Zuy2hAZQo+O/YKJiWZWkGkCb5RNpKId1Vwb1UrKvIGRpzWynpZW/vQxzdytX90/PpveCOA+O8SlK1emRz2+y3ihS0PWAMrUuhLXaQnudUgujyqMGIxVKktKusAvhaN5JwoSWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951839; 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=wjrug66JF7sj2Em1iOXDLtWW+CYxXnfe2H2hXOKSaUU=; b=g689sK/Lz469sfoCvywfD9nAww4lBD0UcZgrELs8EdMEYSr+DyJ+AsTWRaRBFSROPPmNQwuxrx51Ayo/soD0jSw6WZ0yS5+WHtM/OjN4YLA8KLBulYFhyOTEsR/nvkvUtMYtxb5zEEiNef+5xAWFNyQhMlsOiioVAWTDPWdrr3o= 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 178895183989674.66828096104052; Wed, 9 Sep 2026 04:03:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G5l-0002FS-9I; Wed, 09 Sep 2026 07:03:49 -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 1x4G5j-0002F9-Rr for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:03:47 -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 1x4G5i-0005Ep-Hn for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:03:47 -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-152-ALxAPdPEOMmZJNnPxNecAA-1; Wed, 09 Sep 2026 07:03:42 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6F1971954AD7; Wed, 9 Sep 2026 11:03:41 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D022F1800446; Wed, 9 Sep 2026 11:03:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951826; 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=wjrug66JF7sj2Em1iOXDLtWW+CYxXnfe2H2hXOKSaUU=; b=Rdmu+L8HghkXqRUVHqzUnLUSZxGGyo7TXmaLSaYRclfdu3ylZFFO20Bm0nsVgce6K5u1kJ UCqLgqF/VB0sqhQzuay9O+/nT9VhXvYAosXF70v7+ye8cPv0Pg1eSzwkR6+mb0KDsq8/mM aYCgZgfnFNY2iqvVZvfQfQ2WJRLwoeE= X-MC-Unique: ALxAPdPEOMmZJNnPxNecAA-1 X-Mimecast-MFC-AGG-ID: ALxAPdPEOMmZJNnPxNecAA_1788951821 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:09 +0400 Subject: [PATCH v3 04/24] virtio-gpu/virgl: free BHs and timers on renderer reset MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-virtio-gpu-cleanup-v3-4-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=1353; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=pjazvMH3OTm4G/gkcv4HVSFx91Q4hZxlcUF0x0N0LS8=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzyIR3lBujTDdAJiESTnLtTn89BfrKWbWifz OGzIM0g3QCJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88gAKCRDa6OEJdZac 5WHED/4x+Vss34gpEbL+xvbaMOKL8zy1QmXcnQC8654Lq6GuPL/uGHxediEMyjZqXkn7av95rn3 8XwN2mJCCtV2I2rTITDNmv+21wvrUacb6cEXhuRIHotDP7SelmOK0DoeKgNumlLBSXII+iS/QqQ oSOs+xTqyXIVmSte0Z10s+WdzkBWx/Wgy5DvDiyzr8ouhw2NjG+kXuMqL341l5/AMhPzGggfMO1 kMJX9dmfoL8OuuJpXqpiSodkneQ5TrtQvuXpJk7gTfy7uENE69i6HeKihIUhzx/aQIzLk93FfA0 WkQuhnfJ/t9G6vvbGMTo6ZDz1i4nQvws5tWn8hj6nQLWajmCcqyTsV8tOxgjXU8GRR5y8yXdBtY HtkF6rJS/wZV4pLPhXc/PpJua3/cBdnBW1T3BTTxEbpoQlxqqgUpV9zXGDqWcYEp+1/l6Ap7X2z lqSlEqENPwtGq/FmwcMjGw7QSbZKIc+8a4AGvjAvJkFSPHWCi1+bhOk2T78dmGOzuZLPHGsxn0y ATbIWi+l3IUwFgjfmt584RTsPeECdVdCSE6yVQNr52137Rm41cY5lpB3W7mUgT97YnHH1Zh+gze eBFRIvmWWSbTN7IFuHm8OWwDlR3Jg2MDWh7EVAA5AZctYTUHOHLmnv5xthR8SaaJrLnIYQf4FsW EwTzBUcFJ2jZDdA== 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: 1788951841882158500 virtio_gpu_virgl_reset() does not free the bottom halves or timers allocated by the previous virtio_gpu_virgl_init() call. A subsequent virtio_gpu_virgl_init() overwrites the old pointers, leaking the previous allocations. Fixes: 7e688d1bf515 ("virtio-gpu: Handle virtio_gpu_virgl_init() failure") Reviewed-by: Akihiko Odaki Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-virgl.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 742d9dde4a32..7f1d1e0c3276 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -1430,6 +1430,7 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g) =20 static bool virtio_gpu_virgl_reset(VirtIOGPU *g) { + VirtIOGPUGL *gl =3D VIRTIO_GPU_GL(g); struct virtio_gpu_simple_resource *res, *tmp; =20 /* @@ -1448,6 +1449,11 @@ static bool virtio_gpu_virgl_reset(VirtIOGPU *g) =20 virtio_gpu_virgl_reset_async_fences(g); =20 + g_clear_pointer(&gl->cmdq_resume_bh, qemu_bh_delete); + g_clear_pointer(&gl->async_fence_bh, qemu_bh_delete); + g_clear_pointer(&gl->print_stats, timer_free); + g_clear_pointer(&gl->fence_poll, timer_free); + return true; } =20 --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:00:45 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=1788951850; cv=none; d=zohomail.com; s=zohoarc; b=Xj7t+RO/n42xcnSRjM7bFc95xOhdZJ4ZQ1lMO69BCDuCNBZsbGxTjq8ynG7AlrcKhFxdWhtLxrKvKd26LwyLfQ0uWajsW3zX6sin9Zzdf8jKn/mbJ1tXQwZHLyN9NagN2TGAHTEv+akIwjwVk5ouPl7jeGNiH9QbA7izzxZNUt4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951850; 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=oTwr7eiOmBFT4ak8x97KiBe6gCvMvmT8l8RQTmrq2YU=; b=NR3oKeGSIfqBaJiFPGHdil6qFkmHU2aJUB5ABJFoOEDdHL5xZcm1QFVPgFX27Q5kU/sxwCVpMGHLLJAQDkyU0C8pvdS/XB9z5WoZZuIbKeESy+KIOOD+n70rxcXT0kgzt6bIp15qaQotIFKZNY/qRbHfXwm3VeZjQzVkvS+igKw= 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 1788951850214621.6541536706762; Wed, 9 Sep 2026 04:04:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G5q-0002Iu-9p; Wed, 09 Sep 2026 07:03:54 -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 1x4G5p-0002IR-1Q for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:03:53 -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 1x4G5n-0005Ez-NC for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:03:52 -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-230-74zaE0bcMve5p0BVjdzYMQ-1; Wed, 09 Sep 2026 07:03:46 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 994F51954197; Wed, 9 Sep 2026 11:03:45 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C7F853000218; Wed, 9 Sep 2026 11:03:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951831; 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=oTwr7eiOmBFT4ak8x97KiBe6gCvMvmT8l8RQTmrq2YU=; b=CZuty4DhHjZjJEngMycTTdY/rQel2tFryY+40Wq43n1bs4N3dY1iDChTDKF84CNpDFnYRo CkBv2n4C91GK9dsWqG//qP1kvTdh6nsL9x4IpcePVmWVMf2wC4MhFhanoQ5w+nfByv6JA6 pk8AlNhC3kya3WOvVrszj2tv1qM5Irk= X-MC-Unique: 74zaE0bcMve5p0BVjdzYMQ-1 X-Mimecast-MFC-AGG-ID: 74zaE0bcMve5p0BVjdzYMQ_1788951825 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:10 +0400 Subject: [PATCH v3 05/24] hw/display/virtio-gpu: set share_handle for udmabuf blob resources MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-virtio-gpu-cleanup-v3-5-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Developer-Signature: v=1; a=openpgp-sha256; l=1529; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=uiiPrlH+Ljd7fNaQGlC+cwmjR9XSCfSA45QXLM5Je68=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzydNcVMgMTAHSLHAYN2dRTTGiwT82J21bdV YMSm0QgkzaJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88gAKCRDa6OEJdZac 5XOTEACQe5R0QKLtDzbBXKnTskTnbtrDdsg5nkWHm6kVj8lcr0Kgxn0M8vLbkAOpmHusSf44lBP p66VlKu2Pm1nRGotZ0ii26T6qhRnF+DZg8JVkxSpQ0uk0prHCshNjkl1weQNv5lYv3r2S7JTUYc xluCJe55b0XKi2oZ5hM7+22mzQ27ZzpYUpEILDbBgdiod2WkbjWpKaW+6SAGi35wlnefEwDXS59 J2wUI2Ng2Vc1qf/BMndePoMGKIn+P5cjaA9ke+vvnXKsj5ZzYSrlpZmbSwsyKHAgK7BlqApsspI GDoKm3qQrkK/B1MNQ1/LAcyiMBz/P4CL0iy4sgBvLk++nTBHW+tJRCiREGtr2twao5mWp50V1DE kQhLinXfqKC802is73UyU+2/gL5+c6RjhFK/wBTQvQjF9fe51buEe5ce16V9AJiBbvDH5kNrML+ 0pRbjF+kQtgYNjq8bxcsagVbe78rE5mxXL0BVjpXhEds/xLFXPHO6vWoVxibuaQlQmWw76+NsNw hWBmBWHUyNppTfBsPcCLCBCpqEYprEbv0qHfWXdm+2h1Bhi86sY8dE+8FaQbbA/Dum+/r/l5B9/ F0bi6iVugvpU3UGcoEkFQXKotsDq6L2MzQTvI6LNrfqvNRG6tC0jJh8ldw86166caYzCj0hvh1R O0y5NGSaLjRLskQ== 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: 1788951851752158500 Set share_handle to the dmabuf fd after successful udmabuf creation, and reset it to SHAREABLE_NONE on teardown. Fixes: 5f899c34af1d ("virtio-gpu: allocate shareable 2d resources on !win32= ") Reviewed-by: Akihiko Odaki Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-udmabuf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/display/virtio-gpu-udmabuf.c b/hw/display/virtio-gpu-udmabu= f.c index 03f0b29754e1..fc63f2c4ec21 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-udmabuf.c @@ -91,6 +91,7 @@ static void virtio_gpu_destroy_udmabuf(struct virtio_gpu_= simple_resource *res) if (res->dmabuf_fd >=3D 0) { close(res->dmabuf_fd); res->dmabuf_fd =3D -1; + res->share_handle =3D SHAREABLE_NONE; } res->blob =3D NULL; } @@ -150,6 +151,7 @@ bool virtio_gpu_init_udmabuf(struct virtio_gpu_simple_r= esource *res) virtio_gpu_destroy_udmabuf(res); return false; } + res->share_handle =3D res->dmabuf_fd; pdata =3D res->remapped; } =20 @@ -183,6 +185,7 @@ void virtio_gpu_fini_udmabuf(VirtIOGPU *g, struct virti= o_gpu_simple_resource *re res->dmabuf_fd !=3D -1) { qemu_dmabuf_close(dmabuf->buf); res->dmabuf_fd =3D -1; + res->share_handle =3D SHAREABLE_NONE; } } =20 --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:00:45 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=1788951858; cv=none; d=zohomail.com; s=zohoarc; b=LnjzBkLZqq2WLoWvgWIWoLYava7Tcb19jiJA3bxTB5ndY9NYpFmrjPknXyiuFrnltPiMUprKlhLb7WyVSSdTBKfHFNoXGEGVfh8Uv/IDcO0Guib7lBhZ94pJyhFodj5iQ2/AXh8ZfjfNw1IdhXWnZ5ZLaX+0BpYBq+oHx+NDNUk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951858; 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=XfKFdFJfcbMoiYxQvXfquedqLV/zBY+cdNQGkjppDZw=; b=GCTieh3T5pbH54Qcbyko+JY4nd/JAxe5XIBs6emA7PV8ctHDnmvcczkzf4pBznrW0FxBQg9vv7ing2g3uS7VOX/hZPme+wBEpMxoRJYnd1aq80OdXUCO9TnWYjg93kK61Dmp2dbQhIEXzKlw7mksNJL0eVdRDJsa1Lf5L7Cdc5E= 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 1788951858042360.39527130159934; Wed, 9 Sep 2026 04:04:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G5t-0002OS-Mu; Wed, 09 Sep 2026 07:03: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 1x4G5r-0002JJ-VW for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:03:55 -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 1x4G5p-0005FB-RU for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:03:55 -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-316-RLqbrvgsPnKSRMOjlosd7g-1; Wed, 09 Sep 2026 07:03:51 -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 3986A19560AF; Wed, 9 Sep 2026 11:03:49 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6964030001BB; Wed, 9 Sep 2026 11:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951833; 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=XfKFdFJfcbMoiYxQvXfquedqLV/zBY+cdNQGkjppDZw=; b=QZ4djEDbS24WH4a92IiZGhkEOnrz9NIydqjoe4ALUtCb4HvQYaiO554mf3V+vwUC4/K5/0 l5YTGq3ieTKPV3WL3VNMM3YpMkSjHfWsC+N9yYr9ELIG5CwXngukbiprro5ikqKBa1eilc Rtz3c8PiF1frT4xTmbDycGuJA2xTIc4= X-MC-Unique: RLqbrvgsPnKSRMOjlosd7g-1 X-Mimecast-MFC-AGG-ID: RLqbrvgsPnKSRMOjlosd7g_1788951829 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:11 +0400 Subject: [PATCH v3 06/24] 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: <20260909-virtio-gpu-cleanup-v3-6-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=12750; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=GrLY66SgcaNrIHDQCb0KBFVORGuSE1UuoSZdIHkQTbg=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzyQUxbEa+drbdaFQ2G36I2R0bPIo2fzSOvo 75vDQs2kpqJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88gAKCRDa6OEJdZac 5cDeD/0WKk2X4jOeOeTiy1OkKGFeW/1uAu8A7BOEsfNtawlEH91hDrCbOSrVyDUxbnvdRyWvHla eJ8aM9tln7hPO3z1X3LC/k+B14BPGSpu3BE7T4zUEJvIRf5qvDu8bISSj18Q5UlkuPAoMvbjGsH tNTj8CUu/K1pyYakVnTfpNZeDm0EJW0evJ4miXFOVjBiH1gFBnralkkJ87EYOkWosz3NZ8Cryb6 o9it3tTjBkiwWeVXXiLXIt2egXOXgOaTHGjiPcJXZ+EmV39tjui89zthbu6Dw6fxB3mZ/NISlJC S52+dJHmphTgKNI/AmU5h9wwS/8nC8+Aa6YGi/Xzlp+TyVTZaKUzzPXl9NcAd/OfW2YxmFcybbP xl5gXOTN9IF/unBr57qioJ54PBWaIowxSRGbSzF5/0TI85JWXIlJyIWaFnBNPEEsVopQfmVL4/Q SCCD8U4n/ALfgXgFjaJA3g49BMKzJ8ECwNxAeTJO4AoaVU7iOSHhv/YhXT9Ehfp0pCw1U54Ul8O /JMw+kO+ImQ1RQ6WkF3DSXBRqtgALNrD+O9I5kothOPRWnJNh2SgdC9BXeV0ZJux8IlqaEcJ1gn xeh4s7BjBN78QSBP2taFaWfrtHtxbXQtcTcntQ7Db5OX5ez7CGTR4YvmKFi7K1OXv9S8PL1cn0x P0sRTP2rOOCyIqg== 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: 1788951859923158500 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. Reviewed-by: Akihiko Odaki 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 679c79eacd54..533d9afc37ba 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 8e3729a54d15..cb9c1e839cf9 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 Sat Sep 26 20:00:45 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=1788951874; cv=none; d=zohomail.com; s=zohoarc; b=KcQS/UB12y5d+aGaaw8KpKIAuyoD7XNF0Nvo3dKWoyX+Nqjjw6VVqM6zhXS2/hBP6lflM7KEeTuP7dPeJamsDCv/SChiU+G3Z06vSvKWpldmW+A3OlHFuo3PF30nlCEtM8tpch6beHddikvC7oa8c0PM8fzBUsHv1oBSaBY2jhk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951874; 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=mz4PTGP6qudujxpPZjanfIYAxxhnY7znlVXoIeYduh8=; b=ccxSiS5ipqo4+B4CTUtEi3LW7zKbQf9OF7o9JFYlB8PvZON0Z0S5KhXpSVMsnuIQ6Q5eKGnwzXkSKsm78ueQpYaVFFSjk+qYUXLEdfo14MVtyD0h26a57Qv1SQPz6oh+/wK/uH9pHV2laYScOktIff2IbGtjhO8K34l2LVQWcjQ= 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 1788951874977452.73378822175937; Wed, 9 Sep 2026 04:04:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G5y-0002pg-5R; Wed, 09 Sep 2026 07:04:02 -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 1x4G5w-0002gk-0x for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:00 -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 1x4G5u-0005FY-7b for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:03:59 -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-558-UA60zhpNNeOwFrjKZ9wGgw-1; Wed, 09 Sep 2026 07:03:54 -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 D56BC180064D; Wed, 9 Sep 2026 11:03:52 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A8AEC1800473; Wed, 9 Sep 2026 11:03:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951837; 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=mz4PTGP6qudujxpPZjanfIYAxxhnY7znlVXoIeYduh8=; b=cdXQUORGawDYr1VYUYiKRJf7aImaxOcoHVEViLqlZ21XMsbYm3CX+ZaPq9CliXnY6GyJ67 lUVmnkzC/8d3xq9+kJHcGKqDowYOyoBBc7XMN8zivxCQQLEK7F8yunEmWcdLH2oSenNVs0 yH8EUbMWCGmShG0x+iRAJqor9Hr6BkA= X-MC-Unique: UA60zhpNNeOwFrjKZ9wGgw-1 X-Mimecast-MFC-AGG-ID: UA60zhpNNeOwFrjKZ9wGgw_1788951833 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:12 +0400 Subject: [PATCH v3 07/24] ui/gtk: move draw_submitted from QemuDmaBuf to VirtualGfxConsole MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-virtio-gpu-cleanup-v3-7-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=6253; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=+V91CVLcUC+ZLIEMSp2uJ4sCzJ+RyEIZv2HE+0wNKsI=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzyIzswDeKfK0kfQJaU+ndO6UaA+241PwO4P yMMHtItHCCJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88gAKCRDa6OEJdZac 5RSbD/0VCYE8izdr34DHjpUKB9xbPHXtp+wAGUVoZZQoUGkxdCi5twDiBArTwn1liBHr5nFoFpQ ZdzEttn4gIHzq+Xw7KwN58PrUaK7o0v/08vhxmFOJBmn8PwWupRRzIIzPFsGj5yT8Xj0bFJoYsN aTpaJ3O3TsR4d28cSTAv/+k4iavD8b5JndxunWd08yqCZ6vm3xPJ/J+hchDXM+D99+NNsdTH9E5 d7xM17GpuaaDKF/cURoyOPJdAvPLeJhb0+ELOV22qT7bn3fXW2Gj0mz/8ufTo8uCVWvjUcB5eVw 8uRbM7tM2lGi/AWyRq24jmDYDP6eahVFbuD7MHTc3isiNQO50KWqZaCfhXVEXWaknzv7YnLfhkn o25EfbDQwJsC8kepypNqapCU+n0016UFdniyhMRhryMkJ3mzzQ7u4Coam9hrmKt22+l26luhqEZ YysdPiLrKv1oay9+WNjvENWesHod02kxSXnaLtSZYI75CB9mTkIhrN8Hw8U9OjzEZVMVPKueTc1 J5pu9NKNsKeaA+w9p1b1LPYgymjvYf3wrnnVRjT4FhV83YyTlUaNjbEI1u7IcJhaYDHzhjKhmdi rcngdl/kn523UCiNOFWHoR5mm7R5c65oMZWCtnij4u3hNNi219z9E/AI5VFwkic7C/YWwm8ra9D tTFr6GdLmEbwrCg== 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: 1788951878020158500 The draw_submitted flag on QemuDmaBuf is only used by the GTK display backend to gate the draw pipeline and prevent gl_block refcount imbalance when the guest submits frames faster than GTK draws them. It is not an intrinsic property of the DMA-BUF but transient display listener state. Move it to VirtualGfxConsole, replacing the getter/setter calls with direct struct member access. Reset the flag when the active dmabuf is released in gd_gl_release_dmabuf(). Reviewed-by: Akihiko Odaki Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/ui/dmabuf.h | 2 -- include/ui/gtk.h | 1 + ui/dmabuf.c | 13 ------------- ui/gtk-egl.c | 13 ++++++------- ui/gtk-gl-area.c | 10 +++++----- ui/gtk.c | 1 + 6 files changed, 13 insertions(+), 27 deletions(-) diff --git a/include/ui/dmabuf.h b/include/ui/dmabuf.h index 381583bd536c..b972099859f2 100644 --- a/include/ui/dmabuf.h +++ b/include/ui/dmabuf.h @@ -42,8 +42,6 @@ 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); 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_draw_submitted(QemuDmaBuf *dmabuf, bool draw_submitte= d); =20 #endif diff --git a/include/ui/gtk.h b/include/ui/gtk.h index 4b4ef50e3701..b66b9ca5c519 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -59,6 +59,7 @@ typedef struct VirtualGfxConsole { bool scanout_mode; bool has_dmabuf; int gl_fence_fd; + bool draw_submitted; #endif } VirtualGfxConsole; =20 diff --git a/ui/dmabuf.c b/ui/dmabuf.c index b61dc7ad2783..16063dc62ae8 100644 --- a/ui/dmabuf.c +++ b/ui/dmabuf.c @@ -26,7 +26,6 @@ struct QemuDmaBuf { uint32_t backing_height; bool y0_top; bool allow_fences; - bool draw_submitted; }; =20 QemuDmaBuf *qemu_dmabuf_new(uint32_t width, uint32_t height, @@ -212,21 +211,9 @@ bool qemu_dmabuf_get_allow_fences(QemuDmaBuf *dmabuf) return dmabuf->allow_fences; } =20 -bool qemu_dmabuf_get_draw_submitted(QemuDmaBuf *dmabuf) -{ - assert(dmabuf !=3D NULL); - - return dmabuf->draw_submitted; -} - void qemu_dmabuf_set_texture(QemuDmaBuf *dmabuf, uint32_t texture) { assert(dmabuf !=3D NULL); dmabuf->texture =3D texture; } =20 -void qemu_dmabuf_set_draw_submitted(QemuDmaBuf *dmabuf, bool draw_submitte= d) -{ - assert(dmabuf !=3D NULL); - dmabuf->draw_submitted =3D draw_submitted; -} diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index c671aabd11b3..8623181336e9 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -86,10 +86,10 @@ void gd_egl_draw(VirtualConsole *vc) if (vc->gfx.scanout_mode) { #ifdef CONFIG_GBM if (dmabuf) { - if (!qemu_dmabuf_get_draw_submitted(dmabuf)) { + if (!vc->gfx.draw_submitted) { return; } else { - qemu_dmabuf_set_draw_submitted(dmabuf, false); + vc->gfx.draw_submitted =3D false; } qemu_console_hw_gl_block(vc->gfx.dcl.con, true); } @@ -169,8 +169,7 @@ void gd_egl_refresh(DisplayChangeListener *dcl) #endif } =20 - if (vc->gfx.guest_fb.dmabuf && - qemu_dmabuf_get_draw_submitted(vc->gfx.guest_fb.dmabuf)) { + if (vc->gfx.guest_fb.dmabuf && vc->gfx.draw_submitted) { gd_egl_draw(vc); return; } @@ -290,6 +289,7 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl, =20 if (qemu_dmabuf_get_allow_fences(dmabuf)) { vc->gfx.guest_fb.dmabuf =3D dmabuf; + vc->gfx.draw_submitted =3D false; } #endif } @@ -406,9 +406,8 @@ void gd_egl_flush(DisplayChangeListener *dcl, VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); GtkWidget *area =3D vc->gfx.drawing_area; =20 - if (vc->gfx.guest_fb.dmabuf && - !qemu_dmabuf_get_draw_submitted(vc->gfx.guest_fb.dmabuf)) { - qemu_dmabuf_set_draw_submitted(vc->gfx.guest_fb.dmabuf, true); + if (vc->gfx.guest_fb.dmabuf && !vc->gfx.draw_submitted) { + vc->gfx.draw_submitted =3D true; gtk_egl_set_scanout_mode(vc, true); } =20 diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c index 29d1b1e4116f..45c0c8c81a11 100644 --- a/ui/gtk-gl-area.c +++ b/ui/gtk-gl-area.c @@ -82,10 +82,10 @@ void gd_gl_area_draw(VirtualConsole *vc) =20 #ifdef CONFIG_GBM if (dmabuf) { - if (!qemu_dmabuf_get_draw_submitted(dmabuf)) { + if (!vc->gfx.draw_submitted) { return; } else { - qemu_dmabuf_set_draw_submitted(dmabuf, false); + vc->gfx.draw_submitted =3D false; } qemu_console_hw_gl_block(vc->gfx.dcl.con, true); } @@ -319,9 +319,8 @@ void gd_gl_area_scanout_flush(DisplayChangeListener *dc= l, { VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); =20 - if (vc->gfx.guest_fb.dmabuf && - !qemu_dmabuf_get_draw_submitted(vc->gfx.guest_fb.dmabuf)) { - qemu_dmabuf_set_draw_submitted(vc->gfx.guest_fb.dmabuf, true); + if (vc->gfx.guest_fb.dmabuf && !vc->gfx.draw_submitted) { + vc->gfx.draw_submitted =3D true; gtk_gl_area_set_scanout_mode(vc, true); } gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area)); @@ -356,6 +355,7 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *d= cl, =20 if (qemu_dmabuf_get_allow_fences(dmabuf)) { vc->gfx.guest_fb.dmabuf =3D dmabuf; + vc->gfx.draw_submitted =3D false; } #endif } diff --git a/ui/gtk.c b/ui/gtk.c index 1c75b9ea3c4d..55e45e8445bc 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -593,6 +593,7 @@ static void gd_gl_release_dmabuf(DisplayChangeListener = *dcl, egl_dmabuf_release_texture(dmabuf); if (vc->gfx.guest_fb.dmabuf =3D=3D dmabuf) { vc->gfx.guest_fb.dmabuf =3D NULL; + vc->gfx.draw_submitted =3D false; } #endif } --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:00:45 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=1788951881; cv=none; d=zohomail.com; s=zohoarc; b=afgxg9+K19VYuk52Opv1eFhNSCZnyUBakrVL9PW+X7Piq/dN6dy5v0ghcC/VV7gyIlAE7YKIIFB+LP7b7iQMTNEdloCOHtETUGF45iovZbxG/T8ielhsfRsXL7OdJ5N950spdYRmnac3LaYZk62M6Whg+F5wFRDcMM1nyirdM4E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951881; 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=0aCO0uNFxJDrfHiJBs8AT6lTkMw8C7vlFldvNwsdGSk=; b=XvMftteniLy5s0ElnQUhgBC85axsRT+CJLqSNH/HSlum3ehab9YJoX1B3mgMkeb4TEp0r3Lfx7RTQnhV2sVcbLoKXqq6Y1LUkwi0BdM6YP1x7wS8qVn9DUmSw2OIMzBbvLPlMHk/iko4eK9L8T+kCXXaxS4P/6ZI2i79diewUmQ= 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 1788951881666357.91857509673025; Wed, 9 Sep 2026 04:04:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G61-0002qv-OX; Wed, 09 Sep 2026 07:04:05 -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 1x4G60-0002qf-Qq for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:04 -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 1x4G5y-0005Fu-VO for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:04 -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-645-062Vkz8FMyqs5zujA9YSVA-1; Wed, 09 Sep 2026 07:03:57 -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 49823180076B; Wed, 9 Sep 2026 11:03:56 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7A4B630001BB; Wed, 9 Sep 2026 11:03:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951842; 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=0aCO0uNFxJDrfHiJBs8AT6lTkMw8C7vlFldvNwsdGSk=; b=Bkr7X9Q558k+wa/OE4wFGZ5Fqjg7rp+J66lx6h5JMvg7sH86AoutZAMOlOPWSmrnX84EW9 tMz+VyxKajwiUaG2hwOAFKx24T2n4aWUmWZTWl6m5N4W6ugxaV8tiVOmAxHAXkQ/V7Q/pO BXmfSKN0sexVkrF9YD+x7crPaLuDAKU= X-MC-Unique: 062Vkz8FMyqs5zujA9YSVA-1 X-Mimecast-MFC-AGG-ID: 062Vkz8FMyqs5zujA9YSVA_1788951836 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:13 +0400 Subject: [PATCH v3 08/24] 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: <20260909-virtio-gpu-cleanup-v3-8-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=6106; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=gSMT+0AOJarhtVwNErFLIpySAW7A6q8MDifZCjlShj0=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzyFHzPB9+6/9iiaAFCBOeGG/fxn7eMeYXbV FmE/ABWZEyJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88gAKCRDa6OEJdZac 5fXoD/sEqBLqQVbjgBC3PdRuXQ7Zi13UOgaCaXqpjhJHmOkpg0wLmGTNEuEbu3OB1xWgjYkPK5n 3zNiV79rmgAMoDwz4LCHA3Sy51Fla1OOB3yso/3KiwJ50o/Wqdb4ze2jjyZg2GjZbbCsNBCVFD0 7lpi+CdrhHQR9sgVTy3EqO8S0+/PMzKB5P+1oxfgDcKL23l9UwTqzf5ZVa03un3MGSF8kYAOlxy DNp9ZGIUyjnNT97jRDE8FzxgO21aLQWejHoulD5fdjDcfrCVjQLroeh+MOlwzVLtvFw1/NbiRA+ PemoJZAjUP12XgyXhwXX42IGCf9SNmrX/ZsokHUyJvYceUBH0wPNILSEBVA5rstVtha6gJvUJE/ K2BBTkxgqsmrUaVN3NabOhrWewA25wImJ/FyJXSK7AmYx0QXkHeNQEQZZWTxyafQm1urHR8qbhB 3CaRP8s9U9rmhzvBkpcJy41hksOywaScJOuyJB5vyV/0gpxp223xz0Tk86a+xVV9e+coTho6mYZ ii15/Mcg8ZRVNQAcZAy2/1SRX0JoQxNPVsCJROTgfV1sXCknGAUpa49s/4RiT4ktvh79QHopAq2 8pspDISN8aBiGdu70gPwadurJDrykJ10p+Pu6U67xTxKl7XvsEw5xcFFJVREQ0wNoMgK4J9jA1a lYnL3z5HQ4w6ZNg== 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: 1788951884088158500 Narrows release_dmabuf to the active scanout, as the device & console may interleave new scanouts before releasing old ones. Fixes: 142ca628a733 ("ui: add a D-Bus display backend") Reviewed-by: Akihiko Odaki 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 Sat Sep 26 20:00:45 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=1788951878; cv=none; d=zohomail.com; s=zohoarc; b=Joeg39CznZkXrJ+bfY+gz5Ig1i+a+5MC65GzCRgt9sUiMHaTnxrp6guGU5jVWwVsQyX/mZl6wiPBoqe5usQ2H7FORcE/AkholTgsgXqX/HaS6jrDpNOZuZEZItbPKe9BVzBsqueJKYs11x8QCDRG219VBh1EV9abud4qpPgrtao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951878; 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=8eKUMoZq5XV11is/tjts9lB3sVWqkFifCCJ5vtFi2hw=; b=lqlL85P8yInd+BcEZXR/UY3DXMGtyt5TzCqFLz425qJZQ8ci8NBaEYCTDyGZx5TrMtI6zOSykW/ds6ab5Vk2Bzgt/kWKfq9xJp6mvAHbFDxqRLEqDxkCa/d6nyYv7Jl3CF76c8fyspH5avl5Kqcmrts6fv4bNzuXHpqiS84xEsA= 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 1788951878697520.8342841010465; Wed, 9 Sep 2026 04:04:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G64-00032J-Av; Wed, 09 Sep 2026 07:04:08 -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 1x4G62-0002sx-Av for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:06 -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 1x4G60-0005G3-Fc for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:06 -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-662-w26csPBjNGOyF4dYTjsrgQ-1; Wed, 09 Sep 2026 07:04: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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 592B9195419E; Wed, 9 Sep 2026 11:03:59 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8AB7430001BB; Wed, 9 Sep 2026 11:03:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951843; 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=8eKUMoZq5XV11is/tjts9lB3sVWqkFifCCJ5vtFi2hw=; b=bPKmKHZIdGRCo/o0oypI9whxcef4zper/k+OVfeWs721fEjNS4/s1KLt1Iy+H6A6uoCfXZ dH0zGJ4iY43TRr/VPNT3yFrLdGF4gQWX4FVnsftcMubXOYXb31eVZxxaF+CjFHb4CZZaCr SPV1FDKIfWNbj3CXxzACSon2Khu2TQI= X-MC-Unique: w26csPBjNGOyF4dYTjsrgQ-1 X-Mimecast-MFC-AGG-ID: w26csPBjNGOyF4dYTjsrgQ_1788951839 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:14 +0400 Subject: [PATCH v3 09/24] 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: <20260909-virtio-gpu-cleanup-v3-9-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=6595; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=uctf6lHwlbTWsPKln7Zc5X4gjngr0Ppzs4eUPV26194=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzyjC1UokPdMLeJMN9Irkaoy2vNAAbeYcz+3 IAsLdevE9aJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88gAKCRDa6OEJdZac 5XXnD/sHgvjuBiulGKebxu7E/8qycFTgr5oZ/spzoVPWG7u7AzT8vGRl12KPc6wRVj0VSOzODoP fId+WC+8ENkU3HvuITt9s+jOoQFka+3gw188oFhjXmrcfHHpi/H04EwouscdQ4I7viqaH3bzTdC yUnFF6jz3mFijFPSA/fXxcfquj2cDVXPKmNgaC78LuS3IGYsnUlw4kNtsZaYTSURdNssgd38vlr 8fQZQkHkKZqrq07YlhvSrHlU1+fE6lID33gJw0W4Mm158+v+G7pa7cC7MEXK/35nCQT3usW6Rr+ ymalfPx7ziK6gzq0GGCxXdeM5bUBJ0Bzl340yY5gK+HEbM61HnQlYebP7MlsCwZGuUZnYKgn9lu PxhFcC7Y+qKSH34sxD3bnDzRj64aXw9CQQi7sc6mgjxHanD3kMbSj323hSAlLRiwZ6Iclh5cA10 ttSqzOWHJcnGrIzU/N61azE4ZWXTLUiMtnorJm/2zbUJ/SnkdCXJ/yGK8t5OrP8eS2d/iI4mAZJ AM8LRHo0TycmdOcaVPjAIOojnJtJ2Tuc/lfF6vo5W6azrFO3NvVsE4acpcwi4gHi3jDG7qddQ8s nJqnseDfQMVtkS0vpgdSL2vJFWhixKkrT9JOYQPM4p/myLGG34ypAP/vRFoZoAdcKfRCjQnG45o waWhb2ijsBe7zuA== 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: 1788951880013158500 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. Reviewed-by: Akihiko Odaki 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 fc63f2c4ec21..a38afb24c71f 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-udmabuf.c @@ -160,30 +160,19 @@ bool virtio_gpu_init_udmabuf(struct virtio_gpu_simple= _resource *res) return true; } =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; res->share_handle =3D SHAREABLE_NONE; } @@ -192,31 +181,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, @@ -226,26 +207,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 8c0df60b3b7e..ee5f6f2f2375 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -85,6 +85,7 @@ struct virtio_gpu_framebuffer { struct virtio_gpu_scanout { QemuConsole *con; DisplaySurface *ds; + QemuDmaBuf *dmabuf; uint32_t width, height; int x, y; int invalidate; @@ -189,12 +190,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 @@ -226,11 +221,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 Sat Sep 26 20:00:45 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=1788951862; cv=none; d=zohomail.com; s=zohoarc; b=EJP0bTglJoWKaZnK6caH2CIpQZV5eoslCVE8UhFp5BjRiixRSaMihd1YLhLb0Vkkug+78WuAdyYJOKc6Egdf92mOaJ3teVT7nAUsTLZjE1svP0xv2oT0W3GmlUuTTNxRIZA1eZHW78Ckv2c3o567q2nxswu5qp71kBO2/ccyHbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951862; 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=ab79tc0wP1jslXYpwrccZQdhGgSRbeaIJ1DfJSrtXZY=; b=MYnYm2z8PUINbeSUk9EYF2P0w92k4teeoatr0S3iZaEethCsJcBDP/mPbZijEAKo+nsbEVcllOC5hr4D5ZGuZWblr98wxIt6NHLXw9gFX+Erd0/NQtQ0Ap+j3p/61emm6fasfer6VJDgRVpRCHlNXz2Fuu6WsiuGjw72VFKxEYc= 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 1788951862104285.8393775024391; Wed, 9 Sep 2026 04:04:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G65-0003DI-Mv; Wed, 09 Sep 2026 07:04:09 -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 1x4G64-00033t-E6 for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:08 -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 1x4G63-0005GS-1B for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:08 -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-173-rUwtFTSLNvGGR4XQ4bubAw-1; Wed, 09 Sep 2026 07:04:05 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1BA1C1954107; Wed, 9 Sep 2026 11:04:04 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2B9321800352; Wed, 9 Sep 2026 11:04:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951846; 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=ab79tc0wP1jslXYpwrccZQdhGgSRbeaIJ1DfJSrtXZY=; b=PSwXp6bEHI2enwGLrzggD7cKi8sXVTyHT+KggaDQclInYUlUPkjlGB6UQbsoJA3VpUbOk5 OnGIdqV0FJYYaYk5UHXBdcqQ1DKNMhDKyS5Jxj87UZsviCc1g94DANkrWlc2rLRu0b6zk8 BAsCqjFnlJpsguHQBDYKUaOFzmqttMo= X-MC-Unique: rUwtFTSLNvGGR4XQ4bubAw-1 X-Mimecast-MFC-AGG-ID: rUwtFTSLNvGGR4XQ4bubAw_1788951844 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:15 +0400 Subject: [PATCH v3 10/24] 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: <20260909-virtio-gpu-cleanup-v3-10-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=1052; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=OQduuPEP/YmWbLpH074hRz03Ee7qLxiHWTT26EkF3go=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzyf55LkQFR/HUfY9f1KegvTffLqfyKSLcyK 8onYXeISPuJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88gAKCRDa6OEJdZac 5eMgEACkOpwCTxrRGkDXjiguH4Mgq1IPhe3Djy3kDLzSIxLQEedoPcHfmO0Y1YShXCAavz9OF2E VAUe2MVcMVhKVDVsBWr6aJxzJ1jC990R1QUsAeoNcs/Im9tIeHUsZriNNsxre/Y8a2hIKarIquY 5WfddEC7A2dHz9JoJKtJzp9ZIqxfrfafWVqgYEGLQYWHrS2KmWjRhh2EoWWRfv7HV5NY7XMA56d GLxRAPgXYXiOIAHT/MyqwnBmtiqHtt/AS0iEOZcUgHcwM0TLde2CZxnK0eljZAwYs+e6Qlpz024 KJHQaq8QUt8dBySPJPv8oLggKzn5mZQG30C2uypVl85+Rr+4BFrJvtrvm4JwLRQkiZ+EhDCAI3G HkjCzR0lmw5g7OZMtztXoLRKED5kSIxwroSl0qC2JC5dLg9CW4QOF6yp5QgPgHrahifKcATmEPp SfltyL2J6urB0iTx7lvecmQ3vjwnjcOygylhpAxsmyLrUdnRvXTUHK+m2vzYIBmV/lFxKcJKKNh RXt39mdHJIye9BGdpiuXEjapFvWqeIudagjfME+kjGj1QmaPTCKZcvFFC8AKJKzUaA5y1K5+USS LDfc1TRfVCYOXg5W8q604Ko1cJXutlMp6Ha7qekSAJsD1r4sDck584mAdDdY033PtNpIWd9oaPi mUihzUYwdbWGvfg== 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: 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: 1788951863827158500 Disable the GL scanout when the actively-displayed dmabuf is released, so the console does not retain a stale reference. The VFIO commit changes to call qemu_console_gl_release_dmabuf() before qemu_graphic_console_close(), which dereferences the active scanout. Fixes: 239b7c5705a4 ("vfio/pci: close display console during unrealize, not= finalize") Reviewed-by: Akihiko Odaki 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 Sat Sep 26 20:00:45 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=1788951875; cv=none; d=zohomail.com; s=zohoarc; b=VOKKxsdzbkpcIKb9HlblYcvDVGDA1Xp6pvDv+VRXCubJGO/WzLXYe9/liQvY6M0fviO1UxhImf/Y1btY9kXwRj0pY9wIinrInNyD147JWolNZLlhf7UmCyDFgSjBsFyXkYHMcGR83g1u3jHdzyjHanMoOngdxUJmy5lYYJ/KUe8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951875; 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=XHHwspiJ/RpBE0HEPqNXG0+MxDXPOfiZVbdO3BXZFm0=; b=X4xn+9JY3LAoajmjz5C7ZiNEtFJZTzWJfhx5K7tZZ9kRg+ovUnMDSTdpVrwnSoy03SnhR1WvSmV9NfqTGGjspHq4Wvk/5yIYdfJIQdbzwUJEi36nUTYz1lz0qiMmIfOThYr1agto/q/VhlpKAZU3Oy8adqOhMRjN1PSiCIbv4fg= 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 1788951875853965.3404339705642; Wed, 9 Sep 2026 04:04:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G6C-0003nl-J3; Wed, 09 Sep 2026 07:04:16 -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 1x4G6A-0003ki-OI for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:14 -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 1x4G69-0005Gi-8q for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:14 -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-38--v4lBJgyObiLJGlG8gn4Ww-1; Wed, 09 Sep 2026 07:04:09 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 048A518005A3; Wed, 9 Sep 2026 11:04:08 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 778AB1956088; Wed, 9 Sep 2026 11:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951852; 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=XHHwspiJ/RpBE0HEPqNXG0+MxDXPOfiZVbdO3BXZFm0=; b=KzPDO2MT4tKdaCIPoDT5J3hruzKr/gaje/yeopsde5n3H81hGMWLu+WsvBYBz8HWXI15ss 9Xe2LeLpU41RuYMXukcIGHpybhkXMHDg+oG1BgOBy26Q59jHVdznZou3Rf8wlo/G1CY5Ai RmAV3tl5EaOHbia5aLegDPNJV1EqLh0= X-MC-Unique: -v4lBJgyObiLJGlG8gn4Ww-1 X-Mimecast-MFC-AGG-ID: -v4lBJgyObiLJGlG8gn4Ww_1788951848 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:16 +0400 Subject: [PATCH v3 11/24] 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: <20260909-virtio-gpu-cleanup-v3-11-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=1043; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=ckwb6WKTNIogQkoKNEFb6W6xtaAoBV7HCY+xp/SqEdE=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzyrB8KhlzSXZlHtFjChvBUWk3zw8+p5GOh0 3OVEuiTzUGJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88gAKCRDa6OEJdZac 5TOqD/wIRmBq9Jv+x35M39S5KJJ2scewC4glLrzcacflP+YJSOC0y6SU7QZpZeH8N5erJ5wUsR4 YhW4c/h0E2zsGZwii4sAvH6WfZsb6JQ5KDJfeKivLQftNFVWRVgMyhz4++xod6fSCYo71wWdGpm 1L/trsVg7AnHYCMoqp73sntWUKS8AQ0RCqFPm0byuDJQEtUBZMzPMOyAOv0KjlqJ9WatX/Bvpjy 9tO4bTezewPCoCUGfs/G/mzHTYuGtLf076rFrvr+LoSD+nayuMW3tJF9RCq/XMfXLwEn+WmXMy5 Pds+Zf/1Zj8hLa40Ymha40tZYR8M7X16m7bO6LsOGjpjbBDfi3Xosd+w2d97qMFYzg/GIKwoYhw 8R088iIkeA41GT+K9T+SNQBBVlMNcWbdYRHyijHPcPHxBQB7IxFZdGaBsrzfpB46AY0eYMvBJtz z/Oh49DtdGY6/0AE8YGQFW62FfXB9vrSDrBhPeIxGqCx7/ehiqYHKX6ua2AhuzsHxMbdKl9KAyz 1Gzv4e8BrZO2h6qiihic7k8yIHB+739arXq/TfxaM5RLcPsJ6ucnuhYZWKKLIR4BssxPEfTPkYA 0kbgBCtU/LMHH3rOXZqaw7ZE4Jpd+nIAtsUFeKfheZvm9mBYuAaRT3rSSUq0HeCla5d6BO9j6W2 AsKti+d6MhTMt9g== 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.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: 1788951877953158500 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") Reviewed-by: Akihiko Odaki 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 Sat Sep 26 20:00:45 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=1788951866; cv=none; d=zohomail.com; s=zohoarc; b=E1IC7yN4hltCQZMEkFb2cGDPYi1p5bKPsd003iAOplsq8qb+uxWOI/RKTmoPLbYNUipaxIM4I+wAuu3NOm2qRgIf/sSmFPuqDyIF4zWjIxZgCuIi7JTtS0Uxne75+E3vpMptfbAn2TlxO38/hq8qqdfTpv1sGK7D2NzA2MeBI+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951866; 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=PdRv7C7TSGXnmjnEYv9t2u4X5jqEne6llWQ1CsuAeUg=; b=EpG9UBfMe+ffvA+P1UGVq2ug5WQ4/6gvy+zsuRz3lWh3LnRQLA/uP/TyemmQKb+GWSIzxFNxzsKqAV3xwjN/oFt5jPq2Umy2ahfSGdg6avdx1y0qkF8LYecLUAnYYmGP0FkO1QbYDL809tsMuj2+d4Q8ZbeRNmHM4VJBxr3FtZI= 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 1788951866427552.3800983840911; Wed, 9 Sep 2026 04:04:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G6H-00042F-56; Wed, 09 Sep 2026 07:04: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 1x4G6D-0003or-1l for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:17 -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 1x4G6B-0005Gx-8O for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:16 -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-622-rDEM_kRePzqVvZrkDp43CQ-1; Wed, 09 Sep 2026 07:04:13 -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 347CD1800BEC; Wed, 9 Sep 2026 11:04:12 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A7C6E1955D84; Wed, 9 Sep 2026 11:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951854; 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=PdRv7C7TSGXnmjnEYv9t2u4X5jqEne6llWQ1CsuAeUg=; b=S+YLkVtAmwgnjBg+gT0ShYKdUZX7x0AWRN6RZJrSidpRMuYKNxcLxsC5t5Ajfv7nUSzvfB denaGLrt3TLqQTnlOw0sG6I4r6+CRQjXGalL+Qch8ftSarWbTVzDnQNRtoHYL8BNOJ3Dbi SswQIKk3ZBirOiZmc5ykGyvun0fCiCU= X-MC-Unique: rDEM_kRePzqVvZrkDp43CQ-1 X-Mimecast-MFC-AGG-ID: rDEM_kRePzqVvZrkDp43CQ_1788951852 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:17 +0400 Subject: [PATCH v3 12/24] 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: <20260909-virtio-gpu-cleanup-v3-12-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=8315; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=bjg6DVdSzJNq9vo1t3gpro2PxZLTKgZAq8iv4FBWjjA=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzyq0Qb3cbR6m9L637VZoNJRaWWJqV2M/dXW Mq6GRxNrL6JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88gAKCRDa6OEJdZac 5TSoD/9H6Oe/Scp7yteZH6a4xgbA3Q4+i8bwWyXfJ7UD/RfmZgHp6edrZsiZDEVy23f2AtnRoVr Fso94t/LKSXA8T8vfzwFva5tyk1bqCavMwpwP48BTHDomG217ukKqOibucW5O+pNwZ14TUCe8gn G7nFusNBg/QQ7Qr5foXmbH+QWsefrleG7aefk3yZWqyPOV1CuqXoprC0ScHWfKCR60/csSlz7aP H5hodQcvU6+kyZ+cKbvivlJ3MG2hypgJS4HmSh2qWVaarkV2hTT158e3qmOW5QUQU/5CajFmxdK MFU8qF9yGyiR/bJv7AhvFI0uzlSDy/c+hzCthKwf9c6kGqplZ3S+JSieeu5H8BFJpOuKlZ89EpC NyKfQ6a4f4rPkfS6JuWp9uK8NPsZ1ku/b1RcrvSoFdSTdmbhJnIsPG/X/lLrhT2h8ciu552IYr4 BhI9zDqFLgHuJ1iAOhglfXFqMO49jkLei5QH1JOdphXiFYNAkFTXXPAjXZHnkm1nKw4IFAXwv5J 4Llbc79x/E3xElRZvgG82oakdQN5rQ5x+C+fJ/vBbsmx1M7udzVpslFxuPf92O339trZUdcceW3 E18fyBvj1BKelv34ptrYUcZy/rp8HjXtQOgmYxWNehwMnPVo9N4NWOz0ObjYN4kT/LLP7o2GAHP dfN1IdUeaLYRwBQ== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 127.0.0.2 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: 1788951867843158500 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. Reviewed-by: Akihiko Odaki 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 | 33 +++++++++----------------------= -- 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(+), 46 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 0883bf05fac1..1a9dfbdec109 100644 --- a/hw/display/virtio-gpu-udmabuf-stubs.c +++ b/hw/display/virtio-gpu-udmabuf-stubs.c @@ -13,7 +13,7 @@ bool virtio_gpu_init_udmabuf(struct virtio_gpu_simple_res= ource *res) return false; } =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 a38afb24c71f..6d2bc8d9771f 100644 --- a/hw/display/virtio-gpu-udmabuf.c +++ b/hw/display/virtio-gpu-udmabuf.c @@ -82,7 +82,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); @@ -148,7 +148,7 @@ bool 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 false; } res->share_handle =3D res->dmabuf_fd; @@ -160,43 +160,28 @@ bool virtio_gpu_init_udmabuf(struct virtio_gpu_simple= _resource *res) return true; } =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; - res->share_handle =3D SHAREABLE_NONE; - } - } - - 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 cb45360e769e..ecf3cbc4893c 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1077,7 +1077,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 ee5f6f2f2375..c2018b41056f 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -390,8 +390,7 @@ bool virtio_gpu_scanout_blob_to_fb(struct virtio_gpu_fr= amebuffer *fb, /* virtio-gpu-udmabuf.c */ bool virtio_gpu_have_udmabuf(void); bool 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 b972099859f2..968f3f9c8d48 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 16063dc62ae8..697d853ad847 100644 --- a/ui/dmabuf.c +++ b/ui/dmabuf.c @@ -61,10 +61,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 @@ -91,20 +99,6 @@ void qemu_dmabuf_dup_fds(QemuDmaBuf *dmabuf, int *fds, i= nt 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 Sat Sep 26 20:00:45 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=1788951878; cv=none; d=zohomail.com; s=zohoarc; b=EuvhmFdeuo5nqJU97KMZ8jAJ++HnXtUGgyD9ZdFzhw+IWlId/y+4Z2E9XkdKtdjSheQacW+hDapmmFyjlqR3H9Mu9qNknlSWEEtSHXqIoIbkaZ/nHZMckOAF7sjSI++6+XrWokCY0mO9SmT+YkuCDCtuJ9Oc54fj3bcuIFN0F3U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951878; 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=HUayjimk4Im+tvyd38w68Xzxtt9iPgDIR65xIfuixR4=; b=IJkzpM2YE321zzDPoeSvo12dMl7sC7+TRrpY/Izy54Boo+FVyndeiAmtocPgTSYeLctcvQZ5GFqxHXcYddhBEdW8jOcwQvUqjAtZMVmPFLlrwU7YA5hbSEL8+2W/OHwQ9EdPq3L6+IcuXn5j1h2ebWEihEhvoQHBMB0SOXjIUas= 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 1788951878490644.7255227120633; Wed, 9 Sep 2026 04:04:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G6K-0004Ob-Mc; Wed, 09 Sep 2026 07:04:24 -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 1x4G6J-0004Gn-5w for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:23 -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 1x4G6H-0005Hv-94 for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:22 -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-400-CTJAKT9rPGiijPh6QNCUcA-1; Wed, 09 Sep 2026 07:04:17 -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 25D3F1800845; Wed, 9 Sep 2026 11:04:16 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A7EE430001BB; Wed, 9 Sep 2026 11:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951860; 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=HUayjimk4Im+tvyd38w68Xzxtt9iPgDIR65xIfuixR4=; b=MqrFqV8BRxaUYtAs2Mv5469fr+eL+QdkVnYDwwWwSLE6J6dm/crWIqs5nkJtNvOV2Zl1tL KpBA7Vq1ixy9Pkk/qE5/XfoD57zUfinYxF8t5JK8KPs6+HplZIVAtA35I5+HQ/kP03qwpS QFZt4/l41/c9elHpr3VUkoI0kgbX6Ls= X-MC-Unique: CTJAKT9rPGiijPh6QNCUcA-1 X-Mimecast-MFC-AGG-ID: CTJAKT9rPGiijPh6QNCUcA_1788951856 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:18 +0400 Subject: [PATCH v3 13/24] ui: make GL context current before releasing DMA-BUF textures MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-virtio-gpu-cleanup-v3-13-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=7620; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=hpKDgtbR14NBavZrGUQWaBAnPANZrIBPQZn4RdPpenE=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzzCzgCYoDX2ciKum62vw2ZX5DsvxcuQYzGt gk6w03nxDCJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88wAKCRDa6OEJdZac 5UdxEAC6gbaa1tN9Vvs18mQdWIZBs9oMOLBaiDBc5Cv/c1kSBBjLd8K3YMnX5F6lZxuPk4k6CZG Ik4lY2h34VZlJ9t969FWAYtDRfw09i8Ltpdj26oEnwlHQ2zVKTDLs78zojFzV3UNTocQl2pGiRC pCPr1ivdOG6ZKctvYa8etY1TlKuVUzbF7nOCrbNgIVEgMBbII2Fh5TOX32SA9cqXbh6k+bOvAOa JSpYHisMMFA2nBJy8NRN6ZrlruTHOzbMrdVt/B9nDZgjyuS/W2CcNpXHoXxCqYXPYqkS115DSW1 gRg6bmH/aWDb8w/WD0MQAVj+ur0SknRbWCFo7mygRC+RCp6U4fX1calUECdoZOanfSjdX3J9ww4 Mjnnm3s8OFSrwWcgENat2XrtjBwC63H1tcAo13TCvrHb8+oe0as4joa2Apm4jwW28fPi5brn85/ Yyr8C0HHXX7fmJzA2PJL1Q8t4JF08FKf/I463dNm15vLRXDkUfx833Zb2QNaP3jejLbCQg53mna y4F82STGE2mYhu31iZSo/HcWVMpiFoGwfy+QOW/xRVxyHbuqo7dy6W6DJIpZm5fK30r+Xuli3n+ ni9sXkBjhozhS5BFoj99NfaCbeqMwRZX+UDS0qBrqm0zctBFwQEjNs81c7srf9moDkuxhbb1Hai NWwyCki7Q3Nlf5A== 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: 1788951880040158501 The dpy_gl_release_dmabuf callbacks in the GTK, SDL, egl-headless, and spice backends call egl_dmabuf_release_texture(), which calls glDeleteTextures(), without first making the owning GL context current. This is reachable after another console's surface update leaves EGL_NO_CONTEXT current (e.g. gd_egl_update clears the context on return). The deletion then silently fails, leaking the GL texture and its backing storage. With an unshared context current, a coincident texture name could even be deleted from the wrong context. Fix by making the appropriate GL context current in each backend's release callback before calling egl_dmabuf_release_texture(): - GTK EGL: eglMakeCurrent with the VC's EGL context - GTK GL Area: gtk_gl_area_make_current - SDL: SDL_GL_MakeCurrent with the console's window context - egl-headless: eglMakeCurrent with the render-node context - spice: eglMakeCurrent with the render-node context For GTK, the previously shared gd_gl_release_dmabuf is split into backend-specific gd_egl_release_dmabuf and gd_gl_area_release_dmabuf, matching the existing pattern where each backend manages its own context. Reviewed-by: Akihiko Odaki Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/ui/gtk.h | 5 +++++ ui/egl-headless.c | 2 ++ ui/gtk-egl.c | 12 ++++++++++++ ui/gtk-gl-area.c | 11 +++++++++++ ui/gtk.c | 13 ++++--------- ui/sdl2-gl.c | 1 + ui/spice-display.c | 2 ++ 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/include/ui/gtk.h b/include/ui/gtk.h index b66b9ca5c519..6b62e9758813 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -163,6 +163,7 @@ extern bool gtk_use_gl_area; void gd_update_windowsize(VirtualConsole *vc); void gd_update_monitor_refresh_rate(VirtualConsole *vc, GtkWidget *widget); void gd_gl_wait_sync(VirtualConsole *vc, void *sync); +void gd_release_dmabuf(VirtualConsole *vc, QemuDmaBuf *dmabuf); =20 /* ui/gtk-egl.c */ void gd_egl_init(VirtualConsole *vc); @@ -190,6 +191,8 @@ void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl, uint32_t hot_x, uint32_t hot_y); void gd_egl_cursor_position(DisplayChangeListener *dcl, uint32_t pos_x, uint32_t pos_y); +void gd_egl_release_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf); 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, @@ -221,6 +224,8 @@ void gd_gl_area_scanout_texture(DisplayChangeListener *= dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h, void *d3d_tex2d); +void gd_gl_area_release_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf); void gd_gl_area_scanout_disable(DisplayChangeListener *dcl); void gd_gl_area_scanout_flush(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t= h); diff --git a/ui/egl-headless.c b/ui/egl-headless.c index ba27efcf4c3e..ffe7b30f919b 100644 --- a/ui/egl-headless.c +++ b/ui/egl-headless.c @@ -126,6 +126,8 @@ static void egl_cursor_dmabuf(DisplayChangeListener *dc= l, static void egl_release_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf) { + eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, + EGL_NO_SURFACE, qemu_egl_rn_ctx); egl_dmabuf_release_texture(dmabuf); } =20 diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index 8623181336e9..d595916476d9 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -426,6 +426,18 @@ void gtk_egl_init(DisplayGLMode mode) display_opengl =3D 1; } =20 +void gd_egl_release_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf) +{ +#ifdef CONFIG_GBM + VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); + + eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, + vc->gfx.esurface, vc->gfx.ectx); + gd_release_dmabuf(vc, dmabuf); +#endif +} + int gd_egl_make_current(DisplayGLCtx *dgc, QEMUGLContext ctx) { diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c index 45c0c8c81a11..effd88f28721 100644 --- a/ui/gtk-gl-area.c +++ b/ui/gtk-gl-area.c @@ -360,6 +360,17 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *= dcl, #endif } =20 +void gd_gl_area_release_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf) +{ +#ifdef CONFIG_GBM + VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); + + gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); + gd_release_dmabuf(vc, dmabuf); +#endif +} + void gtk_gl_area_init(void) { display_opengl =3D 1; diff --git a/ui/gtk.c b/ui/gtk.c index 55e45e8445bc..c615d35451b6 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -584,21 +584,16 @@ static bool gd_has_dmabuf(DisplayChangeListener *dcl) return vc->gfx.has_dmabuf; } =20 -static void gd_gl_release_dmabuf(DisplayChangeListener *dcl, - QemuDmaBuf *dmabuf) -{ #ifdef CONFIG_GBM - VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); - +void gd_release_dmabuf(VirtualConsole *vc, QemuDmaBuf *dmabuf) +{ egl_dmabuf_release_texture(dmabuf); if (vc->gfx.guest_fb.dmabuf =3D=3D dmabuf) { vc->gfx.guest_fb.dmabuf =3D NULL; vc->gfx.draw_submitted =3D false; } -#endif } =20 -#ifdef CONFIG_GBM static void gd_gl_fence_cb(void *vcon) { VirtualConsole *vc =3D vcon; @@ -639,7 +634,7 @@ static const DisplayChangeListenerOps dcl_gl_area_ops = =3D { .dpy_gl_scanout_disable =3D gd_gl_area_scanout_disable, .dpy_gl_update =3D gd_gl_area_scanout_flush, .dpy_gl_scanout_dmabuf =3D gd_gl_area_scanout_dmabuf, - .dpy_gl_release_dmabuf =3D gd_gl_release_dmabuf, + .dpy_gl_release_dmabuf =3D gd_gl_area_release_dmabuf, .dpy_has_dmabuf =3D gd_has_dmabuf, }; =20 @@ -673,7 +668,7 @@ static const DisplayChangeListenerOps dcl_egl_ops =3D { .dpy_gl_cursor_dmabuf =3D gd_egl_cursor_dmabuf, .dpy_gl_cursor_position =3D gd_egl_cursor_position, .dpy_gl_update =3D gd_egl_flush, - .dpy_gl_release_dmabuf =3D gd_gl_release_dmabuf, + .dpy_gl_release_dmabuf =3D gd_egl_release_dmabuf, .dpy_has_dmabuf =3D gd_has_dmabuf, }; =20 diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c index 46eff768c968..3a5aa09618ca 100644 --- a/ui/sdl2-gl.c +++ b/ui/sdl2-gl.c @@ -288,6 +288,7 @@ void sdl2_gl_release_dmabuf(DisplayChangeListener *dcl, { struct sdl2_console *scon =3D container_of(dcl, struct sdl2_console, d= cl); =20 + SDL_GL_MakeCurrent(scon->real_window, scon->winctx); egl_dmabuf_release_texture(dmabuf); if (scon->guest_fb.dmabuf =3D=3D dmabuf) { scon->guest_fb.dmabuf =3D NULL; diff --git a/ui/spice-display.c b/ui/spice-display.c index 75c7df7bb5e0..22cd1e266caa 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -1176,6 +1176,8 @@ static void qemu_spice_gl_release_dmabuf(DisplayChang= eListener *dcl, ssd->guest_dmabuf =3D NULL; ssd->guest_dmabuf_refresh =3D false; } + eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, + EGL_NO_SURFACE, qemu_egl_rn_ctx); egl_dmabuf_release_texture(dmabuf); } =20 --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:00:45 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=1788951881; cv=none; d=zohomail.com; s=zohoarc; b=aQ8bFKX7gNA1l6zAZ4u+XrTHgEznIyLlBRik5fUHszmmUpZqWU+8Vj4QVhVVtqd5+aGh+Sio55HYHCVx6hyg5Thd8t42rKk5ZzQE7GPVXtx92kz5zPLXF4QgOM1Q5TsIJdKaEhr7cpS6xpvw4Zpxz/WIxvL8zysjgvE0EW8Chi8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951881; 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=lIuJGnpVD5GH145GXgMfkdNa/VC4U9/ZZqHeHcYrX50=; b=gCHyioSz3oyt9So3CQclsLmUtI/e/+U78yOKWwmbwhpn/qfrTzhQrwBHn0saKugnnjzYAH6CV97w2uIibubfz093gpfQU0LZO4tGW3vsv8azJJYV036RGJXAPEzWxnTUv4BMG1vjcvuKSSfv2pBlAyngJ0RsIdy60G9rqLuwI6I= 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 1788951881497563.2278496262086; Wed, 9 Sep 2026 04:04:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G6O-0004h1-AK; Wed, 09 Sep 2026 07:04: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 1x4G6N-0004eX-4H for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:27 -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 1x4G6L-0005IF-Kc for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:26 -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-493-GfFaxbQZM6ijAvDMHqZfkg-1; Wed, 09 Sep 2026 07:04: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 5135F19541A0; Wed, 9 Sep 2026 11:04:20 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DCD8C1800473; Wed, 9 Sep 2026 11:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951864; 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=lIuJGnpVD5GH145GXgMfkdNa/VC4U9/ZZqHeHcYrX50=; b=CL9a5TwdIuQrK5JSI5f7Gw/Do4yvz2KkjFM2D4Kds6XpjimEttAh8DE3EXcaWno6YkWM93 Gn/QG27455whLvs5GN1LInftb8Ku8leoqHppZMRTpnGvdJsrsE4JcI7Ynwzxf6l7O5Pcjt wj202sHZRazdPTPV8uUJ4BTL9gKwCIM= X-MC-Unique: GfFaxbQZM6ijAvDMHqZfkg-1 X-Mimecast-MFC-AGG-ID: GfFaxbQZM6ijAvDMHqZfkg_1788951860 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:19 +0400 Subject: [PATCH v3 14/24] 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: <20260909-virtio-gpu-cleanup-v3-14-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=1596; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=dZ2+WlnJ+Ih2ml2xkL8dChK2pCVpDNOwJQ4Wrb16+6s=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzzNPIqhsp0/89e7FwplvaIUudcFtfxPw8Xz YkURv+SFGuJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88wAKCRDa6OEJdZac 5fujD/wPzlpkAygSQmmgmemRJbadw3Jvrx3SQbgVq2cuZmsRP3Upca8Xmk7UNWVtOGOE72VGIPy GIQWC6wawYJdZuHPw2npe7p5RcJebOXOenWWSzWK1ixwi9jTF1dpY+68UBtHJIcA09oPDgTq7M4 UPJEbf1cwjRUhPd9oP7yUM/fCekMS+uLH3K1F1r76fPK5gr2LzZHqaZD+PoV7XaQa/NF2Z+trZd DB913A5xhT8130hRhDBKI8ASfqTfntv+xbwBEf564C1uQio0kS6EtBrmvOMmjgTvmmI3SDwcLLT MJBUgQcBrPc5QTdpLGJq+uY87Wt3ivQjCUtlBS9EfukFRXwVk0fAsnaF+RUQhChwRUOMyg+1kXt NuPITeTL+vd2wAEWkC2JhoPO7LTwdDTbYlEnIIfku6dGmIYizcJi1YZE8IpS2jVHqVb3QTIM9PD 4BuNhi2z+XUEi5Nh+6Hyp48pvHcFLnL4PQSOFTQ70mP95hT45yE/wgkKXWo2gRDYM8oA87sn2Pr CFePVXMTjBEe6B+Gyb/FbHtQ5MrJmaIr3554y2sPs2SBiABWTkx5Zy2340E7AQ4FTCmLn0XD7pX XRIEqhYzfq8S/uljN9HQXGerKR/kpjD/QL+ndQ2quvt03yJ6EiN9IN7vvsVrjK4P/ooVNdG0VCV 8SR3B6w1wx2snYw== 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: 1788951882005158500 Rather than waiting for the next set_scanout()/update_dmabuf() to replace it. Reviewed-by: Akihiko Odaki 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 ecf3cbc4893c..bcde65b50349 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -418,20 +418,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 Sat Sep 26 20:00:45 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=1788951885; cv=none; d=zohomail.com; s=zohoarc; b=Ro2p73XdIeNRaIjJAwmxvKgaHJ/qQaSdPltQ4SmN1eR21EjvZz79WO/tqt5ZwV9QV30/FKhSfWi5IKZeD+Q+9XwExq4Mw3Z6tH5lVCKwL69sRY+jJjuPIFGaHLKfBaH/YeS9M9s8FRRnpRn5CHkrZkynd0/Uaz/lOjdOpuAsOCc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951885; 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=tTpKPp9bmfG57LODxp6RB5dmZ5vLEDP1G4fJc7F1tIc=; b=MaPFARgjNbObz//srd2wqjDuJf8pqeDeiqtSWLrPk4NDzkBjhqpefQes4FRlmhyKzJEuomM7PWxxiOLX1CyfrMIj5/RZQPwcXeBQ+ku9VEoWznGk+2xQpJrmZF45KQT07AvR9LZjtWIyKuOPJE1J1YHFciQK6+NzAkI8eej1Y6k= 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 1788951885053583.2434218076312; Wed, 9 Sep 2026 04:04:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G6T-0005LA-Py; Wed, 09 Sep 2026 07:04:33 -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 1x4G6S-0005F7-TN for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04: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 1x4G6R-0005If-1g for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:32 -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-370-gO2-2FzXOmCFLH7mv3sVGg-1; Wed, 09 Sep 2026 07:04:25 -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 A4DA31800752; Wed, 9 Sep 2026 11:04:23 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BE4191800473; Wed, 9 Sep 2026 11:04:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951870; 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=tTpKPp9bmfG57LODxp6RB5dmZ5vLEDP1G4fJc7F1tIc=; b=QSi11ebJgM0CxzpExmq8MtxdeQHSrpeZnKWidWKbWGGUkoaLQK3hnan63AAtF1yDaziqdc fJz9Usj4lnTjF/j9qSPxoBG/xeYqO7ImkbFW4ux3WR0ZR2y435TMngI5htNLysfb2qe3Z5 MgW7TkaiPTl6uEPUPiHJpNTHlNEKqjY= X-MC-Unique: gO2-2FzXOmCFLH7mv3sVGg-1 X-Mimecast-MFC-AGG-ID: gO2-2FzXOmCFLH7mv3sVGg_1788951863 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:20 +0400 Subject: [PATCH v3 15/24] 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: <20260909-virtio-gpu-cleanup-v3-15-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=3153; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=6B5EZCR/TOMDpLrG+wIPlLqHW5uL7luP1S9QLKLFUPM=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzzZhSp933dA+hl+r6VOt/z/987iU12/KkD1 Xd3JBIK0AKJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88wAKCRDa6OEJdZac 5eIlD/4/YS079KBlhHF6bw7bKiOEKs48XI6Msv1J52E/iEoXNea/fldfai+hsv4cO2VdVvNReob 8WCTq1R6+J9jBDXA+aQFIrIVIb9YmXdVOoZi2+EOcM34CTgz/54O4AHDAKf7Yu4F/aL7Uhnmyvh FfLFSeQ9d/pi3lYbdlRaz+M+thb173QfTLTIXoWbciEC5yGkRVDNNMt9JPdNMK3g4AjZ6pLQF5/ m6t3ltb1npg/LU4/2PbVj7ijOOZr4u7vqRfWYEwQd1FD4x0l/cX/qqIwD27XW/V2BVZI3qdqD4Q hDYJjf8mi/KKIjGqgz4+MdVdU+nRwGD0JdgAO1tshpSHJ4OQaJyeJZKOWuZVoIGj5sBG4nlKP9/ 8KuWrzkUMiDCNtwJf7USzaFem9JmCFacQdPnesjnxowmbaO8Bg69w26qykjFdf9Jqe2HshzDVWV 2ZvwPxfq3yyCARmB8Msgu1A6HAeX+oLBkZmi+yq7Y1UkskR/upqpd+EYno4tGCNYf7cTV4CANtQ Nl0Irq/2PAH41BDNAINdYZG9jNteypURijKeeOsCvWAvjfc3psTmlBtaFMnC4EFvksy8FA9hANA 57Vhfx5S6ulqbx9USlGcCYxZOYEUN66x9+0oKxplVXMob8MlGx6kzp8YmdvZUZLS2wunk6I7WpM 89f//cw9areCBlg== 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: 1788951886040158500 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. Reviewed-by: Akihiko Odaki 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 933bdbb671c0..f70b34c179f3 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 @@ -662,7 +654,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; @@ -707,12 +699,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; @@ -797,10 +783,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 Sat Sep 26 20:00:45 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=1788951890; cv=none; d=zohomail.com; s=zohoarc; b=LAeXPb0XpLw66lvmJ6TTRr39IbD/32x1+YqEmZkfv+WPRd1vL6t2MUqHD2Dl2Z8fMXDWuZEvTpxbOv+U4BvCvsxs2AccvfCsg5hIdtwPu1hBkdwIQOt2BhkU3D6V4pYhLpWmCQI6kEe+0SkY4SYjEz8nIrVhdmol+S09eTWtP2c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951890; 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=9CEkb1pbqvdSjaTl5T02aLz3SneBoJfy3quphqY3VaY=; b=IdF0Y+fQEmSoXPfFo0mFu3oznf6goelSy6dcubcJS5DpbWv+S83wnDydgtOtaX7ByOMvTa65f/JyrDVE8O0zecsXh92K5k/PUoJmSSDqCH+eqsznT0rja3jeNwIrcG1YlmIPeB17xPmNU+ZDg7p0ntw9tysg3dPp4rnl9VvOjdc= 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 1788951890758959.013219094814; Wed, 9 Sep 2026 04:04:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G6V-0005WO-7Q; Wed, 09 Sep 2026 07:04:35 -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 1x4G6S-0005Dy-OR for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:32 -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 1x4G6Q-0005Ib-V6 for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:32 -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-623-l4m3KMz6MlGQvgNrPKuxzw-1; Wed, 09 Sep 2026 07:04:28 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AD97318005A3; Wed, 9 Sep 2026 11:04:27 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7C98241B; Wed, 9 Sep 2026 11:04:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951870; 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=9CEkb1pbqvdSjaTl5T02aLz3SneBoJfy3quphqY3VaY=; b=GuIR/cT02UDZL6zw6q14Jlh4USlj4gsYdrVvq/tpjIUoKFKBBh0NlYZPSuSbc2EIdxkD3R 1RRLj0FS1pLqSvwNZbhkpkRTnbqVT1bR5fh9U8L0lMHQ107TnzpkM53ozNDyqyTOP3ZJqM +o0cP+eJw2W/VKOIo+PtcCq+azfLly8= X-MC-Unique: l4m3KMz6MlGQvgNrPKuxzw-1 X-Mimecast-MFC-AGG-ID: l4m3KMz6MlGQvgNrPKuxzw_1788951867 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:21 +0400 Subject: [PATCH v3 16/24] virtio-gpu-rutabaga: fix scanout handling MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-virtio-gpu-cleanup-v3-16-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=3051; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=Y+x8YicNAXC2XmwidfmyoGEqbosScCND9O6ybcjTOno=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzzhdEG6he42gAWlH0feGcGRS9FxPaUQz0/t fp0waJE6DaJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88wAKCRDa6OEJdZac 5cjVD/9TShIkUzGN+Qf/aufpMWN46vpsJaGtkkTtsJ7VtJvWhPiA9Xqdd81Sa83faIMMIcAPZk8 H2AZOPellCrpxlckMvEHLeGMC53sVd0TSzTaaNyfIZPZRbGtklWsaTH1l/yU/B/VAS2CiRA5lU0 8lyjx/yJjnUIgoRGqnNdA5vfrW98QmFsTIbn1fAuLZ6SSZo8tXnsRmJfDiNlv9jVx+Pg/vCUwML BrS6FJkH9SC//XY8Ip4B2YeYjQHtbkbDfRFtoLYtPNyNEl8WdvfXbv92uqdk2d6MJxR5F4PZ6Hl yZFNjbXZiKzQP3dYewqIQeCs3cy+9bIcn4tAGPrvryQcalagKyVcuZ0qA7EjXvz4M4/zhLzIjva h2gBjYXN4TWOgUmFQ/etKqmKNT4q3wKh5pZnmXf0R0YdzmX27dOxt5l50eyfR+jfmG9h2HfruMa dhXJuc5X4bmlqbaMDBcDKmVaPAskUUDsKBbvjSUYjtIq5XEpaYerWJ+hzgfSAUs725HdApWH0DG VMwOyjHnF/rC2BmteauMkviINp33PbWdZERPjhHCp+KYLc4Sd4LxQ1MM1TGesrQIgW288++MH6w 5+Zo9frono4GzgykTzWJEjUXW0vgIgg+8x8CwTlyriS3rDZoqiZ/lx6VWhrtPdgBrwmzCpddZhk dU3/QmMjeiJuOqg== 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.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: 1788951892240158500 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. Fixes: 1dcc6adbc168 ("gfxstream + rutabaga: add initial support for gfxstre= am") Reviewed-by: Akihiko Odaki 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 b8f8a2068d0b..8a82e96b7461 100644 --- a/hw/display/virtio-gpu-rutabaga.c +++ b/hw/display/virtio-gpu-rutabaga.c @@ -146,8 +146,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, @@ -251,7 +258,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; } @@ -275,7 +282,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 @@ -299,6 +312,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; @@ -332,7 +346,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 Sat Sep 26 20:00:45 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=1788951914; cv=none; d=zohomail.com; s=zohoarc; b=I4ydwdKVWtDM8TD+vCu71gSrSlyrGmyZfxB49IW5vCzzUzTuONQ+7DeaEqOtVIo9t73vOpgtp81Jdt77cJrFsRMl0C8SBzM+d9aMdQevedYEeXd5sCn1Ti3KMi1d2EjybJQm38XzOEpZMws/D/QDyo5T2eTz3CKydLBQ6vjXXcY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951914; 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=TYeXAmDf1Odc7i8PeL79UpH2Py/hNhTm0ExEtDUltCQ=; b=f5MotPdnaM3wVZmeoErJTKhesoRpl/AayUYkgX1838w8BoDvLURrGM912DGWYSCvLl5Jn15NR6nSt3++S7FQe+TxeobroAb9Vp7wir9GLrFFyIrx1JTmnw3qY9GGyqVUi/6LBEox/ween7NByECANr8ZEEXU3zZpp4j0W6ozb4k= 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 1788951914658718.7254975942352; Wed, 9 Sep 2026 04:05:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G6a-00064K-Un; Wed, 09 Sep 2026 07:04:41 -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 1x4G6Y-0005pn-Kh for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04: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 1x4G6W-0005K7-Ln for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:38 -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-640-Zrm0SNr3Oc2vL34k9CzQAA-1; Wed, 09 Sep 2026 07:04:32 -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 8BEC818007ED; Wed, 9 Sep 2026 11:04:31 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 019B01800446; Wed, 9 Sep 2026 11:04:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951876; 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=TYeXAmDf1Odc7i8PeL79UpH2Py/hNhTm0ExEtDUltCQ=; b=TrEAuyhzymgqsxpNgM00JGX7PTcyaXYd+zjrINSwP3IRhhPpZOneY2b/rpVZaJ9IYLYF9u 6GnIka5EZRhowm3RWHHLhTpPF9GZZJ37icRw/NXgev2BZXW52sE1tvh+byXmtb2UIDZrjR PlRWndC7d3ssqbSPK11VRxZxyb3wGC0= X-MC-Unique: Zrm0SNr3Oc2vL34k9CzQAA-1 X-Mimecast-MFC-AGG-ID: Zrm0SNr3Oc2vL34k9CzQAA_1788951871 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:22 +0400 Subject: [PATCH v3 17/24] virtio-gpu: drop scanout_bitmask bookkeeping MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-virtio-gpu-cleanup-v3-17-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=3592; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=7Xe5PKyYiFdYI1lfnr9DrXWRq+TC3ng9j+1LCsQI3Lo=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzz+KQcETOUEsYnG9QeQ83M9jU2pzEIvEkXm 65gfqojlG2JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88wAKCRDa6OEJdZac 5dMDD/96aqtM5cHSMAAhPZqhl5atikqFlouGTkrbU/Vfr7GgjbPca0rC+Rw60R9t28rrLG2WV/D V/Ix627mHTfDlUvEZlPrb0YpJcXgZsyx+jNjSJW8sw+O6jGYOHuNq7yxDrMvrOwPebbLdhy79yc lyuuotpVKAktk5d4wz2BXYRkVsQDwFex6pbhL5Cnes+Wb0PwwuS4etN7rBVUqKj5fPytyLr3XVz 9htMucBiaQYIVN2QzfPLguN13BTIcm5MmPPQxQLZIs+O/p1LVnkha+GiZ7D81LkNml714gJOWpv VOwHVkMUzsoV1K24B6xrdYYH9yCTlNkZ5rtFc+FKYPQoIHzFff15G2+ZdrsUpvl4fnNYs/TOiba zaqJX6IFiTF19FY8mwhGUATv9AWdOz2iEa9piAGsJZS+Gs8qnl5gvDEp4NgwnJiwQOqEVuvPgk1 ZklZfWvoz3iFjY/8FvHEyKXNQNJg7xGJxwS8AdkZfMK5DBwWHKcW9Lb7qjKFjbZaf27fL9pqwRS 5IqfKSsL3iicxsMkz/z8peZ7I+CANkazs+PONxl5UVzfWho7TqghlL0WObZNMno3OanNO5yMvl8 3tpGI9oCf+9+aMaS/vSQdcwElmBsAY6i6qP96M0SaTdnDunFT3Vi+d+y6o23mrrTwtRb9hFjPVl tCURm0UHaZ91kBA== 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: -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: 1788951916454158500 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. Reviewed-by: Akihiko Odaki 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 bcde65b50349..6e021b78b890 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -434,12 +434,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 @@ -456,11 +450,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 @@ -639,10 +631,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); @@ -667,16 +659,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; @@ -1707,7 +1692,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 c2018b41056f..071cbbb6113e 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 Sat Sep 26 20:00:45 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=1788951935; cv=none; d=zohomail.com; s=zohoarc; b=IdmVXvMqREXJoSRNZwPxJ9g80OZBGHmt4ztzgBa6AizRqTcppK3LnDApwTBtHE+0PdRFYJsuUN3zk5IaUugfhLA+USN9aT2+Ygefl+3FPewh2vVPkm8tanMSRBGFzW/4v1lleqZxo2AdYe167fe3vEHL+5zLm0MI70gpy/bJ0j8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951935; 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=khbpV+xiZresNyGTZT3mIZWPgj/akniR2wAoczGH8Xs=; b=Sl1BedAiOcvpRvxSgRTo5fSlX9Pfd7pXZNrmFebRuYg7cK7UGimIghMFz5frKMK0CJ4CTaVaRRssJrwbGqjlmYKmRbdZQcS44rdLuzfc7ijhVH1/EJfeJ1DmAcVP+6770QqdG6hlycMXUtEPBmC6aIpGfYxiSjyLRXwUGbxP31s= 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 1788951935395582.4110857274691; Wed, 9 Sep 2026 04:05:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G6e-0006De-BZ; Wed, 09 Sep 2026 07:04: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 1x4G6c-0006Ae-Ru for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04: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 1x4G6b-0005LW-9u for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:42 -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-307-MwrIkyAVMG6Jbtp5OON-5w-1; Wed, 09 Sep 2026 07:04:37 -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 3992F1954B17; Wed, 9 Sep 2026 11:04:36 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4DFFC41D; Wed, 9 Sep 2026 11:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951880; 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=khbpV+xiZresNyGTZT3mIZWPgj/akniR2wAoczGH8Xs=; b=ggnTkQO9Sc7J34scpfQXcMdaPcMjpfEZjk1LFwT4DfZStl50cRBrTNYzC57OSaOCKzDGzw WD2lEBPdZbFJnEiBSKW4Fb80LSshRpRodTkbfMWAsjWmpe4ncg3yRBmL+O0KzOAuazcpyE DK0lTHWlEOhqRXpgFQELZq9cmbUacNo= X-MC-Unique: MwrIkyAVMG6Jbtp5OON-5w-1 X-Mimecast-MFC-AGG-ID: MwrIkyAVMG6Jbtp5OON-5w_1788951876 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:23 +0400 Subject: [PATCH v3 18/24] 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: <20260909-virtio-gpu-cleanup-v3-18-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=2604; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=pgJLh95j61L6xCFJ/JYnj7bpQvTkIQF1Ao6BM4GA2P8=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzzRwGFgm6B8jSjLhUCeJ5ICtlidF3mFJqLf bpP209z2miJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88wAKCRDa6OEJdZac 5eZUD/9mrPWi0rrHUO9x8fI/uU96oQuuM/6NTGIlVftrs6rjtqPTAZNMLtOJcde0U+O2sOVmqmE 4j9ps5L+UBg5jOZgh4HVJuI+hj8jyjg2hIWEfvATy/V7oEfh8Y8p3kJK8kOTC/rHd0nkJWo+rNT ozgKQpB4S7JXd/j55jJHsbAq0L6GbWf9nDtnHqlgO4FI0xeyxG701BVhuER9MJN1ICYe8IbfgSz Pqavw7WsBcJDBxSlXp1tl3xuRYwk84TOXLoQmBpici3wpVdgvdT354UD9H/4kXCYAOBQ4UTk5+l Bny6l7gQ4kweFX9NDjEC1UPnuRKXY+wx2ykPTPnfEbKyKl0iXotV+rBzJjxEInNggcTcug0Lo6a NMXXdd9MbTVJKX94fnVYBMsKd9TkTxYkWqlObTqfxydLlrAXGfiil223aZnrZsXhST4cLlT0q/H WZXqHgEyraByks60irQooedOfTV0WjE5do/YcewB2HWugrpiWNi6Zg7YgYCv1StIygPj8xb7iqM sAmYV+Wy00iCy9BBYYV1yXKm04V0VlXjGPcrQjOORjTUOvwWXih1QsAOazZ/8LsoX2XAhoKqFGF VBptMFjrt6VVr02gf973cqoA/lGXnAiS2xtc+NnI2pASwVtF8v9cGCdsbsKPfA4S/XtXwDjS4tt ZbHep/I2ygJ+Spw== 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.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: 1788951936371158500 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. Fixes: 32db3c63ae11 ("virtio-gpu: Add virtio_gpu_set_scanout_blob") Reviewed-by: Akihiko Odaki 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 6e021b78b890..b2cba26405c5 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -704,9 +704,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))= { @@ -733,12 +735,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 @@ -748,7 +749,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 || @@ -773,6 +775,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 Sat Sep 26 20:00:45 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=1788951920; cv=none; d=zohomail.com; s=zohoarc; b=HCjXIIM0nWe+TvoHt//BazTXTBYEWHkvN9aKHKzvhZHT5ukEd6XLK3OhVszaAr2LeVr9NJO5rOSwNJfX9ASq2IJWETxTUttJ3u+KV6IY6zx9D87tVoPImaJesdGh422yzq9jS+DepcjdSgBTNXGszaDaT4pxvMeq4sArYEvkStA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951920; 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=st5ek0kTObO0ESvhhzSIcwXFA2FNe+7z8NziAK39hvo=; b=esp8il0XZS3vtQYczUOEnS13nqkrpXISG19sOJuHMAtUd4ySuUVKtAmu8MIB9Qu7NoPdpQinyi+4uxjxFL/E5ujRsjx18GpJDvET+htuiUhPeCsDdDYXQHPbl+3VhFFqGO2DmdpmYUEqyDjU2e6xmuf7SQVa9lYqGe7YvNrOfIs= 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 178895192065356.86426434425596; Wed, 9 Sep 2026 04:05:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G6k-0006Ni-JW; Wed, 09 Sep 2026 07:04:50 -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 1x4G6j-0006JM-04 for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:49 -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 1x4G6h-0005MC-8f for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:48 -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-441-yknHd8VdMviOeHr0FcEldA-1; Wed, 09 Sep 2026 07:04:41 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 63EB8195419C; Wed, 9 Sep 2026 11:04:40 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9EDB81800370; Wed, 9 Sep 2026 11:04:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951886; 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=st5ek0kTObO0ESvhhzSIcwXFA2FNe+7z8NziAK39hvo=; b=Wd9jhApORh1GrF8p5UeLi+l7r5b2scDD7B6tX+4uDrmgglID59mYIVfk/lZIHfD6nBec21 RTWUPPdj+a3VNh75sQ3whbOWhONMcfnSZilp/9X/vcrv4v92pEA+O4X+nnIgI+bP0/+SrX Wzyi9kyY25iityp1h9RN4L6bFlW6rfU= X-MC-Unique: yknHd8VdMviOeHr0FcEldA-1 X-Mimecast-MFC-AGG-ID: yknHd8VdMviOeHr0FcEldA_1788951880 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:24 +0400 Subject: [PATCH v3 19/24] 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: <20260909-virtio-gpu-cleanup-v3-19-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=2385; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=NSO9nQ7qd+66AiIBNWyR/6HEioFSD0pajYBA2cH3wnA=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzzdpKfhyH5rnOC004Tmlet+qbIVlknKaJWb 6spMO/UO96JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88wAKCRDa6OEJdZac 5YdXEACWgkU14Eyt51jGy9y4YtUWi0pQb1yiwYF757g2Q2uwnzSlHPEuedNUIQgWlaKSOCiDNLx 6CQGsZigzj1w60g/UTmGdxkPmdqRXJhFjVegZ/Q7kg4P29YACEhH387xqakX9fn4Dn/lxQAsDlt vtBBmYem55UYH8aMgK0z9H98mzVi0y84UdrOlObsk4K4TpxNbopSJr/ArBY5NcyffbQCueY2QuF SAyg8hrpyee2F3bb88bpIB5CUSLqQi/klIt5O0tjAzkOKTp8rQknUqjR3IIRLSH4ZPYanDD0RFA NUajHp1jR2eF2MYUCgb+YPqqZGbmrKuYUz40S/7L98rI+a5BHiL3e+b+j82zlH8paamm/GqP27G 926/QY/NP7M4zsJdtMFWYszSwaxaA+p/ZYmNak6GtoMI6sSAuHdg59t9+mngstTus9iP3ruw6hy Cgq0H87mp3Q7mtImIbsQSZ+44bZIbX/BB+9q2pNGqHVHlBmZFCBS9JyNza+tA3z0Mjgvjv5jZJe jbT3kPERUjRHi2EftWoPysE7ytR+wq79PZ4lc+djYilyXt8YJvoPjoj8bRjvoTgyyP540AVHRTq n+yrnETCG20Rk1fZsivShg4Dowdfa5uwzXbuEGTIgCI56le3u0yUbIIDeO9f17s8zcPBQGzd+sg Mf1KavlNuJwWCHw== 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: 1788951922249158500 Release the scanout dmabuf before installing the texture. A full virtio_gpu_disable_scanout() is not used because the scanout is reassigned immediately afterwards. Fixes: 7c092f17ccee ("virtio-gpu: Handle resource blob commands") Reviewed-by: Akihiko Odaki 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 7f1d1e0c3276..79d4c0b569fb 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -605,6 +605,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 b2cba26405c5..f9083e9577c3 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -418,7 +418,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 071cbbb6113e..2f18d839ccd3 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -371,6 +371,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 Sat Sep 26 20:00:45 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=1788951935; cv=none; d=zohomail.com; s=zohoarc; b=MDKoLrA937b+DLNIVlody/Iu434K+KPtQYoWZBlmtLSKHYEagZPYPv/tWAlaJbH5c5KjjsD6kFZONVv3qYfi7BgnRjZo1XRo2VPHri+iZtd18kKECHhLEVJzaDhPB8m9kzLM5iOdWw/7Ld37QxBWMU/iFfLljq1iYuJrwDjuFnU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951935; 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=dGh+L/jlT7Mb71Qal2ca84zs9ws1DPguDNuiiR+Ayw0=; b=hDMNz962tSnejOfMroNAWQDIuJ+9y4trPvz89t/b19QVS5tHLe/ZiwI1tAuEp2LSrVPfiHUGDhXCWLJfo0eFgLYZOTCIGoQp9uAzfhBUkoJIWUayJhzIwtOr+TNLxchef/B2jPJymmt1t7vMdtSpCaCvkAqm9480sTZ4XYbKpgg= 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 1788951935109275.52742291758807; Wed, 9 Sep 2026 04:05:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G6m-0006Vv-TO; Wed, 09 Sep 2026 07:04:52 -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 1x4G6k-0006O3-T3 for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:50 -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 1x4G6j-0005MN-7I for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:50 -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-403-jKm2KQ0rNHqaRwW8JOflng-1; Wed, 09 Sep 2026 07:04:45 -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 72BAA1800601; Wed, 9 Sep 2026 11:04:44 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 12BF41955F19; Wed, 9 Sep 2026 11:04:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951888; 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=dGh+L/jlT7Mb71Qal2ca84zs9ws1DPguDNuiiR+Ayw0=; b=XAapZNPsRth3YJA8uWrlk1B/WAfubK4n9CYvxYDOIDjT6B177FI2NTW8HgP/v70mnHHreh YW1cPXVcO68FtooHlRtfgCcr9Y9peZ7nyvNQCJx3uDYqvk9mE69iTdJ6QFsBCdMtHtYBFX LUgs5XINpIIedEoSjy+y58wfBTtcY1U= X-MC-Unique: jKm2KQ0rNHqaRwW8JOflng-1 X-Mimecast-MFC-AGG-ID: jKm2KQ0rNHqaRwW8JOflng_1788951884 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:25 +0400 Subject: [PATCH v3 20/24] virtio-gpu: consolidate disabling scanout MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-virtio-gpu-cleanup-v3-20-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=2753; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=fjAk7lTxT9/Ns71Yeyz4xpsvnqlRMTTqZ/qL+nEZtiQ=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzzSWF4ThxxPolPX1VBdV5c6I5epZYqlL09y fYWGu581KCJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88wAKCRDa6OEJdZac 5dP+D/9hop1cU1BcG7lQyuRRZEPIRofrAGQMgxnByM8e+0dQArZAASlhIm7ipgBzQm2t0CFFfKq 0v50m+tnDK02hmxLC1hvD6tgbJ0JdeZZGHrmxeDT+dfIPrEDDv+XehS9xLpKSashw4+l8Brh4By qm9uXmWEU4Typm1n3Vj1ZyzBQaDzeutyab9bEXZFrZ0MvX1fE1hUGxu/IATCgV8HKwavWIKqKsF Oz11EOJnRxpbjPtc9YfpkymcL67kfwpLJCkeBQd0mM0Dtsymn4tftEvT8TEfHVw5hfLB6pm6OQF pwznmRe3/K9Gg1xL8Ih+gek5tbKacNswt8XujhAJegJnx3DWBgoMrh+PJXtj4F2gyrh54MvcGYY AIvqdMNtxOUwN6gHj0J5ry1VvIR4uKIIil1vRJ7Svf0Wp14r4Dv1kYhXCz1ofUZlK3nIwzFqLM0 eJe116iWI13eNDedNT9+EcOU5hZFD7txqo3L4YphB4HVqVFvWiv4tIDbZFOxhIfRZoyNCQUxB7D u52RA7wHtDy/KQeB2oCuAy2kbTKRRf1XorB3gVEhlhc5upp2+pT+2jdnc/Kdgrl240zdCIJuxyt JAHUP0bR3sRhepqQCRyCHdJfX59F0TAzrq2dH/rw0eIgLiOBaQNwjXYsscq0g0IahLrorQjSVPQ hcdW/p2LX7ArW/Q== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 127.0.0.2 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: 1788951936350158500 Use the common virtio_gpu_disable_scanout() to reset the scanout state, including GL state if any. Fixes: 7c092f17ccee ("virtio-gpu: Handle resource blob commands") Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: earlier. The framebuffer is created in the virgl context,=20 --- hw/display/virtio-gpu-rutabaga.c | 4 +--- hw/display/virtio-gpu-virgl.c | 6 ++---- hw/display/virtio-gpu.c | 6 ++++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutab= aga.c index 8a82e96b7461..8697dd6936ba 100644 --- a/hw/display/virtio-gpu-rutabaga.c +++ b/hw/display/virtio-gpu-rutabaga.c @@ -312,9 +312,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 79d4c0b569fb..87d1fc3d5f65 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -618,8 +618,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; } @@ -1426,8 +1425,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 f9083e9577c3..dc5b2da9a43f 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -435,8 +435,10 @@ 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); + } + 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 Sat Sep 26 20:00:45 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=1788951940; cv=none; d=zohomail.com; s=zohoarc; b=SYKsM+Z06Bj+0xvfowyn4VVp/Qigs3c3IItwYhkbTI2IqdJy3QYXkfP4WSHyqA1RbayfJxZROTO/JKeDsd36ATSvc1bIwM8ZVJrGVa8lYRXUceyLEFW0jS+ZhjZKT06GYIU0jN/rF3L2H3D0IU4XsI5RBDpn+S0MjJ/XvaG/YQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951940; 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=1QzWw/3YpuNlpbbtK3De1nZgXPTUKbTQhhI4hImd84U=; b=j16WMTDcEFpxQh/Ryf6MGWUdXyJBds2jQqFsPHcOEgYvE59ZNTD/G06boaF7C39Ka8Jx/BmAO07Yc2NdxTXxaOOTrdgxKx07jTQ+IPVbmLyanJYo7WhuiSg+WZHNbc7VSxNMUVhuNdUKr5bBbg+c9KddsdFKKkoklNf5uxnZ5S0= 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 1788951940132957.9294933868755; Wed, 9 Sep 2026 04:05:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G76-0007LQ-SU; Wed, 09 Sep 2026 07:05: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 1x4G6o-0006iU-RL for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04: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 1x4G6m-0005NL-ES for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:53 -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-295-KG6ZqEUiOvmlDEKIz5ZAsw-1; Wed, 09 Sep 2026 07:04:48 -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 99D9118005BA; Wed, 9 Sep 2026 11:04:47 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CB11E1955F19; Wed, 9 Sep 2026 11:04:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951891; 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=1QzWw/3YpuNlpbbtK3De1nZgXPTUKbTQhhI4hImd84U=; b=bnKrbzJxjopSJEUG+Ccj/j75JDhcv94EgynhJgf/mDd4PGoYWm0cWjRZfTprPyg07XO8ZG 5EJFwZj6oRU0dNE25zacZ5IKIw9pN47XCt7waaP7dkhQkHgYmhpHnEm+LX8NOsiWMYjRjC 46blsErXx5GhVIVecyDm8mHc3DOp+N4= X-MC-Unique: KG6ZqEUiOvmlDEKIz5ZAsw-1 X-Mimecast-MFC-AGG-ID: KG6ZqEUiOvmlDEKIz5ZAsw_1788951887 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:26 +0400 Subject: [PATCH v3 21/24] virtio-gpu: minor refactoring MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-virtio-gpu-cleanup-v3-21-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=4171; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=36qNtf5VJCj4Rho3xGqwfp3/DDQJNjPDldw5TS9Jilw=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzzqatNIWCuYCfv6puHdF1X6tv4zO/LwV2/J EUPKdRlkOmJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88wAKCRDa6OEJdZac 5Q5WEACPq0jzrwpTboBX6PyCaQ9Zk+JjeoptNL1gttG/ytOGAG2YHs0a1798qPEJmrwq4YN8z/Z pBlLoJhqq6kitO7ocLO999M1LHOnm0jbu2tSgYDqqIuNns3LjZ57817oZ1J2WHOtc5px+VUXQ9M pelRgxslyYcJQV8kkiJfmHX8wvC6g0jAzQr4BdQVEhBNVKV/AwRZxkPJ5C03H5TGqj08DYyhDB5 uUmMFWVqSXd34lxU6+VD4fnYWzvgjUddZj41ugIDQMMn26KMlBSA26AkOO7JClVpV1UCRqmKkqk DclD3ezL4mSdMRodxxQ2JeNkgUfPSeyD1AX3w2tTcjy6ZI53UJEg3otp42EyaabpAOaJ+ksTiMq KWSnDI9Ev62IwvS7v3kin2jmTKER9JinkVtTKKm7xHoj1GDedM9OHTTGICd79U85bhkWjOCTfPM 8ybsUyIX1BZfUQelIaDCWuhxbVFzxCthJcsEmMHUV4R0mUbLAvuITO7QF3QjjUdyOggB1L4PpBZ Ii8DWOZOc3F0B5RXM63264kKyTHa91jVgjlpecwGVaOKUA88djWzU38Qc49MgH0MlOlpNQKyHa2 F2Le7NPZymBb4b00Qa5eztUuWZ+TyFHtcwMQkHPS35K9fmAc9BTHeOAyfhFymULQaaaaZHGVJZs F/e2LuPKw77wgKQ== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 127.0.0.2 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: 1788951940425158500 Move disable_scanout() branch earlier, return early. (scanout->resource_id is cleared there) Reviewed-by: Akihiko Odaki Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-virgl.c | 71 ++++++++++++++++++++++-----------------= ---- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 87d1fc3d5f65..118419171ff0 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -565,6 +565,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); @@ -579,47 +581,46 @@ 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)); - ret =3D virgl_renderer_resource_get_info_ext(ss.resource_id, &ext); - info =3D ext.base; - d3d_tex2d =3D ext.d3d_tex2d; + struct virgl_renderer_resource_info_ext ext; + memset(&ext, 0, sizeof(ext)); + ret =3D virgl_renderer_resource_get_info_ext(ss.resource_id, &ext); + info =3D ext.base; + d3d_tex2d =3D ext.d3d_tex2d; #else - memset(&info, 0, sizeof(info)); - ret =3D virgl_renderer_resource_get_info(ss.resource_id, &info); + 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; - } =20 - 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 Sat Sep 26 20:00:45 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=1788951932; cv=none; d=zohomail.com; s=zohoarc; b=jDHr5qFtWIDZyEpRkrEqaEBKyyjt9rCU94Xj+DDh29EKD3aiQMnQqbQy0hO240j9SB1M6mMAkDag5wfBbleNyHFlzFInwcFMDv3nLv/NpA1jIoH/TTcs+qSbt1LGI55J0L6H8px/WHDU2xUZkBD5EtFURGuG3GIbAPPCncM0jXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951932; 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=Ny18XTZWgarQi6p9F7g/3cJBjiECYvkOPPCvdP9Tmko=; b=F3KzxP0GoCQLJzb/Nvn7/t7zihQh5CElcjRKgnKM0jiVBe1UVeeN2U/phUPRaxG4yTtuha7Vk2dhKbozrG/AoinqZ8DsLiehq9/fFKxEBbnSe1z94IPOPwUbAuWymOevh3rU7h58ShAr2yOhDSkd2IyRudBB/IWJteIS6xKeHJ0= 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 1788951932494709.0536720447333; Wed, 9 Sep 2026 04:05:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G78-0007Rz-Iw; Wed, 09 Sep 2026 07:05:14 -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 1x4G6q-0006k8-LH for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04: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 1x4G6o-0005NZ-JC for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:04:55 -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-34-fP5dvy8yMnGvbj8v9EXyDA-1; Wed, 09 Sep 2026 07:04:52 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 67B311954209; Wed, 9 Sep 2026 11:04:51 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 34713426; Wed, 9 Sep 2026 11:04:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951893; 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=Ny18XTZWgarQi6p9F7g/3cJBjiECYvkOPPCvdP9Tmko=; b=PFkIrKHlC8VcKOBMfmfrlUna6QXqGu0yX6R7A6n2RpFu4mmiCLeHL/ytyYr0/obz7oKNID CHBX511YgF7hVK9OC/6CR4rLP6INUxXvXbZ4grEqTegR7J8SHTITgK6rRz2UeBrdwIB9iW dQDtDFGoDX5kQL3Yn6WFAASPRw3fBPU= X-MC-Unique: fP5dvy8yMnGvbj8v9EXyDA-1 X-Mimecast-MFC-AGG-ID: fP5dvy8yMnGvbj8v9EXyDA_1788951891 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:27 +0400 Subject: [PATCH v3 22/24] 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: <20260909-virtio-gpu-cleanup-v3-22-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=1424; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=V+rm02I3r7+lVzdWZMkpzlQV+VEE8f+eWV1SGOMC300=; b=kA0DAAoB2ujhCXWWnOUByyZiAGqhPPOgbbsP+NPXvCfNMXO2MgS8N2ayG9Er+7pwRzdtmfAZo okCMwQAAQoAHRYhBIepvZM/h8YG0nb2Ldro4Ql1lpzlBQJqoTzzAAoJENro4Ql1lpzl6ocQAIQu 78mW0k2ImfMtECoUadoaso9Pd41QjvFSfKVm7r2fPvv/+6I60L5/YreQjweF++bPuR471Tw6Dil 6vAN28eXWQ12WYwFeH1m1RSDYXCsvLxcvz2FG3M/a+wD59Hjz6dxThF2mKMa6+iZJ9djbEttbTg 7y/+2/NXqMEoFXgE83gTrfg5oZzPmrJYj5ADRg8nS5pDMcsBFklJtfBE3Vw6UxFoLo2FMkMckGa YKFlj3FxZHZDciDTrZ197K2WNgozQfl3cISayhgeJ0VkG+Q77L25GIirqVTs71yB4B5FXoaqyrC DXCCj+/XP9X7t8sBuHPaxwrJMeO/pT3pvf8aymrg4P5i2/Jnx5pPYPE7Le+kR31Q7QX8tqy/8uX UNKKZ8CQBQUQ1ft9rlylTeWQ4mZrix7B8FTc7Zmlc7clC/FlRZsg5et3f/pCxbdxejuylyQGG6c F6tH/V7ROUI9MRKODG0R2KqkGH8NK+FZIMdANjIV84azmE4EBbxrKhhW/MNvRwNokDZ0cDR5VqB iQ7hN0gg1yeo120WlkukxnIoA/AJP0RDbI84XZx7c00vpnp1pecAAfYJKA4JJtN9+FVBOLjFine jgnh9El6KXabibHOs35jtAKhElwF4QekLggCZrccvB8ZdTQqWaRs56OhDIKw2R2sBa0kgLvt8Ji WOU0K 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: 1788951934342158500 Disable scanouts referencing a resource being unreferenced. The scanout disable callbacks may change the current GL context, so restore the renderer context before detaching and unreferencing the resource. Reviewed-by: Akihiko Odaki Fixes: 9d9e152136bd ("virtio-gpu: add 3d mode and virgl rendering support.") Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-virgl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 118419171ff0..cf624761610a 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -431,6 +431,7 @@ virtio_gpu_virgl_resource_unref(VirtIOGPU *g, { struct iovec *res_iovs =3D NULL; int num_iovs =3D 0; + int i; #if VIRGL_VERSION_MAJOR >=3D 1 int ret; =20 @@ -443,6 +444,13 @@ 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_force_ctx_0(); virgl_renderer_resource_detach_iov(res->base.resource_id, &res_iovs, &num_iovs); --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:00:45 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=1788951937; cv=none; d=zohomail.com; s=zohoarc; b=SoujRpy8KKWr6XJqQalSx2g3LYJ9KCFZ4nVniaz37zIwRmpc3ifb83p6YmnlFYy8s6/XNCFcWieD7y5hfRy1ePaLK0V48Ie/+ifEjoNyt48DDUD7mvjxqMmIgN5yfpqeiW2RveK7c38aqkKcy1cQ7X9rG8oeX6J3ophUK+YzPvI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951937; 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=EI6Q6kP08E6KWYuu4ZM6QP4gQmBboshB5ItlxzoczRs=; b=a19YatcQoYY6+NXxsf+i7o0AYnuGyxn8fGAas2Xlk7UKrpJ4F5w/UX2OGW8oLaPVlKnvufSHeeMOpoL6CbHoiahWo3TvQZSOCt/50hl1eM4WODiAbXX0VPnT4RMFiwDk+6A/cGFl9gWUxQsjP8UkEfJ8aidSL/hYmMwZacfOxEs= 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 1788951937800605.8565901840597; Wed, 9 Sep 2026 04:05:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G75-0007A3-EM; Wed, 09 Sep 2026 07:05: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 1x4G6v-0006ys-I5 for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:05:03 -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 1x4G6t-0005PB-Jr for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:05: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-561-VhSzLt1BNkig5XJnkczOQQ-1; Wed, 09 Sep 2026 07:04:55 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 99EA0180058A; Wed, 9 Sep 2026 11:04:54 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CD52A41B; Wed, 9 Sep 2026 11:04:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951899; 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=EI6Q6kP08E6KWYuu4ZM6QP4gQmBboshB5ItlxzoczRs=; b=MFKYgm2Ig0uCcxnf2M+DH+9TIbnkX9p2oaRRC0Br7eoftDiAl0tccMEhzExyEhPvNZhY7c y4hGDo1wyrNfzU8+RIs+xSrNRu+xf9nLzfuZSwqekT5cLirlMBjBlSg2/tcn/2eXq0Id+a R3GMtGz44kwM2B2cWH5OkpD33ZhBxhg= X-MC-Unique: VhSzLt1BNkig5XJnkczOQQ-1 X-Mimecast-MFC-AGG-ID: VhSzLt1BNkig5XJnkczOQQ_1788951894 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:28 +0400 Subject: [PATCH v3 23/24] virtio-gpu: extract virtio_gpu_disable_scanout_for_resource helper MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-virtio-gpu-cleanup-v3-23-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=4697; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=Q5S8IS9e1gbpCRM7oO2tMg0ySKbDiw+oSBRzVfR9zT4=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzzyqz/1rgiqP/VY+Pd2kjVNIGtLyh7mVnvS c1VLb3A/d+JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88wAKCRDa6OEJdZac 5fDlEACSEJOKkdwriHYMIgmap52zx3Cv3FFpYjAj7KKV5DJ2dCbhWVl++it7oI+y9hw4/LIsbIb J8vx8LtgUv9wnUn4ihuXRGDtAeu8xV7TS91Qj7+JN/jIcSWlEivTrdau8WoiCxzV5QUfid6Qvd+ Y45VwrTJLjZDWxRwM7/hpXj/mFeKTqAehKEwZjCY0HObraThWScpoDy0fvcspblpw2IXa5A+g1F kVTXWNud3HWOXYjAJ9EEiHLdE2rGyql9oSbgtQ/lxrSbl0nwBgHUVqRX8qeEE/W1bqeNiFdj43K PM6/Yb5YUWqH3Lg1I+agluGoiIxy8QKtYegC34eJ52WOPKNmvNSWEhBKRFekZ1SZ4d7h79KtzFi JgK3Ux98qDZEnvoZ8s6astEahZoAv1KWTf+2ZcYe6ZjYRBypuL5bW+3OilAZmmpFKi8OC5okeTt rZP4hz86gyENFoMuc+K4S+t698wE3jm0UH6ENmOt8DnW0w9C+4mwB7UCdujAsUdcF/ypxeQ36bV 6Pcu5c+C5ukcYuis2NGd6ie10TR1JTmK0On1kGhpMHOS3Zd+TjHGEvqKR/GUclg8wd+9vkGV/va Kv0ZbLhMrO6sWVDYY9ceVqZja7/77fT0cBtc3IscE7qkfQol6/S1Jh7ywNhUKCj3ObjVtJ8nks8 9QquTRpwuthwaow== 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.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: 1788951938389158500 The same loop iterating scanouts and disabling those matching a given resource_id was duplicated across four call sites in three backends. Factor it into a shared helper. Reviewed-by: Akihiko Odaki Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-rutabaga.c | 7 +------ hw/display/virtio-gpu-virgl.c | 7 +------ hw/display/virtio-gpu.c | 26 ++++++++++++-------------- include/hw/virtio/virtio-gpu.h | 2 ++ 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutab= aga.c index 8697dd6936ba..3aafa4dc66cd 100644 --- a/hw/display/virtio-gpu-rutabaga.c +++ b/hw/display/virtio-gpu-rutabaga.c @@ -146,14 +146,9 @@ 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); - } - } + virtio_gpu_disable_scanout_for_resource(g, res->resource_id); =20 result =3D rutabaga_resource_unref(vr->rutabaga, res->resource_id); if (result) { diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index cf624761610a..248aaf1a7149 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -431,7 +431,6 @@ 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 @@ -444,11 +443,7 @@ 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); - } - } + virtio_gpu_disable_scanout_for_resource(g, res->base.resource_id); =20 virgl_renderer_force_ctx_0(); virgl_renderer_resource_detach_iov(res->base.resource_id, diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index dc5b2da9a43f..7a6eca944310 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -446,17 +446,21 @@ void virtio_gpu_disable_scanout(VirtIOGPU *g, int sca= nout_id) scanout->height =3D 0; } =20 +void virtio_gpu_disable_scanout_for_resource(VirtIOGPU *g, + uint32_t resource_id) +{ + for (int i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { + if (g->parent_obj.scanout[i].resource_id =3D=3D resource_id) { + virtio_gpu_disable_scanout(g, i); + } + } +} + static void virtio_gpu_resource_destroy(VirtIOGPU *g, struct virtio_gpu_simple_resource = *res, Error **errp) { - int 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); - } - } + virtio_gpu_disable_scanout_for_resource(g, res->resource_id); =20 qemu_pixman_image_unref(res->image); virtio_gpu_cleanup_mapping(g, res); @@ -1064,13 +1068,7 @@ 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_disable_scanout_for_resource(g, res->resource_id); } =20 virtio_gpu_cleanup_mapping_iov(g, res->iov, res->iov_cnt); diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 2f18d839ccd3..631dfc63a4d4 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -404,6 +404,8 @@ void virtio_gpu_update_scanout(VirtIOGPU *g, struct virtio_gpu_framebuffer *fb, struct virtio_gpu_rect *r); void virtio_gpu_disable_scanout(VirtIOGPU *g, int scanout_id); +void virtio_gpu_disable_scanout_for_resource(VirtIOGPU *g, + uint32_t resource_id); =20 /* virtio-gpu-3d.c */ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:00:45 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=1788951941; cv=none; d=zohomail.com; s=zohoarc; b=ce/XwYZ6CEI4Yv1eC1WkjTYdBjNAx2gj91Eo5za/plR1YzeYZzbcJgytgjp4Z6aNx23Te2paeUQ2vUC6w7KR2k56PjM6HW0f2HZHfET7ef+Zv1PB5ZduJNwDz9UV+08UsJtkioqNz4ebpn+LM53dvUfuhCPHBmVSE4Q6Ybg4bc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788951941; 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=/Wj5VzWeDqCex6YztU5VwVvg7TaKkgsfcJttpxYa4aU=; b=E6/1GDNniCIUd7wULw+Kxh+psHO0I3QI2nOqgpuJCtcwF/zYnWCO/jIBbMLUSDgbwQQmlAFprhsGLmVuGDe2/MX+vfBDCl1r9iaYHAeE+JuUzyVe1dy11yKrcp9qO8DCQuBQjw/R0Mzcqwjn/jlJm/yIM/BSmYmxeW5CkiPdrlE= 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 1788951941383679.304482509274; Wed, 9 Sep 2026 04:05:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4G75-0007FH-UP; Wed, 09 Sep 2026 07:05: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 1x4G6x-0006z0-2B for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:05:03 -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 1x4G6v-0005PJ-MO for qemu-devel@nongnu.org; Wed, 09 Sep 2026 07:05:02 -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-538-62w4L1z-OI-J3Kd_XRdXZg-1; Wed, 09 Sep 2026 07:04:59 -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 B00AC195608E; Wed, 9 Sep 2026 11:04:58 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5EFD11956088; Wed, 9 Sep 2026 11:04:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788951901; 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=/Wj5VzWeDqCex6YztU5VwVvg7TaKkgsfcJttpxYa4aU=; b=DDWuu+By5vceDIJdzhh2Vw6mm5nzE+QsbdmX2SgEQfseiaq3yspZ4bvlkhMRIT0/jOWksG BHib3x1D78bEUrVNHha9WrCqO/p1hiKh9u+IRo1oAhgtq/Br2Wljm98wU943T0lFbw5iCj VFoClKBDTNZSflI57oJQWCqX6TvArL4= X-MC-Unique: 62w4L1z-OI-J3Kd_XRdXZg-1 X-Mimecast-MFC-AGG-ID: 62w4L1z-OI-J3Kd_XRdXZg_1788951898 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Wed, 09 Sep 2026 15:03:29 +0400 Subject: [PATCH v3 24/24] contrib/vhost-user-gpu: disable scanouts on resource unref MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260909-virtio-gpu-cleanup-v3-24-99266590e79d@redhat.com> References: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@redhat.com> In-Reply-To: <20260909-virtio-gpu-cleanup-v3-0-99266590e79d@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=1543; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=iZ+oUugkx5oY5Po2y4/QVsUJmAP+CsizW5ruoANWJxA=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqoTzzjbbK2bgu+rUYVeCOeDUWKbJKGzRkwiWJt aYiCQwIv6KJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqE88wAKCRDa6OEJdZac 5Ro+D/4xLm8Wpq/vKiTGvv6cud627PJz+G1Ql6Vnl+BWvPqU+mPlPdiD0QnRFvx7+tEFEaZnSTr lxkLQiHNg5OTK0eklQtNJmDzYNZIx0TK20aSKvUqH4h1/ltrjRFresbAEge6/uEWdwg6uiB0DUm /xlavT04YIXN8bh+A9VPfrkHuwk4HZD6cxoTFsG/PbB7m5V3Vgf0TBKRcBUMnJ0j/J7QP3+EebE vJaVNVwNyiuIfKmn40CIasWk7+XnoLICwJKlcFeL+gzrFOEOwUhdBCTG5V27eZ2jr0jKsoMNVVC ojRRdsg3uL2RuaINHkq74XA59qYgwZeg9dECzt9tJKOWfbTDQlxfbWUaiv4DsBo+q7ise5EfQ43 wzZIoo2ZtXpvQB6GxsXLhb8PFh1lnxv24miTTkO/BVjT9fHU4xbMCAa87pxRfflPBcUzNwsvQyP 0jhHTjgMOGVgGqjcUnwD+dKCnWaQQobn3x0oHlEIkQxg2nqzQ1xlqboXYCKD71v/iQ2iV710BhQ kNXzLqomK4T9pckkN4rQvS91Cr8Gfi3px+ui1/TL7DCtEqged5uRW3UGrY0wgRfoVwvBZYq9NXi 9DnXV0pvcm4JFU0TLEyzxZpEuA+nGJhX03n6W+zOdAljWYkWKFOxfMcpn/kH2gegOjDExH8zH70 og7RjVDko9E4QxQ== 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.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: 1788951942393158500 virgl_cmd_resource_unref() destroys the virgl renderer resource without first disabling any scanouts that reference it. The QEMU frontend then holds a stale DMA-BUF until another DMABUF_SCANOUT message arrives. Send a DMABUF_SCANOUT disable message (fd=3D-1) for each affected scanout before destroying the resource. Reviewed-by: Akihiko Odaki Fixes: d52c454aadcd ("contrib: add vhost-user-gpu") Signed-off-by: Marc-Andr=C3=A9 Lureau --- contrib/vhost-user-gpu/virgl.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/contrib/vhost-user-gpu/virgl.c b/contrib/vhost-user-gpu/virgl.c index 20bae57d0fe4..5a5f9f14c80c 100644 --- a/contrib/vhost-user-gpu/virgl.c +++ b/contrib/vhost-user-gpu/virgl.c @@ -113,6 +113,18 @@ virgl_cmd_resource_unref(VuGpu *g, =20 VUGPU_FILL_CMD(unref); =20 + for (int i =3D 0; i < VIRTIO_GPU_MAX_SCANOUTS; i++) { + if (g->scanout[i].resource_id =3D=3D unref.resource_id) { + VhostUserGpuMsg msg =3D { + .request =3D VHOST_USER_GPU_DMABUF_SCANOUT, + .size =3D sizeof(VhostUserGpuDMABUFScanout), + .payload.dmabuf_scanout.scanout_id =3D i, + }; + vg_send_msg(g, &msg, -1); + g->scanout[i].resource_id =3D 0; + } + } + virgl_renderer_resource_detach_iov(unref.resource_id, &res_iovs, &num_iovs); --=20 2.55.0.543.g5ebe2ebe4ea8