From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=Uk+LIuiv; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.80.75, mailfrom: thomas.lendacky@amd.com) Received: from NAM03-DM3-obe.outbound.protection.outlook.com (NAM03-DM3-obe.outbound.protection.outlook.com [40.107.80.75]) by groups.io with SMTP; Thu, 19 Sep 2019 12:52:34 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bm/vo3DRXbbyJ/nfGS9JwORiYWX5k34eYWWWF0jkR0dREfN/FC51o0Ijc5mUpjrJYOrajYQk+3wQy7G9CB7HE6DCtYjs3UuRxZmUg7OU5HVQaEMASdgaYoRRfTaHH9hahue/nLot1yy2phzrVRqCcR6tyqsSXrCqQxYOaNSBimpwR1W9aTVStXXlTJgYvxZ9QiDDCDSy304l7o27rt5yZhb3JXhhisufVin93ZpXHQa9aJnr9HTj9PTgvmaA1fV3bwo+Sgi0oC8gDCx0AaV1K1rvbjVK9t4wuaZyAdcRVP3xs0pkLsbd9fNqOkuCNcPBlItBQfsQT1Ub1etijnKjPg== 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=BCknf9Ht/NyPEJBUxB6CcGCgW3V8VNj8kSxA+TehLBc=; b=K+oXkrisV0G6UpbhGOPo9UbFGjx+7MbLLc9OHriZoWGfC41BQvjnq1TbvY0hbZrU2Ig4LyvONVSg0dp9uYPyCF4o1WO+urCJ0jTi6OUS1EbfMDdo0Rebci6SF+DPKoxh+0/enHsDJfxJ5jXAiJSx8Xd0RhuSmjWv/AvUXJdUCdSvm4WF2cWjKJIu4SfnJjbpKuv+UyYQhFE6r0m0XMizEJHeymdq7iR1yKdVYnm4m9pHgq+jDT5bQwQL4/9fhKNkBKAkevGsDFzaVc4kJLGV3jrM9nMVAwgw+uR9dysVKsUImxhGuQk1ZQCDp8APNuVKtxsg6mjyHrqaT+3gDEE+pA== 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=BCknf9Ht/NyPEJBUxB6CcGCgW3V8VNj8kSxA+TehLBc=; b=Uk+LIuiv+E/efL6aAUJsQEUIdaqQaoMVRXqBFJrmbopIjqNJ6zH6ZE5xXdv/Mv9EBas1MjXFvEQHSjhh7l3ou3MJUDCj363lXCNdRMlCmmmGOWB/6QLmPhTKiEFvoFILKjLGgIDAUozIx1l3R7HnT4VThEslL7SEsR01QN9Hu/k= Received: from DM6PR12MB3163.namprd12.prod.outlook.com (20.179.104.150) by DM6PR12MB2890.namprd12.prod.outlook.com (20.179.71.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2263.23; Thu, 19 Sep 2019 19:52:32 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::400e:f0c3:7ca:2fcc]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::400e:f0c3:7ca:2fcc%6]) with mapi id 15.20.2284.009; Thu, 19 Sep 2019 19:52:32 +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 , "Singh, Brijesh" , Anthony Perard , Julien Grall Subject: [RFC PATCH v2 07/44] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported Thread-Topic: [RFC PATCH v2 07/44] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported Thread-Index: AQHVbyPGa4HeapA1b0u8+VTJxQpZ4Q== Date: Thu, 19 Sep 2019 19:52:32 +0000 Message-ID: <5aedd92ee8bcf72a70a0feaeb8f1a2a178cd9cb0.1568922728.git.thomas.lendacky@amd.com> References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.17.1 x-clientproxiedby: SN4PR0501CA0146.namprd05.prod.outlook.com (2603:10b6:803:2c::24) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:182::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c269f701-04b7-4432-0fa2-08d73d3ae8fa x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600167)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020);SRVR:DM6PR12MB2890; x-ms-traffictypediagnostic: DM6PR12MB2890: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 016572D96D x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(4636009)(346002)(376002)(366004)(396003)(136003)(39860400002)(189003)(199004)(2501003)(99286004)(6486002)(86362001)(476003)(52116002)(11346002)(446003)(54906003)(2616005)(8936002)(19627235002)(3846002)(6436002)(64756008)(5660300002)(66556008)(66476007)(8676002)(66446008)(76176011)(66946007)(256004)(2351001)(486006)(6512007)(5640700003)(6116002)(50226002)(6916009)(118296001)(71200400001)(71190400001)(2906002)(386003)(6506007)(14454004)(478600001)(4326008)(305945005)(66066001)(36756003)(26005)(7416002)(102836004)(316002)(7736002)(14444005)(81166006)(186003)(1730700003)(25786009)(81156014);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB2890;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-message-info: egm7uE0UDtXq5vS1pN/eOe8V1QGtMY8hyCi8JBGW5L53XXb3iqF5Ezf24+rQDZ+xrVmqmcWcP0CrZwrgcFdC3ZVPdxOmhSrUYwEZdszoTUI9toFF5XSBtLBV8nqy8Q3VNYTWBsj6zs0E+vb0rGTOq9rCsL4btNGrXSYc9lLexCScoutaAf/PVIUk+79dby0fZcOnygpnuQuSvLsTLsNw6fzqm7xgJOVFk4syq1gCuXkf732Xf+WV/trQFx7CFetrHP9hlPA9J77IkX1NHm14M889RniJYyfH+R/Hr++llAe2v4iB1PnT+ysdp2J51p/fFm9dFyTixn4ugTs77+wPqVLpcrN+yvp93auBPflLSAQaw58AwQcdSfqYuM2bYnrcw4SombP1v6XjFrRBnW0+6W4B9NH0rL106qDSGZsV2Cg= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c269f701-04b7-4432-0fa2-08d73d3ae8fa X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Sep 2019 19:52:32.4682 (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: H2ggOk1zY6QDIkJM0lYV5yhKX3nmvpt3Fzu+I//RSstKipSNT1HvTTOI5gMfrpzTsHXbbI2MsUhhZq4Dm0EgVw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB2890 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable From: Tom Lendacky 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 range with an AcpiNVS memory allocation HOB, in PEI. (c) how it is protected from the OS If S3 is enabled, then (1b) 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 (1a), which is fine because (1b) reserved it. (e) how it is accessed on the warm reset path It is rewritten same as in (1a). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall 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 2736347a2e03..a9e424a6012a 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -84,6 +84,10 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDecompressionScratchEnd gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index d451989f31c9..cd2e3abb7c9b 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -32,6 +32,7 @@ Module Name: #include #include #include +#include =20 #include "Platform.h" #include "Cmos.h" @@ -805,6 +806,28 @@ InitializeRamRegions ( (UINT64)(UINTN) PcdGet32 (PcdOvmfSecPageTablesSize), EfiACPIMemoryNVS ); + + if (MemEncryptSevEsIsEnabled ()) { + // + // If SEV-ES is active, 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