From nobody Sat Sep 26 20:50:59 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=1788527521; cv=none; d=zohomail.com; s=zohoarc; b=X//fMh50V77oWc2K3dAdjV5D3u7s9UzYzyyGP5ocU58004LYn1iP1ESS1SkwcwQk462dZtcQZjjv1CrVIknV9fc3vdbMmvWN+JVW6PJiVY1CaNlEpKInFnciQRnir8tai1N5tRhwIuu6mG28kB1KBNSO7qaN16Hbj2xaIAfln24= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527521; 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=5HEkwSuzOhXmto7J4E5NF2/noKk26U+3km90AD2jdMc=; b=iULIdcfuPvS4eCTx7YfCRLSbouUNDuyaJXKINjLGX44kJwDIcH0aJtMde41mTyb8Bj2b6T4n/YtcJW95zj6xut214kmNIaE5ClwEFkgjuVQ4KaPqCM1AZg6C3izeF7TqkK3y8ZADUo2ZuIsxko/VWlwZaGdUp8RTGIoztCzKcNI= 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 1788527521504837.8296448677139; Fri, 4 Sep 2026 06:12:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Tgd-0003C7-Uw; Fri, 04 Sep 2026 09:10: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 1x2Tga-0003Be-G0 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10: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 1x2TgW-00050M-VS for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:27 -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-586-1QTPQ1Z1PqylOAn1xiyRIQ-1; Fri, 04 Sep 2026 09:10:20 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C5FD9195FDE8; Fri, 4 Sep 2026 13:10:18 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8EA831955F00; Fri, 4 Sep 2026 13:10:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527424; 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=5HEkwSuzOhXmto7J4E5NF2/noKk26U+3km90AD2jdMc=; b=VaGDJrmDFYSfe2v3BcRfFXLSuMDsHM5//bLm7pV0QYZST4Cdk+oyZgzWffeLe9EGd3WwHd zaALmXqo83/wN6Z4G2PS1k9qe8/PP/VS/7wvdJxgDVu0idnkvqDcKrAX/2vupcSSaGhVUe a3W5mLbn9TGgcgyvyEgI1vipovHT0dc= X-MC-Unique: 1QTPQ1Z1PqylOAn1xiyRIQ-1 X-Mimecast-MFC-AGG-ID: 1QTPQ1Z1PqylOAn1xiyRIQ_1788527419 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:05 +0400 Subject: [PATCH v2 01/25] 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: <20260904-virtio-gpu-cleanup-v2-1-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=1301; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=q3zv9zCNGeUcSlIz/E/RqZ/72w8TCNyB/dnNjsQxhws=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMvctzR/V5VSitPYL48MzD+laK/Xmf0K0ln5 Y2KkCwBCseJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDLwAKCRDa6OEJdZac 5by6EAChuuk45bvy1SOENvf9nPKDgVGicwUqCLJLR9Xw0vlDUk4RUFGGuuOO6rMaV7ut7OjOxBs U1zS8BIrYKoimeWT0DsQDhZ5DJYQx3MQR8gSDQ37m0HdJmhlVTmfMJJ9p9IGUI9Ejz81AKsiUMw QEuuJdEzrkqRkowLJ3mMPgf61alGrV27o4imZM/klcoapimXjgEVg9KmYlQjTzkAgWNzVjQRCyt PsXnfUrRnNkrcX9iHakod64u1qWKX4HzHD0jxXCazh8S0yfZUDaYcvoS3U3RyaYQC4C5HYa1jOd Aw4FPGDvmkZ+rwTTDc1O9I4Zeu44KTZEA0SHTgIN0TBEBlt/5N0N/Iek19FRn53ZVt9hT2ayge/ fX34xsECQNfs1jrtatOpuweEt0ycU5cLcsbi6a7+GgQND/0L+UPH97SBK+3aADs0LHZzZICs3Kg fn8uqgo2OqA2rFYmGwqXBSQnIhy43aSaZywMO7RsqGUmD4HhJoLV7M98zgayGUeG/k6rtxlkpSQ C3idE2kqILwvEob6Dd+RFOmnKh6HlqerkkPY85g6581xPdilMnoHD/nDsCHH4T6F88NdhOhZmWA F12qYHVAdkyK0ec7I8slYG1CX/LM2FMPen5cjDPh6x6X663IrG7OqoQqJdrO9rM68QzcouLDGNq vcDjqGhAtT+paMA== 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: 1788527523366158501 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 Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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:50:59 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=1788527579; cv=none; d=zohomail.com; s=zohoarc; b=PdJsKxMjE94509C2xUC1GTXZMHqsaAK+4XnQ0OzFO047vaNsEhjTfve1HHRNb3JZOVH14aHkfMsm/rXHCMp6mySMJZXXtq5qPYJ8jtl+tZz4cNkAfzMOhKQSuwOSaY5o9VUqL/CK1qOqk4sPD+Zz9Hu7l5ynjwcBJnWf/ABoQOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527579; 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=NZVQxPXRo2Mnt7IE+v54nLLeu+wwbmLgQ1Z8QgjQpdY=; b=B5SiX7Ztx3z1Mm/S1C83UBY216dLJ7eEd6lIO/fW3DTcVaHtiEV/Y4ljaz3GIFY9v20tlkU4r0wAZqSEN7RuxVaaNVu7khaVWS6Vi9ITl6C8j2UAN8euKk55AiygOVJ9YjqiBoUGsQNhLicju8PVe2FXblXTDi7XIDoNxrqtGOg= 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 1788527579914689.0487521523361; Fri, 4 Sep 2026 06:12:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Tgi-0003FV-7Z; Fri, 04 Sep 2026 09:10:36 -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 1x2Tge-0003Eb-CN for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x2Tga-00050j-Hx for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:30 -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-635-DiMR986iPRuZ8sB517YOtw-1; Fri, 04 Sep 2026 09:10:24 -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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D1C131862D5F; Fri, 4 Sep 2026 13:10:22 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2493F427; Fri, 4 Sep 2026 13:10:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527427; 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=NZVQxPXRo2Mnt7IE+v54nLLeu+wwbmLgQ1Z8QgjQpdY=; b=Q2o0UZ7oehNcbSGMEBJncR0LvwHhboC/1VvoflKjmfUqIoSJBi2coQb04m0Gy40uu92+MV ephcL5oSH/7eJh+/cbSjwui/hIQJ0cRUNxPRdGIp+YLAu0Dk74JFlulIG2qGLnV0wbJPHj r13w1Tr7MGyUNkpS3DKeW4/Qb5YpyP4= X-MC-Unique: DiMR986iPRuZ8sB517YOtw-1 X-Mimecast-MFC-AGG-ID: DiMR986iPRuZ8sB517YOtw_1788527423 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:06 +0400 Subject: [PATCH v2 02/25] virtio-gpu: fix use-after-free on blob cursor after detach MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260904-virtio-gpu-cleanup-v2-2-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=2428; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=2X/5ilzIVjelS+4MXJn8US/LkdRyatM/dM7YRkwm0mE=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMv2Liys2UqBOQUPaHimC4oZp5BxEBV4Vkd2 E3Pz/sxfnOJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDLwAKCRDa6OEJdZac 5ZXFD/9Sa5NseKS+34HjCDQUsWboel3J7v6W6tPuFj08pdlJUyHRg6k2/8cdnlJu3dFClI7Jkf1 klA8rIsy4pJ5/LmlDDBZhjHEBlPa/RO3iaNSW7g9Q+qW27K6yWEbrEVmcRpgD8hv9TsKKE9ulw0 dkzwrH2fgdm2MAdIdVLRUNHHlWvAz1GVMEaTlH7RCqczxW47UsfsyUcq0nhFInDX0qPkdrBlkK/ c4g1I6kXBqDC6d42ksKb3fty/Q+360lmV2H1aetMiv8vYpar40RdmHG8fHQPm+xgSkG59Q2UYHF NFmsssvCtTxfBE/zhGOZk5fQN5dGqkgS3awsCYR+cnc3b8QcZRnjM2fP4YeUfpFhAiUfOU68P21 qC/89cV7GCSZLl5s9KWK80GtcJ6+47j7314zUPKEPXUKQ7Xg5iTh8W5E1WAPEBGlaDs2P+wm2/x bOWDMwxuvxFcpPVn0VHRRSV4mDzhYznY/6+3MRkYSjhGlxQmk2zMGFMqgGALAgvMVbanmOyXBGR 3pWCy5/xzGVdQ39/FgYmvIMTeBZ7eVzoIxd333hKMx77juQrJ0f80UqA0L1jWfs257gvij5n+dA hgIo8cOkQ1v1GJrPZi9iWbS9wD+PwVuV0Md90dMcVuHpQ16DEWBri74/a5iuBG8zciC8fids+5e HVTWpryFzAbeRXg== 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: 1788527585598158500 virtio_gpu_cleanup_mapping() unmaps the guest IOVs and tears down any udmabuf mapping, but leaves res->blob pointing at the freed memory. Once a blob resource goes through RESOURCE_DETACH_BACKING, res->blob is left dangling while res->blob_size is still non-zero. virtio_gpu_update_cursor_data() only checks res->blob_size before copying from res->blob, so an UPDATE_CURSOR on a detached blob resource makes QEMU memcpy from freed memory. Clear res->blob after tearing down its backing, keeping init/fini symmetric, and check it before dereferencing in virtio_gpu_update_cursor_data(). Fixes: CVE-2026-66020 Fixes: bdd53f739273 ("virtio-gpu: Update cursor data using blob") Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3881 Reported-by: =E7=AB=A0=E9=B1=BC=E5=93=A5@aipy (www.aipyaipy.com) Reported-by: swing Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/virtio-gpu-udmabuf.c | 1 + hw/display/virtio-gpu.c | 8 ++++++++ 2 files changed, 9 insertions(+) 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..aeb6155130d0 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->blob) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: resource %d has no blob\n", + __func__, resource_id); + return; + } if (!res->iov || 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:50:59 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=1788527574; cv=none; d=zohomail.com; s=zohoarc; b=deuBzGDQ0mhLmzz40+LMFzQzyN+TtmsywUyXgcPCCc9ekpNslv5Qa2VD3cvjr3ktBax7ooD90UktouBqMD/t9ck8AaHWbTOIDLCZHuOWG+N8FbxQ3KFqlA1J55R47kShgmRQAG7/h0kDqlDSzWxfPMjlEWpAcsUHKBQy+2V0gLU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527574; 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=LUPxGBpIGz75Sy/ExR+TV3Z7/8jhXGFZP/237UKrcQ0=; b=mGJ/UFvpV+PT0TU8YIief1JITOm+Xz7zkAxJbmqUscsbDZj17+na7i8IbjR3MFjEa5Kg/qKiv3QXdr4Qp6FBmb76/heYuVts+3bHDSJi89//9qS11Mgjmq8zTJKAVRYPn7itq0te4FLfNzAlqI69KuuvviMm4jTA8/107X6fGxc= 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 1788527574455569.9159112239673; Fri, 4 Sep 2026 06:12:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Tgo-0003P1-6S; Fri, 04 Sep 2026 09:10:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x2Tgi-0003Fl-C6 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:38 -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 1x2Tge-000513-53 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:33 -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-693-p2Kd2QGnPU-psQTNcUdAag-1; Fri, 04 Sep 2026 09:10:28 -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 D31B419CA46C; Fri, 4 Sep 2026 13:10:26 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9DEF01955F70; Fri, 4 Sep 2026 13:10:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527431; 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=LUPxGBpIGz75Sy/ExR+TV3Z7/8jhXGFZP/237UKrcQ0=; b=Vqv36/yp4KF9ncjFAc/XMBlSY/4EdmloUXIdcIYCuRpLWFyx1avuumjKf2BT+2M46O0WQA II9uvYTXRvkTFgzXA7NNW9fZT6W6ISKv2ebqDUsWRtwD+3riI7S49ymNVD4PpMUdLh8nQ5 4HzCkVrF3FPxpN4pTfI4VlqCSP2CFu0= X-MC-Unique: p2Kd2QGnPU-psQTNcUdAag-1 X-Mimecast-MFC-AGG-ID: p2Kd2QGnPU-psQTNcUdAag_1788527427 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:07 +0400 Subject: [PATCH v2 03/25] 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: <20260904-virtio-gpu-cleanup-v2-3-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=10508; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=PZ3VYE8SzLnC436rfDHqvS0WQkqn6kH670gwHeicr/s=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMvUk8RUjYvOXlgKVAkJegSYIVpPbK+SPiR7 8gbD/oVWv6JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDLwAKCRDa6OEJdZac 5cuSD/wMMfjmh9iD+3IKqMBrEeqWagjhXEL0Om55CzWi7NJ3v0l/zs6Iky6IFQUqBc3RJMp27sc ElYAjb29dBYuPUHQV1NmLrOzl/DZsOp6KklJL5b/pBP0q1VOqhhefZFt8l/AA0y+2KL/gZ/STnq YuDsBzBfHiebhWITFZQqcyqUlCHMJx33P1xwfxAIIzk1710e7LNCa9CuulIuqwEazsTWQtPJmVB IjwadWiFI3ERdLWM7gMsisPHIwSOa6gv++nmN/bdaMMWO3/w5nkULYIKyhIEpFZ19qFQ2X2rObR ahor+3cq2S0FbsdpQSXSWo0ZE8HiO+kDH4gsfqpYlEYeOYRxqOMo89j9W5ldtX2R2yXDNy+SjSU nNVkWMgpa3psTLPKiRqOQigxczxBKQi/X735/4gNnY3JpwqKg6UGJ0QUvtCOu58ky0Q96fqi6Ox 5xJ8r3McTLRBAqnuA7wdJ4B+vTtr0SYKKn4VIKoeQNR3NdI5CmG25sSC5FC9qG+XpCM11siUdvp soQ4I3QvSOgZ0A/WCm1Pjg7B/+8gC1IR3OHMXHcZH+rRI9Pf511dfal/h+WuUHO8StvAQCC+DAw O20sBYBF2Wl7DYDK+2FTWqKoZYRRRnl2BkFYmYCoNd+xh9qZTS/ve08DoFLWUW8pEttMO8DZeCl H/jF+pqIHCEvbdA== 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: 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: 1788527575496158500 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) Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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 aeb6155130d0..1b89d939cfd3 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:50:59 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=1788527590; cv=none; d=zohomail.com; s=zohoarc; b=Sx0dmEqJBUcJbTRWnSV4s2KsIevnKn+OEZ0xqwXUb64SVCj0LXAkdbYEg1JbMjo9IEpi+FhhjZBGJAlQ0g2FpRBSh/oYIVCW03Asloqr6th0yWfSbz4VFBefW/8+7F+QyFeROYwLhad0mZqIDes62IU0m03ukcu9hZYjG1PJDuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527590; 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=WrAqsc61+FPQLZFKyCp2BN89O8jm/CoTzZCeO5hYGqRZxtSaojSOFy2FdOsXTVGWYJwzuCI9kjUEu+Y1lWUpUSzjEcUnjvIMtLzxGw/QTEa6rsd6wBVF2LcyL2FgAUL7KAicVKSdJcZ1wS6ScU78CRkupQX0IT9Q4Nckk5cKd4o= 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 1788527590983871.0643472356438; Fri, 4 Sep 2026 06:13:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Tgs-0003TK-3S; Fri, 04 Sep 2026 09:10:47 -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 1x2Tgk-0003Hq-C6 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:39 -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 1x2Tgi-00051X-0S for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:37 -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-79-rcuulTDkOuydoLBZBAF0nA-1; Fri, 04 Sep 2026 09:10:31 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 213151801314; Fri, 4 Sep 2026 13:10:30 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 357B91955F00; Fri, 4 Sep 2026 13:10:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527434; 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=Qjdj0mim7kfxOyoOBi0vjzbNkR5YLOBJLds2nKKOKq1eVFYUWXgtYq4s/NzFav93VxqbC8 zDWklWX4OxUgUEMqwrwCU+E2GfvvD25eKEu9rsNaDsK7/12jOMdLZ3ffLlo/N+xSQPR+s9 yHP9pfbN+rCrL86DI4pahjR7Ld+SVdw= X-MC-Unique: rcuulTDkOuydoLBZBAF0nA-1 X-Mimecast-MFC-AGG-ID: rcuulTDkOuydoLBZBAF0nA_1788527430 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:08 +0400 Subject: [PATCH v2 04/25] 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: <20260904-virtio-gpu-cleanup-v2-4-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMvFToo+kejW4pAC6TNLOmw580cx8me2WLnl CCedRhlW+iJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDLwAKCRDa6OEJdZac 5ecVEACIkzyTahFzt/+wHL0Kh/mFCrFhoUg8icjH03SRArGoUC7we0j+3dZuO1Yub1V94JIsFmG 8qfQIYopZJ1m2F8kqlrMNjBnuMVaYIuLTX/Ue79FTETiCo1BY17zjFf5cnSglF+p1JviOgXOktH +Vjyj3APPkt8TZllcY6z4n1xikb4C1JZTbEcGbz2wEexndntjrQXF/NnF5Mfd3AiAeSjfFBzwdt Ieuy3x4Pi75R8VCE3csJX07Lb1kOmNPMLs65VxkMgp2jRUiZferJe8hFrwR31jQa1dQZyMVF+Nz 0gQ6FURRgo73IWVQzZf5UPOmtLg0Jj9q/g1eazPX9JnqfOfSe5q6D5DjtpWaASj6lRPnu7fUMLh XqfexlqPNadAZkARM1IYx8UmjvaCwk/hcSyvQUu0a2kA16p+e+f1XvkiAlCHVHvsjxneK9/8cFa g/s0xiljwkfq5hryvHh2YicCO8oBWswZjnLAYZJYfC4341FCyNAkhkrdfnPvgCpUJgaYHncxH20 UnVmYJ8G5Qlj15odSHXQGgy40RGd+ENtiOl5VrZLLZqArQcwZbyAhq/6AXaUl9S9gY2xT2EshfL 191u92WkfsafaA+mhfsY47bNl/1D/X/tTBsMywkuT7MHfGRe0nsCfgPneKnp6c4hc3q4hffe+gN YHog/umRlH0yofQ== 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: 1788527591613158500 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:50:59 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=1788527554; cv=none; d=zohomail.com; s=zohoarc; b=HWCqliiQqKBkuIc2cXP2YfCpPoSttYu+jINkv7aMkEhH2W2YIX8Locdv6JsMmg+13kP3wGHMcjHApS9OEGq7ujh0tq5kv+cNJniSzBvVjjL+P0YziT1+DoDEDajp1vv3+zTdJsa6Hhuyy1yGxMCn4rX1A6SGzK0dhZXNdi3kzgQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527554; 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=P/0nPl28f7pLSpqAXXR0f6DZdhdF09fVFiAWJuT8zBlsZhi874DHmuTytjbWiLQJwVCIZXnZ4ymCNESgIQRBMCMqQ9zYLXk2T/oA0ML54rUVy0p/xfNguVHBb8dXbTv5DrNGd+pIR92M87XMXm9i+u+T78/BF5ztfxda4IbLnJY= 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 1788527554637723.9285447748894; Fri, 4 Sep 2026 06:12:34 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Tgu-0003YV-P2; Fri, 04 Sep 2026 09:10:48 -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 1x2Tgm-0003NG-Aw for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10: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 1x2Tgk-00051p-3R for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:39 -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-149-kkzVR928PfWYSgZnQmPOmQ-1; Fri, 04 Sep 2026 09:10:36 -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 9C73D19540D4; Fri, 4 Sep 2026 13:10:34 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C51C01955F10; Fri, 4 Sep 2026 13:10:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527437; 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=I+fUb/73zlHD8a+Qf7DWzxkMWa3L9VfZa1wEfm1ieKMQLcI41sgGf9SV9aRd8Z8O1jBRV5 jS+IWWq6xkdZErSAT5aGF8W5009uxSpHLOk06URIrKkT9EwPOU0y8VfC4f+bji0tEIQ79Q s0vbmwbdJkDgkj/jtjWmiAHUBPQvYPw= X-MC-Unique: kkzVR928PfWYSgZnQmPOmQ-1 X-Mimecast-MFC-AGG-ID: kkzVR928PfWYSgZnQmPOmQ_1788527435 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:09 +0400 Subject: [PATCH v2 05/25] 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: <20260904-virtio-gpu-cleanup-v2-5-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMvCxlwCRYlYToWPPxbCWHWBGNYdH3pfk4qT q6nsWs827yJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDLwAKCRDa6OEJdZac 5XynEACFDirEYy/WUB5NDvXg+ZYFo42xl44edARvqnMeId8exBVf+thV3K3RNYGo7Nzhw5Nl9Qz yQ4BoGHN9Hjeo9jFCCX2UCBaq4a2ARMN1WBm0+wbbrDMvEFvgIFsOrUGk/nN/kBK8X+222x2G+3 xj9ZJDQVxtJ55zfS1ey6zKaTYD4Ux2IGl95DxAXNfuCGk6v/jWPriM43wxrRk3h320Aqw4+V/A8 8oTw8AG4MkMqQhoXxF5p2qyCEOTjN0xsj9MHguWSo84JRwala38RPjHLNqn5I496DuhqwDxWiSa tCP3z08YSIIGPLPBO/Ij6LW1Pn4r6iVQV0h7eKdNHPhj0Akr63OEj5Nnkx6Nr5Uog2po3anQtzc hBf/Pk3bnGoaFjwKe6vPDfdOATcIIAJHUaZhYeZg1icXQbBvlQTcPQn5wtYrVbHNkr2BEtDKW8R SAZjZzqSwBL1WhbHewbqvegcnIohb/fd5Fz7SoQAtQKB7AxAVGS01YCEKpjiu35edJBS2qu3V0j U0fVT4B+ZhkExfLRKFtyGNhqt5ZQ8V1o9BxNlzus5AteUtYBgvzt16YlBy4etunNMAWU/HXJlvB PujKDo+M8z6U7knMr8yiNmXeEC1Twxy0k+kn5HR7JBSuPKz9DmdLnTo0GSeVGpGTcKq+0ZeW1CP mwSAwvXklntlsWw== 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: 1788527555369158500 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:50:59 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=1788527555; cv=none; d=zohomail.com; s=zohoarc; b=MMBD5kVEUC6qljGJCP0IfAH5Qcm6fIIs9A6fnlhWgUT6G4L8Nb187j6Ld1FrRR3gQCcHPHh99MFUHc9+76MQTG8ofcb3uZ5OoA8bLyJvjNthKzQZ8/2xohYpQqrCPEgg/UKmhVDh6M0Ma4ln30oLyXNsGkmJ97DG6o565kQ6d2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527555; 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=Aez3Vzz2L5nNo9zPUx7UDK6Ucvaer7z6LWfJn8lF/kg=; b=bMLXfWHkca0TzaskaY5et1VMaCr/+UxXKkLgBpoDNQbrlBIyrfDQNvmMwfN3+LIOOHgCQdftFd2YKIn6WOYKnK0IqyUBlaMlq1d+TYbYXDlKJ62EzQjlSB3pVmeUELkieQuhA3wo6/RnUcPAMKb5okje7jHEXQodCnd22ab3T9s= 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 1788527555753529.1875448854992; Fri, 4 Sep 2026 06:12:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Tgw-0003er-E7; Fri, 04 Sep 2026 09:10: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 1x2Tgt-0003WV-CU for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:48 -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 1x2Tgq-00052c-D0 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:47 -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-540-Buy428M9Os-Ghc6nTCTKJg-1; Fri, 04 Sep 2026 09:10:39 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4CD471880937; Fri, 4 Sep 2026 13:10:38 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id F350918005AD; Fri, 4 Sep 2026 13:10:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527443; 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=Aez3Vzz2L5nNo9zPUx7UDK6Ucvaer7z6LWfJn8lF/kg=; b=SkJ48s1/cRAQAPkoR1DSCccDToUGHqLvG4We5LYVCs6MeBmvrATIFpGr0vF4ic0GrInf8R uWEaCGj3a/sUGM6sLL6PLYK43IEx0p202qZakHkfl9Dbg1aF+9tkaTNhUyD8EwZuNA3+b/ bummDFal7tPgMInDx54XgHFptgPJCR4= X-MC-Unique: Buy428M9Os-Ghc6nTCTKJg-1 X-Mimecast-MFC-AGG-ID: Buy428M9Os-Ghc6nTCTKJg_1788527438 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:10 +0400 Subject: [PATCH v2 06/25] 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: <20260904-virtio-gpu-cleanup-v2-6-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=12691; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=RToXP8fzo2M51qblwEyDyuaS9Jg+gjoS+E36wu9O4DM=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMv08BPWZSSdsuiwMUdEkrM5NavLgzLDsZYH bIK0y6BbV2JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDLwAKCRDa6OEJdZac 5fQAD/9212BLB17SMO2jytr6vg08dza+2WWfmV0CHDRKXB8sBDKzUwIQNPjcvS2l0/+/xTekOnU siGvkrc2LTkmuZTe8LlmDvIqHYGp7Q84wHGhK75i8OuXazGhzAHF7kGp8iaJEKMGWGegq6LM8dJ d4x92kIPA6a4Z2CoaQowIbshWozKjO++okaPe3mWSyIzjHAhDZadsS78RT8I0RarMn09f+bfBZN PDNd0ZdXzn2cVjEwFk5r1EUyzF4E8KSBsKIpmMYYYWyCtLIw23j2HEzdpD/ZKH75HQji1U4OOjg w3A7Vdg4vH9753EL7+5ro8c4M8Mpt65V1VHpnZ7fFoNS87jMHATfV6jPjFVQug39NNUlwR81ScF WCzRnr2OVWgyZaMaWbSOPu12a8EdlhumjOXDG7WbA39I255mNPtmXJwX+JJkFUMee2bKXWe3q/W sleJyXjtUOnRA5zqyj9a8zubpFREBAM4SddI+59ZsG33xsfIU1mPfbSRmRQQKDy9ce/agXfNRFX vVetyvaOLR204sGlg9Az6F5w+j2Bf4/e+J6nox75MX0RjHebeYspfM4dvMG+Cr537XWssHusDSp fQP+GBBskiDK6YVN6ZKT/oLV2vSZsNuaRzQXitaNvaDndPe7msd1keA40eEx6h8H1CpAC7aq2el sM2qKxdYBtR9pDg== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1788527557522158501 The sync and fence_fd fields on QemuDmaBuf are only used by the GTK display backend for GPU fence synchronization during draw. They are not intrinsic properties of the DMA-BUF itself but transient GL state tied to the display listener. Move fence_fd to VirtualGfxConsole and keep the EGL sync local to the draw operation. Change egl_dmabuf_create_sync() and egl_dmabuf_create_fence() to return values instead of storing them on the dmabuf. This makes the fence lifecycle independent of the dmabuf lifetime. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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:50:59 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=1788527588; cv=none; d=zohomail.com; s=zohoarc; b=Wl4ILDXW7tpR7LHQxc8VL0Xr3E3ZQRR+ETfa0O7akw71ckWfR0VmmYBPjFbgGb2GctQ6h4311ey5fg8DP+D8M/AmjUgcp2sNhfqU9Sfu7FRIEQihnBKjp2OJQNMZoGMBxaHxvoFjFEcCy7YDbdnQtH5jTCILN9bLuch0mrhcVbs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527588; 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=PE2y/oNgzTqJkspzOVg9RTCAjjRevuAKrC0Gi+I2jnI=; b=FBzh/NA8VAqjF7B+RJcoHaDcbzClb+Q0tzLy5H+3REtXVHfpQxqQVDHKuXzYFivqvVFtlf5rgxUejEjhO6ZIdRz9pS9CYA4N/JJY8SnWQCVsjhLpESpNTvAjqc7cTFVSVodTCgVJsWmmBmLRqhLucBCDd/zRPq51zoMC0QwIoxA= 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 1788527588778973.7766849696444; Fri, 4 Sep 2026 06:13:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Th0-0003jw-AQ; Fri, 04 Sep 2026 09:10: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 1x2Tgw-0003g3-Sa for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:50 -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 1x2Tgv-000536-4p for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:50 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-rLyNd4uJO_iILrgVTuUCdQ-1; Fri, 04 Sep 2026 09:10: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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3F7E01893ECF; Fri, 4 Sep 2026 13:10:43 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 187F55BC; Fri, 4 Sep 2026 13:10:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527447; 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=PE2y/oNgzTqJkspzOVg9RTCAjjRevuAKrC0Gi+I2jnI=; b=iIxw3iLr93fOwp7/p8kw5rrFByPU9ubDIHlyRLp71KeZLTvh23GO87LZWVqugiI05ASoyQ akWT1EESLLK7HgNPjXuCRyO0LknlS/6eguTPlPxlrjDhbsoAFwxTS+BN8y/RsTqHg4T2X8 7hfQcmEc3Pvy3/ypyy33DzS5mOAIO9Y= X-MC-Unique: rLyNd4uJO_iILrgVTuUCdQ-1 X-Mimecast-MFC-AGG-ID: rLyNd4uJO_iILrgVTuUCdQ_1788527443 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:11 +0400 Subject: [PATCH v2 07/25] 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: <20260904-virtio-gpu-cleanup-v2-7-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=6194; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=sbPg4GMfuImsj8Uxx32aC9Ecbd9b3gqJ9T++XNXhrqQ=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMvddVT1QSsHzUsyynmFBNOmBhKMgXscyGPc j3kzePl0PaJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDLwAKCRDa6OEJdZac 5R9nD/9vS5DnAb7z66S17IWGxjUhacrDYQJnYyfrnDKjIbwpphFgEcqBi+ARmWGZeX/6TTItltV GP3smNmTAs8bNLF5e3JyQ1Y17uwWyCUhyZ9/nOshfw2Q73ORrif8pmIhUIO/jGB4ALA0tJ3CznV iYmRrQFvFElRQVC2hLujOTkkH3l7yZgcDNiUlABVRCFWxa/DmsZvsQ5+2EN2zaAlKRRgl1gviS1 hbRheL126wDDWNNVDP77H5DA/400criWR99Z1xwNvtycA4nM1dBHmuBXAuLKML+/xcPHxqvS1dy yBXE+IBFqUPQhbcmehkZ6Uv1HbdRbKQe0YWmJzV+Oxy65yHY/i/vufsMMeLXctvdMsWla8B9aur 8ed7J8na3M/e2VWhvSJV52+La0zSxRyjwIQjJchrQMu/0SQHVJ/5jLhHYRohEciXX8YfHIXzgHg 5spbat3iHksYQNdkmhz8ml8rwLy1r69XhK0D/RaXAvXSoj2S0ZFrfqau4mS5trU39jqqAvqPJBz JWh0bYqSK4GG6XM2mNsRM4Zk+C3YJ0vFfdLOIgHbvjW7MxffNwVLy5tUGrOrdMO7yJoRfu7Ds2/ JyXj6+vq+ABj5R2DEYUDp1sFUCg0bCgqbNWNaUYCIpiHLSgJro/PrlebRZZG+SXh1hDL0U7ysJ9 fgGgOsAqYCNIkWQ== 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: 1788527589706158500 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(). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- include/ui/dmabuf.h | 2 -- include/ui/gtk.h | 1 + ui/dmabuf.c | 13 ------------- ui/gtk-egl.c | 13 ++++++------- ui/gtk-gl-area.c | 10 +++++----- ui/gtk.c | 1 + 6 files changed, 13 insertions(+), 27 deletions(-) diff --git a/include/ui/dmabuf.h b/include/ui/dmabuf.h index 381583bd536c..b972099859f2 100644 --- a/include/ui/dmabuf.h +++ b/include/ui/dmabuf.h @@ -42,8 +42,6 @@ uint32_t qemu_dmabuf_get_backing_width(QemuDmaBuf *dmabuf= ); uint32_t qemu_dmabuf_get_backing_height(QemuDmaBuf *dmabuf); bool qemu_dmabuf_get_y0_top(QemuDmaBuf *dmabuf); bool qemu_dmabuf_get_allow_fences(QemuDmaBuf *dmabuf); -bool qemu_dmabuf_get_draw_submitted(QemuDmaBuf *dmabuf); void qemu_dmabuf_set_texture(QemuDmaBuf *dmabuf, uint32_t texture); -void qemu_dmabuf_set_draw_submitted(QemuDmaBuf *dmabuf, bool draw_submitte= d); =20 #endif diff --git a/include/ui/gtk.h b/include/ui/gtk.h index 4b4ef50e3701..b66b9ca5c519 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -59,6 +59,7 @@ typedef struct VirtualGfxConsole { bool scanout_mode; bool has_dmabuf; int gl_fence_fd; + bool draw_submitted; #endif } VirtualGfxConsole; =20 diff --git a/ui/dmabuf.c b/ui/dmabuf.c index b61dc7ad2783..16063dc62ae8 100644 --- a/ui/dmabuf.c +++ b/ui/dmabuf.c @@ -26,7 +26,6 @@ struct QemuDmaBuf { uint32_t backing_height; bool y0_top; bool allow_fences; - bool draw_submitted; }; =20 QemuDmaBuf *qemu_dmabuf_new(uint32_t width, uint32_t height, @@ -212,21 +211,9 @@ bool qemu_dmabuf_get_allow_fences(QemuDmaBuf *dmabuf) return dmabuf->allow_fences; } =20 -bool qemu_dmabuf_get_draw_submitted(QemuDmaBuf *dmabuf) -{ - assert(dmabuf !=3D NULL); - - return dmabuf->draw_submitted; -} - void qemu_dmabuf_set_texture(QemuDmaBuf *dmabuf, uint32_t texture) { assert(dmabuf !=3D NULL); dmabuf->texture =3D texture; } =20 -void qemu_dmabuf_set_draw_submitted(QemuDmaBuf *dmabuf, bool draw_submitte= d) -{ - assert(dmabuf !=3D NULL); - dmabuf->draw_submitted =3D draw_submitted; -} diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index c671aabd11b3..8623181336e9 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -86,10 +86,10 @@ void gd_egl_draw(VirtualConsole *vc) if (vc->gfx.scanout_mode) { #ifdef CONFIG_GBM if (dmabuf) { - if (!qemu_dmabuf_get_draw_submitted(dmabuf)) { + if (!vc->gfx.draw_submitted) { return; } else { - qemu_dmabuf_set_draw_submitted(dmabuf, false); + vc->gfx.draw_submitted =3D false; } qemu_console_hw_gl_block(vc->gfx.dcl.con, true); } @@ -169,8 +169,7 @@ void gd_egl_refresh(DisplayChangeListener *dcl) #endif } =20 - if (vc->gfx.guest_fb.dmabuf && - qemu_dmabuf_get_draw_submitted(vc->gfx.guest_fb.dmabuf)) { + if (vc->gfx.guest_fb.dmabuf && vc->gfx.draw_submitted) { gd_egl_draw(vc); return; } @@ -290,6 +289,7 @@ void gd_egl_scanout_dmabuf(DisplayChangeListener *dcl, =20 if (qemu_dmabuf_get_allow_fences(dmabuf)) { vc->gfx.guest_fb.dmabuf =3D dmabuf; + vc->gfx.draw_submitted =3D false; } #endif } @@ -406,9 +406,8 @@ void gd_egl_flush(DisplayChangeListener *dcl, VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); GtkWidget *area =3D vc->gfx.drawing_area; =20 - if (vc->gfx.guest_fb.dmabuf && - !qemu_dmabuf_get_draw_submitted(vc->gfx.guest_fb.dmabuf)) { - qemu_dmabuf_set_draw_submitted(vc->gfx.guest_fb.dmabuf, true); + if (vc->gfx.guest_fb.dmabuf && !vc->gfx.draw_submitted) { + vc->gfx.draw_submitted =3D true; gtk_egl_set_scanout_mode(vc, true); } =20 diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c index 29d1b1e4116f..45c0c8c81a11 100644 --- a/ui/gtk-gl-area.c +++ b/ui/gtk-gl-area.c @@ -82,10 +82,10 @@ void gd_gl_area_draw(VirtualConsole *vc) =20 #ifdef CONFIG_GBM if (dmabuf) { - if (!qemu_dmabuf_get_draw_submitted(dmabuf)) { + if (!vc->gfx.draw_submitted) { return; } else { - qemu_dmabuf_set_draw_submitted(dmabuf, false); + vc->gfx.draw_submitted =3D false; } qemu_console_hw_gl_block(vc->gfx.dcl.con, true); } @@ -319,9 +319,8 @@ void gd_gl_area_scanout_flush(DisplayChangeListener *dc= l, { VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); =20 - if (vc->gfx.guest_fb.dmabuf && - !qemu_dmabuf_get_draw_submitted(vc->gfx.guest_fb.dmabuf)) { - qemu_dmabuf_set_draw_submitted(vc->gfx.guest_fb.dmabuf, true); + if (vc->gfx.guest_fb.dmabuf && !vc->gfx.draw_submitted) { + vc->gfx.draw_submitted =3D true; gtk_gl_area_set_scanout_mode(vc, true); } gtk_gl_area_queue_render(GTK_GL_AREA(vc->gfx.drawing_area)); @@ -356,6 +355,7 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *d= cl, =20 if (qemu_dmabuf_get_allow_fences(dmabuf)) { vc->gfx.guest_fb.dmabuf =3D dmabuf; + vc->gfx.draw_submitted =3D false; } #endif } diff --git a/ui/gtk.c b/ui/gtk.c index 1c75b9ea3c4d..55e45e8445bc 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -593,6 +593,7 @@ static void gd_gl_release_dmabuf(DisplayChangeListener = *dcl, egl_dmabuf_release_texture(dmabuf); if (vc->gfx.guest_fb.dmabuf =3D=3D dmabuf) { vc->gfx.guest_fb.dmabuf =3D NULL; + vc->gfx.draw_submitted =3D false; } #endif } --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:50:59 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=1788527533; cv=none; d=zohomail.com; s=zohoarc; b=W5d7pjAtul3MzIy5d3pzhs0MQfUWD0Qp+XkmzALUhMo+dlNUM14W1xPC2mI7h7tDtzjYpEN3lVhjRivTmXHhrPmDvpLS2C5G7SdVh/4qA3uSxcDRGufZiCcX7fDRxHIvEdjXPfyCRqEUWPslz5jNrl6zexMLuxD0S/+H1BALufA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527533; 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=YvJHoMg188dY9Cej0wOxM+Cg2mKPuS+8m95oz9vNeNs=; b=iiBtAyFnlyBKO98RZo4gOGeWLtGjJXFpIOj7e8n7YIn/TuaC7Tkv7hbqt6lAW/HG7WvyINcOO+4dvB6ILd0qzK1CR+sUtbs3K+FSIZWk7mrthXf/qpcUzkaTjqBaxu4rR8CLWY5f20NGRNHkOD5uIKiEflU7DU/HbMuwYN2+MJY= 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 1788527533439417.5044793049241; Fri, 4 Sep 2026 06:12:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Th4-00041Q-31; Fri, 04 Sep 2026 09:10: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 1x2Tgz-0003iD-D1 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:54 -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 1x2Tgx-00053i-NJ for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:53 -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-330-07W-_eHTOnKNpQBzUmpxoQ-1; Fri, 04 Sep 2026 09:10:47 -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 65E5F19775F0; Fri, 4 Sep 2026 13:10:46 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 953C11955F10; Fri, 4 Sep 2026 13:10:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527451; 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=YvJHoMg188dY9Cej0wOxM+Cg2mKPuS+8m95oz9vNeNs=; b=BsZJVVSzGbYmD8E527Swzcp393y4aY98ecDEY6u/51pVyWzkj3nFwy+PqVRF5E3DHHDy2m f3FfrdQpXgpF6VPFJ8mpClRmkb5ZnFwZ72SjBmj7Af+kvn7w1Cm2xT/ocV3JkL9ll8ihHV gnOmxLSXS6dAk1Nm0tOIv7b9jNIs0Mg= X-MC-Unique: 07W-_eHTOnKNpQBzUmpxoQ-1 X-Mimecast-MFC-AGG-ID: 07W-_eHTOnKNpQBzUmpxoQ_1788527446 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:12 +0400 Subject: [PATCH v2 08/25] 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: <20260904-virtio-gpu-cleanup-v2-8-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=6047; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=ufdwXJt2ZyswjTPKDh3Zrq5thr0ojiRyYnYduMUJPlo=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMvV7E8dOinoMT91bm2v7gW+l7iZG90OUe8i KcoN8cM5z2JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDLwAKCRDa6OEJdZac 5bKRD/48zq6HR2KkHtbbMnpbiwbesZKvnWb7YUrM6JcPXJG4WGO98xutuKOHfZAeUDAZecSs0Yx 6khnM2lpFsEisWJptZSehYhVirPkBFJzTuErK+MTzSaJuOfrCGKM8YWZtOFtUI20WAVEZ8WvfiA +2FqX25Cq5BAXPTNBzSOIBmTv2ikDrAS4crjlrJs79/MDSwGqsta74rRC2Y9e/xJEkIYV/bHgqx GJzUOxHO5+DgGX+bQ2Yb8zMZesmhwax16LBYowB6mEsBOkIoJ6/PvwtdbnkZN0g4hTOiDqFc1jz TzsqOXsuwJQ8PpR3x1SQXEFbdlKscMl8mw/enfPT8RAIDyvnwKWrk/i/Uv9chUddJ/DSz8k3TVs atXKow4oNmYQggKNAB0MpJYNNWzlmirhzS496drjhj2xyrsEyMiWKyWH8XPy+JlK3C1BMz+eSvq vHuKahuMpBV+FLbdq7QcpJ+H5sryezROHphOfQNU+f5tnI3PgaWX4P0FSO5Z8yj6jmTub115EKv j6GKV/zeZ4tAmPxggttJvypGGQc9OIZNikSfi+q4YD0QM/239BkFwC+364CkUBkCPfo7iniwXBD 6fhr/phn+iKmfJJ5Yrh4unWRsDlleuWpzXCxlQ2fqzWzeIUFE9wtVe9PpQHTO+V8FpPvB8cGMOj DGlamE8FB8kd5OA== 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: 1788527535335158500 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") Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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:50:59 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=1788527527; cv=none; d=zohomail.com; s=zohoarc; b=oC/bT5recG550B7oJBwy04GHLtpeo5YgM6SzmpR9bmCQwh44S/IhuhGpSN6ZD9EPR+LU5xxjwoLjf0ckbQe5ozlnejgjHp+MMWUPb1WQ97hbC0g++d15AVLXYBEHu9TitH/NMvsbfxxLAK9y+PDXn/YLLCiAIAiBBSPbVd3Mp8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527527; 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=NYNeeKF2BPMfRyEfJxs+uLie4EshM8A1v8S4Pu7JIYI=; b=IwAvuDXfE+UiMasT50JFJB/MX1RFSW4NFsMA8su2821XFvEBG4eCTAPajAUzksJqgHb+m8KdFsgTwHkILTrh7jzXSxmnr7/u05migjwC6J/2CkRqWXRUaQpk1uVkeD0VpBgdpRp+mZR1MCgniZ28a5KVwTlM+h45u0JR8H48K5c= 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 1788527523645100.45496244795174; Fri, 4 Sep 2026 06:12:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Th5-0004Fe-Rn; Fri, 04 Sep 2026 09:10:59 -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 1x2Th3-0003yZ-IX for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:57 -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 1x2Th1-00054R-Qu for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:10:57 -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-274-PXXIljyZPgq5_rZgP5vjhg-1; Fri, 04 Sep 2026 09:10:52 -0400 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AA7E01954B37; Fri, 4 Sep 2026 13:10:50 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D7E197DA; Fri, 4 Sep 2026 13:10:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527455; 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=NYNeeKF2BPMfRyEfJxs+uLie4EshM8A1v8S4Pu7JIYI=; b=aEcXHhractwm6XqQOrrICR6+4gHqkkLhbjTGd+F7iQrwaVjbkFoymfXRpUjMWk6YlgBJjL iI+vx93d01SbzTN1nRDluO8knJL1ZAXm3OFWhpYhAK1WwqZ0ueGguxGGexcx3ctmljhBBa iL8/QeoEQKpz2z+iP+ye6D3UX1cxqoM= X-MC-Unique: PXXIljyZPgq5_rZgP5vjhg-1 X-Mimecast-MFC-AGG-ID: PXXIljyZPgq5_rZgP5vjhg_1788527450 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:13 +0400 Subject: [PATCH v2 09/25] 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: <20260904-virtio-gpu-cleanup-v2-9-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=6536; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=OMFUNGS+YCS3LMpFoua2CDGBKOeqOyOR1f1IIsw8EUQ=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMvdpj5HABmKtq+Nv4Fn8VWs5FrmamQZ+8hK 8TXUkO3+R+JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDLwAKCRDa6OEJdZac 5T2wD/9ngjf820E/V1+slyhv4MQuVh5QzXSpDe6sdE2HcJtMW74/KUfLLu0YIB0SBlm/p9/Dhgb nQ7Z67ErKBlFLjbl+0hOAY3Ljnu6xmH2wub3C/lMbiaFucJKE4mvig+kqJr930iT/l7DkCb2++2 mwM2rPbHD1EAqdCb0dyWYkZmiTCaUzSH92AmEXc8ta+7pObnq7/PdiGtf9J+7IBzEWozeFY6Y2Z y6ktmDDYfRFHrJKQKFAuXumXRYQZuHT3wTQ8kFZkfEvV8kjIapENYduDCgIVioXPHPFCJTdnc5C z5x2H99ORqblOwkJWlrt6gofltbHlLLzgWeRsyK7w9KXSIDwRifDtzya/JND+hHJrgtFA8s+1bn iWXHHsKo16/MvewkEy/p7nDxH3Go9Cir1G5LSNl+3rQLGPMbk/eTy4IO17VPD68NV8aGhBNleo1 lWoSb85TdRllnyk3FUXenRWFEQBmqzFi/6Yv5yVLElNTZjuggXXIv97vwWhWW/cshq3QdjOWKnh nuZSnyK31od7HwFE9luZnbO5NBhT/skYDVN+0zeCxsgxrBJx6noibtXw1BukNzHdQdET9bGwcAL NdwwcUEtakVCQL41AaVrs7DS57cyfexhz/F3CZpmaU3dK4Y++DRq06lOgLKlGwbXmJRYl+ebdO7 hPIfGbiHuRn2aSw== 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: 1788527541570154100 VirtIOGPU tracks presented dmabufs both through a per-scanout primary pointer and a device-wide list of VGPUDMABuf wrappers. Only the current DMA-BUF for a scanout can ever be presented, so the list and the wrapper struct are redundant bookkeeping. Store the QemuDmaBuf directly in virtio_gpu_scanout and drop VGPUDMABuf and the device-wide list. The wrapper only carried the buffer and its scanout id; the id is now implicit in the owning scanout. No functional change intended. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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:50:59 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=1788527495; cv=none; d=zohomail.com; s=zohoarc; b=GT2ta5iPYHP953NlasfBwCUlrMSX113pVBGy26jE43GZ6p/Lma1OqNiofFts0KnfWuZIDKMZov5C05nIwISEHn8Jcu/kDa5yx8mp/U/8QCoB/CGnIv/BEfmcTCMMs5bqAo5UVN0zfJVb148ACLDoOpfVMRii9aayMXvthf49NfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527495; 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=AVAHgQbM/aPiivdzsKn8yGeaKqOnfruJK8/C1MWLsWc=; b=n8o/mFiTBsbaBzhZ4C2oHmpVtyjYyO3+g5mBjz1xK3WdcJM+Ao/0+1CMDNtYQbSG/nk8CBVde8RrVrj85kk2x66yqBKZ1zWnjJOtE0XMxGtIp/MSAKNOUXAV1wDZGrN1p3YbwvtUgqVbPzC340webLCBbW36kA4XLP353pIsuk0= 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 1788527484767448.8970685065658; Fri, 4 Sep 2026 06:11:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2ThB-0004RC-SP; Fri, 04 Sep 2026 09:11:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x2ThA-0004Qz-NX for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x2Th8-00055j-PP for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:04 -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-575-ywnLlXUtMbWQzjCiHyquaQ-1; Fri, 04 Sep 2026 09:10:57 -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 F09D718417EC; Fri, 4 Sep 2026 13:10:55 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 161505BC; Fri, 4 Sep 2026 13:10:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527461; 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=AVAHgQbM/aPiivdzsKn8yGeaKqOnfruJK8/C1MWLsWc=; b=VygB1cWUhUx0s74FB4AqpjGhrmxQRsdlUjtqEa7rXBruZKeLIiybTqQm+pgcN6Mih9dGyr dMKg6OKJjPCdcHjyeuvw8pV/sxYocdPBxoag2Z2Si1f+3eVFOH7O61bXFBcBN3RRuNJ8kH mgo/U0+6Mk2uAOGb5bJpchtzDPLFbjQ= X-MC-Unique: ywnLlXUtMbWQzjCiHyquaQ-1 X-Mimecast-MFC-AGG-ID: ywnLlXUtMbWQzjCiHyquaQ_1788527456 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:14 +0400 Subject: [PATCH v2 10/25] 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: <20260904-virtio-gpu-cleanup-v2-10-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=993; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=U5tu1RWLhciHqx779/J6PMsZlOhqAA0BFItvJyOfq/k=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMvMfzYCHhRtZcb5RvG0me54nAWeTcl6nKqf 923oOBuL4mJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDLwAKCRDa6OEJdZac 5axND/oDULv1AGPnlQc7hH/qVJDyqAMf6WIncd0kvP2kuQxphzeupB+r2MYqdxtv/wZ6NRqp48e e4vTn3p7fYhLCm+EEDAEf77KchwSES6itDOL+Ofy4+hau01p6Vu+U7HQ7tZ0Q5X8e2nMNNLi4tT GiETc0KQB/394Ec0IGzZCGJgLYxz/iiTUbLtuhAklLPgFWEq5euTxMe0aC0aX35RFqJAtqNlFFL 1sL0ezia9KNeJnU8I6ID023TmtA474mMMT5ZchHxZ+PU5pH2GgFlo80G0N0lvouKTVkBe+hVzG2 HyKE3xVDkZRj0DmH3+bikE/yyoXE/Gh/rMTdU/VVrMpj2X+n+FfZ65sRAgYKuW3njQK4dVnUcYP YjlekIxGurIrokGuuqbPzYhhAE6FL4+S9ae2AG9cT094Q1hQPjJhUckaZ2tRFfS/cHloxmD9acS vjsNnoQ1KJg2Z6kYkum/1L1nTbkKP8dGWqK/UjdzPC4pEuUygXor9VAaL2w2p5fMiOl27I+Lm77 /sSBJMzcWfbq3SAHVDZSw0KoOSG5wgNe7JyDYfvS29/2dTDL5okqWXp+/I5VvhPydB9UBf1nUyQ +kJcq9esD+oo8C418sFEtbLas1+Vv9TKuCUbMnLTqNaY0E7xsdEg5/tZQUSh4l/uA/1bC4SE9Yp FDv59fJ/mhdDkYQ== 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: 1788527506392154100 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") Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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:50:59 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=1788527589; cv=none; d=zohomail.com; s=zohoarc; b=Nx/xBoo6teZeieVROMq+M24gnWIFmOXVq7Ng8Q9trPBaHeYty6OfgnGl8XWVaxxwuO8ia8N1UgNOv8yJC4LYCP3ocix7VuBuig5exHBNT/fGyRRTWV2CWJf7Qk8p1Zqs34oJ6NxY2s8xIIIPdQFcALjp5IW1Bx5jDN/5yQoGMCc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527589; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BfqhV0k2wnTQNP/8Pi8Tj3/PSKa/COTcPUpKOxqHnxc=; b=CbynZD5PwzYBqY2r48hQtJoAcF8m35G7gB44eyPd1CP5bXDxH83LSNXml5/VxkLUdbgS2LdTNjuvyDA/HT1jI77G78fiiSaJXgMKxfapmDTk0RdTu8MYkHLJzKrZd2rUZwg/rNY7CFlZI+Ff5eDPwpEWeYRpkTLAKkvX5pmAc2Y= 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 1788527588988497.8087616869125; Fri, 4 Sep 2026 06:13:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2ThD-0004RW-CS; Fri, 04 Sep 2026 09:11: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 1x2ThB-0004R7-Lg for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11: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 1x2Th9-00055q-Qn for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:05 -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-602-zAkaO3lJOgulv72hKfa36g-1; Fri, 04 Sep 2026 09:11:01 -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 F0C11191F5AD; Fri, 4 Sep 2026 13:10:59 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AF9DF1803A40; Fri, 4 Sep 2026 13:10:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527462; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BfqhV0k2wnTQNP/8Pi8Tj3/PSKa/COTcPUpKOxqHnxc=; b=XXHXe6LTd+EigD1UyI0wyeKyVbGsyij86oN87HbYBkrnLJATfNU3IkWnYveWjJ+5S1pdVX yHJxuxScjm87v2PuykCmI2/fZb08hi/62kBnoyehrA+NnPtvLWOcft+If6kFhMwkwVKuuN 2zkH0IaXWuVRS/oJnIMWX9DYdYE7hFo= X-MC-Unique: zAkaO3lJOgulv72hKfa36g-1 X-Mimecast-MFC-AGG-ID: zAkaO3lJOgulv72hKfa36g_1788527460 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:15 +0400 Subject: [PATCH v2 11/25] 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: <20260904-virtio-gpu-cleanup-v2-11-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=984; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=soqzgd5o5ILBeI69vpRutTaDwn5XU9TT0gvi1GNhfSg=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMvsVzzRgiUX2WnCXwjE0GsDQdrHFsXKHdEW xmiad9NTGyJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDLwAKCRDa6OEJdZac 5YKXD/9zJgm8Kjiu6zY9OYDOAIKq2Mh8XBxLf6HH5M5gFDCx9ie+IFTx3L9fDoiUYUuJgpVbYuq 2PJNYqzhktP2SXE9EF9HtgKVJU54KaCYjIulT8rQZWV6foQ5VQirWy1p+/CG4IKBI4mAcg4hyHE ++WaA2MSYKx1iokIAlQ9KkVLccvyCNmA9lTHvlk5POCkFb2DvPg7FKm/7kJn/cA5oxTog4kK66X BH3xHgKmKPEDmhL/fbqv8D18YefqspVU3Fb6T854M+LfkGc8oOw9FSl2o/+wWmFFAjyQAtpklzb CPvOkMm6wwJj2xQRHG7Cud2lSQZqL7vyrY5FKfsPZRGloGAiwnv4/4lQLOzdFYsS+SS8GpQ9RAm W/IMWX9Ldgl2m0QtHrD+YiL2bH7ULHUPlfXgHOop48WQDMXzLsUPuwzcVZEUc4pTc4uFNEY3H5N iI8Mc1EW/Anj+moDWbV8zkHD/xjVrKvLYziKTkl9lwe+X+IK+HAOSTwA8f4erOtuHZqI08B8Ces QYNKk8BLSxCwC18JU2lDhoTvLBZWAW+C/NggkQSd+eKN8j4+2gV2bo5b4RGomWI34qQqvlGhgO2 2pChGKTYBaqToQTY9/BjhGEik5YzbKKMLknpA1h0bxEvrFykgBVQpjXV1vQs/KTdVUHzVLKTXQA pDBim/cjbShdDZg== 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: 1788527589661158500 sdl2_gl_release_dmabuf() releases the texture but leaves the guest_fb.dmabuf pointer dangling. Clear it to prevent stale references after the dmabuf is freed. Fixes: 52053b7e0a0e ("ui/sdl2: Implement dpy dmabuf functions") Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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:50:59 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=1788527530; cv=none; d=zohomail.com; s=zohoarc; b=aHCO8u5uJek4VIKFVoNFc+P3VhKcDS4RLzOJNIAewT6XOEtgEwB6qp0zf3w/+8FxUY9HodxkagRHHB1YTcYaFCKSUbJ/IUwc4UBot6dT5CtGnFnKtZKM76tTIh9fnb+F4Ay1g9LEhbxR+mQlCkpDQOkG3yOc1vshRkYYVvUT0Lk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527530; 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=8Qu/vKp6f3oCKQUomRofq2j2mATQ9j2kAqeFAGiCmrI=; b=KD6nlLAX7v0e7eytskeO8KUkdKQzLl3pMtU1QYDRab+o6tfgmimVQkTla4d7doU9jwEKeE28uuejzbR/FIy7XFQx3f/OLzGQPkFDUmfnDE09Y6dI6YoidH2rp2NaBZloz5tBHpBGXGQFyM83RQ9fJhfQx1hU+VSZywMCzzlrqhI= 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 1788527530141548.4680905310967; Fri, 4 Sep 2026 06:12:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2ThH-0004Su-MH; Fri, 04 Sep 2026 09:11: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 1x2ThF-0004SJ-Pi for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11: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 1x2ThD-00056P-Sd for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:09 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-279-Dpzr076QPKSRo3kV1pmyOA-1; Fri, 04 Sep 2026 09:11:05 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8CFB31955DC7; Fri, 4 Sep 2026 13:11:04 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CEFB63000223; Fri, 4 Sep 2026 13:11:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527467; 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=8Qu/vKp6f3oCKQUomRofq2j2mATQ9j2kAqeFAGiCmrI=; b=aLsEOXSD5y7lM5FY3TmVNM+4eSEpshPecZ7+6HYfOf5bQbcA+gyjv03YP8byPHDnER4ze8 Fc+1LRsmZhPl/l92TO1gmIVlWTXGfloqZU3R14o3rUHVyG7JS99aVBFTMg73/tHDxDIk/s BhNS1kve6kYM6uisk/ziHM/KU7K6NUg= X-MC-Unique: Dpzr076QPKSRo3kV1pmyOA-1 X-Mimecast-MFC-AGG-ID: Dpzr076QPKSRo3kV1pmyOA_1788527464 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:16 +0400 Subject: [PATCH v2 12/25] 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: <20260904-virtio-gpu-cleanup-v2-12-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=8256; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=TGgncS1B7Yhg7ccKYK+NOgOooDEYgUrD+s9ezwXzhSM=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMwMySN/C3LektoWxTwP7A6PTw1xEdzt0opZ WtSCGPPTUGJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDMAAKCRDa6OEJdZac 5afgD/4tc1ymexVH4PlqA1qPEwXq8XEB0n7KHhd/v59U7L6ZrW57GiB8hISTgDIayH/6wfoIuue oPJFDGsV0E+vYUE9E19rS9VMUlwkLFgPrvlZikL275lQGefzKNsKomfoNU06VA6N1vt97yW6vaj TM9fSPvxjschagIrYeYqmYXS4Zfn+lLR3HWCOFB2B9T29YI+2ANXtQJnA76a3TijPh3Y5m0WwJ7 on+AZs5pCDhIiLyFcrj/TC0SpPhURjLePQmA/F6sxtGn7mKg+L8Cfaj62XMafM2ccIO2P0JX3UO WivXKxF6vYrOf5GLA2PQkmNf1JYQx1mEtLLGbv71zU8cIw3BGGtAw2WBcnGPvtbqLt9BMYemeF2 cAairRDk8dDnvDmz9XkWrdQlbylkyiFSXHiBye/TwZfRE1lJ+sopgxCwQpxFqlnPz7lSxkGXaLt Xvw5fmN85rUDC2I0TB0WutnhyD6VXVv98qpYva8tLh4x3/qneovGCCm5C3I71OavK4c4EHL4Hoo VCOK/LxdrCvXUTKbanlqQNiWEL1MOj0vgzjrwY7G6hgSzknPjI21YxK+l+Vl612DlGWpy+HGLXk vZ0sCSUS7o5TIGdgOSjZaoXraR0374VFfQiYDrg46o4L7cU58NDPpag+91A6QiZcnWTPudwqFzM 9jw3+EzSrKunPdQ== 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: 1788527531958158500 Make qemu_dmabuf_free() call qemu_dmabuf_close(), so the dmabuf always owns and closes its fds. This removes the need for callers to explicitly close fds before freeing and simplify the code. To support this, virtio_gpu_create_dmabuf() now dup()s the resource fd so each QemuDmaBuf has an independent copy. The scanout-matching loop in virtio_gpu_fini_udmabuf() is no longer needed and is removed. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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 1b89d939cfd3..c1981efa5cab 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1077,7 +1077,7 @@ void virtio_gpu_cleanup_mapping(VirtIOGPU *g, res->addrs =3D NULL; =20 if (res->blob) { - virtio_gpu_fini_udmabuf(g, res); + virtio_gpu_fini_udmabuf(res); } } =20 diff --git a/hw/vfio/display.c b/hw/vfio/display.c index cb83d98e9af6..89854eceb43c 100644 --- a/hw/vfio/display.c +++ b/hw/vfio/display.c @@ -263,7 +263,6 @@ static void vfio_display_free_one_dmabuf(VFIODisplay *d= py, VFIODMABuf *dmabuf) { QTAILQ_REMOVE(&dpy->dmabuf.bufs, dmabuf, next); =20 - qemu_dmabuf_close(dmabuf->buf); qemu_console_gl_release_dmabuf(dpy->con, dmabuf->buf); g_clear_pointer(&dmabuf->buf, qemu_dmabuf_free); g_free(dmabuf); diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index ee5f6f2f2375..c2018b41056f 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -390,8 +390,7 @@ bool virtio_gpu_scanout_blob_to_fb(struct virtio_gpu_fr= amebuffer *fb, /* virtio-gpu-udmabuf.c */ bool virtio_gpu_have_udmabuf(void); bool virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res); -void virtio_gpu_fini_udmabuf(VirtIOGPU *g, - struct virtio_gpu_simple_resource *res); +void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res); int virtio_gpu_update_dmabuf(VirtIOGPU *g, uint32_t scanout_id, struct virtio_gpu_simple_resource *res, diff --git a/include/ui/dmabuf.h b/include/ui/dmabuf.h index b972099859f2..968f3f9c8d48 100644 --- a/include/ui/dmabuf.h +++ b/include/ui/dmabuf.h @@ -27,7 +27,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuDmaBuf, qemu_dmabuf_fre= e); =20 const int *qemu_dmabuf_get_fds(QemuDmaBuf *dmabuf, int *nfds); void qemu_dmabuf_dup_fds(QemuDmaBuf *dmabuf, int *fds, int nfds); -void qemu_dmabuf_close(QemuDmaBuf *dmabuf); uint32_t qemu_dmabuf_get_width(QemuDmaBuf *dmabuf); uint32_t qemu_dmabuf_get_height(QemuDmaBuf *dmabuf); const uint32_t *qemu_dmabuf_get_offsets(QemuDmaBuf *dmabuf, int *noffsets); diff --git a/ui/dbus-listener.c b/ui/dbus-listener.c index 5a72c7eeae59..c1e86648384c 100644 --- a/ui/dbus-listener.c +++ b/ui/dbus-listener.c @@ -631,7 +631,6 @@ static void dbus_scanout_texture(DisplayChangeListener = *dcl, if (dbus_call_scanout_dmabuf(ddl, dmabuf)) { ddl->scanout_dmabuf =3D NULL; } - qemu_dmabuf_close(dmabuf); #endif =20 #ifdef WIN32 diff --git a/ui/dmabuf.c b/ui/dmabuf.c index 16063dc62ae8..697d853ad847 100644 --- a/ui/dmabuf.c +++ b/ui/dmabuf.c @@ -61,10 +61,18 @@ QemuDmaBuf *qemu_dmabuf_new(uint32_t width, uint32_t he= ight, =20 void qemu_dmabuf_free(QemuDmaBuf *dmabuf) { + int i; + if (dmabuf =3D=3D NULL) { return; } =20 + for (i =3D 0; i < dmabuf->num_planes; i++) { + if (dmabuf->fd[i] >=3D 0) { + close(dmabuf->fd[i]); + dmabuf->fd[i] =3D -1; + } + } g_free(dmabuf); } =20 @@ -91,20 +99,6 @@ void qemu_dmabuf_dup_fds(QemuDmaBuf *dmabuf, int *fds, i= nt nfds) } } =20 -void qemu_dmabuf_close(QemuDmaBuf *dmabuf) -{ - int i; - - assert(dmabuf !=3D NULL); - - for (i =3D 0; i < dmabuf->num_planes; i++) { - if (dmabuf->fd[i] >=3D 0) { - close(dmabuf->fd[i]); - dmabuf->fd[i] =3D -1; - } - } -} - uint32_t qemu_dmabuf_get_width(QemuDmaBuf *dmabuf) { assert(dmabuf !=3D NULL); --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:50:59 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=1788527572; cv=none; d=zohomail.com; s=zohoarc; b=U2jtpxDhMF6wGgtHbrJ3gwTu4FffPheof22qC4vzTW6bjuMIftolgVX/cU5/8bXJyUdXojADc0Nd8vTsZwfEnDN8Ey8LmPUn/pR90UNZtq28wx9vNrJ2xyIbA/icPcCKj6LLTlBZCPh4EDuU1vERrBRQreb5kh/SbjnQ0Sqgx6w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527572; 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=TCXucoL8Mp5Xawf0NyQ8CctTkqOhSXlAR32lSlOVTKM=; b=jie6adBc4rN7n/hJsR9uI/2L/ksqqP9uWytwYtYeYgJjGGGTuIqpqurMge6dQSkPazGsDxWuw0hh3aMpOOGXqWF35LF/a73KzcZBI7atnRo/YXxtYnuKMzOBOjBfqCrHKn277+loD5LX5L8fBbsXA0jpLyQTtZOkQzJpVU3bZAY= 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 1788527572615655.8206594603819; Fri, 4 Sep 2026 06:12:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2ThO-0004lJ-Ef; Fri, 04 Sep 2026 09:11:18 -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 1x2ThM-0004bO-Bh for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:16 -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 1x2ThJ-00056y-I3 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:15 -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-599-hj8x8K7RMguAjjHwYM08Lg-1; Fri, 04 Sep 2026 09:11:09 -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 7533F1886982; Fri, 4 Sep 2026 13:11:08 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 00A13427; Fri, 4 Sep 2026 13:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527472; 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=TCXucoL8Mp5Xawf0NyQ8CctTkqOhSXlAR32lSlOVTKM=; b=VMwsilzosFd86Ihbv1IKdeLg2duU72DTGjd2l7gXEdHH2/AuyTgnjInkCB7aQShYCitt7w wq3vWAA28h28+sKfyHN88TZudhwFtHVDEkFNem1YhzQ01lcTbrzVhL+MtzhQaiKWNsefSa 86lmhZE8biGhpITKiQbbrEN5BSSwILk= X-MC-Unique: hj8x8K7RMguAjjHwYM08Lg-1 X-Mimecast-MFC-AGG-ID: hj8x8K7RMguAjjHwYM08Lg_1788527468 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:17 +0400 Subject: [PATCH v2 13/25] ui: make GL context current before releasing DMA-BUF textures MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260904-virtio-gpu-cleanup-v2-13-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=7561; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=T5midtH6nj5RLjRDE79ajOg0zyaO3Y/HJs9rjpCqG3c=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMwdvWFsBSUuyaohx6UrgNFr22mCnK/jXLTQ +2U5xqE5/2JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDMAAKCRDa6OEJdZac 5e88D/9m1rzk9rjfWf18S7QgoGNn5hZNrXvOgdirYeFfJ0/y0K2A++NBUIsGE6X7oS0UjIZnD8j la+nCLQvek4oLl7u/04K6JjUfjZvySifR81JXH4Y03SevuNClB37G2ADpacLRfFJi4DbO257bqD Fyl7XypRBxHgtgp0+M6REop8B5uPo357eCMtTuxr+cgQ5gsU4tV/DiYDE60+ePIQSrvQhJu3v9+ uAzL/DphBDHpMcDCRgHckjGzfGNY/01F+i0CMu6aTJIzlG/d9FGymVFSLckHgWZpBilw7esi01i 7G1v0m1Z0Vs3gZI+BvaUtdtr+3efoSIx+WAhRUcW8z3vD9Q3Zhgxvzl5BWIK7JJq1FovUHEDhhE OOqBwy0Gk2z1kdpHI8+lW515v8Xm0u7FxP2RQ8ot5+Snxv7dPVwbzBI/M0pZ42wpwHjg0c2fhbL lWuprP6YpAUpGU04F3yf2Ez8vcnbwf0mpRRpcg1/6y9yd6ISsCRezIMtxzSk9iySAMW99Lk4Z4Y AdSCbnJISFemIT0VrBbM1yUoDwuzGvcrimNOgbwpw1D0QCk+ABbzWmXVbuzHOGUEQPRTV5te0+N mPjS8WjFW2FZKjuhjtoiAQOyAhlbZJcTsBcoGUYh3UAGwn7rgjxvxy9LmUF4Kb3xO7WXQY6b2MK SzVUY9kJX8cPUJQ== 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: 1788527573606158500 The dpy_gl_release_dmabuf callbacks in the GTK, SDL, egl-headless, and spice backends call egl_dmabuf_release_texture(), which calls glDeleteTextures(), without first making the owning GL context current. This is reachable after another console's surface update leaves EGL_NO_CONTEXT current (e.g. gd_egl_update clears the context on return). The deletion then silently fails, leaking the GL texture and its backing storage. With an unshared context current, a coincident texture name could even be deleted from the wrong context. Fix by making the appropriate GL context current in each backend's release callback before calling egl_dmabuf_release_texture(): - GTK EGL: eglMakeCurrent with the VC's EGL context - GTK GL Area: gtk_gl_area_make_current - SDL: SDL_GL_MakeCurrent with the console's window context - egl-headless: eglMakeCurrent with the render-node context - spice: eglMakeCurrent with the render-node context For GTK, the previously shared gd_gl_release_dmabuf is split into backend-specific gd_egl_release_dmabuf and gd_gl_area_release_dmabuf, matching the existing pattern where each backend manages its own context. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- include/ui/gtk.h | 5 +++++ ui/egl-headless.c | 2 ++ ui/gtk-egl.c | 12 ++++++++++++ ui/gtk-gl-area.c | 11 +++++++++++ ui/gtk.c | 13 ++++--------- ui/sdl2-gl.c | 1 + ui/spice-display.c | 2 ++ 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/include/ui/gtk.h b/include/ui/gtk.h index b66b9ca5c519..6b62e9758813 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -163,6 +163,7 @@ extern bool gtk_use_gl_area; void gd_update_windowsize(VirtualConsole *vc); void gd_update_monitor_refresh_rate(VirtualConsole *vc, GtkWidget *widget); void gd_gl_wait_sync(VirtualConsole *vc, void *sync); +void gd_release_dmabuf(VirtualConsole *vc, QemuDmaBuf *dmabuf); =20 /* ui/gtk-egl.c */ void gd_egl_init(VirtualConsole *vc); @@ -190,6 +191,8 @@ void gd_egl_cursor_dmabuf(DisplayChangeListener *dcl, uint32_t hot_x, uint32_t hot_y); void gd_egl_cursor_position(DisplayChangeListener *dcl, uint32_t pos_x, uint32_t pos_y); +void gd_egl_release_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf); void gd_egl_flush(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h); void *gd_egl_scanout_flush(DisplayChangeListener *dcl, @@ -221,6 +224,8 @@ void gd_gl_area_scanout_texture(DisplayChangeListener *= dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h, void *d3d_tex2d); +void gd_gl_area_release_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf); void gd_gl_area_scanout_disable(DisplayChangeListener *dcl); void gd_gl_area_scanout_flush(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t= h); diff --git a/ui/egl-headless.c b/ui/egl-headless.c index ba27efcf4c3e..ffe7b30f919b 100644 --- a/ui/egl-headless.c +++ b/ui/egl-headless.c @@ -126,6 +126,8 @@ static void egl_cursor_dmabuf(DisplayChangeListener *dc= l, static void egl_release_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf) { + eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, + EGL_NO_SURFACE, qemu_egl_rn_ctx); egl_dmabuf_release_texture(dmabuf); } =20 diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index 8623181336e9..d595916476d9 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -426,6 +426,18 @@ void gtk_egl_init(DisplayGLMode mode) display_opengl =3D 1; } =20 +void gd_egl_release_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf) +{ +#ifdef CONFIG_GBM + VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); + + eglMakeCurrent(qemu_egl_display, vc->gfx.esurface, + vc->gfx.esurface, vc->gfx.ectx); + gd_release_dmabuf(vc, dmabuf); +#endif +} + int gd_egl_make_current(DisplayGLCtx *dgc, QEMUGLContext ctx) { diff --git a/ui/gtk-gl-area.c b/ui/gtk-gl-area.c index 45c0c8c81a11..effd88f28721 100644 --- a/ui/gtk-gl-area.c +++ b/ui/gtk-gl-area.c @@ -360,6 +360,17 @@ void gd_gl_area_scanout_dmabuf(DisplayChangeListener *= dcl, #endif } =20 +void gd_gl_area_release_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf) +{ +#ifdef CONFIG_GBM + VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); + + gtk_gl_area_make_current(GTK_GL_AREA(vc->gfx.drawing_area)); + gd_release_dmabuf(vc, dmabuf); +#endif +} + void gtk_gl_area_init(void) { display_opengl =3D 1; diff --git a/ui/gtk.c b/ui/gtk.c index 55e45e8445bc..c615d35451b6 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -584,21 +584,16 @@ static bool gd_has_dmabuf(DisplayChangeListener *dcl) return vc->gfx.has_dmabuf; } =20 -static void gd_gl_release_dmabuf(DisplayChangeListener *dcl, - QemuDmaBuf *dmabuf) -{ #ifdef CONFIG_GBM - VirtualConsole *vc =3D container_of(dcl, VirtualConsole, gfx.dcl); - +void gd_release_dmabuf(VirtualConsole *vc, QemuDmaBuf *dmabuf) +{ egl_dmabuf_release_texture(dmabuf); if (vc->gfx.guest_fb.dmabuf =3D=3D dmabuf) { vc->gfx.guest_fb.dmabuf =3D NULL; vc->gfx.draw_submitted =3D false; } -#endif } =20 -#ifdef CONFIG_GBM static void gd_gl_fence_cb(void *vcon) { VirtualConsole *vc =3D vcon; @@ -639,7 +634,7 @@ static const DisplayChangeListenerOps dcl_gl_area_ops = =3D { .dpy_gl_scanout_disable =3D gd_gl_area_scanout_disable, .dpy_gl_update =3D gd_gl_area_scanout_flush, .dpy_gl_scanout_dmabuf =3D gd_gl_area_scanout_dmabuf, - .dpy_gl_release_dmabuf =3D gd_gl_release_dmabuf, + .dpy_gl_release_dmabuf =3D gd_gl_area_release_dmabuf, .dpy_has_dmabuf =3D gd_has_dmabuf, }; =20 @@ -673,7 +668,7 @@ static const DisplayChangeListenerOps dcl_egl_ops =3D { .dpy_gl_cursor_dmabuf =3D gd_egl_cursor_dmabuf, .dpy_gl_cursor_position =3D gd_egl_cursor_position, .dpy_gl_update =3D gd_egl_flush, - .dpy_gl_release_dmabuf =3D gd_gl_release_dmabuf, + .dpy_gl_release_dmabuf =3D gd_egl_release_dmabuf, .dpy_has_dmabuf =3D gd_has_dmabuf, }; =20 diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c index 46eff768c968..3a5aa09618ca 100644 --- a/ui/sdl2-gl.c +++ b/ui/sdl2-gl.c @@ -288,6 +288,7 @@ void sdl2_gl_release_dmabuf(DisplayChangeListener *dcl, { struct sdl2_console *scon =3D container_of(dcl, struct sdl2_console, d= cl); =20 + SDL_GL_MakeCurrent(scon->real_window, scon->winctx); egl_dmabuf_release_texture(dmabuf); if (scon->guest_fb.dmabuf =3D=3D dmabuf) { scon->guest_fb.dmabuf =3D NULL; diff --git a/ui/spice-display.c b/ui/spice-display.c index 75c7df7bb5e0..22cd1e266caa 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -1176,6 +1176,8 @@ static void qemu_spice_gl_release_dmabuf(DisplayChang= eListener *dcl, ssd->guest_dmabuf =3D NULL; ssd->guest_dmabuf_refresh =3D false; } + eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, + EGL_NO_SURFACE, qemu_egl_rn_ctx); egl_dmabuf_release_texture(dmabuf); } =20 --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:50:59 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=1788527597; cv=none; d=zohomail.com; s=zohoarc; b=Fp06RDPgT4luc5D5K8rGgGyXTMZea2no0lSOo+ejY+0jzaMt0+rGp+qHW9V0Do7cRUjYyzMqYL9QeheGhmNRq7X3GQVS5M1WZ+3QgqIr4OTP31bbjkdGLsCPXD7+ycI9eboM6Tp2J9Zp7R5aOofczLjAR+8YmQBpmRU4xIR8i/k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527597; 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=dylo7uRlN2jGtbkt4NZGoGkiwnxIrYCu9WsQYWsaljE=; b=DByK/oQAEfB8rutU7xB+G+8YnWTLoEXG5tcmXLpWuZzCdd0OzBVhkVZ3rhp0/AvWBH1zuj7ChGrW0f6mdapsifoU6JgUXMat2EkjgCDKvVwZrJ2kCNAFT6qrkQ+ekPU8DpKREPOfqL92ggz2M4MML3jjf5hT9funekUewHC5j5U= 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 178852759733925.150930541103207; Fri, 4 Sep 2026 06:13:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2ThP-0004np-Cx; Fri, 04 Sep 2026 09:11: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 1x2ThO-0004kF-AG for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:18 -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 1x2ThM-00057G-3B for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:17 -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-372-U3kZN3UbOf-aub5n0WmIMg-1; Fri, 04 Sep 2026 09:11:14 -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 D812F195FCF6; Fri, 4 Sep 2026 13:11:12 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 561721955F10; Fri, 4 Sep 2026 13:11:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527475; 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=dylo7uRlN2jGtbkt4NZGoGkiwnxIrYCu9WsQYWsaljE=; b=GjFtQeZhzz8MlmtGMfEEmLVGKuMgTT8vAudJyNsOTnAi4KQ7bb9aYRpoIFs2nZTa9mHphk xhwZzsh5JT/Flizu2p911H9vGxk4CxCBdeiFt7NOXrfwCaF8m9w8Vl6ucUy4vX7eW/ddWG v9tfsBmAQSnr54OO00f8wMZkhHhQQ/s= X-MC-Unique: U3kZN3UbOf-aub5n0WmIMg-1 X-Mimecast-MFC-AGG-ID: U3kZN3UbOf-aub5n0WmIMg_1788527473 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:18 +0400 Subject: [PATCH v2 14/25] 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: <20260904-virtio-gpu-cleanup-v2-14-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=1537; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=G+Xs5SEHOp7PGnyBeL+nUCL9JN/NzEETW+C6fPka598=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMwFheo9Gf3g6VUTd87kEQ+9yngba7wFeNW5 ytoeNhSCwOJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDMAAKCRDa6OEJdZac 5WLfD/9tMlPhjNoy325UJe3qw2pFo4LDj/wzOA/ue1Jvm4ZhPqWFt2SM93kjqh2MO+/ZpH0zstY fDnBJ0cn+p6klPap2bNsFWsoA8rIydbNcDf8X8YRelwgo9xGcSb/J0cTm1S466zVHpq9cNpcgHy Lq+jErJw1rmxds5V3dXXmShDipawsC1fgY2cxCeBhk473P5beoPoHm7Qsmn5paXpOHNMAZDCnlv /K8nE+JL4AZ6kNYkAPbWSm872uHJiqVTnKJACtL57Z3aUput9/fmC4P0xvtwWYvtvucDi1ippel canThvmYxB7XbwlhYc4Sg8u1bVD9szvRWT2Jxr+3NkzXNZdBKBLegB/IwHs9snl+/P6q//c9lRf NtjHFOfcHiAT1z6kNVVOmUTPzJ5NDhJZanXjAI6Dk72QTtzHCDmLKF/QINvVHgPHY9PrVPXIeSi qzeol1uShOYKJsmXiPVpfPMMthryQf6Fk2rZjFx9yNsynEnhtZVvPTkdW3kqJyqy616fKzQXGVf Xn7tGF5MfrJfckXJcF5JetwXz1rZ5YU7gQH5npQyE5ZrVrizZT9l50Zv5IZT4AW/KcKUyoyP2pb l1f58ZiaZ+ZHrNQzBPtWT9xb2V/FeMf4tDXRn5cUNhUUh92T0T8/yYc/xjx0bMGx8OIdzITMoqJ DcM+d/nvgTn4PfQ== 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: 1788527597668158500 Rather than waiting for the next set_scanout()/update_dmabuf() to replace it. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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 c1981efa5cab..95c905b4fec5 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:50:59 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=1788527590; cv=none; d=zohomail.com; s=zohoarc; b=cXk9tq5LL3DI+VnYXLUaVucbv02lUCzeAvt8Oed4tX3Yi6hPxSb1+lOXY4lcBMM0KkFQ8sbG3wwpJ9GopMnvas+YSziINe/JZnqEy9DLvn2ryBsrjFjhe0mCdsdIL1se9OGkihfsHfn5MXWxg1i9NNiqxMQYBocHxOOFjXp4Csg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527590; 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=1ogN5Q72a9eOOhrFxC1dZ74jR7oqZv4dsYzPV0Ax+hg=; b=lFNTRe5mK28Aw3TMHW01+2W0fyFYDKK6sEM+AYP8KJ6I8lkkCQ4QVwyCJC+vpNBGziA019QYsDvyBRTZcpcz+ggTLb4iqCv6y6LPp0mW++3LKZLRUI4tMUopBgc1sd03bqnhjgcbkX/8DbXUFzT1HwhiKYh8c1IGtX1jagM3tqM= 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 1788527590605565.974664624902; Fri, 4 Sep 2026 06:13:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Tj2-0001hC-9k; Fri, 04 Sep 2026 09:13:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x2Tj0-0001gL-AW for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:12:58 -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 1x2Tiy-0005bH-QZ for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:12:58 -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-541-EbiRTzPSPzOzGJJ9W9JE6w-1; Fri, 04 Sep 2026 09:12:07 -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 9A34E195FDD6; Fri, 4 Sep 2026 13:11:16 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 71AA51800765; Fri, 4 Sep 2026 13:11:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527576; 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=1ogN5Q72a9eOOhrFxC1dZ74jR7oqZv4dsYzPV0Ax+hg=; b=IrGcFgV7xXapFiQEPaQ7Qhvm+lzKNeGQoz/G+2zpXV+Sbelj+6QtUPlSQ7WKFqlSMMJCTm bjoPUEnkTkqWpgsP0nkHZqphwU072k5OvpiNywjCd+Sw49vpnD1JTn4EnEqyC9AFFflKao ivL1+fzc5hnpYah6VLNv4498PxKXfWU= X-MC-Unique: EbiRTzPSPzOzGJJ9W9JE6w-1 X-Mimecast-MFC-AGG-ID: EbiRTzPSPzOzGJJ9W9JE6w_1788527476 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:19 +0400 Subject: [PATCH v2 15/25] 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: <20260904-virtio-gpu-cleanup-v2-15-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=3094; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=A37YX35GVOBJzZqDYHROObSH9zDX7yUaTjA+BdwdCtA=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMw3rwQyqGzGEdWC3EnA3uCvTrD/oGcvAH8M R+zGhm/S6+JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDMAAKCRDa6OEJdZac 5ZbTD/9FS0blJynzNZka7tkWfR/TFiGHingTv0MQrqLyDjBtmS4XiU4s7HVBvsMNrn6GBlOhXuk 4ln8ZSsHpQ+V2778pJekKPFy7eNPeutlx2LFR7eeO7EkiRW2DjItV/3KQ2Nj+jxg21dqHZAmDxL x9lOCj+ZirFqDVOUUY/DboUEuYydZNUc8dfhIOXtBLT+5qMXwwkwscRbr9zgStzXpQpyZnSYLzE 9rJiqsLxNFnM4AQvmTowNXZf1fwzoZnwFdrEAEOJypyXLKuJ3ShGt4CFcuZyi9IGz/mxtg7ZG6D shKd77KFDY0khDpA3xgGafKKR3XTgoR+Nj5YCH9hDAB3wjV4+ckTYdSnEwwF94f7QPUD/vmVeno 0dKSN8oJvN8Aw9oiiFAlf2G86hy2bhbiB6HlevgxIfuJIgxFkoIBR4Z8TyOZ4ckx0pTSD/tc+qF G8OHQJMVLxlVOo6sRs17R/HcyJjqGFtBJN6yLWcZDpHotposmM9lZ9NDfBNtb+l9IqAG22OkMNk /7Du/bfqi17PAhl+/V1MNWGt1xrvi5vdJXkcmHE4pOVR8SwAUsvgWjD0hCbZcLp/hJZJ1mExGXt fwoYmYYtj/54VajiZSTbhtFxHzqnrcsdHrDt1kj54i2rX+johiVgiAVDZvdWD6PPDgLFKH/+AhR B2JgdWcotamK+8w== 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: 1788527591657158500 The per-resource scanout_bitmask is a reverse index of which scanouts reference a given resource. The information is already available from scanout->resource_id. Performance impact should be negligible. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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:50:59 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=1788527589; cv=none; d=zohomail.com; s=zohoarc; b=RhkCN7+QhT70ZoLwh1fM4ah4ASUXZmq9aTLq334dKYs9rzHzYKVP6jX7O/i9pqtQwAvb87jlqS1+IN0mPGl4Teke1iygDugTrlk+rEbWBv5kDuBfr+POzAFYkDTKImDCI7CYVW7N3h1SJgcTahA7xkFGQ7J+3i37mG4ChsvJumU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527589; 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=ibqhERt06xtbZ3QiVCu/UfPVG5M/nC53uPXTo21sXrg=; b=JzLsqCYgEjqDFm50Rs/vlFZHeZfCAeG5Ue/6uQwQcG0XAKCirhqQcGOzoVS1LKPuFqcBErhaT62O+F6F9qGjVHyc3Nb65os2M21XRBwDGYy4Vx4xOyxggGcNQ3cHsx89iAnJKnxbhzeRbxgVClRRckegqnQlOxS/vYj4RTrArzc= 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 1788527588992354.4754628080103; Fri, 4 Sep 2026 06:13:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Tha-0005M9-8C; Fri, 04 Sep 2026 09:11:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x2ThY-0005GD-O4 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x2ThV-00058w-CY for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:28 -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-577-yg1C7L8lOgyp7nTKK8KbuQ-1; Fri, 04 Sep 2026 09:11:21 -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 1FAA518D7265; Fri, 4 Sep 2026 13:11:20 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4F2771955E72; Fri, 4 Sep 2026 13:11:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527484; 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=ibqhERt06xtbZ3QiVCu/UfPVG5M/nC53uPXTo21sXrg=; b=GhZpf9Z/Oj6yzY6E0orRacz9wEqi95bzTAh/TB4EgSmJSWOg4UfEtvLVcQ2ByvADwx+mYa IRlkY9FIUZFIv5ofKl4L3hc7SU+2QJm+I8kqBY/bdddZ8MGiVYtsY9TPndzuzCOWIcZStt QLbOoBy3p/rrz/NnKqlplspJyZKlWMg= X-MC-Unique: yg1C7L8lOgyp7nTKK8KbuQ-1 X-Mimecast-MFC-AGG-ID: yg1C7L8lOgyp7nTKK8KbuQ_1788527480 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:20 +0400 Subject: [PATCH v2 16/25] virtio-gpu-rutabaga: fix scanout handling MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260904-virtio-gpu-cleanup-v2-16-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=2992; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=3zs+1jG7cAuagGUnkATpCae6RXUVUGEBt/fm+AZmRak=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMwElbKqp8cUBh5sEQaPEYKq8tiiLHOLbzBZ wZNnf+2oDiJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDMAAKCRDa6OEJdZac 5TWZD/9DjGUTtvrKaPmAGod7GF8papraFLOWwf8DHqdL7jvngNCrau9tjrpshuzzqqphbM4NJD9 U9HcLOyusTaQOiLVxvYgsvzhZWQX0C7utCdnOYwyfzFHttz/GQ4M7xlDhLydDNih0sBBXn87RCl 3SGh1Ex926azJRnyiOKUStXa4ATkD+cjVBqFOMZwBTz9r3E7NcjmVIatC5T38sHojuMxzpfP6ud NlEkPW745WOfPPygbQtClTlsyCYTZRUv9osBTGb0IIqScdZIsJ4fmgqir6YORxOqL9KczY6o3xH 5OH6VSRC8brP0VhSU89xAcXhns2OJrwjf3/KxR2sgaDn9956mfOuo1Mzp4E4D4oMIrAfwGh3Ike lRXCMnmVEMb64BJWVOzFM7/lU4WG9Ulurc+raAA5CAHo+CCMtCg0xrwMm+3A7dDe6YS4/LY1na2 OvtflSgHWaAnG0bWdT++XcAA/i9e50o7ybGUTmKQgOycUhGe/ao7s58LtobSCFZq9fPt6ZdRBwR aNDwOkED7m2Pygl2MJS8ecfgvyrlq0kOd7kEWuNemtyk+txHmlfrA4Qx/SzB2Eg/O3R3Teb5dvx TfpEqWFslP0YM/Ln5WxYc6jcq3kM+mjGs7p2DgO81xyO6Cx7cfdt2CFAaz1whrlpb5q4BnNVe9J 7WkMKfqeUO02EGg== 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: 1788527589605158500 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") Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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:50:59 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=1788527538; cv=none; d=zohomail.com; s=zohoarc; b=iJZ278FTRRptoTYtUN4098rqqnpDOSZWJIEZh7kbzEOwnigpRobAkM3Xu0j2dxGGqyy3BEgsE/ZrLBNuOHaH1SniRlNsRQ1tFenuuOH4jDh4bJ43pmGkorIbUUtcww2+uwqdle45CwRdslgZkRjG5084cw5sgiVjVuaX9S1msRA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527538; 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=dAaK0yhjS0Ztp5ky/+LpGTZUDzifpD2VL1IIx2cZVaI=; b=kGrmoPG/ypAr6sD5XcRX5ZaIOi5PFNrmIqgXjFpwyDRqV9L5VPM2rqbi7P6luRGnSvmOFjlZEo2kVNQdw3Zz0m8cfF6loM2Ud8Y2f58izQXWWVfF41YcjpKUkQxuDT8v8oUgHx/C+6MAJ9yf1Ozx1XlSCLMPcyauy/++RGORd7c= 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 1788527538934793.2622754577994; Fri, 4 Sep 2026 06:12:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2The-0005bv-No; Fri, 04 Sep 2026 09:11:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x2Thd-0005Yl-CV for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:33 -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 1x2Thb-0005Ac-M6 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:33 -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-319-cv97j8h-Mm-F9bfC19pXCQ-1; Fri, 04 Sep 2026 09:11:25 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CBE8B1925776; Fri, 4 Sep 2026 13:11:23 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 740CF3000223; Fri, 4 Sep 2026 13:11:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527491; 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=dAaK0yhjS0Ztp5ky/+LpGTZUDzifpD2VL1IIx2cZVaI=; b=HRutBHTO8QO74TRk2PSnRkdUe1EqpWuHVKvwtLaSKAzqNj8ooY3GTPZKzexuqOzkZVeaXW 2a7zSh9PeCqHmR5p2J1RYA43IAcJkU2mguIEp811BBpVLqZbST3xn2ROgIDbQgkzxkqjFy FxaqVhMXMdEpnzwTqbI0OL8PkcoCQmE= X-MC-Unique: cv97j8h-Mm-F9bfC19pXCQ-1 X-Mimecast-MFC-AGG-ID: cv97j8h-Mm-F9bfC19pXCQ_1788527483 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:21 +0400 Subject: [PATCH v2 17/25] virtio-gpu: drop scanout_bitmask bookkeeping MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260904-virtio-gpu-cleanup-v2-17-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Akihiko Odaki , Dmitry Osipenko , "Michael S. Tsirkin" , Stefano Garzarella , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=3533; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=jQVxNMscLnmbP4WigWrn6p+D1DEvXhd1N0hmCD3n39Y=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMwZQRgaiUJDuJ9lp556ITBI0zt9mImsouBZ UGa7XeCuwiJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDMAAKCRDa6OEJdZac 5WAiEACLFX67Aid+xTxLoBe4C1tl/mGUtomfc3WRKZa6F/gkESkf8NC7nvQmlUSzyAWWyzND7GT 52wjIq3J3GFaD1XP31hpgxXGePY6kPQJO98IVREKxyOnOTFErlQS9LFOJ21hnqPmNs2/AIpQUQE y2PtpsNLMzJxA6gKxn6xvr26d27pTazVEhxYuBqUg2wpE1cF1N4s8yox3bi3FkTsphAdg4xxA9P mTueEhm0Cq6gapEWOQq0GTh3ST/CEzu+RQ/690l9lys7lZ3sxPkOAEBQwCx/oOoJtg4+AybFIrh ABhmlkdQsLZmslxlaAK0WPkyNhhsjRluD0Swy2Gw0qj00Tueef9k0tPsl05yKtVkYQzEj19/1OT Dz0vObrBGYGhoPFrsWFzxMr2dhdw+IrrmrIIr8zeGTlSWFvmzWZglBaBKP4glg68ncJyvru5anE 0U/SUY6WrL+oy51BZRMzU1F7dguE40955y64r1ysFqIpIyFghHc2GwKU/47pXJw5gTWIc/pOxRB FmvNKJu+3D3XHyfY3Ei7I4QWsC3U2Hn9Z/lK4/Z9Bih/buvpEdOAuChtpNnlvu5/8YxitBJGJD5 qz39YBeyqbNdYVJz+OjWLKeqb3IVKamSl4wekphM+dmLJV8oGzhI3lglM8L27LWlCN/Wh6Ki3O7 AQTD5LgIJN0/kfA== 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: 1788527539260158500 The per-resource scanout_bitmask is a reverse index of which scanouts reference a given resource. The information is already available from scanout->resource_id. Performance impact should be negligible. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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 95c905b4fec5..b244afb69e4e 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:50:59 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=1788527534; cv=none; d=zohomail.com; s=zohoarc; b=kCcP4UJNDyvRgPTmo6HLpK3CJFsoLjZp8n/tNd2C1qkHKGhJwY7urcmy5RdHhl6p2JnwC8BrKqe7XOQFrLc3jfxe96p6gxIL86TuzT8qieQWSGI7unddLhvBqdWEXBeC9amm+TggeNIx6CUCNJK4Ua3Ji1DzBg7yBw6K//Czs58= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527534; 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=tpR6y0YPua1oePMHs+e2bIlt2sPRGymy4HgKrE81ORM=; b=TT0rNucwRwDU7LhomBuo3WWGO8V+Cebj5nT4FJoVsasGdKdm9z+S/JFPanaMeapQ8wNNZB9ZzxqxPXTO7EUFB8uWOmJkcI1/qvk9KemtGyAjOl6B9sstOCMBHNkszWLwJg04lfe93dFYRVezcf0RTVqdffC3ZYDMR/eA138Wv0I= 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 1788527534943407.6856260915947; Fri, 4 Sep 2026 06:12:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Thf-0005e5-Tp; Fri, 04 Sep 2026 09:11:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x2The-0005Zo-1b for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:34 -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 1x2Thc-0005As-H3 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:33 -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-111-vs0WJcfFOK2u63fyromsyg-1; Fri, 04 Sep 2026 09:11:28 -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 4D09418DEB01; Fri, 4 Sep 2026 13:11:27 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7E88A18001D0; Fri, 4 Sep 2026 13:11:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527491; 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=tpR6y0YPua1oePMHs+e2bIlt2sPRGymy4HgKrE81ORM=; b=NL86Ug/PN4grDewSgdKjw5K+PSB3jTGhycIwlMa5udcy6oPnh3AIpYUW6atSpCKrNz9820 GeK4NQ9GS/hAPnmmYfiNMzum01DAr6ELVwDjWF0TFzgIktRKB0naxEkWzQUZ6MJv5CGyEs FuleyeX9lzj+KugUTj2vTg7m9H5ncW4= X-MC-Unique: vs0WJcfFOK2u63fyromsyg-1 X-Mimecast-MFC-AGG-ID: vs0WJcfFOK2u63fyromsyg_1788527487 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:22 +0400 Subject: [PATCH v2 18/25] 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: <20260904-virtio-gpu-cleanup-v2-18-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=2545; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=Ke8qPQ1kPjfvFQxnwuX6hhLMR1dx8hj/OM/RSRZyxhw=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMwicrk01vChlKYDR9AmKrP9QddpRS9neLz+ hOEJQirIFuJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDMAAKCRDa6OEJdZac 5Uc/D/oClVaNCgfAiZkMu8TQ01UcWSt3P5d5DFjdPd2hm02bsGBurhLRZuGY/3MxoKTNlWKi7iV Wqu6B/8dvtpLNN5NT62EE00owx1kLZzozjqElREGkO1BZGZa3pnODekXD7j20rmVmMGE8BfhFa6 Be4jedLl3bQ7E8c9SUFyOFmIpB7kFI3k9it+DuBk4Im5134AcvYiXINJ5PEUQsLsJK5jvPv63Sq rgvDGW4XVjDTHw5fZcMS4pH9GH+2PIMzzEhfxkcROBWKprGsB862YLsnVEprX2n7cCn1MwD4Wb5 0BjEdzRiRGFNj58rDFsWllQ/nKcsgd0egFlTM6EI3xO0DTqVsrz8x9+CzYVmdLRPbQZQBNvqhuj +KBujY6rzoHLJgtdVisC0nVEN2A2n3TlUHKPHRhtYGZcgL7qY4Wt5iSSO3ffM5XehE1owsntwpk xrepo5YZW5waA0sKklhbav1NsueVNckvFKD9EMp+ipiMXufcPOd+3nv/GBAqBgxiU+lrvT+jzMf NN4eHfbiCHtL2Nmc6G31TUyj5SR2O1IarEiwLA11JewbMWVer4JmddhOz6Bho5EuRLgMhyolima WZlA4kMrg/MIq/ntPFUxlZzbfydpz2bczao6XIOtATJPJjgshKvt6cTTd/p19dT82Tct0W/rwDf M+1m101xVK6G4UA== 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: 1788527537290158500 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") Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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 b244afb69e4e..5c3cd2fb4616 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:50:59 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=1788527571; cv=none; d=zohomail.com; s=zohoarc; b=aFvnNSxu63tGZQPBP+k+Ll+MOX2pqVa/XBbDXP9tTop8GzJEQIQz+rXmKqHSeD20KXOJ+qG/Wqk6Ykm1I3naXccMI/vbYJqzDQ1lYs/VCUi9opz/FcaLSEIk1/fPxAxLgdMSZSYYa0IsMyPiQU6WwjubHzIfXhihh9YMPNXf+9k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527571; 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=FCNMy2CvVf79esuze58qFl+MHajxnyU48srBBmsZXqc=; b=ZnSQZfLd97Id6YjPY+gFKqCms+lOfixU+Ok9E4zvEn+k1/ahwfVAE7dR6/qpCLreGqJ+Nimja97VHVoq/pqc/fybT/yRA8lCkE/CP4rBYxTVOgNTTMJ1PC6TVZlfJ4KKYvsmIQegefMCqeIJrV+A5UjZB2/kYvo2xz4AoD74xPc= 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 1788527571187435.7065799495256; Fri, 4 Sep 2026 06:12:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Thl-0005qb-CJ; Fri, 04 Sep 2026 09:11:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x2Thj-0005jf-JW for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:39 -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 1x2Thi-0005Bs-30 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:39 -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-591-1ZHmQ0fYMgCZ4jotAIFwpQ-1; Fri, 04 Sep 2026 09:11:33 -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 271C918CD289; Fri, 4 Sep 2026 13:11:32 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C349A1955F00; Fri, 4 Sep 2026 13:11:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527497; 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=FCNMy2CvVf79esuze58qFl+MHajxnyU48srBBmsZXqc=; b=LekMdxLCqqWFB5/HA7OkfmsiP4EtVXp9/JmlB6ZC0BihzrEdgobEgcg2TF0Mv0Xy4c3VUv VgVGvbclech0gJn6WBZbXGNvqRCybJp7SSZsuiCxO1KWIlQppDBC9e8TSjMDFqPLsihJQf bn2UWYC7ekwlOyhnWxR8wZP5Hk6QSzk= X-MC-Unique: 1ZHmQ0fYMgCZ4jotAIFwpQ-1 X-Mimecast-MFC-AGG-ID: 1ZHmQ0fYMgCZ4jotAIFwpQ_1788527492 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:23 +0400 Subject: [PATCH v2 19/25] 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: <20260904-virtio-gpu-cleanup-v2-19-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=2326; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=eW7Q8CWWp1NbLU+0pwDCazy7H8yDhaZDMn306wrFAB8=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMwKvdNVgzAEaqFyjI+xGJp4ZJb/OYOV86CG B9Bm8jptkWJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDMAAKCRDa6OEJdZac 5dbHD/wI3JMFuyCFjliZK6lQWP7kwxrwOCU9ovd5FNr5ilkRL/EJWQs4m8WEUPsb1XJquRAPZLq FG+iCG+73B8DjL7fVRk257K1d1Mi8C4doimGlmJkjiaH07U+2kmdgWc7Ju/Lji+olRjqqjxdfx6 YTOkQxtaqGvO5fJgGuN488ANZxbtj+wzwTOHSjCae5nPSiYIdKDoopbd5oqzywP4A7oOe9dpRMp qxFOZMCX8Wk5lJ19gl9t3bU9rpoqh7jsFhtWt22DQYpIkkWtmol/1ZnsVm8VECd/uv5wo38O5+c EaUS8FzRzMd/ktgqTuXATX7H6t1RrknZ/2XjyPlyazLQyw0VFE/QYE1qAEiNy7Relu4CAX7gtuq GIVD7zh2iUdr57koqGJu/v/c+IBwv9Bg+JHeDbDPRYRBQCKlzNFTHgO5blt3rEceW9nc+mSgd7D Dco5Kx7wmirObQojENg4KonGck3OSKwy+Kdrj7hUDzRWscYmG1pgq4ZpRIjFC6422LN8R5uIijA 43tWOjQivewlY9LLMIKVPF2cRpGK4r/VqhCQapmw0MCCdtyQUTTVF5Azh0QoeXTMaBYEpQPssAQ 0PJY9jKN39zf4Zov5itmNEf8VJ4qhRb+NPRp8zlb317UiP1pYqe22SWTQjnjuB3Vc9WVpOhT3Z2 Ih0Ttucw7bQc2Ug== 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: 1788527571503158500 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") Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- hw/display/virtio-gpu-virgl.c | 3 +++ hw/display/virtio-gpu.c | 2 +- include/hw/virtio/virtio-gpu.h | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 7f1d1e0c3276..79d4c0b569fb 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -605,6 +605,9 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, &cmd->error)) { return; } + + virtio_gpu_release_scanout_dmabuf(g, ss.scanout_id); + qemu_console_resize(g->parent_obj.scanout[ss.scanout_id].con, ss.r.width, ss.r.height); virgl_renderer_force_ctx_0(); diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 5c3cd2fb4616..ae1f87ad68b2 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:50:59 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=1788527546; cv=none; d=zohomail.com; s=zohoarc; b=A59kbZt4NRXyTwTfASg+E0SGbz1IKYfX89ng9mqRBZy6nAK6I1euIBbyrkVClTgDEwYk4XrN7oyBSWH6vcbC/v522KflHvzxjh87fYYAd5ucIXYp8LvG+Uw0L/qaIcHfUzzzvBmXu83ZTZ8JYnBqjb9wwTJbpZz3iqEDSvWf83Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527546; 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=Efx/zhWGeDCKFdjtEJc3Lq+2TrEFGjPToQFoP2ihkTk=; b=AHQ2rQGEjjryagaFZcas1mwEOTreYfWa5wUgjK0nHmHL597mZ6WVbCN1xESIrUkoKb13OdrMfZezzRIFs9UrjSxlibpMK2i1OS/e8HhdmQaOA6cjWJs0d/Ws5fhNG4E7gFUIwKUVCKGBPRKip1Z6uXxWS1HrC0p84O5BdQqVdpI= 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 1788527546613735.9612756751781; Fri, 4 Sep 2026 06:12:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Tho-00060x-Vp; Fri, 04 Sep 2026 09:11:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x2Thn-0005yK-Dy for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:43 -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 1x2Thm-0005Ch-03 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:43 -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-396-K3JIAV5HNuOeHNqxG9pLJA-1; Fri, 04 Sep 2026 09:11:38 -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 D9F05195F14B; Fri, 4 Sep 2026 13:11:35 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CCF7D1800609; Fri, 4 Sep 2026 13:11:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527501; 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=Efx/zhWGeDCKFdjtEJc3Lq+2TrEFGjPToQFoP2ihkTk=; b=AvYx9GQs/ZwGLxkqMfDBut6B9L2x3aIPGXqDL9M9xk3rz35hehNWhV+9qRjNRxD1Q5A4o3 tuswTliQFT6I+4zIM9kvQ+vXdf44zGfDGqzRwagaqEZaNxLkZPiZ4cmhf94uXvkP+gm2zq 8OfHZR2OxAuXDONWY9PrITDwq/AMJN0= X-MC-Unique: K3JIAV5HNuOeHNqxG9pLJA-1 X-Mimecast-MFC-AGG-ID: K3JIAV5HNuOeHNqxG9pLJA_1788527496 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:24 +0400 Subject: [PATCH v2 20/25] virtio-gpu: consolidate disabling scanout MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260904-virtio-gpu-cleanup-v2-20-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=2773; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=/TWjBGhK7kLsr8SXcbZYQUN0FT/lpu0Z0T0eXdCKmKo=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMww2hrEXTlaahvY5lG2mNXNHqHTdYhu9qPq xJ7LGf8dMaJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDMAAKCRDa6OEJdZac 5VITD/0eTmXuJcuSvkIqP3Cerc9O7QCOlMv54EvXBPomwMjBqvU7y5ifH9HmuhXt5JJw2feH7Nz Rf33m6WaGwvS3IgRFAE4qqXEAnlpB3VvY67LaJoMccQNFVpZk09z0d8fPo2d0SGM+Oq4AHV7237 +SgNElNI2fGRiQT5Y0XBThhJZw8ZLvwKorwTwkctWWbcWsXUnLpvNg1Pn/bcSngpdfqbVOSqZHU s0hJFYgd/NkrsUaLD6/NE7chIkEY0OEq0QrMQ/hfkDrdfG3W1/UpLYwYA5BX+9DlzrHiXQKcFn3 qewgHo/vanLoXPTQ0Bqdf5rUf4XHyFftkgDxJRMpZUa9PWpw33CJn6h5lEyy2HIsgUBbrcoPbQz Tpgu5OO/gWwE5QCTErM0LwuT1HoC3nrgQ4YLhtBsJxk1EMH8wnxaZd4flxaIttmGpyfhr62DRh/ OV1CF0zeSwd64Gxzcdrf5yHL8aisWpkY+GVTsM4XhwbwMAq0Ry4/o32zDmp+xTYtesdogSCiHTF wsx5JRgvrK5JtEIk1a1k5hThrb7o2Rj3Ko5q4hOFl1UBCAhoA4qpEtIFjdtxry8h9MD8IBjntKG 2mlJGI4cJsKCMiO/SYcoga08Yw/Qp+r9+qgRcKIRR01Z61oXQxTVJq7i8RF42r5unxRs+61ILs5 cqtohdqfx09ZDaw== 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: 1788527547308158500 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 --- hw/display/virtio-gpu-rutabaga.c | 4 +--- hw/display/virtio-gpu-virgl.c | 6 ++---- hw/display/virtio-gpu.c | 7 +++++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutab= aga.c index 8a82e96b7461..8697dd6936ba 100644 --- a/hw/display/virtio-gpu-rutabaga.c +++ b/hw/display/virtio-gpu-rutabaga.c @@ -312,9 +312,7 @@ rutabaga_cmd_set_scanout(VirtIOGPU *g, struct virtio_gp= u_ctrl_command *cmd) scanout =3D &vb->scanout[ss.scanout_id]; =20 if (ss.resource_id =3D=3D 0) { - scanout->resource_id =3D 0; - qemu_console_set_surface(scanout->con, NULL); - qemu_console_gl_scanout_disable(scanout->con); + virtio_gpu_disable_scanout(g, ss.scanout_id); return; } =20 diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 79d4c0b569fb..87d1fc3d5f65 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -618,8 +618,7 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, ss.r.x, ss.r.y, ss.r.width, ss.r.height, d3d_tex2d); } else { - qemu_console_set_surface(g->parent_obj.scanout[ss.scanout_id].con,= NULL); - qemu_console_gl_scanout_disable(g->parent_obj.scanout[ss.scanout_i= d].con); + virtio_gpu_disable_scanout(g, ss.scanout_id); } g->parent_obj.scanout[ss.scanout_id].resource_id =3D ss.resource_id; } @@ -1426,8 +1425,7 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g) int i; =20 for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { - qemu_console_set_surface(g->parent_obj.scanout[i].con, NULL); - qemu_console_gl_scanout_disable(g->parent_obj.scanout[i].con); + virtio_gpu_disable_scanout(g, i); } } =20 diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index ae1f87ad68b2..cb096cb349cd 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -435,8 +435,11 @@ void virtio_gpu_disable_scanout(VirtIOGPU *g, int scan= out_id) { struct virtio_gpu_scanout *scanout =3D &g->parent_obj.scanout[scanout_= id]; =20 - virtio_gpu_release_scanout_dmabuf(g, scanout_id); - + if (scanout->dmabuf) { + virtio_gpu_release_scanout_dmabuf(g, scanout_id); + } else { + qemu_console_gl_scanout_disable(scanout->con); + } qemu_console_set_surface(scanout->con, NULL); scanout->resource_id =3D 0; scanout->ds =3D NULL; --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:50:59 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=1788527611; cv=none; d=zohomail.com; s=zohoarc; b=aZOVvsgYflpMotSnJrXdHP71hUnbj07S42EEyj43wzdIXIqA+Q/UanGo59MrlPs4RuYdN9WDHmKCVlJV/RJoiH3CRyU4td6IzwyzYtpQEfBu5DVSPPO5P/ns/8MPHCP6rcArsxgx3XeXfQknf8K4jMYkH18qiER8oxD1D0zbY/U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527611; 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=oFqL6HNGNtklhH6v3w0zsoM3lfO6CEl2tFKNlf91OZ8=; b=MYxvsx/cVyHmJ8ElabYPWhpu/LcEeYCyw89usOJewtxRJN9F/8PFeoU+hc9LVIUOXWrl5Iao2aFk3p0RBBKaTKDEXOicgo/hRrO/wygHAooigIk9/OUz6bAlO0k/AIg6W2HjfiQXqAe9T1qV6YA6ev2SIkwny6uqV6QCv6I4Pp0= 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 1788527611573960.365585208649; Fri, 4 Sep 2026 06:13:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Ths-0006Aw-1q; Fri, 04 Sep 2026 09:11:48 -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 1x2Thp-00063x-Nn for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:45 -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 1x2Tho-0005D7-18 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:45 -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-339-mfk7ST-bOeSmwoj2jzN35Q-1; Fri, 04 Sep 2026 09:11: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 21D85195FDF7; Fri, 4 Sep 2026 13:11:39 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 52C9C18001D0; Fri, 4 Sep 2026 13:11:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527503; 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=oFqL6HNGNtklhH6v3w0zsoM3lfO6CEl2tFKNlf91OZ8=; b=d87/U1QKiZ2l1F219x3TD3R2PwUt5RKuyMNUFCQ/GPM84tDdQ5aAgSUFhP5sVvac8Jlg6k E+qHmSHuYdCnu8k8mR9jdqnjUnT1FTU8n6kkVp15T83kwOuaIIinO06wwG5gwgQDC7bPw4 8pCiSKVH9umy49OWkDGuiTqDmvPaH2k= X-MC-Unique: mfk7ST-bOeSmwoj2jzN35Q-1 X-Mimecast-MFC-AGG-ID: mfk7ST-bOeSmwoj2jzN35Q_1788527499 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:25 +0400 Subject: [PATCH v2 21/25] virtio-gpu: minor refactoring MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260904-virtio-gpu-cleanup-v2-21-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=4112; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=tNo3CvkmjzZ/FPYiFRd3UUcJmpqGg7/OhLUKKESOyTE=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMw3SLFKqvoga90UQfDxWoC1cSw3moSLYz29 Hue5dfsleSJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDMAAKCRDa6OEJdZac 5eJFD/9ePha6DGvor9V3s9Iar0k4r8FzkXmEn8ArQDQchjhJC1WZvxsaG73M3ptSsliIDt+Fb+p wiPnsoWJ+j2Oyt6pxFwrr/UJ0xwckuzIbm4hp3wCEfSwMn46kN8Ikmh9aJinm1EmspPI2soBPVy oLtR3WahwIQOoKvAwJGStFp9lvgq7J4Pm2ptROoPeDzDgOCG9oxudz2NqajYGoVJ0R9LGz73zDq nZtzQSMgbT3+F2kEZC42GTd50Mt7xYmP+8Z+ub/0kJcz/d2s5iubNKHED+HbqE0R96e5pQzxXaT dciUMCTJp4+7Zu8DSsemGXfRcrbhoglcEgXanIX4vAy8ZOKOqLMfsP5b+0mPkAr8J35G4YBjV/w Lw3Tj3mHj46ns+HkvrmtXWnyCeIhKqZCdV/PhIlSQlikLF2LdK+1dzZ+VsKBkLTClYMsbzgZY/9 qrjZXJsmpqsYWR9RttNDaH4g2n4bXdSjUHAmnGGJ1EdiQZNOPXEwJrylpa2YfHYKfZbgwaX1akt Dsh4L2qSdzWlUtXpJ4CX3pALR3iSe0qKwGZAdUofV2KBIvLUdZLPAnazJV8W4+1ms/r87x0Cfdx QGqBiwznX//tYgrQq0Z0N5h9hM7GwKPMxejhWvETSxkmF4qvK9sFYhxc0dtLcFovjGcvWdOFetI 8g6NqsAIG9l2D7w== 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: 1788527613778158500 Move disable_scanout() branch earlier, return early. (scanout->resource_id is cleared there) Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- hw/display/virtio-gpu-virgl.c | 71 ++++++++++++++++++++++-----------------= ---- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 87d1fc3d5f65..118419171ff0 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -565,6 +565,8 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) { struct virtio_gpu_set_scanout ss; + struct virgl_renderer_resource_info info; + void *d3d_tex2d =3D NULL; int ret; =20 VIRTIO_GPU_FILL_CMD(ss); @@ -579,47 +581,46 @@ static void virgl_cmd_set_scanout(VirtIOGPU *g, } g->parent_obj.enable =3D 1; =20 - if (ss.resource_id) { - struct virgl_renderer_resource_info info; - void *d3d_tex2d =3D NULL; + if (!ss.resource_id) { + virtio_gpu_disable_scanout(g, ss.scanout_id); + return; + } =20 #if VIRGL_VERSION_MAJOR >=3D 1 - struct virgl_renderer_resource_info_ext ext; - memset(&ext, 0, sizeof(ext)); - ret =3D virgl_renderer_resource_get_info_ext(ss.resource_id, &ext); - info =3D ext.base; - d3d_tex2d =3D ext.d3d_tex2d; + struct virgl_renderer_resource_info_ext ext; + memset(&ext, 0, sizeof(ext)); + ret =3D virgl_renderer_resource_get_info_ext(ss.resource_id, &ext); + info =3D ext.base; + d3d_tex2d =3D ext.d3d_tex2d; #else - memset(&info, 0, sizeof(info)); - ret =3D virgl_renderer_resource_get_info(ss.resource_id, &info); + memset(&info, 0, sizeof(info)); + ret =3D virgl_renderer_resource_get_info(ss.resource_id, &info); #endif - if (ret) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: illegal resource specified %d\n", - __func__, ss.resource_id); - cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; - return; - } - if (!virtio_gpu_check_scanout_bounds(ss.scanout_id, ss.resource_id, - info.width, info.height, &ss.= r, - &cmd->error)) { - return; - } =20 - virtio_gpu_release_scanout_dmabuf(g, ss.scanout_id); - - qemu_console_resize(g->parent_obj.scanout[ss.scanout_id].con, - ss.r.width, ss.r.height); - virgl_renderer_force_ctx_0(); - qemu_console_gl_scanout_texture( - g->parent_obj.scanout[ss.scanout_id].con, info.tex_id, - info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP, - info.width, info.height, - ss.r.x, ss.r.y, ss.r.width, ss.r.height, - d3d_tex2d); - } else { - virtio_gpu_disable_scanout(g, ss.scanout_id); + if (ret) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: illegal resource specified %d\n", + __func__, ss.resource_id); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID; + return; } + if (!virtio_gpu_check_scanout_bounds(ss.scanout_id, ss.resource_id, + info.width, info.height, &ss.r, + &cmd->error)) { + return; + } + + virtio_gpu_release_scanout_dmabuf(g, ss.scanout_id); + + qemu_console_resize(g->parent_obj.scanout[ss.scanout_id].con, + ss.r.width, ss.r.height); + virgl_renderer_force_ctx_0(); + qemu_console_gl_scanout_texture( + g->parent_obj.scanout[ss.scanout_id].con, info.tex_id, + info.flags & VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP, + info.width, info.height, + ss.r.x, ss.r.y, ss.r.width, ss.r.height, + d3d_tex2d); g->parent_obj.scanout[ss.scanout_id].resource_id =3D ss.resource_id; } =20 --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:50:59 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=1788527544; cv=none; d=zohomail.com; s=zohoarc; b=YTdW2crPB+c3w2lVKs+tBSFRNnGvyTEMlYDeb0PGE6DB6CHbnHt+Ig/VtW7IfsNkJDqT9b0w+dXwAXKsanrQl9gWyBPl1ECbLUMHckfOWiQ8263lS8K0f0LEImF4nRyz9Vn7/ZxtMeFHBxOzGVTMUKmDMySy4r5bxI9TcX0ZUto= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527544; 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=eDpJv5fVSHBFINWcnPkvTTbGfWX5pHmQw/bOk6t9n7o=; b=SfX6oOJwwHh6Qw0RaQnZchh73vnjmWbU5UTo297ggsCt54zLpONTcVWO/fs79VfybV0krNqRDuQtozPa6QU5ublOmEQbzDg1a1UNssLzqHP8bc4keW0w0N8LhmFssKA32zDvDnmc95mWaVFU3xSV8ub3mJiTXrTp0Co86GqkV5g= 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 178852754439810.044078818794901; Fri, 4 Sep 2026 06:12:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Tht-0006Gk-3z; Fri, 04 Sep 2026 09:11:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1x2Thr-00067T-C7 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:47 -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 1x2Thp-0005DW-VE for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:47 -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-299-FSwanOTwNC2e3W8HxxZJHQ-1; Fri, 04 Sep 2026 09:11:44 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 13AD7180AD5C; Fri, 4 Sep 2026 13:11:43 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id CA6AE18005AC; Fri, 4 Sep 2026 13:11:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527505; 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=eDpJv5fVSHBFINWcnPkvTTbGfWX5pHmQw/bOk6t9n7o=; b=IQZfbNYvucibsgG3+woJy1d9r+1shto9dwhOiqFw7CLjm8pN/hB5j6pd2KqSWS0oFFgZhd CgtAlrh1x20eW8s44VbXxght2301N+yLFjyJ2SZe6Zolt3jMqRebzg7Adr+ISJE7I7LvsS yyqsMfLo0RUI4BcsAPBCPTKrNsuIgGM= X-MC-Unique: FSwanOTwNC2e3W8HxxZJHQ-1 X-Mimecast-MFC-AGG-ID: FSwanOTwNC2e3W8HxxZJHQ_1788527503 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:26 +0400 Subject: [PATCH v2 22/25] 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: <20260904-virtio-gpu-cleanup-v2-22-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=1365; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=V1GN5LoBN9Orpkbh0wMfjyjOHFm67aaxsE17BfJbx1k=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMwzg89Cv1ZHxmIW5Z1+75qsFM/V8bVix3u6 Ce0FjTeWDeJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDMAAKCRDa6OEJdZac 5YxBEACvDgvoXyEAMhArIw3aGQdJcp3naIGfin3TuGm+FZV+t50/E+5etuWogbZNZD1GsxEE131 qaZm7aUkp5GDqkEUNfZzeaWeKhBO9Nvhh2XcWuJp7I+tNKT/zxrZRyi5VGkrfAYjNXWhyxwG+Mi FEFtxj05P/VSNfr/dHcREo/pTXRUkDRr2m2J6m6IMYQAKBqL84hSuIhCEP+OO3AxQiyupD9xnER h4p2CN5x2jl5LP1savXM5W7Cp1sShyCr/g7CeC0pmrh3uCn33JfbgkOgWmnXznA2Kog1ByH3rW0 Kqsb5UfUxA2kV2JC7K5MVOZJ3oReEUswZZrEGpf3bhYu5tpKLeSl4hOTbm6A2LlxpMBpDpd/8ux iJ5RkCKl+phvGQVOcpY0vdF4OAdWcN9sOdgjHS/TKkGIEkAJ3jGxx+htBqndkglNetIT03bJFLA GE9L+Bh9GObJNqXNccQdLs6JybulCoav6cRjlSJaBGpE9Pdlh/XJVIwGnmDFh+euLykM0hJ+Qob XJTEWpYbuqqJqVOq/0onACpT306FVcAeuyLsmas4xcwkoCiqHm1I9nDnIpKaNU84lrP8Plxw309 88KbsjfCCxHSSev53h39+mbLAjp+fvb+FGEtMy1QqpZgoW5YLEEkU6H961vII9bTUpn990J+cxJ cYAqe31rB8YsH8w== 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: -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: 1788527545293158500 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. Fixes: 9d9e152136bd ("virtio-gpu: add 3d mode and virgl rendering support.") Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- hw/display/virtio-gpu-virgl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 118419171ff0..cf624761610a 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -431,6 +431,7 @@ virtio_gpu_virgl_resource_unref(VirtIOGPU *g, { struct iovec *res_iovs =3D NULL; int num_iovs =3D 0; + int i; #if VIRGL_VERSION_MAJOR >=3D 1 int ret; =20 @@ -443,6 +444,13 @@ virtio_gpu_virgl_resource_unref(VirtIOGPU *g, } #endif =20 + for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { + if (g->parent_obj.scanout[i].resource_id =3D=3D res->base.resource= _id) { + virtio_gpu_disable_scanout(g, i); + } + } + + virgl_renderer_force_ctx_0(); virgl_renderer_resource_detach_iov(res->base.resource_id, &res_iovs, &num_iovs); --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:50:59 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=1788527573; cv=none; d=zohomail.com; s=zohoarc; b=Jg3W709jI380SfeD/9rjjmI1BvxBV81b3+glJaXmvXc4mPxe1RrOdzCwpqKAbin0EYNv50DZvW8lGBJG3+ASTzK0bxV9h3oup1thY+QbL04OvblFtFNc3/5csAc3PZYRnJD/poqSANB5HU0x0qNF9F3SyoPq//6cclJQqL4HTco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527573; 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=i0NIziQTq1h4MzDGVZ6bdGTJI7TGbe5OSJ55loeX+RE=; b=YAkv/aHJ9FtDqC57Cwpzwro1QlIWndGt+bkBIqZWpYJbl3neJiQE/cWx2/O/M/ERf0xj6NY39JtYGpIg4i7LA0a0x/P6Ti5YHNUZ5etWc85Cnk0w+U49n0HNLeN23YsOdkI8FNWcT6PD1JZxuT/EGg7MWmLVcnUjfmCoxrdQyR4= 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 1788527573861528.1648451110977; Fri, 4 Sep 2026 06:12:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Ti1-0006cl-GI; Fri, 04 Sep 2026 09:11: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 1x2Thx-0006WT-5q for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:54 -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 1x2Thv-0005EP-Fx for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11: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-692-lqXkkBCtNcyTiD9pcl16eg-1; Fri, 04 Sep 2026 09:11:47 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4918B1964CFF; Fri, 4 Sep 2026 13:11:46 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7A78418005AC; Fri, 4 Sep 2026 13:11:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527510; 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=i0NIziQTq1h4MzDGVZ6bdGTJI7TGbe5OSJ55loeX+RE=; b=FjhGr8wjY0JxD2e36VuEgCIMikLEp1gHWCWtCTMMK0bJEfE3aRhnTA1w5hhv1WgBkjIj05 VFBArT6vT3/MxH3H7pemUq8zfS1EhLn2tnOUWbmeRzpeT//uHCfuaSfiQGmgnP6VxbDgcd CUZLPxj15OzHL1TPYE+Oc3rsEjFyGds= X-MC-Unique: lqXkkBCtNcyTiD9pcl16eg-1 X-Mimecast-MFC-AGG-ID: lqXkkBCtNcyTiD9pcl16eg_1788527506 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:27 +0400 Subject: [PATCH v2 23/25] 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: <20260904-virtio-gpu-cleanup-v2-23-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=4638; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=8xvsPIWc0Xnv3CBLlwXfGbLEVAJErRlne2ni4LLhj1M=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMwF7WDek9O8pCXtOYlWrbceHoX3meZvEYGP HF9yczbwWyJAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDMAAKCRDa6OEJdZac 5bCUD/9SFvoqwo3bhPOnp1qW4Z0d0FnVTuf04AY2J/7TEBWur7PbnUtYDChHPhF2ljV5eX8zIYm b8dy0y4lt4H2MzbeAFX6suY0Ro3tLuAtnDgLQEbe4aL8fVoDju/uAfEdZX5A/QcrJKlA54yBVtT 6E5A6fXxVsPLiecMLmu4j+MQSuHkvCNmUwk71d6NPv1DhAL29Y8/89YJGdAhebFTZkfyDKZ1d/s uIb6lzkdHAJYCS/C+dgKKaS8l8VfDzfPzC46HsS/a31etaFnmwqx1vX7XsQqMHzVBIuZNup4wwt +HkHCoPSWiJhf8j+3FboRcVHCwKxI87VuqXPMNJFS4fImi9d13tZH5+nshyw/x29i9FpJC6a+tU PmoeeQNOA2CfleLLCI930nd/4N++DL3N5S9jjarITyCv/adlHPGUJbqbtUShrE2mrLwwFf9MvcG 3O9rYxIEdI10DxJBCcGaddVnMqhcFWfifgYsfghhi4wFcdzf0z49b5CHL8mZiWKc7vLYD2xusWY ptLJ24hfuKRbL6SBkJT+4YMWHFJ8qLRi8yp/G8a/7Y6K6qcYnOOKRLWN6Y0x+H+3hYRBjLlU6/J fJKYrUylbN2ye1xeDfFTAQ5e6NiuXDo/IxbYj6GqdfPpLpg8c3I07yLINWO3Rh1v1Aav3f1Suab yu1g1Qu5sFqDorg== 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: 1788527575487158500 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. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- hw/display/virtio-gpu-rutabaga.c | 7 +------ hw/display/virtio-gpu-virgl.c | 7 +------ hw/display/virtio-gpu.c | 26 ++++++++++++-------------- include/hw/virtio/virtio-gpu.h | 2 ++ 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutab= aga.c index 8697dd6936ba..3aafa4dc66cd 100644 --- a/hw/display/virtio-gpu-rutabaga.c +++ b/hw/display/virtio-gpu-rutabaga.c @@ -146,14 +146,9 @@ virtio_gpu_rutabaga_resource_unref(VirtIOGPU *g, Error **errp) { int32_t result; - int i; VirtIOGPURutabaga *vr =3D VIRTIO_GPU_RUTABAGA(g); =20 - for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { - if (g->parent_obj.scanout[i].resource_id =3D=3D res->resource_id) { - virtio_gpu_disable_scanout(g, i); - } - } + virtio_gpu_disable_scanout_for_resource(g, res->resource_id); =20 result =3D rutabaga_resource_unref(vr->rutabaga, res->resource_id); if (result) { diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index cf624761610a..248aaf1a7149 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -431,7 +431,6 @@ virtio_gpu_virgl_resource_unref(VirtIOGPU *g, { struct iovec *res_iovs =3D NULL; int num_iovs =3D 0; - int i; #if VIRGL_VERSION_MAJOR >=3D 1 int ret; =20 @@ -444,11 +443,7 @@ virtio_gpu_virgl_resource_unref(VirtIOGPU *g, } #endif =20 - for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { - if (g->parent_obj.scanout[i].resource_id =3D=3D res->base.resource= _id) { - virtio_gpu_disable_scanout(g, i); - } - } + virtio_gpu_disable_scanout_for_resource(g, res->base.resource_id); =20 virgl_renderer_force_ctx_0(); virgl_renderer_resource_detach_iov(res->base.resource_id, diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index cb096cb349cd..9995f7184610 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -447,17 +447,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); @@ -1065,13 +1069,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:50:59 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=1788527602; cv=none; d=zohomail.com; s=zohoarc; b=JD6ynYoNvCLzy9jUg8WG00/B2ny7kvhX/UXk9gn0jjahp7Zz2ChFOgWBGhx1YeBOO2RfHG5vrRxfV3WlcR3+laVg1t+fcbTdn8ZrDkwjVmJqzQMX2eTRylUn617MdtlDcGm106HwFSod4ULuaMfZKD5WV0fFFGuCXJpTz+/bZBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527602; 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=x7+kWJumHiGoESszyyHPgWEThNe8AKRBcx3EKAf8V+Q=; b=TukZ8spGDjhsoM+vXENEBBUpF76fH0yeBHsiTenualzcORLmfviX+HmqwqBj47e/+gXA+ODd5mVD8LwxzDipF1SNPA2Sgzk2EJM9NRPXpZWr98RmMjN5YqpMNiW6Yjz/jbpNk9n9g49vMOrnNN/14pswo7nUVVb58nQJB4Lg3hw= 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 1788527602453454.5221383228269; Fri, 4 Sep 2026 06:13:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2Ti7-0006mB-SU; Fri, 04 Sep 2026 09:12: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 1x2Ti2-0006dw-QB for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:59 -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 1x2Thz-0005Ez-W6 for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:11:58 -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-642-O9OtoM1NPPKzaAixa9lgGA-1; Fri, 04 Sep 2026 09:11:52 -0400 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D4F8E190561B; Fri, 4 Sep 2026 13:11:50 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D7BEE427; Fri, 4 Sep 2026 13:11:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527515; 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=x7+kWJumHiGoESszyyHPgWEThNe8AKRBcx3EKAf8V+Q=; b=G0ldDOffmxh7/IE8s43LEWizxMAOCYTP1WO0gFvwFCtjbSGcPhsMGndrMp8hEK6kumSb9d s4run77yzXxepB41eF3p+4o6pHVuJQv0svlgrS1q9CIJxE3OoqGGExZZ/Jb44O1lbDXNDP OeLtL7QN/S8CYWgnFQwg5KvTfJhnbPs= X-MC-Unique: O9OtoM1NPPKzaAixa9lgGA-1 X-Mimecast-MFC-AGG-ID: O9OtoM1NPPKzaAixa9lgGA_1788527511 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:28 +0400 Subject: [PATCH v2 24/25] vhost-user-gpu: release DMA-BUFs on scanout disable, reset and finalize MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260904-virtio-gpu-cleanup-v2-24-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=2574; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=KyLeK/1UDKjo+OdCRBTXB67t9Vi4GdvzCZHlivAn0Ng=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqmsMwS+iuZ4Ko7ueMQz1EVkt0nJ0zc96F9mJFy CTQy2t0FY2JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaprDMAAKCRDa6OEJdZac 5YxND/9izhMa4X+7vxbDjyibJjyb1VRpepzrbLnJI/EHucNKlkr64GoWK3KQk0kuEy2sjacGoz+ 6d3O97JgVCphM6SFVCnhjUNA1KFlzJPaLq1kzI9pyEGOk36eN/Rg1UAq2FdS1/wLNfCyqdiMn40 uogqYM2W7ejO46aeIGyJCCoE42v+tAbnrlqoBk+wBxgCoSKZWWaHzkNQWnMSCHlxsTrRbfEED7C xi08tD3tp3KvUdq7CX5YYyNpWHiAc66fJTRNJU4zMeYYtuo9oOKeNXBG/WRfQW5lu0jG5ZHK5TI tU8DJY3Wt9+BfVnHcOZk4EcZ1O9YCx448V+KLYrGFYInQSR5n96DRQenI/U9CIz2uBpHqlK3oPl GvFGb5qkKg92e7ug7FTFRcZY06AK+0xDo3yiaQ3JFzX/X4sm74GwxZx2w2I/SKOOry6feYkGVgp n6kIv91bYOTnYVpujD+rY5uwzONHmo1Uq3rEQGOVfNYg4Gngn7plH18tYWf8W8KNIUCYixAtHh4 Nkh3WBbDXpwmlkriIZ8gAHQbPbtCeVsDgH+Q1Gpb+Vs0e18IHh9p03yl4uKal6DQ9IEU7YA7120 s/UJAn5ZxEBpvNFhtcLFs4aA4ygJT8dbzCfw0SDwTJmSYqVXC/j+1xMGuUO5mjG99I/N8XAx8X+ NUXGrPsoJ/gZn3w== 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: 1788527603728158500 When the backend sends VHOST_USER_GPU_SCANOUT with zero dimensions to disable a scanout, the frontend only calls qemu_console_set_surface(NULL) without releasing the g->dmabuf[] entry or invoking qemu_console_gl_scanout_disable(). Display listeners (GTK, SDL) can therefore remain in GL scanout mode and keep redrawing the stale buffer. Release the DMA-BUF and call qemu_console_gl_scanout_disable() in the SCANOUT handler when a previously active DMA-BUF exists. Additionally, vhost_user_gpu_reset() and vhost_user_gpu_instance_finalize() never iterate the dmabuf[] array, so active DMA-BUFs leak on device reset or object destruction. Add cleanup loops to both paths. Fixes: 267f664658fe ("hw/display: add vhost-user-vga & gpu-pci") Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/display/vhost-user-gpu.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index c09aca041135..3f1fd333eeab 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -263,6 +263,11 @@ vhost_user_gpu_handle_display(VhostUserGPU *g, VhostUs= erGpuMsg *msg) con =3D s->con; =20 if (m->width =3D=3D 0) { + if (g->dmabuf[m->scanout_id]) { + qemu_console_gl_release_dmabuf(con, g->dmabuf[m->scanout_i= d]); + g_clear_pointer(&g->dmabuf[m->scanout_id], qemu_dmabuf_fre= e); + qemu_console_gl_scanout_disable(con); + } qemu_console_set_surface(con, NULL); } else { s->ds =3D qemu_create_displaysurface(m->width, m->height); @@ -631,6 +636,10 @@ vhost_user_gpu_instance_finalize(Object *obj) { VhostUserGPU *g =3D VHOST_USER_GPU(obj); =20 + for (int i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { + g_clear_pointer(&g->dmabuf[i], qemu_dmabuf_free); + } + object_unref(OBJECT(g->vhost)); } =20 @@ -639,6 +648,15 @@ vhost_user_gpu_reset(VirtIODevice *vdev) { VhostUserGPU *g =3D VHOST_USER_GPU(vdev); =20 + for (int i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { + if (g->dmabuf[i]) { + QemuConsole *con =3D g->parent_obj.scanout[i].con; + qemu_console_gl_release_dmabuf(con, g->dmabuf[i]); + g_clear_pointer(&g->dmabuf[i], qemu_dmabuf_free); + qemu_console_gl_scanout_disable(con); + } + } + virtio_gpu_base_reset(VIRTIO_GPU_BASE(vdev)); =20 vhost_user_backend_stop(g->vhost); --=20 2.55.0.543.g5ebe2ebe4ea8 From nobody Sat Sep 26 20:50:59 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=1788527552; cv=none; d=zohomail.com; s=zohoarc; b=cy298GEEKet9mPmCgGg+3PHwep8T8mFSz4NbRLU6jxqZDLM2NWT450lHx6UJylnPd7u+Xy26fPS66Q8GHGLtDG0f+Vn5oY8Lt7iQAk2YI9TrruKWCdmyQzZLLIVwWKA/XAdqV3Cpxo5Y8ydqNujx7SjD9YoDQ25sX9wJNsYz8dw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1788527552; 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=rbRdxbD6P12CEVrbxoY+AhOP0j7nufFZ/uajBCMBXvE=; b=mW7DcjtO5JQ1AgjIvMHsrPefTY9A9TV61a/wD/RT9TNeJ/uEE72P/O703CZNitD6rWXpTKHtNVsApfCSdEF1lwtLJPPMveg61DHWYThCjk6jf+3qWcCO4U8N9f/OQZHT8pVWPNPHg9lhW7ukb39aA6Pju6U5N92oQXw/oDw5mUA= 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 1788527552578501.6033639385521; Fri, 4 Sep 2026 06:12:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1x2TiE-00072u-HY; Fri, 04 Sep 2026 09:12: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 1x2Ti5-0006lS-SK for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:12: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 1x2Ti4-0005FT-7q for qemu-devel@nongnu.org; Fri, 04 Sep 2026 09:12:01 -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-313-Hb8ytDFDP4-VWUHgcnKEYQ-1; Fri, 04 Sep 2026 09:11:56 -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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C90FB18CD28F; Fri, 4 Sep 2026 13:11:54 +0000 (UTC) Received: from localhost (headnet05.pony-001.prod.iad2.dc.redhat.com [10.2.32.117]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 364D01953944; Fri, 4 Sep 2026 13:11:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1788527519; 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=rbRdxbD6P12CEVrbxoY+AhOP0j7nufFZ/uajBCMBXvE=; b=Ui7Ff6ic2nBfX0U9ZZ6u53Xb6NGmgXv+MQDuoArUoC7YAt90xc1EuMhRODhmAe468tcBzL vgnOA0o3472YfQ0hIKS754MEZhcgi5fWoRj1n4OUndQn206OKDAFh1wbUDhWNcNg8JfPNJ lpqtbP1a9vPdcC6M2lwFTRyDI+bl3o8= X-MC-Unique: Hb8ytDFDP4-VWUHgcnKEYQ-1 X-Mimecast-MFC-AGG-ID: Hb8ytDFDP4-VWUHgcnKEYQ_1788527514 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Fri, 04 Sep 2026 17:10:29 +0400 Subject: [PATCH v2 25/25] 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: <20260904-virtio-gpu-cleanup-v2-25-15b5ae6b0023@redhat.com> References: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@redhat.com> In-Reply-To: <20260904-virtio-gpu-cleanup-v2-0-15b5ae6b0023@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=1484; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=VhBqERV1PpBBS/4qnNZnTFB5pbaJRCUO4hEvGx6g398=; b=kA0DAAoB2ujhCXWWnOUByyZiAGqawzCi5EBg/W8EvwTdwYXJSah4zLVk3/Kj3Lv7wDcAAlZG1 YkCMwQAAQoAHRYhBIepvZM/h8YG0nb2Ldro4Ql1lpzlBQJqmsMwAAoJENro4Ql1lpzlRg4P/2BS aDkAfvQ/8rj12XlnMJ9iLNydW+rlzNGNtPWl2K5wSr/TXrDTNV3WnUn6wlDknmgpEnM8R5V9Qsc c3/QspqAGIBCpOdaaZP84Bn04avV8Bnxzfz9f8p/+JWRpqLA9SZeIObD4iYXs0HW0zxxRd8DI7j 8fU193Bvq2TfpT/drOFIceflcaILFVb/MeP1Z/0K9MX5FOEGkkRKycBaCLSU3gvVa993+AtblF/ vZTUYFimaB+LuxUzeN0SyGrwIQjd3j5Mq/S5Z83SSZbb+tyVWJ8qEgNLfBi8iSEqoU07EXUeKbP R8I68QIqynG+gOSKlP6d00gvWdRNYnjBBIDfBVGqFUqBGPiBqqb1FcsT3jg39gLFoRBU60y4eP8 UHwPw1LdDRkT74+bvRjh7U4VFdYksMbI+5gIWZvoxIns/m/okS53J4FeanQB9ttuuIPdDO9yZjj YhE8LqcPY3SX+8qaMBD0mT2R0LMiCtJ73ePqBb78g4F5HrCjUhGkg7Qa9BVy6b7bVj7v0UppDvs B+aMcy6ur36tzzRnGLD/8RgN9h//DHK39XyUCzodH/7PvyV29NBDFp6d6OJYwfFrqzp1YhJ6xOd N2KXmSj0OPZLghwwHRUFdAfQwYf3mRUFgSLCrE+hpCMWMwvJe5i0M9ktJg7e7Vgjc5YoTCTp2tf 8ioLi 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: 1788527553340158500 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. Fixes: d52c454aadcd ("contrib: add vhost-user-gpu") Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Akihiko Odaki --- 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