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.81]) by mx.groups.io with SMTP id smtpd.web12.15087.1634672416969957697 for ; Tue, 19 Oct 2021 12:40:17 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=N9deyEkT; 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.81, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YBXK2BkYcWdYm2Sg8b9j1leN51t2UUeN77q33evXsgL7+V/Pd3hgC5uDhamkkflcSnP3YNVq3uEhWN0KrvlxybVEPev8eyg1++Ozuk8eWVUKIqGlQClCEfLkBYQNlZ3OWfzJydMzrPN7u+f3TaKyiLAGnElaLgW88wJKiMc4kzZ900qJKt7xGE8JZEOVc0xZ50ec9lAhrbLp02T9MLR5t6MhMT//Me4RVgW5sl1UwHzlEH9EIeuVmJ4H5/y3nurIy5Bdu+0cLXevjE0Ev4Apei0mDZfsE3qfB98kX3+zyENVhcWG9Q90HZPow1zlT0Ilo7wDamU52XoEO41QSVr8JQ== 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=BL/ZDTQyGpvJHm8+zKK/g5GTaldaOSGS7vDNFebt5fI=; b=OKNj1RZmuht7I4t8AQr1iXSJR4AJhBlPud+8jgj8GIkmoKCNfDrvVAnR6mGNVCWI3DXa13InuVaK1oLdWl53ZgENAQVJskFGEsnSEWb/5wVeJ1FOVfnc49i7pKV0HCsWadn4oRqWPp4yvv6fi3UbCx45qf+elvkk//w0jsJiERpXqx8CNqKiDsnw3Qa8RPtJNJqI60zOM/gdgN3TLDAGDAwBdE8iQUTq9gH/aPb9CvSq86UCEzQ0JTHi54GQ0jCkJil5fspChmhXIP4hN/NcLC8HdxUa/T8E5lNIlrewCes0U6CWiPLCnF4Hr5aIKI2t9b38IRvo6Tn0RKCdug5GDg== 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=BL/ZDTQyGpvJHm8+zKK/g5GTaldaOSGS7vDNFebt5fI=; b=N9deyEkTSxX72B8WnzFdrvc2xZN426AkdKlUsHHmbYOyVCnoLtaOYqCz+FRBQTJSgR7b5w//ii2/kvHn2hpipDidZg2Pnq6SRs87WEaavClmMPR0f6QGtdWG5UoDPiCF9PNRydyU5Xa4BEE/x40P239oZKV5CcOnC60YpsNS9j4= Received: from MWHPR02CA0021.namprd02.prod.outlook.com (2603:10b6:300:4b::31) by BL1PR12MB5173.namprd12.prod.outlook.com (2603:10b6:208:308::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.17; Tue, 19 Oct 2021 19:40:14 +0000 Received: from CO1NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:300:4b:cafe::1c) by MWHPR02CA0021.outlook.office365.com (2603:10b6:300:4b::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.15 via Frontend Transport; Tue, 19 Oct 2021 19:40:13 +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 CO1NAM11FT054.mail.protection.outlook.com (10.13.174.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Tue, 19 Oct 2021 19:40:13 +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.2308.15; Tue, 19 Oct 2021 14:40:09 -0500 From: "Brijesh Singh" To: 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 v10 24/32] OvmfPkg/PlatformPei: set the Hypervisor Features PCD Date: Tue, 19 Oct 2021 14:39:26 -0500 Message-ID: <20211019193934.1052465-25-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211019193934.1052465-1-brijesh.singh@amd.com> References: <20211019193934.1052465-1-brijesh.singh@amd.com> MIME-Version: 1.0 Return-Path: brijesh.singh@amd.com X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d76e314f-9885-4025-5494-08d993384512 X-MS-TrafficTypeDiagnostic: BL1PR12MB5173: 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: JQceNHqpq98yRwMTsr4Z4SGuJbhYRLMW3vNoRVkPifZgtifVuoRo+ZD4T+KftwzB9JhOg8a1sKPn8atd69Cf0DWiDH4EnXQBo80Ttxz0CypdA4S/WwbYsbzDDQpzysGfJf74uRTUf6M2owDPmnBATjO+ysGSDIR67Y+ArZaFRaIemxtQrDYf00kg461AgQg0ovblU3BSKow8l/TIQRRaZfHr+UhHZ7xTl5hShP2rww2OzAeQsGt7EVQjkjOZ+E2LeToDyHc3QnC0NOf35kDtx29ejsKYeMF2uC6BiqfFB2UI9lPyHK5Bxsrngq2TGAUYiTG94DUIyWNi5Ba7oBVOUcu6Ly1/nKUXpJ9NgcdnfB//iOaMmtqMnz4hZoTgvkZzECZZ6N7NpPi0mwmXzMSvPlCrHSSCUa958Sf4HrfwMMY1iEUUBAVamzE5LtxYiggJf6GwgaCinsr0g3BDGMwqYwZNWgk17ksBSkixvPa4/1VmUwifFLPBodQ9cjMwGEEp4J5wgrJ1NZ9+cSj/clTmL/giRKotW21Dz+zopZnF/8DI4RzpjTpKpv2ezX4cqFv4HzyzxYgFoJUtSbgIaWFKoIXJMgYnhInne8l1tSEj6np+rF4k46N2y4YAXylRw6KpmPpBRc4h33u/VtczpYq8vpqfLEfJpbKdoCAJ3kT+5VxX33T9GqDVKbFBbpcROloUDkh8Ah7lz9IV1+BBgDq6yPmGYHmUnjdFryUUPk3elFR16QTcrPQ/s7AxhrADOeguJL62C4gAwK8I9xOz5X7HxvkXJ4eIu6nUutesLteUDRGVoaOdHfBLpuAqzF9Hp+Jy 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)(36840700001)(46966006)(8676002)(86362001)(36860700001)(8936002)(36756003)(1076003)(316002)(82310400003)(54906003)(966005)(83380400001)(26005)(70206006)(70586007)(186003)(44832011)(16526019)(81166007)(2616005)(336012)(426003)(6916009)(5660300002)(7696005)(508600001)(47076005)(4326008)(6666004)(356005)(2906002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 19:40:13.4407 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d76e314f-9885-4025-5494-08d993384512 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: CO1NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5173 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 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