From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.88]) by mx.groups.io with SMTP id smtpd.web12.14900.1624902226236465703 for ; Mon, 28 Jun 2021 10:43:46 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=5B/gg+lP; 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.93.88, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cbv9W/QcALpW14t1jXPpoW7k0N6YQEely4PVle2SY3nQeJV+Z+WUfJHXl+s7P40Tc8Wtp+yLuqB3SeCsQOZjEQzs9rSkRc5XIsoA9+mm+i7wUm+2X4rMmpa18hC+2vCfdomib9MSOxyfL2rIrqpnttvXXVPcuJj6xu5rL0m0FqKoPAbHeEnKZ0NgZx5G9G+KiQUaH8JvYjJNqtGe/ap4Z0deu+dsESabVEYnfe+XC2GlSMm+yE+UxAEJHr0siSvVcKLum8tnKitOPSqDoTeOmGaOxi839ijcHPGsvjLRNL/zkiOZQv5Hx80/HEtt2fj4pD7QowN4DB7F2JfXawwKoA== 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-SenderADCheck; bh=HarEirsAlWxBPkdouOrEXW02GvfNEf8OJefmxvRVBBc=; b=DhBvin9XbKL9I8v3v4/GIWLDGiDUllgSNIUd9suO9T5W5xWB4nXAgEOTGLpyuFUHF+sLefs3rHJXvQDAfhny8r6wfNBunwUIdoj/3wReWPew9BdGFjmZop+EzyF9Zk6depBcrhuKQv2kQC+IdmdFwNcJ7RkKGF/N+B8vXXtqxjTVWBfSw3DySyp03dCVVOesbiKCEK/74u8U7+F9mmdLetkHSDgNsH0GRob0b1/xEiJ8fDVbkVqh2y67EQVtizNKX7+PkjQZBD+gbQrHr4RFvcH2Y5M2VJUyYvV2DNfpBNS6WmZAjmE/nSiOu/99psoCb8MHvmhFinfGhO+bJ+3PKg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=HarEirsAlWxBPkdouOrEXW02GvfNEf8OJefmxvRVBBc=; b=5B/gg+lPe+KJTUWcWLXodsIMtBhXseN1POhcVKDzyAI/WRYpgt4qarxELURDPBOtTnPJaR6VRqhXtBC7lHQwMzSlQpwONZumhpFT4SYsDGpQYr3Nc0lN2dR5a4fv4GEnXPn6V6sUWoDhZAHuNisW3B0CoLHimHfPQybL00XbFD0= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) by DM6PR12MB4371.namprd12.prod.outlook.com (2603:10b6:5:2a3::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.18; Mon, 28 Jun 2021 17:43:45 +0000 Received: from DM6PR12MB2714.namprd12.prod.outlook.com ([fe80::7df8:b0cd:fe1b:ae7b]) by DM6PR12MB2714.namprd12.prod.outlook.com ([fe80::7df8:b0cd:fe1b:ae7b%5]) with mapi id 15.20.4264.026; Mon, 28 Jun 2021 17:43:44 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io CC: James Bottomley , Min Xu , Jiewen Yao , Tom Lendacky , Jordan Justen , Ard Biesheuvel , Laszlo Ersek , Erdem Aktas , Eric Dong , Ray Ni , Rahul Kumar , Michael D Kinney , Liming Gao , Zhiguang Liu , Michael Roth , Brijesh Singh Subject: [RFC PATCH v4 20/27] OvmfPkg/PlatformPei: set the Hypervisor Features PCD Date: Mon, 28 Jun 2021 12:42:16 -0500 Message-ID: <20210628174223.1302-21-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210628174223.1302-1-brijesh.singh@amd.com> References: <20210628174223.1302-1-brijesh.singh@amd.com> X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN4PR0601CA0020.namprd06.prod.outlook.com (2603:10b6:803:2f::30) To DM6PR12MB2714.namprd12.prod.outlook.com (2603:10b6:5:42::18) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN4PR0601CA0020.namprd06.prod.outlook.com (2603:10b6:803:2f::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4264.19 via Frontend Transport; Mon, 28 Jun 2021 17:43:43 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7cad8306-4a70-42f2-b004-08d93a5c46be X-MS-TrafficTypeDiagnostic: DM6PR12MB4371: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3276; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gJRf4fIN5CWeIf1iljNoo6atgM61NFxF0iJanIBzi0pXtYc2Xtf/Vi/uLbPHRunGjIvM2QxZQR10qVJkHGbPkyC9BX5UeYhQGICRNA+QUSp2zXkJPZv/fFYDtOknkOfi76bz8A+baGfPCHJuFVs8YGVOMG8STa93LMwNx55B5Tn3Px9QoZxPeLomnu4gtsHQ4KT028JtSvaHWAQyj50UtE73MsPNxQkycHQppC7UW+Vng651bKQtIZfVvU2PW6bmCPRVD0dwJWicp4d105G+Wh1nOqTORJvszpku8IY8kjAYxp1Jkcy0afJe2GcXcIY8VWYnt5DufBg4KidBtErxDpfCa2ThjtnekB+2JwKeRX+omU0B1IixXxmvla7T6FDGHYzTU1NmMwlaxXxK3S4LcSGeEVIxXQK/X0t2udDHM/1/beDDFCL6AZhC4OgW0cy+iLJctnw/aZWa4l6bauNO8LG6cKWKKnN0dXizswyJkle3USvXt5noYJZn4tBD5bQOxWbRs24xOX27WVX4iaTVYJrtITdtR5LP0AQYyK0GOsodmAPNheK2Hsm4+yeXEQOsqjxf+lEEEiWJ6xwSKXLUEpYnkCJtu/7JIyzQMy3Z8JliOiMmIc0TZQWYIpc7ohvBsybWsAD2Jr59sqxw2OaV5tSLbefr4A7lgw6sKknJ5yUCw2Fap472DqXvHpPHLCtIRG+2Yl1DWcefcJj4lUdPsAJpcWryA/YSK9yEjkxm6OCGlvCv2j2dpZwcp4xpAxaZ8hG/zfI0B+zOBO6QpzU3w4aHXAdvhQRzuPeIKJ9TVFvWJIbDzXh0RjDCJy5dF6G6 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB2714.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(136003)(376002)(396003)(346002)(366004)(8676002)(8936002)(83380400001)(7416002)(66946007)(1076003)(36756003)(478600001)(7696005)(38100700002)(186003)(38350700002)(2906002)(26005)(44832011)(52116002)(16526019)(966005)(6666004)(6916009)(4326008)(54906003)(86362001)(5660300002)(2616005)(66556008)(956004)(66476007)(6486002)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?5D3asPh+wauy7PVuJAfC2O4ezAcGw0/XrPDfYbNVXLbKElp1EGBvSNg2lVqJ?= =?us-ascii?Q?y9y9o8b8wCV+UxmjpvXDAQSpuAXNy+TPG/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= =?us-ascii?Q?6ejhURtVYN+qE3EMgGagEyvnUkoI3oTVNtmhocTz/hnUfjlqMguzstLDSb4G?= =?us-ascii?Q?42cT9DfTwELdS64GO3/OH8IK8VDPC1S9e8cmpfObLL/Z4OVY/Ccisg+ShpNY?= =?us-ascii?Q?g0DS1Oaan69NKjxYSOVcLqusDdM1LrjBcfXcfmRlFEmy7BJ+wRcGGRJJe2ez?= =?us-ascii?Q?wFijSlz48z+MlPxh0pLK84uRcUYsJAhLcCxvoAlX5yqFy2NCvNnDzWcAplfy?= =?us-ascii?Q?kTs3RUfuhxX0sRI2eK6FOJhpdoSobDMnB5spxeVt/uZ552LeFJIYYTzru8GN?= =?us-ascii?Q?zXdVcmIuhcBGFMYEOQ7RhMTPh611VYd5TftoMFO3cgOJNtO8SDAeBsQ1ieaK?= =?us-ascii?Q?3RTMxozoJCbz2WxuM0A2snBA?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7cad8306-4a70-42f2-b004-08d93a5c46be X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB2714.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jun 2021 17:43:44.9209 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: W/YX6JErLdTIzpvKtV8/9hn3kBX0OBhMfOs7iImOrMAaLdvBWleFVQrRn5YR/ZwsMuVRYhzCDrGiIQqgKOpd1A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4371 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: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Erdem Aktas Signed-off-by: Brijesh Singh --- OvmfPkg/PlatformPei/PlatformPei.inf | 3 ++ OvmfPkg/PlatformPei/AmdSev.c | 55 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 041b3262ff3b..bd0ade9f33d7 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,8 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled gUefiCpuPkgTokenSpaceGuid.PcdSevSnpIsEnabled + gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures + =20 [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index ec577ef3efcc..b488cd5aed9b 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -23,6 +23,12 @@ =20 #include "Platform.h" =20 +STATIC +UINT64 +GetHypervisorFeature ( + VOID + ); + /** Initialize SEV-SNP support if running as an SEV-SNP guest. =20 @@ -36,6 +42,7 @@ AmdSevSnpInitialize ( RETURN_STATUS PcdStatus; EFI_PEI_HOB_POINTERS Hob; EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob; + UINT64 HvFeatures; =20 if (!MemEncryptSevSnpIsEnabled ()) { return; @@ -44,6 +51,15 @@ AmdSevSnpInitialize ( PcdStatus =3D PcdSetBoolS (PcdSevSnpIsEnabled, TRUE); ASSERT_RETURN_ERROR (PcdStatus); =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. // @@ -94,6 +110,45 @@ SevEsProtocolFailure ( CpuDeadLoop (); } =20 +/** + Get the hypervisor features bitmap + +**/ +STATIC +UINT64 +GetHypervisorFeature ( + VOID + ) +{ + RETURN_STATUS 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.17.1