From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.46]) by mx.groups.io with SMTP id smtpd.web11.40.1622070700168787057 for ; Wed, 26 May 2021 16:11:40 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=K+gwcgHm; 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.223.46, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mSRE3IQHOi0D5jTmquXGEOq+C7R9rpiN2sXaXbThnn+6eUJq3zzDzUExvWkTzNvOZeE1cEHtnJ15moYi3n3KDx4Lnw0qqGfTDHCdA6D859RNjaNyD2j4XNj8xRz+34JW7PyB5HdLpdPoGR/ldQsVto5DF+lC/Du09ZROJX5guxi0MxQHkpWgJ3qoC6dhpevUMES9jKEzBQZj+qP1F9mGYIashHfT0BmsXE1CnZtRFE08RJss+YiR6ciU2U+oMFo1t+ZtDXMHrZ5yTzTE4hnLOopM3jPK2Jd/e3b9NHdzk/r0Qq/FFbK6r9M8KEG6vaWnteMG+ulrblXa0o2Mw9AkNQ== 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=pAQ2yzaG2DhwzMX+Xt8/fWYBLyWYAeB9iYtrckZ1LGA=; b=YT6pdNou0NSHwpSd7zoLl78S3ZLxtrsmfTd8Rq3QYEnHdyjK5sghkloeBhxvq3d68uCqpF2L2HCOvmfuRmmyQnlki2Upy3hUGEl0dEnYDKg2WQuBMfTsWszQ/tAeJmq2DlpklGS9ZmL6/QIxhuQysj5qCsYmag9SBafoPrDskGkzNbUBXhCTao7rvkF6b9ibrPAWBR3RcyyZIA202WSWRxy/eyCt/YxhiLra44f612EGgRZDrY/KZeuMNvxyYX+LOcEIou7GKiNsXmszNAlUMPXTaM8/BUFE91w6kkdPqodL05dQ4m6j4fjX2OPeNSD71bIJq1Uhoj9g/vkVuyrcRA== 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=pAQ2yzaG2DhwzMX+Xt8/fWYBLyWYAeB9iYtrckZ1LGA=; b=K+gwcgHmJhzYtaRtEncCexbQY/OJy8eTdIMx1BIvGrdvcHA25S8TJQssxdqZhY+7Oqp6/E7svDU3uz509zXCKFyza6ktJAeBQGHGQa/Y5nIzweRqc3wGnWm2+yLGxnu8HCjLvJFd+T8/wAs9rPSrCbEtnmbVn8y0R7VE+2k+8us= Authentication-Results: linux.ibm.com; dkim=none (message not signed) header.d=none;linux.ibm.com; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SN1PR12MB2543.namprd12.prod.outlook.com (2603:10b6:802:2a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Wed, 26 May 2021 23:11:36 +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.4150.023; Wed, 26 May 2021 23:11:36 +0000 From: "Brijesh Singh" To: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Laszlo Ersek , Erdem Aktas , Eric Dong , Ray Ni , Rahul Kumar , devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel Subject: [RESEND PATCH RFC v3 00/22] Add AMD Secure Nested Paging (SEV-SNP) support Date: Wed, 26 May 2021 18:10:56 -0500 Message-ID: <20210526231118.12946-1-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0202.namprd11.prod.outlook.com (2603:10b6:806:1bc::27) 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 SA0PR11CA0202.namprd11.prod.outlook.com (2603:10b6:806:1bc::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.21 via Frontend Transport; Wed, 26 May 2021 23:11:35 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6e384ac0-74c0-4b0c-34f8-08d9209b9bde X-MS-TrafficTypeDiagnostic: SN1PR12MB2543: 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: tT1J0ZdW67q/x99R6tB+Q/GHnhIs1y/R6KHF/5zAFSNI1F30514+4w5T83dEtPGbDX+S2QqPPbwegZgifv7u8VQ2YzqtOYemUq9wj/RsGloMhJUjfExiE4X/U8BL1jWRePN2eUKkuCbGP4+MjO2XkdL8FVrjkJFo0DxI11R5K+zHVabiYkdPS1jO+wRdyh9kHIJjOx/EU3330OHLRmNXETq+q0wNDrxwP0O2Qm0m4PjFlOtT83SGjBNizV/g0GXQ7DjxW2eWK1bscqwXGAMIsxbF2POdkuMsMBE/M2jKrY1naIilyk1Dz4nWs+tt2IPHmLxJCZ/P8qC5s1spRN1Q3/zyOx2ncEeCpsKstVoESZ4T+fUdDtYfz6vIZ8rOkS5Zl0+RJt+cZcAmd54Jgb4PDgQ2pMrWflxl6O34B2i6WeHSm/kE++NreegM0tKXUivHp9gHVg+dcwt5q0aGXEcUzQ7OJieXyZtzUFpWuXrrylH2kQXcN1HOwuwg/u7dFwCmIAWWcs1+70hz6RvcgcaWCbUFcI27AsQjQhYbNXXRtxahufqta5Div0fb/iB+BfMYeNKBqNTQivGZVv3rNyMbsizdlilIkucIetxAJ1rFyo45ooIyCmFpGM4+ztUkKe8mDkOXwIGnAoOacGGiFMk39XA14UxeshXwlkr3sPFf+9D1pcbZuKFAatDZ9CK+Qy1c73MP2hx+G5FyyEVI5xexBpAwklUbrr/zR9M2AzuWrIkgAHy/pgpblIS+BHyGmEepz3+ejewIruIvZz0CQfDl9IoCzwCLlfUx4ZayF9nS5o8= 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)(39860400002)(346002)(136003)(376002)(396003)(966005)(8936002)(2616005)(956004)(52116002)(7696005)(83380400001)(6486002)(921005)(16526019)(7416002)(110136005)(26005)(478600001)(36756003)(44832011)(54906003)(38350700002)(8676002)(38100700002)(316002)(1076003)(6666004)(66946007)(66556008)(66476007)(5660300002)(186003)(2906002)(4326008)(19627235002)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?51JaVH8/paWAoPjlvV+cu+eFvlDL3UtN/1SCl0jsB6pLJ4jskQzw5MONFkxP?= =?us-ascii?Q?lnhjhQz4xcQ7w3cWcN+vEh6oPNoMVf/TolzK6iYw6uW3o5mLwF/smbg+IBOh?= =?us-ascii?Q?7SgBzYlCbWKufBuzat/T3W79RZCSGO/DWe3ZT1bs++SeN6YjJBF0erGGmJHf?= =?us-ascii?Q?udSCbgrnuG2Pz5RnbobPyBhN81lpASqcg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7q4nKLXMLsi8/7Q0RDb3LmSnQGGSg5waBb5DB2ccaLiGsT4KW2z8OyzfD?= =?us-ascii?Q?3I+phU1OUc0XvRz6QbdXtGO6LFtW4Na6TMcMYq6Nk9e15o7+ooL/TZAGUYE2?= =?us-ascii?Q?cC2DZELUEeihkkmnhXGVhx+nVA+MVpT5WqnBiUZAk4ezORi6WPr9LA+cl22P?= =?us-ascii?Q?paI5mLVCwrUeHt5TVX8PCdkZInk+Df5zy78k92LYY4Qpd57xMBSVT2s+q5HL?= =?us-ascii?Q?qjS5V31on/xWMdqDMX4xaThn?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6e384ac0-74c0-4b0c-34f8-08d9209b9bde X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2021 23:11:36.1193 (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: s5F89SkUaXF086yzMU1F32LW+GSjy1V3kjEi6cjtfcUZc/czXD88bf8Ny1dPlwE5X+f6J7Y0E4HDJF6Aj2wTNQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2543 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain (I missed adding devel@edk2.groups.io, resending the series) 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 The series builds on SNP pre-patch posted here: https://tinyurl.com/pu6admk= s 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-2 GHCB spec: https://developer.amd.com/wp-content/resources/56421.pdf SEV-SNP firmware specification: https://developer.amd.com/sev/ =20 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 v2: * Add support for the AP creation. * Use the module-scoping override to make AmdSevDxe use the IO port for PC= I reads. * Use the reserved memory type for CPUID and Secrets page. *=20 Changes since v1: * Drop the interval tree support to detect the pre-validated overlap regio= n. * 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 MM= IO ranges. * Pull the SevSecretDxe and SevSecretPei into OVMF package build. * Extend the SevSecretDxe to expose confidential computing blob location t= hrough EFI configuration table. Brijesh Singh (21): UefiCpuPkg: Define the SEV-SNP specific dynamic PCDs OvmfPkg/MemEncryptSevLib: add MemEncryptSevSnpEnabled() OvmfPkg/MemEncryptSevLib: extend the workarea to include SNP enabled field OvmfPkg/MemEncryptSevLib: extend Es Workarea to include hv features OvmfPkg: reserve Secrets page in MEMFD OvmfPkg: reserve CPUID page for the SEV-SNP guest OvmfPkg/ResetVector: validate the data pages used in SEC phase OvmfPkg/ResetVector: invalidate the GHCB page OvmfPkg: add library to support registering GHCB GPA OvmfPkg/PlatformPei: register GHCB gpa for the SEV-SNP guest UefiCpuPkg/MpLib: add support to register GHCB GPA when SEV-SNP is enabled 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/MemEncryptSevLib: Change the page state in the RMP table OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address OvmfPkg/AmdSev: expose the SNP reserved pages through configuration table MdePkg/GHCB: increase the GHCB protocol max version Tom Lendacky (1): UefiCpuPkg/MpInitLib: Use SEV-SNP AP Creation NAE event to launch APs OvmfPkg/OvmfPkg.dec | 21 ++ UefiCpuPkg/UefiCpuPkg.dec | 11 + OvmfPkg/AmdSev/AmdSevX64.dsc | 5 +- OvmfPkg/Bhyve/BhyveX64.dsc | 5 +- OvmfPkg/OvmfPkgIa32.dsc | 2 + OvmfPkg/OvmfPkgIa32X64.dsc | 7 +- OvmfPkg/OvmfPkgX64.dsc | 8 +- OvmfPkg/OvmfXen.dsc | 5 +- OvmfPkg/OvmfPkgX64.fdf | 17 +- OvmfPkg/AmdSev/SecretDxe/SecretDxe.inf | 4 + OvmfPkg/AmdSev/SecretPei/SecretPei.inf | 1 + .../DxeMemEncryptSevLib.inf | 3 + .../PeiMemEncryptSevLib.inf | 7 + .../SecMemEncryptSevLib.inf | 3 + .../GhcbRegisterLib/GhcbRegisterLib.inf | 33 +++ OvmfPkg/PlatformPei/PlatformPei.inf | 5 + OvmfPkg/ResetVector/ResetVector.inf | 4 + 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/GhcbRegisterLib.h | 27 ++ OvmfPkg/Include/Library/MemEncryptSevLib.h | 31 +- .../X64/SnpPageStateChange.h | 31 ++ .../BaseMemEncryptSevLib/X64/VirtualMemory.h | 19 ++ UefiCpuPkg/Library/MpInitLib/MpLib.h | 19 ++ OvmfPkg/AmdSev/SecretDxe/SecretDxe.c | 22 ++ OvmfPkg/AmdSev/SecretPei/SecretPei.c | 15 +- .../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 | 230 +++++++++++++++ .../Library/GhcbRegisterLib/GhcbRegisterLib.c | 97 +++++++ OvmfPkg/PlatformPei/AmdSev.c | 81 ++++++ OvmfPkg/PlatformPei/MemDetect.c | 12 + OvmfPkg/Sec/SecMain.c | 106 +++++++ UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 11 +- .../MpInitLib/Ia32/SevSnpRmpAdjustInternal.c | 31 ++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 274 ++++++++++++++++-- .../MpInitLib/X64/SevSnpRmpAdjustInternal.c | 44 +++ OvmfPkg/FvmainCompactScratchEnd.fdf.inc | 5 + OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 23 ++ OvmfPkg/ResetVector/Ia32/PageTables64.asm | 227 +++++++++++++++ OvmfPkg/ResetVector/ResetVector.nasmb | 6 + UefiCpuPkg/Library/MpInitLib/MpEqu.inc | 1 + UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 51 ++++ 52 files changed, 1956 insertions(+), 38 deletions(-) create mode 100644 OvmfPkg/Library/GhcbRegisterLib/GhcbRegisterLib.inf create mode 100644 OvmfPkg/Include/Library/GhcbRegisterLib.h 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 OvmfPkg/Library/GhcbRegisterLib/GhcbRegisterLib.c create mode 100644 UefiCpuPkg/Library/MpInitLib/Ia32/SevSnpRmpAdjustIntern= al.c create mode 100644 UefiCpuPkg/Library/MpInitLib/X64/SevSnpRmpAdjustInterna= l.c --=20 2.17.1