From nobody Sat Sep 26 20:00:48 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=1789028354; cv=none; d=zohomail.com; s=zohoarc; b=TOhUtSMp/3jVY7ZKagsyRK2w8BOeXIMjTj0Pr2G7wiNMOdtplaNdrR7V7o+mo6AMBjYN6Owjvp5fCYVL5Ax7WFyn1IL4sppUqxG2q4YNO0pO58Y3cplqMYUHSW6/wCD6nOfP3xZxjTT1Q5dk0F+5Rzwuf7dk0zPFggFDZnWy73o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028354; 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=ag37QXQ7OJqVFDOa5d+RJPnyJhmlBB36zkI16si0miooD74s6O1xUVGjT18QCmKDHi/UZcHE4VBM2Rzcvk0a8zPkePQLJ8MIXekRGiQgBhycVA+cnkvqxA7ikGp/TaMyj/7DzoHdAXpjZdnK94R7fXq89rk2int4Aq9sGlkW9S4= 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 1789028354411822.9478331159735; Thu, 10 Sep 2026 01:19:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4Zyt-0003GQ-7s; Thu, 10 Sep 2026 04:18:03 -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 1x4Zys-0003G4-Dq for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:02 -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 1x4Zyq-0004sG-Nl for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:02 -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-113-OgotuSlTNJWyO4fDIlCwvQ-1; Thu, 10 Sep 2026 04:17:55 -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 C75FA1800589; Thu, 10 Sep 2026 08:17:53 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 398D41956040; Thu, 10 Sep 2026 08:17:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028279; 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=SpVrm3JTSF6LRlzBdYc+iOzJBHzxVlyCeYp/9DgWn27pJxImLM5gArbTzQl0HlGgsSxQq5 1babzFUP8D/s/nvA/BmbgDbYaTuaZWBc4a1ZV15jlcoMwynbPkf/MlO8pd/3K8Zk9IJgtS 2IK5h4OHZChaKmvTB+k2IJDdRB8oK74= X-MC-Unique: OgotuSlTNJWyO4fDIlCwvQ-1 X-Mimecast-MFC-AGG-ID: OgotuSlTNJWyO4fDIlCwvQ_1789028274 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:29 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-1-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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=owEBbAKT/ZANAwAKAdro4Ql1lpzlAcsmYgBqomencp3xL2aGqfWQQIPF57D+hYLP+97hcxEBU mv4b159MBGJAjIEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnpwAKCRDa6OEJdZac 5b1gD/jRpAJJIuBTofW5lddvZf/DSA1rf3im5Qjl39HZ6pM3scDnI6CRQfl8H6W61YUYoEJe5uI 6wr9ucK+E7l9a3BPBx9lnf1OA1ghtUmkqzSn5LXt6LkLvtkX/T4sSWuP2ip/E2b492oQqLB6Eh7 lHFvgezTWVcRTdT7p3I7egHqataYkfHpeKlvCGaaJBHtrimTsNHToS/BrsMFEhvg9D+ynBgsCpQ Oc9n7WT6JUkPKBSDt8sntSkeH7dwexLPQNoYrhaNFG0hREU6qBed1hosgnPv2GlkvYdbna0Zfml Sr4AmT5aTkt+1qNizlTKNSv3BEVEtaQd971m80SvzS6fvdYE/q7D5Iv02OlpE/ufnW0Ema/Y6jy fY3V+RMVmbsC+n/c1c8M2FTDPgz49ZeZJSWd6IeWtKvowHNNawlMTo+TOQZALETSozFZZ59Nod6 YSXxYe83R2TT5Yfb04tOWkmQ76SqxNfQq6t2lDfhMKZoJ8gjJ/7LmMVE0t2DVbVuQNpp9eV2wkn KOQ2BAzA2aXpxs1+Oy1+QT1HeguSIt1RrXVtbaHxKBmw4Oz4iWdlz3GzJceE+5SNSdai2B2TXr2 B3KiaoiSDwb1v1y3J4xR9sleHXo8PgZrDF1+mAx4g5bb1KCn/r/Xsk7T3SrCiUP8T21pwudvPMn nrgu4jQx1DsNO X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1789028356155158500 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:48 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=1789028316; cv=none; d=zohomail.com; s=zohoarc; b=LVbqwrEX+xXQ65slfScqTofMGoxqGdgcyMx/AftSyoTvyYRlFdBwow7ZmnBc57/AllOeTDx8fTYulCs56SeAOHRWhCKfWJ+ckyJhldIzhATaTHZeqql3CrASWtbK6Dxu4VRPF9BlBfEjh8HpPyqT9sOO0QBKeGG3tKEgokg8mX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028316; 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=TikkYz8c3/fNENa6pL9yhbMSpzGUiYvvtS6AgjEfV9k=; b=J/oE31STeoyTwYrxxy8NN+xZ5UwON+X6yv6T285ILzsbJAHaVt7rVT18gAnYunWc6OM8XeSgV8eSej+K69DpzBqfwd0eD5xxReXCCxevT3EF7wO0qQzfZGqcciJC9z1asQKtI7q3vtHmbMEKeN93MEC/wFKiY2utZcUn4D33Ln4= 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 1789028316849551.7161643947821; Thu, 10 Sep 2026 01:18:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4Zyu-0003Ga-Kt; Thu, 10 Sep 2026 04:18:04 -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 1x4Zyt-0003GS-Pa for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18: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 1x4Zys-0004sK-2n for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:03 -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-644-wP3r31ByMMKTrUigo3GhkA-1; Thu, 10 Sep 2026 04:17:59 -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 1240219560BB; Thu, 10 Sep 2026 08:17:58 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5DFA31800351; Thu, 10 Sep 2026 08:17:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028281; 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=TikkYz8c3/fNENa6pL9yhbMSpzGUiYvvtS6AgjEfV9k=; b=iLO6UijDC6biPc2uaYlzOL7LgZky8fF38GF+DRZLtIwHCnVe8M/GdChDEOikamd4kLQpf8 DzIti/6mA6juG3owGD0GdtufCzkMGORzf25h36qvD8/VWtBC3F3eO7FFHu0AS2Dc22YUXG FMhjRlSYnY3MUYpncaVmx7hO+9Un6vo= X-MC-Unique: wP3r31ByMMKTrUigo3GhkA-1 X-Mimecast-MFC-AGG-ID: wP3r31ByMMKTrUigo3GhkA_1789028278 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:30 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-2-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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=2329; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=PrgX7l2qQPAdPLNhPkM5aNrYf4ZSg/Qi9smSw4mXwxk=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqomenYeS4ZfzYPUeiv28hNvQ2Fkvdhba2XhF1n KGEBKbMcBmJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnpwAKCRDa6OEJdZac 5brID/9pDElyhn6OYb/zddKn3Hrh1PspZo8YD+zfm0OYwVyf2Jc5Cq6buZ9jxGnpuOt1mcCR91A zdY/AM0rkTYCz6La4nz6VH7Ozs524iFj6G8KvH5k4CmAXVIsVe/37eAGRZ4TVQxDPDjZrz24Xdy 3Rk934V1uzceh7hF9IDmk5fza7LVmXM+Vr53jrkvYYjpoj60XPnXX8UO3K/+hqBzw2x9dDMrZyZ A95ENLAX0Bp6C6Ernvc356J889k7nz1FQ5GvqPF0Du9MCozSkHat20cDUh0fgvhxFzdlDpIctym t10/NMUdACHg7XRBJQPVQyyqrJkpy5px+IRrD46AyaefjmXrkBjV1+usY44VmReYiU81PsGUgy7 LVuYOvwwbzxtPYWKWOd4yhCEamB5nFkiWojP/JEGZ/FDaPzLYfe+Zw+X+908ZuHCsPtc+sYkS6i /Fp5Qyl1pblCeaVMuqmHFqE3sGExv73MZKdRvXTxscjAfP6uJw0LqsMEuU9CZFD1m4HiT5muRpc QWxygAyCbArdmvd8NwARJHnmmlOCHIfvwBlyrKaidogpbByGf7LRJ0MsSbH0AUdSmtgsAKUlBIc dEzg5ARqf9r05m2/ay5oaargtzmaJNMOZLTVNL8SxW2dQtilH63rBhMNViaWL8BUUts9D+owr92 viAQSBA+oGziwSA== 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: 1789028319354158500 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 Reviewed-by: Akihiko Odaki Signed-off-by: Marc-Andr=C3=A9 Lureau --- 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:48 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=1789028355; cv=none; d=zohomail.com; s=zohoarc; b=Rvujy6Pbk3lWZgZsunnkEBX+u68PbPnngsuNqn5yB41zbvTcKNRNoqmI+rTqtQ6gQtioqUQU5NH8IJosp8VIs4+S2qoR4yVcIYkeNW0HEPCbDYgSpCn054yzOE8cKwRNBDPUhRFeAw2ccD+D1DACAap4q2vRdIbpTNaNYBloRcg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028355; 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=NrZcLuFrGEpfE8BCDiEyrMiPMMH5hwmR4t2r2qPRPq3wuL8Vt3g/RuzSqRBs5yaGyP0OYO4ngMoT/FG5PDvm4DXgawKIEHM4lmTdS8ki8Ej7ZQXhM0AeiQHVEMhFHMDcRmQczElNfJlWVWtxyU6onTDWDZzt4Ybftpb6ppNbwQc= 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 1789028355332299.1988071644914; Thu, 10 Sep 2026 01:19:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4Zz1-0003HA-1Z; Thu, 10 Sep 2026 04:18: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 1x4Zyz-0003Gx-7W for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:09 -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 1x4Zyx-0004se-Ci for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18: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-199-RuADn1BYMJOmoVdDPR5SUQ-1; Thu, 10 Sep 2026 04:18:02 -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 AC3A71954213; Thu, 10 Sep 2026 08:18:01 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B33B51800351; Thu, 10 Sep 2026 08:18:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028286; 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=jGXkrNT6Y+l/mFFm/jNlYIMiZjVsXN3TiZ7WdzSl0P+3QJTkJCg8wpM9fVDh8EcnX4XyKW 87wS3TVANWtH0tL/KWgYyhd+8Cz1lnw3oxcB+hDsm73inusH3ozAM7y/2zkceRoecspgf9 evCiKsOW+mNwIKrweFRdbGrADFnz5lg= X-MC-Unique: RuADn1BYMJOmoVdDPR5SUQ-1 X-Mimecast-MFC-AGG-ID: RuADn1BYMJOmoVdDPR5SUQ_1789028281 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:31 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-3-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeobk4/6RYOmltxNjFIUNvX5wK02NtXBEkbo DqFs5ks97OJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5b/bEACkqCfpDdAZpCq3uGunjvx8pnxqym/7VOqfRhP5jO9wfv96qu83Yf9y3rYvaXVFOIBCkOY p9XFNQwKZB7qjpczYnt8VciK4XEcxRwhnXoVJzfzQtl4IJB1Fpap2ZqJ4f5ubQbeiTtjeYEN4DN YzcQ+ec+/hCQgCYdTa9nUcCFpaRzrCXfnNGSPsmJcGHJZypO1vIsZMufaBY45NurfNPg3+4LNck lswDij4eewkCIC3XQtQ3qz9OMJE/jsXuQtrVFUVb0aVrwsBsJ7HkN4MNALneSy3cB0Jb8WPCEjY 1fS9TmYsLEgzNjyeVYGsBFQc8udSDnoQ3zUNacQ0Nbh+P9jIqSZL3hvKfF6PGWZQPg3EYfiSOd2 U+O+/nCBOFZfrH6qlb8cvDSMYcRt3D9OCsmJswgNIATc9KMKk8aXaHbIbOphSVXPXJ+PQatcj4C NQDbct/ZpclnDEgmfuA/HXjaFstbJLqZtBUYdyttH8FZqunUJYsmRZvKkfgAJoAXpWQqjk1wmzJ Z3QVkPSVlrXvl5EiM3y9UvhjvaO8cVQNcyt7KeUm+6ZEl3TGIjS9x6J17tgb/BEeTHaOcLH5rEG WToSQTlZwYA57ab3Sm+5Z4f2mAWWXeXZSXiDD30egzE9YjdbXpldbYjo8PSx2hJRKsWswmU21dV wNzSDo5JErdVeZw== 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: 1789028356266158500 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:48 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=1789028338; cv=none; d=zohomail.com; s=zohoarc; b=EKB1J7iWsjwC/wIIJR1bEa+MXkb/I09pF6tH8O5esF6KFuf8bzyZcLgIvo8s6Qv3ZOGuU/F137Mwrt/wxfOPiqLT8Mc0h2mbXubIANB4YgcLJQJVjJ2UmLaov05VcIU1SURqcjr2w+sqPLm0Ru84hpUx4jopmk7Y1vAedOQj1nU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028338; 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=lXdSveEDrnITJZP28c4zxc6tVw4LSzIfR5HgbyOv+9R9JVN/Gx3g0gB/Y677iWhDYgmaK5O3M0PQksSPCNrZVCJNBvldG4cKGOs6SFQnL11yRPbthifr5D2IXMs5dNJE8lOlkApvIAUSQVuV8fMVNR/9IuHw76uwFMPWxpcQ1mI= 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 178902833837677.58170024665594; Thu, 10 Sep 2026 01:18:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4Zz4-0003Hm-Ex; Thu, 10 Sep 2026 04:18: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 1x4Zz3-0003HS-MB for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:13 -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 1x4Zz2-0004st-9B for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:13 -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-54-WlaPyVFTN5eYNNKJg2lQsQ-1; Thu, 10 Sep 2026 04:18:08 -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 8199B18007F2; Thu, 10 Sep 2026 08:18:06 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A36421956040; Thu, 10 Sep 2026 08:18:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028291; 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=UGw7XIhxeEti6xC/AKL66NkkBUVvKG7rQ5schTA4myzTBqtBVffQX2EEYRZiEYXhBfbZSq MjY9Uf+DvEmOrXjjniPAlzjWUjvrt0XBj9HavHv95Q2aYAq8srfq8rGZC33BZ/6PPrzEPi boq+Ao7bN++D25tAZhm/gc6NrXtJoa8= X-MC-Unique: WlaPyVFTN5eYNNKJg2lQsQ-1 X-Mimecast-MFC-AGG-ID: WlaPyVFTN5eYNNKJg2lQsQ_1789028287 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:32 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-4-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeon7tDdj2cH+bctXAv5EPSveKgragpfnbXq +Q/X45nAiyJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5aUnD/9JBOBkvkB05xWA6a0IsdxvIyCQBeegUDrf6nc5fJDV2359QzqGZy1OLadkCZaaZE7/YqL 8q4EaShlDAXmGFJdclTV7AMevH853tO5cC35+oEQ20TH24DDADZF1aQHm8Om5DoPgnscPtftsZm t8o7FTz0Vy4zlL89aCzMfFRbsI+y73ixPWis+1A/uBMu7bDdZQay5cWmb4Mp3PBt4O9gY4K0nPO q6pJANbTjIJmh5htCFxRopQBpg7HlMph2ccBQgO9pPO9zvS+Hj+h6lFlTzcstNSX6Tycw/bMNiL Ro7EZLjAaBCso5Yqiv+nGyCKqE7zDCH4w1sbmPbXs/zAObIhXMl94mw0hH05OwJpqqqe8a9oI5e XC0oY5cLjW61sm52w4gZ3/6eNd+2DmfHL9kmhU/qMsQ5bnIdijx2s5ohEb+vNL/40WExopJ7HBO KMWgmJmfRdjW5bkJfMtb1yurXldH4oxANZU8oCnz0MjcK6hWL01XBVWonlTi3sU+YxDnzj1bSW+ xaVTM5qYPnis3TlaY3qjvqjd/GxdChGd5u1QThGcR5rL27UleXw4EQVU+/0hP6hY0neeos7OBjq 538VokIh63wTpOM3/WBKeIe1d0kCTKAcbBSnooqumKAkKjmcf+/QSU2tZ3vFU8sQQaY0s6CqmZG IP52lqCJOmZPxFQ== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1789028339995158500 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:48 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=1789028387; cv=none; d=zohomail.com; s=zohoarc; b=XHHPeFKYIF1Pxa2l//ninW8slA3XNqtK9ibtG3+n5sGUPRZUWUnwrywGeXmZSl6x3jgTaRC5X432ttVixdpEeGrdOlgpBTUeMxDiRKUoE7AJFtgGXddqjEhdbpWrAEm6pwqN2604yZkS6TbWsp6HzCPBzWIwTi92XY77UgevnUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028387; 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=HxMWlhhixtXydaqnMt8EsSkLlRDNXGXBXQwqkizJ3s5+w1cC2SbJWPDhvG3U9RD4LTaNk5LiqWxZhyPZlllYgP2mn/gaab4tl95ELCpajZUyd6oiEOcfxMoRiN38v0XiXXjWjT2jOGvbTvIvppe3rm7iz8II5P27eJcR6co2O7c= 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 1789028387743563.5770996178712; Thu, 10 Sep 2026 01:19:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4Zz7-0003IT-MK; Thu, 10 Sep 2026 04:18:17 -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 1x4Zz6-0003II-HX for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:16 -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 1x4Zz5-0004tG-A7 for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:16 -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-264-9JSK9h12MeabyqBFiqLGoA-1; Thu, 10 Sep 2026 04:18:11 -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 17672195422E; Thu, 10 Sep 2026 08:18:10 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E3686433; Thu, 10 Sep 2026 08:18:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028294; 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=FY5DISis4Ha2mzX61xLDVi4vSezuKKxdUGSMfArgEEh0eJFdWBxGO8DGmO18mtrT3PWoRj 2/fg2UvB20vJ2Wh0ppgIAKlEEVAvk9k51LbdpbifFV7s0jLJdHCD/HxgbSKR5Pt7uHp7TQ GlhoJp0Qky/axWwuuTixPiewfHF2c4o= X-MC-Unique: 9JSK9h12MeabyqBFiqLGoA-1 X-Mimecast-MFC-AGG-ID: 9JSK9h12MeabyqBFiqLGoA_1789028290 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:33 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-5-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeoFWDRSa8LJi62FbahwiVE2o9rhjfjxFLQA k5hGwzaQ2SJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5XM2D/90zQ20iJHzavKbncmq1eWkB+CVRGcklpNutlJjnPl8XyJ1Hl6x0z53osWsAOxBL2Su9Vo p/9giZmMg5bKsQTwx0UHKWMruxsXvwkeTF28XF02CU2qmtbWW5+bMlRGy6HrQ4vnidSFTatmiEt x8066RGqCJq7KXjGJMmhU5zzhO8e028YpSQV644JsfkaUYfRhfC7O+8U0ITC4yPs9/POZzJTMY8 79nFax1W706btQgBO8PVHRGFWp8/9A8MAKsjeD4GWKlXLHfeghuBj8sU4Fq/+PjTryCLXr9IrpF Fcr0vKCieB9QD7tqqkKAAwEQc5FbLoXa+gk+54vTZl8pTu4des1hvu3Ofo7LMnd1vE/z1vBskkw UD7NTQWhB8fMWu5po/pZx496a/kg2zaGs7RJJJVkvntXHKlb8mR2PeKp9wrjs54aG4GQR0fP6Nm mskAOTa/sVnersbRuyTkJhRhpueSaVPW8aq4NoBeP/RVbNq+ovaE/B3jJEF29TQ5ACbGgFkqtiO IWufgSUer+jb/mnnWlw1cc9Wu6CBzug91Kb3kd599XQsxbQEe4ObeF9D8wLgofjPbTnJzwFDYKC AF2e5X9/5eHQ1PSqX+J7xn6JkX20bL122r4IAZ06+L9Asvjyj6BvRGs99pm2UjRHO0+8eCceqHH qoOyHOC9OGfqRUA== 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: 1789028388260158500 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:48 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=1789028347; cv=none; d=zohomail.com; s=zohoarc; b=JPSVhkVDZ7r1go/5OFUCXVUNgEguFOfNaNbZU6oM8HgfrvNpITZD6A3sQQW5JlkkFAiMJEqsO7mfH9H6h7B4+qJNaFTtWL4XBpHX7sO9QNv8J1UC/JOtc0fxW9JMKnQnF9vKY/OCgbMzx8ht0AeKSenMmckeuum4urJTOqPQSpY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028347; 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=Yheq9a7t1qEl+sgnYY1kCbvl5lIsYlm3bPmQSCpG1yzdWTBqE7OMPmpZAskGXw1p5gjtosCgthv5ukQF6FTLpHKeZ/8y/qGByBzExR6uKYGxPDDtawqXwc0C5eUndDn/tueP3oNskIhB3qJn5K89cqv9MZAnROOqJcZbsc82ZJA= 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 1789028347750139.51726835143393; Thu, 10 Sep 2026 01:19:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4ZzC-0003JG-SS; Thu, 10 Sep 2026 04:18:22 -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 1x4ZzB-0003Im-9m for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:21 -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 1x4Zz9-0004tY-9g for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:21 -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-637-mc2QIUj0PCC1uVVyQoRPhg-1; Thu, 10 Sep 2026 04:18:15 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2EF611956071; Thu, 10 Sep 2026 08:18:14 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CD7631800351; Thu, 10 Sep 2026 08:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028298; 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=KDORTRmrO9OoFgGWYO6b3D1IfwaomPjbrpr5l0CwDpJZtK4r2GIqKU/OFNIJARMXO8Kau+ lCTTermraS834ia7fy+XLcB7n3n3fj51xHxcRAACQUjGtId5D/ID/L4Xh8x5ICNkxwn3Fs Lgph+iAq4vT3XrDk2hoBGwzokQl3nY4= X-MC-Unique: mc2QIUj0PCC1uVVyQoRPhg-1 X-Mimecast-MFC-AGG-ID: mc2QIUj0PCC1uVVyQoRPhg_1789028294 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:34 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-6-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeo4Busb7axw58FqWNNlylcAaORt4wUqFDpC AX6AdwECvqJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5X0FD/sHgCBPbaVKvJWgSI8IX3JTdSecIqm2CUYf/GS2b6c/rJlektA49Y4uHaYcHeNTwH7Q1jq Y6AdTquNON/KnckRlz5SO5/X5RcUjlZGTLly48AxJlQDsJC8sUdHRXZL3Bwf3E4SaPiM4jVnxfw v4PIQcS0dmTsb9InzGm73xjXyoEKNSj3Xa+86Jz0YxQOmm3pB/7H4tpVNGpnS7Cx9RnGF9YtoNp WeYw1sAeHowqan1Z9VnsN5S0wivIuEVwDWbpH4G02G20mTSNG8G3ZAwfn9VIBI2fRmyYiSBgFFk wvn8WV599pSHcyKreINEGUe2Ho6H2+p8HosdvRwaYmD1vL4Db07OFzBdaNWbPG+TVs1u8W74N7j 9boGU8UwPnuFAlPrq7KP6POKV2ZvZdkxUcqOkbEUHuXyfAxsYhkC0VSCZJ6UO0k17QJY6U23oRj TXJY08w4FDc9l+HjxkMhHTBIqiEozNcekWmgMD3vXZ7Wwp8eaS+QyZhFMN56B3ogXpHAeS2cJFQ HcgwHOLHImEAd14NzJali9iADKMqtqyOQCfWvRhGIqmR4hnO/Hyxt8+3QsgpO80kIFTSp0iqPWD RaO9WU2qHlPvYqjly/+3X1T05yUt5dkwWcqElePCN61+y+nZaex9Pkq2JMZeUVdV4Yzaq81ICMf Vb5CYlUAoBCjrEQ== 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: 1789028348244158500 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:48 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=1789028328; cv=none; d=zohomail.com; s=zohoarc; b=aT6AE2s7ASvGO1xILLzusvY9AdkxtC9IJEjUFglzMohGr00EYCf3FtLB/RF8Dt+jJ/l3+YXWNcK44gBFDQq25wKM+08u0Dz0Pd0glP84noxltxuAC8Un5Hj/r/R6TE99SUVIVshdCvYxInWg7jKzb2PlqzokuJm3P1q0HcBJaz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028328; 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=O82sAP5Hj+bGeZK3beOKC9TNFaKpvhY6RCKuJLTbO1I=; b=iML7UCa+L5X2nyb+EObtGzdcfvIRBQ9Wk6ePWy2WvR+l9vybHS4nCxJfq8cfMOAK0Pfdj067Oe43Y/Xo6BdBfHd48DXAGnZZ3FIwGiELehGNAG1+oiQ5C0piP5OmPtGBMlMVGyxXgusF2rRCN29F6xZzIZh4ph0923chJ6+khN8= 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 1789028328858594.3963534249563; Thu, 10 Sep 2026 01:18:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4ZzG-0003JQ-1k; Thu, 10 Sep 2026 04:18:26 -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 1x4ZzE-0003JI-8G for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:24 -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 1x4ZzC-0004tk-H8 for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:24 -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-685--w3hUNbRPeuSbCfEqyYiRA-1; Thu, 10 Sep 2026 04:18:18 -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 70D63180057B; Thu, 10 Sep 2026 08:18:17 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A2DEB1956040; Thu, 10 Sep 2026 08:18:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028301; 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=O82sAP5Hj+bGeZK3beOKC9TNFaKpvhY6RCKuJLTbO1I=; b=X2D882xhVSK4z9FDtKtXCLEk3ONx7tdRt6mqT2JwtNxOpcLukcrvM4QCE+RsI1XRMnTDRi Fr1A6JvDRGm4P/5I2E8xEzA6SupFwnBtX7vchOnkzqegSHBODQkzGUR3abbuj6leUlbahO 0ELeCpancAVzE5QRP2+chamWFIYqutY= X-MC-Unique: -w3hUNbRPeuSbCfEqyYiRA-1 X-Mimecast-MFC-AGG-ID: -w3hUNbRPeuSbCfEqyYiRA_1789028297 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:35 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-7-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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=6254; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=gBqWaKJgA4/yz9sjt8xtm7yhbFIUll6dO32lThJ4IRw=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeo0Gc9A7bOAENTfi+pyGef81NnNLj4yRSWl 53v0IaT3o6JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5QrjD/920Yr8LWHki9rCr0CvxH71hY7qPCCOB6XXuj0R/RtgzkU3PzoDnuEkNKr9lMyJ3on3dG/ Y2nuf8cKjvBEoE505mZxtD8gi7QHJo/dwgnTfYD9HUV/FS1NAeVu58kAty4XBhjZ7MXlya94Rmv UT2vsguIi4MNAFTQ8pOagn8D1xWaaW1ImFRWDb5iVHgw6fmQVDwlUiN8CcfWYiHLOu1OCXE/fki HK2nlmhDJniczsoTkoHGmV3Hd/Nm3ja45R908fpvTIcoAZooarG1jbBWgNWsJ16q/augmu3CQ+s ECTr7V5OZnN7Tg18QpxtmXasCEqQrZxfONpClkB48Ii4aj+sfdbOpIHL9/6dylKUDwaeUm+t0Pc dxOdoqW9waJz2kW9zA58ISOaIb6A9ub0u4T2Y2296hQb59E0uLd8zy5H95+h+fDQv9xDbat9OYt OwDAmZMXGslf841F+IrDBVeWYa1EQW5NkXzYyYXJZnV0ntUa2LEDhOObQs80zdkYUYDHZ6Hk1CQ yO+C0+HzwqOvlI6XL0GzBMsRMsa5cCsgDNaqdtvW2z6ih/dGOM5frE/dRT9qmGzyTpbdq14C4/W 0R2ZAjDwDq8PLnqauuFKnqRNnnVuks0RpZZXqIbJDdfhkZL2oBnaBa3S3HimPxe4YNecfj72tYw pdcW+jQ+Bv8Lmow== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1789028330220158500 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 | 14 -------------- ui/gtk-egl.c | 13 ++++++------- ui/gtk-gl-area.c | 10 +++++----- ui/gtk.c | 1 + 6 files changed, 13 insertions(+), 28 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..495270f29bd6 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,8 @@ 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; } - -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:48 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=1789028378; cv=none; d=zohomail.com; s=zohoarc; b=ILotdl44EP72Da7eLO/jbeZYcgjEVrh+REmqssAV4+042DvYAZt3IxNiLQB2oaFDrtpbte6ZJ8Mfb2DegnNwhVn/hRI3PL2IWZMufjEfDgvGpsqDG+l9VNCpDChR7gRhAmypHgAhJ4jgI/d/jLdQJ1BYrA7Jmt/VXIjpNLDXZN8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028378; 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=j1ShXoVlDUyzG6U/hT4oXA2NH6xn1d6jqUMEu1d+RwqcnKcJXowwlIXVrN3D0USMp9qkniCCfAYnwunv8r1KO9N0i8U6OIoRvQRaDuCoEWMvsJzvqdtenn/oLGgawdOOOt7+8UI0dSfswo2Gth6qk0fTwgekV45nO1x3X3SDV+g= 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 1789028378620940.9462952323737; Thu, 10 Sep 2026 01:19:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4ZzJ-0003K2-Gl; Thu, 10 Sep 2026 04:18:29 -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 1x4ZzI-0003Js-6i for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:28 -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 1x4ZzG-0004tw-GF for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:27 -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-386-F-iroEWKP-uCsj6KiTs8oA-1; Thu, 10 Sep 2026 04:18:22 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 339BF195608A; Thu, 10 Sep 2026 08:18:21 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 07E7D195608C; Thu, 10 Sep 2026 08:18:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028305; 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=ewzaaQu5uz0oRt4LEgluHy/F/1MwFKl+rZQzj5gMHsPCp0MVhbHgrlxY/gU10VUZ7AbyVM xJ7W3AcdU/aR5F70q+RG+iiTsN2iylWplqvenbKLfo5emkjksnPoL3nUaUI8DFzTIFb01m EaJ7uWV889Dcx/uw7HBZknzdUvx99zE= X-MC-Unique: F-iroEWKP-uCsj6KiTs8oA-1 X-Mimecast-MFC-AGG-ID: F-iroEWKP-uCsj6KiTs8oA_1789028301 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:36 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-8-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeodubnMGt9Wc415d2OpFAOdYcq+Y56g9pCg b55W/etzoqJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5fwpEACsCmvj/YAxW65F8VEzzC8c1LjyG3bqhUu9kcGv8+68zbSN1PUupmRrZfwq4crDAagZrWs 5oYX9WHgokK9/iywUeLj3Qej7grwEnFlWL27OjRlFl9iXK2XVNeT49wJ869xVZqHFXURAoHP1HH gH77kVZsUnWP0PxJfF5Jwn1smPZdEmAXHTMGQYGkJmLRHbVCz39L0O1O5cACnXNLyPNiUuwEbFV eeeboDD8mdsxIGKcy3qQ0+Ai5qNjkT8yX32ayt8nD5XSoF5f/PeNtyRQHRoHzoM8aGn4U2Ctfqd AkTo3uA58VIyrV7tKg/jPSRP3U0BiWDGyxq9uGk7Qs0c/aWHJToCt6naSYmyslKWZM7JQToQY4c omV8u3ucgc+PXOE4gqFLcihYCpPRNHoFMj82AqIwU0qRRm+3qPnNfaA87la63YIlxQd3j4hiB59 uORtyEDdmce1ikjXCyNp5rEqvCRjpKqI+wetNrOd0QJj0nKO7VNXQlt1UxiTqgYbpMx27uOsslU ECdvbk3I0UtoL2lKNMEhMT233cwQl4ncZqUP8Y9RKVdiii5ZUFHAr/ksYnCpLITEtX2uT125CyC SeY2NuZ9SNKx+1c1e0wo5k3Topkpa6EdZDy1bwivR3vPma8YpNOZMHrVlRhsr8nGr+IYKsrqBKb e4tJv7wcHLv1DPw== 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: 1789028380322158500 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:48 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=1789028357; cv=none; d=zohomail.com; s=zohoarc; b=b3x7dQ4fQkEg19Q+Y4+JcV9J9fbQJi+fjAfgOEXXvrx12lOb6l3hsVQLkyZiqsGVseaEsE38bDbuQZ4RNMOPQ6iwrSyfgspIpP8phJuWLObgGtFds2hf5yYk+CSPK2t1Qql2vfh6vKHi109BvQmylbh4U1jEi6MCYnyOyRhky1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028357; 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=ABtzUpBUo2dYdcOQVcf6hOEVu2g+v2AHOZ6ph0V/Q0SJ/d5AbBv49fkUA+qOSjhaoFg9TTrpQTNOa1ztzXJYmK4FVO6UPkVQwXaqHxAxnTzmNC8T7ib5FXzR5oHm4as+WyG9ULc2Ho/tStwnk3r937n7gQuhi27dTQiEu/ksBew= 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 1789028357802869.073524438974; Thu, 10 Sep 2026 01:19:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4ZzL-0003Kg-Ak; Thu, 10 Sep 2026 04:18:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x4ZzJ-0003KH-OZ for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:29 -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 1x4ZzH-0004u5-Vj for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:29 -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-37-qV7JrOvpN56Wp48LPNEvKA-1; Thu, 10 Sep 2026 04:18:25 -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 57EBF180049D; Thu, 10 Sep 2026 08:18:24 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 82977195608B; Thu, 10 Sep 2026 08:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028307; 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=P/La/y/T1NBdseHOrRi55nh0woEHrIxrq6k9ZRrPoNJWsqyJsZeE/46K35lDEttyab7iFD AyeeSurSOhW6JRPp5dpt9/g3yMMxqmx4DqUzURlG2+67ByC5i9wZXvwIMZcWoHXiFS7igh 7h8kw8rSzBiUE0thQqbHb0Uv/fs65Pc= X-MC-Unique: qV7JrOvpN56Wp48LPNEvKA-1 X-Mimecast-MFC-AGG-ID: qV7JrOvpN56Wp48LPNEvKA_1789028304 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:37 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-9-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeowLROBw+D7grh0rPWPR5kjfTERv6HLUOIr 9NqrwBQRn+JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5S79D/9stlc/6c4gyYm7kcrkVTHAIdwCo4PUpGiP2gvsegvzr+8b8LWbLtPm9C5pqQ2D37k0i7O yAtW32OF5qlVk5kPcckuwyaVw+BQUoU+bZOiZ7h1fpyf7OaDSD+/mHzVqHO2sov3DFaCZZLLeMl gX6daOcv/FGMV7Y1S+Zs0WVuZE6p8z6MaHSEuBlxTJ8YA689b8gsvw94wqGsGBvB1SCUEKdfBJi 2JVYuO5+Wcvf/BVfsUMg+JgCciX+vOmWteZyusu/fEvXYiPB9XD/b17GXObNcoveNpIEqQeOXF+ isS4OGmpGaoqCXw18bOLjRu5Gdb3/BbHn5CjFNuyHhqBsT8uvLiPj4gnOA8x6fjA2BrEDfCD8PZ wbbzCchTUJwVgriAeZ4vudlMqbnSG9lCgKM9iQZg8eoSRFQdQW2PN18Vt+IeSATQCvCJSwjMdq2 Ar53Cai221ZJZad1e9WRLGIp9W38TuPSnjq7Oj4ybx51nMPufKknRKlO9d4W6Kiw1I1H5HxBBtm Bc/lhN78r0j5EQh7A1+VJa8vkj2ULDd7U68qrkvPzfr7Qe7ZR0iwa8wTzz6IEgJbOW4lLh4OeKy y8nRoCYkhLoHjjMxEn/25881BKjSretSoaMsX62dGx+ajyE1v/0GiAREnMU1U4076ZAKh0KhjUF Vks7DK+Whd2A7uw== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1789028358233158500 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:48 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=1789028413; cv=none; d=zohomail.com; s=zohoarc; b=ExVZbAYkDE3DL23qOQUB3zzY0TSyzcBwVEACDTaEJ/k5NvYiCfKJyPP2MtmlgHGa/59SIMhkK0zEutZJJfXKA4xuNYKTLCmj8Mo8TdacTJXPt9CXmb09mI7qk++imn1wI0FY4yOt38EkuvewvpvWWOlA23j1GRjjQSq8eYXVc8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028413; 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=QWwmyknpNVnkVErSvxcztnrC8G7+yk3zs9oMh9jLYCaWsuUNhGjXzRfVx6cE9hJCaMFF6Tckb98qkX4IXdH/P7y+TwMWngopIPdMAanNNHEyvKh7Snt34fQsWEaUXP/WRaRV5zzeEf2F/3M0bPJWxML3Rf8FZGECxL8WVPE6lRM= 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 17890284133171016.0256218010146; Thu, 10 Sep 2026 01:20:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4ZzR-0003Qi-E1; Thu, 10 Sep 2026 04:18:37 -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 1x4ZzP-0003OK-5f for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:35 -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 1x4ZzN-0004uW-QO for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:34 -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-306-YENPm2ENMFSmMW2xcTUQCA-1; Thu, 10 Sep 2026 04:18:29 -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 879DA1954213; Thu, 10 Sep 2026 08:18:28 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 07C50180049F; Thu, 10 Sep 2026 08:18:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028313; 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=AKqbOKzpdN27o/z73kd3QEhznkX9DpIEPjKvCgXVEVjgtvA+u5Vz9jStmXK3u02++ViWmz 7zy7l4SpHh/s0VmUJ+hev8wjWkKb9l4WqYZXUeX761SqPng42kvY6M4FlJ42u2FxPmwUky igUIIvb51fHcQXoprynas2bFxF5nxgY= X-MC-Unique: YENPm2ENMFSmMW2xcTUQCA-1 X-Mimecast-MFC-AGG-ID: YENPm2ENMFSmMW2xcTUQCA_1789028308 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:38 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-10-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeotwTamMPYRRXwZO/jb/uRK05lHMjdvrdUr grSqB/lCwWJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5R9aD/9Fmmin1SEIWj8CxuIyunyVEI3Z1Kfhd2cYBhIeNPzhVbDiQ3JfeIu7U3oYWc4XO/93fTG SqZ5vBSRuBvhTwsduqsfRziku8mu0jrNO+o3t/HKoE9OJkDmYApfR9v6ReU1Mv/ZedTFoDv74FS ORVDD0Tvh4LpiZd6ThFuzTVkVx5dYr/qMp5E5AUaUs3zNyQ2j4UnRZMIX+ALJZYxQmyhV3rr0Hz dve+JJHXV2QUUHQrDh1ubZP7JRqhwB99vhBodjyjA9kPQBcBbodKHerlA64G1gypDMj5D1RmlGf s2sZ61tNmPva7XZJKh2DcGlRb6mWrhr5WDr1qOGg5d8zGuyiH5dKRMLER6O0WBXTewcO2xB1vMN WFW5y7ultOarr6VNoz0Pull5od/eTrEKu7lNP1TsEYvdlr1Hi7kKVs6H2TkfC8eyMPlpDG6KGIf 6vZ2dWIOtWdocOQNTAVwuFcZYVRFXGnZaoOu6DrLkmwdT5+cMFeJAmNZ52rSf/ZsGy+HAVl8gDD c6xbbtaPBTcVrDA5QVMReV32qCX6GGamthLwJsK6If074uXSDVy6d1ftTP8tHq8Q1r2BsO8iicJ mDAWj2INBRlsIPe/yNjC0sMp8Dcni9TrwZHWxnjUri02+VVNAhTGvv79qIt5IOCJ56V+CHp373V VJ4E6x52210QavA== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1789028414472158500 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:48 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=1789028327; cv=none; d=zohomail.com; s=zohoarc; b=bWCWYGIr65Puq0LIm9FL1L3zYPOBSvHMYPp/KZhCFywCSxRxDgmd6B87/+6PfJygeOiNt0FcrSG8DkHGSi4OF6MLt2Zy8NtGA2Bg0GjoE0w21De3TT9g9dGrd9b3FvYBLeaO9QMLmLotlBxqrE4/NvDcRGrKkAhYmbcc4F4ckSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028327; 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=B0YIf1v51cMjKeO+6C1PNqWMW4OMfU4ZX/Wfz/4+eIbrLnbKFw/pWSPoXxqk11Wl6dHG1YQtzCk6/9IJCgbJwq7D10QmUH241HMUD46juCAhsQc5ORdbqj16WEAH6+XRVSh8yqH6uzhig3n8HHUg4JHq7TygDojKZOulwirKeYM= 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 1789028327370609.5373533357091; Thu, 10 Sep 2026 01:18:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4ZzU-0003RJ-RH; Thu, 10 Sep 2026 04:18:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x4ZzT-0003R7-53 for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:39 -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 1x4ZzR-0004uj-6o for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:38 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-418-4mr2L9krPz6yZLBbOZibKg-1; Thu, 10 Sep 2026 04:18:33 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2AEBF1956060; Thu, 10 Sep 2026 08:18:32 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EBEC41800351; Thu, 10 Sep 2026 08:18:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028316; 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=QtG0K4K7deKmTnbtv6ISb6VdGcSdaIkdgVugTD3EJ7n/0RCiPv0B44zUFew//753IsIyST iIdk/hQ9GVicM9PRNVOWCfnxErJaRx4E3T2YKDISEkm39G/tkXfV+owCrkLWMnk/Xc8NVm V7ovMrFt96fgBBd+u5QbZBfRxeZ2SWQ= X-MC-Unique: 4mr2L9krPz6yZLBbOZibKg-1 X-Mimecast-MFC-AGG-ID: 4mr2L9krPz6yZLBbOZibKg_1789028312 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:39 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-11-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeo2fQLG3Msg8Yg3jsXFe2NaNvivQ/qccdAn ldDz3ekkY+JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5ROsD/9W1eGSiOvGzg6P7oUHOUkSw+1O6cUdA0l1cTq2bx6p4DbIVAGFGLW5L7arumrCeNGj2XI kup1rG8BfoAyjDJYt0GUZBRg+UD03kR9YKu/nIETrmXckeSyYraeew1vI5HzLyl7CFl7hXuAKlu QixYOaiT5RFsf1q/lIzZ13dR7NT4DoYGqIXS0gxvEqVCEyERth+piL0Uood/T/Uu7ek6ZXuvNv8 IcUYfgFC4uzX7awDXoe3QWV+D1lqp9NLZygKrYMutf1VoM76OCNCB70WO3Eu3wZcgvnEEN8j/VC MkDntcgRX4QibzEsZwpDNsjyU9Cni6aO1CGBJksd7I7O7Avt8gKyBBumsJxkWOw4EyoD6axYkJK MmLke/Ztm5BGiAEiFbK2a2RCXdPdGFotVgEbnjj7GwGby7EqI8/J65s2rL38Y0C2oRev4n7N8ch VVBkIk3R77+CLxwnNjMNFuOrgPASZmOaMt+4aAN3qJEKdVUuhSHcerE2fOBGUWLwNlDVd/ceb9f NMDJ2k7ZXwLEeUM4BaBmS/zEbHTUQS5cF7JxTqqVwWhC9dxJlj4422A4WEkbqdJN8Uhp8xH4/Mm gf4llojub8XiHy2e1sVzaq++pMgZ1SkEQylIUNsshZq1SrBReWLVAF3PYe/fWjGEqafkDiwesXG d5h7SywjupZno5Q== 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: 1789028327976158500 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:48 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=1789028376; cv=none; d=zohomail.com; s=zohoarc; b=FYTEaLbqNsUG5Crs9pfIj2t0iSW4NV9RlxsI4WoBpQrvJNCK7dZid1Pyf0IeT5ozYv6v36bn6obFbD1eER+KMWWHzywaKCKqhRMrz3bLdaVWojauabL3SqUp06lrO4RAD0lgVmUNijVlEOo0x/YvgWieVjgx2rrjSLpRlJZyEUA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028376; 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=VZnshOqku4FavFQORr10V8m874qk9cgcha/ptLZZv0A=; b=C9xioEHYpWg8TVb6COX58OxN9DJC9oj4G9lw/iP2WHpWsPFSMu6/QIYCZGqSTPiVN1FAr1aKQyrr8JPV4/2Keblq9V9O166YHrlk2BVgVOKY3oKG4y9FEKA8n0BUSvZP0knw9ZY4pfL+gjArS3zgCuZ3U372h6I23MnYcc6nACQ= 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 1789028376404259.0493273750807; Thu, 10 Sep 2026 01:19:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4ZzY-0003S3-0D; Thu, 10 Sep 2026 04:18: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 1x4ZzV-0003Ro-Q6 for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:41 -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 1x4ZzT-0004v8-U7 for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:41 -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-383-Gm8Jbj_jM865NheAl79gXg-1; Thu, 10 Sep 2026 04:18:37 -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 41D541954B18; Thu, 10 Sep 2026 08:18:36 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E504230001B9; Thu, 10 Sep 2026 08:18:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028319; 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=VZnshOqku4FavFQORr10V8m874qk9cgcha/ptLZZv0A=; b=JBxF6bO5OoKCOb1qb1ChDUTSmtKPM5Xjnh/qr03Fa3wFL5Sg1gazj/VP4yDtRIWK2/TVQS ZIQDV/0FnsS8xQge+CezTL84dsQdZXyRsmQhyikYsPUSCwQwLsD5hM61Hg7OsH4h1OeN3t ZhdQWiE3rFPsSHY28Tp+601e7j7x0ec= X-MC-Unique: Gm8Jbj_jM865NheAl79gXg-1 X-Mimecast-MFC-AGG-ID: Gm8Jbj_jM865NheAl79gXg_1789028316 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:40 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-12-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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=Rpjn/T9FKWIsPe+2tcKGUZHI81cTdeyhzq1ZW8DwiI4=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeoWpmr2e5NXX4xKoXmXmo0tih0fynWeo4lq n5DPI6kuHeJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5dgED/99h0fh1rABGj8I2cnu921M271TydQvxSd8Y8SOuxwnJHN4IUkpKEKFCDZJG9SYlP+O/mE tOcNJlxp4FdxD74uTRvBjpXDshjcPRQmcB9lEnQLG7mldJHGsxfs/SwzNx6JUukt0m+iWGn4Xlj w/k7BNw8mqPLTPvQnYYsSPc9GUDuE9VdVlF34rnzSawnOsCK12moY7wcPbmoX9IaCMjR6ZxRjML bLXiG0i/FOIDHtPtWNBvIbVLxGSCaT5xu2WHxigDiJ1B4c1DcIZa5dyVviGVb/ZMYVuB6GVbolF vTsKUlZ9YKdjlNMQMAO0LIVup4ehwToEPtFwhFlBxnQX6X/PLLPXIfXJd8AEys7Hh1c2zbTvCZO kOg3lkgP3WlDycNVVqaM0+VpbwWsvVJomdBbt0khkv/XQ4neJIVUVtryMPrUXYsjnVXPa6pHT5g tOVjyvi1kCWEXtFHTp98NwGEEfCsk2Ec1oboE53c8yW7A0NlVP+9DqQIw/y/3WA2ruHeoNYQF1Y Ol2GZy3Kue0xnw+/paWVC4manKZus/ryJ7VCwzpsgdv/bVBAV1LF/b2QlNVhCsbGXdxifI91H3H wHJpq7NF5MZ/pwtW+KzvL+O0p7fN1MWyfbAswO7lZVWWV9K5iD9eK2xiU6NhH2Q1f3UqL7Wjl4L putnZRdIxH69t4Q== 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: 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: 1789028378188158500 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 495270f29bd6..497f82cc61f2 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:48 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=1789028386; cv=none; d=zohomail.com; s=zohoarc; b=P5vKs/pcZ3Xh+LpR2TBlSuY7O2DggRvdC8+dMBrQ4d2AX3VW+oZw8EpoSN54jZF9wdMpxd45gW9SwBNMBDCnt27ZKgl+K67GOID73UEsSm4OHSSDsmo2f3MlVk8AWvn4NBFuyHOD2sySycFSVv6ffYzik7/ExUovJZPRFsUP/jA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028386; 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=apCMEdujy8gDXKlO0P+Bl9YQJjK25Nuw48NrsNslB6k=; b=FrMX+bXXw/zU/ulHWlJXNlAn8u7CdnY+VZGH6JC3P/UWObXBu6sBqG48DPCZaLktkPH5Tt9rH8BEetjjXfxxxMtzsUBnmdXN4QYu+FIAkIt7aUmSkXw9kd60tnOvs8dmvRi/fqxH/JwsWNlRQAwyWgKmKe1DQWhia9SXpsu0xdg= 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 1789028386564519.405633780222; Thu, 10 Sep 2026 01:19:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4Zze-0003W9-G3; Thu, 10 Sep 2026 04:18: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 1x4Zzb-0003U4-Df for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18: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 1x4ZzY-0004vO-IV for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:46 -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-80-Fq3yqhA1OEWV1-vSy2Cedw-1; Thu, 10 Sep 2026 04:18:40 -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 76C201955DEA; Thu, 10 Sep 2026 08:18:39 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A82021800345; Thu, 10 Sep 2026 08:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028323; 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=apCMEdujy8gDXKlO0P+Bl9YQJjK25Nuw48NrsNslB6k=; b=EMxSfxZkA6xxArokmFKXlupZ9ax8Ro+iq/MD4jKzmdnokBS6lUyYaZ/SaU9Xo3iTxItuS+ Yy/GEhkpkJqMagl5uW/SpdlrUV/389KgEwUuOqN39+NqGoUxrvuOH4NBdEOBKBMzswc7QZ nGHYjIjGERjwdQ3eJy0MGR/ZSGXp16Q= X-MC-Unique: Fq3yqhA1OEWV1-vSy2Cedw-1 X-Mimecast-MFC-AGG-ID: Fq3yqhA1OEWV1-vSy2Cedw_1789028319 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:41 +0400 Subject: [PATCH v4 13/24] ui: make GL context current in display backend callbacks MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260910-virtio-gpu-cleanup-v4-13-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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=11198; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=BTbh3x2r+OtOo7jp0MG+eE7UNVBp9XimgaPMlHb1+NI=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeogt/YB6KWkbU2YedVp0P4+n5aDjRalRMFH mEJFzcathOJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5Sf5EACHZtZ00ljv4sffWomvH5WDjFYiEdgVKD4+QoS/vjVqdWEG9hnuUmnYiaZ0HbdFdp63Lz7 uh95iwheEMRSu4DEk9sOg6VqjjXIzvTV+79ItP6tsPgyHxi4+NpQYQjq4oyjHb7ZrFi4MerxHIG tMQpv9JpdXsFJgvEilBMDDIgbGP+JBe0gr9K0TU19IPEioF6mCi/lTIWgHDk8ze+4izbHqJMsyN JgSjaEFoYGO67iILkXtCoKjGFIYH8QzjZUd4EnuXzWRsFRtl2TIgqTPTq2USqaIbSNiLDrlsA9d v+wiIkoSYjHRtGXYDCfQTBztjtsL0KnofcPFsmqId94e1cM79bYlL1ChGu3aJGF/aIRE8xgrlcO qXAYjlT1NIASYPw2ad931pGS6tTgW1xxvOs1sQ0YNWS9+UKtZmsmrvXL4ZeEVi09EXFIrtro2BG OcK4wvbhFIfnGAABAbRd8ZvD5Jnj++b4od3pL/fd93sLNElbtWiijeUlk6day2jCx67JK8hTAsB LIJUszTl8P6AkhfRHVeaGazLu8Jh1Di3v87z2j3+5YPJtKRozn8fS8NJGo0t/efVXZiKVXau8o3 tzgBkhQ7UcDz64Ty8pyY/7RGQdzsJJL3p/Lt7G5szYD0TVoGDMp0brYgZsGcYtDEN6QILYqbaq5 Qh/UbREtfLNrM8Q== 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: 1789028388359158500 Display backend GL callbacks (scanout, flush, release, etc.) may be invoked from a different GL context, like virgl. Since framebuffer objects are per-context and textures require a valid context for deletion, each callback must ensure the correct context is active before performing GL operations. Make each backend's own GL context current at the entry of every callback that performs GL work. 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. On the virgl side, restore ctx0 with virgl_renderer_force_ctx_0() after SET_SCANOUT, RESOURCE_FLUSH, and SET_SCANOUT_BLOB command handlers, since their display callbacks may have changed the current GL context. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- hw/display/virtio-gpu-virgl.c | 4 ++++ include/ui/gtk.h | 5 +++++ ui/egl-headless.c | 17 +++++++++++++++++ ui/gtk-egl.c | 12 ++++++++++++ ui/gtk-gl-area.c | 11 +++++++++++ ui/gtk.c | 13 ++++--------- ui/sdl2-gl.c | 2 ++ ui/spice-display.c | 2 ++ 8 files changed, 57 insertions(+), 9 deletions(-) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 7f1d1e0c3276..0e43eacca406 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -1091,9 +1091,12 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, break; case VIRTIO_GPU_CMD_SET_SCANOUT: virgl_cmd_set_scanout(g, cmd); + /* Display callbacks may change the current GL context. */ + virgl_renderer_force_ctx_0(); break; case VIRTIO_GPU_CMD_RESOURCE_FLUSH: virgl_cmd_resource_flush(g, cmd); + virgl_renderer_force_ctx_0(); break; case VIRTIO_GPU_CMD_RESOURCE_UNREF: virgl_cmd_resource_unref(g, cmd, &cmd_suspended); @@ -1130,6 +1133,7 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, break; case VIRTIO_GPU_CMD_SET_SCANOUT_BLOB: virgl_cmd_set_scanout_blob(g, cmd); + virgl_renderer_force_ctx_0(); break; #endif default: 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..c3f319c0960b 100644 --- a/ui/egl-headless.c +++ b/ui/egl-headless.c @@ -52,6 +52,8 @@ static void egl_scanout_disable(DisplayChangeListener *dc= l) { egl_dpy *edpy =3D container_of(dcl, egl_dpy, dcl); =20 + eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, + EGL_NO_SURFACE, qemu_egl_rn_ctx); egl_fb_destroy(&edpy->guest_fb); egl_fb_destroy(&edpy->blit_fb); } @@ -69,6 +71,9 @@ static void egl_scanout_texture(DisplayChangeListener *dc= l, =20 edpy->y_0_top =3D backing_y_0_top; =20 + eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, + EGL_NO_SURFACE, qemu_egl_rn_ctx); + /* source framebuffer */ egl_fb_setup_for_tex(&edpy->guest_fb, backing_width, backing_height, backing_id, false); @@ -88,6 +93,8 @@ static void egl_scanout_dmabuf(DisplayChangeListener *dcl, { uint32_t width, height, texture; =20 + eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, + EGL_NO_SURFACE, qemu_egl_rn_ctx); egl_dmabuf_import_texture(dmabuf); texture =3D qemu_dmabuf_get_texture(dmabuf); if (!texture) { @@ -108,6 +115,8 @@ static void egl_cursor_dmabuf(DisplayChangeListener *dc= l, uint32_t width, height, texture; egl_dpy *edpy =3D container_of(dcl, egl_dpy, dcl); =20 + eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, + EGL_NO_SURFACE, qemu_egl_rn_ctx); if (dmabuf) { egl_dmabuf_import_texture(dmabuf); texture =3D qemu_dmabuf_get_texture(dmabuf); @@ -126,6 +135,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 @@ -151,6 +162,8 @@ static void egl_scanout_flush(DisplayChangeListener *dc= l, } assert(surface_format(edpy->ds) =3D=3D PIXMAN_x8r8g8b8); =20 + eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, + EGL_NO_SURFACE, qemu_egl_rn_ctx); if (edpy->cursor_fb.texture) { /* have cursor -> render using textures */ egl_texture_blit(edpy->gls, &edpy->blit_fb, &edpy->guest_fb, @@ -225,6 +238,8 @@ static void egl_headless_init(DisplayState *ds, Display= Options *opts) =20 egl_dpys =3D g_ptr_array_new(); =20 + eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, + EGL_NO_SURFACE, qemu_egl_rn_ctx); for (idx =3D 0;; idx++) { DisplayGLCtx *ctx; =20 @@ -250,6 +265,8 @@ static void egl_headless_cleanup(void) return; } =20 + eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, + EGL_NO_SURFACE, qemu_egl_rn_ctx); for (guint i =3D 0; i < egl_dpys->len; i++) { egl_dpy *edpy =3D g_ptr_array_index(egl_dpys, i); =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..f41fc8bb9634 100644 --- a/ui/sdl2-gl.c +++ b/ui/sdl2-gl.c @@ -200,6 +200,7 @@ void sdl2_gl_scanout_disable(DisplayChangeListener *dcl) struct sdl2_console *scon =3D container_of(dcl, struct sdl2_console, d= cl); =20 assert(scon->opengl); + SDL_GL_MakeCurrent(scon->real_window, scon->winctx); scon->w =3D 0; scon->h =3D 0; sdl2_set_scanout_mode(scon, false); @@ -288,6 +289,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:48 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=1789028425; cv=none; d=zohomail.com; s=zohoarc; b=QM2jA8OspS8wk4WT0Atx5FtbIq1e8iaSAAx/r/XV86hF5XfIORRRrzJD/wPEm25Fl90LEWH6gJbqFYZUFtDA70njlZSxojPd3JcJOosDVrpJcZpRB2pPr63++RT0+AG5kU/Bv3BnJ4zgVc5w2H4lrbiWIcwRUo2P0kfMRX7AwYo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028425; 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=mBMJnWapP4c5yUCMoEs5FTbtCaFPjKcekjjvuC63hWuyuI8BMCCa4ddTTKx3d+mHwjL9voLY0gD2FsfiGnCcQgM/+1SAeNmoXXvuI7nBiJj3U3uEfnqL+ljoCPd6gmxUMB8V6sAqta6Nbq0Gb2RVcBx08xqrMU+wS2Nl4lPnhvM= 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 1789028425354193.10386515500443; Thu, 10 Sep 2026 01:20:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4Zzi-0003ZA-01; Thu, 10 Sep 2026 04:18: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 1x4Zzg-0003Yf-Gm for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:52 -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 1x4Zzf-0004vf-7I for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:52 -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-224-9DJHgR2uNpe4B1hnfZC9Gg-1; Thu, 10 Sep 2026 04:18:44 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 719C31956089; Thu, 10 Sep 2026 08:18:43 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 20398434; Thu, 10 Sep 2026 08:18:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028329; 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=aNfpA6JsdPPlY6GRAyU/neghqBd9s/tQaqiPLpON+B6emshl5XN1ffqgLXcBPF3UWzhyaf 98UHjxovTW6VVnoq/p8ggxZhATF6bVtDIhmo2byGSZZnfmaBoXLY7j5m1r6fZVwlCCESod Wpn1xeEUAhHOgv7EXCZdK59oc0o606o= X-MC-Unique: 9DJHgR2uNpe4B1hnfZC9Gg-1 X-Mimecast-MFC-AGG-ID: 9DJHgR2uNpe4B1hnfZC9Gg_1789028323 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:42 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-14-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeo9aix/7HgFBUBerA0JKGB77vLLJHUiomcm a/iK7WVqFqJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5c5hEACUgWMYlK32ygri0GO3M2od898bEExNS7f/mCsr/95CT/px8lQufcl9I75LMbcBX4zy5j1 bE1KgBtWsXMt2wrqSzFB9O3ynHB7Jd5zqoR0OriGybSSvn7YbZoeAKojPsWmWd9qhbCbYruTAPw sGIb+nchB9MnVCAquKPHHYN2oGAW/3UkmzkD8/6zXeq8ZIzLWoI7Er54kTvGOf2S/YZrj82cLdJ EmZiyBdToMr0UqdlUv/+f57XldI2QhOr+mk8i41b0v/42GxnC/IWEWf3UOoCAsQxz0FuY3qell8 jylDdc7SLrRSdWWC3oAfLciU3fSRm8lACbj9t9KbOVPqDL4JPr/F7oZOSGshD1GPiBpWLWmZtWy dqCp4Scob1TLg+bnMo4hLFIIb0x5YvHoTCfPx8QNUGdcoW/MI7ojh/YBgV+s2lJn7SCc9Eq9RQA iFVaJDIa0wMbgiTYwcbhBD4i1ZfMPav2FXWNMwgySqEGxKXL9/iOzo/eGIE2TnkxDTixxIAe0gW Y74765sBRHg5vBuoqNNzI21p+DqG/o1MKVWQvj7mStRHE0VVOzsC95wzikejOta3BoT83i1Nscj hu92mkgsGxkLCZFGIqinxfcVYvSksyIgprFa8+g8Ac6IZmcOMduFkZDw2nTtdZHGSeLrKrJe0W3 1a5xskFWKcP0IFg== 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: 1789028426534158500 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:48 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=1789028372; cv=none; d=zohomail.com; s=zohoarc; b=GLhQGhaG7r+6DuFY5hA6J49rB2GIONzOlm3hmCOp/tXcLaDAy86dphoc+BtCv68P65AQs4PM9iMuQ/RFubVgfjPNNc5BjFSd+e7eI62rOuHFqeoIdrPOEg1mgiYPv1/9Ko7YdLX4OV0OXjIusOTu1jmMDZTCPh4rlAQLD53yZ8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028372; 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=TctyMXwVd9g8RL1ys4Ll1GN1G1iVpt9FDjCoZA37bWktPC6K/U7t/8zms+wn7obl1WrReZqp3L+AcIgyrZOGw6az3isaECaTcEPPy7v2dUdsMfxt5YJvUsG6kQlsSb02WxAsYXcxGAlK73t0iXZv9YdX1e509ovX9ByXVEh9w3Q= 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 1789028372307504.37735161041337; Thu, 10 Sep 2026 01:19:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4Zzh-0003Z9-Um; Thu, 10 Sep 2026 04:18:53 -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 1x4Zzh-0003Yr-0m for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18: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 1x4Zzf-0004vq-IU for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18: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-516-AdtHw4lrMpW-ClpKkTPDnA-1; Thu, 10 Sep 2026 04:18:47 -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 8DF531954B17; Thu, 10 Sep 2026 08:18:46 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BF8E21800345; Thu, 10 Sep 2026 08:18:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028331; 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=CDWpJWz98S4CnlFYT2V7UF3heqb543JBoMufcla50LexdDZx1fOSJ7UbijxDLA+bO5bobA q1AkL3tKmZKFwLDogSz/n4xABylKvzAba+wpHQd3auubQr2H8gI6+CLiEa/wEOLDT4JXPY Amqn7FEql0aYcU25oohrJ8ZZOfNS47A= X-MC-Unique: AdtHw4lrMpW-ClpKkTPDnA-1 X-Mimecast-MFC-AGG-ID: AdtHw4lrMpW-ClpKkTPDnA_1789028326 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:43 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-15-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeop1O+6TP+Yw9NcDKEGi30Q4orxl5Y2Sm96 XK9hJRr01qJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5VGAD/0YtqW2HqWVthRruvRPKQRcWphk8eH3dVmVubRylmTbIhzxjbDMUufX2x4Ieu6AthcKc1C eByXIxqRPgqIQxhPGeX6f7L/3ENMqrJ6TNsHDB/eszcDTESAB57EzKS6nh1dClDB0m4G7a9rxeg FaZj7u/mZ0MkPtypI34io/Xg26mMXGSsAV/qTSLL392xI4ZTGjHMxYl8oJbbK4oMXCkJBqfubDX 5S0ffO8RxSSHS9p73MExWg3Hfl3RR9EIFYiPNT6thgEFujeRZJT3tg2vyqpQlrRqmi92Xvpc+Tq /wVI2WI/YAKrKUbCEpKG9x2KbnoqjYx/4iari5HpRjaIoVV7cQ9jCtWwe9fxyxvjLrNWnZu3apO KExhMSObUtx/LVeUdluJ+l1usEHYY9qStzT2Oz8V+kwBOEaqkxxUBlrgiW6KpmUQEaFRbMNhaS4 HtjyOUSM6S26NfH7nQvOnBnb0GpiPV4h2MZC5Z69SAxpO3PgZj7QnT/mEZcDwn1ytYWPe6RiJzW 2425P9hXPCs1RPUSUMI5wzyizCy3+9IG08a6Zt0SGD9GbCp6NvzwzWbi0N6gl41ccRzfRZHWTrY bhFjN7iCZBH5SvTY1luJT+U9o/8SiIp30qE9dRp9Ak4MWac/I3+eUMbCVaLRL/GVVEBteebvZqw u+Y+fVOlfnFsE6g== 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: 1789028374244158500 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:48 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=1789028347; cv=none; d=zohomail.com; s=zohoarc; b=BPXVlo2KLdcrU8zcWRGimXSTt/de4Mi3aTjIfdJTkB6T050xlD6byoTjk9se45YiYKU6X2MzScwz17mL3wCcy0KY4C517l1C6Zymb+0cd+qQRqEw/99UDQtO1o7T8U7AcEwP+j1W0TmP+Q2B/4Ga0mwmbmb4QSGK3KClf9ZTDrk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028347; 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=KzDAusuQBsHURzI28ldSh+/XYMtyJTjKLssuN9IqxHQ3BDWWZIKyP4ELQRnUCNyU1N5w46ByOANCdJMo8w9bIA/BI65YoY6eDFP33K1pupDSQ4ViZd+in4lLFFp9g1hXSGRF2PMuDoHPw1LwoDypI5ZfWI99v4vasRRIgodRd+I= 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 1789028347725815.2556258539598; Thu, 10 Sep 2026 01:19:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4Zzm-0003kF-Fa; Thu, 10 Sep 2026 04:18:58 -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 1x4Zzk-0003Zs-UT for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:56 -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 1x4Zzj-0004w8-CI for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:18:56 -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-678-BTjBcueUOcaw5ZEuU0ce8Q-1; Thu, 10 Sep 2026 04:18:51 -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 7017D18005AA; Thu, 10 Sep 2026 08:18:50 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3B7C51956040; Thu, 10 Sep 2026 08:18:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028334; 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=V669OF+jAbfGH5aSlmaafGW9kHdsTL2K9jKwXyvPtnr4NSKXE6eo4IkPlkXP1TTXea7E9m QzS9k7fBvAd1kurv6INehY06IPvQ4ZXnxruFj2brNkj4a9APRSPW8xajPfQ8aIrN6loQ1q f866OziUQBQPpNN8DP/Lj6/3JwrhNhk= X-MC-Unique: BTjBcueUOcaw5ZEuU0ce8Q-1 X-Mimecast-MFC-AGG-ID: BTjBcueUOcaw5ZEuU0ce8Q_1789028330 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:44 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-16-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeolQqnRjUuAvA9/FgS/DbhRxjHZWi6OP2v0 2sH3gHPVs2JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5f46D/4u9Sf7FMdgnmHoQ4pzbDnsArDqy0w13Tr4Jad8hiV9ZXTV3r/J8BOMJafO6rpxbMaYL8P aFIoSf04mKjSFpK96I+qHbWqZiOcIikEjBOgXnrWkQC4VmkfsFyoq1iAB70Wv1U4db9OLKk0wXe ssZ4T1fWAPJ2o5HSqaaMqfw6AD4j0Bh7tLsgI21+ODO61O0pC7q8bvf/KzacEaEFsB63LCxIxtw EAWCcqaUR++9SQ/abUr8vuCwU9fz/vZfQY/ACLxuHrbPezoC4zfiNRiKoEBtgjqS7o0wQrvj+Zw 9rSg95GIpV/UJdBCn7G4A008ugd4pWyQLM+M5pEzi76fHk4Un+eR/owOZ9JwcPKl6loBUCSA3Y/ OgPe+vV441xN/jVM7ArYDc2HKAd4fDhw+pKBwDqbNoJ0DcZjO2Q19T/KE9ZvNrrZydSzRlIScXI 7AZTK0EWbTDu23hwReT38Slo6w5zB4fXn+cn1MdG2GCqzbafkXSZYBbvBOkDt71VmaUz28IdlTQ twoYl+nBqWvYpeNBG1KmtswqIhTUjP8ofpQKtf+g+5KmzZt5J7zABZCzhIRkBIhz80D+gtdLOic 111TO5ChO7fgs1aO9ccNjUWMl2TQtZ/cERwYkRnFmqW/iVr7pIG3BpS2kxn8Y+FGrl6Y24J3Lhy yTXfMTHdHGe95zw== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1789028350062158500 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:48 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=1789028429; cv=none; d=zohomail.com; s=zohoarc; b=WhzbRuLiXAbos8pPhAN9+pKlqZmyRt9p7wq8I3puhACUkabtK5RaV9HBnPm0QxoqqWy2p3wnVTBiXzLmxJt45PJQsUlNjeYXMYGKR9u5gtvQV1RF6ca4WPzt+Bxbrfp33lP6d8SfuRRfGAaRcB5O4td23qPZX6G77ZL+03Pj89U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028429; 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=jKWfqfZh2Io1MOWHKLqWmnwYy3AIILRffdsw6+stHX5UePHS8CFvjTc5fLibD0IIAr22/k6WHwX/IWC4Fg7Lq+wY2Xo2gkfwWvFd0eOWWehrzHnSEWBBlRVCUptofNRlm9g3OEL10DmuPg+beb3SMGF+VPaSmkdBcAU67dot2/Q= 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 1789028429891699.5851595664649; Thu, 10 Sep 2026 01:20:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4Zzq-0004GF-G2; Thu, 10 Sep 2026 04:19: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 1x4Zzo-00041i-Of for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:00 -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 1x4Zzm-0004wK-U8 for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:00 -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-pZTF5j6lOlmyFLp8lNEmCA-1; Thu, 10 Sep 2026 04:18:54 -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 A58B918005A3; Thu, 10 Sep 2026 08:18:53 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D6908433; Thu, 10 Sep 2026 08:18:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028338; 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=T8IOIYLcY65LPpv3gAg9wjIRm/lAY64cZMiEl8Rx1Txdf/1ziBwErTQPIvyt9d9FBq+NlB 43HiooqFF2hyoR8UEhQWn7kT/43RVIGTImWfNqgJjr/raXP13MOJq2TIVuOIA7//2F/6ej fx7hqBGAhSJ1ikkVeQcYtpGYWgcjykA= X-MC-Unique: pZTF5j6lOlmyFLp8lNEmCA-1 X-Mimecast-MFC-AGG-ID: pZTF5j6lOlmyFLp8lNEmCA_1789028333 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:45 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-17-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeoho4FI3GA51hWPtPaqBewz2poMJv/YHD6A FZb97kDrM6JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5a/hD/4r4zuZFcmKWU3ufnOV73KOdm0Z5fcQ5G80uZWF/94URAy8kYKD/HvtT/h7nSmmNMpSZSX inBhLtmbjTqN9CrQZBFRTO0kSMgxc+CXkAR9gSs5UPRTdEptAwBnW0SZHmlA/cvFan9fhvHBNvZ 4erayay820OYTa3rs+ILqzZ/x1AsuS/4OTqlBeXqP+vxLIhCmYUUsUUjvvmLL4b+oMOrWlNHFdj 3Yw1ZC6ZZaiepri8AcFG/1I5YA7xgGV+bRuPq9QE84mMaXE+f6HPePxkzgLmgg1OwsZeaGREHzp lgm5PFo+l2KgOCJN8/JlDkMCyDeJLL6vWr4K9TgHHlaB8w05paGxu004MpP4R2jva+giaCIgKaW K/FsmJ4GJrVqZ7m6fb4Ig8S0DzoKsBRjLXLTT86tDPhbhHXDbnr+Do7A4shzNaQcDNLHn7WKLDr C3IZ+Bzvm/0xqq8caJ7sOmBsf8ikFsYwEI4pXZ1zgV9EPxPJGVgyDyre05G+2bai08cMKBAidly 0/VOosc8KSvB7EtiJVGI4fyEqezm+THAw93nEmF2/qc+bj001Un1bkRZRmkWkb1FOiZbeEnDhUT Jplti/mNjVrzNlOpKLRpFDZSevR5Kgpga/Y5i/B9KefD0z5dFjGecnayaXtOxj5fcQwI5k8A1pC YR9O0ekXa3jyGbA== 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: 1789028430521158500 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:48 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=1789028423; cv=none; d=zohomail.com; s=zohoarc; b=QFdqAJD4MeVn0armI++dg27dwAB1DQAyadXPdQkAHOI4X2KbSLSxSYlwOWqUtTDRICb+ycWr3sZcMP+csxmZ4QhRKa5iE+1LPukA1tszANVvkwRXpAL1/3OV4RTBwfYxiL0Ov3pTK6r/7iDY8/GWfSJJlMeUmCeNPNPOVZPS5hc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028423; 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=lEQmEZ3pQuBl1lKmOCqM1HEMSzOInNM5NYpcvOjZr9PgiHU48A8WRH+hv6GPEXvsvKEU+WZ/E35Hb1ADaf9U38JSSzvKYAeLxQIvOCyIEQf72ZG3cF9l9co41RGxBVDbIzYIFdBIDUPBpdMop9vdm2D0iW/nQ0Gaj0JIrYUG65o= 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 1789028423393433.56273217192575; Thu, 10 Sep 2026 01:20:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4Zzv-0004wD-1W; Thu, 10 Sep 2026 04:19:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x4Zzt-0004je-II for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:05 -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 1x4Zzr-0004wc-Sa for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:05 -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-96-SHMaM6QaPhKd_5YyP7qcdA-1; Thu, 10 Sep 2026 04:18:58 -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 7D9F319560A5; Thu, 10 Sep 2026 08:18:57 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3FC2E195608B; Thu, 10 Sep 2026 08:18:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028343; 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=Of3/u39V+k3iaygsoUKYuW/rqJOB3baEzkS40hXO1wN2TeqlFcqT0ilyeLOT3AEBSVMdIp FlvWceOOZ5qBt6FuW2OB9QV7c65GJSLP8b9Xu3CDGdEdcSK3eO+6ex9yvVVZs1X55vKyV2 60lHqgqtCzZVV6Q5H0/6Ik1vxShH4eM= X-MC-Unique: SHMaM6QaPhKd_5YyP7qcdA-1 X-Mimecast-MFC-AGG-ID: SHMaM6QaPhKd_5YyP7qcdA_1789028337 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:46 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-18-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeokukma0luU/rP4t9zcnL4BpGVKxBgFDsGH rtejOVXAEKJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5RmuD/9aHUNUXCNzsXuQH1KtVnZB9QhkWVrHqtVNgmo1cdE7VSKU+rlVumoQsBk/M0qKfP2oGRO c9h3PzVCA0lHpq9CKEgzEJJrX9HeAIZ/sWXXEAAV5AKyP22tPtgY/+y2zLI8YTuCh5u39806VBL ReeAv2mdgoCUjLZ/GMUKYU+glSKiFVabRhUwuoY5PXY1H+3zWSXoc2PFJLuJdBJGmC12XJkQ2/7 3B65TK5f9zo8m3ZKSBk1UvAYJ013zQ7Af2ud/Jj7l7RZZj4BGQh/ICuyiHHVqlZL+g2/Qo92q4j GcH0IWVdK6hD0XzJ1n6qA7lTJ0aFZUByzVvLWqpJ1mWTifUSH9130g+68SIDgqvZuBBIdE7Kxnj EOIeh1oQ53ZF33t3muTjsDrt+W7DN/WJVZlOadKVp0gpdTy4/UI/H9nWYOZyTw6+EJM+mEcWaih 880ngZVnkLa5n0x+GsrgAHDn5qtbFiZPordCEGRq+iEHNdG4N/ktZFWFr98xe7UpHGRwPfLdR01 krSKdVWylKa/L/d3v3DlwGPtkmRpsj32m36AgI6bGZI/QncTTllQDbTgNig/aZwANbR5MwS99JY JL8XRD1mr9TO70KlGBPt3fqxZBJ1fTfGJiMC76A5bpxOT0UG3ShoNUYsbGZEkU0CQSuxSCmvSk2 w/dESTU022A4mLw== 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: 1789028424513158500 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:48 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=1789028409; cv=none; d=zohomail.com; s=zohoarc; b=OyD3/0e9tgytLoQgGX+go0/u6AycOfoXfjPrJi2+RGy/KAjBa93dKTsvkKi/ENCUXCazDKPgRLNFzDyH7LiC/69Uf9OxBA62ikQs7IWeAAR3/7i10hLVQ1YHndrme6cXVW3Ni6wAVFce+2HpkaVMdZJtOqOCAQ/pu18Q992ue78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028409; 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=Qzuszcrbg6cohD5Tu05YF9g7VRkT6a8sFno1QxC857s=; b=I3V0SI5a8ezkfWAdf9LQrywX6yigyxncaaZ79/4rSIlmMXXsMJ8zkBxZjgjn+tTOfOhINdHGorSnf7TGq7Y7QHlKzIC1Qd6UeKAdvZ2tLzSA2t+fw0pYvDx6ZezB/Cock1bHgKDmPu2kNIHWTibxG8BoVCQeigt0InSrFQ253Qg= 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 178902840980360.41063719483316; Thu, 10 Sep 2026 01:20:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4Zzx-00051x-Q7; Thu, 10 Sep 2026 04:19:10 -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 1x4Zzv-0004xD-CB for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:07 -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 1x4Zzt-0004wr-Rl for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:07 -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-688-5oNWGusKNvCp8tRYXUagPQ-1; Thu, 10 Sep 2026 04:19:01 -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 954761800589; Thu, 10 Sep 2026 08:19:00 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B8AE9195608C; Thu, 10 Sep 2026 08:18:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028345; 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=Qzuszcrbg6cohD5Tu05YF9g7VRkT6a8sFno1QxC857s=; b=EE2P+evt7gU0+3whnOrdY+/bnd+519kFmw06ovMGURfzPkquDZLDW0WMCDGV/oEZDBCn6i hGkeFd7ZGQ1xVFIuoIX0wjoPMxhnJynlzrpYveHUGN+FuuExIsrHTpneeML45IsWr8gfmw afVIo4ekAzqOviB0FlPxOxFNolw7MeI= X-MC-Unique: 5oNWGusKNvCp8tRYXUagPQ-1 X-Mimecast-MFC-AGG-ID: 5oNWGusKNvCp8tRYXUagPQ_1789028340 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:47 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-19-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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=1ZzvdpWhDv1qIdQGLav3DavQ9DdkXg1Nj4VP5JBHZlI=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeoQgpct7O/gE+X2nQD2aboAAVji/qQgpy3l mcFRPInk7KJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5SVGEACkuXtEVoKu71nb/6duoBi1diRM/KluG2UnbEd8515eCY2mgCjzxz3iw5K71lqkit+phl3 Vh392PbD3AESULvPVMJxSP6XtBmplvR8TuR7TYV1GMKC7qSEYrsq1l+GgCalj5c9PiZRsC+KlSJ aHlSTx/z2B8hsi9wMFZGwGz1r25Hh+QGPZ7eht8j9NuCGdABqRaXqfbKXov5q1LqT8PSIyJhsd7 8w0MrN4rzLpaGutfSgRAUb/U5ZGsX75meQmav8/HG9GyLbW0dRzvZ4usRrqrWxCUQbujW/3IE5n 2MVAY1CI42/6IIa+EokJlQ8jAOyGXn7VJaJhx7zuDRGZ9e2Bq2ADya7g5wxNGqPPLw/HthufYuB 4v0z+lYLi69QIT4RutJwhawunTIIWA3J/W41SZntv3r8/v2kR6AXQvzSHKRC05XrlSn63v5HycK 712p0eKEjzMsBia26ELdfWlos3lrmj1uTHgei5EB+oTUxvV9zctYJAz3vBsQkU7BuyuA33Uikcd aO+Aa5dnci1uglSNC8PAZ00hQFC3QEwqtVF5N3qlfgyS0om/izb6CkZ1MB4MH6HeW0w0pCUQZ6f 4rT1dt3mv+MbzXc2W3zkfmajByGvuh8NC9gX1cjG3G1KxE1Ju/Yq1XA+m+/JTLW8ldUtV5NGMhf ZahhMAuF13Zi0MQ== 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: 1789028410415158500 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 0e43eacca406..07349c5c5502 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:48 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=1789028419; cv=none; d=zohomail.com; s=zohoarc; b=E30RaqlDJ7cO/uQd5tay7X4wueHuBX83uhsK4xFVkqCoKkaIOVxlZK9ng+DaXKoF8aTl249juVjJd57dq4Uyk1U1yTvZaM5PCugzAafjdk5grbNgMIDUq6f95tQ1ZYyxFMe+xQ3v5bHSN4MYbL1EASMI8sfN/5fHAAaZwA4/qis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028419; 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=P+LJpzE+RjjkgYSeQKJ5RVT1MCyaZWX7PVm9AyyDt/g=; b=TiNr7HLVpwjIdOeUMPZdXICmB1nvTmyU8jsw8deMTK5IF/6zHuTvTUMeTUIMLQZvh2sy3kv4ICO+E5i1C6kX+3oS+RPOkXugiVhpCpzW47kmjkMnd2HkfLDSln5LlkUp57/49pXbRSECP708z7x/+Lgq49ghD1u1ZbfBSOc1erc= 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 178902841947171.47563269154591; Thu, 10 Sep 2026 01:20:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4a01-00054l-Ve; Thu, 10 Sep 2026 04:19: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 1x4Zzx-00051y-CV for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:09 -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 1x4Zzv-0004xF-HZ for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:09 -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-quR5506ZNeS2ggOMlB_HvQ-1; Thu, 10 Sep 2026 04:19:05 -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 956E9195419C; Thu, 10 Sep 2026 08:19:04 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7E5CE195608B; Thu, 10 Sep 2026 08:19:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028346; 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=P+LJpzE+RjjkgYSeQKJ5RVT1MCyaZWX7PVm9AyyDt/g=; b=Ke0dWo0t2jQ7+VziDCX1IpvpsYm9pDKb9d7KQd6iR4PZzlVm6LeC8zDA0eVjifDF3ukP0R ms6JgOGd/v8Ttobtb3g3Hg04fPlfJ3QiXb/kgWXSvaR1C3YFzvP6MA921RhS7JJQHP6Mob FjCcBbGVX7TuhRW36XJIUBBkxfGHpyw= X-MC-Unique: quR5506ZNeS2ggOMlB_HvQ-1 X-Mimecast-MFC-AGG-ID: quR5506ZNeS2ggOMlB_HvQ_1789028344 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:48 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-20-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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=vvVc9oWVlWehPCOEZBNwVLPKhD8ajquNxr7NNx8p86Q=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeoRzt/Rdx2/hp6kfRVamoQEsGK8MyJWpJpv GEHhFfOXm6JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5bzGEACwHOsvif5RiZLlUxefhNCn2gNDN09FF4MHciNwF2fSCQqg9gLkQevfGx5xVtN+3tBz2ey 99evedUNEsunmDReEVKBvIumAJkiGaDkkYd9OaMCVpf//m0ySgNfY9YzGjKMp18/GuhEGdAf68O vaUoV+kFukqhvJPFktHpFEYpVLF5btAE+GGI+v1azNgiQkc6jd1Psl4vJsLWsndP57W9Hi+sb6R k5lAHo/I5zpd6iaUQjL5+jLspwhRQJQ3wU+T4vtDfR2v/HWMBbojoP+2d6hOix1mGZTkFMFb2D0 LlhaXct3Tu+seeDQc9jViP4Xx5kJNBndiJAM4MWxDmc2fRn/nyuw14+rMYOc3XoGsj5rOwRHnzX JAVs9+C2Bn1gZyscNSx9NPZsmV5RpHuvrc7YmEhSgPdG3NJwdFI7/I84DfNTULDOnMzWai3swEp 5AjLL6aaf5hv6vExO+H5wNyELttveBnppgsUx4kgQ54ElVbdm1nIyk7AMofIAOBakRhItwpGs5H oktLBnB+XxlCXcMXM9c6P0a7O2gJPGO73cYAhwqJoadhB6LQ+4SR4dVEn/v3J0ANXYUaEis96Qb +heD5u+eJsV1ijSXbW1+KJowao709ct1CuLMW7uEFxAC2c2eICg0W5Zdv51N66BkUKtiaETEvsA JioQzZalndMkUyQ== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1789028420539158500 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: Akihiko Odaki --- 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 07349c5c5502..9ca7b946ac65 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; } @@ -1430,8 +1429,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:48 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=1789028376; cv=none; d=zohomail.com; s=zohoarc; b=nhdJPpF79UMavXDsPWLcHGVatrvqON5s3rfhd7kYlkjdbXy6D29VIAft/yiaDUSxzis19744LI68m9JP5wIkDAMYggLDH8XNFnGrLdxXpGyAbqpzrYGPwKoU+JVenIFigKRHA2Xe3tP6T0ETtZvw2K4Dxjg0wGR6xOfVZIs7JR8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028376; 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=902u+6hgzHqWrogcJHQVHdXlrrsugRKXQmYtn6d7nPM=; b=DNs+O/Y7OGUKfq8mLkDp8UL+RTZ4chMNR9dJVA5iOEkwK6hO5urPEjBZ4Ha+NVjnOLsw8/+Whbmn+esoLRH+g2DdbDtLVhh243fDjyVEYfpMvZvpSL+hEXMa5c4OOwB2K22dSxPMc1Xzxw9H80GPr89GJX3U+nXneXuDT2mxKFM= 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 1789028376461316.739032660288; Thu, 10 Sep 2026 01:19:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4a06-0005Lq-Ix; Thu, 10 Sep 2026 04:19:19 -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 1x4a02-00058a-5w for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:15 -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 1x4a00-0004xq-0l for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:13 -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-488-FxK9E4S2P76Gl4P-aymjWA-1; Thu, 10 Sep 2026 04:19:09 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6107A1954223; Thu, 10 Sep 2026 08:19:08 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CDB931956040; Thu, 10 Sep 2026 08:19:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028351; 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=902u+6hgzHqWrogcJHQVHdXlrrsugRKXQmYtn6d7nPM=; b=Oud782us3JT+R0olZcsy112n9OKJQ6fCq0iKERNKmR/BNehEppHidYCtHQ1IZYvDAoN31d xue4u0awqinZ+JIPFBsVKe4jhI1saHIIq5YU4M09u0sXUXz1EbXsNJ4UhRTS4H+VGJ9YV3 HXGnR2KxrOKDOKwldgsqKjNT5cm2a1Q= X-MC-Unique: FxK9E4S2P76Gl4P-aymjWA-1 X-Mimecast-MFC-AGG-ID: FxK9E4S2P76Gl4P-aymjWA_1789028348 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:49 +0400 Subject: [PATCH v4 21/24] virtio-gpu: minor refactoring MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260910-virtio-gpu-cleanup-v4-21-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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=IklnvtowgSiW7XcZhDXrwO6dFmeBIZQTUPYB+WJoMZk=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeovZSFXAFrMTlyl1U1lfRraHcAZkQkaRn+B eaiN+JvQRCJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5YjSD/9JfuTrZMLUbfgX7cSw4b+yTvTEC2U0L35rfdn2WdHayo1Z8bOj20WSPb/SBapXEm/Tpeb M/cg1TWYZ2Fju3cfrc6FCuYdyIK2nlLLrNyjwQqDOqNnzis8tad4I3U8FGWm7YQel7ag7+ts/IZ pyeWezLYX1NLDAD9Wa+L+E6HrdRROSFMyNo3YMPC9npjgNIJf/wV9PJt6ePSl/nEanvyZP1EGcU xpVykYhkMhf+yqNsyI9pLuD6vyw3xAjjLiuWC+aCd0leZXc+3ho8nmx4A3i1xnDBQqlYWgFb7lo H06Z7odlJ52ALE1hZxxOi4pBGBcabziw4s3F4wRJbprYTI3XZmUCleoJ90LEzc/xkyZgk7C8TOE gEJsm89Wwtk89nSexzLDiZEqk1VC4rx6Zso8Ass3i1zdiZB1i8ATp6O306CHVVazFe0JUgSXPU9 La2loOcNrBdV4jZrHXF6+N5bQIfg9ygUsVCpW3WRUImQs5vVzs6aHaGkx+TAf0QnMtIWz6ePaU1 kHYFRmdlsIH2cWUlhQxxvNGzXoJEMb3EBhVFd0oO1r8uC29VFrzKOZPTUzwcLI6/FQOA+JPEWLC 8TwlqyqCfp6a/Dt7LOQW93w/PUfPId31wl6dvk8jgB11TWwYq0q4elnklqCLKbGRLl6B5B8nMrM TQTxrAyuW95enZw== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1789028378185158500 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 9ca7b946ac65..439a6e1c1cff 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:48 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=1789028407; cv=none; d=zohomail.com; s=zohoarc; b=Y2TutoR2+HhxWFFFIMM0IBfEAlulzO8mkPeUxaMxHgt/FQXpKe9zjUAbdxMD4PQext6K1nYdUMMDuFxc3nGH0NO9wBOYRCTnZTIapGWKnN/ptW+mqNoAKbjmiXxdWcO8BGe/9zig7gG6HuovZWNWnutFc4EzdYVBee/Eme5w29o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028407; 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=ciD/ZVt5jW5QMxT+f6uRd+L51Y2xcWI2H63rFBdrxlU=; b=CIn3CtmENo+peWOiikB5y8gp5GbOJap1i5WO/iAro9R15e69cBCY44kfUq3hnKWT/AKqUqro0XyMyOSLXChU0fFob5oAEOvfXA/tObizDRduZYsczdhiMmOV+Mj1y1Gy1CGKx5171RBulLOUEVHLEG8XiT2saxBgSY2CBnun2+o= 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 17890284079851017.4256511687796; Thu, 10 Sep 2026 01:20:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4a0H-0005jU-ID; Thu, 10 Sep 2026 04:19:29 -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 1x4a07-0005Si-Ra for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:21 -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 1x4a05-0004yU-Lx for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:18 -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-214-MwPevmj1OF23JbzIZzddYw-1; Thu, 10 Sep 2026 04:19:13 -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 771611800644; Thu, 10 Sep 2026 08:19:12 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 25C923000239; Thu, 10 Sep 2026 08:19:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028356; 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=ciD/ZVt5jW5QMxT+f6uRd+L51Y2xcWI2H63rFBdrxlU=; b=J2UmvH0Lw8qazesi9m7NLgwXQJjNwbp6OM+gN6c25ng7Vfrdfis6vtqfc3s6r59pGiOzeP a2N9uDF+OWlFESq5a+a63xOPgRwcuMpqdS1/E40mqeRxiVmGkTMqN40qrL6EFrqqLV8V0C 5kzEKFq5gYlxIRXiDeaUYD+4xQ5RsDU= X-MC-Unique: MwPevmj1OF23JbzIZzddYw-1 X-Mimecast-MFC-AGG-ID: MwPevmj1OF23JbzIZzddYw_1789028352 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:50 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-22-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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=n0CW0Sj52YaRlzK5eDiTgnftbv+1PgAfeZqW5A1Onl0=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqomeoiubOJm69hZsNSjfBPxXm5wyYr9SFDO1yp b9NmiQe4sWJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqAAKCRDa6OEJdZac 5T8fD/sFPHU98fHx13GVRmJr5jZ3TI9AAALVXmxYcWJEOxiGNonEMheUGEi77iKQ1QNj0ajJFE3 gd8JRRC7VU9XO6BOqU5rDu8CYNnRWWTTo0KJGN3TEzgp/CNIQfqh29RqaZnq+eKQ5QMzhnJrp+4 AIjtuSX+yuyoTaSsUjDEEzJpnVSySokMTyrMTwpdwxWfKWfECUKnwUJQWpRvaukGbR1IRm6tPZd zPs8dYHmACddPLsYEM8rUyFzyOYJcYcYH0R5LIMWiu+neZ1cxkOiuH2FMkMC84HENtEcv1YDE6p t1HHkGMN9Rh1yD7Dc0EIBa3aattRavX+3LZBCK034yQ/0jvMX/GnWwt4F94fN28MkVqecW5d5g0 le+ha0Zrscc2yAxk4IATYAs8Ja7nbugMSgMHvVB23kTIeWOgvpsPGzzHJnPpGB5664jd+hlxMDb QyMpa8fOmH3/sDDMsa0aEbifU4vKhVur4ldCJMlhYjKW0SNKSXaklk63CacEEOKLNHQvKkT0EfN BdXjbbLH7SJqFZbUEyeTCNzok6qVwld1TLPp4l12MKW/M2HzJbNc9mIyM2Rrvpad6D0CAVY6mur KEXlNiLNTbLpQIXtZ2g43ticwcABTk+G6GhtsVeOuAANBUhgUF1GqnKRfbb68GVPR0T/vMNInl6 zoSfuTQ3KR1x2uw== 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: 1789028408446158500 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 439a6e1c1cff..494be3fb4f8d 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:48 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=1789028398; cv=none; d=zohomail.com; s=zohoarc; b=JHgt9+OgiFamJKNYoA0tmfGZd8LmfilrMvDMnXm1VUjuMr7PWC25p2OBjne9pqqZinhG7ZQDknyG1dO299OPzAX6tGJgG+MS6ugJQDY2AUg88Y7ruHj39+qXEFotBywnxBDUd7rIi0SvWUgS4rbeQU0uqfQTRdrnrvlrbWijV0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028398; 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=g9Kx5qSQU4ebKuH6Hjm/A0uLvdOMWD193tpaNLHf8To=; b=JVv8XZYWP4Qz1Pi761Guxxoq9fu7qpMhDDpFRXo5HsMK02yIk7/ITOi9SMAyru19wgGCPJYeuTlncpcLsqJIqSQzXPDxG7+UuZGw2WUSoLIw8zj4qPZKvZN/24Ru+rwtp7X/C+Tpz/9KlSmmeYJD5C9aDzIHglE+Rb9KxgwDXJk= 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 1789028398044898.3667248696185; Thu, 10 Sep 2026 01:19:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4a0J-00061f-5m; Thu, 10 Sep 2026 04:19:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x4a0D-0005j3-Qo for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:27 -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 1x4a0A-0004z4-QV for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:24 -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-572-Ct-vRP3vMnyjpNd1TRFZmQ-1; Thu, 10 Sep 2026 04:19:17 -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 ED02F1800592; Thu, 10 Sep 2026 08:19:15 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C6051434; Thu, 10 Sep 2026 08:19:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028361; 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=g9Kx5qSQU4ebKuH6Hjm/A0uLvdOMWD193tpaNLHf8To=; b=RLHSMhyCuA6JHqwChMB+Qn6k43GEbzRSeYpl8EmI7+HFsKV8k3aAzXJbkSq45E9c27T4th ePa4KUVTxNRXNaIFHBPl4TyCCdZ1HoUTzFRWkgVtZQQrLaX2JjZPmxg/MM4ZXUFsI5hc1C 9HcR9BCgEYng5XyNpVq5IVZXI4RpDAw= X-MC-Unique: Ct-vRP3vMnyjpNd1TRFZmQ-1 X-Mimecast-MFC-AGG-ID: Ct-vRP3vMnyjpNd1TRFZmQ_1789028356 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:51 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-23-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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=J1s4r73v/+72Pe6/xXLo8NJr54S4WEk0Ssl7lo04RCk=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqomepE8BCvJMGq5jN+V8x18coISvqk5906rGWN t81lNWwxi6JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqQAKCRDa6OEJdZac 5TRyEACnwDeAVUwE7NbEnG9jYJM6PcUhryAkNCf9CElOVCAddDFNKef4i/JvwdWxCc1VN0ybYwZ tS9bzNj9T/OcqrMVVF/OPZS79Hs8j2KYsT/gSbJMzuA/SOqo2pT31Dq53vFxhPWAjYlAQI9PKT+ wEfwA0GNjOkeh4smebStRv7l6ay4FdtYmc/KCvndqG8B1AeGhXG0BCH+oZOXYyJEmGkKZgEEZVm 99DNAsNB6ZM4q940hMCFiHHkWpFG/d2VpuzFI8n1EnXskfLKY4bwWQaznCfcjYiWZ/Nxxmx6FaW inc0iQaRT23DmJmLhPxxyLNerpFd6CYqk+0HSQKeFN+URmCTB04RfzmXMVRzq8NkjK+NrJKKN9k wPOzZiQj2YwG2oLPXNSGlMUvQVZXwStBsxc4TQRguAAI9Ea3U5hlxf0czUR2I0m8JPyi+7RSRof ckkCEwedI72neggx38OXCBLMgumd3aBI8g8hRYFsiRX+qjpGWIda06F9Y+o9yhMpVQuptKCN+In rF4kfxbHORbFDFF8KF7GO6cvvUd90PMip7060w0RSDzlJPKaiPl2VdgsqGMw/Od17Sn4TOoHnO0 vOX3D27vhPQaL3AaC34hMeU1rAs4cW8sjkCNHvXcgC5+7HRMUyqP4ULD1QdAZ0r48q70VTeekO9 +l40MF+VYGRVVEg== 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: -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: 1789028398352158500 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 494be3fb4f8d..1c9380e2a6d2 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:48 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=1789028386; cv=none; d=zohomail.com; s=zohoarc; b=l1p2HM9vQAbOvp1yoHz2nLNm40DjDGQN5N4ZhdDbMSCmjeULS6a6btbrFFmwKiVGEDnAIpFTy62skbDZaYH2F3isg+ORUb3fusPCN353wGTW26V5BAZ5XOeBYGQE57AUoGoxWawmJgGFr2qPH1MrMo5y7UC4522VG1XQ5CcY6m0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1789028386; 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=gmI1I8Zdxkrl/K8DZjJBvqL25vtrIMVOUcPcWpG5B4R4W9qJc9R35sy0q+l/XDmE6mZhC5esQRreZD0t+3vxqlr1iqKcztx/HFMbSKwAUS7fLcOGpnw+LxLbKC6JpjXgq7JZLgLZrcqYxT2rWy96RTwz/eGPkPGQ4i1ULAE7x/E= 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 1789028386225857.3682348134334; Thu, 10 Sep 2026 01:19:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x4a0L-0006J9-6B; Thu, 10 Sep 2026 04:19: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 1x4a0F-0005nO-Qo for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:29 -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 1x4a0D-0004zW-Iu for qemu-devel@nongnu.org; Thu, 10 Sep 2026 04:19:26 -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-231-fdTz8YMeNQuilF1w5MwYqQ-1; Thu, 10 Sep 2026 04:19: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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DFD0D195423A; Thu, 10 Sep 2026 08:19:19 +0000 (UTC) Received: from localhost (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 86F82180049F; Thu, 10 Sep 2026 08:19:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789028364; 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=STM5A3HiP4cJln1fQfPljPcb/hvGWlRgq16s9l/7LDjB9Evn2DiKl/RlUumEMn4f94k021 QcbSEkUO5OC+mb02YtWm0WQuG4XYyKdfwslAlXDuBnGioPK5r0mOpSGbzA/Py9p/5jSqv2 RxSig+lOAPOaH03A05r9uWxJFmadYxs= X-MC-Unique: fdTz8YMeNQuilF1w5MwYqQ-1 X-Mimecast-MFC-AGG-ID: fdTz8YMeNQuilF1w5MwYqQ_1789028360 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 10 Sep 2026 12:17:52 +0400 Subject: [PATCH v4 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: <20260910-virtio-gpu-cleanup-v4-24-7d623714bd71@redhat.com> References: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@redhat.com> In-Reply-To: <20260910-virtio-gpu-cleanup-v4-0-7d623714bd71@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqomepbvk65y88pSZ+4xruouIK47GPqqqjfAQZN awxhypvVwCJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaqJnqQAKCRDa6OEJdZac 5bbTD/4vKljmc0UqjIYLaclwkSDlHgjjzgwHNycP38pwgjnpcV0S6GTsndaeeycKZeqmPegEkND eagOZY3DeJd87KwyBLMxYNRCL46VJDBrlMHh4e3GcS0zKVY/Z1sprVFq8FHo5/R8Hj9tjFtINia O7eALUaklv9ZVludJBFtZoYL3GreY+GJrW/wSijzK4hIpGWyA0v8SPj4sZRB6XFN1RILsJ1KK3E Sj3sKdDnFlWuW9wac5xDanek1nNbfj3q2lP9jcCgK+5yvY5iCbREwKMrykd4S9I67h+QN0PlYeL taAK/LDcYLIKUWezOWRYj+9QM26wJ1UHKqBVPq/cOtnZ+ri9YWC2XmQSlcDCo8IE1TWYWYBXpbZ KQbVqFFwVmSn9jXy3YapkBt7IDWkSCyo2vJmiBzAch3KWB/YkMfThYq0IejdKkHtB5BdfJlyDZ+ 7ZA4/0VXPde3NVIBZi475jX5UHY+c3VqJlZ6cfFKrX0uxtAgQKkP1HGbeMNbB4wusgNPli8mDkc IuqhlehsuMy1EisiFdnxcFeuHpGu7LEBrLcmCrgK1HENlSC0Vwr6lVJWDoqoo7GLOGKpFvNcyGg ArclxRXlkrEb4esaFS7a06HQd1rjO1KlGybi6tUK73V7NdhzT87RJhTTftimvKyX+FXdHwySmaz wd0LNEJbvIDQ63A== 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: 1789028388247158500 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