From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (NAM04-BN8-obe.outbound.protection.outlook.com [40.107.100.45]) by mx.groups.io with SMTP id smtpd.web10.1174.1610045507969198554 for ; Thu, 07 Jan 2021 10:51:48 -0800 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=2Q7QY1UK; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.100.45, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ItwHcX++TgbuX/S3wlZZYHU+U99LSKhV++97afcPcQS0aZafW7PK6gvwM8rGA9vNLkJp9ZR4WYEgodWYbL0qN2uEatG/rIjJX0ANLTF8KS1eOVSPtNp6PH8FGFppTQzC5D1IU8ShuEeaWqgJqA6BGWelcV9wH698mtw2NP0tCVE33q9/YQcLXMaz1Z3F5xlYD+h+nNQrmeq6CeWBHniGaHwgOhAsbfw6aJIW5NRoZBQZ4IBMa3eRsx1oX1CggDz/GgEijdV2To3lzP3ug4UivbMtMjq3qMZHQcNln6nJSgFT2HzWuB0jz0dZYwvbx6FACCOIxR8awkWc3jPqTPlzjg== 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=mdmLM6cNCtI0J4G6FIYY5jcP+TMvniVf70QE2BrfEMk=; b=CCWD248GFcloDKJ5zc2Nhz0JbGtygd5OL0u1ucBAmRh0FDv/1oiLj6viGZCqOu3dlY8/SjEPZcMsj/S8+t3B+J3d1JSi6DS8JoZKQEb3ktYiLn3fqJRJMEc3vLZYViVataJyRth6uXr7sd7k/p5TXq+vLICXg46Ik7Av9nW6fYO45eOHg+pkSInLgD76zt+l7i0yHxktegEX6Jb/WDuNOIaFPqNiBquqU3rEn9KySlXX6IjYpByYf0nP9iEwOZJILuim6dQuzY6fUECjWVq1R3mtSeqWQSWxRuBlOI60oouv7q/zgbBfnWPNVhhA/BPO7r77wWc8Cgpli9GwolObCA== 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=mdmLM6cNCtI0J4G6FIYY5jcP+TMvniVf70QE2BrfEMk=; b=2Q7QY1UKOEF6ynYd4e6hd//Zz7N4acw8j789TcGWDFepEgL2Jg8ncpwZpELV8wlfp51GTBCHWRmGL+VIxe8HxrYS83o4wkBxw7dPS8aFntDp2G1Pf+YOS0Tu/24mQHOSvTqIuPI8qwei38g5qxXKkPp3ipgB+CToyCtifKwXfy8= 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 DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR1201MB0121.namprd12.prod.outlook.com (2603:10b6:4:56::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.23; Thu, 7 Jan 2021 18:51:43 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::d95e:b9d:1d6a:e845%12]) with mapi id 15.20.3721.024; Thu, 7 Jan 2021 18:51:43 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , James Bottomley , Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Anthony Perard , Julien Grall Subject: [PATCH v3 14/15] OvmfPkg/PlatformPei: Reserve GHCB backup pages if S3 is supported Date: Thu, 7 Jan 2021 12:48:24 -0600 Message-ID: <119102a3d14caa70d81aee334a2e0f3f925e1a60.1610045305.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA0PR11CA0052.namprd11.prod.outlook.com (2603:10b6:806:d0::27) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) 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 SA0PR11CA0052.namprd11.prod.outlook.com (2603:10b6:806:d0::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Thu, 7 Jan 2021 18:51:43 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b39fdebd-399e-4257-2a62-08d8b33d4710 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0121: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vJatIQVtBrr2BAVJwmnf44ib9Nau03hfR/grm7F31PLaVEwV23825mL1dl3LarnFQHuAD3KzBEdqWZTvALuL1l4wFS+MNJJc52gxcQDpdiTf5sM969alNz8f2Ghn072KU7rOSUaVWAnkfAPa4RX7jOr3v+oTWksoBoQXtUhufkgbovF+qfEy0RaC6ExwmfIMsJHKs/OnKcibkn2jm7M/oOxkngtieTqzVusJt95SBjYsdNsEGGg1DQ97KDqVRy89JdiTNY89S2M9dHTnlgc1u+JzuzdVtBw1Zd55OF1aDkjdc8FNNYmKbb4YQ9HV+/kphSh2BirZ0/Exa1Raj1D1n2JeAFH0NqGv+DU5xd5AuDQavXgtgH2G+zwhaLDrgn/037aOriHZLdK4CKHBxRmIOlGBoObQGn55c5yElA5jOZBFLBfnE/A3T8h2Sp1a8yo+BsxA2gP9ZyPzwxsK8MXbdw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1355.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(136003)(366004)(346002)(376002)(396003)(54906003)(36756003)(316002)(52116002)(16526019)(186003)(6666004)(7696005)(4326008)(83380400001)(66556008)(66946007)(6916009)(956004)(2906002)(8936002)(5660300002)(6486002)(66476007)(8676002)(86362001)(478600001)(966005)(2616005)(26005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?7bLUKNAv/jG+xw1jEcssC7D0g0rEciPpelZ2+saHhZztQ9XKmKyLGnJLg7DU?= =?us-ascii?Q?6pTjQ8Jxrff+Bo617vTgcSkaUG4qiWZz1PVM/OaCWu7RGYt/dpNDR89pEh/g?= =?us-ascii?Q?WjqR2+bLLyg6CInvSH+TBJq+HLhuvP0w8ndZ1VL8OULJX7E4F8CfEALqnbCp?= =?us-ascii?Q?Qp3ws3QBZBeDNCiA5/RX0GWNVavM+BGszF0pdt4H/UngiQE3AjFaXoGwq52t?= =?us-ascii?Q?+UJJb0Eh5qBpfcrjdCbTfH9Hzrpxvl/cftU2fIRdf4tjbAj4zYnRxUUT4QMv?= =?us-ascii?Q?nchutMLjWIxud/Q3Nws3AlbYGGf8C0y0IcwpqB2TLvTU+IZuI1KCLxG3Uqcn?= =?us-ascii?Q?PnzaHuSeTeuOQ0cmbZ+PJQCnClkjpi8ExsE5mgAXL8ucK5tvYjCWcH3XHBC6?= =?us-ascii?Q?L9kdHSuN4smiTpGQdCRwIGqpjT7uN2n8cImZxgRkS99Rl1WZBflmhOOQ7UVr?= =?us-ascii?Q?UsBLBhkceXS5XBFvuGc/fmXaAxVY4tuA86THImoSG/iC9Xpk/YtZ4fniI4yU?= =?us-ascii?Q?GVvXdo0CSes/kUv/GQ6bYcwQUerVCYoVWZwGjAKvPZAbvGKbnHSnxwILX456?= =?us-ascii?Q?RAVgJKq9LTEuE8XEMzFiOAQ3Qf4j4uD1LmRCP6U+hMOuNGkenNGoci49M3gt?= =?us-ascii?Q?SGCt5oWnpT+jrgHr6prN1Uaf/OavqWy4T7QvmzZbhyp31yDCs5N06WQYD4SV?= =?us-ascii?Q?od0t4aSdMAmzHFVB05ybhSkVKAFMumoVDdEzdSrLz31gmCJvbc62X+kqp3AA?= =?us-ascii?Q?KsllTWjnumKsOixDTdXP4hFqnd6gohkRIRdQ7sOiEaee0DjwbjNoxu47ftta?= =?us-ascii?Q?Sjp9V8isH9kySH0SNZoqbtP6WBmomyyFUzk5MRUog48bkyWW8wKJorRAX/4c?= =?us-ascii?Q?Upxv2b54KJGwfJrNOwWmcmRE0qxtkZn1x/U8FfnAkbzfL1cGdC/Xf2fOH83h?= =?us-ascii?Q?gXl73H7w9WCJOA4EiW6sKE5isG8qZLG+pDEDRLUovRTVNDJ/sNsO0haP9rgP?= =?us-ascii?Q?Kmpx?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2021 18:51:43.9064 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-Network-Message-Id: b39fdebd-399e-4257-2a62-08d8b33d4710 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: LucfXVYOZGr+P6vf/4dD4rSlqjaV06TwSLoGxT39lp+M3srH9GKOLnigG7Yu3+nE53QiTWAZbgHR0mLjq+1BmA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0121 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3108 Protect the GHCB backup pages used by an SEV-ES guest when S3 is supported. Regarding the lifecycle of the GHCB backup pages: PcdOvmfSecGhcbBackupBase (a) when and how it is initialized after first boot of the VM If SEV-ES is enabled, the GHCB backup pages are initialized when a nested #VC is received during the SEC phase [OvmfPkg/Library/VmgExitLib/SecVmgExitVcHandler.c]. (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. PEI switches to the GHCB backup pages in permanent PEI memory and DXE will use these PEI GHCB backup pages, so we don't have to preserve PcdOvmfSecGhcbBackupBase. (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 Cc: Brijesh Singh Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/PlatformPei.inf | 2 ++ OvmfPkg/PlatformPei/MemDetect.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index c53be2f4925c..6ef77ba7bb21 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -118,6 +118,8 @@ [FixedPcd] gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize =20 diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index ffbbef891a11..c08aa2e45a53 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -888,6 +888,11 @@ InitializeRamRegions ( (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbSize), EfiACPIMemoryNVS ); + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbBackupBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbBackupSize), + EfiACPIMemoryNVS + ); } #endif } --=20 2.30.0