From nobody Thu May 9 23:03:11 2024 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=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1682039598; cv=none; d=zohomail.com; s=zohoarc; b=IRahMRTNnOS2ozfmxTWJI8tkks214lD9Imt3N7rv92+y7ic+ZtS60Obi4mFDyEGZs/3QNZts94QNrZOebw3pM6qUoiWFvxZHxUEGL4H1KHqE4nTGSQ4aQUaA0J2agt3194uN3RyST7eUBdq8Xw3EvH1MG1DcvDaYdqNko2nJF/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682039598; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+1/aJ9cKYlVu/fza4q8BHTu511UJuh61NIe2fSyDtS0=; b=aD/LYejXIs1dPUBcaiRAaGOTAO0JtGHqn2mSeUklotU8JrLDh5BsKCOf/CHy3BmUi9w2oSP8VxiAAIzCEcp4JlFD9TdTKUJt96fprZjVUuTP/Rw9sOIps3iPFNce1+4qqH+rkriQszUDNzhMR6BG6ukoYAc3e3846XvuGau50VI= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682039598533831.9356163364525; Thu, 20 Apr 2023 18:13:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppfKk-0002hE-55; Thu, 20 Apr 2023 21:13:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppfKL-0002bB-1r for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:41 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppfKA-0008KX-B7 for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:40 -0400 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-246fa478d45so1451014a91.3 for ; Thu, 20 Apr 2023 18:12:29 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:a7:2:6625:6aa3:1b0e:a808]) by smtp.gmail.com with ESMTPSA id f4-20020a17090a8e8400b0024702e7c80fsm1697640pjo.23.2023.04.20.18.12.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 18:12:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682039549; x=1684631549; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+1/aJ9cKYlVu/fza4q8BHTu511UJuh61NIe2fSyDtS0=; b=KxRoGc3j5LUc1tgSh6j7RX6rnB3+ku5ZcilsTyDNv2eA8nIWYWUySP4McEsuvI5yDm vDCgymPa5RxOqEEPOPRZCd1X/qXVjXq+zhS7pibfJW4cWSVpR+nyHqgU9gvi0QVycVD9 D4Grp4LgH6aNJllNuHDqJG77h3/m0GNmieFJU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682039549; x=1684631549; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+1/aJ9cKYlVu/fza4q8BHTu511UJuh61NIe2fSyDtS0=; b=QMdPHoqmiSDaz/V2V2xVKBKjV0PlxsDLE+h0dDGbqQsm1/rjH5SQ/Q+EYKUyyxVP2S 6usxUwfFwAKpT9C8AL+0D0HG3fAyYdGK+ZNgbYB1U8elIOMEJaCpSx2JGtr2AUOaiO6A BdAXpSSuHYpP3JbwenH0CuyS7CVtohD1Jqnks/ILEDqm2OrDkB2RfhhgAYKIxSivFpCf Ejn+mjpqkwV1u0tEaw5AmQaxNGvEKNmg7CMs6x14rxyf03epQdxRNKwYOgCO1zgHQscH Ru07bXiWTinqwGtvhbdipr7k7uWS3qCuBgIQqCKjZb2Apn3eLwSF6d1QBDDS1XlYCXLQ Zc7Q== X-Gm-Message-State: AAQBX9e/UPqrCjl1lGkqvxOsjTvgIBdrll4DTrZQVAa3asQo6r2BFlYU dtZ5v7GJi4FmJ7yekxeOTYpmm7EJZCykG92PIabIapg8 X-Google-Smtp-Source: AKy350agKVaE3oUxvUc2LJMEjMBEv/swjNSxEecHODiXvX+eZwhXp37KA0XL6eJaHQ4W5z6h8PIt8Q== X-Received: by 2002:a17:90b:1018:b0:247:6a93:1d56 with SMTP id gm24-20020a17090b101800b002476a931d56mr3208310pjb.22.1682039548814; Thu, 20 Apr 2023 18:12:28 -0700 (PDT) From: Gurchetan Singh To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, david@redhat.com, stefanha@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, akihiko.odaki@gmail.com, dmitry.osipenko@collabora.com, ray.huang@amd.com, alex.bennee@linaro.org Subject: [RFC PATCH 01/13] virtio: Add shared memory capability Date: Thu, 20 Apr 2023 18:12:11 -0700 Message-Id: <20230421011223.718-2-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230421011223.718-1-gurchetansingh@chromium.org> References: <20230421011223.718-1-gurchetansingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=gurchetansingh@chromium.org; helo=mail-pj1-x102e.google.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @chromium.org) X-ZM-MESSAGEID: 1682039600277100004 Content-Type: text/plain; charset="utf-8" From: "Dr. David Alan Gilbert" Define a new capability type 'VIRTIO_PCI_CAP_SHARED_MEMORY_CFG' to allow defining shared memory regions with sizes and offsets of 2^32 and more. Multiple instances of the capability are allowed and distinguished by a device-specific 'id'. Signed-off-by: Dr. David Alan Gilbert Signed-off-by: Antonio Caggiano --- hw/virtio/virtio-pci.c | 18 ++++++++++++++++++ include/hw/virtio/virtio-pci.h | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 247325c193..08ba76fca2 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1399,6 +1399,24 @@ static int virtio_pci_add_mem_cap(VirtIOPCIProxy *pr= oxy, return offset; } =20 +int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, + uint8_t bar, uint64_t offset, uint64_t length, + uint8_t id) +{ + struct virtio_pci_cap64 cap =3D { + .cap.cap_len =3D sizeof cap, + .cap.cfg_type =3D VIRTIO_PCI_CAP_SHARED_MEMORY_CFG, + }; + + cap.cap.bar =3D bar; + cap.cap.length =3D cpu_to_le32(length); + cap.length_hi =3D cpu_to_le32(length >> 32); + cap.cap.offset =3D cpu_to_le32(offset); + cap.offset_hi =3D cpu_to_le32(offset >> 32); + cap.cap.id =3D id; + return virtio_pci_add_mem_cap(proxy, &cap.cap); +} + static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr, unsigned size) { diff --git a/include/hw/virtio/virtio-pci.h b/include/hw/virtio/virtio-pci.h index ab2051b64b..5a3f182f99 100644 --- a/include/hw/virtio/virtio-pci.h +++ b/include/hw/virtio/virtio-pci.h @@ -264,4 +264,8 @@ unsigned virtio_pci_optimal_num_queues(unsigned fixed_q= ueues); void virtio_pci_set_guest_notifier_fd_handler(VirtIODevice *vdev, VirtQueu= e *vq, int n, bool assign, bool with_irqfd); + +int virtio_pci_add_shm_cap(VirtIOPCIProxy *proxy, uint8_t bar, uint64_t of= fset, + uint64_t length, uint8_t id); + #endif --=20 2.40.0.634.g4ca3ef3211-goog From nobody Thu May 9 23:03:11 2024 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=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1682039697; cv=none; d=zohomail.com; s=zohoarc; b=Spo47tvfGQOlge9lVCnLv8nToIZ/YG8JRdnMefqp9NJCyX8PH74+4x3lEcSAajr4Y4Zr10dmXi+magg3sq1SsuKgvFBI1wvtOgWcwqszacpXf+h6SudxK8APrJvyVt1e/L9Z5BJfNr1Gc/CVc2kqj3Mpul0gUgeRJoPPRbdA/44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682039697; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yEGhWvKYYAsoTWsLnkWYtmM6QMixFRB0SUc95utwx6Q=; b=AFVauSxv5BUACdNOqbOO5sv7ChFx+MEGFo1jjFUeoBF9ZA9hjLL6BxIAcPOCxg0ag1kTD9ksatKc2ahqQjid6s3+1qijzgglSwW02Ro9adApvqb15dkgp6AHFx5NlSWpr+F4ykkp42DihVKEaYEEGzQ770tXg4BPJBKpqBEBUg4= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682039697777886.0109383663165; Thu, 20 Apr 2023 18:14:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppfKi-0002go-5d; Thu, 20 Apr 2023 21:13:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppfKL-0002bK-3r for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:41 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppfKC-0008Ly-6r for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:40 -0400 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-247048f86c7so1195155a91.2 for ; Thu, 20 Apr 2023 18:12:31 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:a7:2:6625:6aa3:1b0e:a808]) by smtp.gmail.com with ESMTPSA id f4-20020a17090a8e8400b0024702e7c80fsm1697640pjo.23.2023.04.20.18.12.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 18:12:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682039550; x=1684631550; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yEGhWvKYYAsoTWsLnkWYtmM6QMixFRB0SUc95utwx6Q=; b=jtldk4amrVzoJ6r6MwuGdap4AQ24uz323fy/ZekRe0fXSsF4CEMdS3QXFFUX6K9rgz ql6St7xjwNJ3oCdRsv5i9//HC5bKinWyPAz7VVViOLsB/KEycX9Eo8pFALr6idahfohy joJD5PbKoNmacYocpOliTX8DDA9w3XcZg4Zbk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682039550; x=1684631550; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yEGhWvKYYAsoTWsLnkWYtmM6QMixFRB0SUc95utwx6Q=; b=mIXU3zfn5rXfcFpJrspyEirGO2eIZabfH5NFqAqpozPQgsgir0OVjAEgJTzOzC8qRx 8uGHY9QRXrnq9n75XMNeWgsUNwKvdJYrzaVnSKLF4wGTXJlgzwoL7/7J+yZqJLwUNJ9k l7kUE2He22MOrAX2ttNCeyXBHJfQ2m+OGUn4u7yAr5Vuokz7jrbiKy7YKFbMH1DMPTLn h8WAZz686Tl9JkauVBvViVzkJE9HfTBCOcM+MkEDGUwpTJJrNkl3XGTvFvKOdxNBr5X4 VsbnuXv+FxusFgQ29SOu6wh/AUbAGbnwId71aR+x+qjPPPBmKr21DQCQCTpSsJMlyU0f 11kA== X-Gm-Message-State: AAQBX9ehSqxwZHHEQ9vk00Pp2fjdw4Emr3ljXRv8nYuEQ81lTihuEOYd gOnacO8626POKTvjPi2PlXwH/wzVvK3B0L4aO0Lg2JIH X-Google-Smtp-Source: AKy350Y1WSZtT5fMZSkvydHVnX2BtPMHc1XMQJgudtv1LIUQFDpQU2XJuN997v5rJWkJxu51OmBPog== X-Received: by 2002:a17:90b:1494:b0:23c:fa83:2a7d with SMTP id js20-20020a17090b149400b0023cfa832a7dmr3784034pjb.12.1682039550308; Thu, 20 Apr 2023 18:12:30 -0700 (PDT) From: Gurchetan Singh To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, david@redhat.com, stefanha@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, akihiko.odaki@gmail.com, dmitry.osipenko@collabora.com, ray.huang@amd.com, alex.bennee@linaro.org Subject: [RFC PATCH 02/13] virtio-gpu: hostmem Date: Thu, 20 Apr 2023 18:12:12 -0700 Message-Id: <20230421011223.718-3-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230421011223.718-1-gurchetansingh@chromium.org> References: <20230421011223.718-1-gurchetansingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=gurchetansingh@chromium.org; helo=mail-pj1-x1029.google.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @chromium.org) X-ZM-MESSAGEID: 1682039698244100001 Content-Type: text/plain; charset="utf-8" From: Gerd Hoffmann Use VIRTIO_GPU_SHM_ID_HOST_VISIBLE as id for virtio-gpu. Signed-off-by: Antonio Caggiano Acked-by: Michael S. Tsirkin --- hw/display/virtio-gpu-pci.c | 14 ++++++++++++++ hw/display/virtio-gpu.c | 1 + hw/display/virtio-vga.c | 33 ++++++++++++++++++++++++--------- include/hw/virtio/virtio-gpu.h | 5 +++++ 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/hw/display/virtio-gpu-pci.c b/hw/display/virtio-gpu-pci.c index 93f214ff58..da6a99f038 100644 --- a/hw/display/virtio-gpu-pci.c +++ b/hw/display/virtio-gpu-pci.c @@ -33,6 +33,20 @@ static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *= vpci_dev, Error **errp) DeviceState *vdev =3D DEVICE(g); int i; =20 + if (virtio_gpu_hostmem_enabled(g->conf)) { + vpci_dev->msix_bar_idx =3D 1; + vpci_dev->modern_mem_bar_idx =3D 2; + memory_region_init(&g->hostmem, OBJECT(g), "virtio-gpu-hostmem", + g->conf.hostmem); + pci_register_bar(&vpci_dev->pci_dev, 4, + PCI_BASE_ADDRESS_SPACE_MEMORY | + PCI_BASE_ADDRESS_MEM_PREFETCH | + PCI_BASE_ADDRESS_MEM_TYPE_64, + &g->hostmem); + virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, + VIRTIO_GPU_SHM_ID_HOST_VISIBLE); + } + virtio_pci_force_virtio_1(vpci_dev); if (!qdev_realize(vdev, BUS(&vpci_dev->bus), errp)) { return; diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 5e15c79b94..7b592f998d 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1425,6 +1425,7 @@ static Property virtio_gpu_properties[] =3D { 256 * MiB), DEFINE_PROP_BIT("blob", VirtIOGPU, parent_obj.conf.flags, VIRTIO_GPU_FLAG_BLOB_ENABLED, false), + DEFINE_PROP_SIZE("hostmem", VirtIOGPU, parent_obj.conf.hostmem, 0), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c index e6fb0aa876..c8552ff760 100644 --- a/hw/display/virtio-vga.c +++ b/hw/display/virtio-vga.c @@ -115,17 +115,32 @@ static void virtio_vga_base_realize(VirtIOPCIProxy *v= pci_dev, Error **errp) pci_register_bar(&vpci_dev->pci_dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &vga->vram); =20 - /* - * Configure virtio bar and regions - * - * We use bar #2 for the mmio regions, to be compatible with stdvga. - * virtio regions are moved to the end of bar #2, to make room for - * the stdvga mmio registers at the start of bar #2. - */ - vpci_dev->modern_mem_bar_idx =3D 2; - vpci_dev->msix_bar_idx =3D 4; vpci_dev->modern_io_bar_idx =3D 5; =20 + if (!virtio_gpu_hostmem_enabled(g->conf)) { + /* + * Configure virtio bar and regions + * + * We use bar #2 for the mmio regions, to be compatible with stdvg= a. + * virtio regions are moved to the end of bar #2, to make room for + * the stdvga mmio registers at the start of bar #2. + */ + vpci_dev->modern_mem_bar_idx =3D 2; + vpci_dev->msix_bar_idx =3D 4; + } else { + vpci_dev->msix_bar_idx =3D 1; + vpci_dev->modern_mem_bar_idx =3D 2; + memory_region_init(&g->hostmem, OBJECT(g), "virtio-gpu-hostmem", + g->conf.hostmem); + pci_register_bar(&vpci_dev->pci_dev, 4, + PCI_BASE_ADDRESS_SPACE_MEMORY | + PCI_BASE_ADDRESS_MEM_PREFETCH | + PCI_BASE_ADDRESS_MEM_TYPE_64, + &g->hostmem); + virtio_pci_add_shm_cap(vpci_dev, 4, 0, g->conf.hostmem, + VIRTIO_GPU_SHM_ID_HOST_VISIBLE); + } + if (!(vpci_dev->flags & VIRTIO_PCI_FLAG_PAGE_PER_VQ)) { /* * with page-per-vq=3Doff there is no padding space we can use diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 2e28507efe..eafce75b04 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -102,12 +102,15 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED)) #define virtio_gpu_blob_enabled(_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED)) +#define virtio_gpu_hostmem_enabled(_cfg) \ + (_cfg.hostmem > 0) =20 struct virtio_gpu_base_conf { uint32_t max_outputs; uint32_t flags; uint32_t xres; uint32_t yres; + uint64_t hostmem; }; =20 struct virtio_gpu_ctrl_command { @@ -131,6 +134,8 @@ struct VirtIOGPUBase { int renderer_blocked; int enable; =20 + MemoryRegion hostmem; + struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUTS]; =20 int enabled_output_bitmask; --=20 2.40.0.634.g4ca3ef3211-goog From nobody Thu May 9 23:03:11 2024 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=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1682039633; cv=none; d=zohomail.com; s=zohoarc; b=he/iBELG3LLTmBU4y2gnYjJHAfcoCckR+6/nEg5AxM/I4UeAclENUyftQNgT2EHO0kFim46A4L2uytFx3fK9ey3RkZDUFksYVYoeFZcMtPta1S8PWmmCBOA54XYS069lEWJy6hbE716EzsQAzbXY8CA/phtArKlUlCJwWlATpoA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682039633; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YbYbYvIR+nexInwmsXUkH35G7DOBN8Wfy4B7MS5xdSM=; b=hRktLrEwC6U56fmR+Ugh5ntoAGSX9C/xZbjZ7XKbJL4C5pDGo9znYiqh2CfE6NdqKLsQ2/dGgtW0ya+1anyZvlXu/23YAFBndcLjqJFKpT26XnWxqPDqQnMrSfQNzraa7f9pYz4Byf71Ixpjg6+D66T3i1Ciul4UTKzOIpoHbG4= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682039633387587.7541349876159; Thu, 20 Apr 2023 18:13:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppfKV-0002eB-3i; Thu, 20 Apr 2023 21:12:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppfKL-0002bO-77 for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:41 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppfKD-0008M5-9a for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:40 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1a526aa3dd5so19124385ad.3 for ; Thu, 20 Apr 2023 18:12:32 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:a7:2:6625:6aa3:1b0e:a808]) by smtp.gmail.com with ESMTPSA id f4-20020a17090a8e8400b0024702e7c80fsm1697640pjo.23.2023.04.20.18.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 18:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682039552; x=1684631552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YbYbYvIR+nexInwmsXUkH35G7DOBN8Wfy4B7MS5xdSM=; b=h0ieZlEUGVAmqa5FUkk92axRULu52YqDo0CYpNXGa3YINY9kGzDbB8glwyi+mL5J9F g3Ev5cTwSlYRfjIMEWKYA32tRP+vSHiDcrLuiZIKsnW1rUXQXOnFM3hEgx0Gy41wQeeq b7ZbSpdu8C8ZBxuoxN5PaBe9+5qVUHDGQ6zTM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682039552; x=1684631552; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YbYbYvIR+nexInwmsXUkH35G7DOBN8Wfy4B7MS5xdSM=; b=NNKoA3PX2IJzUEdaIUFJ5WPo6aOYHVr/D+5kDn3S062YyapVUMhqScHAWK4x87v08t jAyQE3IZaa4vMYb2TIoSMoaxWX4wvg5UpmlIbnYT2TQapl3IltP2/sGJdC4I8Hh3xlpo a8CzJowR2JfXTRh3TOfshZ9GHtx4pWRHCmy/iYdUk7JwWCgk9NmaC0mH3UHEHwFeeV5O ZTcl2i6mBDXagZn+LkAYjcrDuFvav2mE9/hMhH7Wr5+984Ho+Htg0AG2WO8igj/SaaOS LoTdu7d7FNQnwnT80UbM3Zz/1zMZVqR5wDYu54bzBfLKFQoKyftFXfua1vIT+IOnV5bM J9jQ== X-Gm-Message-State: AAQBX9ficbm+t0udtHekrMCIZQWXy/7DH1+9QKfoJ0nW2KAdOUWOzcD/ SlkROP8QxgaJq4zOhWazQxi0yJA37B+be9gQ4DPTDn2d X-Google-Smtp-Source: AKy350a/mX5mPruVGeyHTHbtzTkNsxWdLamIdIuJTtWHJuR0M0JyHIPsmyYGQVinQ/6qACFg723Wrg== X-Received: by 2002:a17:902:db11:b0:1a6:8405:f709 with SMTP id m17-20020a170902db1100b001a68405f709mr4245663plx.20.1682039551873; Thu, 20 Apr 2023 18:12:31 -0700 (PDT) From: Gurchetan Singh To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, david@redhat.com, stefanha@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, akihiko.odaki@gmail.com, dmitry.osipenko@collabora.com, ray.huang@amd.com, alex.bennee@linaro.org Subject: [RFC PATCH 03/13] virtio-gpu blob prep: improve decoding and add memory region Date: Thu, 20 Apr 2023 18:12:13 -0700 Message-Id: <20230421011223.718-4-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230421011223.718-1-gurchetansingh@chromium.org> References: <20230421011223.718-1-gurchetansingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=gurchetansingh@chromium.org; helo=mail-pl1-x629.google.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @chromium.org) X-ZM-MESSAGEID: 1682039635195100003 Content-Type: text/plain; charset="utf-8" From: Antonio Caggiano This adds preparatory functions needed to: - decode blob cmds - track memory regions associated with mappable blobs - tracking iovecs Signed-off-by: Antonio Caggiano Signed-off-by: Dmitry Osipenko Signed-off-by: Gurchetan Singh --- hw/display/virtio-gpu.c | 11 +++-------- include/hw/virtio/virtio-gpu-bswap.h | 18 ++++++++++++++++++ include/hw/virtio/virtio-gpu.h | 8 ++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 7b592f998d..938eed9181 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -33,16 +33,11 @@ =20 #define VIRTIO_GPU_VM_VERSION 1 =20 -static struct virtio_gpu_simple_resource* -virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id); static struct virtio_gpu_simple_resource * virtio_gpu_find_check_resource(VirtIOGPU *g, uint32_t resource_id, bool require_backing, const char *caller, uint32_t *error); =20 -static void virtio_gpu_cleanup_mapping(VirtIOGPU *g, - struct virtio_gpu_simple_resource *= res); - void virtio_gpu_update_cursor_data(VirtIOGPU *g, struct virtio_gpu_scanout *s, uint32_t resource_id) @@ -115,7 +110,7 @@ static void update_cursor(VirtIOGPU *g, struct virtio_g= pu_update_cursor *cursor) cursor->resource_id ? 1 : 0); } =20 -static struct virtio_gpu_simple_resource * +struct virtio_gpu_simple_resource * virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id) { struct virtio_gpu_simple_resource *res; @@ -872,8 +867,8 @@ void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g, g_free(iov); } =20 -static void virtio_gpu_cleanup_mapping(VirtIOGPU *g, - struct virtio_gpu_simple_resource *= res) +void virtio_gpu_cleanup_mapping(VirtIOGPU *g, + struct virtio_gpu_simple_resource *res) { virtio_gpu_cleanup_mapping_iov(g, res->iov, res->iov_cnt); res->iov =3D NULL; diff --git a/include/hw/virtio/virtio-gpu-bswap.h b/include/hw/virtio/virti= o-gpu-bswap.h index 9124108485..dd1975e2d4 100644 --- a/include/hw/virtio/virtio-gpu-bswap.h +++ b/include/hw/virtio/virtio-gpu-bswap.h @@ -63,10 +63,28 @@ virtio_gpu_create_blob_bswap(struct virtio_gpu_resource= _create_blob *cblob) { virtio_gpu_ctrl_hdr_bswap(&cblob->hdr); le32_to_cpus(&cblob->resource_id); + le32_to_cpus(&cblob->blob_mem); le32_to_cpus(&cblob->blob_flags); + le32_to_cpus(&cblob->nr_entries); + le64_to_cpus(&cblob->blob_id); le64_to_cpus(&cblob->size); } =20 +static inline void +virtio_gpu_map_blob_bswap(struct virtio_gpu_resource_map_blob *mblob) +{ + virtio_gpu_ctrl_hdr_bswap(&mblob->hdr); + le32_to_cpus(&mblob->resource_id); + le64_to_cpus(&mblob->offset); +} + +static inline void +virtio_gpu_unmap_blob_bswap(struct virtio_gpu_resource_unmap_blob *ublob) +{ + virtio_gpu_ctrl_hdr_bswap(&ublob->hdr); + le32_to_cpus(&ublob->resource_id); +} + static inline void virtio_gpu_scanout_blob_bswap(struct virtio_gpu_set_scanout_blob *ssb) { diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index eafce75b04..326988e4d5 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -55,6 +55,9 @@ struct virtio_gpu_simple_resource { int dmabuf_fd; uint8_t *remapped; =20 + MemoryRegion region; + void *mapped; + QTAILQ_ENTRY(virtio_gpu_simple_resource) next; }; =20 @@ -245,6 +248,9 @@ void virtio_gpu_base_fill_display_info(VirtIOGPUBase *g, struct virtio_gpu_resp_display_info *dpy_info); =20 /* virtio-gpu.c */ +struct virtio_gpu_simple_resource * +virtio_gpu_find_resource(VirtIOGPU *g, uint32_t resource_id); + void virtio_gpu_ctrl_response(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd, struct virtio_gpu_ctrl_hdr *resp, @@ -263,6 +269,8 @@ int virtio_gpu_create_mapping_iov(VirtIOGPU *g, uint32_t *niov); void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g, struct iovec *iov, uint32_t count); +void virtio_gpu_cleanup_mapping(VirtIOGPU *g, + struct virtio_gpu_simple_resource *res); void virtio_gpu_process_cmdq(VirtIOGPU *g); void virtio_gpu_device_realize(DeviceState *qdev, Error **errp); void virtio_gpu_reset(VirtIODevice *vdev); --=20 2.40.0.634.g4ca3ef3211-goog From nobody Thu May 9 23:03:11 2024 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=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1682039611; cv=none; d=zohomail.com; s=zohoarc; b=MUYX7b3WHXpYE6BbGt9WTCHkNk2pYpQtPTxuB0VTm/cW7KC9qxmfMSlmD5V2vedzk8XVns5HOMIP6059j7YcOnXKJYva+hIwD3mHTqr8TduOS8cStu3sgE5b+3K06M8dMQg4xecjNxcvAX64N8HgHkmrEb61mrzsafBW34+FB/k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682039611; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JR0TNlvN0Q7HJGAqqrRHfNCdk0Mlg/TBNVfhiBqdfsQ=; b=EjXvoisdXnCGZuSwfXWq1ECNs01ciZbZH3UFqqBQKiddvwSsuP34UtHhOygjwSzCNPUSITlhlyIH+y+Lb6reln90304YKv7FDQ/PbpaYa0tEPeCKHOGKI1HhI4agYAgIcUDoDIokjk7Ovs8tqs7W2PcKjsj3LiAJi9KE7+QIpvA= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682039611124722.1055006996835; Thu, 20 Apr 2023 18:13:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppfKN-0002cc-L9; Thu, 20 Apr 2023 21:12:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppfKL-0002bL-58 for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:41 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppfKF-0008MB-R4 for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:40 -0400 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-51f597c97c5so1282399a12.0 for ; Thu, 20 Apr 2023 18:12:34 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:a7:2:6625:6aa3:1b0e:a808]) by smtp.gmail.com with ESMTPSA id f4-20020a17090a8e8400b0024702e7c80fsm1697640pjo.23.2023.04.20.18.12.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 18:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682039553; x=1684631553; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JR0TNlvN0Q7HJGAqqrRHfNCdk0Mlg/TBNVfhiBqdfsQ=; b=fYrWNOrFQsEGzlYRMZAT2/EbmPnjloBYibQ9Xk3tCg+LPY3+SMR4GPLHulxQMSSi9F 1CzS3v1HoyIBSxY9uDCpXiqnOZ/2B9eFhfvN0KfaBobrja77xfSqFgUnW/cMbw4op82A jc6OuE+puIyY0fVVLqBfoZTzfS3NeGQSCY/ys= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682039553; x=1684631553; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JR0TNlvN0Q7HJGAqqrRHfNCdk0Mlg/TBNVfhiBqdfsQ=; b=YdVv7ZxMFVDLgMMhgIqcFCH6cJHs94Vq+kwEsj9fuSGQEvEMkgnb6063YqguLdB82C MkwML41GM4T+u106rDx61KWxxw5qlnxXfkapAUTi+GcMTkxeE2iKyPqbZEdIDBCVwkhU z/qfw/8XebOqt4d93mCS3KseQ+QjKmBSGVzjNUHLG/D4VxmUnvFBKPpDbuUJlag1siFY P3xiDjw6oprPvX7wsKDF85KXKU0P6F+IbrHp/y7FjSBw7mmcZ2VsbnrGUFUZSR3PinFE kQGrjZLZQbKaSwLCPxfu88NxIniDf/woLA2D+To05JN5PhPq9xSbVaOFwLSD5rxqpT8H ybEQ== X-Gm-Message-State: AAQBX9eSSSTmqFzx1BQa8VzW0zL/9Tyq7I78mjqrxcJLg1Uys39qe+Yi eKw7U0Uco1HpCOktNI+nJrTikdw1zyjAg0HgdHsDBfyq X-Google-Smtp-Source: AKy350YC8dooTZS+VUOi3yAR4i/VOznAebA6XHBaO4JCiK9BfYb4PjLAKf01UwCLk50HdT9TBxk0YA== X-Received: by 2002:a17:90b:3a88:b0:247:6023:f884 with SMTP id om8-20020a17090b3a8800b002476023f884mr3577333pjb.15.1682039553353; Thu, 20 Apr 2023 18:12:33 -0700 (PDT) From: Gurchetan Singh To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, david@redhat.com, stefanha@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, akihiko.odaki@gmail.com, dmitry.osipenko@collabora.com, ray.huang@amd.com, alex.bennee@linaro.org Subject: [RFC PATCH 04/13] virtio-gpu: CONTEXT_INIT feature Date: Thu, 20 Apr 2023 18:12:14 -0700 Message-Id: <20230421011223.718-5-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230421011223.718-1-gurchetansingh@chromium.org> References: <20230421011223.718-1-gurchetansingh@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=gurchetansingh@chromium.org; helo=mail-pg1-x52e.google.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @chromium.org) X-ZM-MESSAGEID: 1682039612783100003 From: Antonio Caggiano The feature can be enabled when a backend wants it. Signed-off-by: Antonio Caggiano Reviewed-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Gurchetan Singh --- hw/display/virtio-gpu-base.c | 3 +++ include/hw/virtio/virtio-gpu.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c index a29f191aa8..6c5f1f327f 100644 --- a/hw/display/virtio-gpu-base.c +++ b/hw/display/virtio-gpu-base.c @@ -215,6 +215,9 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64= _t features, if (virtio_gpu_blob_enabled(g->conf)) { features |=3D (1 << VIRTIO_GPU_F_RESOURCE_BLOB); } + if (virtio_gpu_context_init_enabled(g->conf)) { + features |=3D (1 << VIRTIO_GPU_F_CONTEXT_INIT); + } =20 return features; } diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 326988e4d5..adee17968d 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -93,6 +93,7 @@ enum virtio_gpu_base_conf_flags { VIRTIO_GPU_FLAG_EDID_ENABLED, VIRTIO_GPU_FLAG_DMABUF_ENABLED, VIRTIO_GPU_FLAG_BLOB_ENABLED, + VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED, }; =20 #define virtio_gpu_virgl_enabled(_cfg) \ @@ -107,6 +108,8 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED)) #define virtio_gpu_hostmem_enabled(_cfg) \ (_cfg.hostmem > 0) +#define virtio_gpu_context_init_enabled(_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED)) =20 struct virtio_gpu_base_conf { uint32_t max_outputs; --=20 2.40.0.634.g4ca3ef3211-goog From nobody Thu May 9 23:03:11 2024 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=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1682039597; cv=none; d=zohomail.com; s=zohoarc; b=a3wBnYhr60oj0DWX3EzETvz2Ad9oQZWaVj4bVo7EehGgUx2ehY08arPXGwfMfQ+D5G6wHPdqsTzV7ab0LV/0u+T+yCTJpyS2AuOt9LbHNw+xrHD18pkF+zg2HEL78it1w0vlEzSV+AvNgtVdbjuuJNgWmE9Dd5cCgtGBCfIrkHM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682039597; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kfHhm4nND4bStTj+yGgL15ysAxO8GJhh6JBse4owvSs=; b=hx76O4cbnCJAf67mKpjs2AO8gNUocJQ9qDIEgrVlV8DDYYc2cpu0WJKYunbVBstfuw9C4bTiE3Z/HYrdlGO2NHVgDfP3OyKhovn3NonhwkS9QEmKIEftS7Im8Zwy0cjcpHAowMTwzQDWlUu07oe406FWQP/T+r7nCA6a04Cp74w= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682039597544921.9244230314321; Thu, 20 Apr 2023 18:13:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppfKN-0002cf-LI; Thu, 20 Apr 2023 21:12:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppfKL-0002bN-6e for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:41 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppfKI-0008MU-Mu for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:40 -0400 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-247526f0eceso1187001a91.2 for ; Thu, 20 Apr 2023 18:12:36 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:a7:2:6625:6aa3:1b0e:a808]) by smtp.gmail.com with ESMTPSA id f4-20020a17090a8e8400b0024702e7c80fsm1697640pjo.23.2023.04.20.18.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 18:12:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682039555; x=1684631555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kfHhm4nND4bStTj+yGgL15ysAxO8GJhh6JBse4owvSs=; b=KS7Z542rFWVB1stGg0lFyumYUE6ieEY2dhyJ7B4wTsJQ8ze85L43I6DYiahXfpVy/Y 9nbFbxR8hyUaZ+oa6a/JY2msPzBF+RjxIjDy333jFhUQD3VDa+Yf6GYMom1mZbBdtFC+ Vk8kaCykJGTX9mgmvWg7TffnmJfRummmHN9N4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682039555; x=1684631555; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kfHhm4nND4bStTj+yGgL15ysAxO8GJhh6JBse4owvSs=; b=LkrNldHx90JqOQsR0w1RXmI9iBy+OBoZbnXaCSSaYpHygUbF5z9xhiECkvGq8KkuZt RalSGr6T+guHPd+5vbaAtP8zwtnsl+pVYxLzSotoBHPR9JVCgcrziBTtrhATlQxjoLJS +LilNWGUaJMq5awYHMTFBRk6xHE7PAujLl2Lvlg+45GVzYFVyJesIc2+AQD6Zz9VB3D1 MlJgNlaCr36xcE+jRfjSr7pVLuVOjbiac2y/2jtuCxgV9c9BPO+Ia+dnst9h1DSodsCd m0DIVIwyjOQMAa7L6xIfIe81P1q1vQit81AqoNGBpQJyrHDEizXL/zOgPeYcCCJnGBXk 6Pkg== X-Gm-Message-State: AAQBX9cC4Ah90zFI8T7mwhg3RBFc8meJCTq9W7rjuhTU7GNovDGfDXO6 0Pe3jQ3DUOYCy7M0MzGC88jCaoTKhL+qCaVvEtO/vyI3 X-Google-Smtp-Source: AKy350bw9b/BSApze1eDEktYM6VFCRxx3h4N9ycclng6YJOQO+yTf4ie8NU32MhvT0AAVmj6BOWzLw== X-Received: by 2002:a17:90a:4741:b0:249:6a63:7b8e with SMTP id y1-20020a17090a474100b002496a637b8emr3470649pjg.5.1682039555019; Thu, 20 Apr 2023 18:12:35 -0700 (PDT) From: Gurchetan Singh To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, david@redhat.com, stefanha@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, akihiko.odaki@gmail.com, dmitry.osipenko@collabora.com, ray.huang@amd.com, alex.bennee@linaro.org Subject: [RFC PATCH 05/13] gfxstream + rutabaga prep: virtio_gpu_gl -> virtio_gpu_virgl Date: Thu, 20 Apr 2023 18:12:15 -0700 Message-Id: <20230421011223.718-6-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230421011223.718-1-gurchetansingh@chromium.org> References: <20230421011223.718-1-gurchetansingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=gurchetansingh@chromium.org; helo=mail-pj1-x1032.google.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @chromium.org) X-ZM-MESSAGEID: 1682039600272100003 Content-Type: text/plain; charset="utf-8" The virtio-gpu GL device has a heavy dependence on virgl. Acknowledge this by naming functions accurately. Signed-off-by: Gurchetan Singh Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/display/virtio-gpu-gl.c | 27 ++++++++++++++------------- hw/display/virtio-gpu-virgl.c | 2 +- include/hw/virtio/virtio-gpu.h | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c index e06be60dfb..dc648aacb2 100644 --- a/hw/display/virtio-gpu-gl.c +++ b/hw/display/virtio-gpu-gl.c @@ -25,9 +25,10 @@ =20 #include =20 -static void virtio_gpu_gl_update_cursor_data(VirtIOGPU *g, - struct virtio_gpu_scanout *s, - uint32_t resource_id) +static void +virtio_gpu_virgl_update_cursor(VirtIOGPU *g, + struct virtio_gpu_scanout *s, + uint32_t resource_id) { uint32_t width, height; uint32_t pixels, *data; @@ -48,14 +49,14 @@ static void virtio_gpu_gl_update_cursor_data(VirtIOGPU = *g, free(data); } =20 -static void virtio_gpu_gl_flushed(VirtIOGPUBase *b) +static void virtio_gpu_virgl_flushed(VirtIOGPUBase *b) { VirtIOGPU *g =3D VIRTIO_GPU(b); =20 virtio_gpu_process_cmdq(g); } =20 -static void virtio_gpu_gl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) +static void virtio_gpu_virgl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) { VirtIOGPU *g =3D VIRTIO_GPU(vdev); VirtIOGPUGL *gl =3D VIRTIO_GPU_GL(vdev); @@ -71,7 +72,7 @@ static void virtio_gpu_gl_handle_ctrl(VirtIODevice *vdev,= VirtQueue *vq) } if (gl->renderer_reset) { gl->renderer_reset =3D false; - virtio_gpu_virgl_reset(g); + virtio_gpu_virglrenderer_reset(g); } =20 cmd =3D virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command)); @@ -87,7 +88,7 @@ static void virtio_gpu_gl_handle_ctrl(VirtIODevice *vdev,= VirtQueue *vq) virtio_gpu_virgl_fence_poll(g); } =20 -static void virtio_gpu_gl_reset(VirtIODevice *vdev) +static void virtio_gpu_virgl_reset(VirtIODevice *vdev) { VirtIOGPU *g =3D VIRTIO_GPU(vdev); VirtIOGPUGL *gl =3D VIRTIO_GPU_GL(vdev); @@ -104,7 +105,7 @@ static void virtio_gpu_gl_reset(VirtIODevice *vdev) } } =20 -static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp) +static void virtio_gpu_virgl_device_realize(DeviceState *qdev, Error **err= p) { VirtIOGPU *g =3D VIRTIO_GPU(qdev); =20 @@ -143,13 +144,13 @@ static void virtio_gpu_gl_class_init(ObjectClass *kla= ss, void *data) VirtIOGPUBaseClass *vbc =3D VIRTIO_GPU_BASE_CLASS(klass); VirtIOGPUClass *vgc =3D VIRTIO_GPU_CLASS(klass); =20 - vbc->gl_flushed =3D virtio_gpu_gl_flushed; - vgc->handle_ctrl =3D virtio_gpu_gl_handle_ctrl; + vbc->gl_flushed =3D virtio_gpu_virgl_flushed; + vgc->handle_ctrl =3D virtio_gpu_virgl_handle_ctrl; vgc->process_cmd =3D virtio_gpu_virgl_process_cmd; - vgc->update_cursor_data =3D virtio_gpu_gl_update_cursor_data; + vgc->update_cursor_data =3D virtio_gpu_virgl_update_cursor; =20 - vdc->realize =3D virtio_gpu_gl_device_realize; - vdc->reset =3D virtio_gpu_gl_reset; + vdc->realize =3D virtio_gpu_virgl_device_realize; + vdc->reset =3D virtio_gpu_virgl_reset; device_class_set_props(dc, virtio_gpu_gl_properties); } =20 diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 1c47603d40..f91d33ce13 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -599,7 +599,7 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g) } } =20 -void virtio_gpu_virgl_reset(VirtIOGPU *g) +void virtio_gpu_virglrenderer_reset(VirtIOGPU *g) { virgl_renderer_reset(); } diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index adee17968d..e256e44172 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -297,7 +297,7 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd); void virtio_gpu_virgl_fence_poll(VirtIOGPU *g); void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g); -void virtio_gpu_virgl_reset(VirtIOGPU *g); +void virtio_gpu_virglrenderer_reset(VirtIOGPU *g); int virtio_gpu_virgl_init(VirtIOGPU *g); int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g); =20 --=20 2.40.0.634.g4ca3ef3211-goog From nobody Thu May 9 23:03:11 2024 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=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1682039710; cv=none; d=zohomail.com; s=zohoarc; b=bm3tlrLf6nByJBKTy/WHfu8HL+v1o07dng0TM4PeF9JCyww79oupiPXneCUc5vJ4rMlTf2EYN0vpkIPrFmt2B+05FHeoOhXLNXoNm6CYT/QrczsUvN4JiarNeDr5GZzAIPw9/ZNWpulK1XZ8+CYG7slcoLC7knOGWRr1eRBib9Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682039710; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hhHTLIfJpfuTUDeD8Y57brA0Bsbdi/Q3CGhvHbiGyKc=; b=jDUGa4iLw/FdbMvLh4gezbjyxuufAYEjDc5SxzNueQ5zj6qFwozp7mz47jGlxgyUONLKr1jVUZe/EHcbK5XaFCbapr8oinl9xHzrK3tzIaVzqeTLu+XN2FEaUTjKSsVMzUB/sICArdZWVGRSWxPOaeUF50lcTMDfj62Jtb0qGL8= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682039710408601.7137955914552; Thu, 20 Apr 2023 18:15:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppfKQ-0002dU-Ve; Thu, 20 Apr 2023 21:12:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppfKL-0002c3-Vg for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:42 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppfKI-0008Mj-NG for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:41 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-63b5ce4f069so2173746b3a.1 for ; Thu, 20 Apr 2023 18:12:38 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:a7:2:6625:6aa3:1b0e:a808]) by smtp.gmail.com with ESMTPSA id f4-20020a17090a8e8400b0024702e7c80fsm1697640pjo.23.2023.04.20.18.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 18:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682039557; x=1684631557; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hhHTLIfJpfuTUDeD8Y57brA0Bsbdi/Q3CGhvHbiGyKc=; b=Rb1DTRIbt4XIrq6XeCf60wGDJZMoyeZ0On8mjGsqsuLtkKW9ylzriLsCoE0qAWYL13 xRyoZyDRuLzwlCj+eX9WnB0+/iU79xG2CQCTBwfrk9grGvM9IODjWkbfDclwraUUAw1r 8MfH2fJ10RZJQK1gOx3/mSkZL/7/6FwnORabM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682039557; x=1684631557; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hhHTLIfJpfuTUDeD8Y57brA0Bsbdi/Q3CGhvHbiGyKc=; b=Caf7qtxSgNiQzGSB94lsYdAms6OTobFpjemMU0hSmBeH+JW3b4hQHsj4A2anm+uZ2f BOh0Dwlum+4rG4bL+dPe2qtpTBP+BzkLeu/DvI8qEEBM9mtNSGI1cns/X2QVvnfvbzOH CdqbHF9GoGUNtCH0YxWjSLYmfr4zod4Htb/6YVjJcJub+HDDrC8u7uOon75KUib6tVN6 +dQkwmco97qihd4axvoSpA/tRINGPuJ5Fg18dYTy2lRqbrryfdVWoNmKhFHw3COWcZTJ D2tMLwHsb/4jT1L1DRNFA1M/EXtck6+HzkQ30VxQjmNmOBuKgxz7e2I0xE2JNuGEw6Z9 TWtA== X-Gm-Message-State: AAQBX9eewDoYSHSh6vOgiGT8n5w4tdlpJBjyVK/6GS4dee9w5QluIl+t F+nBD9LeJu+XKikE0LqUQA5GpvgzO4CkXP1VxtehR7Ov X-Google-Smtp-Source: AKy350bR8+LmuvrhRtj9zKLrbffGsdjt3iRA+eMEKbrP+v3oxKlvX1Ms8oSvfirPzsAJQu0IrIPg/Q== X-Received: by 2002:a17:903:1c4:b0:1a2:9183:a49c with SMTP id e4-20020a17090301c400b001a29183a49cmr4169439plh.32.1682039556760; Thu, 20 Apr 2023 18:12:36 -0700 (PDT) From: Gurchetan Singh To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, david@redhat.com, stefanha@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, akihiko.odaki@gmail.com, dmitry.osipenko@collabora.com, ray.huang@amd.com, alex.bennee@linaro.org Subject: [RFC PATCH 06/13] gfxstream + rutabaga prep: make GL device more library agnostic Date: Thu, 20 Apr 2023 18:12:16 -0700 Message-Id: <20230421011223.718-7-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230421011223.718-1-gurchetansingh@chromium.org> References: <20230421011223.718-1-gurchetansingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=gurchetansingh@chromium.org; helo=mail-pf1-x432.google.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @chromium.org) X-ZM-MESSAGEID: 1682039710876100001 Content-Type: text/plain; charset="utf-8" Rather than create a virtio-gpu-gfxstream device and it's associated variants (vga, pci), let's just extend the GL device. We need to: - Move all virgl functions to their own file - Only all needed class callbacks in the generic GL device Signed-off-by: Gurchetan Singh --- hw/display/virtio-gpu-gl.c | 110 ------------------------------ hw/display/virtio-gpu-virgl.c | 119 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-gpu.h | 11 +-- 3 files changed, 120 insertions(+), 120 deletions(-) diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c index dc648aacb2..2d140e8792 100644 --- a/hw/display/virtio-gpu-gl.c +++ b/hw/display/virtio-gpu-gl.c @@ -15,122 +15,12 @@ #include "qemu/iov.h" #include "qemu/module.h" #include "qemu/error-report.h" -#include "qapi/error.h" -#include "sysemu/sysemu.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" #include "hw/virtio/virtio-gpu-bswap.h" #include "hw/virtio/virtio-gpu-pixman.h" #include "hw/qdev-properties.h" =20 -#include - -static void -virtio_gpu_virgl_update_cursor(VirtIOGPU *g, - struct virtio_gpu_scanout *s, - uint32_t resource_id) -{ - uint32_t width, height; - uint32_t pixels, *data; - - data =3D virgl_renderer_get_cursor_data(resource_id, &width, &height); - if (!data) { - return; - } - - if (width !=3D s->current_cursor->width || - height !=3D s->current_cursor->height) { - free(data); - return; - } - - pixels =3D s->current_cursor->width * s->current_cursor->height; - memcpy(s->current_cursor->data, data, pixels * sizeof(uint32_t)); - free(data); -} - -static void virtio_gpu_virgl_flushed(VirtIOGPUBase *b) -{ - VirtIOGPU *g =3D VIRTIO_GPU(b); - - virtio_gpu_process_cmdq(g); -} - -static void virtio_gpu_virgl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) -{ - VirtIOGPU *g =3D VIRTIO_GPU(vdev); - VirtIOGPUGL *gl =3D VIRTIO_GPU_GL(vdev); - struct virtio_gpu_ctrl_command *cmd; - - if (!virtio_queue_ready(vq)) { - return; - } - - if (!gl->renderer_inited) { - virtio_gpu_virgl_init(g); - gl->renderer_inited =3D true; - } - if (gl->renderer_reset) { - gl->renderer_reset =3D false; - virtio_gpu_virglrenderer_reset(g); - } - - cmd =3D virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command)); - while (cmd) { - cmd->vq =3D vq; - cmd->error =3D 0; - cmd->finished =3D false; - QTAILQ_INSERT_TAIL(&g->cmdq, cmd, next); - cmd =3D virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command)); - } - - virtio_gpu_process_cmdq(g); - virtio_gpu_virgl_fence_poll(g); -} - -static void virtio_gpu_virgl_reset(VirtIODevice *vdev) -{ - VirtIOGPU *g =3D VIRTIO_GPU(vdev); - VirtIOGPUGL *gl =3D VIRTIO_GPU_GL(vdev); - - virtio_gpu_reset(vdev); - - /* - * GL functions must be called with the associated GL context in main - * thread, and when the renderer is unblocked. - */ - if (gl->renderer_inited && !gl->renderer_reset) { - virtio_gpu_virgl_reset_scanout(g); - gl->renderer_reset =3D true; - } -} - -static void virtio_gpu_virgl_device_realize(DeviceState *qdev, Error **err= p) -{ - VirtIOGPU *g =3D VIRTIO_GPU(qdev); - -#if HOST_BIG_ENDIAN - error_setg(errp, "virgl is not supported on bigendian platforms"); - return; -#endif - - if (!object_resolve_path_type("", TYPE_VIRTIO_GPU_GL, NULL)) { - error_setg(errp, "at most one %s device is permitted", TYPE_VIRTIO= _GPU_GL); - return; - } - - if (!display_opengl) { - error_setg(errp, "opengl is not available"); - return; - } - - g->parent_obj.conf.flags |=3D (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED); - VIRTIO_GPU_BASE(g)->virtio_config.num_capsets =3D - virtio_gpu_virgl_get_num_capsets(g); - - virtio_gpu_device_realize(qdev, errp); -} - static Property virtio_gpu_gl_properties[] =3D { DEFINE_PROP_BIT("stats", VirtIOGPU, parent_obj.conf.flags, VIRTIO_GPU_FLAG_STATS_ENABLED, false), diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index f91d33ce13..87eccb2b97 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -14,6 +14,8 @@ #include "qemu/osdep.h" #include "qemu/error-report.h" #include "qemu/iov.h" +#include "qapi/error.h" +#include "sysemu/sysemu.h" #include "trace.h" #include "hw/virtio/virtio.h" #include "hw/virtio/virtio-gpu.h" @@ -584,12 +586,12 @@ static void virtio_gpu_fence_poll(void *opaque) } } =20 -void virtio_gpu_virgl_fence_poll(VirtIOGPU *g) +static void virtio_gpu_virgl_fence_poll(VirtIOGPU *g) { virtio_gpu_fence_poll(g); } =20 -void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g) +static void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g) { int i; =20 @@ -599,12 +601,12 @@ void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g) } } =20 -void virtio_gpu_virglrenderer_reset(VirtIOGPU *g) +static void virtio_gpu_virglrenderer_reset(VirtIOGPU *g) { virgl_renderer_reset(); } =20 -int virtio_gpu_virgl_init(VirtIOGPU *g) +static int virtio_gpu_virgl_init(VirtIOGPU *g) { int ret; =20 @@ -625,7 +627,7 @@ int virtio_gpu_virgl_init(VirtIOGPU *g) return 0; } =20 -int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g) +static int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g) { uint32_t capset2_max_ver, capset2_max_size; virgl_renderer_get_cap_set(VIRTIO_GPU_CAPSET_VIRGL2, @@ -634,3 +636,110 @@ int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g) =20 return capset2_max_ver ? 2 : 1; } + +void +virtio_gpu_virgl_update_cursor(VirtIOGPU *g, + struct virtio_gpu_scanout *s, + uint32_t resource_id) +{ + uint32_t width, height; + uint32_t pixels, *data; + + data =3D virgl_renderer_get_cursor_data(resource_id, &width, &height); + if (!data) { + return; + } + + if (width !=3D s->current_cursor->width || + height !=3D s->current_cursor->height) { + free(data); + return; + } + + pixels =3D s->current_cursor->width * s->current_cursor->height; + memcpy(s->current_cursor->data, data, pixels * sizeof(uint32_t)); + free(data); +} + +void virtio_gpu_virgl_flushed(VirtIOGPUBase *b) +{ + VirtIOGPU *g =3D VIRTIO_GPU(b); + + virtio_gpu_process_cmdq(g); +} + +void virtio_gpu_virgl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtIOGPU *g =3D VIRTIO_GPU(vdev); + VirtIOGPUGL *gl =3D VIRTIO_GPU_GL(vdev); + struct virtio_gpu_ctrl_command *cmd; + + if (!virtio_queue_ready(vq)) { + return; + } + + if (!gl->renderer_inited) { + virtio_gpu_virgl_init(g); + gl->renderer_inited =3D true; + } + if (gl->renderer_reset) { + gl->renderer_reset =3D false; + virtio_gpu_virglrenderer_reset(g); + } + + cmd =3D virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command)); + while (cmd) { + cmd->vq =3D vq; + cmd->error =3D 0; + cmd->finished =3D false; + QTAILQ_INSERT_TAIL(&g->cmdq, cmd, next); + cmd =3D virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command)); + } + + virtio_gpu_process_cmdq(g); + virtio_gpu_virgl_fence_poll(g); +} + +void virtio_gpu_virgl_reset(VirtIODevice *vdev) +{ + VirtIOGPU *g =3D VIRTIO_GPU(vdev); + VirtIOGPUGL *gl =3D VIRTIO_GPU_GL(vdev); + + virtio_gpu_reset(vdev); + + /* + * GL functions must be called with the associated GL context in main + * thread, and when the renderer is unblocked. + */ + if (gl->renderer_inited && !gl->renderer_reset) { + virtio_gpu_virgl_reset_scanout(g); + gl->renderer_reset =3D true; + } +} + +void virtio_gpu_virgl_device_realize(DeviceState *qdev, Error **errp) +{ + VirtIOGPU *g =3D VIRTIO_GPU(qdev); + +#if HOST_BIG_ENDIAN + error_setg(errp, "virgl is not supported on bigendian platforms"); + return; +#endif + + if (!object_resolve_path_type("", TYPE_VIRTIO_GPU_GL, NULL)) { + error_setg(errp, "at most one %s device is permitted", + TYPE_VIRTIO_GPU_GL); + return; + } + + if (!display_opengl) { + error_setg(errp, "opengl is not available"); + return; + } + + g->parent_obj.conf.flags |=3D (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED); + VIRTIO_GPU_BASE(g)->virtio_config.num_capsets =3D + virtio_gpu_virgl_get_num_capsets(g); + + virtio_gpu_device_realize(qdev, errp); +} diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index e256e44172..7317b60004 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -295,10 +295,11 @@ int virtio_gpu_update_dmabuf(VirtIOGPU *g, /* virtio-gpu-3d.c */ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd); -void virtio_gpu_virgl_fence_poll(VirtIOGPU *g); -void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g); -void virtio_gpu_virglrenderer_reset(VirtIOGPU *g); -int virtio_gpu_virgl_init(VirtIOGPU *g); -int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g); +void virtio_gpu_virgl_update_cursor(VirtIOGPU *g, struct virtio_gpu_scanou= t *s, + uint32_t resource_id); +void virtio_gpu_virgl_flushed(VirtIOGPUBase *b); +void virtio_gpu_virgl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq); +void virtio_gpu_virgl_reset(VirtIODevice *vdev); +void virtio_gpu_virgl_device_realize(DeviceState *qdev, Error **errp); =20 #endif --=20 2.40.0.634.g4ca3ef3211-goog From nobody Thu May 9 23:03:11 2024 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=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1682039655; cv=none; d=zohomail.com; s=zohoarc; b=LUmuig6VDi+vGIiJ3cIHpS9ywtfDIYCaRgN1FRqtz3au+f228gejMBTu160HZpP4AqqzV32jtLyjAaorRwOcU0UyFFhXQeufLhBKvlQ4UVYQV/qj6aPi3uVSQOJklr/RnQyzGGvWn9GaeBNs4eu0wZ8rb2gXK6fCrG9tcrHXgrA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682039655; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ODhRNpYxDaUUcHw5UOrxy4qV9LqgrKicEwn5wh2863M=; b=n1Of0+BjU4eMV9Ynub6eymRVz6uotBmNxf+updaGh95FL3CTNArzwI6MShyAtqCNrhyXL5QfiEsNDP/51UwwLw88Y8JsnOjy1lxEauoSjtVe5vwBpFMx73mQfd/Tgjcnun8msRI279KLat7K+An5miEsGKpvZMbWUVsoal+lxfU= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682039655478899.3940923851164; Thu, 20 Apr 2023 18:14:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppfKh-0002gm-Ei; Thu, 20 Apr 2023 21:13:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppfKM-0002c9-JX for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:42 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppfKJ-0008Mn-Ms for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:42 -0400 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1a66b9bd7dfso19135425ad.2 for ; Thu, 20 Apr 2023 18:12:39 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:a7:2:6625:6aa3:1b0e:a808]) by smtp.gmail.com with ESMTPSA id f4-20020a17090a8e8400b0024702e7c80fsm1697640pjo.23.2023.04.20.18.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 18:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682039558; x=1684631558; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ODhRNpYxDaUUcHw5UOrxy4qV9LqgrKicEwn5wh2863M=; b=jOf4LDSQp1Jpg1LoXVGkH1aKlMewJhPhkti4tnVjN0KLLPj340fjk0tIwSRhwMUPK6 48bIxB1juxeDNFvGCBS5RcOkHo0yI6bTVBbDi1RovQ6lKUEC/57OGEfX34q/2K4PIVio tWYGwdQetL3zDKV3bWOnNCnq6ZGc3LWH7Bd2Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682039558; x=1684631558; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ODhRNpYxDaUUcHw5UOrxy4qV9LqgrKicEwn5wh2863M=; b=TIm3mPwWtEl5frDa498Dy85bAUB8qyZSktyi0PaZMtjI9WKnM3ZFxrO8nAPkjqVZaa RVgghZea3ZJulO3SHu0eJAro1uqfyNcTNUtc8ett9Bj8VrVKTvQeS+Lhg1PwKAIE9BeU UnPnJUKd6KooaFzbdfbLgj3jFDLHA/4ZE16QW5J3yAuyiDonPWE0vNqb/UHnuKGzZN4S BEfyxePQiErIZhbA/NxMPgVkqoWNJ5rCUJ/2VxS02OatMyQWrFTV/oK6tc6eblg2GU1U 20h3NRM1Lr+WiOxsiWgP0iZNNiDbGqL1JmCfmopDtYhN6vlKae5cdnM5FP0PqLATt+oy 2h6w== X-Gm-Message-State: AAQBX9cqQbDf5Tnl7OxrbhyXwa4/5aLX3cnbggiGHt9TVHbp8iS6VVBe 2Bx0fAnZpdngDccqDukYNvrHRgTFIwOm2AZZt5mK4ZVx X-Google-Smtp-Source: AKy350aVzE7JaanqumalpRY0wmTSwAG1QmZlAgjRbC5Dl700ZN5TjKLLQEQW2M5jzA3CfLJ/jrXEeg== X-Received: by 2002:a17:902:f651:b0:1a2:85f0:e73d with SMTP id m17-20020a170902f65100b001a285f0e73dmr3623509plg.33.1682039558269; Thu, 20 Apr 2023 18:12:38 -0700 (PDT) From: Gurchetan Singh To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, david@redhat.com, stefanha@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, akihiko.odaki@gmail.com, dmitry.osipenko@collabora.com, ray.huang@amd.com, alex.bennee@linaro.org Subject: [RFC PATCH 07/13] gfxstream + rutabaga prep: define callbacks in realize function Date: Thu, 20 Apr 2023 18:12:17 -0700 Message-Id: <20230421011223.718-8-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230421011223.718-1-gurchetansingh@chromium.org> References: <20230421011223.718-1-gurchetansingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=gurchetansingh@chromium.org; helo=mail-pl1-x635.google.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @chromium.org) X-ZM-MESSAGEID: 1682039656631100001 Content-Type: text/plain; charset="utf-8" This reduces the amount of renderer backend specific needed to be exposed to the GL device. We only need one realize function per renderer backend. Signed-off-by: Gurchetan Singh Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/display/virtio-gpu-gl.c | 17 +++++++++++------ hw/display/virtio-gpu-virgl.c | 35 ++++++++++++++++++++++++---------- include/hw/virtio/virtio-gpu.h | 7 ------- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c index 2d140e8792..547e697333 100644 --- a/hw/display/virtio-gpu-gl.c +++ b/hw/display/virtio-gpu-gl.c @@ -21,6 +21,11 @@ #include "hw/virtio/virtio-gpu-pixman.h" #include "hw/qdev-properties.h" =20 +static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp) +{ + virtio_gpu_virgl_device_realize(qdev, errp); +} + static Property virtio_gpu_gl_properties[] =3D { DEFINE_PROP_BIT("stats", VirtIOGPU, parent_obj.conf.flags, VIRTIO_GPU_FLAG_STATS_ENABLED, false), @@ -34,13 +39,13 @@ static void virtio_gpu_gl_class_init(ObjectClass *klass= , void *data) VirtIOGPUBaseClass *vbc =3D VIRTIO_GPU_BASE_CLASS(klass); VirtIOGPUClass *vgc =3D VIRTIO_GPU_CLASS(klass); =20 - vbc->gl_flushed =3D virtio_gpu_virgl_flushed; - vgc->handle_ctrl =3D virtio_gpu_virgl_handle_ctrl; - vgc->process_cmd =3D virtio_gpu_virgl_process_cmd; - vgc->update_cursor_data =3D virtio_gpu_virgl_update_cursor; + vbc->gl_flushed =3D NULL; + vgc->handle_ctrl =3D NULL; + vgc->process_cmd =3D NULL; + vgc->update_cursor_data =3D NULL; =20 - vdc->realize =3D virtio_gpu_virgl_device_realize; - vdc->reset =3D virtio_gpu_virgl_reset; + vdc->realize =3D virtio_gpu_gl_device_realize; + vdc->reset =3D NULL; device_class_set_props(dc, virtio_gpu_gl_properties); } =20 diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c index 87eccb2b97..5be288562d 100644 --- a/hw/display/virtio-gpu-virgl.c +++ b/hw/display/virtio-gpu-virgl.c @@ -401,8 +401,9 @@ static void virgl_cmd_get_capset(VirtIOGPU *g, g_free(resp); } =20 -void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, - struct virtio_gpu_ctrl_command *cmd) +static void +virtio_gpu_virgl_process_cmd(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) { VIRTIO_GPU_FILL_CMD(cmd->cmd_hdr); =20 @@ -637,7 +638,7 @@ static int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *= g) return capset2_max_ver ? 2 : 1; } =20 -void +static void virtio_gpu_virgl_update_cursor(VirtIOGPU *g, struct virtio_gpu_scanout *s, uint32_t resource_id) @@ -661,14 +662,14 @@ virtio_gpu_virgl_update_cursor(VirtIOGPU *g, free(data); } =20 -void virtio_gpu_virgl_flushed(VirtIOGPUBase *b) +static void virtio_gpu_virgl_flushed(VirtIOGPUBase *b) { VirtIOGPU *g =3D VIRTIO_GPU(b); =20 virtio_gpu_process_cmdq(g); } =20 -void virtio_gpu_virgl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) +static void virtio_gpu_virgl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) { VirtIOGPU *g =3D VIRTIO_GPU(vdev); VirtIOGPUGL *gl =3D VIRTIO_GPU_GL(vdev); @@ -700,7 +701,7 @@ void virtio_gpu_virgl_handle_ctrl(VirtIODevice *vdev, V= irtQueue *vq) virtio_gpu_virgl_fence_poll(g); } =20 -void virtio_gpu_virgl_reset(VirtIODevice *vdev) +static void virtio_gpu_virgl_reset(VirtIODevice *vdev) { VirtIOGPU *g =3D VIRTIO_GPU(vdev); VirtIOGPUGL *gl =3D VIRTIO_GPU_GL(vdev); @@ -719,7 +720,21 @@ void virtio_gpu_virgl_reset(VirtIODevice *vdev) =20 void virtio_gpu_virgl_device_realize(DeviceState *qdev, Error **errp) { - VirtIOGPU *g =3D VIRTIO_GPU(qdev); + VirtIODevice *vdev =3D VIRTIO_DEVICE(qdev); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); + + VirtIOGPUBase *bdev =3D VIRTIO_GPU_BASE(qdev); + VirtIOGPUBaseClass *vbc =3D VIRTIO_GPU_BASE_GET_CLASS(bdev); + + VirtIOGPU *gpudev =3D VIRTIO_GPU(qdev); + VirtIOGPUClass *vgc =3D VIRTIO_GPU_GET_CLASS(gpudev); + + vbc->gl_flushed =3D virtio_gpu_virgl_flushed; + vgc->handle_ctrl =3D virtio_gpu_virgl_handle_ctrl; + vgc->process_cmd =3D virtio_gpu_virgl_process_cmd; + vgc->update_cursor_data =3D virtio_gpu_virgl_update_cursor; + + vdc->reset =3D virtio_gpu_virgl_reset; =20 #if HOST_BIG_ENDIAN error_setg(errp, "virgl is not supported on bigendian platforms"); @@ -737,9 +752,9 @@ void virtio_gpu_virgl_device_realize(DeviceState *qdev,= Error **errp) return; } =20 - g->parent_obj.conf.flags |=3D (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED); - VIRTIO_GPU_BASE(g)->virtio_config.num_capsets =3D - virtio_gpu_virgl_get_num_capsets(g); + gpudev->parent_obj.conf.flags |=3D (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED= ); + VIRTIO_GPU_BASE(gpudev)->virtio_config.num_capsets =3D + virtio_gpu_virgl_get_num_capsets(gpudev); =20 virtio_gpu_device_realize(qdev, errp); } diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 7317b60004..421733d751 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -293,13 +293,6 @@ int virtio_gpu_update_dmabuf(VirtIOGPU *g, struct virtio_gpu_rect *r); =20 /* virtio-gpu-3d.c */ -void virtio_gpu_virgl_process_cmd(VirtIOGPU *g, - struct virtio_gpu_ctrl_command *cmd); -void virtio_gpu_virgl_update_cursor(VirtIOGPU *g, struct virtio_gpu_scanou= t *s, - uint32_t resource_id); -void virtio_gpu_virgl_flushed(VirtIOGPUBase *b); -void virtio_gpu_virgl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq); -void virtio_gpu_virgl_reset(VirtIODevice *vdev); void virtio_gpu_virgl_device_realize(DeviceState *qdev, Error **errp); =20 #endif --=20 2.40.0.634.g4ca3ef3211-goog From nobody Thu May 9 23:03:11 2024 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=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1682039685; cv=none; d=zohomail.com; s=zohoarc; b=EXjc6ZwYVggaCgLwx6M3ogrFnrOgeZDQghU20khbX4HzFRHyFFmxVj9jP+IhZoASX8naX1DCn6ltHHEXdr9T4oVAZFM6YDZB6yoBNwXo1O+6umzQbWnbCQenqSmw7PSoxFkSaPy8ex+WEBJMo704BNwK0OfVQPPamn7zKqJNxGw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682039685; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=eJb6pN/TSibQ3w1Gl1G/ulXh2/oAF2ihyHqUQmiUUD0=; b=h9s2+QvInUBYuq1iM0JD4aR1NflHMug7Bt7xUnpQRr5Ge65Ie8vP6AyHdmA9rYD+eoCt7QzOt+sEUrMGYC7vt5XwoyCCIgkfntQr0rAT49Do61uePTUE+Vq1FVOjan9G/I+D7hgXo8oiAFdqMRGk2MUjGXJH2TAzm1JUgLHd0hQ= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168203968570086.25354169013383; Thu, 20 Apr 2023 18:14:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppfKi-0002gn-5X; Thu, 20 Apr 2023 21:13:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppfKN-0002ca-F0 for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:43 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppfKL-0008N3-7w for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:42 -0400 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-51f6461af24so1299482a12.2 for ; Thu, 20 Apr 2023 18:12:40 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:a7:2:6625:6aa3:1b0e:a808]) by smtp.gmail.com with ESMTPSA id f4-20020a17090a8e8400b0024702e7c80fsm1697640pjo.23.2023.04.20.18.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 18:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682039560; x=1684631560; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eJb6pN/TSibQ3w1Gl1G/ulXh2/oAF2ihyHqUQmiUUD0=; b=VtdBXoNf8EXAu1hTUwSTT7qAZlfwyqfi/0r3FOiQ1W/GrawKUDmWUNYvdoOCg3P/pF +yUxs4GO9pLcj/cJu7APeqRGtUGmrnSvgzHXdpW4Z0Y92N0Vp0jkyUYP3pqISKqupoqJ /FHyDSYk2QpqIyWTNPZ8TFkAyZA5thCLnKIyI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682039560; x=1684631560; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eJb6pN/TSibQ3w1Gl1G/ulXh2/oAF2ihyHqUQmiUUD0=; b=R9XSKCY60VYRHT5cI/fzJkOxrNPX8CV1djC82P80ndmaXU8XPyztWBAlzseQ1w4p5k kS5q48GETd5dzw51W+0udc5E5l95KMsrpNusZSlMBktaQ+6SOmYTeKyZJBUmJNxHAsLl ziiQ8VtJO+5cbmjKJslpz5UUrT7b9vx+q844GpvwjxzRVsdOZ3dTbD2e29pLua391PCW b+lfIZ2TYE1Z5vkPCLMgWDwndlvHM9J/SvI7fsKhwSWnh6DVeUha+SYtPvi54G6rx3C+ 7cJyNWAXPjKBHixxPtVrOJsH3d0EX+TgjKZAK69K8zFTDFsWW37/XEhoHwLCqupw92WP lljQ== X-Gm-Message-State: AAQBX9erJP0e6K17fsvK0BY6Z+Uwyxxs67NkN1H0UmFoTa/52azHJF+z kniWpOhsQ4kzr5IkeFrWOXGmpF77PL4c5qsFI7X3tnm0 X-Google-Smtp-Source: AKy350a/e9I+LS6fyYFFJ3otd43DyvHG+K9NAIAjBTellfF4f7dvlydBRcVjX1w0D7kz/4nYvDmLUQ== X-Received: by 2002:a17:90a:8993:b0:246:af1f:62ef with SMTP id v19-20020a17090a899300b00246af1f62efmr3322365pjn.5.1682039559817; Thu, 20 Apr 2023 18:12:39 -0700 (PDT) From: Gurchetan Singh To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, david@redhat.com, stefanha@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, akihiko.odaki@gmail.com, dmitry.osipenko@collabora.com, ray.huang@amd.com, alex.bennee@linaro.org Subject: [RFC PATCH 08/13] gfxstream + rutabaga prep: added need defintions, fields, and options Date: Thu, 20 Apr 2023 18:12:18 -0700 Message-Id: <20230421011223.718-9-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230421011223.718-1-gurchetansingh@chromium.org> References: <20230421011223.718-1-gurchetansingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52d; envelope-from=gurchetansingh@chromium.org; helo=mail-pg1-x52d.google.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @chromium.org) X-ZM-MESSAGEID: 1682039687163100001 Content-Type: text/plain; charset="utf-8" This modifies the common virtio-gpu.h file have the fields and defintions needed by gfxstream/rutabaga. It also modifies VirtioGPUGL to have the runtime options needed by rutabaga. They are: - a colon separated list of capset names, defined in the virtio spec - a wayland socket path to enable guest Wayland passthrough The command to run these would be: -device virtio-vga-gl,capset_names=3Dgfxstream:cross-domain, \ wayland_socket_path=3D/run/user/1000/wayland-0,hostmem=3D8G \ Signed-off-by: Gurchetan Singh --- hw/display/virtio-gpu-gl.c | 2 ++ include/hw/virtio/virtio-gpu.h | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c index 547e697333..15270b0c8a 100644 --- a/hw/display/virtio-gpu-gl.c +++ b/hw/display/virtio-gpu-gl.c @@ -29,6 +29,8 @@ static void virtio_gpu_gl_device_realize(DeviceState *qde= v, Error **errp) static Property virtio_gpu_gl_properties[] =3D { DEFINE_PROP_BIT("stats", VirtIOGPU, parent_obj.conf.flags, VIRTIO_GPU_FLAG_STATS_ENABLED, false), + DEFINE_PROP_STRING("capset_names", VirtIOGPUGL, capset_names), + DEFINE_PROP_STRING("wayland_socket_path", VirtIOGPUGL, wayland_socket_= path), DEFINE_PROP_END_OF_LIST(), }; =20 diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 421733d751..a35ade3608 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -94,6 +94,7 @@ enum virtio_gpu_base_conf_flags { VIRTIO_GPU_FLAG_DMABUF_ENABLED, VIRTIO_GPU_FLAG_BLOB_ENABLED, VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED, + VIRTIO_GPU_FLAG_RUTABAGA_ENABLED, }; =20 #define virtio_gpu_virgl_enabled(_cfg) \ @@ -106,6 +107,8 @@ enum virtio_gpu_base_conf_flags { (_cfg.flags & (1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED)) #define virtio_gpu_blob_enabled(_cfg) \ (_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED)) +#define virtio_gpu_rutabaga_enabled(_cfg) \ + (_cfg.flags & (1 << VIRTIO_GPU_FLAG_RUTABAGA_ENABLED)) #define virtio_gpu_hostmem_enabled(_cfg) \ (_cfg.hostmem > 0) #define virtio_gpu_context_init_enabled(_cfg) \ @@ -217,6 +220,11 @@ struct VirtIOGPUGL { =20 bool renderer_inited; bool renderer_reset; + + char *capset_names; + char *wayland_socket_path; + uint32_t num_capsets; + void *rutabaga; }; =20 struct VhostUserGPU { --=20 2.40.0.634.g4ca3ef3211-goog From nobody Thu May 9 23:03:11 2024 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=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1682039677; cv=none; d=zohomail.com; s=zohoarc; b=aJkmlxesvxZPKvZp+OurRVB7038G9f28Wqp4bMvkYvlnokaMKLStBnbTJGn1M50u+KaIfftXwDKTwg5D+djwKN0iAl2EQzkl+38ghW5kb4VnGLdaGsTM/P/a1+9yNqWps8r+Q1CcECJlapnMUS/9OvjnE116Xfsag8sgttoi9OQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682039677; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LXY0t1sdRfO0Bja7CZEHyKYHZekZSXUgtaYjb6Qv2vI=; b=RGaIAGnetHuXRS163aEHtbFbhEe8ay2GCaxBgghp1+sIOi9EnNm3lyPcDshuolZPsYstpNLl3fZkYk4Nb6lvb1qm6RtrIMguhLdL4PHuLueDGtvcBLVGy0dgLFstI393lGGtaEjtpebbljeq3nprm+2CfCQiVPhNiy72CMyALx0= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682039677652950.9991597863346; Thu, 20 Apr 2023 18:14:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppfKU-0002dX-6p; Thu, 20 Apr 2023 21:12:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppfKP-0002dE-Hn for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:45 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppfKN-0008Ng-7s for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:45 -0400 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-5144a9c11c7so1666207a12.2 for ; Thu, 20 Apr 2023 18:12:42 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:a7:2:6625:6aa3:1b0e:a808]) by smtp.gmail.com with ESMTPSA id f4-20020a17090a8e8400b0024702e7c80fsm1697640pjo.23.2023.04.20.18.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 18:12:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682039561; x=1684631561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LXY0t1sdRfO0Bja7CZEHyKYHZekZSXUgtaYjb6Qv2vI=; b=ai+yC73xbN5y2mUbJlOWqdztP4eW4XSWJT2GgEuUC+6O7WRTdZjUg3OvTCmq8ytRb3 f7bMYZsDXvt1YZQLNaBSct62MGppKmy3idFly2lC+5sO62LTkObcAWiGSBiQRbBwnai9 DXqkhWZnlEr4gPMmHu5nt2Lf+Nc+40udrVyQs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682039561; x=1684631561; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LXY0t1sdRfO0Bja7CZEHyKYHZekZSXUgtaYjb6Qv2vI=; b=FEYslvAbkyQUfXKnCZ/Gev87RmzF0C4yzgchDCszCpgvG3/Sg1tbRxKVoo9ryrf3JH gPdneZ+WSo2k7ITh6i8DjUyDDdqQHn2IPg+pGjTvHsRRyVy8XkAgVlKnirtI+Fzhz9CP pMjD10vqgGJpdvvga9PeKSOHwN49I7T0q0fbzLqyco5ZCL0fGobEbtN0k3Xp/zeA1jlc LPa/UamN3pa9FoC/lNHOy7sFLq5GaKT05rJCxiyt8RCJyCL5+U0a2AdNR6MSD2ALPtpj B7Q1DvrDEzEYFAKkCNzzuEsHVuEBEd6eC83ZG61RFvaPVnFr3EY68zted/7fP0Th6MuN 9Ofw== X-Gm-Message-State: AAQBX9c/k79SjrU64D0OmslkweQ+7cYMsr3l8FPNCkp07w+26kGqvQoT BEQkv9n/0WRLh1qAeNmQpHvUtSx6TGpRgclsBRO0aSK4 X-Google-Smtp-Source: AKy350b+atDUBAxIDdBUYZ8B5o+vmCDS071Zv2Ga7c8hBBFQkegilFV3f5SW9Oyvj70V2x2Zlf9//A== X-Received: by 2002:a17:90a:5509:b0:247:a272:71d1 with SMTP id b9-20020a17090a550900b00247a27271d1mr3471120pji.7.1682039561419; Thu, 20 Apr 2023 18:12:41 -0700 (PDT) From: Gurchetan Singh To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, david@redhat.com, stefanha@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, akihiko.odaki@gmail.com, dmitry.osipenko@collabora.com, ray.huang@amd.com, alex.bennee@linaro.org Subject: [RFC PATCH 09/13] gfxstream + rutabaga: add required meson changes Date: Thu, 20 Apr 2023 18:12:19 -0700 Message-Id: <20230421011223.718-10-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230421011223.718-1-gurchetansingh@chromium.org> References: <20230421011223.718-1-gurchetansingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=gurchetansingh@chromium.org; helo=mail-pg1-x52b.google.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @chromium.org) X-ZM-MESSAGEID: 1682039679416100002 Content-Type: text/plain; charset="utf-8" - Add meson detection of rutabaga_gfx - Compile stubs when rutabaga_gfx_ffi is not installed - Compile stubs when virglrenderer is not installed Signed-off-by: Gurchetan Singh --- hw/display/meson.build | 40 ++++++++++++++++++++------ hw/display/virtio-gpu-rutabaga-stubs.c | 8 ++++++ hw/display/virtio-gpu-virgl-stubs.c | 8 ++++++ include/hw/virtio/virtio-gpu.h | 5 +++- meson.build | 8 ++++++ meson_options.txt | 2 ++ scripts/meson-buildoptions.sh | 3 ++ 7 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 hw/display/virtio-gpu-rutabaga-stubs.c create mode 100644 hw/display/virtio-gpu-virgl-stubs.c diff --git a/hw/display/meson.build b/hw/display/meson.build index 4191694380..48785cfcb6 100644 --- a/hw/display/meson.build +++ b/hw/display/meson.build @@ -63,6 +63,8 @@ softmmu_ss.add(when: 'CONFIG_ARTIST', if_true: files('art= ist.c')) =20 softmmu_ss.add(when: [pixman, 'CONFIG_ATI_VGA'], if_true: files('ati.c', '= ati_2d.c', 'ati_dbg.c')) =20 +virgl_found =3D virgl.found() and opengl.found() +rutabaga_found =3D rutabaga.found() =20 if config_all_devices.has_key('CONFIG_VIRTIO_GPU') virtio_gpu_ss =3D ss.source_set() @@ -73,12 +75,27 @@ if config_all_devices.has_key('CONFIG_VIRTIO_GPU') virtio_gpu_ss.add(when: 'CONFIG_VHOST_USER_GPU', if_true: files('vhost-u= ser-gpu.c')) hw_display_modules +=3D {'virtio-gpu': virtio_gpu_ss} =20 - if virgl.found() and opengl.found() - virtio_gpu_gl_ss =3D ss.source_set() - virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', virgl, opengl], - if_true: [files('virtio-gpu-gl.c', 'virtio-gpu-vi= rgl.c'), pixman, virgl]) - hw_display_modules +=3D {'virtio-gpu-gl': virtio_gpu_gl_ss} + virtio_gpu_gl_ss =3D ss.source_set() + if virgl_found or rutabaga_found + virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU'], + if_true: [files('virtio-gpu-gl.c'), pixman]) endif + + if virgl_found + virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU'], + if_true: [files('virtio-gpu-virgl.c'), virgl]) + else + virtio_gpu_gl_ss.add([files('virtio-gpu-virgl-stubs.c')]) + endif + + if rutabaga_found + virtio_gpu_gl_ss.add(when: ['CONFIG_VIRTIO_GPU'], + if_true: [files('virtio-gpu-rutabaga.c'), rutabag= a]) + else + virtio_gpu_gl_ss.add([files('virtio-gpu-rutabaga-stubs.c')]) + endif + + hw_display_modules +=3D {'virtio-gpu-gl': virtio_gpu_gl_ss} endif =20 if config_all_devices.has_key('CONFIG_VIRTIO_PCI') @@ -89,9 +106,10 @@ if config_all_devices.has_key('CONFIG_VIRTIO_PCI') if_true: files('vhost-user-gpu-pci.c')) hw_display_modules +=3D {'virtio-gpu-pci': virtio_gpu_pci_ss} =20 - if virgl.found() and opengl.found() + + if virgl_found or rutabaga_found virtio_gpu_pci_gl_ss =3D ss.source_set() - virtio_gpu_pci_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRTIO_PC= I', virgl, opengl], + virtio_gpu_pci_gl_ss.add(when: ['CONFIG_VIRTIO_GPU', 'CONFIG_VIRTIO_PC= I'], if_true: [files('virtio-gpu-pci-gl.c'), pixma= n]) hw_display_modules +=3D {'virtio-gpu-pci-gl': virtio_gpu_pci_gl_ss} endif @@ -108,8 +126,12 @@ if config_all_devices.has_key('CONFIG_VIRTIO_VGA') hw_display_modules +=3D {'virtio-vga': virtio_vga_ss} =20 virtio_vga_gl_ss =3D ss.source_set() - virtio_vga_gl_ss.add(when: ['CONFIG_VIRTIO_VGA', virgl, opengl], - if_true: [files('virtio-vga-gl.c'), pixman]) + + if virgl_found or rutabaga_found + virtio_vga_gl_ss.add(when: ['CONFIG_VIRTIO_VGA'], + if_true: [files('virtio-vga-gl.c'), pixman]) + endif + virtio_vga_gl_ss.add(when: 'CONFIG_ACPI', if_true: files('acpi-vga.c'), if_false: files('acpi-vga-stub= .c')) hw_display_modules +=3D {'virtio-vga-gl': virtio_vga_gl_ss} diff --git a/hw/display/virtio-gpu-rutabaga-stubs.c b/hw/display/virtio-gpu= -rutabaga-stubs.c new file mode 100644 index 0000000000..26c38d3892 --- /dev/null +++ b/hw/display/virtio-gpu-rutabaga-stubs.c @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "qemu/osdep.h" +#include "hw/virtio/virtio-gpu.h" + +void virtio_gpu_rutabaga_device_realize(DeviceState *qdev, Error **errp) +{ + /* nothing (stub) */ +} diff --git a/hw/display/virtio-gpu-virgl-stubs.c b/hw/display/virtio-gpu-vi= rgl-stubs.c new file mode 100644 index 0000000000..b29e35f990 --- /dev/null +++ b/hw/display/virtio-gpu-virgl-stubs.c @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "qemu/osdep.h" +#include "hw/virtio/virtio-gpu.h" + +void virtio_gpu_virgl_device_realize(DeviceState *qdev, Error **errp) +{ + /* nothing (stub) */ +} diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index a35ade3608..034c71e8f5 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -300,7 +300,10 @@ int virtio_gpu_update_dmabuf(VirtIOGPU *g, struct virtio_gpu_framebuffer *fb, struct virtio_gpu_rect *r); =20 -/* virtio-gpu-3d.c */ +/* virtio-gpu-virgl.c or virtio-gpu-virgl-stubs.c */ void virtio_gpu_virgl_device_realize(DeviceState *qdev, Error **errp); +/* virtio-gpu-rutabaga.c or virtio-gpu-rutabaga-stubs.c */ +void virtio_gpu_rutabaga_device_realize(DeviceState *qdev, Error **errp); + =20 #endif diff --git a/meson.build b/meson.build index c44d05a13f..ba1c1905fb 100644 --- a/meson.build +++ b/meson.build @@ -777,6 +777,13 @@ if not get_option('virglrenderer').auto() or have_syst= em or have_vhost_user_gpu required: get_option('virglrenderer'), kwargs: static_kwargs) endif +rutabaga =3D not_found +if not get_option('rutabaga_gfx').auto() or have_system or have_vhost_user= _gpu + rutabaga =3D dependency('rutabaga_gfx_ffi', + method: 'pkg-config', + required: get_option('rutabaga_gfx'), + kwargs: static_kwargs) +endif blkio =3D not_found if not get_option('blkio').auto() or have_block blkio =3D dependency('blkio', @@ -3963,6 +3970,7 @@ summary_info +=3D {'PAM': pam} summary_info +=3D {'iconv support': iconv} summary_info +=3D {'curses support': curses} summary_info +=3D {'virgl support': virgl} +summary_info +=3D {'rutabaga support': rutabaga} summary_info +=3D {'blkio support': blkio} summary_info +=3D {'curl support': curl} summary_info +=3D {'Multipath support': mpathpersist} diff --git a/meson_options.txt b/meson_options.txt index fc9447d267..3b4249c2fe 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -213,6 +213,8 @@ option('vmnet', type : 'feature', value : 'auto', description: 'vmnet.framework network backend support') option('virglrenderer', type : 'feature', value : 'auto', description: 'virgl rendering support') +option('rutabaga_gfx', type : 'feature', value : 'auto', + description: 'rutabaga_gfx support') option('png', type : 'feature', value : 'auto', description: 'PNG support with libpng') option('vnc', type : 'feature', value : 'auto', diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh index 009fab1515..ce35c44926 100644 --- a/scripts/meson-buildoptions.sh +++ b/scripts/meson-buildoptions.sh @@ -144,6 +144,7 @@ meson_options_help() { printf "%s\n" ' rbd Ceph block device driver' printf "%s\n" ' rdma Enable RDMA-based migration' printf "%s\n" ' replication replication support' + printf "%s\n" ' rutabaga-gfx rutabaga_gfx support' printf "%s\n" ' sdl SDL user interface' printf "%s\n" ' sdl-image SDL Image support for icons' printf "%s\n" ' seccomp seccomp support' @@ -394,6 +395,8 @@ _meson_option_parse() { --disable-replication) printf "%s" -Dreplication=3Ddisabled ;; --enable-rng-none) printf "%s" -Drng_none=3Dtrue ;; --disable-rng-none) printf "%s" -Drng_none=3Dfalse ;; + --enable-rutabaga-gfx) printf "%s" -Drutabaga_gfx=3Denabled ;; + --disable-rutabaga-gfx) printf "%s" -Drutabaga_gfx=3Ddisabled ;; --enable-sdl) printf "%s" -Dsdl=3Denabled ;; --disable-sdl) printf "%s" -Dsdl=3Ddisabled ;; --enable-sdl-image) printf "%s" -Dsdl_image=3Denabled ;; --=20 2.40.0.634.g4ca3ef3211-goog From nobody Thu May 9 23:03:11 2024 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=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1682039650; cv=none; d=zohomail.com; s=zohoarc; b=Axcbo8g6/fggX4xpUCr/gC0FNRf5zo92vZs3FvCPm0Ix+FU8RpKiLIid/IfIRA82hfTSwd2HQAz40+QWWjc3lOzTO2RFXnnGi9/lSCumG9gSE7ZpD1ZBo02t5FP+EGDcILYnJ6tdgUg/oBLsKwZAQmdACqyC0fwZY8DJZHEi5Rw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682039650; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Vuw10pNJG6y0MSJhqNR8kgs+tYikNhByjEVnGHt0010=; b=iK98FrL5ATzRtv+ysmYyBqO77ZxsxZ0x5hOswWV583yIPRKQBmDZ71zF8wxJBaqGayYowZTaA8gSL9R4WAksykwLYwrlzouUPA2FOVymAGQ35e6KQAVAwEzNYK2eCN3PJX+P5JN9C0rOvnEFOUvh/rAG9189EIeC2590B18Jrl4= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682039650751957.4575715292165; Thu, 20 Apr 2023 18:14:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppfKj-0002gq-Bh; Thu, 20 Apr 2023 21:13:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppfKU-0002dY-0Z for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:50 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppfKP-0008Nz-Ai for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:49 -0400 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-246fdb97191so1165355a91.0 for ; Thu, 20 Apr 2023 18:12:44 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:a7:2:6625:6aa3:1b0e:a808]) by smtp.gmail.com with ESMTPSA id f4-20020a17090a8e8400b0024702e7c80fsm1697640pjo.23.2023.04.20.18.12.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 18:12:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682039563; x=1684631563; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Vuw10pNJG6y0MSJhqNR8kgs+tYikNhByjEVnGHt0010=; b=UrXNBp3rG2cMz6COA1f3td284cz5+C6eBm5WedAuzrGulgWfPXhtKKsz8pANrN4It/ y70JTcFG9nn0kgKOrup7P7QZhf9c0gEbQZasArtGj9PWG4tgn1l4vjw0WPWkVXZDBICp QCTA0qyG+fH7UcQPB+eG6TNX1nWJbYsjt0qQ4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682039563; x=1684631563; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vuw10pNJG6y0MSJhqNR8kgs+tYikNhByjEVnGHt0010=; b=R9qMjYrTei0NOT9/knMdo6G2OUIjcq4hL9lpk/9IF01m9YVmV+VdrtUOk1/sIzE0bC XA2fzw9NHVBSMtOIpPDkU75dBik/XgP9B6jfvdCIOoD1rtPID1rsdGTXLtALWzhXsrSv GxEhG9S0/RpFb9T9/sNfLcLT0rcdIzf20HRNdKj72dLIIwhFTg3HCYdaa6kFjItc03j+ ssgdwR72srbSqT97kLQ24E62ac8LEtQ3xq0eBEJTAJqScnUssjdtbVMfMvUA5cjVdBH6 Y4lo2+YFBep833maYvEJN96UyK8Kd5ON660ba9Id4YuntFcKX6ERe8hecBxcqUECsjm3 fhDQ== X-Gm-Message-State: AAQBX9cpcDyQEdoHfAe7EmNKKMTXUEJ6g6BradoJ411sqrfgW95q2SGg 1iwwhXpPsAUT88pE5j0goGUm+RoMMIdCLld0J1fiDmAD X-Google-Smtp-Source: AKy350atzKow00WNVZdaxISZst3VT4MU5gcF615MYcKggmeWLDlncFP7P5uFxwg6/0zeYzZzspBvOA== X-Received: by 2002:a17:90a:2e17:b0:244:9227:5eca with SMTP id q23-20020a17090a2e1700b0024492275ecamr2942648pjd.49.1682039562973; Thu, 20 Apr 2023 18:12:42 -0700 (PDT) From: Gurchetan Singh To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, david@redhat.com, stefanha@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, akihiko.odaki@gmail.com, dmitry.osipenko@collabora.com, ray.huang@amd.com, alex.bennee@linaro.org Subject: [RFC PATCH 10/13] gfxstream + rutabaga: add initial support for gfxstream Date: Thu, 20 Apr 2023 18:12:20 -0700 Message-Id: <20230421011223.718-11-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230421011223.718-1-gurchetansingh@chromium.org> References: <20230421011223.718-1-gurchetansingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=gurchetansingh@chromium.org; helo=mail-pj1-x1029.google.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @chromium.org) X-ZM-MESSAGEID: 1682039651334100001 Content-Type: text/plain; charset="utf-8" This adds initial support for gfxstream and cross-domain. Both features rely on virtio-gpu blob resources and context types, which are also implemented in this patch. gfxstream has a long and illustrious history in Android graphics paravirtualization. It has been powering graphics in the Android Studio Emulator for more than a decade, which is the main developer platform. Originally conceived by Jesse Hall, it was first known as "EmuGL" [a]. The key design characteristic was a 1:1 threading model and auto-generation, which fit nicely with the OpenGLES spec. It also allowed easy layering with ANGLE on the host, which provides the GLES implementations on Windows or MacOS enviroments. gfxstream has traditionally been maintained by a single engineer, and between 2015 to 2021, the iron throne passed to Frank Yang. Just to name a few accomplishments in a reign filled with many of them: newer versions of GLES, address space graphics, snapshot support and CTS compliant Vulkan [b]. One major drawback was the use of out-of-tree goldfish drivers. Android engineers didn't know much about DRM/KMS and especially TTM so a simple guest to host pipe was conceived. Luckily, virtio-gpu 3D started to emerge in 2016 due to the work of the Mesa/virglrenderer communities. In 2018, the initial virtio-gpu port of gfxstream was done by Cuttlefish enthusiast Alistair Delva. It was a symbol compatible replacement of virglrenderer [c] and named "AVDVirglrenderer". This implementation forms the basis of the current gfxstream host implementation still in use today. cross-domain support follows a similar arc. Originally conceived by Wayland aficionado David Reveman and crosvm enjoyer Zach Reizner in 2018, it initially relied on the downstream "virtio-wl" device. In 2020 and 2021, virtio-gpu was extended to include blob resources and multiple timelines by yours truly, features gfxstream/cross-domain both require to function correctly. Right now, we stand at the precipice of a truly fantastic possibility: the Android Emulator powered by upstream QEMU and upstream Linux kernel. gfxstream will then be packaged properfully, and app developers can even fix gfxstream bugs on their own if they encounter them. It's been quite the ride, my friends. Where will gfxstream head next, nobody really knows. I wouldn't be surprised if it's around for another decade, maintained by a new generation of Android graphics enthusiasts. One thing is for sure, though -- it'll be filled with friendship and magic! Technical details: - Very simple initial display integration: just used Pixman - Largely, 1:1 mapping of virtio-gpu hypercalls to rutabaga function calls [a] https://android-review.googlesource.com/c/platform/development/+/34470 [b] https://android-review.googlesource.com/q/topic:%22vulkan-hostconnectio= n-start%22 [c] https://android-review.googlesource.com/c/device/generic/goldfish-openg= l/+/761927 Signed-off-by: Gurchetan Singh --- hw/display/virtio-gpu-rutabaga.c | 995 +++++++++++++++++++++++++++++++ 1 file changed, 995 insertions(+) create mode 100644 hw/display/virtio-gpu-rutabaga.c diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutab= aga.c new file mode 100644 index 0000000000..5fd1154198 --- /dev/null +++ b/hw/display/virtio-gpu-rutabaga.c @@ -0,0 +1,995 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qemu/iov.h" +#include "trace.h" +#include "hw/virtio/virtio.h" +#include "hw/virtio/virtio-gpu.h" +#include "hw/virtio/virtio-gpu-pixman.h" +#include "hw/virtio/virtio-iommu.h" + +#include + +static int virtio_gpu_rutabaga_init(VirtIOGPU *g); + +#define GET_VIRTIO_GPU_GL(x) = \ + VirtIOGPUGL *virtio_gpu =3D VIRTIO_GPU_GL(x); = \ + +#define GET_RUTABAGA(x) = \ + struct rutabaga *rutabaga =3D (struct rutabaga *)(x->rutabaga); = \ + +#define CHECK(condition, cmd) = \ + do { = \ + if (!condition) { = \ + qemu_log_mask(LOG_GUEST_ERROR, "CHECK_RESULT failed in %s() %s= :" \ + "%d\n", __func__, __FILE__, __LINE__); = \ + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; = \ + return; = \ + } = \ + } while (0) + +#define CHECK_RESULT(result, cmd) CHECK(result =3D=3D 0, cmd) + +static void +virtio_gpu_rutabaga_update_cursor(VirtIOGPU *g, struct virtio_gpu_scanout = *s, + uint32_t resource_id) +{ + struct virtio_gpu_simple_resource *res; + struct rutabaga_transfer transfer =3D { 0 }; + struct iovec transfer_iovec; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + res =3D virtio_gpu_find_resource(g, resource_id); + if (!res) { + return; + } + + if (res->width !=3D s->current_cursor->width || + res->height !=3D s->current_cursor->height) { + return; + } + + transfer.x =3D 0; + transfer.y =3D 0; + transfer.z =3D 0; + transfer.w =3D res->width; + transfer.h =3D res->height; + transfer.d =3D 1; + + transfer_iovec.iov_base =3D (void *)s->current_cursor->data; + transfer_iovec.iov_len =3D res->width * res->height * 4; + + rutabaga_resource_transfer_read(rutabaga, 0, + resource_id, &transfer, + &transfer_iovec); +} + +static void +virtio_gpu_rutabaga_gl_flushed(VirtIOGPUBase *b) +{ + VirtIOGPU *g =3D VIRTIO_GPU(b); + virtio_gpu_process_cmdq(g); +} + +static void +rutabaga_cmd_create_resource_2d(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct rutabaga_create_3d rc_3d =3D { 0 }; + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_resource_create_2d c2d; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(c2d); + trace_virtio_gpu_cmd_res_create_2d(c2d.resource_id, c2d.format, + c2d.width, c2d.height); + + rc_3d.target =3D 2; + rc_3d.format =3D c2d.format; + rc_3d.bind =3D (1 << 1); + rc_3d.width =3D c2d.width; + rc_3d.height =3D c2d.height; + rc_3d.depth =3D 1; + rc_3d.array_size =3D 1; + rc_3d.last_level =3D 0; + rc_3d.nr_samples =3D 0; + rc_3d.flags =3D VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP; + + result =3D rutabaga_resource_create_3d(rutabaga, c2d.resource_id, &rc_= 3d); + CHECK_RESULT(result, cmd); + + 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; + + QTAILQ_INSERT_HEAD(&g->reslist, res, next); +} + +static void +rutabaga_cmd_create_resource_3d(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct rutabaga_create_3d rc_3d =3D { 0 }; + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_resource_create_3d c3d; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(c3d); + + trace_virtio_gpu_cmd_res_create_3d(c3d.resource_id, c3d.format, + c3d.width, c3d.height, c3d.depth); + + rc_3d.target =3D c3d.target; + rc_3d.format =3D c3d.format; + rc_3d.bind =3D c3d.bind; + rc_3d.width =3D c3d.width; + rc_3d.height =3D c3d.height; + rc_3d.depth =3D c3d.depth; + rc_3d.array_size =3D c3d.array_size; + rc_3d.last_level =3D c3d.last_level; + rc_3d.nr_samples =3D c3d.nr_samples; + rc_3d.flags =3D c3d.flags; + + result =3D rutabaga_resource_create_3d(rutabaga, c3d.resource_id, &rc_= 3d); + CHECK_RESULT(result, cmd); + + 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; + + QTAILQ_INSERT_HEAD(&g->reslist, res, next); +} + +static int32_t rutabaga_handle_unmap(VirtIOGPU *g, + struct virtio_gpu_simple_resource *re= s) +{ + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + res->mapped =3D NULL; + return rutabaga_resource_unmap(rutabaga, res->resource_id); +} + +static void +rutabaga_cmd_resource_unref(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_resource_unref unref; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(unref); + + trace_virtio_gpu_cmd_res_unref(unref.resource_id); + + res =3D virtio_gpu_find_resource(g, unref.resource_id); + CHECK(res, cmd); + + result =3D rutabaga_resource_unref(rutabaga, unref.resource_id); + CHECK_RESULT(result, cmd); + + if (res->image) { + pixman_image_unref(res->image); + } + + if (res->mapped) { + result =3D rutabaga_handle_unmap(g, res); + CHECK(result, cmd); + } + + QTAILQ_REMOVE(&g->reslist, res, next); + g_free(res); +} + +static void +rutabaga_cmd_context_create(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct virtio_gpu_ctx_create cc; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(cc); + trace_virtio_gpu_cmd_ctx_create(cc.hdr.ctx_id, + cc.debug_name); + + result =3D rutabaga_context_create(rutabaga, cc.hdr.ctx_id, cc.context= _init, + cc.debug_name, cc.nlen); + CHECK_RESULT(result, cmd); +} + +static void +rutabaga_cmd_context_destroy(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct virtio_gpu_ctx_destroy cd; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(cd); + trace_virtio_gpu_cmd_ctx_destroy(cd.hdr.ctx_id); + + result =3D rutabaga_context_destroy(rutabaga, cd.hdr.ctx_id); + CHECK_RESULT(result, cmd); +} + +static void +rutabaga_cmd_resource_flush(VirtIOGPU *g, struct virtio_gpu_ctrl_command *= cmd) +{ + int32_t result, i; + struct virtio_gpu_scanout *scanout =3D NULL; + struct virtio_gpu_simple_resource *res; + struct rutabaga_transfer transfer =3D { 0 }; + struct iovec transfer_iovec; + struct virtio_gpu_resource_flush rf; + bool found =3D false; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(rf); + trace_virtio_gpu_cmd_res_flush(rf.resource_id, + rf.r.width, rf.r.height, rf.r.x, rf.r.y= ); + + res =3D virtio_gpu_find_resource(g, rf.resource_id); + CHECK(res, cmd); + + for (i =3D 0; i < g->parent_obj.conf.max_outputs; i++) { + scanout =3D &g->parent_obj.scanout[i]; + if (i =3D=3D res->scanout_bitmask) { + found =3D true; + break; + } + } + + if (!found) { + return; + } + + transfer.x =3D 0; + transfer.y =3D 0; + transfer.z =3D 0; + transfer.w =3D res->width; + transfer.h =3D res->height; + transfer.d =3D 1; + + transfer_iovec.iov_base =3D (void *)pixman_image_get_data(res->image); + transfer_iovec.iov_len =3D res->width * res->height * 4; + + result =3D rutabaga_resource_transfer_read(rutabaga, 0, + rf.resource_id, &transfer, + &transfer_iovec); + CHECK_RESULT(result, cmd); + dpy_gfx_update_full(scanout->con); +} + +static void +rutabaga_cmd_set_scanout(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) +{ + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_scanout *scanout =3D NULL; + struct virtio_gpu_set_scanout ss; + + VIRTIO_GPU_FILL_CMD(ss); + trace_virtio_gpu_cmd_set_scanout(ss.scanout_id, ss.resource_id, + ss.r.width, ss.r.height, ss.r.x, ss.r= .y); + + scanout =3D &g->parent_obj.scanout[ss.scanout_id]; + g->parent_obj.enable =3D 1; + + res =3D virtio_gpu_find_resource(g, ss.resource_id); + CHECK(res, cmd); + + if (!res->image) { + pixman_format_code_t pformat; + pformat =3D virtio_gpu_get_pixman_format(res->format); + CHECK(pformat, cmd); + + res->image =3D pixman_image_create_bits(pformat, + res->width, + res->height, + NULL, 0); + CHECK(res->image, cmd); + pixman_image_ref(res->image); + } + + /* realloc the surface ptr */ + scanout->ds =3D qemu_create_displaysurface_pixman(res->image); + dpy_gfx_replace_surface(scanout->con, NULL); + dpy_gfx_replace_surface(scanout->con, scanout->ds); + res->scanout_bitmask =3D ss.scanout_id; +} + +static void +rutabaga_cmd_submit_3d(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct virtio_gpu_cmd_submit cs; + void *buf; + size_t s; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(cs); + trace_virtio_gpu_cmd_ctx_submit(cs.hdr.ctx_id, cs.size); + + buf =3D g_malloc(cs.size); + s =3D iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, + sizeof(cs), buf, cs.size); + if (s !=3D cs.size) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: size mismatch (%zd/%d)", + __func__, s, cs.size); + cmd->error =3D VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER; + goto out; + } + + result =3D rutabaga_submit_command(rutabaga, cs.hdr.ctx_id, buf, cs.si= ze); + CHECK_RESULT(result, cmd); + +out: + g_free(buf); +} + +static void +rutabaga_cmd_transfer_to_host_2d(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct rutabaga_transfer transfer =3D { 0 }; + struct virtio_gpu_transfer_to_host_2d t2d; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(t2d); + trace_virtio_gpu_cmd_res_xfer_toh_2d(t2d.resource_id); + + transfer.x =3D t2d.r.x; + transfer.y =3D t2d.r.y; + transfer.z =3D 0; + transfer.w =3D t2d.r.width; + transfer.h =3D t2d.r.height; + transfer.d =3D 1; + + result =3D rutabaga_resource_transfer_write(rutabaga, 0, t2d.resource_= id, + &transfer); + CHECK_RESULT(result, cmd); +} + +static void +rutabaga_cmd_transfer_to_host_3d(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct rutabaga_transfer transfer =3D { 0 }; + struct virtio_gpu_transfer_host_3d t3d; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(t3d); + trace_virtio_gpu_cmd_res_xfer_toh_3d(t3d.resource_id); + + transfer.x =3D t3d.box.x; + transfer.y =3D t3d.box.y; + transfer.z =3D t3d.box.z; + transfer.w =3D t3d.box.w; + transfer.h =3D t3d.box.h; + transfer.d =3D t3d.box.d; + transfer.level =3D t3d.level; + transfer.stride =3D t3d.stride; + transfer.layer_stride =3D t3d.layer_stride; + transfer.offset =3D t3d.offset; + + result =3D rutabaga_resource_transfer_write(rutabaga, t3d.hdr.ctx_id, + t3d.resource_id, &transfer); + CHECK_RESULT(result, cmd); +} + +static void +rutabaga_cmd_transfer_from_host_3d(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct rutabaga_transfer transfer =3D { 0 }; + struct virtio_gpu_transfer_host_3d t3d; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(t3d); + trace_virtio_gpu_cmd_res_xfer_fromh_3d(t3d.resource_id); + + transfer.x =3D t3d.box.x; + transfer.y =3D t3d.box.y; + transfer.z =3D t3d.box.z; + transfer.w =3D t3d.box.w; + transfer.h =3D t3d.box.h; + transfer.d =3D t3d.box.d; + transfer.level =3D t3d.level; + transfer.stride =3D t3d.stride; + transfer.layer_stride =3D t3d.layer_stride; + transfer.offset =3D t3d.offset; + + result =3D rutabaga_resource_transfer_read(rutabaga, t3d.hdr.ctx_id, + t3d.resource_id, &transfer, N= ULL); + CHECK_RESULT(result, cmd); +} + +static void +rutabaga_cmd_attach_backing(VirtIOGPU *g, struct virtio_gpu_ctrl_command *= cmd) +{ + struct rutabaga_iovecs vecs =3D { 0 }; + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_resource_attach_backing att_rb; + struct iovec *res_iovs; + uint32_t res_niov; + int ret; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(att_rb); + trace_virtio_gpu_cmd_res_back_attach(att_rb.resource_id); + + res =3D virtio_gpu_find_resource(g, att_rb.resource_id); + if (!res) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: illegal resource specified %d\= n", + __func__, att_rb.resource_id); + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + return; + } + + if (res->iov) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + return; + } + + ret =3D virtio_gpu_create_mapping_iov(g, att_rb.nr_entries, sizeof(att= _rb), + cmd, NULL, &res_iovs, &res_niov); + if (ret !=3D 0) { + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + return; + } + + vecs.iovecs =3D res_iovs; + vecs.num_iovecs =3D res_niov; + + ret =3D rutabaga_resource_attach_backing(rutabaga, att_rb.resource_id,= &vecs); + if (ret !=3D 0) { + virtio_gpu_cleanup_mapping_iov(g, res_iovs, res_niov); + } +} + +static void +rutabaga_cmd_detach_backing(VirtIOGPU *g, struct virtio_gpu_ctrl_command *= cmd) +{ + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_resource_detach_backing detach_rb; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(detach_rb); + trace_virtio_gpu_cmd_res_back_detach(detach_rb.resource_id); + + res =3D virtio_gpu_find_resource(g, detach_rb.resource_id); + CHECK(res, cmd); + + rutabaga_resource_detach_backing(rutabaga, + detach_rb.resource_id); + + virtio_gpu_cleanup_mapping(g, res); +} + +static void +rutabaga_cmd_ctx_attach_resource(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct virtio_gpu_ctx_resource att_res; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(att_res); + trace_virtio_gpu_cmd_ctx_res_attach(att_res.hdr.ctx_id, + att_res.resource_id); + + result =3D rutabaga_context_attach_resource(rutabaga, att_res.hdr.ctx_= id, + att_res.resource_id); + CHECK_RESULT(result, cmd); +} + +static void +rutabaga_cmd_ctx_detach_resource(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct virtio_gpu_ctx_resource det_res; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(det_res); + trace_virtio_gpu_cmd_ctx_res_detach(det_res.hdr.ctx_id, + det_res.resource_id); + + result =3D rutabaga_context_detach_resource(rutabaga, det_res.hdr.ctx_= id, + det_res.resource_id); + CHECK_RESULT(result, cmd); +} + +static void +rutabaga_cmd_get_capset_info(VirtIOGPU *g, struct virtio_gpu_ctrl_command = *cmd) +{ + int32_t result; + struct virtio_gpu_get_capset_info info; + struct virtio_gpu_resp_capset_info resp; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(info); + + result =3D rutabaga_get_capset_info(rutabaga, info.capset_index, + &resp.capset_id, &resp.capset_max_ve= rsion, + &resp.capset_max_size); + CHECK_RESULT(result, cmd); + + resp.hdr.type =3D VIRTIO_GPU_RESP_OK_CAPSET_INFO; + virtio_gpu_ctrl_response(g, cmd, &resp.hdr, sizeof(resp)); +} + +static void +rutabaga_cmd_get_capset(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct virtio_gpu_get_capset gc; + struct virtio_gpu_resp_capset *resp; + uint32_t capset_size; + uint32_t current_id; + bool found =3D false; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(gc); + for (uint32_t i =3D 0; i < virtio_gpu->num_capsets; i++) { + result =3D rutabaga_get_capset_info(rutabaga, i, + ¤t_id, &capset_size, + &capset_size); + CHECK_RESULT(result, cmd); + + if (current_id =3D=3D gc.capset_id) { + found =3D true; + break; + } + } + + if (!found) { + qemu_log_mask(LOG_GUEST_ERROR, "capset not found!"); + return; + } + + resp =3D g_malloc0(sizeof(*resp) + capset_size); + resp->hdr.type =3D VIRTIO_GPU_RESP_OK_CAPSET; + rutabaga_get_capset(rutabaga, gc.capset_id, gc.capset_version, + (uint8_t *)resp->capset_data, capset_size); + + virtio_gpu_ctrl_response(g, cmd, &resp->hdr, sizeof(*resp) + capset_si= ze); + g_free(resp); +} + +static void +rutabaga_cmd_resource_create_blob(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int result; + struct rutabaga_iovecs vecs =3D { 0 }; + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_resource_create_blob cblob; + struct rutabaga_create_blob rc_blob =3D { 0 }; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(cblob); + trace_virtio_gpu_cmd_res_create_blob(cblob.resource_id, cblob.size); + + CHECK(cblob.resource_id !=3D 0, cmd); + + res =3D g_new0(struct virtio_gpu_simple_resource, 1); + QTAILQ_INSERT_HEAD(&g->reslist, res, next); + + res->resource_id =3D cblob.resource_id; + res->blob_size =3D cblob.size; + + if (cblob.blob_mem !=3D VIRTIO_GPU_BLOB_MEM_HOST3D) { + result =3D virtio_gpu_create_mapping_iov(g, cblob.nr_entries, + sizeof(cblob), cmd, &res->a= ddrs, + &res->iov, &res->iov_cnt); + CHECK_RESULT(result, cmd); + } + + rc_blob.blob_id =3D cblob.blob_id; + rc_blob.blob_mem =3D cblob.blob_mem; + rc_blob.blob_flags =3D cblob.blob_flags; + rc_blob.size =3D cblob.size; + + vecs.iovecs =3D res->iov; + vecs.num_iovecs =3D res->iov_cnt; + + result =3D rutabaga_resource_create_blob(rutabaga, cblob.hdr.ctx_id, + cblob.resource_id, &rc_blob, &v= ecs, + NULL); + CHECK_RESULT(result, cmd); +} + +static void +rutabaga_cmd_resource_map_blob(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct virtio_gpu_simple_resource *res; + struct rutabaga_mapping mapping =3D { 0 }; + struct virtio_gpu_resource_map_blob mblob; + struct virtio_gpu_resp_map_info resp; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(mblob); + + CHECK(mblob.resource_id !=3D 0, cmd); + + res =3D virtio_gpu_find_resource(g, mblob.resource_id); + CHECK(res, cmd); + + result =3D rutabaga_resource_map(rutabaga, mblob.resource_id, &mapping= ); + CHECK_RESULT(result, cmd); + + memset(&resp, 0, sizeof(resp)); + resp.hdr.type =3D VIRTIO_GPU_RESP_OK_MAP_INFO; + result =3D rutabaga_resource_map_info(rutabaga, mblob.resource_id, + &resp.map_info); + + CHECK_RESULT(result, cmd); + virtio_gpu_ctrl_response(g, cmd, &resp.hdr, sizeof(resp)); +} + +static void +rutabaga_cmd_resource_unmap_blob(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + int32_t result; + struct virtio_gpu_simple_resource *res; + struct virtio_gpu_resource_unmap_blob ublob; + + VIRTIO_GPU_FILL_CMD(ublob); + + CHECK(ublob.resource_id !=3D 0, cmd); + + res =3D virtio_gpu_find_resource(g, ublob.resource_id); + CHECK(res, cmd); + + result =3D rutabaga_handle_unmap(g, res); + CHECK_RESULT(result, cmd); +} + +static void +virtio_gpu_rutabaga_process_cmd(VirtIOGPU *g, + struct virtio_gpu_ctrl_command *cmd) +{ + struct rutabaga_fence fence =3D { 0 }; + int32_t result; + + GET_VIRTIO_GPU_GL(g); + GET_RUTABAGA(virtio_gpu); + + VIRTIO_GPU_FILL_CMD(cmd->cmd_hdr); + + switch (cmd->cmd_hdr.type) { + case VIRTIO_GPU_CMD_CTX_CREATE: + rutabaga_cmd_context_create(g, cmd); + break; + case VIRTIO_GPU_CMD_CTX_DESTROY: + rutabaga_cmd_context_destroy(g, cmd); + break; + case VIRTIO_GPU_CMD_RESOURCE_CREATE_2D: + rutabaga_cmd_create_resource_2d(g, cmd); + break; + case VIRTIO_GPU_CMD_RESOURCE_CREATE_3D: + rutabaga_cmd_create_resource_3d(g, cmd); + break; + case VIRTIO_GPU_CMD_SUBMIT_3D: + rutabaga_cmd_submit_3d(g, cmd); + break; + case VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D: + rutabaga_cmd_transfer_to_host_2d(g, cmd); + break; + case VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D: + rutabaga_cmd_transfer_to_host_3d(g, cmd); + break; + case VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D: + rutabaga_cmd_transfer_from_host_3d(g, cmd); + break; + case VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING: + rutabaga_cmd_attach_backing(g, cmd); + break; + case VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING: + rutabaga_cmd_detach_backing(g, cmd); + break; + case VIRTIO_GPU_CMD_SET_SCANOUT: + rutabaga_cmd_set_scanout(g, cmd); + break; + case VIRTIO_GPU_CMD_RESOURCE_FLUSH: + rutabaga_cmd_resource_flush(g, cmd); + break; + case VIRTIO_GPU_CMD_RESOURCE_UNREF: + rutabaga_cmd_resource_unref(g, cmd); + break; + case VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE: + rutabaga_cmd_ctx_attach_resource(g, cmd); + break; + case VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE: + rutabaga_cmd_ctx_detach_resource(g, cmd); + break; + case VIRTIO_GPU_CMD_GET_CAPSET_INFO: + rutabaga_cmd_get_capset_info(g, cmd); + break; + case VIRTIO_GPU_CMD_GET_CAPSET: + rutabaga_cmd_get_capset(g, cmd); + break; + case VIRTIO_GPU_CMD_GET_DISPLAY_INFO: + virtio_gpu_get_display_info(g, cmd); + break; + case VIRTIO_GPU_CMD_GET_EDID: + virtio_gpu_get_edid(g, cmd); + break; + case VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB: + rutabaga_cmd_resource_create_blob(g, cmd); + break; + case VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB: + rutabaga_cmd_resource_map_blob(g, cmd); + break; + case VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB: + rutabaga_cmd_resource_unmap_blob(g, cmd); + break; + default: + cmd->error =3D VIRTIO_GPU_RESP_ERR_UNSPEC; + break; + } + + if (cmd->finished) { + return; + } + if (cmd->error) { + fprintf(stderr, "%s: ctrl 0x%x, error 0x%x\n", __func__, + cmd->cmd_hdr.type, cmd->error); + virtio_gpu_ctrl_response_nodata(g, cmd, cmd->error); + return; + } + if (!(cmd->cmd_hdr.flags & VIRTIO_GPU_FLAG_FENCE)) { + virtio_gpu_ctrl_response_nodata(g, cmd, VIRTIO_GPU_RESP_OK_NODATA); + return; + } + + fence.flags =3D cmd->cmd_hdr.flags; + fence.ctx_id =3D cmd->cmd_hdr.ctx_id; + fence.fence_id =3D cmd->cmd_hdr.fence_id; + fence.ring_idx =3D cmd->cmd_hdr.ring_idx; + + trace_virtio_gpu_fence_ctrl(cmd->cmd_hdr.fence_id, cmd->cmd_hdr.type); + + result =3D rutabaga_create_fence(rutabaga, &fence); + CHECK_RESULT(result, cmd); +} + +static void +virtio_gpu_rutabaga_fence_cb(uint64_t user_data, + struct rutabaga_fence fence_data) +{ + VirtIOGPU *g =3D (VirtIOGPU *)(void*)(uintptr_t)user_data; + struct virtio_gpu_ctrl_command *cmd, *tmp; + + bool signaled_ctx_specific =3D fence_data.flags & RUTABAGA_FLAG_INFO_R= ING_IDX; + + QTAILQ_FOREACH_SAFE(cmd, &g->fenceq, next, tmp) { + /* + * Due to context specific timelines. + */ + bool target_ctx_specific =3D cmd->cmd_hdr.flags & + RUTABAGA_FLAG_INFO_RING_IDX; + + if (signaled_ctx_specific !=3D target_ctx_specific) { + continue; + } + + if (signaled_ctx_specific && + (cmd->cmd_hdr.ring_idx !=3D fence_data.ring_idx)) { + continue; + } + + if (cmd->cmd_hdr.fence_id > fence_data.fence_id) { + continue; + } + + trace_virtio_gpu_fence_resp(cmd->cmd_hdr.fence_id); + virtio_gpu_ctrl_response_nodata(g, cmd, VIRTIO_GPU_RESP_OK_NODATA); + QTAILQ_REMOVE(&g->fenceq, cmd, next); + g_free(cmd); + } +} + +static int virtio_gpu_rutabaga_init(VirtIOGPU *g) +{ + int result; + uint64_t capset_mask; + struct rutabaga_channels channels =3D { 0 }; + struct rutabaga_builder builder =3D { 0 }; + + GET_VIRTIO_GPU_GL(g); + virtio_gpu->rutabaga =3D NULL; + + if (!virtio_gpu->capset_names) { + return -EINVAL; + } + + result =3D rutabaga_calculate_capset_mask(virtio_gpu->capset_names, + &capset_mask); + if (result) { + return result; + } + + /* + * rutabaga-0.1.1 is only compiled/tested with gfxstream and cross-dom= ain + * support. Future versions may change this to have more context types= if + * there is any interest. + */ + if ((capset_mask & (1 << RUTABAGA_CAPSET_VIRGL)) || + (capset_mask & (1 << RUTABAGA_CAPSET_VIRGL2)) || + (capset_mask & (1 << RUTABAGA_CAPSET_VENUS)) || + (capset_mask & (1 << RUTABAGA_CAPSET_DRM))) { + return -EINVAL; + } + + builder.user_data =3D (uint64_t)(uintptr_t *)(void *)g; + builder.fence_cb =3D virtio_gpu_rutabaga_fence_cb; + builder.capset_mask =3D capset_mask; + + if (virtio_gpu->wayland_socket_path) { + if ((builder.capset_mask & (1 << RUTABAGA_CAPSET_CROSS_DOMAIN)) = =3D=3D 0) { + return -EINVAL; + } + + channels.channels =3D + (struct rutabaga_channel *)calloc(1, sizeof(struct rutabaga_chan= nel)); + channels.num_channels =3D 1; + channels.channels[0].channel_name =3D virtio_gpu->wayland_socket_p= ath; + channels.channels[0].channel_type =3D RUTABAGA_CHANNEL_TYPE_WAYLAN= D; + builder.channels =3D &channels; + } + + result =3D rutabaga_init(&builder, (struct rutabaga **)&virtio_gpu->ru= tabaga); + if (builder.capset_mask & (1 << RUTABAGA_CAPSET_CROSS_DOMAIN)) { + free(channels.channels); + } + + return result; +} + +static int virtio_gpu_rutabaga_get_num_capsets(VirtIOGPU *g) +{ + int result =3D 0; + uint32_t num_capsets; + GET_VIRTIO_GPU_GL(g); + + if (!virtio_gpu->renderer_inited) { + result =3D virtio_gpu_rutabaga_init(g); + if (result) { + qemu_log_mask(LOG_GUEST_ERROR, "Failed to init rutabaga"); + return 0; + } + + virtio_gpu->renderer_inited =3D true; + } + + GET_RUTABAGA(virtio_gpu); + + result =3D rutabaga_get_num_capsets(rutabaga, &num_capsets); + if (result) { + qemu_log_mask(LOG_GUEST_ERROR, "Failed to get capsets"); + return 0; + } + virtio_gpu->num_capsets =3D num_capsets; + return (int)(num_capsets); +} + +static void virtio_gpu_rutabaga_handle_ctrl(VirtIODevice *vdev, VirtQueue = *vq) +{ + VirtIOGPU *g =3D VIRTIO_GPU(vdev); + GET_VIRTIO_GPU_GL(g); + struct virtio_gpu_ctrl_command *cmd; + + if (!virtio_queue_ready(vq)) { + return; + } + + if (!virtio_gpu->renderer_inited) { + int result =3D virtio_gpu_rutabaga_init(g); + if (!result) { + virtio_gpu->renderer_inited =3D true; + } + } + + if (!virtio_gpu->renderer_inited) { + return; + } + + cmd =3D virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command)); + while (cmd) { + cmd->vq =3D vq; + cmd->error =3D 0; + cmd->finished =3D false; + QTAILQ_INSERT_TAIL(&g->cmdq, cmd, next); + cmd =3D virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command)); + } + + virtio_gpu_process_cmdq(g); +} + +void virtio_gpu_rutabaga_device_realize(DeviceState *qdev, Error **errp) +{ + int num_capsets; + VirtIOGPUBase *bdev =3D VIRTIO_GPU_BASE(qdev); + VirtIOGPUBaseClass *vbc =3D VIRTIO_GPU_BASE_GET_CLASS(bdev); + + VirtIOGPU *gpudev =3D VIRTIO_GPU(qdev); + VirtIOGPUClass *vgc =3D VIRTIO_GPU_GET_CLASS(gpudev); + + num_capsets =3D virtio_gpu_rutabaga_get_num_capsets(gpudev); + if (!num_capsets) { + return; + } + + vbc->gl_flushed =3D virtio_gpu_rutabaga_gl_flushed; + vgc->handle_ctrl =3D virtio_gpu_rutabaga_handle_ctrl; + vgc->process_cmd =3D virtio_gpu_rutabaga_process_cmd; + vgc->update_cursor_data =3D virtio_gpu_rutabaga_update_cursor; + +#if HOST_BIG_ENDIAN + error_setg(errp, "rutabaga is not supported on bigendian platforms"); + return; +#endif + + gpudev->parent_obj.conf.flags |=3D (1 << VIRTIO_GPU_FLAG_RUTABAGA_ENAB= LED); + gpudev->parent_obj.conf.flags |=3D (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED); + gpudev->parent_obj.conf.flags + |=3D (1 << VIRTIO_GPU_FLAG_CONTEXT_INIT_ENABLED); + + VIRTIO_GPU_BASE(gpudev)->virtio_config.num_capsets =3D num_capsets; + virtio_gpu_device_realize(qdev, errp); +} --=20 2.40.0.634.g4ca3ef3211-goog From nobody Thu May 9 23:03:11 2024 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=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1682039658; cv=none; d=zohomail.com; s=zohoarc; b=aM/hnZ564cGJZ2jIcTIrSQMQEEza3QZc/MfcxPjARQKBOi4A2jGrbQc7q8Sare4EUtBs05Itf8bEsgu24tE3psarXIqFBRxWvQH348s+pw86FCAFHzyhlCV7+dl1uald6zQ6ddftDez/MgENjXoKZPBggZPxh4aSiOuAG0OXGq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682039658; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aIaMG88FZ7ZzQ9tREuZQMJNFNXVSeS7yq+zL/NQHUzg=; b=TJyWpZ0HXPSW4iuqUz4EVaNpgjR60ZTUA5qkm1XV+jVD7LL3YwMKkFc7Cl3aNw5aqLbHWqd8MgVAK+AFjxJJHY+N09HDPqicCCa9mM9XbNurJxqHxlEudUAIj/UaRqfUYh+xggWox75zVqlTyqcAi5MiUsHES0dKq6rkUTYOiL4= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682039658936769.7678603427817; Thu, 20 Apr 2023 18:14:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppfKo-0002i3-Dd; Thu, 20 Apr 2023 21:13:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppfKV-0002eL-CD for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:52 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppfKP-0008O6-Ti for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:51 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1a6ebc66ca4so14052365ad.3 for ; Thu, 20 Apr 2023 18:12:45 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:a7:2:6625:6aa3:1b0e:a808]) by smtp.gmail.com with ESMTPSA id f4-20020a17090a8e8400b0024702e7c80fsm1697640pjo.23.2023.04.20.18.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 18:12:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682039564; x=1684631564; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aIaMG88FZ7ZzQ9tREuZQMJNFNXVSeS7yq+zL/NQHUzg=; b=CodcqKhYaGr2c0hTW89XnTNyGkHt+zan+b6iMyODJeTYLqrm0vTsS4oYO9Il7kRAVM kqmFWE8KWvlpUXfChQfmEHYIhrN9sbImr8Tzh8xVch+9jRpaVbOmtvGXDlDFrSJYXOxp ElL+C3LdlsVLhRNECKBaCmPxzWoSW2/CshMZY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682039564; x=1684631564; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aIaMG88FZ7ZzQ9tREuZQMJNFNXVSeS7yq+zL/NQHUzg=; b=PBUJUEoqzNkcLnENETElRq+X7A0KpqYsdIun9URKQK1STWLI1PSrI++YsC5GdeFCAx K/2Yv+qlz8vL4lxNK89o4jbaTDbq1/BQjd18bYmWY9EHGZK5NV0Ot9YKgndzqNzQF9J4 KLp41J2xxB56IxS8ViSfrPYhnullPQB9bu2CdIw9l5ZFMjUpyV0jhoIExcDviVv42uPN 7i2SYygA4s1w26rZ0IGFfZ19OB0DCN5G5qlOBDo7iRR3lC1O3zpgsU0U2Sr2fYu/1pZZ qQl7faImg1ArJ1HMa0aEzdRUbor3WRZxDzYyxeatXRYhClGbLfztbeg4IAeQxJKI1oUE Y3jA== X-Gm-Message-State: AAQBX9cZvohCF0KYL6O7Rh7Nw0wrp/Rp2NuDgljTi4u4x1CoP1HjV8VO 5V7AnLrRujBA9iYJY1McoLUQhId0MNsufooK/15TYVue X-Google-Smtp-Source: AKy350aHqYU2+Sg0xoEGbYUeVTKh3HQXuH5Y1Ss0rRQLGSzoBhNGZbDZ9wjFazOu3nLHIyk5/3McaQ== X-Received: by 2002:a17:902:c951:b0:19e:8566:ea86 with SMTP id i17-20020a170902c95100b0019e8566ea86mr3964062pla.62.1682039564482; Thu, 20 Apr 2023 18:12:44 -0700 (PDT) From: Gurchetan Singh To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, david@redhat.com, stefanha@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, akihiko.odaki@gmail.com, dmitry.osipenko@collabora.com, ray.huang@amd.com, alex.bennee@linaro.org Subject: [RFC PATCH 11/13] gfxstream + rutabaga: enable rutabaga Date: Thu, 20 Apr 2023 18:12:21 -0700 Message-Id: <20230421011223.718-12-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230421011223.718-1-gurchetansingh@chromium.org> References: <20230421011223.718-1-gurchetansingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=gurchetansingh@chromium.org; helo=mail-pl1-x62d.google.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @chromium.org) X-ZM-MESSAGEID: 1682039660662100001 Content-Type: text/plain; charset="utf-8" This change enables rutabaga to receive virtio-gpu-3d hypercalls when it is active. Signed-off-by: Gurchetan Singh --- hw/display/virtio-gpu-base.c | 3 ++- hw/display/virtio-gpu-gl.c | 9 ++++++++- hw/display/virtio-gpu.c | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c index 6c5f1f327f..7913d9b82e 100644 --- a/hw/display/virtio-gpu-base.c +++ b/hw/display/virtio-gpu-base.c @@ -206,7 +206,8 @@ virtio_gpu_base_get_features(VirtIODevice *vdev, uint64= _t features, { VirtIOGPUBase *g =3D VIRTIO_GPU_BASE(vdev); =20 - if (virtio_gpu_virgl_enabled(g->conf)) { + if (virtio_gpu_virgl_enabled(g->conf) || + virtio_gpu_rutabaga_enabled(g->conf)) { features |=3D (1 << VIRTIO_GPU_F_VIRGL); } if (virtio_gpu_edid_enabled(g->conf)) { diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c index 15270b0c8a..fc09900ed9 100644 --- a/hw/display/virtio-gpu-gl.c +++ b/hw/display/virtio-gpu-gl.c @@ -23,7 +23,14 @@ =20 static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp) { - virtio_gpu_virgl_device_realize(qdev, errp); + VirtIOGPUGL *virtio_gpu =3D VIRTIO_GPU_GL(qdev); + virtio_gpu->rutabaga =3D NULL; + virtio_gpu_rutabaga_device_realize(qdev, errp); + + /* Fallback to virgl if rutabaga fails to initialize */ + if (!virtio_gpu->rutabaga) { + virtio_gpu_virgl_device_realize(qdev, errp); + } } =20 static Property virtio_gpu_gl_properties[] =3D { diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c index 938eed9181..3e92f9db6b 100644 --- a/hw/display/virtio-gpu.c +++ b/hw/display/virtio-gpu.c @@ -1314,8 +1314,9 @@ void virtio_gpu_device_realize(DeviceState *qdev, Err= or **errp) VirtIOGPU *g =3D VIRTIO_GPU(qdev); =20 if (virtio_gpu_blob_enabled(g->parent_obj.conf)) { - if (!virtio_gpu_have_udmabuf()) { - error_setg(errp, "cannot enable blob resources without udmabuf= "); + if (!virtio_gpu_have_udmabuf() && + !virtio_gpu_rutabaga_enabled(g->parent_obj.conf)) { + error_setg(errp, "need udmabuf or rutabaga for blob resources"= ); return; } =20 --=20 2.40.0.634.g4ca3ef3211-goog From nobody Thu May 9 23:03:11 2024 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=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1682039608; cv=none; d=zohomail.com; s=zohoarc; b=H0me5gDCwzpJ7EPcvZTMWe6lg7oM2tDvYMIoT+3B0ITMr7Gmy1C/gnLzh5U6Ns4a1kjIx7FPeVE7kgJyVeZHwiZyu16ufYrpscOMf27BvhQzbw6MsB+kGHTF6K5PRjfPSPsQfzadc/rnSlzPCkpFME3UaCq7nQjP6U3Hz8ZC10I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682039608; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dGVxufv435zSU4KrQ+6NR01fwhxqaFbsFZNIoUMt/hQ=; b=N15ba9KoF5W93VKPqCT0RpVaep1j8V4PI6/P69EDqyzeBSw3SOpzU1DwrBTCe4B6pGu0D/vwZRjrtdHPLFmQ9wP1suxdv/AAi4SOtOSROdRsndOS+RDLwY2EVgi9RZWP6DLwfpZAGKIyJvCTLpuRQ9UTK5n75uRlZXnGHYlpAO0= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168203960806336.13838842290454; Thu, 20 Apr 2023 18:13:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppfKf-0002gd-Gm; Thu, 20 Apr 2023 21:13:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppfKW-0002eP-Dx for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:52 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppfKT-0008OH-PO for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:51 -0400 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2471214cdd3so1160690a91.1 for ; Thu, 20 Apr 2023 18:12:47 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:a7:2:6625:6aa3:1b0e:a808]) by smtp.gmail.com with ESMTPSA id f4-20020a17090a8e8400b0024702e7c80fsm1697640pjo.23.2023.04.20.18.12.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 18:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682039566; x=1684631566; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dGVxufv435zSU4KrQ+6NR01fwhxqaFbsFZNIoUMt/hQ=; b=ZTt9r1I8TUMPft6NAIG1pc+s0Gr97XT1LOkw65ssAhjieUl4pRPwV5J3+wPvaON/2n f4xd1+YMZTqS5GKYcqevhFWhWrVvu41cheOURmH9MngGZw871BVhwLRAkiLBqr7g2AzF UoPr5SfLDoJy3Njf2v92yv1bI+0+vXwfF3d00= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682039566; x=1684631566; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dGVxufv435zSU4KrQ+6NR01fwhxqaFbsFZNIoUMt/hQ=; b=R7UqCFsT90O6qIJ8NSsSaHAgzaMHWE+oODGT+/j2Qu4YeEF1P6O/JelcHl3aqjRVrT Nq/2rpX2R5lDJTwxezQpu6uz0zvirdOlAN1HLdIlnSdUmutTszrF9H/dSdvAxjsn0iTz w0USbLeBnm6gf2ERA5gYi35r32aZAs4rEKCWzw4mT6RWSz6pnTi54oP3aSupBL+6F2E9 otIFFSSeSAd4xMNQiU15fkGkL3Bq/Vgr+fQQWXZoRMMDJmUDRtHG6p5n0RJZZPn9TEUc kyA+BMZEnOhg9G5A8RQM/N4sY8G1lyC5IhFO2M/45R9CTx+AGJL7ylujyHSo1S7q//Le 0lwg== X-Gm-Message-State: AAQBX9fbIk7Ltgh0SIUzC7lCSdQj8pONvGQmEhJtH90IXm0jXxQogeql tFrkxcsNeuvrAvuuuhYmiddvgfb82T+efmDSlGIfl5Os X-Google-Smtp-Source: AKy350amNwXq56Zmme/caDCN16+34u7VQPrN7JAS0ZGE1wm4gsmaPX6aQqwdTwqM/giQIhkLwqheSA== X-Received: by 2002:a17:90a:2e17:b0:244:9227:5eca with SMTP id q23-20020a17090a2e1700b0024492275ecamr2942746pjd.49.1682039566167; Thu, 20 Apr 2023 18:12:46 -0700 (PDT) From: Gurchetan Singh To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, david@redhat.com, stefanha@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, akihiko.odaki@gmail.com, dmitry.osipenko@collabora.com, ray.huang@amd.com, alex.bennee@linaro.org Subject: [RFC PATCH 12/13] HACK: use memory region API to inject memory to guest Date: Thu, 20 Apr 2023 18:12:22 -0700 Message-Id: <20230421011223.718-13-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230421011223.718-1-gurchetansingh@chromium.org> References: <20230421011223.718-1-gurchetansingh@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=gurchetansingh@chromium.org; helo=mail-pj1-x1031.google.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @chromium.org) X-ZM-MESSAGEID: 1682039608950100002 I just copied the patches that have been floating around that do this, but it doesn't seem to robustly work. This current implementation is probably good enough to run vkcube or simple apps, but whenever a test starts to aggressively map/unmap memory, things do explode on the QEMU side. A simple way to reproduce is run: ./deqp-vk --deqp-case=3Ddeqp-vk --deqp-case=3DdEQP-VK.memory.mapping.suball= ocation.* You should get stack traces that sometimes look like this: 0 __pthread_kill_implementation (no_tid=3D0, signo=3D6, threadid=3D1407373= 16304448) at ./nptl/pthread_kill.c:44 1 __pthread_kill_internal (signo=3D6, threadid=3D140737316304448) at ./npt= l/pthread_kill.c:78 2 __GI___pthread_kill (threadid=3D140737316304448, signo=3Dsigno@entry=3D6= ) at ./nptl/pthread_kill.c:89 3 0x00007ffff7042476 in __GI_raise (sig=3Dsig@entry=3D6) at ../sysdeps/pos= ix/raise.c:26 4 0x00007ffff70287f3 in __GI_abort () at ./stdlib/abort.c:79 5 0x00007ffff70896f6 in __libc_message (action=3Daction@entry=3Ddo_abort, = fmt=3Dfmt@entry=3D0x7ffff71dbb8c "%s\n") at ../sysdeps/posix/libc_fatal.c:1= 55 6 0x00007ffff70a0d7c in malloc_printerr (str=3Dstr@entry=3D0x7ffff71de7b0 = "double free or corruption (out)") at ./malloc/malloc.c:5664 7 0x00007ffff70a2ef0 in _int_free (av=3D0x7ffff7219c80 , p=3D0= x555557793e00, have_lock=3D) at ./malloc/malloc.c:4588 8 0x00007ffff70a54d3 in __GI___libc_free (mem=3D) at ./mall= oc/malloc.c:3391 9 0x0000555555d65e7e in phys_section_destroy (mr=3D0x555557793e10) at ../s= oftmmu/physmem.c:1003 10 0x0000555555d65ed0 in phys_sections_free (map=3D0x555556d4b410) at ../so= ftmmu/physmem.c:1011 11 0x0000555555d69578 in address_space_dispatch_free (d=3D0x555556d4b400) a= t ../softmmu/physmem.c:2430 12 0x0000555555d58412 in flatview_destroy (view=3D0x5555572bb090) at ../sof= tmmu/memory.c:292 13 0x000055555600fd23 in call_rcu_thread (opaque=3D0x0) at ../util/rcu.c:284 14 0x00005555560026d4 in qemu_thread_start (args=3D0x5555569cafa0) at ../ut= il/qemu-thread-posix.c:541 15 0x00007ffff7094b43 in start_thread (arg=3D) at ./nptl/pth= read_create.c:442 16 0x00007ffff7126a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clo= ne3.S:81 or this: 0x0000555555e1dc80 in object_unref (objptr=3D0x6d656d3c6b6e696c) at ../qom/= object.c:1198 1198 g_assert(obj->ref > 0); (gdb) bt 0 0x0000555555e1dc80 in object_unref (objptr=3D0x6d656d3c6b6e696c) at ../q= om/object.c:1198 1 0x0000555555d5cca5 in memory_region_unref (mr=3D0x5555572b9e20) at ../so= ftmmu/memory.c:1799 2 0x0000555555d65e47 in phys_section_destroy (mr=3D0x5555572b9e20) at ../s= oftmmu/physmem.c:998 3 0x0000555555d65ec7 in phys_sections_free (map=3D0x5555588365c0) at ../so= ftmmu/physmem.c:1011 4 0x0000555555d6956f in address_space_dispatch_free (d=3D0x5555588365b0) a= t ../softmmu/physmem.c:2430 5 0x0000555555d58409 in flatview_destroy (view=3D0x555558836570) at ../sof= tmmu/memory.c:292 6 0x000055555600fd1a in call_rcu_thread (opaque=3D0x0) at ../util/rcu.c:284 7 0x00005555560026cb in qemu_thread_start (args=3D0x5555569cafa0) at ../ut= il/qemu-thread-posix.c:541 8 0x00007ffff7094b43 in start_thread (arg=3D) at ./nptl/pth= read_create.c:442 9 0x00007ffff7126a00 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clo= ne3.S:81 The reason seems to be memory regions are handled on a different thread than the virtio-gpu thread, and that inevitably leads to raciness. The memory region docs[a] generally seems to dissuade this: "In order to do this, as a general rule do not create or destroy memory regions dynamically during a device=E2=80=99s lifetime, and only call object_unparent() in the memory region owner=E2=80=99s instance_final= ize callback. The dynamically allocated data structure that contains the memory region then should obviously be freed in the instance_finalize callback as well." Though instance_finalize is called before device destruction, so storing the memory until then is unlikely to be an option. The tests do pass when virtio-gpu doesn't free the memory, but progressively the guest becomes slower and then OOMs. Though the api does make an exception: "There is an exception to the above rule: it is okay to call object_unparent at any time for an alias or a container region. It is therefore also okay to create or destroy alias and container regions dynamically during a device=E2=80=99s lifetime." I believe we are trying to create a container subregion, but that's still failing? Are we doing it right? Any memory region experts here can help out? The other revelant patch in this series is "virtio-gpu: hostmem". [a] https://qemu.readthedocs.io/en/latest/devel/memory.html Signed-off-by: Gurchetan Singh --- hw/display/virtio-gpu-rutabaga.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutab= aga.c index 5fd1154198..196267aac2 100644 --- a/hw/display/virtio-gpu-rutabaga.c +++ b/hw/display/virtio-gpu-rutabaga.c @@ -159,6 +159,12 @@ static int32_t rutabaga_handle_unmap(VirtIOGPU *g, GET_VIRTIO_GPU_GL(g); GET_RUTABAGA(virtio_gpu); =20 + memory_region_transaction_begin(); + memory_region_set_enabled(&res->region, false); + memory_region_del_subregion(&g->parent_obj.hostmem, &res->region); + object_unparent(OBJECT(&res->region)); + memory_region_transaction_commit(); + res->mapped =3D NULL; return rutabaga_resource_unmap(rutabaga, res->resource_id); } @@ -671,6 +677,14 @@ rutabaga_cmd_resource_map_blob(VirtIOGPU *g, result =3D rutabaga_resource_map(rutabaga, mblob.resource_id, &mapping= ); CHECK_RESULT(result, cmd); =20 + memory_region_transaction_begin(); + memory_region_init_ram_device_ptr(&res->region, OBJECT(g), NULL, + mapping.size, (void *)mapping.ptr); + memory_region_add_subregion(&g->parent_obj.hostmem, mblob.offset, + &res->region); + memory_region_set_enabled(&res->region, true); + memory_region_transaction_commit(); + memset(&resp, 0, sizeof(resp)); resp.hdr.type =3D VIRTIO_GPU_RESP_OK_MAP_INFO; result =3D rutabaga_resource_map_info(rutabaga, mblob.resource_id, --=20 2.40.0.634.g4ca3ef3211-goog From nobody Thu May 9 23:03:11 2024 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=none dis=none) header.from=chromium.org ARC-Seal: i=1; a=rsa-sha256; t=1682039706; cv=none; d=zohomail.com; s=zohoarc; b=Faz34sD5/zvfHrbDiTTBK+7xLSMQ1qFEF80j5qg9nsqggXR+tqxn1bVUdi7ELid0lXlRc0elk8dRyu1sjl5kaXoCi4xLr0RSA471pWrUmutXY2OtMy6nT/KP9DJ9K3r6y66WAt81e6Nk4l2gSA0fwcZhyAbbbn126BtPyxlCz/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682039706; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4vTpbF7v1Tm3KrZR4fV6SJq1l9EN0aN9Wua7fdDEubE=; b=BU9e7fSVmz07IdODuvAFSxq5z0aIFKCJ2XzpDrlpzYPjtqf65SQrnNYL2i5rsqjWAz1/Vsyj53tHvz23xoYMPrjZJsk8V6jkOQYNqj3zFOgALXTE3/70PVJL1iPFvjqMQAWIJiOtAcluf0dp7ddd/BE3ApFzjXujaHkGuqbjYI0= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682039706103371.46033773570673; Thu, 20 Apr 2023 18:15:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ppfKn-0002i0-Jr; Thu, 20 Apr 2023 21:13:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ppfKW-0002en-PJ for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:52 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ppfKT-0008Oa-Pz for qemu-devel@nongnu.org; Thu, 20 Apr 2023 21:12:52 -0400 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-517bfdf55c3so1019638a12.2 for ; Thu, 20 Apr 2023 18:12:48 -0700 (PDT) Received: from gurchetansingh0.mtv.corp.google.com ([2620:15c:a7:2:6625:6aa3:1b0e:a808]) by smtp.gmail.com with ESMTPSA id f4-20020a17090a8e8400b0024702e7c80fsm1697640pjo.23.2023.04.20.18.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Apr 2023 18:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1682039567; x=1684631567; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4vTpbF7v1Tm3KrZR4fV6SJq1l9EN0aN9Wua7fdDEubE=; b=h/9TVHF85ucrcXdjxf/Xmji0v9YvJvyCuA3o0ATUAHBx8coP4T4IICWphK/QGEGKz5 d+22jBHoL4hFJssU+JEBWQ4BHvo6OREgrgxDak/ipXREocfOgBeIffydao5ynGrKS4uu jnOIxUWWxkpuU3SWyuRHLLuVQCfw7dWy3kF7c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682039567; x=1684631567; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4vTpbF7v1Tm3KrZR4fV6SJq1l9EN0aN9Wua7fdDEubE=; b=k9VtNFiEKQPepEcQM7b9NK/v4Njjm58wvwhY/RPp8nXfbee4bUqOXWPMxH7gN0v6+5 41a2794Fuf20Fh06W8ZNST0pTa7341z4hcMDooG/s9Oneh+JPRPgWy2J3KhgDJOs+kUB TYaBAxJuVseR1SLMSnHPHaWnq02q0Aex1cpqUlJrMEu85OGoDXE4Tslm1y/y/S43vazf 0ezFPRPJAAvJj9i8R3xbng/cExPHJcn+DMty2sXArEHLKEbz5XhtbcwkOywqcKYb2QL2 Q96fjYwO3535V8bcZCDIw7UISWf8bvuOztG1LpFIbqJC+Fgpm739R89YOv7V09RQi+KY f4fA== X-Gm-Message-State: AAQBX9eLpPzVnnMDfnE8P7eCPvYNlcXgxYUxc3fA4GdJUqNSjns5xaLK IgPbgjidTX0yNb4BjKZZD7J+/khJFYbvbOzvd5VqdIWb X-Google-Smtp-Source: AKy350ZzK14O7raC/KS7JOD/yUp2VkZTPYE9vWJCu+pY5lrSU8XNtpox3OfXudTOidx8Nj9rtPfBlQ== X-Received: by 2002:a17:90b:2289:b0:246:97d2:dc0d with SMTP id kx9-20020a17090b228900b0024697d2dc0dmr3307246pjb.39.1682039567662; Thu, 20 Apr 2023 18:12:47 -0700 (PDT) From: Gurchetan Singh To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, david@redhat.com, stefanha@redhat.com, kraxel@redhat.com, marcandre.lureau@redhat.com, akihiko.odaki@gmail.com, dmitry.osipenko@collabora.com, ray.huang@amd.com, alex.bennee@linaro.org Subject: [RFC PATCH 13/13] HACK: schedule fence return on main AIO context Date: Thu, 20 Apr 2023 18:12:23 -0700 Message-Id: <20230421011223.718-14-gurchetansingh@chromium.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20230421011223.718-1-gurchetansingh@chromium.org> References: <20230421011223.718-1-gurchetansingh@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=gurchetansingh@chromium.org; helo=mail-pg1-x535.google.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 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 @chromium.org) X-ZM-MESSAGEID: 1682039706852100001 Content-Type: text/plain; charset="utf-8" gfxstream and both cross-domain (and even newer versions virglrenderer: see VIRGL_RENDERER_ASYNC_FENCE_CB) like to signal fence completion on threads ("callback threads") that are different from the thread that processes the command queue ("main thread"). This is generally possible with locking, and this what we do in crosvm and other virtio-gpu1.1 implementations. However, on QEMU a deadlock is observed if virtio_gpu_ctrl_response_nodata(..) [used in the fence callback] is used from a thread that is not the main thread. The reason is the main thread takes the big QEMU lock (bql) somewhere when processing the command queue, and virtio_gpu_ctrl_response_nodata(..) needs that lock. If you add in the lock needed to protect &g->fenceq from concurrent access by the main thread and the callback threads, you end can end up with deadlocks. It's possible to workaround this by scheduling the return of the fence descriptors via aio_bh_schedule_oneshot_full(..), but that somewhat negates the rationale for the asynchronous callbacks. I also played around with aio_context_acquire()/aio_context_release(), doesn't seem to help. Is signaling the virtio_queue outside of the main thread possible? If so, how? Signed-off-by: Gurchetan Singh --- hw/display/virtio-gpu-rutabaga.c | 29 ++++++++++++++++++++++++++--- include/hw/virtio/virtio-gpu.h | 1 + 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/hw/display/virtio-gpu-rutabaga.c b/hw/display/virtio-gpu-rutab= aga.c index 196267aac2..5c296aeef1 100644 --- a/hw/display/virtio-gpu-rutabaga.c +++ b/hw/display/virtio-gpu-rutabaga.c @@ -31,6 +31,11 @@ static int virtio_gpu_rutabaga_init(VirtIOGPU *g); =20 #define CHECK_RESULT(result, cmd) CHECK(result =3D=3D 0, cmd) =20 +struct rutabaga_aio_data { + struct VirtIOGPUGL *virtio_gpu; + struct rutabaga_fence fence; +}; + static void virtio_gpu_rutabaga_update_cursor(VirtIOGPU *g, struct virtio_gpu_scanout = *s, uint32_t resource_id) @@ -823,10 +828,11 @@ virtio_gpu_rutabaga_process_cmd(VirtIOGPU *g, } =20 static void -virtio_gpu_rutabaga_fence_cb(uint64_t user_data, - struct rutabaga_fence fence_data) +virtio_gpu_rutabaga_aio_cb(void *opaque) { - VirtIOGPU *g =3D (VirtIOGPU *)(void*)(uintptr_t)user_data; + struct rutabaga_aio_data *data =3D (struct rutabaga_aio_data *)opaque; + VirtIOGPU *g =3D (VirtIOGPU *)data->virtio_gpu; + struct rutabaga_fence fence_data =3D data->fence; struct virtio_gpu_ctrl_command *cmd, *tmp; =20 bool signaled_ctx_specific =3D fence_data.flags & RUTABAGA_FLAG_INFO_R= ING_IDX; @@ -856,6 +862,22 @@ virtio_gpu_rutabaga_fence_cb(uint64_t user_data, QTAILQ_REMOVE(&g->fenceq, cmd, next); g_free(cmd); } + + g_free(data); +} + +static void +virtio_gpu_rutabaga_fence_cb(uint64_t user_data, + struct rutabaga_fence fence_data) { + struct rutabaga_aio_data *data; + VirtIOGPU *g =3D (VirtIOGPU *)(void*)(uintptr_t)user_data; + GET_VIRTIO_GPU_GL(g); + + data =3D g_new0(struct rutabaga_aio_data, 1); + data->virtio_gpu =3D virtio_gpu; + data->fence =3D fence_data; + aio_bh_schedule_oneshot_full(virtio_gpu->ctx, virtio_gpu_rutabaga_aio_= cb, + (void *)data, "aio"); } =20 static int virtio_gpu_rutabaga_init(VirtIOGPU *g) @@ -912,6 +934,7 @@ static int virtio_gpu_rutabaga_init(VirtIOGPU *g) free(channels.channels); } =20 + virtio_gpu->ctx =3D qemu_get_aio_context(); return result; } =20 diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h index 034c71e8f5..b33ad0c68f 100644 --- a/include/hw/virtio/virtio-gpu.h +++ b/include/hw/virtio/virtio-gpu.h @@ -225,6 +225,7 @@ struct VirtIOGPUGL { char *wayland_socket_path; uint32_t num_capsets; void *rutabaga; + AioContext *ctx; }; =20 struct VhostUserGPU { --=20 2.40.0.634.g4ca3ef3211-goog