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.47]) by mx.groups.io with SMTP id smtpd.web09.156.1630513070864767401 for ; Wed, 01 Sep 2021 09:17:52 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=kbCFo0tu; 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.47, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HZSCF9JHYojYCRRZo+l3+IBr6eb8VW6Ptnt5nmVW/Kw7E3zPlqDgHeiG3P9ZlfcQ3wt9YW3O7rQH10rPJN3t91VCWP8YAySEesLpoT3qAoM6HcoKNPSiwKwtHvmEqTafWxG0tHUnPhDJzAUAeJsdD7NLq0XgvdgLNLemyjEVImhVn5gwByvTLXNUWAjOXndM3axbqVgMOFuYe0y5Fmvrbv3DXhkmc+d6d2CJpOtdBuVS80ie4gGc/ba0uE70+M4+dy8DduqW1KbIi0/P8+xYn9drGIKbFsANwv8Y1CmCwlrqxgrzUO7IwpV1VvEgKHlrmonGtho4jo5IHqSZPSSctg== 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; bh=9OrGPvTZvfeDqIruWJry2xwW7hUkqVnvvrCbg9Y4xE8=; b=L1zmDDlkxwdDLq60ap6VvtJ5/weLpDr6ujI7ep1lddSV76K99u7ujoUtp5yi8VcLtgkIib+3Cj0rJ8aWBQr6EnfFPBVX8F8jTlLX9g6hWD7fnFxhRpp8+bSLdUv69GVbIAEoRjFjo/Ey9/V0zGf19w6VpogbmlC/5XwlpLWHG//ZIEw7fjp7It4EM7+wEa+QNlc/FkjQ6oi4jDv4BI8waIIEMcvI1SNAcfRuc95cAL9w5cQc/hdCC6RJIlo56PvoB4Z8RA8JL/xAEB6DzgY55xZvyWiFxnp6xtGhYrieaWL8SzMSHdu1PKbQ96Sox/3brpUITkf1sjbYfToXXFIMDg== 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=9OrGPvTZvfeDqIruWJry2xwW7hUkqVnvvrCbg9Y4xE8=; b=kbCFo0tuNrD23dyd3FJpDcsFjKzZQ31ZOHASJvE4d0Txc9J095fnrsrccRQGlzP/bcGDKepcKhsa5qFOMopliHTCdhk+dDe1BHuAkat6LxsLdN5fPVsh9I8SJzBRvptVcsMyV9Snr0SMyJjE2nPnrHt+s9BWlPNcjfeTU9Tsky4= 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 SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SA0PR12MB4512.namprd12.prod.outlook.com (2603:10b6:806:71::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.17; Wed, 1 Sep 2021 16:17:50 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::78b7:7336:d363:9be3%6]) with mapi id 15.20.4457.025; Wed, 1 Sep 2021 16:17:50 +0000 From: "Brijesh Singh" To: devel@edk2.groups.io 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 v6 21/29] OvmfPkg/PlatformPei: set the Hypervisor Features PCD Date: Wed, 1 Sep 2021 11:16:38 -0500 Message-ID: <20210901161646.24763-22-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210901161646.24763-1-brijesh.singh@amd.com> References: <20210901161646.24763-1-brijesh.singh@amd.com> X-ClientProxiedBy: SN4PR0501CA0062.namprd05.prod.outlook.com (2603:10b6:803:41::39) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) 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 SN4PR0501CA0062.namprd05.prod.outlook.com (2603:10b6:803:41::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.12 via Frontend Transport; Wed, 1 Sep 2021 16:17:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4e21b71f-6f8e-4f15-5658-08d96d640b57 X-MS-TrafficTypeDiagnostic: SA0PR12MB4512: X-MS-Exchange-Transport-Forked: True 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: eCooubiJUDyQAwVNPcdfzrHJU76pYoQq5i+V/JVIq0TjkGtS7zPDGhrl9wZ1Ilpkuvw+pxwE7ablExzpKqlv+tGBt2vSE8OAKZ6V2/91/GdhZgG75lx1dQ0UOZ0WowHVb2q7wIskgBNaiwceaMbzhGWq0L0CEVYgKkAgYPzxk/BXo5HgQFxzZpxPNGDiHop99QyycWT23xZdepmgM66yXch+PMfWgEnk/LNLeGEBabtnwIZ0MFi51qUoQ2SCzVN5R1wvMd5qCf+BwZdkx1h8WhxrH+772ZTZNKKbMvsL7nqIESGN3aILb+OtOyxeKU9k/4SujkEyJduRK7X+/lenc+ddyavql19s9ulik9ivE5fimWuFPIQZVS0eoVkFwJLFZwQh18DkANA7lPUuRgWhrd4iSbIkxvu9gsBRsJwZiWQ4TF4Wrws0fXsChCSLFT4FJNYQ5VSVQsS6kYYzip2LYwaZrfqg8LEwCXeZ36JJ4AknBBYLhdkbAph6UfAmKpdRNKaxlWWWrpYE8ZmIAGy+WAlHZC82kNn70J4m14pQlg5EEi45FrT0k/JYzaWU2MUNws3NSNcc36qiNk3n2KgGXek8durZrtCsyGeMoLF1h5D+qiBeuUQYTBQlvuWrzI25CzqcP3YpghRog+xaeYLzlDdxMoGmCTVbscB1sHCzEV008SdqgpYK5VPG+iH7josUg/oPjxY7LJgVkh/hIS/5plL0yX2IR1e1HIkm8KJZLLuAGU6oxrOeNaMmNAAeRoVe8zaRg2RWBqEl+eY0I5aS7V2zwXO1BB60OY3Q3dqERY4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(376002)(346002)(366004)(39860400002)(136003)(66476007)(66946007)(66556008)(4326008)(478600001)(316002)(26005)(2616005)(956004)(186003)(83380400001)(44832011)(5660300002)(966005)(86362001)(54906003)(7696005)(8936002)(36756003)(2906002)(8676002)(38100700002)(38350700002)(6486002)(6666004)(52116002)(1076003)(6916009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?sLVy9ANZIxOKahQkGrUBX0m5CjaSPJld7BwJ19abNzt6C2PzwXolp/ONRRQn?= =?us-ascii?Q?Sk2TtS/pCN2orzNMwXzJcBj2HGB7Z5C2U1xUkimwQvxPycmOHE9Hp/LNpp+3?= =?us-ascii?Q?INsAMMAZn/ot58iijwXMFXNaE75yRTN59cmdxNpqSvIhVj/Fp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x+E9vBJO3zAK8fxan4/oTTXW/8fc4UBN+gI3SEDCm/XGHIBeq1OW1?= =?us-ascii?Q?czb5H3JGWEVefwayfyRGR/b95GXWjkVIu4mf5xU1F9MkmsQpuea/FmkfRe4J?= =?us-ascii?Q?BHvyw96YOkjZIIeeX+g1/HZjkIxs2swzDRm5/V3XjXosFSvJZJdSIVazM1H0?= =?us-ascii?Q?MpNhw/ihOOGS8dqrxQqZWBTYza2/YJqzq6kL7LurEUfWT5m9dDEQgehe70UR?= =?us-ascii?Q?YvNvr8OwPCOg8jNDfQwPDz9hx779xBPYUjcKvur3ZFyuuUkTjRfkBz+HYNtY?= =?us-ascii?Q?UCwAw/i1bP9QX2qHWV6rO88Q?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e21b71f-6f8e-4f15-5658-08d96d640b57 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2021 16:17:50.5225 (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: U9zNXRv8a7N3K0EXZIkGQ+t1IvvzT2JDles3pSyo4Yp4ugHaXr8VoBBcX5nJStJhdy1nns+XuCpn0YLvxX5Svw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4512 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 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 c8c89ab648d0..8c9795095a10 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