From nobody Fri Dec 19 17:40:35 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+57860+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 158757736881067.22404792288762; Wed, 22 Apr 2020 10:42:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id BVnnYY1788612xiGeHfb0z1p; Wed, 22 Apr 2020 10:42:48 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.483.1587577366746588780 for ; Wed, 22 Apr 2020 10:42:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q1d+/wj8C45RI/rW1n8ddH4nbPjvhh2VZEvCmHLufTwFG2Ojm1MulgunqThhU1CMWVcLGfslk+pBVujzfuySaTIFXiI53IFJPjJEy7PW9jpl1g2e0yBinOZfnDOArsHKTrj7Q3WtiYKftFHwqhIYnqBpBOQAMVQG3PK0Ixk7NfYxleSxQ4RYKS3zjFqFknxF20GXSLdI+gDsZSb0odZyxidNqhI1XJoBhzZsbu1v78jqQgV5acB8lPzUBa8REN2tIU7o3k2SpLUkWLtYCpa2WpBR6GqyBOVxqCBvRuql//urKrUUDA6nIDjxxFILwKKY9f88egMRGhnetfVVHV63WQ== 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=hz0rVTIw9pEWH+p8YWyumJTnIWRaqgpBpBl4rPkYBVU=; b=cpnKBmYkIJXy24nowL/ipEIg7p328U3agaQya10SrZBc6E/lkzn04iX0LekJS0PztTxCLwzEX1M2G4Jymmtnem0sPD85dAHaS+vYtDBqmCulo6ooFcHwVPyk6XmnDTFbRGh8t16Tdec1KH8zHrHMnOGbQY1/tReMIDfwSOzHosUdK+cSvKxfDzDu6Qi+4tsvbt3CGhCjWMcEsOXA6BWPQ9JLJuf4p/orvJwaMueu6/evYG30s84M59mtRFftfC2/VccuGecGP2/Yi4oP+t77mq0/KmOVdATGtP60rx5g33YlSbFPYnPOu1Vb1vOsQQnxDTh52wT9TEAsoLMCxjiHWg== 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 X-Received: from DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) by DM6PR12MB3673.namprd12.prod.outlook.com (2603:10b6:5:1c5::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.29; Wed, 22 Apr 2020 17:42:45 +0000 X-Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf%4]) with mapi id 15.20.2921.030; Wed, 22 Apr 2020 17:42:45 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v7 29/43] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported Date: Wed, 22 Apr 2020 12:41:44 -0500 Message-Id: <13831d3a85c50dad962bf75cdcdc301ae4572775.1587577317.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0060.namprd04.prod.outlook.com (2603:10b6:3:ef::22) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR04CA0060.namprd04.prod.outlook.com (2603:10b6:3:ef::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Wed, 22 Apr 2020 17:42:44 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9a51bf2e-ad45-4733-d24a-08d7e6e490c8 X-MS-TrafficTypeDiagnostic: DM6PR12MB3673:|DM6PR12MB3673: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+57860+1787277+3901457@groups.io; helo=web01.groups.io; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: O5Bt7cMgTCudsvXOAPAQOvqB4DEgH50araKG//GtOzlIDXJFju4tiH6I6BAQ3M4j2Fy43Zmahe8CNDrzlmJdV0s1JHrFNMiA7lYoaArc9WqC2sRDKMXxGB8TxR6L+SKm8CfUz3oDDcPIc8yD62aw2xeXSGxC+Pq+D0U8XP0jWUrUkwPLrnE4IMS6v0u+vOp5KK45RXMky2Bznap4iy09SHoSh/NyGqOZjPBXZQ4vlSYisa368vFFi0bBtCybbZR/MXIUjScAUIaGaYtD71XFX20y8xRYIoq8EM8KeQoZhxP3nalEkOSxxkujYWhDU/aFDP5Kb+Pix4OHZxPksK6MPuuR51AeTz58rxeHjhSYSlUF9Q8uDa0/6m4h1DNGtLoC+sdkzUdMfjvpyuJPmmY1500sINucY6dZvFfLCZ9JwiOfDgsqKgHOH91rO/TqbXeeTTDB6VNeNjVpWYLBO7UhlUg7R3RDRw6SsfweUIc+NAJUxPqYBtq1KN6pOJ+IK1Z4e21dMt4Bza/Mdts3JiJ7Pv2f6euHrXo2IOMOYWlz1isxeEueaNlql5ObbRt7Wj6Ovu7nY4JAgokPngDVZlG/ag== X-MS-Exchange-AntiSpam-MessageData: X9zaxiWWetA10Pkdw4hztx82gviBDh6PHWZw4JuvKpGKu3v0R5C0xw+uyjRAl3/LeQjoovotpfu8rHcQKgr35e2QwELAF8bSJGYNM0T4ieYgbMhE001+7bi+f9FvapWowAcrgLLhV1x1T3tWOt7oOA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9a51bf2e-ad45-4733-d24a-08d7e6e490c8 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2020 17:42:45.3875 (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: aB6m3H+a1XUeipdYXJk86yyceFau3zCBCfIeuGVqo6XK3q2dDr3at/xoQ1LFaWkMhVIFfi55zoxzDRMVJAGLwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3673 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: kTARXqAmMydgFSoF0DLTs0Q9x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1587577368; bh=czf5sL4+js1pZh8boghb3M+54JfkIzi09+GomkxD/x0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=I7Hiiq+M3mfFmoRhyCGVJMCgJseQZlj2+SCAzCw1igtf0Zh8ZqWULCfDtUVG0F2QpNu 02PEQB6F0gxV3hzjku4tsEWhlxb1Uu9BxGNLwNofu5EhhEuAKTi26qa6fMyfep8QJw3Zd /1AuYYN2h6uNnTQI57HALDLOaM7VfJhlvnk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Protect the memory used by an SEV-ES guest when S3 is supported. This includes the page table used to break down the 2MB page that contains the GHCB so that it can be marked un-encrypted, as well as the GHCB area. Regarding the lifecycle of the GHCB-related memory areas: PcdOvmfSecGhcbPageTableBase PcdOvmfSecGhcbBase (a) when and how it is initialized after first boot of the VM If SEV-ES is enabled, the GHCB-related areas are initialized during the SEC phase [OvmfPkg/ResetVector/Ia32/PageTables64.asm]. (b) how it is protected from memory allocations during DXE If S3 and SEV-ES are enabled, then InitializeRamRegions() [OvmfPkg/PlatformPei/MemDetect.c] protects the ranges with an AcpiNVS memory allocation HOB, in PEI. If S3 is disabled, then these ranges are not protected. DXE's own page tables are first built while still in PEI (see HandOffToDxeCore() [MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c]). Those tables are located in permanent PEI memory. After CR3 is switched over to them (which occurs before jumping to the DXE core entry point), we don't have to preserve PcdOvmfSecGhcbPageTableBase. PEI switches to GHCB pages in permanent PEI memory and DXE will use these PEI GHCB pages, so we don't have to preserve PcdOvmfSecGhcbBase. (c) how it is protected from the OS If S3 is enabled, then (b) reserves it from the OS too. If S3 is disabled, then the range needs no protection. (d) how it is accessed on the S3 resume path It is rewritten same as in (a), which is fine because (b) reserved it. (e) how it is accessed on the warm reset path It is rewritten same as in (a). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/PlatformPei.inf | 4 ++++ OvmfPkg/PlatformPei/MemDetect.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index c90b5f7ae200..c5b92ab4afd8 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -73,6 +73,10 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 47dc9c543719..200021098161 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -27,6 +27,7 @@ Module Name: #include #include #include +#include #include #include #include @@ -860,6 +861,28 @@ InitializeRamRegions ( (UINT64)(UINTN) PcdGet32 (PcdOvmfSecPageTablesSize), EfiACPIMemoryNVS ); + + if (MemEncryptSevEsIsEnabled ()) { + // + // If SEV-ES is enabled, reserve the GHCB-related memory area. This + // includes the extra page table used to break down the 2MB page + // mapping into 4KB page entries where the GHCB resides and the + // GHCB area itself. + // + // Since this memory range will be used by the Reset Vector on S3 + // resume, it must be reserved as ACPI NVS. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableBas= e), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableSize), + EfiACPIMemoryNVS + ); + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbSize), + EfiACPIMemoryNVS + ); + } #endif } =20 --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#57860): https://edk2.groups.io/g/devel/message/57860 Mute This Topic: https://groups.io/mt/73201930/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-