From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=JMQOgutG; 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.236.61, mailfrom: brijesh.singh@amd.com) 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 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=JF/Fi5KmXmZrtStMBqHVQG/xTbyGCtKUx/JrTQUTJKU=; b=JMQOgutGQk99lzfvTqf8UaO8gLEM7yCoWxH2b9wQPss5/cGpvmIwTr5RlJZbl6u2rxrPz23oVus+fiCjUAr7Qae39ZsCmPCIbIowv050o43USo3Pfzvht0uQ7Ci40EhAhi5+mdmFJtBP1ySIcD4JvIFcdmwk5lmX/IOyiF3aLOU= 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 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 (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 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 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" 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: [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> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211013165713.727815-1-brijesh.singh@amd.com> References: <20211013165713.727815-1-brijesh.singh@amd.com> MIME-Version: 1.0 Return-Path: brijesh.singh@amd.com 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: BCL: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-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)(508600001)(6916009)(54906003)(44832011)(4326008)(81166007)(316002)(70586007)(356005)(336012)(5660300002)(2616005)(1076003)(16526019)(47076005)(36756003)(7696005)(36860700001)(83380400001)(8936002)(82310400003)(86362001)(8676002)(2906002)(26005)(186003)(426003)(6666004)(36900700001);DIR:OUT;SFP:1101; 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 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 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