From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.79]) by mx.groups.io with SMTP id smtpd.web12.14892.1624902202276237707 for ; Mon, 28 Jun 2021 10:43:22 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=WQ8Fy45D; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.93.79, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iQBVYw36Qr8UvpwjB1CG6OkydhiR+AUyqsDWo+ium2u+VVlFs2o9wbuaI43/bLIJR/d3TZ4+edVdYZkhDPu9VkvzfE2NU15st6V1xrif6//2jImXi9UPUiWoA96ocCVXOTM1uNCXZ2BcmWjaXyVjM2HeyHaKLBV7B1tE7UJKhoxzFb8rKJbwyF9tiTwtEVlH/oPdg9nkyYSiMckj0ZxkC3jUww5rB2e8ndgJQBsXgc5T2t5VAjlPs1VhgqTCSp47by/qsEqUiDF2LtHkzXfy5I6NQtB9uWmeddOg+rIaUuI810UAzeFz77NPi0Lg2RR3fetSps0NjE8OUg2XNDrzTw== 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=BL0wBsfUvHR/q25QB+jtndfrDKXDAZzH5QCGJENi3dg=; b=kQjMZC1Br5Ik4EW9VFN4FuSzyF2Ax/x0mxINBvhLKA8LaZ1VpCinvORRMuKA/92bH72iiiPmH9BoKKQEuBxO0Gly4iYqbde9HYlNuHirsAXJZOy53jlX+8XeBKZgY7af9QBmGE5dcsVE73MtY0Md/EMXleqsV9Y+jf71ZhKxEdFffD7zrlm6ebuHIfcbS3imfvaJLSuWZvqzpWJ40Q3wdgJxqoQ4hMUzZcpZWYktoAHitehsU2LQsVbBQ3wR4wsLgO/FTLuF5TrRfipPpexy/xO/GZRFzrOeYRupJb1pK/IAC+lF/Y5Cl3xVmYXJpD1a29fFeEBT87Gw5I5CVVpTcA== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BL0wBsfUvHR/q25QB+jtndfrDKXDAZzH5QCGJENi3dg=; b=WQ8Fy45D6pp+JsewgogzT3Vnks3w08cPfxRjg5ufsjrwdoJi2lAxQdBPwgW15CZJRkcZGHk0aaJybTwph0cxfMfmMQDrXJv4E2EVp1DiaWA1UURPwjDbX/Ep6AETY5F7uwu94CBv0md02vqbem8VC8aBEr7aAQqfbcDuE1ayblk= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) by DM6PR12MB4371.namprd12.prod.outlook.com (2603:10b6:5:2a3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.18; Mon, 28 Jun 2021 17:43:20 +0000 Received: from DM6PR12MB2714.namprd12.prod.outlook.com ([fe80::7df8:b0cd:fe1b:ae7b]) by DM6PR12MB2714.namprd12.prod.outlook.com ([fe80::7df8:b0cd:fe1b:ae7b%5]) with mapi id 15.20.4264.026; Mon, 28 Jun 2021 17:43:20 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io CC: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Laszlo Ersek , Erdem Aktas , Eric Dong , Ray Ni , Rahul Kumar , Michael D Kinney , Liming Gao , Zhiguang Liu , Michael Roth , Brijesh Singh Subject: [RFC PATCH v4 00/27] Add AMD Secure Nested Paging (SEV-SNP) support Date: Mon, 28 Jun 2021 12:41:56 -0500 Message-ID: <20210628174223.1302-1-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0601CA0020.namprd06.prod.outlook.com (2603:10b6:803:2f::30) To DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN4PR0601CA0020.namprd06.prod.outlook.com (2603:10b6:803:2f::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.19 via Frontend Transport; Mon, 28 Jun 2021 17:43:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ea2ab2a6-1c4a-4cc5-d416-08d93a5c383f X-MS-TrafficTypeDiagnostic: DM6PR12MB4371: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ou+PY/NTAQScfmptwoHs0Akc2goqixBx2I0pcZBQPMKrGFVpM6HLnI2hOhyBg28iBAImupzAnFTzY6mgEMlcpdOrldQxRu8r93urn2fhLqtzmZyvuEZJUiYkoTg2zlxZwcL2gidtkv2umG0H47GHgQ5kcwalBmpTPfGbmoSUeJvTyUJ5F6/NEmu3P1n64otowLrfdf7fS//xNEXGA7ILKW9X43lIK93OECWGrq9MSveqo4fYeaOBvz19bgxar3V3hQMTh3R/ey3Hi+9urRna5ldBa9WvlyeSpXOTyWtJHGzXzNHTHZtd9ySfpHy3GTKovbJtwdRHk6EqpFl8EYm7+OIKhH80/1beniXJGlZ4RQ/JnIjHWogC1jv01sT7Su7PB4fRgnstAsM5h1WcjMnqdDQEUWlUWwhhDNI833FuPjVTcf5/nuWDX8/NC9sJ63dqfrPTD9F8rpOgsjZkvtJennN0UJ8Hcx3bMd4L4+iNd5XDxTEtev5FeZvzjD+EGL/hrosR4i36fEnkmUIlIqxrFAwNBWIB+Pg/r+BKVcllTi5D9b9GCrZoJr2Bj1oYb8jXVYDW6XkdjpQqMZUj9BV6M/z3Sw0b8AmCwHsHuzRzj//lepoKkWbt0UJwgbpFBpK+elACUF05IL+pHwcoM10RklEhvljevhJ2p1pnb/bN0PyLNEPlWeXZQccNCoGX9j3xO4xW7H0lVa3izswhcO2ttwJGVc/kdGVrFPCcpzT9KIhIwnCX5ef3LUzg1z8gVDP1DouDvjtNREIQL9PhvOAGlXLv1gTZFh+YgZO331Nwyw6arVx0jyjFtXsWrLeqQsqAXyRBz1mcbvMOY2Velr9/WoMRp5Rv3cUApBx/eFtKZEs= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB2714.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(136003)(376002)(396003)(346002)(366004)(8676002)(8936002)(83380400001)(7416002)(66946007)(1076003)(36756003)(478600001)(7696005)(19627235002)(38100700002)(186003)(38350700002)(2906002)(26005)(44832011)(52116002)(16526019)(966005)(6666004)(6916009)(4326008)(54906003)(86362001)(5660300002)(2616005)(66556008)(956004)(66476007)(6486002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?zc5nPTLYwa3eAupMzvOuwYTEC4VLBTQq1lBrAlXbDfCzylEvJLz7l+zz4t5q?= =?us-ascii?Q?q1STN5jM2VpLWpEh4eqZGoZipdqNIBw8oFXhOXK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?DZ74DE0cBtkXVTbdl73PWnlu6xo23uvR9DAqngYtMb3nBXT+t9wIyh1EZHc8?= =?us-ascii?Q?Hj+TEZ8cUxTlBWcpIE/6eGJRWPLcvSjA+K0o/IxTpp6oSKY589xHPmtycERx?= =?us-ascii?Q?ZSkhN5IFfXCLzvgOdOUACuO5ksPQ6bCMkEQqaPKawhLm0AgnCJNeVVK6SL5e?= =?us-ascii?Q?6Hvnbo4w57BLK74EYIpDS86viy1GLFi153bYR7sL8zJRhhj97SxyO5YPaxzi?= =?us-ascii?Q?BRHH5CLu8As87Cnwi2X8Wlgv6BSlkQQLYtUOs+z8Jk85WxAg5Ru2+e21WC5s?= =?us-ascii?Q?3kUMNKv1XmpdIbnq3+DkQVMGL/V1dg70T+Qrvr51GFFt/Lr8KnSHR+a4nFiK?= =?us-ascii?Q?FaerTinjBejZqmFOZwM+nrmG?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ea2ab2a6-1c4a-4cc5-d416-08d93a5c383f X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2714.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2021 17:43:20.6594 (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: 8LtTiBhKRkUyKY1Vbj8DgOywAaZpBrO0Z+fmT7s7V3U076pytN62s+TNKrQbeUe2Q8Wafn9ImAYxzDW7llx5+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4371 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 SEV-SNP builds upon existing SEV and SEV-ES functionality while adding new hardware-based memory protections. SEV-SNP adds strong memory integrity protection to help prevent malicious hypervisor-based attacks like data replay, memory re-mapping and more in order to create an isolated memory encryption environment. =20 This series provides the basic building blocks to support booting the SEV-S= NP VMs, it does not cover all the security enhancement introduced by the SEV-S= NP such as interrupt protection. Many of the integrity guarantees of SEV-SNP are enforced through a new structure called the Reverse Map Table (RMP). Adding a new page to SEV-SNP VM requires a 2-step process. First, the hypervisor assigns a page to the guest using the new RMPUPDATE instruction. This transitions the page to guest-invalid. Second, the guest validates the page using the new PVALIDATE instruction. The SEV-SNP VMs can use the new "Page State Change Request NAE= " defined in the GHCB specification to ask hypervisor to add or remove page from the RMP table. Each page assigned to the SEV-SNP VM can either be validated or unvalidated= , as indicated by the Validated flag in the page's RMP entry. There are two approaches that can be taken for the page validation: Pre-validation and Lazy Validation. Under pre-validation, the pages are validated prior to first use. And under lazy validation, pages are validated when first accessed. An access to a unvalidated page results in a #VC exception, at which time the exception handler may validate the page. Lazy validation requires careful tracking of the validated pages to avoid validating the same GPA more than once. The recently introduced "Unaccepted" memory type can be used to communicate the unvalidated memory ranges to the Guest OS. At this time we only support the pre-validation. OVMF detects all the avail= able system RAM in the PEI phase. When SEV-SNP is enabled, the memory is validat= ed before it is made available to the EDK2 core. This series does not implements the following SEV-SNP features yet: * CPUID filtering * Lazy validation * Interrupt security Additional resources --------------------- SEV-SNP whitepaper https://www.amd.com/system/files/TechDocs/SEV-SNP-strengthening-vm-isolatio= n-with-integrity-protection-and-more.pdf APM 2: https://www.amd.com/system/files/TechDocs/24593.pdf (section 15.36) The complete source is available at https://github.com/AMDESE/ovmf/tree/sev-snp-rfc-4 GHCB spec: https://developer.amd.com/wp-content/resources/56421.pdf SEV-SNP firmware specification: https://www.amd.com/system/files/TechDocs/56860.pdf Brijesh Singh (26): OvmfPkg/ResetVector: move SEV specific code in a separate file OvmfPkg/ResetVector: add the macro to invoke MSR protocol based VMGEXIT OvmfPkg/ResetVector: add the macro to request guest termination OvmfPkg: reserve SNP secrets page OvmfPkg: reserve CPUID page for SEV-SNP OvmfPkg/ResetVector: introduce SEV-SNP boot block GUID OvmfPkg/ResetVector: pre-validate the data pages used in SEC phase OvmfPkg/ResetVector: invalidate the GHCB page UefiCpuPkg: Define the SEV-SNP specific dynamic PCDs OvmfPkg/MemEncryptSevLib: add MemEncryptSevSnpEnabled() OvmfPkg/SecMain: register GHCB gpa for the SEV-SNP guest OvmfPkg/PlatformPei: register GHCB gpa for the SEV-SNP guest OvmfPkg/AmdSevDxe: do not use extended PCI config space OvmfPkg/MemEncryptSevLib: add support to validate system RAM OvmfPkg/BaseMemEncryptSevLib: skip the pre-validated system RAM OvmfPkg/MemEncryptSevLib: add support to validate > 4GB memory in PEI phase OvmfPkg/SecMain: pre-validate the memory used for decompressing Fv OvmfPkg/PlatformPei: validate the system RAM when SNP is active OvmfPkg/PlatformPei: set the SEV-SNP enabled PCD OvmfPkg/PlatformPei: set the Hypervisor Features PCD MdePkg/GHCB: increase the GHCB protocol max version UefiCpuPkg/MpLib: add support to register GHCB GPA when SEV-SNP is enabled OvmfPkg/MemEncryptSevLib: change the page state in the RMP table OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address OvmfPkg/PlatformPei: mark cpuid and secrets memory reserved in EFI map OvmfPkg/AmdSev: expose the SNP reserved pages through configuration table Tom Lendacky (1): UefiCpuPkg/MpInitLib: Use SEV-SNP AP Creation NAE event to launch APs OvmfPkg/OvmfPkg.dec | 24 + UefiCpuPkg/UefiCpuPkg.dec | 11 + OvmfPkg/AmdSev/AmdSevX64.dsc | 5 +- OvmfPkg/Bhyve/BhyveX64.dsc | 5 +- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 6 +- OvmfPkg/OvmfPkgX64.dsc | 5 +- OvmfPkg/OvmfXen.dsc | 5 +- OvmfPkg/OvmfPkgX64.fdf | 14 +- OvmfPkg/AmdSevDxe/AmdSevDxe.inf | 7 + .../DxeMemEncryptSevLib.inf | 3 + .../PeiMemEncryptSevLib.inf | 7 + .../SecMemEncryptSevLib.inf | 3 + OvmfPkg/PlatformPei/PlatformPei.inf | 8 + OvmfPkg/ResetVector/ResetVector.inf | 6 + OvmfPkg/Sec/SecMain.inf | 3 + UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 4 + UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 4 + MdePkg/Include/Register/Amd/Ghcb.h | 2 +- .../Guid/ConfidentialComputingSecret.h | 18 + OvmfPkg/Include/Library/MemEncryptSevLib.h | 26 ++ .../X64/SnpPageStateChange.h | 31 ++ .../BaseMemEncryptSevLib/X64/VirtualMemory.h | 19 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 19 + OvmfPkg/AmdSevDxe/AmdSevDxe.c | 23 + .../DxeMemEncryptSevLibInternal.c | 27 ++ .../Ia32/MemEncryptSevLib.c | 17 + .../PeiMemEncryptSevLibInternal.c | 27 ++ .../SecMemEncryptSevLibInternal.c | 19 + .../X64/DxeSnpSystemRamValidate.c | 40 ++ .../X64/PeiDxeVirtualMemory.c | 167 ++++++- .../X64/PeiSnpSystemRamValidate.c | 126 ++++++ .../X64/SecSnpSystemRamValidate.c | 36 ++ .../X64/SnpPageStateChangeInternal.c | 295 +++++++++++++ OvmfPkg/PlatformPei/AmdSev.c | 192 ++++++++ OvmfPkg/PlatformPei/MemDetect.c | 21 + OvmfPkg/Sec/SecMain.c | 111 +++++ UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 11 +- .../MpInitLib/Ia32/SevSnpRmpAdjustInternal.c | 31 ++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 275 +++++++++++- .../MpInitLib/X64/SevSnpRmpAdjustInternal.c | 44 ++ OvmfPkg/FvmainCompactScratchEnd.fdf.inc | 5 + OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 27 ++ .../Ia32/{PageTables64.asm =3D> AmdSev.asm} | 415 +++++++++--------- OvmfPkg/ResetVector/Ia32/PageTables64.asm | 404 +---------------- OvmfPkg/ResetVector/ResetVector.nasmb | 7 + UefiCpuPkg/Library/MpInitLib/MpEqu.inc | 1 + UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 51 +++ 48 files changed, 1978 insertions(+), 630 deletions(-) create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateCh= ange.h create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRa= mValidate.c create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRa= mValidate.c create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRa= mValidate.c create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateCh= angeInternal.c create mode 100644 UefiCpuPkg/Library/MpInitLib/Ia32/SevSnpRmpAdjustIntern= al.c create mode 100644 UefiCpuPkg/Library/MpInitLib/X64/SevSnpRmpAdjustInterna= l.c copy OvmfPkg/ResetVector/Ia32/{PageTables64.asm =3D> AmdSev.asm} (67%) --=20 2.17.1