From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.61]) by mx.groups.io with SMTP id smtpd.web12.6773.1639020568207471646 for ; Wed, 08 Dec 2021 19:29:28 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=KcR3oX8Y; 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.102.61, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kK0J+jXDJ3FFgC/J8V49TYD9+k+WSPs5wnzaD9haf2a31c3QfElJ2s1++EkvUHw9G7hbjH1j+ZIadlILHpLF/744u9EKrU6cEKr+PKaAc77YdHq0fc3ktmjoKS5XbQ8T2obT13FjufVtweq/zw7E6NBMjzIOboO0TDF7+UAZGOE82dALjAg7CmiWD18qJVzX6phFNS7sSbmruFNF3L0Klwrf8bHEx+K4Jts06I13k0UQ6XYTmv/ZnCS2jdc5qTdqaGgU5IkVcgRF2bSt2mpNF49gfMUrt8ESjAr3HBsaSVWVbuSit8NJC16eUWJ9vC3ImdyrtAToK/JWAuJF8yLGiw== 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=+RozJ1lm1vcL+TYv6jXzlFdBtZv5BVhvnmmuCZ2UUyE=; b=en5PPSNB7xzgMLL2Hdp0VCFZHWF27wwCq5lgpz8b9Ulr+7jNWGu0jbFWr+Uhlwb4uHT5S0vGdPn5Cef6yH9RcMtPM19lhtvUogUAN6sTObWin/u+9hdg14Tnw9VLZsWY/gp0M+iSwFGTPJr6gEJNfMMkgCq8u9eyfWf2HWE5RDzPaWvpWKsXHbjUKMd2x8VEATF1eErm03+bLwUr3H9reJYEHinQuFEbGQH1KSCR6f+/fGlZDQ3NPCiA9aXBmkjIl0HSgbFIZWJiELrNt8hkm200F9ce1i3emj5v1kkxBxNfeqMl7gPZG4COtGmRNjabsOxcrrnEI+aGXcBsr5W9mA== 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=+RozJ1lm1vcL+TYv6jXzlFdBtZv5BVhvnmmuCZ2UUyE=; b=KcR3oX8YXFrPV9NcCOLe4vg9BO/LKNHCcG5vT/pu+dsrX++Dzu4OtNsojASeMZMXFtLM5ub8ItHSUODQtq1n5Plyel+0daTTuOcCMkUXf/NzrcDGnq0CFX1XrUYEouJ7k5FyZvhyiXc305ECNlb4KRWQzw5aDQHttCpXZ7Glw7o= Received: from CO2PR04CA0182.namprd04.prod.outlook.com (2603:10b6:104:5::12) by BYAPR12MB2599.namprd12.prod.outlook.com (2603:10b6:a03:6b::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 03:29:21 +0000 Received: from CO1NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:104:5:cafe::4c) by CO2PR04CA0182.outlook.office365.com (2603:10b6:104:5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4778.11 via Frontend Transport; Thu, 9 Dec 2021 03:29:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;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=SATLEXMB03.amd.com; Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT031.mail.protection.outlook.com (10.13.174.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4755.13 via Frontend Transport; Thu, 9 Dec 2021 03:29:20 +0000 Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Wed, 8 Dec 2021 21:29:14 -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 , Jiewen Yao Subject: [PATCH v14 24/32] OvmfPkg/PlatformPei: set the Hypervisor Features PCD Date: Wed, 8 Dec 2021 21:27:52 -0600 Message-ID: <20211209032800.3802995-25-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7dcb1317-48a9-48e6-7297-08d9bac416d8 X-MS-TrafficTypeDiagnostic: BYAPR12MB2599:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3276; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: djPUU1CLne4UE6UVtF8HGoY5nLav0Ub9qPqSmbcULrsePg+GtGsAWXdJVYtFgDR5nzJMXw/nG2YMw7m6nZOJyy6azZnHIadEfqwjN9XwPWZMDDVl4iz0VHVwGC50IXH3l9O2JA+K4q4N6ldMzuOvA0TZAlx8svtGF9y5qmAV6L/+3Jf7w7bJTXl+YdnGn6qic3Qe9NgJGuOKpLivBxHFWBW4G2zTk4x+Soq0i1Z3ACnr8q/g/5ba54b89ioE+sBayJRtRDK0N8yI3GIzEdkAtkKAjNQbHWCojBtSoC1N10R0DFmN4aqQvMcgOOsoh6OvXlgN3Fou7odBO6AVc57cDiLtXUxhrJ5upO33CQMUq7GvNsEkC77lNQg0Fwu8Lzq7H2iuaSiJayVPiZ0SN3Wa4z/MmFdC3JuFdX4d9XKdLekRAGMMIlFN5U6csYN+dxKwDcdziEGsdj0/5V0XrpenySjp9bdUbyO8QU4CtQn8acWA6/ei+gGnTCcEvS5ydwuGZE1RNmsO4yxSNCn7sNcFCkJ38Cibl5ufdORiAFzq0TRZo6L3JcP4W1iatwq5qO0KrjOV90HrG3IPeSTI3X3PA/mdMIiaANOA8B1YopbCZYKdA/zJK0VPoCylk+DU7my8KQyMK5Rp1um/1M0ekMmXP6dBQ8usti3l/P9vtnRE9GLdSzGlw3MqQYTH9GfE+HKep41cMzKLQh+KMmNJk5JmYbDe2oIUMJaoYATVqqDVRxYpXMgUo+jDsnQ/YmyNBrA6QHAx8AJajY+g436wA69oyC4GUHTa/vYCmX0wmKpeLvsfSQ4DR3IFnStzeJ+w0yOwyKtZvxoR7fOOXw2ERmDUY1JECTpCMc4c0UDM2z8AUYWrPnlCwLpe4cUCtj6BUXTs X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(40470700001)(70586007)(86362001)(36756003)(356005)(81166007)(83380400001)(70206006)(47076005)(36860700001)(8676002)(82310400004)(508600001)(6916009)(7696005)(5660300002)(40460700001)(4326008)(8936002)(316002)(54906003)(1076003)(2906002)(6666004)(186003)(26005)(336012)(16526019)(426003)(2616005)(44832011)(7416002)(966005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:29:20.7713 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7dcb1317-48a9-48e6-7297-08d9bac416d8 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2599 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 Version 2 of the GHCB specification added the support to query the hypervisor feature bitmap. The feature bitmap provide information such as whether to use the AP create VmgExit or use the AP jump table approach to create the APs. The MpInitLib will use the PcdGhcbHypervisorFeatures to determine which method to use for creating the AP. Query the hypervisor feature and set the PCD accordingly. 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- OvmfPkg/PlatformPei/PlatformPei.inf | 2 ++ OvmfPkg/PlatformPei/AmdSev.c | 55 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index bada5ea14439..3c05b550e4bd 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -62,6 +62,7 @@ [LibraryClasses] MtrrLib MemEncryptSevLib PcdLib + VmgExitLib =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase @@ -107,6 +108,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr + gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures =20 [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index c60a153a059e..9b71f7cf2fab 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -24,6 +24,12 @@ =20 #include "Platform.h" =20 +STATIC +UINT64 +GetHypervisorFeature ( + VOID + ); + /** Initialize SEV-SNP support if running as an SEV-SNP guest. =20 @@ -36,11 +42,21 @@ AmdSevSnpInitialize ( { EFI_PEI_HOB_POINTERS Hob; EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + UINT64 HvFeatures; + EFI_STATUS PcdStatus; =20 if (!MemEncryptSevSnpIsEnabled ()) { return; } =20 + // + // Query the hypervisor feature using the VmgExit and set the value in t= he + // hypervisor features PCD. + // + HvFeatures =3D GetHypervisorFeature (); + PcdStatus =3D PcdSet64S (PcdGhcbHypervisorFeatures, HvFeatures); + ASSERT_RETURN_ERROR (PcdStatus); + // // Iterate through the system RAM and validate it. // @@ -91,6 +107,45 @@ SevEsProtocolFailure ( CpuDeadLoop (); } =20 +/** + Get the hypervisor features bitmap + +**/ +STATIC +UINT64 +GetHypervisorFeature ( + VOID + ) +{ + UINT64 Status; + GHCB *Ghcb; + MSR_SEV_ES_GHCB_REGISTER Msr; + BOOLEAN InterruptState; + UINT64 Features; + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + // + // Initialize the GHCB + // + VmgInit (Ghcb, &InterruptState); + + // + // Query the Hypervisor Features. + // + Status =3D VmgExit (Ghcb, SVM_EXIT_HYPERVISOR_FEATURES, 0, 0); + if ((Status !=3D 0)) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL); + } + + Features =3D Ghcb->SaveArea.SwExitInfo2; + + VmgDone (Ghcb, InterruptState); + + return Features; +} + /** =20 This function can be used to register the GHCB GPA. --=20 2.25.1