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 []) by mx.groups.io with SMTP id smtpd.web11.694.1583190475799820802 for ; Mon, 02 Mar 2020 15:07:57 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=nCzPryB8; 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=VE29n/wNUVzknkjEY3I9a/njGTtF0lelkVrfhE5kh2W7qoNw6XhkE59r/RsvecPKHi82eQQZHeTbvM9tlQ0bqrjMbUl4S2LgwBzo4JT+m7qzDaolfnHcZN8cEEDoFwg6fnD6r3G5nZ+AVh7xvrYxY7PV6g5AwIsE9uuaLsqQb/Y/3pOFAdnv1tNWbekfTbk6M5HSzhsZMATQEokRuqi+ZsYJlsyyfveH7gIpaPXPaJE2bw9MbXG/FVj6UTnzD9ivbZOOBzv277vH1mEGxXtHYceGOtyfoeyoZ/+YYcIG3s4m4XYQjle+OPKDOZ8l8C9KP2cjGXrozEf71VFwyK4Wbw== 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=rMRCz7KGJqcAtGEKhWJMN4hJxH87cmXbRZ+NDbs53rM=; b=lCvkgMgYHat/EOFZfK/c/WcRfs7n5HQ65lMpCk9+zTZEGzmnajqz0S56cay8of4Yy87vZJ18dY/hF500QvdzBM4jeWZb1S2wBxwI6Kxx52HNu4R7JTevI3CeYx6znwmxVIOUK6ifhZ7U/eUZUs3ij6DHKj+UDqNnLH6ysFficxwY0AuvFWQT9cbsBWnpFUt2WdyPC/qMmsZ5D+iTwjCYIt4T91eYgVoDak18K9iiD3vSui5Iu7wArUZfZS4xyY1ZnmW9W8dAGgRU5Bz9aA+W9qNHTM15Vai/ENm3/4/9Hp7kz/7/PzBMFuWS6mg7sDlzDIH1obQjfACH9BWwDPXu4g== 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=rMRCz7KGJqcAtGEKhWJMN4hJxH87cmXbRZ+NDbs53rM=; b=nCzPryB84fLUTFnGYsUoAHMPjtIPg0lb1fFCozpyPlUs1rAJseUAWD/TRZL2VK5Dw1mkhYL8smG7+2NjfyVSQVzolN5NK5qcX+R5Zvj6kHJoGopWUzmpGDqAYgRwXzRyumo9CRPHwK20k1ge2b/lXVlZlh53dQwlhFIOWFsTWFQ= 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 DM6PR12MB4201.namprd12.prod.outlook.com (2603:10b6:5:216::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.18; Mon, 2 Mar 2020 23:07:55 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::f0f9:a88f:f840:2733]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::f0f9:a88f:f840:2733%7]) with mapi id 15.20.2772.019; Mon, 2 Mar 2020 23:07:55 +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 v5 28/42] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported Date: Mon, 2 Mar 2020 17:06:59 -0600 Message-Id: <93bcaf8d1044eef013ef631129f568fc7082655d.1583190432.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR2001CA0013.namprd20.prod.outlook.com (2603:10b6:4:16::23) 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 DM5PR2001CA0013.namprd20.prod.outlook.com (2603:10b6:4:16::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.16 via Frontend Transport; Mon, 2 Mar 2020 23:07:54 +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: c154625e-d1a8-42de-83c3-08d7befe8aaa X-MS-TrafficTypeDiagnostic: DM6PR12MB4201:|DM6PR12MB4201: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-Forefront-PRVS: 033054F29A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(376002)(366004)(136003)(346002)(396003)(39860400002)(199004)(189003)(66946007)(8936002)(7416002)(54906003)(316002)(81156014)(81166006)(6486002)(6916009)(66556008)(8676002)(4326008)(66476007)(52116002)(7696005)(2616005)(5660300002)(2906002)(36756003)(186003)(966005)(86362001)(478600001)(16526019)(26005)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB4201;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; 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: h5xjiVpKXPLTO7XZkFhKuZsyCFQnWjLoDk/pPlBQIkLupw9jyqX3k4DWsmN+3+dSXmtyVDrXwc7hM9NGxYIQPJvTf9oFmGrBD09Iy4bXL9Mq+IqC/sQTWcKXH6wgmgt5MbQPxJx5J5V30YB7ew0s8sFKL+dI9OyEJXsFj5oDyFkslVo5I40Ge8w+CrO3fnOPPGm0Zg/pucCl9XY0KzqWFI+7ghehE6r/DTkFwXGKV4iPmcvuGnkJPjSagPzUNOsWrLTikfq2ilaxpvk+3OpM+b473jgThib2ZqL1OWhAXWzRXHoL0cdwTY2kcP8pNdZzfAlZcp44SRWxTpmT+cE4Db0/JCfZLOt59fxXhOxKyTWVwML+u6wwSoh1aPyOJLb9+3p5hgysv0STV5nVLK3ftaZB4QG5ZOXX+BVvbdQxsTw3RVjGdS1UnK9qSkay4h8mT2RbwJTJv7gmNZUZCVbnFuzyZPsKudxR28y1WUmDtlneAP8jqqld/qJGnKcRRsazKzZhOXLUksZTJTw03frLKg== X-MS-Exchange-AntiSpam-MessageData: suFfaHM+lNxVnMi/d5ztL0F/iJrZ3CBOX/Iwo9k/F6E33V2XnL2ep50cpWq6Vsfl/BhFxOTdsM9WFLy2I+GWvqrIRI6wyXwQ7TZ84f6nQKrBZOZkcdyJRQmxjh2UtBIYrIr/hwvwlQfr6TkP20EgTg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c154625e-d1a8-42de-83c3-08d7befe8aaa X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2020 23:07:55.5954 (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: jAFxDM1hM3lr9t8YWV5msAx87+DdXTDiYy/vi6dXMDIHsr9bBci0suMduIHCOxYkwttsjxqnAWrwAp/TDbOqww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4201 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 5b2585a4f09c..f1c2024526c8 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -72,6 +72,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