From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.78]) by mx.groups.io with SMTP id smtpd.web12.25.1616599950939575559 for ; Wed, 24 Mar 2021 08:32:31 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=EaJQfsJH; 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.220.78, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ixl6Dy3DBZmzadda1stwNQBXvG+/Mr+jBaG154YPZe5QojWDvdqRrFUScWmjlkHYZjp+EXY8BvI1A2VDCiI/KpCteFGD5lL2s5r9Ek4KvCCZYIBAt2iIuZjH/KXcrOtNbfpTTvJT5TDGhYHP9hIxc/LUIqjlsnGBk+Sh6GQzxm5x/0VvYs+Pp04W5hDL7GD2i7G5i09hSC42qjZnHRKJg8wv41KvAncQFHcinOsbNOTd3OMRoY9cT43aH9ncEZmbUqyrb3vIQSsAo/imwue+YomuWAbB21bZGbcj2W5dw1b8gpp+2RI8iaTqR2mLmbQflNTAINyyMq+W6E1ToJ7uWQ== 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=gtmNayxnuYZdR7qTmc4lImGGu27FYnISqcpMOIaxnU8=; b=XDvd7gAsvqmUpeOC2sD5X54nz9ZqNLT3K785sUE7dFdCXzaGd14XF9Rvtnr9BGAAZRiDXbfh/gFyWA9gFoRn7I/VhwuzdT4Cj16sa/9V0xmpo7HFaebfw88DtMn+3/mp6yb9LFNRR7HBrTebqDA8npIsuDeSuSLTSId2FtVZDyaambb24gLqBP2flBNkAxZJZBMNUmkrcKPllF2XaNlESLrTIf425gdfwB0MvsUVmcwzQG8c4Wvnoz9VZOHe/5UJU3dkuj5gmsMRJfn90sX0nHi8yEcoq60qC5KIltiRYGcuxTVkURQZqWUmhUxUt/ueD9o+uWcqTtGIXw3ZHcBoGQ== 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=gtmNayxnuYZdR7qTmc4lImGGu27FYnISqcpMOIaxnU8=; b=EaJQfsJHpcoLhlc3bg4cQ5cuhxv3DmL1zXgnsG/roYEgGNTWiRsFaODX7Dy5ikuil2NSVJrlxpwh06cBaytlOO5lUQ1MaVwKNXP8wuKplWAntFW/RHGerPA8CZKDZyfrcedkyuVt3NRMIdTD3MlfYGmJ0wpDVrUxZakhLbT2q64= 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 SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SN1PR12MB2541.namprd12.prod.outlook.com (2603:10b6:802:24::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18; Wed, 24 Mar 2021 15:32:28 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::30fb:2d6c:a0bf:2f1d]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::30fb:2d6c:a0bf:2f1d%3]) with mapi id 15.20.3955.027; Wed, 24 Mar 2021 15:32:28 +0000 From: brijesh.singh@amd.com To: devel@edk2.groups.io Cc: Brijesh Singh , James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Laszlo Ersek Subject: [RFC PATCH 00/19] Add AMD Secure Nested Paging (SEV-SNP) support Date: Wed, 24 Mar 2021 10:31:56 -0500 Message-Id: <20210324153215.17971-1-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR11CA0006.namprd11.prod.outlook.com (2603:10b6:806:6e::11) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) 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 SA9PR11CA0006.namprd11.prod.outlook.com (2603:10b6:806:6e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3955.18 via Frontend Transport; Wed, 24 Mar 2021 15:32:28 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9bced59f-4b57-4952-49fd-08d8eeda0874 X-MS-TrafficTypeDiagnostic: SN1PR12MB2541: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Uqw+9hFBDSuPWyPgtmnapvEwWf7gaiTtlnMekK00xSVNI7TI+4SdxV9tZCKC7UabixWdvVVXni8MxgkiYfvEHqVZ+a1nEdt3UzIz0k09MUV2+Mr2/ae4NGG/nq18tP6FyQsZ1QjMeZg6hKufQUCGRZ+iX9RViqV02VnsGvWmXQHC2Ad5XCRplvwi/hG2xwM9q2Bt9LOa26RSIreOKdPpmL9ptP0Eq8Tmv9HhIWTUhzCZhaFosaRAPjROmHADSZyy9IqyMPLj1Z5TFy7QKKMMUESSEYFUpqyWm1XQCHJPzpBXHuZS2V/6oqK2rxv3nu8rIVgMAmHw0CfjbD0VVgwh+Wi2OZK6vn2bwYW1BMa5JCkiKJw15JvXy4/xlvtudMAEY+U3lHbGfE5BeFx0LqxylVm6Wb8SUg2NSjnkjSwCRFsun5FHDdGUiHMeaf+S8QGdfTrl/EtwdLGTM9aM2mALOHS3PU5k90aQALqeDbYFFhZV4QLuyH44sRmw4j+Z8q8nQus5gla/VmmUqLJtrLHL/COoGDUW3tecrjvcuGjtjKc320bhR1sPa4A11uId50u2mjc+YH+3bT/dEOcrngTe2CSE8yq4sonYofQ34Kh3I6vr4VgLLzRy/9HQc29+WCUfzm5/h5FxhbCRtNJd8JrjHyZpgbm2DhsihjdicITjGNhw7ltDMuqpEssE8pokhr3LaEZZYBLkPJFKRwUYfRZH8fNXZIUo1U7dG0VTjoFQZR4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(136003)(376002)(396003)(39860400002)(346002)(36756003)(8676002)(316002)(52116002)(54906003)(7696005)(5660300002)(1076003)(66946007)(6916009)(8936002)(83380400001)(2906002)(86362001)(6666004)(6486002)(38100700001)(26005)(66556008)(478600001)(956004)(66476007)(2616005)(966005)(19627235002)(4326008)(44832011)(186003)(16526019);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?RtcpOl+ussAsvDXYeAtnLiJZVBDfhuM8BQkuPKcNq9lT+MWXIXV0cn+LrT45?= =?us-ascii?Q?pT2qsM0ZBMeu5d6u+cwIhfkxKnbjVogxGJXGKFvsfMUVA4MqJGH7R0+kaLJs?= =?us-ascii?Q?2h4veGJ+LBcPUKPYHAIg+HV8SQVl3au3FG/IMWA/JjCTIVj0zs5LdsrByTwj?= =?us-ascii?Q?cSqxiHIsMLiQ/2FD1EiRaq8teP/0sGWcKiITuzNuSUardmfW4ZBHDZ8ymJ5H?= =?us-ascii?Q?TNGu0zFQ6mc63C9m1EU4OA/k+SIJAKVaCMbWhpD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RPHzi+2JV36EPk5jOMBElRo4W/98H2JXQfptNNgWD9TS2v?= =?us-ascii?Q?v5XzaDgWHDDLuQJJiZI5fFOE+sSBhCAvn4iUYOWilEo7DWpgsUYfB+IdawdD?= =?us-ascii?Q?adUxh0oCOC2KwgT1MPVLhzvBJdAJujTyM8+A28ZPjz2QETO/p+uR/j9HKso/?= =?us-ascii?Q?vHH4oNE540nzVeev2ovHrNY/?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9bced59f-4b57-4952-49fd-08d8eeda0874 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2021 15:32:28.6814 (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: 0srxxmhwO1UwagB2mBrFnNOn2FooBRJlR0Xi2aDttn9KkU1q9+4ZyzsO6Y0QynWiUmBHTnBEGM5hz6FEYpnzfg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2541 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3275 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. This series provides the basic building blocks to support booting the SEV-SNP VMs, it does not cover all the security enhancement introduced by the SEV-SNP 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 available system RAM in the PEI phase. When SEV-SNP is enabled, the memory is validated before it is made available to the EDK2 core. This series does not implements the following SEV-SNP features yet: * CPUID filtering * AP bring up using the new SEV-SNP NAE * Lazy validation * Interrupt security The series is based on commit: e542e05d4f UefiCpuPkg/SmmCpuFeaturesLib: Abstract PcdCpuMaxLogicalProcessorNumber Additional resources --------------------- SEV-SNP whitepaper https://www.amd.com/system/files/TechDocs/SEV-SNP-strengthening-vm-isolation-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-1 GHCB spec v2: The draft specification is posted on AMD-SEV-SNP mailing list: https://lists.suse.com/mailman/private/amd-sev-snp/ Copy of the spec is also available at https://github.com/AMDESE/AMDSEV/blob/sev-snp-devel/docs/56421-Guest_Hypervisor_Communication_Block_Standardization.pdf GHCB spec v1: SEV-SNP firmware specification: https://developer.amd.com/sev/ Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Laszlo Ersek Brijesh Singh (19): OvmfPkg: Reserve the Secrets and Cpuid page for the SEV-SNP guest OvmfPkg: validate the data pages used in the SEC phase MdePkg: Expand the SEV MSR to include the SNP definition OvmfPkg/MemEncryptSevLib: add MemEncryptSevSnpEnabled() MdePkg: Define the GHCB GPA structure UefiCpuPkg/MpLib: add support to register GHCB GPA when SEV-SNP is enabled OvmfPkg: Add a library to support registering GHCB GPA OvmfPkg: register GHCB gpa for the SEV-SNP guest MdePkg: Add AsmPvalidate() support OvmfPkg: Define the Page State Change VMGEXIT structures OvmfPkg/ResetVector: Invalidate the GHCB page OvmfPkg/MemEncryptSevLib: Add support to validate system RAM OvmfPkg/SecMain: Validate the data/code pages used for the PEI phase OvmfPkg/MemEncryptSevLib: Add support to validate RAM in PEI phase OvmfPkg/PlatformPei: Validate the system RAM when SNP is active OvmfPkg/MemEncryptSevLib: Add support to validate > 4GB memory in PEI phase OvmfPkg/VmgExitLib: Allow PMBASE register access in Dxe phase OvmfPkg/MemEncryptSevLib: Validate the memory during set or clear enc attribute OvmfPkg/MemEncryptSevLib: Skip page state change for non RAM region MdePkg/Include/Library/BaseLib.h | 37 +++ MdePkg/Include/Register/Amd/Fam17Msr.h | 31 ++- MdePkg/Include/Register/Amd/Ghcb.h | 39 ++- MdePkg/Library/BaseLib/BaseLib.inf | 1 + MdePkg/Library/BaseLib/X64/Pvalidate.nasm | 43 +++ OvmfPkg/Include/Library/GhcbRegisterLib.h | 27 ++ OvmfPkg/Include/Library/MemEncryptSevLib.h | 30 +++ .../DxeMemEncryptSevLib.inf | 7 + .../DxeMemEncryptSevLibInternal.c | 27 ++ .../Ia32/SnpPageStateChange.c | 17 ++ .../PeiMemEncryptSevLib.inf | 9 + .../PeiMemEncryptSevLibInternal.c | 47 ++++ .../SecMemEncryptSevLib.inf | 4 + .../SecMemEncryptSevLibInternal.c | 39 +++ .../BaseMemEncryptSevLib/SnpPageStateChange.h | 37 +++ .../X64/PeiDxeSnpSetPageState.c | 63 +++++ .../X64/PeiDxeVirtualMemory.c | 151 ++++++++++- .../X64/PeiSnpSystemRamValidate.c | 129 +++++++++ .../X64/SecSnpSystemRamValidate.c | 23 ++ .../X64/SnpPageStateChangeInternal.c | 254 ++++++++++++++++++ .../X64/SnpPageStateTrack.c | 119 ++++++++ .../X64/SnpPageStateTrack.h | 36 +++ .../X64/SnpSetPageState.h | 27 ++ .../BaseMemEncryptSevLib/X64/VirtualMemory.h | 19 ++ .../Library/GhcbRegisterLib/GhcbRegisterLib.c | 97 +++++++ .../GhcbRegisterLib/GhcbRegisterLib.inf | 33 +++ OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf | 4 + OvmfPkg/Library/VmgExitLib/VmgExitLib.inf | 7 + OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 45 ++++ OvmfPkg/OvmfPkg.dec | 12 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfPkgX64.fdf | 33 ++- OvmfPkg/PlatformPei/AmdSev.c | 52 ++++ OvmfPkg/PlatformPei/PlatformPei.inf | 2 + OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 24 ++ OvmfPkg/ResetVector/Ia32/PageTables64.asm | 106 ++++++++ OvmfPkg/ResetVector/ResetVector.inf | 5 + OvmfPkg/ResetVector/ResetVector.nasmb | 4 + OvmfPkg/Sec/SecMain.c | 102 +++++++ OvmfPkg/Sec/SecMain.inf | 2 + UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/MpEqu.inc | 1 + UefiCpuPkg/Library/MpInitLib/MpLib.c | 2 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 2 + UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 51 ++++ UefiCpuPkg/UefiCpuPkg.dec | 6 + 47 files changed, 1790 insertions(+), 19 deletions(-) create mode 100644 MdePkg/Library/BaseLib/X64/Pvalidate.nasm create mode 100644 OvmfPkg/Include/Library/GhcbRegisterLib.h create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/SnpPageStateChange.c create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/SnpPageStateChange.h create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeSnpSetPageState.c create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiSnpSystemRamValidate.c create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SecSnpSystemRamValidate.c create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateTrack.c create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateTrack.h create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpSetPageState.h create mode 100644 OvmfPkg/Library/GhcbRegisterLib/GhcbRegisterLib.c create mode 100644 OvmfPkg/Library/GhcbRegisterLib/GhcbRegisterLib.inf -- 2.17.1