From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (NAM12-BN8-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web09.10434.1619783538721945423 for ; Fri, 30 Apr 2021 04:52:19 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=sHQGTq5A; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: , mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OUf186fUjh+kvy64ndkW7eMLW+xs+LAGUDsHzxr/Mwpv8l/09/Sd8vBGuntnAErDq9xAhAYM5NfvUJaRIYsYsb/R8qm0nJnputEeTT901S4QDgJXbr7HP9rf0B4ILeu1xudtnovc1S4R0H//CdqjtlwtCFIlj7YIbJb/oK2BsBopsAt1680XWgECxATVqPRAfANSCguy4TYlGTaiXGSirts3r7rpJw5rTec6DEZAmdSALQFfg5qmh2Zngnk7IoEINaE4wkbsOE4F6G40V1brul83KZFHZlD+IDS6eKW9gGWVTq7Md4EcYsQa6gJ5P3GUYs1GyegNnSMrDZFZWYbOww== 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=B9gPwwutJE+R3kZndhBKhTD1cnSXR0WdsEBtyah5QSo=; b=W0j0BzWtcS1qbhMyfFzKqxtSZYXHosvaED+QppG8JkV4Rtwp7sHdBYjz5fBcp1jAUq7CDgSzWktz5dmxcdHeZDybKzFZu+9O0VmHZlo4VcbMiMduj2QJnf8K+QzI5jG/THh5yXrMN3j5BoovTfp674EU3OJVI5Mw7TeRkCpcTOTbooH4DPZJub1GU4VVfZ44mMCE1mgbjYH7vKa7PpEjAOqb+t/Y5i5n4O8wsnG5YTF9WSP2VTKl8eBv9/rOrCzwuzQUHI/UI6EywB2aBmRsTIraFHXOhMUHYOfaw1VoAUfiNgLM5uSGCLBbr7jvD/1Du2YeYZcqJOctG3tTkmXp9w== 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=B9gPwwutJE+R3kZndhBKhTD1cnSXR0WdsEBtyah5QSo=; b=sHQGTq5AFv0TJ/tcVjHIeUvStg/nglGt/b0wUVKFXzqtNNrqtHWeSEImzpTFNW51DyhlJuMyDIof8sBJuws9uzhXOi40CPU8LeNRDlvfJYDmIjZ2dO07asPP+P22frp3yW7IsvDspwQlvKiQ6Gv0MsAr//G3zxmdq61gCj9i7Ck= 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 SA0PR12MB4349.namprd12.prod.outlook.com (2603:10b6:806:98::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.23; Fri, 30 Apr 2021 11:52:14 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94%6]) with mapi id 15.20.4065.027; Fri, 30 Apr 2021 11:52:14 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io Cc: Brijesh Singh , James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Laszlo Ersek , Erdem Aktas Subject: [PATCH RFC v2 00/28] Add AMD Secure Nested Paging (SEV-SNP) support Date: Fri, 30 Apr 2021 06:51:20 -0500 Message-Id: <20210430115148.22267-1-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR12CA0006.namprd12.prod.outlook.com (2603:10b6:806:6f::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 SA0PR12CA0006.namprd12.prod.outlook.com (2603:10b6:806:6f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27 via Frontend Transport; Fri, 30 Apr 2021 11:52:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6800c004-b001-4db2-6b7d-08d90bce659c X-MS-TrafficTypeDiagnostic: SA0PR12MB4349: 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: wylJmfzIk1E/gS2CvsooSOTA0FEw57RYerxA2Y16AVeUWQzdcJylkwMYbtIQYS1zutKnXwkADRSfSqGLB71rT3lpVmNBTLsvEIwD5uHvdu7j2O3sbp3uiwiH2R3h7YamyUldDEt5Uk6AS0O6r6VsqlBW9vzokNe/YiakaHIOKqGbXt/mSVsLsn+uyUrHzCFS5U67ImcI2HnaN8y14BZIW3ckKJILradTwtTKsGA/6wVwLugAdniMz96qsHm4EUh1Lem5S6sQ/3/L+wmAPzvZkQDc3ga4feR25CtF3d/qDd9lJZjQCFPm/8GonWxPt6jgZVUXBjHnDeIZl5Haq9J7tS2Sy6kBkBVvaJKKjQKiC7k8YK1ngPMlI1Us/nRUcBEcwqDUf88abwerWaNhAAHP3YCuonp3OTTKInTooeDum6uOm67SLMSDfrvRea3xrlyux8Z2xNf7HOpHP/4FKU6QYM2nn5IPKZtQO6tz0UrgXSeob8P52RY9c+uCvQSw+3aKApy/yhavojQsCi2GJ7FRNErnh8CcCE2SWevyZmJ62kl1Rnu/XyMBoA+VePPofc5cg5bIwKuoQUNQ/KZP/f60M9JuuyC6cOikSPADThG1w4EKeFUHl0UWJa/AxPwcXR3IigHycalVUt2qjTzCNJN0h/6eHsVuwVzeobxLHuik7Mqut9cdzig43o0jR7UFMaBN9HgXYmX8QAFdvi5PqQ/ghtrkZ2g4M0ESMbzQGBE0/jPmFSKS1xHtn2puJlT4bvk4 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)(39860400002)(366004)(396003)(346002)(136003)(376002)(966005)(38100700002)(2616005)(26005)(1076003)(86362001)(316002)(6916009)(8936002)(6666004)(2906002)(4326008)(52116002)(66946007)(5660300002)(186003)(54906003)(44832011)(36756003)(66556008)(8676002)(66476007)(16526019)(19627235002)(83380400001)(478600001)(956004)(7696005)(38350700002)(6486002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?kRx5ZcK3mxNiqm1jYz6jUZtoytEd6MtBJJa4Wa4kuWGUx7J9hASXgUg/cemb?= =?us-ascii?Q?hCAbdtRlCeNN+qJnWlTNkEte1yo7aWszYCc/yGYlyHC+UKkN6wFKBEowBLEH?= =?us-ascii?Q?HRRQYZR3W3d6YuFhjwoKJVG0VmL1BuKdMMntWXZ3j0m5beBlyDcuXfaYP9HX?= =?us-ascii?Q?nmUUCHrADyu52AOfVt3FD2m/H70HwSgHA3e8ylFBMwRWcUWWobL/0S1sQryv?= =?us-ascii?Q?sYhbD5TY2/guQtOCf0IWt3STuhdOMVpaZMPQr3XQTcsBzWTokx97RejtZqrd?= =?us-ascii?Q?W8XLHE0DIwrPsNwp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e+127z?= =?us-ascii?Q?EAR6JOXheRvBnmHtpVJexLmgetqJSvjgJ03aTfw4sQNEGc2IPeFc4oHDHIf1?= =?us-ascii?Q?vV1M4wU3ZOV1itQ9nKd8zYZ33NGwfMdk4Pv5ccOPP55mqPXIwpFIfnH/3n7i?= =?us-ascii?Q?UwOLQNhzDD0k7JgE25Utfxay?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6800c004-b001-4db2-6b7d-08d90bce659c X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2021 11:52:14.8222 (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: f3fRoALipmAbvkWGvR8LGEe4kM1AWBNGsDy+gR2is/Wo4q+yvnyXnKKzyKAAWSDhZIyaFVGMN1ppPeW5VbB0qQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4349 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: 01c0ab90be (origin/master, origin/HEAD, master) AzurePipelines: Add support for ArmPlatformPkg 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-2 GHCB spec: https://developer.amd.com/wp-content/resources/56421.pdf 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 Cc: Erdem Aktas Changes since v1: * Drop the interval tree support to detect the pre-validated overlap region. * Use an array to keep track of pre-validated regions. * Add support to query the Hypervisor feature and verify that SNP feature is supported. * Introduce MemEncryptSevClearMmioPageEncMask() to clear the C-bit from MMIO ranges. * Pull the SevSecretDxe and SevSecretPei into OVMF package build. * Extend the SevSecretDxe to expose confidential computing blob location through EFI configuration table. Brijesh Singh (28): MdePkg: Expand the SEV MSR to include the SNP definition MdePkg: Define the GHCB Hypervisor features MdePkg: Define the GHCB GPA structure MdePkg: Define the Page State Change VMGEXIT structures MdePkg: Add AsmPvalidate() support OvmfPkg/BaseMemEncryptSevLib: Introduce MemEncryptSevClearMmioPageEncMask() OvmfPkg: Use MemEncryptSevClearMmioPageEncMask() to clear EncMask from Mmio OvmfPkg/BaseMemEncryptSevLib: Remove CacheFlush parameter OvmfPkg/VmgExitLib: Allow PMBASE register access in Dxe phase OvmfPkg/MemEncryptSevLib: add MemEncryptSevSnpEnabled() OvmfPkg: Reserve Secrets page in MEMFD OvmfPkg: Reserve CPUID page for the SEV-SNP guest OvmfPkg: Validate the data pages used in the Reset vector and SEC phase UefiCpuPkg: Define the SEV-SNP specific dynamic PCDs OvmfPkg/MemEncryptSevLib: extend the workarea to include SNP enabled field OvmfPkg/MemEncryptSevLib: Extend Es Workarea to include hv features OvmfPkg/ResetVector: Invalidate the GHCB page OvmfPkg: Add a library to support registering GHCB GPA OvmfPkg: register GHCB gpa for the SEV-SNP guest UefiCpuPkg/MpLib: add support to register GHCB GPA when SEV-SNP is enabled 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/MemEncryptSevLib: Change the page state in the RMP table OvmfPkg/AmdSev: Expose the SNP reserved pages through configuration table MdePkg/GHCB: Increase the GHCB protocol max version MdePkg/Include/Library/BaseLib.h | 37 +++ MdePkg/Include/Register/Amd/Fam17Msr.h | 36 ++- MdePkg/Include/Register/Amd/Ghcb.h | 37 ++- MdePkg/Library/BaseLib/BaseLib.inf | 1 + MdePkg/Library/BaseLib/X64/Pvalidate.nasm | 43 +++ OvmfPkg/AmdSev/SecretDxe/SecretDxe.c | 21 ++ OvmfPkg/AmdSev/SecretDxe/SecretDxe.inf | 4 + OvmfPkg/AmdSev/SecretPei/SecretPei.c | 16 +- OvmfPkg/AmdSev/SecretPei/SecretPei.inf | 1 + OvmfPkg/AmdSevDxe/AmdSevDxe.c | 13 +- OvmfPkg/FvmainCompactScratchEnd.fdf.inc | 5 + .../Guid/ConfidentialComputingSecret.h | 17 ++ OvmfPkg/Include/Library/GhcbRegisterLib.h | 27 ++ OvmfPkg/Include/Library/MemEncryptSevLib.h | 66 ++++- OvmfPkg/IoMmuDxe/AmdSevIoMmu.c | 6 +- .../DxeMemEncryptSevLib.inf | 3 + .../DxeMemEncryptSevLibInternal.c | 27 ++ .../Ia32/MemEncryptSevLib.c | 58 +++- .../PeiMemEncryptSevLib.inf | 7 + .../PeiMemEncryptSevLibInternal.c | 27 ++ .../SecMemEncryptSevLib.inf | 3 + .../SecMemEncryptSevLibInternal.c | 19 ++ .../X64/DxeSnpSystemRamValidate.c | 40 +++ .../X64/MemEncryptSevLib.c | 49 +++- .../X64/PeiDxeVirtualMemory.c | 203 +++++++++++++- .../X64/PeiSnpSystemRamValidate.c | 126 +++++++++ .../X64/SecSnpSystemRamValidate.c | 36 +++ .../X64/SecVirtualMemory.c | 8 +- .../X64/SnpPageStateChange.h | 31 +++ .../X64/SnpPageStateChangeInternal.c | 261 ++++++++++++++++++ .../BaseMemEncryptSevLib/X64/VirtualMemory.h | 52 +++- .../Library/GhcbRegisterLib/GhcbRegisterLib.c | 97 +++++++ .../GhcbRegisterLib/GhcbRegisterLib.inf | 33 +++ .../SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 3 +- OvmfPkg/Library/VmgExitLib/SecVmgExitLib.inf | 4 + OvmfPkg/Library/VmgExitLib/VmgExitLib.inf | 7 + OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 45 +++ OvmfPkg/OvmfPkg.dec | 21 ++ OvmfPkg/OvmfPkgIa32.dsc | 2 + OvmfPkg/OvmfPkgIa32X64.dsc | 2 + OvmfPkg/OvmfPkgX64.dsc | 3 + OvmfPkg/OvmfPkgX64.fdf | 17 +- OvmfPkg/PlatformPei/AmdSev.c | 84 +++++- OvmfPkg/PlatformPei/MemDetect.c | 13 + OvmfPkg/PlatformPei/PlatformPei.inf | 5 + .../FwBlockServiceDxe.c | 5 +- .../QemuFlashSmm.c | 5 +- OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 23 ++ OvmfPkg/ResetVector/Ia32/PageTables64.asm | 216 +++++++++++++++ OvmfPkg/ResetVector/ResetVector.inf | 4 + OvmfPkg/ResetVector/ResetVector.nasmb | 6 + OvmfPkg/Sec/SecMain.c | 103 +++++++ OvmfPkg/Sec/SecMain.inf | 3 + 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 | 11 + 60 files changed, 1970 insertions(+), 80 deletions(-) create mode 100644 MdePkg/Library/BaseLib/X64/Pvalidate.nasm create mode 100644 OvmfPkg/Include/Library/GhcbRegisterLib.h create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/DxeSnpSystemRamValidate.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/SnpPageStateChange.h create mode 100644 OvmfPkg/Library/BaseMemEncryptSevLib/X64/SnpPageStateChangeInternal.c create mode 100644 OvmfPkg/Library/GhcbRegisterLib/GhcbRegisterLib.c create mode 100644 OvmfPkg/Library/GhcbRegisterLib/GhcbRegisterLib.inf -- 2.17.1