From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.63]) by mx.groups.io with SMTP id smtpd.web12.5657.1595366632766196578 for ; Tue, 21 Jul 2020 14:23:52 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=0RXnyu0X; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.244.63, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OvrTd+70sL5wJPAe3WWdmflJ0B/Ny45EDhPsqhXTKJpA+CAnU+WNv/ll2yvS0GeNneoBrKe3A8kxAiXQ/YP2Cnjn/jPAX6v94q/sADauCJbsAUdh2/SgEiKrk5f26R/4we4y/HzdvREoseEguHLSlXspfnWMrQ5bFBJo1EjpqS38Jbb2nKEk+1O70n+zCCPm4WLH1m0ysH0lE/6C6h8G6hpCK3oC5al7s0F+OcIyQNFVXFqNQjOyUPyKlDD4lJnWMy2WkZW5Qk5SiivAQqX8pWjUUXOakpzqqSqKpJ4/9vVZPe7jnF5KlhdCTP9NaFCtEvayuNl9CMOuixiJotVbMg== 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=JR+MS9LL61uEdrhA9WIjPAHChgJxbHnfKw/wTMqc9/Y=; b=lUhSkYWu1MmrEy84AM1StHR5itgjGOcNR3ah81Llby6nkGMEnH5761I1/B6nWvu2MPOsKDbxqMeaw4obnDOINtWLL9YgtPCl4j1RyCTCvTz/JAPYbcaxd1uGBlIJem0zumQgpBBZon85Ma8UeB2H9nr6VC3X5unlAvyRptskjyGVJR/qNBZHTSbSyzi/FolZOFdZNPcqEHlaQRrSRxSFf87CQHiy9MnBteDtBiKaOpyYHt2zDZgXixWDtYyuwkb4jaNDpko/1HJ2wDRNcRbDoQbHRqCo+So6aDs7j5fK2GXL8wt/Yw87xEJHm68Ph+iVLsxN8i+nyHcrpShN49ByQA== 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=JR+MS9LL61uEdrhA9WIjPAHChgJxbHnfKw/wTMqc9/Y=; b=0RXnyu0XxIP2OwUCNsNiahYLW6teqXdvGCydOjtdNgGL9wnJQ6AoBRNCuCy6VXDJ0UV9oTcGUViNexCm3jqJrxHTSvMnJccClMO2K4RciUXc1BUDvF2CQ5P51S3dBgGH5BS6VV6Qg4UHHzr+ptB55R7kkS0NCNwogG7cClt8ePw= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1143.namprd12.prod.outlook.com (2603:10b6:903:38::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.25; Tue, 21 Jul 2020 21:23:51 +0000 Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3216.020; Tue, 21 Jul 2020 21:23:50 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Anthony Perard , Julien Grall Subject: [PATCH v11 30/46] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported Date: Tue, 21 Jul 2020 16:19:07 -0500 Message-ID: <9b3188da79b85f740f0f56bdc1c4673dbd252bda.1595366363.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN2PR01CA0003.prod.exchangelabs.com (2603:10b6:804:2::13) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) 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 SN2PR01CA0003.prod.exchangelabs.com (2603:10b6:804:2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Tue, 21 Jul 2020 21:23:49 +0000 X-Mailer: git-send-email 2.27.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8da1f088-68b8-4698-9579-08d82dbc5c7d X-MS-TrafficTypeDiagnostic: CY4PR12MB1143: 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: YL3gAVDApOgpEtM8DzsYZIsFTJ1jZ0UjkiSUN7qISSDC56yiPDK95t2x6J8krdbj+K2mZiU2FR8/1Sdu5V53gyZvWtuiATwMeumLBpLFR0VN8qjK6cpDpA9tGBRXcIKxf5VDSO/5QNR6p0fSAuetLpLkO95A3b8zDh2/Y5ikpzKfgu8E6i028osQCxy11/GDqmV5UJMQfmzZkbjtvRs4pLJLUoGdR//k0TFFU5J7GF5UMDCPNd4/gN4SnZSEoxq/JSqjO8EWpXSWz9JZsR+V+jgmXO7hz27zZ0RwhGVmCoQjSF2czq3hhtDP7uzfw4TknLW1B2hp498FuWAdFuVw3P5RABugMzl+hsYuPc+UXVJOm+zLG8pD7uuT2np/Ltsy2slaI86A0Pr0bocKHLdyW0iaACd7OZueBuRUTpn4byToPvasrDU6PUanKKqvrbRjhDYksaUtadX+LgOWElWdRQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(396003)(346002)(136003)(39860400002)(376002)(366004)(966005)(6916009)(26005)(6486002)(86362001)(8936002)(2906002)(66946007)(36756003)(8676002)(16526019)(186003)(7416002)(2616005)(956004)(54906003)(478600001)(4326008)(66556008)(66476007)(7696005)(6666004)(52116002)(5660300002)(83380400001)(316002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: jsxhZJhkfjD9+TpkbMCg1l2/8x7GL9cgz777Mag0c0aSMLq01hl7ObRRVmcbHKYvYte1LeeIFBl4fktsuTcaiEUwotklkqYdPdqtlSKXQvlrujd/8/IP/af8mg/btfj6cmKjj/4UBa5kpE7NWBCizNxUFaWnWToU4hnRuiLhQ8JvFbkqCz6nm98xy07qXj2u669V86hSFIEQrUaWMpFXeCjZLJT1yfGzGBKu1ml+cFzgRyuvCHyTFFgKxxSFVFsaHUGlsjhjEFCb8BC28+h++Edx13QgOpnc5aM4QvThiinG0SApNxj9FknN4wNu1TlV8c7MxLixhAzDuC9ccd24pIHu24TLhTIW3l788OF0jCfK1LYOA1iazy5VWbtSxpR/lmq6PLbZXwoa7b8iuCi2+XwUEuO7TiYnTcMu5UvA2Jfc8mehJ3pXwJLBvIfulDxPQD9ooC0/lHlBdrT4CxTMvlFkP4DOZzPeLM+GMwoGNuc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8da1f088-68b8-4698-9579-08d82dbc5c7d X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2020 21:23:50.3560 (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: CLEgAHEEWkgO/9EFg9jNKuyfgtESp+SoXjNgteLA3TM0UyvOxvHtOSDfwv1lyk/+u2L4CFRoCa1FFptrJ5m4iw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1143 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable From: Tom Lendacky 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 00feb96c9308..a54d10ba90d5 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -75,6 +75,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 3b46ea431ade..6b5fee166b5d 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -27,6 +27,7 @@ Module Name: #include #include #include +#include #include #include #include @@ -866,6 +867,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.27.0