From patchwork Thu Aug 31 09:32:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huang Rui X-Patchwork-Id: 1828182 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=N/oWC1EG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RbwwY2T0mz1ygM for ; Thu, 31 Aug 2023 19:34:20 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qbe3L-0005Fs-3f; Thu, 31 Aug 2023 05:33:27 -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 1qbe3J-0005C0-M4 for qemu-devel@nongnu.org; Thu, 31 Aug 2023 05:33:25 -0400 Received: from mail-sn1nam02on20626.outbound.protection.outlook.com ([2a01:111:f400:7ea9::626] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qbe3F-0005A9-Jf for qemu-devel@nongnu.org; Thu, 31 Aug 2023 05:33:25 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NWpia6LSni2HH+R19FgEnQYCWCD4FSkSL+exj7E2WwupvwdI6WpCu+j/TiBRCGl0PGcfcF7iChmsjMGXrXubmlGykWXmFh5hot4hQuGy9FZFWnpJLTEytJRRdh8Y9/5jzMWVLKQOGKzG6Qj/+5vhh9x5DIeOdTrbamNgk0zlSzy2Ar/OFbLqijdLP86iyhW86flFS+l5iLD0TPoWHZMnyDKMQWvUZAcvqh2XiwuYw1hTIAzN99HW3bShBzPkMFWS7HD7RCeEoMgDP8TndzjSsmYyB73znR4UULrWoXIPUvVGBiGfyTNAMoyKh7a/44BnBZhkhjW7OroShWlcXE6isg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=40iM+fZux/xCi4XmCq6hzMQOQ9bUd0OFvX4rrQtY/pc=; b=UU60r8fG+F1JJnuVh3njYnUoA0j36Ri9Ge1O/iRm2NVXokLmvphlFrU7Lps5uy3kdxslZsdyRLZaausYz0bYT15cqjXguzAcuNO/GZcKRlm4TT/1glJOCK/zI6gWzW3Dl6FbFZZjkGruldIrwSNzs8+uAH9gFCEpBm0DuBJVE+bujdJia+ITiS+fO2yfwrI540vvVcvsQoWVSxof9P1DmJw/SZ5hkCypEquXGm9/bWisbFX15b6u7RZHODneIch+7LdbIntSPRutYSfgxaKSuK+IaaUH8UN4XrOW3WHoFst1KvNA/sHyS3PoNwGsUYy7WJar2yixnrMcolUx26y/+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=redhat.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=40iM+fZux/xCi4XmCq6hzMQOQ9bUd0OFvX4rrQtY/pc=; b=N/oWC1EG6DRzt1lSSUXsSQ9YalQ4H8wUMdaG1Gqx/4XU6WRECl46UOTtK9wEgnryOfMKNP9yZtTM4kGcGbSOBm5+4rYV62A/zPOjhqVAjKIHWwc1E3BYLo+oquOE+yAywVqogH6wfDpJ15kG1Hauaq75LFBUOXufzWeNSjCVhpg= Received: from MW2PR2101CA0024.namprd21.prod.outlook.com (2603:10b6:302:1::37) by DM8PR12MB5400.namprd12.prod.outlook.com (2603:10b6:8:3b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35; Thu, 31 Aug 2023 09:33:17 +0000 Received: from MWH0EPF000989E9.namprd02.prod.outlook.com (2603:10b6:302:1:cafe::55) by MW2PR2101CA0024.outlook.office365.com (2603:10b6:302:1::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.9 via Frontend Transport; Thu, 31 Aug 2023 09:33:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by MWH0EPF000989E9.mail.protection.outlook.com (10.167.241.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6745.17 via Frontend Transport; Thu, 31 Aug 2023 09:33:16 +0000 Received: from hr-amd.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 31 Aug 2023 04:33:10 -0500 From: Huang Rui To: Gerd Hoffmann , "Michael S . Tsirkin" , Stefano Stabellini , Anthony PERARD , Antonio Caggiano , "Dr . David Alan Gilbert" , Robert Beckett , "Dmitry Osipenko" , =?utf-8?q?Alex_Benn?= =?utf-8?q?=C3=A9e?= , CC: , Gurchetan Singh , , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Akihiko Odaki , Alyssa Ross , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , Xenia Ragiadakou , Pierre-Eric Pelloux-Prayer , "Honglei Huang" , Julia Zhang , "Chen Jiqian" , Huang Rui Subject: [QEMU PATCH v4 00/13] Support blob memory and venus on qemu Date: Thu, 31 Aug 2023 17:32:39 +0800 Message-ID: <20230831093252.2461282-1-ray.huang@amd.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWH0EPF000989E9:EE_|DM8PR12MB5400:EE_ X-MS-Office365-Filtering-Correlation-Id: bf3c0d40-ad27-4e8e-874f-08dbaa054e60 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /iHGW0ABY3mH3/L11xmSshoBnuBFKerSyq8+VZw7zz6+m+CjsrIR9MTOBAmZctxICpznEIkv+vCK2EZ2+oPaZmEE5bWvDX4V6c0lkJ6lel278gJITQrFs8ZLYqidcYGvsw5EymjMhrVICA4mWtGKLvu9yw6xJJqQIQkHP89iVywcEw5vLohJ+dQ9GLKIVaGfKFCRIM8Q7kyBECmoD3uDjzP0hzkjTELuVi2HdIwp8tBLiBvpZMqAVfSarMsD9qjr1DosHliR5w5ixpyIqTNBSwKiCz0jTKEHNfKi07M/OrN1s3Fvz4bR1KwiZo3jUIHyFo8xjgKnd7B43vs3s16VvaT/coxurAqol5mDdK1cWU+30Ei5Mk+55T9O3qtzGKtpgrpuEx2X0D6wdnnEgK8coDsAIOpKArtS9ot4HyPr1q8nhfeN77GUCsXLGdixmMplfoBD/V7C4IhbNR9NRBx0qbtyt6hMogr+BaKsZdtkMVgqGqw5IhtcdvsKwxVXz8IaXHPh5T9cLfzygjK+OvPXxKXagAipjbu/0Pwho1e4AKmpgiAHvhhKXIAltZ5L3dMHV7bDBl2Gqg6ng5DALDsxnihiKDUbI+wVpKGJZwGTZ9qizzQoHzvGW8KPoNfPigJT8ta+PFn4iRSm9ixReY48vKBLNh2f5XhQSNEL2KozxSrgbPC7ZE6z6Fx2tQjwe6RQx41BTI5x4oND7b3Gge1mCRrhbP3Hy/oLQtRfnM5XSRt/wl8hf8D6FPewiawwuTL6WBI4dBwuohjB33f/7ZzRAfGsYK5qCeNzCRU9DyivEgWkWDb1LGyUQKSk+BRHHgz6 X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB04.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(346002)(396003)(376002)(136003)(82310400011)(451199024)(1800799009)(186009)(40470700004)(36840700001)(46966006)(426003)(40460700003)(316002)(66899024)(41300700001)(5660300002)(336012)(4326008)(7416002)(8676002)(47076005)(16526019)(83380400001)(2616005)(86362001)(26005)(36756003)(1076003)(36860700001)(2906002)(40480700001)(8936002)(6666004)(356005)(82740400003)(81166007)(921005)(7696005)(966005)(54906003)(70206006)(70586007)(478600001)(110136005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Aug 2023 09:33:16.8001 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf3c0d40-ad27-4e8e-874f-08dbaa054e60 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: MWH0EPF000989E9.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM8PR12MB5400 Received-SPF: softfail client-ip=2a01:111:f400:7ea9::626; envelope-from=Ray.Huang@amd.com; helo=NAM02-SN1-obe.outbound.protection.outlook.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_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Hi all, Antonio Caggiano made the venus with QEMU on KVM platform last September[1]. This series are inherited from his original work to support the features of context init, hostmem, resource uuid, and blob resources for venus. At March of this year, we sent out the V1 version[2] for the review. But those series are included both xen and virtio gpu. Right now, we would like to divide into two parts, one is to continue the Antonio's work to upstream virtio-gpu support for blob memory and venus, and another is to upstream xen specific patches. This series is focusing on virtio-gpu, so we are marking as V4 version here to continue Antonio's patches[1]. And we will send xen specific patches separately, because they are hypervisor specific. Besides of QEMU, these supports also included virglrenderer[3][4] and mesa[5][6] as well. Right now, virglrenderer and mesa parts are all accepted by upstream. In this qemu version, we try to address the concerns around not proper cleanup during blob resource unmap and unref. Appreciate it if you have any commments. [1] https://lore.kernel.org/qemu-devel/20220926142422.22325-1-antonio.caggiano@collabora.com/ [2] V1: https://lore.kernel.org/qemu-devel/20230312092244.451465-1-ray.huang@amd.com [3] https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1068 [4] https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1180 [5] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22108 [6] https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23680 Please note the first 4 patches 1 -> 4 are inlcuded in these series because the series depends on them and not because we want them to be reviewed since they are already in the process of review through the "rutabaga_gfx + gfxstream" series. - https://lore.kernel.org/qemu-devel/20230829003629.410-1-gurchetansingh@chromium.org/ Changes from V1 to V2 (virtio gpu V4) - Remove unused #include "hw/virtio/virtio-iommu.h" - Add a local function, called virgl_resource_destroy(), that is used to release a vgpu resource on error paths and in resource_unref. - Remove virtio_gpu_virgl_resource_unmap from virtio_gpu_cleanup_mapping(), since this function won't be called on blob resources and also because blob resources are unmapped via virgl_cmd_resource_unmap_blob(). - In virgl_cmd_resource_create_blob(), do proper cleanup in error paths and move QTAILQ_INSERT_HEAD(&g->reslist, res, next) after the resource has been fully initialized. - Memory region has a different life-cycle from virtio gpu resources i.e. cannot be released synchronously along with the vgpu resource. So, here the field "region" was changed to a pointer and is allocated dynamically when the blob is mapped. Also, since the pointer can be used to indicate whether the blob is mapped, the explicite field "mapped" was removed. - In virgl_cmd_resource_map_blob(), add check on the value of res->region, to prevent beeing called twice on the same resource. - Add a patch to enable automatic deallocation of memory regions to resolve use-after-free memory corruption with a reference. References Demo with Venus: - https://static.sched.com/hosted_files/xen2023/3f/xen_summit_2023_virtgpu_demo.mp4 QEMU repository: - https://gitlab.freedesktop.org/rui/qemu-xen/-/commits/upstream-for-virtio-gpu Thanks, Ray Antonio Caggiano (6): virtio-gpu: CONTEXT_INIT feature virtio-gpu: blob prep virtio-gpu: Handle resource blob commands virtio-gpu: Resource UUID virtio-gpu: Support Venus capset virtio-gpu: Initialize Venus Dmitry Osipenko (1): virtio-gpu: Don't require udmabuf when blobs and virgl are enabled Dr. David Alan Gilbert (1): virtio: Add shared memory capability Gerd Hoffmann (1): virtio-gpu: hostmem Huang Rui (3): virtio-gpu: Support context init feature with virglrenderer virtio-gpu: Configure context init for virglrenderer virtio-gpu: Enable virglrenderer render server flag for venus Xenia Ragiadakou (1): softmmu/memory: enable automatic deallocation of memory regions hw/display/trace-events | 1 + hw/display/virtio-gpu-base.c | 5 + hw/display/virtio-gpu-pci.c | 14 + hw/display/virtio-gpu-virgl.c | 270 +++++++++++++++++++- hw/display/virtio-gpu.c | 61 ++++- hw/display/virtio-vga.c | 33 ++- hw/virtio/virtio-pci.c | 18 ++ include/hw/virtio/virtio-gpu-bswap.h | 15 ++ include/hw/virtio/virtio-gpu.h | 22 ++ include/hw/virtio/virtio-pci.h | 4 + include/standard-headers/linux/virtio_gpu.h | 2 + meson.build | 8 + softmmu/memory.c | 19 +- 13 files changed, 446 insertions(+), 26 deletions(-)