From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.13468.1574280464489331508 for ; Wed, 20 Nov 2019 12:07:45 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=R+6/wKMR; 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=B69chEOZsvxFp4ymVQkFSfWb2X18OqBwa1ISI9S/5x+R8z4aleHzqYmTkDNOml1mCPZgGSJHQbiB7jLJ21HIDmjHBHwuAP6Hm/2O4WmIqykrAtw9W25R/o1QtliDGBpQVkL8MR/2VahoKpICe3gjjnrV2rjnA//HS7Fdoi6kSgL/8HSpX4/2JyGfGAh5JmOyx5t96k3iAZTIwMRWq/WZojujpCNs8pcZ6ZCGWAexlg7tWkuXGE5OSpSkMZqgKS+3kQpivb5zWTViriy5e29AKzaS+Mhk11j3r9c/L0hfEKqsS48/N/U+qaJG4L/c/aiH65EMD57Zqtu6/jlLSbHj9Q== 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=AzSaOo/iKZ505Tkjv6NszQYBACZmMr+D5P88y9tpnFg=; b=So3bRwzyA+p58b7spx3e2zKFWoC3ZIKEtaWSkmdstrI0ioQiRa7ie4F9MXjJDnVrM4t76q02Ux1ElieYxNO4dDrfYdHWogK0qGc99ZFH7nz/v8SjCRmG22+v+Qpnld1afXopEKmWLCeg/Psc8Y1DpgGTfCnq8eF3z33vfFSroyfqF2T9T7CHnsz0WB2Gd8/ArSuSQV9e48ll8Py7QIv4bmvMmiV9UW6Tn2mT9eNbehlvNdzBrgFMpeb+sHUZ6TtWm10nvFQw8bY9OtJAycU+vXRsAXSlB4SPgviR3GZmdsYelCYdX5OjdJETtAMsDrW4/BUWU0YnmaY99eH+51Ax/g== 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=AzSaOo/iKZ505Tkjv6NszQYBACZmMr+D5P88y9tpnFg=; b=R+6/wKMRH//eIV8gBmENz5N19D4HIA9HCCfKTK7c/MhEw9H0Fh8/Yku57tEfscWmVB+Ct+OdAu2w7+M83lqxpqjyhfSGksvVPU8xU5KeYktkMUZMnpc7ZiLHEd5ELOjQtALXd3fQHrvAIYViLb8Kg/S5I42EMPzJXp8QfLX8AIw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (20.179.71.154) by DM6PR12MB3675.namprd12.prod.outlook.com (10.255.76.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2451.28; Wed, 20 Nov 2019 20:07:43 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::dd0c:8e53:4913:8ef4]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::dd0c:8e53:4913:8ef4%5]) with mapi id 15.20.2451.031; Wed, 20 Nov 2019 20:07:43 +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: [RFC PATCH v3 27/43] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported Date: Wed, 20 Nov 2019 14:06:49 -0600 Message-Id: <79d9835bcada36a92b5bcb5ad4347647627a7dd9.1574280425.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0087.namprd12.prod.outlook.com (2603:10b6:0:57::31) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 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: 3ad99860-3eca-400c-4314-08d76df54dea X-MS-TrafficTypeDiagnostic: DM6PR12MB3675: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-Forefront-PRVS: 02272225C5 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(1496009)(4636009)(376002)(346002)(396003)(39860400002)(366004)(136003)(189003)(199004)(7416002)(2361001)(50226002)(81156014)(81166006)(8676002)(2906002)(6486002)(99286004)(66476007)(486006)(47776003)(66556008)(25786009)(2616005)(476003)(54906003)(11346002)(118296001)(8936002)(316002)(2351001)(7736002)(305945005)(66066001)(6916009)(86362001)(16586007)(3846002)(6116002)(48376002)(14454004)(478600001)(5660300002)(66946007)(446003)(76176011)(36756003)(51416003)(6506007)(386003)(50466002)(52116002)(4326008)(6436002)(14444005)(6512007)(19627235002)(26005)(186003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3675;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A: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: VxTatn1dQittNMzDJMMu+DBF1qAOk8jAJww9Y0sgzoPcNl2at75sxfVSrkB9bNyivVhWfVgZ3Ru4mOg2qTLWma583KAZbHwAzzPOlpWBP4YWXmyvzaGd3fwScL+FvW5t4iXtVyaq+z7ZaiIZ8DmNZblmDapRy55QY59HSgWsjjxXhaOJ7fPuWdO9el5exGbbbQl8JZEV31KqBjc8pWWLwoHT0sWEn/3H2qd0b/Bn14Rr9jDEKox4CDjtFDAmGrr76VB2GSr8ygy39nuMX7OyIO1/y8ef3TiAg+a5ov9rfdo4MLrJyylYAZicC/mINVi7SaX+cxmTONv2jaoTPMHU8egeVRFJCNcaryyyzn9rwnfwmIkBuV2/U1Tqzm1hCZDrt4/+y7QXDY0ijx2hFabTS6olgF89wnYQUr9i8/JmRjCrMgLdvJxN25HYOEpNgPwI X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ad99860-3eca-400c-4314-08d76df54dea X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2019 20:07:43.9177 (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: 7sAJS7sJz6k3PM7u2LKQuHdB2WcHvUclxPAqSFNFSdrF7M9ICyBokqYHVG+Uamw9YOPpdZ29FpzShz6P3KfO1A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3675 Content-Type: text/plain 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 031154389426..920b619446f0 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -72,6 +72,8 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize @@ -96,6 +98,8 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask gEfiMdeModulePkgTokenSpaceGuid.PcdSevEsIsEnabled + gEfiMdeModulePkgTokenSpaceGuid.PcdSecGhcbBase + gEfiMdeModulePkgTokenSpaceGuid.PcdSecGhcbSize gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c index d451989f31c9..677e65e86d7b 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -26,6 +26,7 @@ Module Name: #include #include #include +#include #include #include #include @@ -805,6 +806,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 (PcdSecGhcbBase), + (UINT64)(UINTN) PcdGet32 (PcdSecGhcbSize), + EfiACPIMemoryNVS + ); + } #endif } -- 2.17.1