From nobody Tue Feb 10 13:16:25 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+83730+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 163673884596622.031808670093596; Fri, 12 Nov 2021 09:40:45 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id nfy3YY1788612xabT0Ny8nsi; Fri, 12 Nov 2021 09:40:45 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.84]) by mx.groups.io with SMTP id smtpd.web08.398.1636738844427402940 for ; Fri, 12 Nov 2021 09:40:44 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FrJmeWX+mD2NtjD5Dbp+YbLrH0VGCLT2o6q1d4fIzvd1RqDLox+wf7vrQq2Aft83kLcTjKknUG5dBqp/ZSweyVfWiLfBoXCgj0Lzg6dRdMpaq2eQk9WBma1jC9cne1ztV3n4auMBE8hBt+N8FjxlRXiQxg7dGPMUddPuPtdk7+Z2k9wXnAjcBj9lNQeodwmMDqx85IO2P5QjE28OThIqrI1eoXXhuhtIJAjKkQQlKqnHtE0gJfKxVKsmchHMBDO878fpteleh3JJC/lEuQqpPSGOKCEtCq1BEbya44dIYXJtXdMYxHxC7B82W8mPtOo84uDKJzLa0mRwVt+3wU455Q== 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=J4EYiTwmfbfr8sO7aGxNLaRJ5SaNghSiw5L2jEgGUKk=; b=gnBl8nNuLJrQ1WX0SrVSGsV9kb5V8s2yOk47uEd86Iy2KuIAFQiZKFYDiEY1qP6908D9iIrI+gVEmbMyy+6j2SUMxegqW/YH4wn73f2D8FMpXmKaDVjSa5mXBpyIZdOF43fFKZ7w8Yu9Tld7LMWE4x/CqMTJ7USOd2aiscV1GqXDvz+blKl3GwD8ck/GlbOEk+tRtfheXPKBpTC/OS8meLzBiVv7F9X6Jt0dU1GPThSY7qwwBFj0siKuYRyalJAp2sio+GsTgiqgQQE4autDbu/4oaURZhAulSDzxiAI0m+2dQ9Lqfq34VfLzr+H4O1kukc/r+oGGYlVvN6n+NTYLA== 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 BN6PR19CA0078.namprd19.prod.outlook.com (2603:10b6:404:133::16) by DM6PR12MB3228.namprd12.prod.outlook.com (2603:10b6:5:18c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.16; Fri, 12 Nov 2021 17:40:41 +0000 X-Received: from BN8NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:404:133:cafe::d9) by BN6PR19CA0078.outlook.office365.com (2603:10b6:404:133::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11 via Frontend Transport; Fri, 12 Nov 2021 17:40:41 +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+83730+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 BN8NAM11FT052.mail.protection.outlook.com (10.13.177.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4690.15 via Frontend Transport; Fri, 12 Nov 2021 17:40:41 +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.2375.17; Fri, 12 Nov 2021 11:40:39 -0600 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 , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth Subject: [edk2-devel] [PATCH v13 30/32] OvmfPkg/PlatformPei: mark cpuid and secrets memory reserved in EFI map Date: Fri, 12 Nov 2021 11:39:57 -0600 Message-ID: <20211112173959.2505972-31-brijesh.singh@amd.com> In-Reply-To: <20211112173959.2505972-1-brijesh.singh@amd.com> References: <20211112173959.2505972-1-brijesh.singh@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 10dda27e-615c-40d3-7239-08d9a6038c02 X-MS-TrafficTypeDiagnostic: DM6PR12MB3228: 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: nmSWZXSXaM5EsJ2VgDH8cp/Yhj6qucEARE4F3DfsPswh+8191Z97dJpgstGj3mVdd2gdRBmT/K23vCeFFjXx2Fg9jLlAskMQN9k5nH6JM6pM+ej2972wz3UT1b4bqpXVX2heSmXNkI90I5OwFeZoc3aEXx4LnZWDcAGNg+6x7j/fcPlcl0FQDECMXCkbjfjlC6EfrotqZHdJ7jFd9CrtBGN1diYalwWpx/M/mql5wOdUickjCUw17zgu57rhDY+bMRXNr+aB46+IJ/HOerWjqfkHWF26+p80TdHZQ3doUZRWRgwvHnLnE1q5Y29URFWozJUjoJtvbv+Fvl0aq37BY+rVW9nIpRJxMZAW6cubMNFTX+GhiEJPMDkwori6uZVI4TPRtn2kCaWrT0rXO2Fs9r7qgtqGjbXa1trXarc8bVFcQSEaxiQkNpf7BBeb3fMc4aSbq1nCpHTERVwVCmFAxxqxr08f3AbLrrCJW346uKK8swv8sKeM3lR6dEYdcnnbqjY/sjJZS8sKCRVFDai7Wwj8sI9YXDGh9zsCH+VCFjk4v6FaPLLhHOU/d6f0DRmBc0rVSWVzB8n3B43ZVk3r6AR96EICeu2XnKPGDzureO2xEuggYrc1bJQT600d7FGl22pzt70kmVfiFeP16nkZp/uvLn55nBwOPBw+702MCFsEIXtHge7m55ucAMS9CJaAgsgksz948e/TBeyv9/gQMY1rA1th3cEjJmQQMRAHlJU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2021 17:40:41.3279 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 10dda27e-615c-40d3-7239-08d9a6038c02 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: BN8NAM11FT052.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3228 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: UEdEHBqn3SN67nNU3b1zvCWtx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1636738845; bh=dHE88YwDfAe23wffqjFgbCUJzRM8FsfZd/vyN9zSXgw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=GbQ3m37Cn1j9gp1sQ6y/WwBlEliJt/tM/uNJED9gKxeKF78rfARCN5uzRYXav1sI1x3 c9N9IS07aL0ve1YuKrmf4QdPlHCoefhErXIHGariWeOvSBtDtN/MDQFKZDxSAUd3XHR+2 ydjjbApaIlIr96AzbI7jFQSY+zemxlq5uYU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1636738846639100026 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 Acked-by: 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 3c05b550e4bd..1c56ba275835 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -111,6 +111,8 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures =20 [FixedPcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfCpuidSize gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory @@ -121,6 +123,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 7da6370113f0..e71c601aa716 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -410,3 +410,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 (#83730): https://edk2.groups.io/g/devel/message/83730 Mute This Topic: https://groups.io/mt/87011909/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-