From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.60]) by mx.groups.io with SMTP id smtpd.web08.2421.1636582532855986443 for ; Wed, 10 Nov 2021 14:15:33 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=iVHVktca; 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.92.60, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ngEEG7SVHHdXHc5OhnZYP0pgsGFGLmDyrxgjFZunlWdOucn+18oxPa2KzNn6e/Oroin8ki7VYyYAe7pFdZACYGyS47glOwSnonAQCDHYMR6oJcV8LalPpEZfFJh1jAE+0dELyEVc6Sx9z1mUYqn9CdRmg2BFCBhoWCv+FF0U92zrhlj2wo04mcZpuNXkanpSq8adEf8nhEPjMnQhidqc3ZKyMvazllmTDi+3H/L/Ndcp1goHZCgPYoKlZKhd0/lICUhH08KfWbnfKg/MoDQKqB8rhaBBZQiAqnat/XBMcj4fjlSF4EBU87uG5F5I7ESG5HiXRES0eI9SS/B8cjbz2Q== 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=EGKMOfstyLIrpsJe/EKx5CLbterS1FlHUOciwvJTk0M=; b=V7Yt2C44hHuGAhTivm19+HLPah2+0y5WesnLYQLZUd10JAAyxOij/nDZStoQ5Gm91CPQ98wyIhozYEKgGQO7EvrbD3CbER9CVx1WiirdLj5Dl/T7jDaejVF2mCbhU29/qGqXqNKb/RMvub4KFcH7UFEuGVa2G0eVxOPyv0CkuVk5tR9L/WSEWrF7ekz1KR/BTrpvLMpp9bYIO7vr/5bEDJnwPJuF9ANucKtmAEPnc0007QZ5sgyE9Apre9M0j2Ju0OM0fPV4AMfun2gDkMgMVcC29IEZoTP9nqujl168FaKWcf4cWu3dee7H1jPvhP7Or9S0IRHsMf9IRBZhhoC7xg== 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=EGKMOfstyLIrpsJe/EKx5CLbterS1FlHUOciwvJTk0M=; b=iVHVktca7XyyXMbS6ZeXeZOBotQKnJ6SX0oRG1SUVbP7ukYV/eaGUimRuPJEjxYKuuz2ByDRu0OtJ1Glbr+HNdEMbpIsQcZpWlyfHsK+zov2O7rpUIO+zBwNqKly0gN5EoBh3ZHxf8Ox2VBnvQkap04pSyH0Ry2JrjDYutiofJU= Received: from BN6PR2001CA0020.namprd20.prod.outlook.com (2603:10b6:404:b4::30) by SN6PR12MB2637.namprd12.prod.outlook.com (2603:10b6:805:6b::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13; Wed, 10 Nov 2021 22:15:30 +0000 Received: from BN8NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:404:b4:cafe::51) by BN6PR2001CA0020.outlook.office365.com (2603:10b6:404:b4::30) 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:30 +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:30 +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:27 -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 v12 24/32] OvmfPkg/PlatformPei: set the Hypervisor Features PCD Date: Wed, 10 Nov 2021 16:14:49 -0600 Message-ID: <20211110221457.2397234-25-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: 0a878752-bb6f-42ba-1fa2-08d9a4979b56 X-MS-TrafficTypeDiagnostic: SN6PR12MB2637: 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: NLiR40NRTBZM+62OybXHmkiHqbZXwPaRxp/S4j+ZmXe8lnJ6bHOxtqHDfRPPRA37obUkQUTjc5u+KHp3FMtjf+UIgCDwMEpFLWlwWK6APANiiyYRe2JLB/YhEU/JFlibEGOUFN+dCXQRgJSvP9fiF/hAWZfmbqPMjMfzW+Z9QkGgKw12G3zk5rDIH3cTqPkVObgUCDhs8Dy9jYYRrNubaRsOahjQpUAy6QfvS8i7nW0VfPpIWgoCXrIcjEEf7xqlPDgxBrjvEUh79HYRVKQZkwLtFKuKKa1cVAXg58dG1mk+eX1EyGfYDczJOSs32ODf+b0bi+I6vdtFXHuP0xcQnhElyXJGh0vYhjabg2SguO40DbeLyJf6xhRsinJyOxQLZO+PnzknysBBCfLm4bcUAEIhSL2GTfXa1HrTgSQ0gO1tZ/LlHIuL4G/LrDFvta+9TKN2k2kOwD1lMEr2Rlk7C5RXnWDqsbKPLfdjUnAI4WegNcnDGcvFb9AONvHTyp6CS8SDLzrsoDL3DNCMbTsmw5r2AKmFjpgckw1bqmE1vsQtIx55oVVYXPbVPEs0aA3yoo8eWXLfVZD6FEDAaM+PuNSfg+hOQmh9hvYf5C01h2FsvMi+ppEtvxiTb7P5L/9n63o3ikjie/1Pcq1r2/MGLMdk1Awa2IOK8gb1kFXSnLF3m1Pxh+ON/FVxNHFkuKlstQr4nZ44Prn88jhxFj+ShmgyAb7K7rWdMsACn0MU/RGGp0V2BQI53KMYjxG3ZQZknKlumzJOB+3nklsMZOQRsZJIbWGkDLaoAPwfLKQZLdtrQdRlxkgCu37C7s71ADKe 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)(336012)(966005)(83380400001)(6666004)(81166007)(356005)(5660300002)(16526019)(8936002)(2616005)(8676002)(36756003)(7696005)(426003)(54906003)(86362001)(70586007)(70206006)(1076003)(6916009)(7416002)(4326008)(316002)(47076005)(36860700001)(44832011)(82310400003)(508600001)(186003)(26005)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 22:15:30.2335 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0a878752-bb6f-42ba-1fa2-08d9a4979b56 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: SN6PR12MB2637 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 | 56 +++++++++++++++++++++++++++++ 2 files changed, 58 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 c447753075b1..7da6370113f0 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,22 @@ 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 +108,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