From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id DE5A6AC141B for ; Fri, 8 Mar 2024 15:30:10 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=eAOltdwLhCF+uHlED9e/Kz0z2vhvkaA6a+KOLsxgC8o=; c=relaxed/simple; d=groups.io; h=Received-SPF:From:To:CC:Subject:Date:Message-ID:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type:Content-Transfer-Encoding; s=20240206; t=1709911809; v=1; b=aj0jj330NYPTWi8679MZDg4TF1TyBL4AILo/ZQ2QHUsrDdMBXSUnE62er1nR5W4f6gSJJL0o H3n4hrwkStgQ6tXSUztFv7ART/5RytOad2Zc1wmuWlEveKMpyzO2Ui1//2P/gSQvfRCAzvW8NyZ h78IgpSWx7QPO/QjSB1QIxm8gM/kB9p+gX/4KtqgtquazT0Tee3fiThc39njZ1sN+x13wDglsml /XJ7WDJARfQjSxCDF/7e+tEXtg6dwVCvIaqIG2xIqyPleoYSyNyl9fLbrI9Ku6bW0jNNfY/fAcs FbFsO6F5eEIFgi+zMjXL9V53BFVqrkdJkyMTkIDwrBtyw== X-Received: by 127.0.0.2 with SMTP id EVdsYY7687511xSxL9WCM5uB; Fri, 08 Mar 2024 07:30:09 -0800 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.60]) by mx.groups.io with SMTP id smtpd.web11.24813.1709911808533665674 for ; Fri, 08 Mar 2024 07:30:09 -0800 X-Received: from DM6PR11CA0041.namprd11.prod.outlook.com (2603:10b6:5:14c::18) by SA1PR12MB8918.namprd12.prod.outlook.com (2603:10b6:806:386::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7339.39; Fri, 8 Mar 2024 15:30:04 +0000 X-Received: from CY4PEPF0000E9D7.namprd05.prod.outlook.com (2603:10b6:5:14c:cafe::55) by DM6PR11CA0041.outlook.office365.com (2603:10b6:5:14c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.29 via Frontend Transport; Fri, 8 Mar 2024 15:30:04 +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 X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9D7.mail.protection.outlook.com (10.167.241.78) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7386.12 via Frontend Transport; Fri, 8 Mar 2024 15:30:04 +0000 X-Received: from tlendack-t1.amdoffice.net (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.35; Fri, 8 Mar 2024 09:30:02 -0600 From: "Lendacky, Thomas via groups.io" To: CC: Ard Biesheuvel , Erdem Aktas , Gerd Hoffmann , Jiewen Yao , Laszlo Ersek , Liming Gao , Michael D Kinney , Min Xu , Zhiguang Liu , "Rahul Kumar" , Ray Ni , Michael Roth , Anatol Belski , "Anthony Perard" , =?UTF-8?q?Corvin=20K=C3=B6hne?= , Gua Guo , Guo Dong , James Lu , Jianyong Wu , Rebecca Cran , Sean Rhodes Subject: [edk2-devel] [PATCH v3 00/24] Provide SEV-SNP support for running under an SVSM Date: Fri, 08 Mar 2024 07:30:09 -0800 Message-ID: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D7:EE_|SA1PR12MB8918:EE_ X-MS-Office365-Filtering-Correlation-Id: c37c4552-7e1e-47ab-4b45-08dc3f84a094 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: zCdIHOXQdGFInsEVi8m9cPINTRmwq9bOrax1nQKI5i1ECz4Y03pxhhKNYfUKQj/YLWKzp+Fg3W/HqthyPGmHwLgSpGf3XxoMRTGgathPiIuIChvqoIUbALT+2rqiK1EUOMINRQJom1ATZzTubEttc9/MtKYHD/Y2xhu1szlc9kWGl+XDT3GRnwonSQkENWdLrZGscEscAoJLnMyZ6LemdYtzCO51qNfiql9vdE7zZuTtVt864I0bnndLLV02y6fdbgKmQJh4D5Q3w+9alMkiBDRKfejfSOLi9X3Xur4+9D2wXJ4hlWKZw5uBJIDLu3pSa+P3lPw5vvxATUkwl4bLY/sWIAkkJ4rfznG64E7Kmhp3NvCmU4a7igB6inVil9puaDwuKI7aYj/38LlcE58blQcxyg+Pw77a3otEjh8qNZL0zCltlhYI+DGhjK6U8HLs5osntVCxkXoOhgSyuDaaAQ9uc+O5jf29zfHSyBC1I/gfd2iA2G8x5wGTfyJz73e346LJj8X3aS3mjTjBoMz+MY2d3IjvFjUNg3MzAzlQyNasrKAnS+THgVDSywscPV9o2wbmWzxL/lJat5+HCW3k/6JTHib9SzIeZVbfMS+z5U/JkAk19rB2rlXiEE7CcxrG5zuxhKqJaSRAQMjNmIhOViwLS1ortujYTIydK7ukrnHfG3xj2iA0pn8DhmuPxF0/z32z9pFSSUXtbmvFqaJ76A== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 15:30:04.0511 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c37c4552-7e1e-47ab-4b45-08dc3f84a094 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: CY4PEPF0000E9D7.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8918 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: I1CggkKgdD04QYdbvLhfLLaEx7686176AA= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=aj0jj330; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4654 This series adds SEV-SNP support for running OVMF under an Secure VM Service Module (SVSM) at a less privileged VM Privilege Level (VMPL). By running at a less priviledged VMPL, the SVSM can be used to provide services, e.g. a virtual TPM, for the guest OS within the SEV-SNP confidential VM (CVM) rather than trust such services from the hypervisor. Currently, OVMF expects to run at the highest VMPL, VMPL0, and there are certain SNP related operations that require that VMPL level. Specifically, the PVALIDATE instruction and the RMPADJUST instruction when setting the the VMSA attribute of a page (used when starting APs). If OVMF is to run at a less privileged VMPL, e.g. VMPL2, then it must use an SVSM (which is running at VMPL0) to perform the operations that it is no longer able to perform. When running under an SVSM, OVMF must know the APIC IDs of the vCPUs that it will be starting. As a result, the GHCB APIC ID retrieval action must be performed. Since this service can also work with SEV-SNP running at VMPL0, the patches to make use of this feature are near the beginning of the series. How OVMF interacts with and uses the SVSM is documented in the SVSM specification [1] and the GHCB specification [2]. This support creates a new AmdSvsmLib library that is used by MpInitLib. The edk2-platforms repo requires updates/patches to add the new library requirement. To accomodate that, this series could be split between: patch number 12: UefiCpuPkg/AmdSvsmLib: Create the AmdSvsmLib library to support an SVSM and patch number 13: UefiPayloadPkg: Prepare UefiPayloadPkg to use the AmdSvsmLib library The updates to edk2-platforms can be applied at the split. This series introduces support to run OVMF under an SVSM. It consists of: - Retrieving the list of vCPU APIC IDs and starting up all APs without performing a broadcast SIPI - Reorganizing the page state change support to not directly use the GHCB buffer since an SVSM will use the calling area buffer, instead - Detecting the presence of an SVSM - When not running at VMPL0, invoking the SVSM for page validation and VMSA page creation/deletion - Detecting and allowing OVMF to run in a VMPL other than 0 when an SVSM is present The series is based off of commit: e60529df58e4 ("UefiPayloadPkg: Make Dsc accomodative of other archs") [1] https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/sp= ecifications/58019.pdf [2] https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/sp= ecifications/56421.pdf Cc: Anatol Belski Cc: Anthony Perard Cc: Ard Biesheuvel Cc: Corvin K=C3=B6hne Cc: Erdem Aktas Cc: Gerd Hoffmann Cc: Gua Guo Cc: Guo Dong Cc: James Lu Cc: Jianyong Wu Cc: Jiewen Yao Cc: Laszlo Ersek Cc: Liming Gao Cc: Michael D Kinney Cc: Michael Roth Cc: Min Xu Cc: Rahul Kumar Cc: Ray Ni Cc: Rebecca Cran Cc: Sean Rhodes Cc: Zhiguang Liu --- Changes in v3: - Renamed CcSvsmLib to a more AMD-specific AmdSvsmLib with corresponding function name changes - Moved the GHCB APIC ID list GUID definition from MdePkg to UefiCpuPkg and change the name from gEfiApicIdsGuid to gGhcbApicIdsGuid - Separated the OvmfPkg changes for the AmdSvsmLib into two patches: - First patch adds usage of the AmdSvsmLib NULL library - Second patch adds the OVMF AmdSvsmLib implementation - Updated the commit message for the OVMF AmdSvsmLib implementation to indicate that the base functionality for PVALIDATE and RMPADJUST was copied from the original locations in prep for converting those sites to using the library API. Changes in v2: - Move the APIC IDs retrieval support to the beginning of the patch series - Use a GUIDed HOB to hold the APIC ID list instead of a PCD - Split up Page State Change reorganization into multiple patches - Created CcSvsmLib library instead of extending CcExitLib - This will require a corresponding update to edk2-platform DSC files - Removed Ray Ni's Acked-by since it is not a minor change - Variable name changes and other misc changes Tom Lendacky (24): OvmfPkg/BaseMemEncryptLib: Fix error check from AsmRmpAdjust() MdePkg: GHCB APIC ID retrieval support definitions UefiCpuPkg/MpInitLib: Always use AP Create if GhcbApicIds HOB is present OvmfPkg/PlatformPei: Retrieve APIC IDs from the hypervisor OvmfPkg/BaseMemEncryptSevLib: Fix uncrustify errors OvmfPkg/BaseMemEncryptSevLib: Calculate memory size for Page State Change MdePkg: Avoid hardcoded value for number of Page State Change entries OvmfPkg/BaseMemEncryptSevLib: Re-organize page state change support OvmfPkg/BaseMemEncryptSevLib: Maximize Page State Change efficiency MdePkg/Register/Amd: Define the SVSM related information MdePkg/BaseLib: Add a new VMGEXIT instruction invocation for SVSM UefiCpuPkg/AmdSvsmLib: Create the AmdSvsmLib library to support an SVSM UefiPayloadPkg: Prepare UefiPayloadPkg to use the AmdSvsmLib library Ovmfpkg: Prepare OvmfPkg to use the AmdSvsmLib library Ovmfpkg/AmdSvsmLib: Create AmdSvsmLib to handle SVSM related services UefiCpuPkg/MpInitLib: Use AmdSvsmSnpVmsaRmpAdjust() to set/clear VMSA OvmfPkg/BaseMemEncryptSevLib: Use AmdSvsmSnpPvalidate() to validate pages OvmfPkg: Create a calling area used to communicate with the SVSM OvmfPkg/AmdSvsmLib: Add support for the SVSM_CORE_PVALIDATE call OvmfPkg/BaseMemEncryptSevLib: Maximize Page State Change efficiency OvmfPkg/AmdSvsmLib: Add support for the SVSM create/delete vCPU calls UefiCpuPkg/MpInitLib: AP creation support under an SVSM Ovmfpkg/CcExitLib: Provide SVSM discovery support OvmfPkg/BaseMemEncryptLib: Check for presence of an SVSM when not at VMPL0 OvmfPkg/OvmfPkg.dec | = 4 + UefiCpuPkg/UefiCpuPkg.dec | = 8 +- OvmfPkg/AmdSev/AmdSevX64.dsc | = 1 + OvmfPkg/Bhyve/BhyveX64.dsc | = 1 + OvmfPkg/CloudHv/CloudHvX64.dsc | = 1 + OvmfPkg/IntelTdx/IntelTdxX64.dsc | = 1 + OvmfPkg/Microvm/MicrovmX64.dsc | = 1 + OvmfPkg/OvmfPkgIa32.dsc | = 1 + OvmfPkg/OvmfPkgIa32X64.dsc | = 3 +- OvmfPkg/OvmfPkgX64.dsc | = 1 + OvmfPkg/OvmfXen.dsc | = 1 + UefiCpuPkg/UefiCpuPkg.dsc | = 4 +- UefiPayloadPkg/UefiPayloadPkg.dsc | = 1 + OvmfPkg/AmdSev/AmdSevX64.fdf | = 9 +- OvmfPkg/OvmfPkgX64.fdf | = 3 + MdePkg/Library/BaseLib/BaseLib.inf | = 2 + OvmfPkg/Library/AmdSvsmLib/AmdSvsmLib.inf | 3= 8 ++ OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf | = 3 +- OvmfPkg/Library/BaseMemEncryptSevLib/PeiMemEncryptSevLib.inf | = 3 +- OvmfPkg/Library/BaseMemEncryptSevLib/SecMemEncryptSevLib.inf | = 3 +- OvmfPkg/Library/CcExitLib/CcExitLib.inf | = 3 +- OvmfPkg/Library/CcExitLib/SecCcExitLib.inf | = 3 +- OvmfPkg/PlatformPei/PlatformPei.inf | = 3 + OvmfPkg/ResetVector/ResetVector.inf | = 2 + UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf | 2= 7 ++ UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | = 2 + UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | = 2 + MdePkg/Include/Library/BaseLib.h | 3= 9 ++ MdePkg/Include/Register/Amd/Fam17Msr.h | 1= 9 +- MdePkg/Include/Register/Amd/Ghcb.h | 1= 9 +- MdePkg/Include/Register/Amd/Msr.h | = 3 +- MdePkg/Include/Register/Amd/Svsm.h | 10= 1 ++++ MdePkg/Include/Register/Amd/SvsmMsr.h | 3= 5 ++ OvmfPkg/Include/WorkArea.h | = 9 +- OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChange.h | = 6 +- UefiCpuPkg/Include/Guid/GhcbApicIds.h | 1= 7 + UefiCpuPkg/Include/Library/AmdSvsmLib.h | 10= 1 ++++ UefiCpuPkg/Library/MpInitLib/MpLib.h | 2= 9 +- OvmfPkg/Library/AmdSvsmLib/AmdSvsmLib.c | 50= 0 ++++++++++++++++++++ OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.c | 1= 1 +- OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c | 2= 7 +- OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c | 2= 2 +- OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c | 3= 1 +- OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c | 20= 6 ++++---- OvmfPkg/Library/CcExitLib/CcExitVcHandler.c | 2= 9 +- OvmfPkg/PlatformPei/AmdSev.c | 10= 3 +++- UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.c | 10= 8 +++++ UefiCpuPkg/Library/MpInitLib/Ia32/AmdSev.c | 2= 1 +- UefiCpuPkg/Library/MpInitLib/MpLib.c | = 9 +- UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c | 13= 4 ++++-- MdePkg/Library/BaseLib/Ia32/VmgExitSvsm.nasm | 3= 9 ++ MdePkg/Library/BaseLib/X64/VmgExitSvsm.nasm | 9= 4 ++++ OvmfPkg/ResetVector/ResetVector.nasmb | = 6 +- OvmfPkg/ResetVector/X64/OvmfSevMetadata.asm | 1= 1 +- UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.uni | 1= 3 + 55 files changed, 1641 insertions(+), 232 deletions(-) create mode 100644 OvmfPkg/Library/AmdSvsmLib/AmdSvsmLib.inf create mode 100644 UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.inf create mode 100644 MdePkg/Include/Register/Amd/Svsm.h create mode 100644 MdePkg/Include/Register/Amd/SvsmMsr.h create mode 100644 UefiCpuPkg/Include/Guid/GhcbApicIds.h create mode 100644 UefiCpuPkg/Include/Library/AmdSvsmLib.h create mode 100644 OvmfPkg/Library/AmdSvsmLib/AmdSvsmLib.c create mode 100644 UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.c create mode 100644 MdePkg/Library/BaseLib/Ia32/VmgExitSvsm.nasm create mode 100644 MdePkg/Library/BaseLib/X64/VmgExitSvsm.nasm create mode 100644 UefiCpuPkg/Library/AmdSvsmLibNull/AmdSvsmLibNull.uni --=20 2.43.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116525): https://edk2.groups.io/g/devel/message/116525 Mute This Topic: https://groups.io/mt/104810672/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-