From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.76]) by mx.groups.io with SMTP id smtpd.web12.165.1630513077014031814 for ; Wed, 01 Sep 2021 09:17:57 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=Lz552Wa6; 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.92.76, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TUcRnckaWPo2x5dHh+Pc8WCEfi9RQd9/N2xTj6zza4w4kpO8TPKvGLztOJodDrIMLtynHcGJA8d/d3uaIQu0JwFmfKe1jSDRS4zpsoP0ATW6vw8a+SpbdXV3trex/TKIEXicJ24m9rDyZl4ed+I1WS8LzzO9jInbnxAaLuyOLYdyzCfDIXUAtDvhGxVk7pBR/nnHmMv8XTU+W8wEO7KjYd4efUlB1LKcMJWO5QRgsRw2PGoF0xbg0edMRluoJoXZYUGrKozB6bR6ZG1vuUg11T1BGAan1q0cwgbcExu7nDgGIfEZbLYiwPFahnzZ/N10SHxPalLF8gA9L7nFmdmjJw== 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; bh=0cAck3GUVGG3XDoaGy8JYF5AgZvUawhcQTCvX8en/pE=; b=MKZOWQko0MEL73XpnSN9mQVpCUvx2unxVvTQ+TjFrkjS9V/QbRM9El4TV8wQ47uxWJ8D6T4d/37T/NoHLR2XHOmx0ZzsQqRyD/A2mbL5eJr6RKt4CCSU4BpIrW/2r64kpPonDdbxrRlFT/HPv991E0P60+Uf7V7X7nx+GpDO+TBE6ADBnuTdx7F/2YyXL8Z8rFGW+ldfppA5KjkU3YRsDPP5bAv7hQKD1mkJEtq+YPRP1mfmmvaJd3dIJJ8B5XfO4sKRF04F/f4ZW2a8rO/iNe1YWEHuAzVRcHjmrOPRjbd33EjkJ4jG4ztl3vwmwtg4MQ0xL6xGJRehc/sBKlNYyA== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0cAck3GUVGG3XDoaGy8JYF5AgZvUawhcQTCvX8en/pE=; b=Lz552Wa681gAifKF4AYTX3vDBJI7EPLi/u5pyzdhZwPRRW50lhDq1nyjMt3MEdyUTBNl2DPr97XDhcfu8vaQk3ZjJQJab2OXrAcDLCPwubVhMY9AkyQlZlGXnau0z+taTOVjD+0cVO8unM4z+k9orZUKMG7CLHF3t9yTc4CaDMo= 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 SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SA0PR12MB4512.namprd12.prod.outlook.com (2603:10b6:806:71::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17; Wed, 1 Sep 2021 16:17:55 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3%6]) with mapi id 15.20.4457.025; Wed, 1 Sep 2021 16:17:55 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io CC: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Erdem Aktas , Michael Roth , Gerd Hoffmann , Brijesh Singh , Michael Roth Subject: [PATCH v6 27/29] OvmfPkg/PlatformPei: mark cpuid and secrets memory reserved in EFI map Date: Wed, 1 Sep 2021 11:16:44 -0500 Message-ID: <20210901161646.24763-28-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210901161646.24763-1-brijesh.singh@amd.com> References: <20210901161646.24763-1-brijesh.singh@amd.com> X-ClientProxiedBy: SN4PR0501CA0062.namprd05.prod.outlook.com (2603:10b6:803:41::39) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN4PR0501CA0062.namprd05.prod.outlook.com (2603:10b6:803:41::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.12 via Frontend Transport; Wed, 1 Sep 2021 16:17:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1cad0b5f-9344-4cf0-4434-08d96d640e44 X-MS-TrafficTypeDiagnostic: SA0PR12MB4512: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Kmh3QkkD4zVId3lhEhtO29LFY6x+OvEI/oGAiGfHciemCsMplB9hknYdgQwGTsNOl7ipmyUYowYLdso1+5/cEBH5jJwy9Ghjo6LzR0WP+EaPxD03Zk2ISN47pzDjqssOA5D4MDlnXL5L3slOTsZatiGfmZ5b+jWW9O8Xa+ypz5XpVmLmvg83rvGV6Wqn9LWDS9lRZUd8z83OI4Sa8vlxYGGnj7P+N1r96eCLYJW8G0lrdp0E7Wkfc4Btt4F7Ge0nxsHJwDaMeL61Iyzqb/exI44ENwSJBgCZT1Ri5bQwETZR+kZtawDpqa21B91RookTd4yk9KyuC2L8FzdwhiyTLuwFljtIY1SJMmHeeT7OBLg17Ye4RqV47ptvvSfkI/VEyjMsNiFiyQv8j9pLhAiekl8PQePMzFX8fDLsFzsy2nuQ1YmMP21H4Fsnnj9xGj5cMPIr+MOZLXYVE52c/tnmQHmqGVLrB0PmgjM6IL/rNSbzvznzo+nYs0zo9gKpELGzKjdW4izfU+IzEXv9hhzQ3DNcKNS8MzytjXtuOVED3/ZvTXvJlPtEy6EgSt2t+1yfUoRPnCrvV/ojOGwf/XF8mc7TSyUGmMd8ONUaozFCjkIjYzsSnJ7vqLBbiWTh+VaV4hfp86sHa5UjEhVtadO3XmE5qr2mQ7ar3BbFjE3xnC9wEi+790FwPFBtoBiIN19PD7Uwdzja2rGTDqDKKl+SfA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(376002)(346002)(366004)(39860400002)(136003)(66476007)(66946007)(66556008)(4326008)(478600001)(316002)(26005)(2616005)(956004)(186003)(83380400001)(44832011)(5660300002)(86362001)(54906003)(7696005)(8936002)(36756003)(2906002)(8676002)(38100700002)(38350700002)(6486002)(6666004)(52116002)(1076003)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?lbFMgvAy3n2YHQ5miAfX4zmPpABKicXTk71bHoGohoUGL4Gps3KaaB1nKRVR?= =?us-ascii?Q?JhnfvQWRkrbZ9rtf/rLYoTqCUdRXinZG++9Y40LmeXtHKCZaYcHTrANh8AGd?= =?us-ascii?Q?sHcbC1aLfD3Z2JUP7cIG17WllJYaPPgG4M4758/U/mTKL/B59QA9kSHregPS?= =?us-ascii?Q?nBwadl9qRdJlBYV/59KqR90qdLyBbaUTK5UVCzudoR+HX18s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FFGC1bR+COVxBjx49EVJad8ekWQ4BmNTIQe5pBbzlZ?= =?us-ascii?Q?sfudOMR6d+fVGFX3RyFWOwSalSJG2jS6ZMOg67WlQumZY55E5DQmHGX1VZHp?= =?us-ascii?Q?Ub0k8tWr/pAcHEoim5zmjoDovRnFI9YdNpNdOEKXSYWjdRF7vLbWtu7DFRTP?= =?us-ascii?Q?ldgl4UkpRUX7pjXLT0XGf3HudEZBujk22em8FsFqX3uiaoqyiRSQWAgmZhnG?= =?us-ascii?Q?4e4OEKiAhiXGphGWT9fzOCrK?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1cad0b5f-9344-4cf0-4434-08d96d640e44 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2021 16:17:55.4826 (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: iE/fEkTp65S/5gIdMeHk/JIMJiR/MBwmQmUw9EDbCi9oN4aI4ShWtL8NgcSmJsaVqUtHYAfy5c1iWZKGg02ebA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4512 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain When SEV-SNP is active, the CPUID and Secrets memory range contains the information that is used during the VM boot. The content need to be persist across the kexec boot. Mark the memory range as Reserved in the EFI map so that guest OS or firmware does not use the range as a system RAM. Cc: Michael Roth Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Erdem Aktas Signed-off-by: Brijesh Singh --- OvmfPkg/PlatformPei/PlatformPei.inf | 6 ++++++ OvmfPkg/PlatformPei/MemDetect.c | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 8c9795095a10..82a0ee721da2 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -122,6 +122,12 @@ [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaSize + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpCpuidBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpCpuidSize =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdCsmEnable diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 2c2c4641ec8a..564c3dabc487 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -817,6 +817,27 @@ InitializeRamRegions ( { QemuInitializeRam (); =20 + if (MemEncryptSevSnpIsEnabled ()) { + // + // If SEV-SNP is enabled, reserve the Secrets and CPUID memory area. + // + // This memory range is given to the PSP by the hypervisor to populate + // the information used during the SNP VM boots, and it need to persis= t + // across the kexec boots. Mark it as EfiReservedMemoryType so that + // the guest firmware and OS does not use it as a system memory. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSnpSecretsBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSnpSecretsSize), + EfiReservedMemoryType + ); + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSnpCpuidBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSnpCpuidSize), + EfiReservedMemoryType + ); + } + if (mS3Supported && mBootMode !=3D BOOT_ON_S3_RESUME) { // // This is the memory range that will be used for PEI on S3 resume --=20 2.17.1