From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=Af4Gg73w; spf=none, err=SPF record not found (domain: amd.com, ip: , mailfrom: thomas.lendacky@amd.com) 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hz0rVTIw9pEWH+p8YWyumJTnIWRaqgpBpBl4rPkYBVU=; b=Af4Gg73wSSozIMl6Tig1AfXbOaES5W37s7quh0VmrsdPcG+dEIXb+o4hMyZEXVViKpMZQNGRGehzc1RHOzLSUnsB5JN9TEFD+LAue1trhFnY9q81GiYLaIDxni9IToDOromDigbJ+tn/WBLUG7bXNHrNLs44OnOyny4Ik0PFRAo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; 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 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: [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> X-Mailer: git-send-email 2.17.1 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) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 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-Mailer: git-send-email 2.17.1 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; X-Forefront-PRVS: 03818C953D X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3163.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(4636009)(346002)(136003)(396003)(366004)(39860400002)(376002)(16526019)(186003)(8936002)(8676002)(956004)(4326008)(316002)(6916009)(86362001)(2616005)(36756003)(26005)(52116002)(7696005)(5660300002)(7416002)(2906002)(478600001)(81156014)(966005)(66556008)(66946007)(66476007)(6486002)(54906003)(136400200001);DIR:OUT;SFP:1101; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; 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 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 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/PlatformPei.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/MemDetect.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 (PcdOvmfSecGhcbPageTableBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableSize), + EfiACPIMemoryNVS + ); + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbSize), + EfiACPIMemoryNVS + ); + } #endif } -- 2.17.1