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=kGV1E7ln; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.72.58, mailfrom: thomas.lendacky@amd.com) Received: from NAM05-CO1-obe.outbound.protection.outlook.com (NAM05-CO1-obe.outbound.protection.outlook.com [40.107.72.58]) by groups.io with SMTP; Mon, 19 Aug 2019 14:35:48 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JtjPXiwXZvnucLo/YDQTOi1biJUqrs99oiANoBSYFgoF9UOVONiIVkrDzS9DWBX9p+m087VuxNA5TJDQYw9Enba8FI2dxTrQFybngH/pLE2P4evpN2IhujDqORFz9KYPHzFI/Pq4bQvGO5ArubCeaREAO5RcysTSSXwg4C6MeFdEuTxc0zIw7YxaKQnOlPRJb5Gzwaiv5ikN8W7gUv55nLkdoMzyZFHMX52U78mg3AED+OProbUtqQp6jGiy6R2PeQufRvNhh1vDFvYCp05lkV+7AXfE9KCnSkexmJhPL/YO8As3fEHRhRXSr2cB8g2gimTX3pSNQAZTFEg8sqAcvQ== 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=adehdhXVrOjnSRv33/x8YE6Sgt7Oq5fXpmmjQjkLpN0=; b=Q3Fhi995HX1vplHNLxaf27c/X/o5K77vrQRPgVTCneG0I8EIjbJCNu5dcXh//NASmx1FqOKD47LCxtBJbUQ1WmvwHEbNhjVaXBWp55s0w41403lL9MJvaKRePeenSX4+x8v23BL6POX8G0QbsGqQDLRiWgAs8TQXq7WjzxQRd5gaT/kwPByBLybhjAm4Nsl4RfqRSkCitUSPYiiQaC3zgjj9RBwzWnSHO+UnqvXSXCBICRWLOy990iUama9L+gxRUvxI9iTphdfFqIKKuFr6fN76g1N/0uMtJ4RP5ikfQ2Cd69NFQPCgNnyEhOQ/OuiwBFQ8lZNMFUnDh6hfyI/Aag== 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=adehdhXVrOjnSRv33/x8YE6Sgt7Oq5fXpmmjQjkLpN0=; b=kGV1E7lnxsAWfSNcLzuch3FYapwIZY3VD00fRSVx0FBS11oPd7fMFMtZsjLLB7x21FSeAp6cZfzjSMHoxOtpiBOMmoY69WBRhwr0ZhRo85NaDFTxggOVQPtokBqGFN6r9gaBIZvnCTiO0cSkV5S3e+v7XpMtXS+Xrs8nPuqVeFY= Received: from BYAPR12MB3158.namprd12.prod.outlook.com (20.179.92.19) by BYAPR12MB3112.namprd12.prod.outlook.com (20.178.54.205) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.20; Mon, 19 Aug 2019 21:35:46 +0000 Received: from BYAPR12MB3158.namprd12.prod.outlook.com ([fe80::39b9:76bd:a491:1f27]) by BYAPR12MB3158.namprd12.prod.outlook.com ([fe80::39b9:76bd:a491:1f27%6]) with mapi id 15.20.2157.022; Mon, 19 Aug 2019 21:35:46 +0000 From: thomas.lendacky@amd.com To: "devel@edk2.groups.io" CC: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , "Singh, Brijesh" Subject: [RFC PATCH 00/28] SEV-ES guest support Thread-Topic: [RFC PATCH 00/28] SEV-ES guest support Thread-Index: AQHVVtYPQVk7XNyBuUKf1Orz8bZcKQ== Date: Mon, 19 Aug 2019 21:35:46 +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: SN2PR01CA0031.prod.exchangelabs.com (2603:10b6:804:2::41) To BYAPR12MB3158.namprd12.prod.outlook.com (2603:10b6:a03:132::19) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4975dff4-1f51-4b3a-c1ba-08d724ed31fd x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600148)(711020)(4605104)(1401327)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020);SRVR:BYAPR12MB3112; x-ms-traffictypediagnostic: BYAPR12MB3112: x-ms-exchange-purlcount: 3 x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 0134AD334F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(4636009)(39860400002)(346002)(376002)(366004)(396003)(136003)(189003)(199004)(66556008)(66476007)(5660300002)(52116002)(186003)(86362001)(305945005)(7736002)(6116002)(66446008)(6916009)(5640700003)(36756003)(6436002)(6486002)(6306002)(102836004)(6506007)(386003)(26005)(2351001)(476003)(2501003)(2616005)(486006)(66066001)(25786009)(54906003)(2906002)(19627235002)(4326008)(6512007)(99286004)(71200400001)(8936002)(50226002)(71190400001)(316002)(14444005)(8676002)(478600001)(256004)(53936002)(3846002)(81166006)(1730700003)(81156014)(966005)(66946007)(64756008)(14454004);DIR:OUT;SFP:1101;SCL:1;SRVR:BYAPR12MB3112;H:BYAPR12MB3158.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: KMqHiKkGhSy8Pq36IPuespWUfJZnuInH/hqbMq+lA1xLrI4aRo+5NJ0F7A3UZixyyPdD15jw9N4KOiCu9OI4swGW5BMg/zyzDgRAO1F3nImoFXIHpnIE6Tn7KIqlUEldcaqo414IQ9EaSX4iIHE0t5p0+FO1HC8XLnepnkjR5E68EaPJtpvCBItLkqJA0xldFnQfW0nGVkgRMoWwkNIZyqC3tnU2hdB01ZyiNWU5ICxx5B77Kf9RPl/8XE6sPFh918LteuX6KKjIGFPiHYh0y62uVG0JZOth32Mor7afIE1etdtmwAIhP33/0quuWqOnOw6QsVyJVpWnbQBOu/SIZyT10eTJedT8DTEM5HDWn4IYjtNJTPYELh7aiVM7RwQ4bOqTbZlpxE0fb1hSCIoMU8AE3f9ng5VadvF4CsWR6wI= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4975dff4-1f51-4b3a-c1ba-08d724ed31fd X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Aug 2019 21:35:46.4525 (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: R4TDfCHfttOPWyN2jN4a9kN9nGz+/CHDefjJ91UNYdzfANVTfpj0BLmBx7kCMsRwrU0IOCRXMuI2Z9qKy5bn2g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB3112 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 [3] https://github.com/AMDESE/ovmf/tree/sev-es-v6 Tom Lendacky (28): OvmfPkg/Sec: Enable cache early to speed up booting OvmfPkg/ResetVector: Add support for a 32-bit SEV check OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function OvmfPkg: Create a GHCB page for use during Sec phase OvmfPkg: Create GHCB pages for use during Pei and Dxe phase OvmfPkg: A per-CPU variable area for #VC usage OvmfPkg/PlatformPei: Move early GDT into ram when SEV-ES is enabled MdePkg/BaseLib: Implement the VMGEXIT support UefiCpuPkg/CpuExceptionHandler: Add base support for the #VC exception UefiCpuPkg/CpuExceptionHandler: Add base #VC exception handling support for Sec phase UefiCpuPkg/CpuExceptionHandler: Add support for IOIO_PROT NAE events UefiCpuPkg/CpuExceptionHandler: Support string IO for IOIO_PROT NAE events 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/CpuExceptionHandler: Add base #VC exception handling support for Pei/Dxe phases UefiCpuPkg/MpInitLib: Update CPU MP data with a flag to indicate if SEV-ES is active UefiCpuPkg/MpInitLib: Allow AP booting under SEV-ES UefiCpuPkg/MpInitLib: Introduce an MP finalization routine to support SEV-ES OvmfPkg/OvmfPkg.dec | 5 + UefiCpuPkg/UefiCpuPkg.dec | 7 + OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 6 + OvmfPkg/OvmfPkgX64.fdf | 9 +- MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 3 + MdePkg/Library/BaseLib/BaseLib.inf | 2 + OvmfPkg/PlatformPei/PlatformPei.inf | 5 + OvmfPkg/ResetVector/ResetVector.inf | 4 + OvmfPkg/Sec/SecMain.inf | 1 + .../DxeCpuExceptionHandlerLib.inf | 4 + .../PeiCpuExceptionHandlerLib.inf | 4 + .../SecPeiCpuExceptionHandlerLib.inf | 4 + UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 4 +- UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 2 + .../Core/DxeIplPeim/X64/VirtualMemory.h | 12 +- MdePkg/Include/Library/BaseLib.h | 30 + MdePkg/Include/Protocol/Cpu.h | 6 + OvmfPkg/Include/Library/MemEncryptSevLib.h | 12 + UefiCpuPkg/CpuDxe/CpuDxe.h | 14 + UefiCpuPkg/CpuDxe/CpuGdt.h | 2 +- UefiCpuPkg/Include/Library/MpInitLib.h | 17 + UefiCpuPkg/Include/Register/Amd/Fam17Msr.h | 28 + UefiCpuPkg/Include/Register/Amd/Ghcb.h | 197 +++ .../CpuExceptionHandlerLib/AMDSevVcCommon.h | 19 + .../CpuExceptionCommon.h | 2 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 73 +- 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 | 17 + MdePkg/Library/BaseLib/X64/GccInline.c | 45 + .../MemEncryptSevLibInternal.c | 78 +- .../BaseMemEncryptSevLib/X64/VirtualMemory.c | 33 +- OvmfPkg/PlatformPei/AmdSev.c | 83 ++ OvmfPkg/Sec/SecMain.c | 34 +- UefiCpuPkg/CpuDxe/CpuDxe.c | 10 + UefiCpuPkg/CpuDxe/CpuGdt.c | 10 +- .../CpuExceptionCommon.c | 2 +- .../Ia32/AMDSevVcCommon.c | 13 + .../PeiDxeAMDSevVcHandler.c | 22 + .../PeiDxeSmmCpuException.c | 16 + .../SecAMDSevVcHandler.c | 45 + .../SecPeiCpuException.c | 16 + .../X64/AMDSevVcCommon.c | 1192 +++++++++++++++++ UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 124 +- UefiCpuPkg/Library/MpInitLib/MpLib.c | 255 +++- UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 16 + UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c | 2 +- MdePkg/Library/BaseLib/X64/VmgExit.nasm | 38 + MdePkg/Library/BaseLib/X64/XGetBv.nasm | 39 + OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 85 ++ OvmfPkg/ResetVector/Ia32/PageTables64.asm | 210 ++- OvmfPkg/ResetVector/ResetVector.nasmb | 3 +- .../X64/ExceptionHandlerAsm.nasm | 15 + UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc | 4 +- .../Library/MpInitLib/Ia32/MpFuncs.nasm | 15 + UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc | 4 +- UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 367 ++++- .../ResetVector/Vtf0/Ia16/Real16ToFlat32.asm | 9 + 62 files changed, 3239 insertions(+), 108 deletions(-) create mode 100644 UefiCpuPkg/Include/Register/Amd/Ghcb.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 MdePkg/Library/BaseLib/X64/VmgExit.nasm create mode 100644 MdePkg/Library/BaseLib/X64/XGetBv.nasm create mode 100644 OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm --=20 2.17.1