From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.63]) by mx.groups.io with SMTP id smtpd.web08.2424.1636582536060781075 for ; Wed, 10 Nov 2021 14:15:36 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=0m4nm7+Z; 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.243.63, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P8CoPulLjehd8lenyfOrk9JZDDCerMrE9JTThhm0W/k36n1qG0U7IlXy/NbeH4e7rcY0GkAiwc5z0MQwetakY+ciwcj7rzJGRNQjWtoj2mVVdNO7LL1sR08uJq9zWJdGVZCIVwzvhMOfjiAO9bVQGaxIyy1UdAAsBEMTTUQ742idxFibIQLf/GLay8l2Bxi/4E3iYDgpAjRLZkMwfEPnTN/Mn27h+5zYzAurYR+kX3PKryQWFtq5dCfVP3DkEy38DnFa73k3N08ae/BF/Ahw/679vsvYfQi0whGIm1tZ37Px+0Qo6X+yQD+QVtl98p7tfeeIzbszDsRPubxXXZTs8g== 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=hlwW+aLx2Bp2Fb0HLIJgY0EZd2jmzsuwTqA4Ie4IHa4UzXzH/yzLC2HeAvr2wFhngUrXy/5gZyGnWxCJvo1r+Kajpj5HII7XBHE+iXdHsOVkHWW2yijbj7LGFHnPEuHXJ4Y7FaxHTn/a+eiji9xXCJUFVKjW7knNn6nqp/Lb7G9JYd3dhPTD/bYTFiootbasXl0sz0NwTCXXoBksV3TGYb/AEJXIX3MB7ajfAC1wMmc9IGtdOzDoKS6arvGP8VLuVxIwFuCFrTkCNj5Td9wKgQX6C+2f3cQTLi6lbdek86zm1piXoKlqGRIFV3xnFYGqn2D99+nntnjA9LxxUOxI/Q== 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 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=J4EYiTwmfbfr8sO7aGxNLaRJ5SaNghSiw5L2jEgGUKk=; b=0m4nm7+ZQLr98ifLCN7pHfX52dyIdQEN3H+TC3V6jJ0TsY1TlkpAJm4bl4cQAgh+7Tl2iIJR3OxU+kysL4LmCcqBtpl3gxUsg5Ms0APcv2uR7knkl+sxHcSnwFKGfYs+EN9/38te6RRVkOf4ICuFnY7lC4FiC1ssbdqVMRHoLxw= Received: from BN6PR2001CA0015.namprd20.prod.outlook.com (2603:10b6:404:b4::25) by BL1PR12MB5287.namprd12.prod.outlook.com (2603:10b6:208:317::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.16; Wed, 10 Nov 2021 22:15:33 +0000 Received: from BN8NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:404:b4:cafe::cd) by BN6PR2001CA0015.outlook.office365.com (2603:10b6:404:b4::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.16 via Frontend Transport; Wed, 10 Nov 2021 22:15:33 +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 (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; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT066.mail.protection.outlook.com (10.13.177.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 22:15:33 +0000 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; Wed, 10 Nov 2021 16:15:32 -0600 From: "Brijesh Singh" 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: [PATCH v12 30/32] OvmfPkg/PlatformPei: mark cpuid and secrets memory reserved in EFI map Date: Wed, 10 Nov 2021 16:14:55 -0600 Message-ID: <20211110221457.2397234-31-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211110221457.2397234-1-brijesh.singh@amd.com> References: <20211110221457.2397234-1-brijesh.singh@amd.com> MIME-Version: 1.0 Return-Path: brijesh.singh@amd.com 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: cbc259fe-b069-4dea-e770-08d9a4979d23 X-MS-TrafficTypeDiagnostic: BL1PR12MB5287: 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: VQC5PWwURQs0jn9qOWsU9ObsT6QILH5OjNvB3EB7gyuxRKQod/rvka8aQVsKGLC1TfbN/sgRavsm1+4El5wL+xxZ+kKIIfmzeWAFriC2NX1jDdy2MrdWH+kx+TtLCvS6PyUkwbrfKmImRYmhOJzfkZ/HH+lkEFojqPMXLppXRUnw33rr/9CV5CLyNgZGh0UmxWXjogzzOnoppiL9i/CS0GMKOTTalWFcD3eADvb2HvaGXEQEcxuuuT0IvzPTK3YNaexIjU2j5cmR7FnD1whmOHuoq9hlyCp1jZJCBEM2PXvKFWYe5sY3uypDnxJz1Y5PuNjhesS1z3wl4W7lDgrWNtZlOljkd8M12xPqF9V3eO7urgOxC6GTjJcW0NE2k5OyC07P+3fgDIpKRtwI6oyiGpyGZR25Hwr48Wn/NPQDBInyLHXf/59hJ71D/TeYYuR+MHAY6WJaBoDuXXusIPrJT3Cs3yH4BE0D/ssO+N5Z584+LJYbcNEobX5xXPGyq8U3MN8NQDxZzgI8rx7llrXXyvqxtJiWoCRHklK7EGRt7P6FGL5VkTKpwHcjT5diq/n7I8EyFbqtBkxqHBDM7LM7xAJuvEg6nZgjR0HApDUIhqy2r5R5oJ25e/F9YTX46JBoyrjtVRgBUkyW18qhSWic2W+5MGN14TmCF0w1DXE5J72jggVy2m7SrJJbkSg/FmfNm9jBKTFB/P6D2R9yhBMcTKlannG62wHPA+uxVHZYIpI= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(70206006)(2616005)(83380400001)(336012)(7416002)(36756003)(70586007)(356005)(44832011)(426003)(186003)(81166007)(47076005)(26005)(6916009)(36860700001)(16526019)(54906003)(4326008)(82310400003)(316002)(5660300002)(7696005)(8936002)(2906002)(8676002)(508600001)(1076003)(6666004)(86362001)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 22:15:33.2588 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cbc259fe-b069-4dea-e770-08d9a4979d23 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: BN8NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5287 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 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 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 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