From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.85]) by mx.groups.io with SMTP id smtpd.web11.1352.1632163637873995110 for ; Mon, 20 Sep 2021 11:47:18 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=nJI//vYl; 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.93.85, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fdbKYQFRyaVNFhggmazoeCIjTlOl8ZK3Vz8xGxPISYiaKozsT7yeVpTNdafOFHE0C4Wo/ZE6/ZoRwuvRBn2UDrLlfQ/+efvol1eXTBTDFNn2OZHI0zYNRZPnnGT8+3aBnsm74zX46HJS45TRqcqVPRBXACcjSsQEkjcpFmRdJvEGnzbU2yHl3Rf8QL13zH6s8pFs8nt+9Df3WI/U9QhMpekfpLmIk2TJ11HsF9LS1A5PaOW5d2HIoTGlO2sWgl8sDWQcnI6ML/MuEGXaoWYMoegsMWTEzd4UGsIWO04PaA0T3zmr7Og5FfX0QarFRC305JggsMPj9HENIOdbBr/ngg== 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=XHd6FP6AxvbnYVxqe/ZUDcYAGkVsM3oiEB5M4Fskcq8=; b=QjnJ3lY1hhiX/OO2SOeJyTgA97VI5rZ+gafrtwD+e0tpVSUpvi80gtniAJVgkZa80FuIHWiP79ljei7b8ztODGb9NnpBy2vWcfvD7/oOLw9jw7LT2DMwo63NgrNmAJxwqO3IQwWxG2QwInV8pl6Jy38qeF4oGbXULlMSlP2KxCKW5pdlCnlB/cwx5CfpCE57GWi0rEtX1j5cjOSPvbhNITLUIsormZ4T/q2gS+Wc5VqV/6aRPmon3a89K1YUKdXt+kFPkFcuecsqGqOLaXixELVGgvXxM8Bqj5cxn/YOGiFzfjU1imVUs96KEbbu82EU28CXfve6i8shZi5yjiMuvQ== 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=XHd6FP6AxvbnYVxqe/ZUDcYAGkVsM3oiEB5M4Fskcq8=; b=nJI//vYlOrZY5amb0S9+2cbwcGGCsHZLR4tfdfyrctfG8ZLhBGQMEtv91p2ZgMpib46Zv3q+eU52MdFEXNWrwcuOzE4RswVfUeJoIaZIoRS2T7iX+RspDUHlILNM/kVzK61P6IfCZLE0G3ymFvVfDSOZiFf4oWgh9+jaoCZgqrY= 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 SA0PR12MB4384.namprd12.prod.outlook.com (2603:10b6:806:9f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Mon, 20 Sep 2021 18:47:16 +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.4523.018; Mon, 20 Sep 2021 18:47:16 +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 v8 30/32] OvmfPkg/PlatformPei: mark cpuid and secrets memory reserved in EFI map Date: Mon, 20 Sep 2021 13:46:02 -0500 Message-ID: <20210920184604.31590-31-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210920184604.31590-1-brijesh.singh@amd.com> References: <20210920184604.31590-1-brijesh.singh@amd.com> X-ClientProxiedBy: SN4PR0201CA0034.namprd02.prod.outlook.com (2603:10b6:803:2e::20) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN4PR0201CA0034.namprd02.prod.outlook.com (2603:10b6:803:2e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Mon, 20 Sep 2021 18:46:44 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2996fbce-5118-46d7-fea5-08d97c66fe96 X-MS-TrafficTypeDiagnostic: SA0PR12MB4384: 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: PB3g2mVUOT0MeIpSpxJCOyezZ7Up/b+1/xFNzCv7r5cFmimq9BgZhSOqpNOZ1Typ23iHXQMQpS7xvSrWfC1tglVavs9ddPqZ0XGnADAm1nmHypsjw2EFjP0Ni12oqo+02Ezi5A2eJMfw3MXIt1jzsjdHiEkBfNjmdJJBqUWO7WONeWsyTSZgCdH7ZAzYoGKkbb02ICsW0VeOAdftcoSTomaj0dcqKvsCxU/5XxGcFdh2bHeGDchiXRz/EThYg7O+vBJo8IyNUKhXERnJJl4izxrxftKAj7SyKj15ZfkkV9esV7Qx6gMP9JnTlT1kaCU1vuwBSR17uSecGWLB2PKGR3viNzi3JM2neLN1/+7XP3OvU0HEXTG7gLVEjo8iSW7PaiUFatpqqZzO+tCWcF18N8OEywG7HoS8butQom7ij8+CyvJmBR8cN2G7qAjYQpwSd/PTka22NNiEcAtn4j34WxEC6hDKLHTRT5eGG5PC1gBJTUHnL5lKGUMih4LOIDG9Wq8m9mddST0SDT7UCBExTE0f++9ADzWiAkmePqgQGW/hhJCTlzyTdORxh9i6zfT5mUY6M0IDJmwphg2IurI/plorXuXw5tJ6NYf+okoBhC4LWimIkMZ15M9C9sS5wg0DyirCHWFMlFHnQ5jo9vCgDzlXYvIvbrVXPhUCXurdnJx4FdU3fyawfk6r+LZD5W565wXn5HylhR1cIShfl+pCKw== 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)(366004)(346002)(396003)(376002)(136003)(39860400002)(26005)(44832011)(6916009)(8936002)(86362001)(5660300002)(52116002)(66946007)(38100700002)(2906002)(4326008)(54906003)(8676002)(186003)(956004)(36756003)(2616005)(66556008)(478600001)(6666004)(6486002)(316002)(83380400001)(38350700002)(66476007)(1076003)(7696005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?2aKJZRoNOmy6lXqaZpxv+nOqZ7dtiHtzm5OGsuktlbebdDoEPpfJ2/QmHQ0E?= =?us-ascii?Q?akaG33KzJ3wIiCrXj/INc4NLiqeTF9tYltRFtIl2W4CnmJHvRea9Uim9ms/H?= =?us-ascii?Q?m+RuowBO0dhM4Oij3yC7d9dygUd9kIZeI8wGdc15D0wUeJInWANy8tSik74j?= =?us-ascii?Q?8pBYBh1WJFoSgjvn8/3VMgtR206nzIxkm5xex6JfEtHChkzuXQ6hsnkTBvzn?= =?us-ascii?Q?ca26Xjggv17uI6k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UoEbt86?= =?us-ascii?Q?qBGHRWkhS8sWu5gSm6fUyOZuQhjEezoeAkEBT4j6Dcxrk0fq7wFGaJsgpWtp?= =?us-ascii?Q?g0LjM98hKTaU8RQK6WqeQDpJ/HYZFhWE6DomCUKgcDigZ1MnZUGVatsGlxfF?= =?us-ascii?Q?mZz0PpfryKu6/x4PF/pBj/QNxcrTOePKgTGUhNmYq8gL738ZdvFC6NzJK/xk?= =?us-ascii?Q?MssegpSMH5J9haMDckeg6FGW?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2996fbce-5118-46d7-fea5-08d97c66fe96 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2021 18:46:45.1231 (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: Yokoym/eKVEOLIAuwWKA3lbx2lTfOSNiYp6fwjmzwMUUmKj1fZqvyq1HSMjyY38/G8xArrTPmJg+bRs0Saau5A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4384 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 Cc: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/PlatformPei/PlatformPei.inf | 4 ++++ OvmfPkg/PlatformPei/Platform.h | 5 +++++ OvmfPkg/PlatformPei/AmdSev.c | 31 +++++++++++++++++++++++++++++ OvmfPkg/PlatformPei/MemDetect.c | 2 ++ 4 files changed, 42 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index d048b692f155..0a89e1a0760e 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -112,6 +112,8 @@ [Pcd] =20 =20 [FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory @@ -122,6 +124,8 @@ [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBackupSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdCsmEnable diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.= h index 8b1d270c2b0b..4169019b4c07 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -102,6 +102,11 @@ AmdSevInitialize ( VOID ); =20 +VOID +SevInitializeRam ( + VOID + ); + extern EFI_BOOT_MODE mBootMode; =20 extern BOOLEAN mS3Supported; diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index b71a4a7304f7..133382407bc5 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -414,3 +414,34 @@ AmdSevInitialize ( ASSERT_RETURN_ERROR (PcdStatus); =20 } + +/** + The function performs SEV specific region initialization. + + **/ +VOID +SevInitializeRam ( + VOID + ) +{ + 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 (PcdOvmfCpuidBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfCpuidSize), + EfiReservedMemoryType + ); + } +} diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 2c2c4641ec8a..96487b810014 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -817,6 +817,8 @@ InitializeRamRegions ( { QemuInitializeRam (); =20 + SevInitializeRam (); + if (mS3Supported && mBootMode !=3D BOOT_ON_S3_RESUME) { // // This is the memory range that will be used for PEI on S3 resume --=20 2.25.1