From nobody Wed Feb 11 05:59:58 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81919+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one); dmarc=pass(p=none dis=none) header.from=groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634144290637457.5491006270855; Wed, 13 Oct 2021 09:58:10 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id E4GsYY1788612xfhyHpSyXGz; Wed, 13 Oct 2021 09:58:10 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.61]) by mx.groups.io with SMTP id smtpd.web11.119.1634144289452090389 for ; Wed, 13 Oct 2021 09:58:09 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TiNOG3zyGT8bV0emfY3YluQnpTed3QAP2DnwD06+V/ERyJAuR5qVYEns66gN8pSBxU+iKyuBgdhsai9UqyrxDyzh9EVv7t+qMMTKSBsYfCvscAodS0bAS9anN3Q3RhbRES8cA6jdEbsXelqjKGF01DMe/01gzmTQzX0QIOMV0K0S0bfIHRKSCw4Dg5PpMBkX23wSoq68IBhWddAoEgmFg9HB2ztnKyO8255Pv4P1h+aL5WtzQ0wOqGtClgkh0bxzw2bu+4p6jeNFaUhZKdCSajeafW1qeI75iEGIifYQb452wetkbwedHZCtPRctsrkxt0cXZi/al1RCblmDmv/cUg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JF/Fi5KmXmZrtStMBqHVQG/xTbyGCtKUx/JrTQUTJKU=; b=ngvsGhMC0Z4Kc/iZC95xkkKa3QNW8yj2P5bg4A7Jdzu4YNMT/FlAC7huXym3ZuSJqYihs7e4mrXquUOXF9hQWGzh4lFhOdCQeiGibK2ZBHLi2zv9MCkmExQcF12uBbTvjZAwPRIooCoWiuS4lcZIbAh8cqUr1XWxJjMFUUxyp/TsCIEc4XFOReRRih58zvaUCOqRfEGoi4z3cSmrr4dQ0dcsszqR2n4gkaBRA0w3tGWhHEUxpYglBSS+a6nlhXeAKZZGSzhihnXLSuKFckyFdE04w6CI2zL+8dbv5jjYR1Wk9gZrM12SC/FwYTK4qE0NX4St7FyjaLLdsH3rC/cq2Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none X-Received: from MWHPR19CA0011.namprd19.prod.outlook.com (2603:10b6:300:d4::21) by PH0PR12MB5481.namprd12.prod.outlook.com (2603:10b6:510:d4::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.20; Wed, 13 Oct 2021 16:58:07 +0000 X-Received: from CO1NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:300:d4:cafe::c5) by MWHPR19CA0011.outlook.office365.com (2603:10b6:300:d4::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.14 via Frontend Transport; Wed, 13 Oct 2021 16:58:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81919+1787277+3901457@groups.io; helo=mail02.groups.io; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT019.mail.protection.outlook.com (10.13.175.57) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Wed, 13 Oct 2021 16:58:06 +0000 X-Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 13 Oct 2021 11:58:00 -0500 From: "Brijesh Singh via groups.io" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v9 30/32] OvmfPkg/PlatformPei: mark cpuid and secrets memory reserved in EFI map Date: Wed, 13 Oct 2021 11:57:11 -0500 Message-ID: <20211013165713.727815-31-brijesh.singh@amd.com> In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3b07c2b2-6365-471a-c27e-08d98e6aa0fd X-MS-TrafficTypeDiagnostic: PH0PR12MB5481: 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-Message-Info: ad53KghsOoyYu/TAeL+5WMnLTNnuRut8m1bghhYBqTiiR9LRUP5iIDvARyND5lqUPy5U16qk6UOzi0KZ+nYSWmZeAfGpDUgYLpSSNIW8AgSRR5va9qf+8QPO21YVdmwwdwe244GldvWKFjmSK5mHJ/VwQpJZkxWG3ocaJgoMzhXhFXITZj7psGMLDje+4Q++0wUfkyNPMrC8z2nFWaBtkpFXiKPzWMszpHjirBVrnOkbzXT0+KwBbhtQLf/Fr790/+rSVXz6w/K9RoihdobaDnFHURtWweyHg3TLvUK+OIjVaYdz90Pxq+7IW+7wS0POSn2BZtNP7j1zX/8m7eMP+KwjPdXVzoS0b6YVbLLKd8rYe6yYW9USu6XKQQKRzqlonSGnbW3zfn3BBCsqcMHCDLoCtQIWxa08Q+qmWi3AR9Qa9zeEMxGz7sEv5lEdxLe3U1el9zSYzNzMsqYAUrTd6pWHwBIP+eiVFjgEFH6epT2EUo9Fl+a6W8FpL30RiyirfiZHgSxxz7TRkHPOpVFuWvocguMEErSLuJxq3Xd8TMF/tDbRj+2IjgPj/copD5dYzEM3DZgiPRdWFsK28O9NDq2BU0FCbKVi+TfqoFosfGps/gmBgsFvcA0tKZ9AXXJ0warFAYRtnRd2FadMvh+pjoXvZLjph4kndfTNRon8U0LJZUFUr/pVc8LVKxWPnP3w2NaUrgrgAjSxhhRa7fkGlnBekJrj7+K1zi2AWOzAI1M= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Oct 2021 16:58:06.6669 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3b07c2b2-6365-471a-c27e-08d98e6aa0fd X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5481 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,brijesh.singh@amd.com X-Gm-Message-State: yrqAAxdtEuHS9iEavohpL1Gkx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634144290; bh=N3/vSnO59PYTk88xM8n8zBwIwpbllnKYVuoc9diYEUA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=OD8gnFS/XhZ5d5vZGyR32HbaQCGsVvpBfiK6OJnsyV5bI/zuem5cs0Ua/9V5/sE/aWy HrpsmkOJOruC42xZAyL8ds2Oak7mLm/Wv8AeETm1LhfRBVJUXIhHr3FAe0/Pm0ed/Nt9A ClYM1BM+zdEur8XLN/C4dU+p37bBTnXStMI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634144291968100066 Content-Type: text/plain; charset="utf-8" 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 Acked-by: Gerd Hoffmann --- 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 persist + // 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 d736b85e0d90..058bb394f0df 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -821,6 +821,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 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#81919): https://edk2.groups.io/g/devel/message/81919 Mute This Topic: https://groups.io/mt/86292921/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-