From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=iu5qB0Fc; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.76.73, mailfrom: thomas.lendacky@amd.com) Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.107.76.73]) by groups.io with SMTP; Thu, 19 Sep 2019 12:52:26 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l8ZiJF4p3lPimEq2NxFRyp0UHQZ7RgcRHPYLzBPU+fH+DM8sIHEbkQ0GlVIm7idWKC7uToDifjuxLyoRPsST9HEtL1jCxFI58ELFAE/9I463qIOf9JxOok8j0S4d+OgZ5XsuPl9/hlZ+/tO4vOxIfDvZvOzZvEazChq0YuQKmiuOVNllJc35Zb89k4UdRRNVOWaF13I7iQmnsfcmZ4TPn/Jr1QgdGEF6gL8RgHXEd+mP/hcVc7WM7RjV4YRva10MgSO3NtkUcPrT3u62Doeue9W2AtaJP9QXn0lqLr1B000yCG/DDdJajemNzNsO730R1n0EWzAcTI8HuRIMAMLsBg== 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-SenderADCheck; bh=ynmmqm7BCqkEtXKk0u7Siexl01kJ3V9rjQ4rSGb7oNQ=; b=IY8rh3a2DlQE4W31ZyL3Z3PUljlHWM+hlYab7EnZbH+RviIikvWrmXKbOO+Z9iGu0a4VoedGyGf79Xc42r4dBsbgZ8LFfdlX7GaQaIpWbjIIIEtibt/zHg+X6TYdjLV8Q+XpxUxULHwU0ZV//BZ/WgANRP6opJIDAs/raoR1PT16vra2lH9oNfR0w9er8epdh86/K+NO0uo1r4A7/Amsyn7YZG97R5LFUnTp9EkKGzIeEalkbwRoS1MOZ6RPG0d2aP5VXGrWHnwp/TBfFB4AIcjjuKVUEe6IQ6GscW1EnsC6Av2uBWqRYxbZ+A6pLn1i4I28ZfzRmRSBFpYtM0sd9g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ynmmqm7BCqkEtXKk0u7Siexl01kJ3V9rjQ4rSGb7oNQ=; b=iu5qB0FcI3v/hPJn7YHz/vpGUYK97TS+MdjJdDl5fZx6KrebUzTXotqg9U1SG5tesld1W/UHkdFVndBapSX5Mdue4z2gspX168xRyfVsEeMxpR1++VVKzwPLzie2NgwtXhJw7KqkULM73PylUwzzbLlg3zNAknMuWyro7rwAJgE= Received: from DM6PR12MB3163.namprd12.prod.outlook.com (20.179.104.150) by DM6PR12MB3228.namprd12.prod.outlook.com (20.179.105.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2263.13; Thu, 19 Sep 2019 19:52:24 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::400e:f0c3:7ca:2fcc]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::400e:f0c3:7ca:2fcc%6]) with mapi id 15.20.2284.009; Thu, 19 Sep 2019 19:52:24 +0000 From: "Lendacky, Thomas" To: "devel@edk2.groups.io" CC: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , "Singh, Brijesh" , Benjamin You , Dandan Bi , Guo Dong , Hao A Wu , Jian J Wang , Maurice Ma Subject: [RFC PATCH v2 00/44] SEV-ES guest support Thread-Topic: [RFC PATCH v2 00/44] SEV-ES guest support Thread-Index: AQHVbyPBwDESMVfbj0yqTR3rjeLCpQ== Date: Thu, 19 Sep 2019 19:52:24 +0000 Message-ID: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.17.1 x-clientproxiedby: SN4PR0501CA0146.namprd05.prod.outlook.com (2603:10b6:803:2c::24) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:182::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e39a5297-c4d3-4100-1faf-08d73d3ae425 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600167)(711020)(4605104)(1401327)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020);SRVR:DM6PR12MB3228; x-ms-traffictypediagnostic: DM6PR12MB3228: x-ms-exchange-purlcount: 3 x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4303; x-forefront-prvs: 016572D96D x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(4636009)(366004)(376002)(396003)(136003)(39860400002)(346002)(189003)(199004)(4326008)(26005)(7416002)(25786009)(52116002)(14444005)(19627235002)(71200400001)(71190400001)(8936002)(81156014)(81166006)(256004)(8676002)(186003)(50226002)(2351001)(2616005)(102836004)(486006)(476003)(66066001)(386003)(6506007)(66446008)(14454004)(99286004)(6486002)(36756003)(5640700003)(66556008)(3846002)(316002)(7736002)(2501003)(1730700003)(6116002)(5660300002)(478600001)(54906003)(6916009)(966005)(6436002)(2906002)(64756008)(305945005)(86362001)(6512007)(6306002)(66476007)(66946007);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3228;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: UbVWn0SHfwtLb8mWaahoFRChXRNuMvRLJG/QUnbrcvJdmRWlSg5HaToM/2JLVmf0kg2VxyrMsWS8t2ZGLLfHPDWk5hM5EXhV83mX1v3kH/NJklJ1+IzpLiimAE6PYNwVpLAkp52HnpPbFL5ZLdl5nBYmPwtorMAnFQZ3BkQaZn50HWRjkRXwNWnZ7Fb20vOKhoA0S7BH4KAE5VB+6MGla4Gq59ZiM8JnY3lBJUwjCVOhW1N8JKS0Wu5GYY0GjuqY0dNjaZqS9qUpWPEjEn6TlCLT9iKTb4qlo4LqKd7KKZKQQRJc6h/pufa7PNZMpZTv3Na56Sj8byjy42htq5CNPMyRIV85txvxBeCWcKumvketxmLG8sQkshLHFUylkZTtt5SM8K1MNnlJfII5diZ3PeJHVHinaCsTE5OO3gWPamM= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e39a5297-c4d3-4100-1faf-08d73d3ae425 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Sep 2019 19:52:24.3269 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: rN8bZAvZ79r/RUso3pA/NY7PDw4A1OMu/QdTNAsdh8A6mhuVPDECiRJgio8J1WSUOq46ORFW6j3gk/pGUfS8/w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3228 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable From: Tom Lendacky This patch series provides support for running EDK2/OVMF under SEV-ES. Secure Encrypted Virtualization - Encrypted State (SEV-ES) expands on the SEV support to protect the guest register state from the hypervisor. See "AMD64 Architecture Programmer's Manual Volume 2: System Programming", section "15.35 Encrypted State (SEV-ES)" [1]. In order to allow a hypervisor to perform functions on behalf of a guest, there is architectural support for notifying a guest's operating system when certain types of VMEXITs are about to occur. This allows the guest to selectively share information with the hypervisor to satisfy the requested function. The notification is performed using a new exception, the VMM Communication exception (#VC). The information is shared through the Guest-Hypervisor Communication Block (GHCB) using the VMGEXIT instruction. The GHCB format and the protocol for using it is documented in "SEV-ES Guest-Hypervisor Communication Block Standardization" [2]. The main areas of the EDK2 code that are updated to support SEV-ES are around the exception handling support and the AP boot support. Exception support is required starting in Sec, continuing through Pei and into Dxe in order to handle #VC exceptions that are generated. Each AP requires it's own GHCB page as well as a page to hold values specific to that AP. AP booting poses some interesting challenges. The INIT-SIPI-SIPI sequence is typically used to boot the APs. However, the hypervisor is not allowed to update the guest registers. The GHCB document [2] talks about how SMP booting under SEV-ES is performed. Since the GHCB page must be a shared (unencrypted) page, the processor must be running in long mode in order for the guest and hypervisor to communicate with each other. As a result, SEV-ES is only supported under the X64 architecture. [1] https://www.amd.com/system/files/TechDocs/24593.pdf [2] https://developer.amd.com/wp-content/resources/56421.pdf --- These patches are based on commit: ada905ab5c0e ("MdeModulePkg DxeCore: Fix for missing Memory Attributes Tabl= e (MAT) update") A version of the tree can be found at: https://github.com/AMDESE/ovmf/tree/sev-es-v7 Cc: Ard Biesheuvel Cc: Benjamin You Cc: Dandan Bi Cc: Eric Dong Cc: Guo Dong Cc: Hao A Wu Cc: Jian J Wang Cc: Jordan Justen Cc: Laszlo Ersek Cc: Liming Gao Cc: Maurice Ma Cc: Michael D Kinney Cc: Ray Ni Changes since v1: - Patches reworked to be more specific to the component/area being updated and order of definition/usage - Created a library for VMGEXIT-related functions to replace use of inline functions - Allocation method for GDT changed from AllocatePool to AllocatePages - Early caching only enabled for SEV-ES guests - Ensure AP loop mode set to halt loop mode for SEV-ES guests - Reserved SEC GHCB-related memory areas when S3 is enabled Tom Lendacky (44): MdePkg: Create PCDs to be used in support of SEV-ES OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function OvmfPkg: Add support to perform SEV-ES initialization OvmfPkg/ResetVector: Add support for a 32-bit SEV check MdePkg: Add the MSR definition for the GHCB register OvmfPkg: Create a GHCB page for use during Sec phase OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported OvmfPkg: Create GHCB pages for use during Pei and Dxe phase MdeModulePkg/DxeIplPeim: Support GHCB pages when creating page tables OvmfPkg: A per-CPU variable area for #VC usage OvmfPkg/PlatformPei: Move early GDT into ram when SEV-ES is enabled MdePkg: Add a structure definition for the GHCB MdePkg/BaseLib: Add support for the VMGEXIT instruction UefiCpuPkg: Implement library support for VMGEXIT UefiCpuPkg/CpuExceptionHandler: Add base support for the #VC exception OvmfPkg/MemEncryptSevLib: Make MemEncryptSevLib available during SEC UefiCpuPkg/CpuExceptionHandler: Add #VC exception handling for Sec phase OvmfPkg/Sec: Enable cache early to speed up booting UefiCpuPkg/CpuExceptionHandler: Add support for IOIO_PROT NAE events UefiCpuPkg/CpuExceptionHandler: Support string IO for IOIO_PROT NAE events MdePkg: Add support for the XGETBV instruction UefiCpuPkg/CpuExceptionHandler: Add support for CPUID NAE events UefiCpuPkg/CpuExceptionHandler: Add support for MSR_PROT NAE events UefiCpuPkg/CpuExceptionHandler: Add support for NPF NAE events (MMIO) UefiCpuPkg/CpuExceptionHandler: Add support for WBINVD NAE events UefiCpuPkg/CpuExceptionHandler: Add support for RDTSC NAE events UefiCpuPkg/CpuExceptionHandler: Add support for RDPMC NAE events UefiCpuPkg/CpuExceptionHandler: Add support for INVD NAE events UefiCpuPkg/CpuExceptionHandler: Add support for VMMCALL NAE events UefiCpuPkg/CpuExceptionHandler: Add support for RDTSCP NAE events UefiCpuPkg/CpuExceptionHandler: Add support for MONITOR/MONITORX NAE events UefiCpuPkg/CpuExceptionHandler: Add support for MWAIT/MWAITX NAE events UefiCpuPkg/CpuExceptionHandler: Add support for DR7 Read/Write NAE events UefiCpuPkg/MpInitLib: Update CPU MP data with a flag to indicate if SEV-ES is active MdeModulePkg: Reserve a 16-bit protected mode code segment descriptor UefiCpuPkg: Add a 16-bit protected mode code segment descriptor OvmfPkg: Add support for SEV-ES AP reset vector re-directing UefiCpuPkg: Allow AP booting under SEV-ES OvmfPkg: Move the GHCB allocations into reserved memory MdePkg: Add a finalization function to the CPU protocol UefiCpuPkg/MpInitLib: Add MP finalization interface to MpInitLib UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs for OS use UefiCpuPkg/CpuDxe: Provide an DXE MP finalization routine to support SEV-ES MdeModulePkg/DxeCore: Perform the CPU protocol finalization support MdeModulePkg/MdeModulePkg.dec | 15 + OvmfPkg/OvmfPkg.dec | 10 + UefiCpuPkg/UefiCpuPkg.dec | 3 + OvmfPkg/OvmfPkgIa32.dsc | 10 + OvmfPkg/OvmfPkgIa32X64.dsc | 10 + OvmfPkg/OvmfPkgX64.dsc | 10 + UefiCpuPkg/UefiCpuPkg.dsc | 5 + UefiPayloadPkg/UefiPayloadPkgIa32.dsc | 2 + UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc | 2 + OvmfPkg/OvmfPkgX64.fdf | 6 + MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 2 + MdePkg/Library/BaseLib/BaseLib.inf | 4 + .../BaseMemEncryptSevLib.inf | 2 +- OvmfPkg/PlatformPei/PlatformPei.inf | 7 + OvmfPkg/ResetVector/ResetVector.inf | 6 + OvmfPkg/Sec/SecMain.inf | 2 + .../DxeCpuExceptionHandlerLib.inf | 5 + .../PeiCpuExceptionHandlerLib.inf | 5 + .../SecPeiCpuExceptionHandlerLib.inf | 5 + UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 3 + UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 3 + UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf | 33 + .../Core/DxeIplPeim/X64/VirtualMemory.h | 12 +- MdePkg/Include/Library/BaseLib.h | 30 + MdePkg/Include/Protocol/Cpu.h | 18 + MdePkg/Include/Register/Amd/Fam17Msr.h | 28 + MdePkg/Include/Register/Amd/Ghcb.h | 105 ++ OvmfPkg/Include/Library/MemEncryptSevLib.h | 12 + UefiCpuPkg/CpuDxe/CpuDxe.h | 12 + UefiCpuPkg/CpuDxe/CpuGdt.h | 4 +- UefiCpuPkg/Include/Library/MpInitLib.h | 14 + UefiCpuPkg/Include/Library/VmgExitLib.h | 74 + .../CpuExceptionHandlerLib/AMDSevVcCommon.h | 19 + .../CpuExceptionCommon.h | 2 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 77 +- MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 5 + .../Core/DxeIplPeim/Ia32/DxeLoadFunc.c | 6 +- .../Core/DxeIplPeim/X64/DxeLoadFunc.c | 11 +- .../Core/DxeIplPeim/X64/VirtualMemory.c | 49 +- MdePkg/Library/BaseLib/Ia32/GccInline.c | 45 + MdePkg/Library/BaseLib/X64/GccInline.c | 47 + .../MemEncryptSevLibInternal.c | 77 +- OvmfPkg/PlatformPei/AmdSev.c | 78 ++ OvmfPkg/PlatformPei/MemDetect.c | 23 + OvmfPkg/Sec/SecMain.c | 39 +- UefiCpuPkg/CpuDxe/CpuDxe.c | 21 +- UefiCpuPkg/CpuDxe/CpuGdt.c | 8 +- .../CpuExceptionCommon.c | 2 +- .../Ia32/AMDSevVcCommon.c | 13 + .../PeiDxeAMDSevVcHandler.c | 22 + .../PeiDxeSmmCpuException.c | 16 + .../SecAMDSevVcHandler.c | 45 + .../SecPeiCpuException.c | 16 + .../X64/AMDSevVcCommon.c | 1200 +++++++++++++++++ UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 136 +- UefiCpuPkg/Library/MpInitLib/MpLib.c | 259 +++- UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 35 + UefiCpuPkg/Library/VmgExitLib/VmgExitLib.c | 75 ++ UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c | 2 +- MdePkg/Library/BaseLib/Ia32/VmgExit.nasm | 31 + MdePkg/Library/BaseLib/Ia32/XGetBv.nasm | 31 + MdePkg/Library/BaseLib/X64/VmgExit.nasm | 32 + MdePkg/Library/BaseLib/X64/XGetBv.nasm | 34 + OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 80 ++ OvmfPkg/ResetVector/Ia32/PageTables64.asm | 256 +++- OvmfPkg/ResetVector/ResetVector.nasmb | 13 + .../X64/ExceptionHandlerAsm.nasm | 15 + UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc | 2 +- .../Library/MpInitLib/Ia32/MpFuncs.nasm | 15 + UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc | 4 +- UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 373 ++++- UefiCpuPkg/Library/VmgExitLib/VmgExitLib.uni | 15 + .../ResetVector/Vtf0/Ia16/Real16ToFlat32.asm | 9 + 73 files changed, 3600 insertions(+), 97 deletions(-) create mode 100644 UefiCpuPkg/Library/VmgExitLib/VmgExitLib.inf create mode 100644 MdePkg/Include/Register/Amd/Ghcb.h create mode 100644 UefiCpuPkg/Include/Library/VmgExitLib.h create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/AMDSevVcCommo= n.h create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/AMDSevVc= Common.c create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeAMDSevV= cHandler.c create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/SecAMDSevVcHa= ndler.c create mode 100644 UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcC= ommon.c create mode 100644 UefiCpuPkg/Library/VmgExitLib/VmgExitLib.c create mode 100644 MdePkg/Library/BaseLib/Ia32/VmgExit.nasm create mode 100644 MdePkg/Library/BaseLib/Ia32/XGetBv.nasm create mode 100644 MdePkg/Library/BaseLib/X64/VmgExit.nasm create mode 100644 MdePkg/Library/BaseLib/X64/XGetBv.nasm create mode 100644 OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm create mode 100644 UefiCpuPkg/Library/VmgExitLib/VmgExitLib.uni --=20 2.17.1