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.61]) by mx.groups.io with SMTP id smtpd.web12.1426.1632163600302992824 for ; Mon, 20 Sep 2021 11:46:41 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=ZI7m3POo; 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.61, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c808GCtgG/O3Kcyu8KbQV6YivlaeqL28irAnwMV4cWo6vkPvgTG8ID3DhayRo0eGVLF1uHY3reAxtaEGXxn91WxLq+w6xW8g7jtd+ik1lhPedFgLeYSRc6oaQWrJYRew+TTyHaR8gBGSrj9NCNG3UMV5KDqXQaC4TNRtKHKq+EaMasJEqFVtUFUbCL7ECmCA8A2U64bwMgBF0wBqobpB34YKfKrEUzxZy7LKyDG4uqPPNBabAPLP5GCfqjTRdoYbsewews6fvZM6uE9gsDTFhKx3l+ZeJKAVO90DztFoX+EPsLAgnTV32+OkVYYZIaFS2PneMgV9R9pmzMQop0XuFg== 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=/hdsez3xb2KZTWgM42sW8N43QppxNiNrNubCQQZPUkY=; b=njlstk7YLSRmknTK0ZxbZHZi9oG3BiIBbV6fKTJJGMD1DmSAOD2j6xgI1Nj2ox96FfsQi9slahE0VsILrAPoHBpCOQOPSx6i+oYcOkNpYtbyoTOMCpBHer2qbaCH2dstzDIedcVPPT37blXGVEfXd4QkuoKYi6sDTuVRYbMysfLjpkmn/Vl0qSma3nkoa18VWEDGbeIF9wpqudW73ZacIYX+sGOrraTiwz0C2y98JqmqcYPmxB8MDxoNePkyhGdJWKMcPWS+gEFgQ7qBr8OCpiz/lihdX4Enw1FnTcZ7Ga5IkFVo1VMUtXriKOEBVqxciNUpmQ8CaNRvK2gBe7+h5A== 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=/hdsez3xb2KZTWgM42sW8N43QppxNiNrNubCQQZPUkY=; b=ZI7m3POoinWNgDhhdr5JvP8okBs85kCFg4T54qbCq+DsBqEgOY3hxLJDaeUnKlJw12nM9UbrMHMJElXFuqPmdjbIBoAhr59KjeySJaRkGo/Y9MJkNmFgdR/jChuO+9m3jYppWsqgxKen0dRWR80eH8LTqkBKvf8ruCpjlg3/I54= 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 SA0PR12MB4575.namprd12.prod.outlook.com (2603:10b6:806:73::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14; Mon, 20 Sep 2021 18:46:39 +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.4523.018; Mon, 20 Sep 2021 18:46:39 +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 , Jiewen Yao Subject: [PATCH v8 24/32] OvmfPkg/PlatformPei: set the Hypervisor Features PCD Date: Mon, 20 Sep 2021 13:45:56 -0500 Message-ID: <20210920184604.31590-25-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210920184604.31590-1-brijesh.singh@amd.com> References: <20210920184604.31590-1-brijesh.singh@amd.com> X-ClientProxiedBy: SN4PR0201CA0034.namprd02.prod.outlook.com (2603:10b6:803:2e::20) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) Return-Path: brijesh.singh@amd.com MIME-Version: 1.0 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN4PR0201CA0034.namprd02.prod.outlook.com (2603:10b6:803:2e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Mon, 20 Sep 2021 18:46:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 78b57e67-b8ff-4d33-90d1-08d97c66fb11 X-MS-TrafficTypeDiagnostic: SA0PR12MB4575: 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: vRbsFQscNxRiuifE+r+IqXyciPBiU8CvS3YEDGZlWgxy/ENd8ZI+QnasIwUw1FU42bRjzSxtAf9Rvaflur/Bp2f1uzStMy3Eu3/tSMALTHfHl9HeNFUxGeSh08QbrjsTRm8mWYhxnsAdVbgqcqQfPEpMjyfJgrWypAkb0cU3e+06NFXVaqGdZrOz7L6MisAPYrR9QZhqS5RtQFxNdmPc4Le1Fot3X1UklxQs0xFg3ecB4g4bMDbnkofJ18sETPfNcCWL4IKygDF8157zqKEXEi3/Eq6AxEmUcfezqqHC07YqtZspqy5C6aBlt8ai4oJHRjFZTudKsFNJ88FsKvvY+Krp2gboZLFBuoTf746FlN+NKRCmjoBcGGJwjhgQ54+WS84HE50kW4Iv0+EBGHs85fn5cGosrlXzFO7MX/Cl1Fo6zOGLf4LXg1jvLHaYfzmTQKXmE8y9eQC916u4UTjOJLFsf822Iob9tY30oLnt/PB0xu8Bfi6QIosxiVKo6cz9DVvoAkcWZ9Bj1ANasMqLTvMKSpPzU7ymu1hA8IoLeatXvKhS/Gv4n6yHiOyaI5Btahhq3ZMi0I39nwXxxZjd3bsqd6RkEADPV+erRpRTDvn6V2zeFDxAtmnwbPvie6OHhlnRVURtAaDDuGqsMYF/Lia6MduyfLSOQUAcyeJAB7ozgG4nS3Z0nw8Dcj7bBt8dksuy7tDEHI66IdCsL/QVI7HtCmeIbJlBS6PPCSNixte+98G+LVFKtwxw0OLL2rTbGoS8dyV1C6TeBcQAP25beA== 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)(366004)(38350700002)(44832011)(5660300002)(36756003)(83380400001)(38100700002)(8936002)(66946007)(508600001)(6916009)(7696005)(52116002)(1076003)(6666004)(956004)(8676002)(186003)(54906003)(2616005)(2906002)(6486002)(26005)(316002)(66556008)(66476007)(966005)(86362001)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?vqjxTJudtAk6n+CXJ9O9SHTO9UxGQ8RHM4Jhqwx7/peqxIXb1dBkgfLGTWOT?= =?us-ascii?Q?VQaAU7D0/v3aCPZ87m9gcL1zp6wAAnRUts0rYL6OEEFVUAhRpzfePne3M/rz?= =?us-ascii?Q?v5T13f+sUQtN/2NLUemFHbjtLHw53c+TGkZ7AvM5G1OK9q8ygvWKYbARrVN0?= =?us-ascii?Q?Ljl1t+MsbX0a3RJ/Ys1mGHWDL4+DdnvFIUeTAfmJ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nj87Q7Cfyd/D7dl/m/VNeJ4DahZXR4WuZgNb?= =?us-ascii?Q?4S0lYFDk3b7d0V5fZMdavbWarW1gP5EP1eMqKsqzrnYFHHce6FTX52jGoR6y?= =?us-ascii?Q?zjeX//LqDPW0KCDltWeepr6drm7yWon5a4f2uxOJCyvTT4o6e91iUS/pNyDM?= =?us-ascii?Q?bHSIEgkYr1e/TvVQbIv+R4vRT4DBrkPtbKMW+smi4n9fwiz4uk997hy6Ig6w?= =?us-ascii?Q?VzYt/gIbvP1FJjyrujV0uuuf?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 78b57e67-b8ff-4d33-90d1-08d97c66fb11 X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Sep 2021 18:46:39.7532 (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: AFtX6SMBKvCOK8NeF4wFz7rrwE6p+AZ+OYmHecaohuCodXkizv89HGJQsIyqlM30KTj4GEP+EgdaBjQHiK5ieQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4575 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 Signed-off-by: Brijesh Singh --- OvmfPkg/PlatformPei/PlatformPei.inf | 3 ++ OvmfPkg/PlatformPei/AmdSev.c | 56 +++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 233b9494f64b..d048b692f155 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.PcdConfidentialComputingGuestAttr + gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures + =20 [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 5e2c891309d4..b71a4a7304f7 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