From nobody Mon Feb 9 08:12:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+88223+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+88223+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1648597664; cv=none; d=zohomail.com; s=zohoarc; b=cI3FxlFoMqqUiGjzQ5mqYemiUNG6QfuW1MHRve+JC6Dx7fsRplzYAgs7wJwBsvdVZ84OrE4fhOikiLWIV1+K4YaTpD6nQPb4DPqEaRnhkpSbTI4jPw6zGGiI5e5oj9Vrh9LvvfQzZLtrnWro7oOqxnTDh9ae2ED+v8/znG+SR6o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1648597664; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=cF+/qjqfz/UJOooXefJP39iSZ4urqoSoj6MCrQuNDVQ=; b=AqMK68dlbJUMPwvKwdUzgLReHmtH+gEXs7t5nz9aoQYb7uwLogqy2ip2r5xPboeQcCW8czCD08DJV+glqxMoNc7LAK4W6mZVtJ9eBuuYVIIAAfzydyr2IiTPfmQ1RMtpSrH6rsp2HATXp9Z98030tHJfyoGUtb63WerjQnNhV+o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+88223+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1648597664531409.39813747775736; Tue, 29 Mar 2022 16:47:44 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 6fwnYY1788612xfXxUJJBfwQ; Tue, 29 Mar 2022 16:47:43 -0700 X-Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web12.1139.1648597631562797263 for ; Tue, 29 Mar 2022 16:47:43 -0700 X-IronPort-AV: E=McAfee;i="6200,9189,10301"; a="259375181" X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="259375181" X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 16:47:43 -0700 X-IronPort-AV: E=Sophos;i="5.90,220,1643702400"; d="scan'208";a="521658589" X-Received: from zhangpen-mobl.ccr.corp.intel.com (HELO mxu9-mobl1.ccr.corp.intel.com) ([10.255.29.230]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2022 16:47:40 -0700 From: "Min Xu" To: devel@edk2.groups.io Cc: Min Xu , Brijesh Singh , Erdem Aktas , James Bottomley , Jiewen Yao , Tom Lendacky , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann Subject: [edk2-devel] [PATCH V12 14/47] UefiCpuPkg: Enable Tdx support in MpInitLib Date: Wed, 30 Mar 2022 07:46:07 +0800 Message-Id: <4bea523a89e872e3abe72eb5e800a0a245282480.1648555175.git.min.m.xu@intel.com> In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,min.m.xu@intel.com X-Gm-Message-State: G3VyHbhPDtPzccDvXGlW1pPbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1648597663; bh=jdwZ7YNGEfkN18Ef0PKUfxZIaZj+ywt0rpGvXmEWEV8=; h=Cc:Date:From:Reply-To:Subject:To; b=QWe1w6K/SQ9oUGa/P9sTOxyv1Oy1YSwaWpEf8flg+Yk1b3pFJNdpj0eDLp5ghHZt8K/ gdFKz82+evQbVeTmCH0TxQsSlkRDN4Nu2RUcY3khv/DwDPvF305fIwXsRkHPN/4YEJBVL Olszq5BEJWMjzBCpS7am7tIg9Zc06IWMdxI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1648597666518100003 Content-Type: text/plain; charset="utf-8" RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3429 In TDVF BSP and APs are simplified. BSP is the vCPU-0, while the others are treated as APs. So MP intialization is rather simple. ApWorker is not supported, BSP is always the working processor, while the APs are just in a wait-for-precedure state. Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Tom Lendacky Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Acked-by: Gerd Hoffmann Signed-off-by: Min Xu Reviewed-by: Ray Ni + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef MP_INTEL_TDX_H_ +#define MP_INTEL_TDX_H_ + +#include +#include +#include +#include +#include + +/** + Gets detailed MP-related information on the requested processor at the + instant this call is made. This service may only be called from the BSP. + + @param[in] ProcessorNumber The handle number of processor. + @param[out] ProcessorInfoBuffer A pointer to the buffer where informat= ion for + the requested processor is deposited. + @param[out] HealthData Return processor health data. + + @retval EFI_SUCCESS Processor information was returned. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist in the pl= atform. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + +**/ +EFI_STATUS +TdxMpInitLibGetProcessorInfo ( + IN UINTN ProcessorNumber, + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer, + OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL + ); + +/** + Retrieves the number of logical processor in the platform and the number= of + those logical processors that are enabled on this boot. This service may= only + be called from the BSP. + + @param[out] NumberOfProcessors Pointer to the total number of l= ogical + processors in the system, includ= ing the BSP + and disabled APs. + @param[out] NumberOfEnabledProcessors Pointer to the number of enabled= logical + processors that exist in system,= including + the BSP. + + @retval EFI_SUCCESS The number of logical processors and ena= bled + logical processors was retrieved. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfE= nabledProcessors + is NULL. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + +**/ +EFI_STATUS +TdxMpInitLibGetNumberOfProcessors ( + OUT UINTN *NumberOfProcessors, OPTIONAL + OUT UINTN *NumberOfEnabledProcessors OPTIONAL + ); + +#endif diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 4a73787ee43a..91c7afaeb2ad 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -9,9 +9,11 @@ **/ =20 #include "MpLib.h" +#include "MpIntelTdx.h" #include #include #include +#include =20 EFI_GUID mCpuInitMpLibHobGuid =3D CPU_INIT_MP_LIB_HOB_GUID; =20 @@ -1803,6 +1805,10 @@ MpInitLibInitialize ( UINTN BackupBufferAddr; UINTN ApIdtBase; =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return EFI_SUCCESS; + } + OldCpuMpData =3D GetCpuMpDataFromGuidedHob (); if (OldCpuMpData =3D=3D NULL) { MaxLogicalProcessorNumber =3D PcdGet32 (PcdCpuMaxLogicalProcessorNumbe= r); @@ -2073,6 +2079,10 @@ MpInitLibGetProcessorInfo ( CPU_INFO_IN_HOB *CpuInfoInHob; UINTN OriginalProcessorNumber; =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return TdxMpInitLibGetProcessorInfo (ProcessorNumber, ProcessorInfoBuf= fer, HealthData); + } + CpuMpData =3D GetCpuMpData (); CpuInfoInHob =3D (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob; =20 @@ -2167,6 +2177,10 @@ SwitchBSPWorker ( BOOLEAN OldInterruptState; BOOLEAN OldTimerInterruptState; =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return EFI_UNSUPPORTED; + } + // // Save and Disable Local APIC timer interrupt // @@ -2307,6 +2321,10 @@ EnableDisableApWorker ( CPU_MP_DATA *CpuMpData; UINTN CallerNumber; =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return EFI_UNSUPPORTED; + } + CpuMpData =3D GetCpuMpData (); =20 // @@ -2367,6 +2385,11 @@ MpInitLibWhoAmI ( return EFI_INVALID_PARAMETER; } =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + *ProcessorNumber =3D 0; + return EFI_SUCCESS; + } + CpuMpData =3D GetCpuMpData (); =20 return GetProcessorNumber (CpuMpData, ProcessorNumber); @@ -2405,12 +2428,16 @@ MpInitLibGetNumberOfProcessors ( UINTN EnabledProcessorNumber; UINTN Index; =20 - CpuMpData =3D GetCpuMpData (); - if ((NumberOfProcessors =3D=3D NULL) && (NumberOfEnabledProcessors =3D= =3D NULL)) { return EFI_INVALID_PARAMETER; } =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return TdxMpInitLibGetNumberOfProcessors (NumberOfProcessors, NumberOf= EnabledProcessors); + } + + CpuMpData =3D GetCpuMpData (); + // // Check whether caller processor is BSP // @@ -2490,13 +2517,16 @@ StartupAllCPUsWorker ( BOOLEAN HasEnabledAp; CPU_STATE ApState; =20 - CpuMpData =3D GetCpuMpData (); - if (FailedCpuList !=3D NULL) { *FailedCpuList =3D NULL; } =20 - if ((CpuMpData->CpuCount =3D=3D 1) && ExcludeBsp) { + Status =3D MpInitLibGetNumberOfProcessors (&ProcessorCount, NULL); + if (EFI_ERROR (Status)) { + return Status; + } + + if ((ProcessorCount =3D=3D 1) && ExcludeBsp) { return EFI_NOT_STARTED; } =20 @@ -2504,6 +2534,22 @@ StartupAllCPUsWorker ( return EFI_INVALID_PARAMETER; } =20 + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + // + // For Td guest ExcludeBsp must be FALSE. Otherwise it will return in = above checks. + // + ASSERT (!ExcludeBsp); + + // + // Start BSP. + // + Procedure (ProcedureArgument); + + return EFI_SUCCESS; + } + + CpuMpData =3D GetCpuMpData (); + // // Check whether caller processor is BSP // @@ -2643,6 +2689,13 @@ StartupThisAPWorker ( CPU_AP_DATA *CpuData; UINTN CallerNumber; =20 + // + // In Td guest, startup of AP is not supported in current stage. + // + if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) { + return EFI_UNSUPPORTED; + } + CpuMpData =3D GetCpuMpData (); =20 if (Finished !=3D NULL) { diff --git a/UefiCpuPkg/Library/MpInitLib/MpLibTdx.c b/UefiCpuPkg/Library/M= pInitLib/MpLibTdx.c new file mode 100644 index 000000000000..fdb58fba9323 --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/MpLibTdx.c @@ -0,0 +1,106 @@ +/** @file + CPU MP Initialize Library common functions for Td guest. + + Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "MpLib.h" +#include "MpIntelTdx.h" + +/** + Gets detailed MP-related information on the requested processor at the + instant this call is made. This service may only be called from the BSP. + + In current stage only the BSP is workable. So ProcessorNumber should be = 0. + + @param[in] ProcessorNumber The handle number of processor. + @param[out] ProcessorInfoBuffer A pointer to the buffer where informat= ion for + the requested processor is deposited. + @param[out] HealthData Return processor health data. + + @retval EFI_SUCCESS Processor information was returned. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL or Processor= Number is not 0. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist in the pl= atform. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + +**/ +EFI_STATUS +TdxMpInitLibGetProcessorInfo ( + IN UINTN ProcessorNumber, + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer, + OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL + ) +{ + UINTN OriginalProcessorNumber; + + // + // Lower 24 bits contains the actual processor number. + // + OriginalProcessorNumber =3D ProcessorNumber; + ProcessorNumber &=3D BIT24 - 1; + + if ((ProcessorInfoBuffer =3D=3D NULL) || (ProcessorNumber !=3D 0)) { + return EFI_INVALID_PARAMETER; + } + + ProcessorInfoBuffer->ProcessorId =3D 0; + ProcessorInfoBuffer->StatusFlag =3D PROCESSOR_AS_BSP_BIT | PROCESSOR_EN= ABLED_BIT; + ZeroMem (&ProcessorInfoBuffer->Location, sizeof (EFI_CPU_PHYSICAL_LOCATI= ON)); + + if ((OriginalProcessorNumber & CPU_V2_EXTENDED_TOPOLOGY) !=3D 0) { + ZeroMem (&ProcessorInfoBuffer->ExtendedInformation.Location2, sizeof (= EFI_CPU_PHYSICAL_LOCATION2)); + } + + if (HealthData !=3D NULL) { + HealthData->Uint32 =3D 0; + } + + return EFI_SUCCESS; +} + +/** + Retrieves the number of logical processor in the platform and the number= of + those logical processors that are enabled on this boot. This service may= only + be called from the BSP. + + @param[out] NumberOfProcessors Pointer to the total number of l= ogical + processors in the system, includ= ing the BSP + and disabled APs. + @param[out] NumberOfEnabledProcessors Pointer to the number of enabled= logical + processors that exist in system,= including + the BSP. + + @retval EFI_SUCCESS The number of logical processors and ena= bled + logical processors was retrieved. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfE= nabledProcessors + is NULL. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + +**/ +EFI_STATUS +TdxMpInitLibGetNumberOfProcessors ( + OUT UINTN *NumberOfProcessors, OPTIONAL + OUT UINTN *NumberOfEnabledProcessors OPTIONAL + ) +{ + ASSERT (NumberOfProcessors !=3D NULL || NumberOfEnabledProcessors !=3D N= ULL); + // + // In current stage only the BSP is workable. So NumberOfProcessors + // & NumberOfEnableddProcessors are both 1. + // + if (NumberOfProcessors !=3D NULL) { + *NumberOfProcessors =3D 1; + } + + if (NumberOfEnabledProcessors !=3D NULL) { + *NumberOfEnabledProcessors =3D 1; + } + + return EFI_SUCCESS; +} diff --git a/UefiCpuPkg/Library/MpInitLib/MpLibTdxNull.c b/UefiCpuPkg/Libra= ry/MpInitLib/MpLibTdxNull.c new file mode 100644 index 000000000000..b5aaf6df283f --- /dev/null +++ b/UefiCpuPkg/Library/MpInitLib/MpLibTdxNull.c @@ -0,0 +1,69 @@ +/** @file + CPU MP Initialize Library common functions (NULL instance) for Td guest. + + Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "MpLib.h" +#include "MpIntelTdx.h" + +/** + Gets detailed MP-related information on the requested processor at the + instant this call is made. This service may only be called from the BSP. + + @param[in] ProcessorNumber The handle number of processor. + @param[out] ProcessorInfoBuffer A pointer to the buffer where informat= ion for + the requested processor is deposited. + @param[out] HealthData Return processor health data. + + @retval EFI_SUCCESS Processor information was returned. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER ProcessorInfoBuffer is NULL. + @retval EFI_NOT_FOUND The processor with the handle specified = by + ProcessorNumber does not exist in the pl= atform. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + +**/ +EFI_STATUS +TdxMpInitLibGetProcessorInfo ( + IN UINTN ProcessorNumber, + OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer, + OUT EFI_HEALTH_FLAGS *HealthData OPTIONAL + ) +{ + ASSERT (FALSE); + return EFI_UNSUPPORTED; +} + +/** + Retrieves the number of logical processor in the platform and the number= of + those logical processors that are enabled on this boot. This service may= only + be called from the BSP. + + @param[out] NumberOfProcessors Pointer to the total number of l= ogical + processors in the system, includ= ing the BSP + and disabled APs. + @param[out] NumberOfEnabledProcessors Pointer to the number of enabled= logical + processors that exist in system,= including + the BSP. + + @retval EFI_SUCCESS The number of logical processors and ena= bled + logical processors was retrieved. + @retval EFI_DEVICE_ERROR The calling processor is an AP. + @retval EFI_INVALID_PARAMETER NumberOfProcessors is NULL and NumberOfE= nabledProcessors + is NULL. + @retval EFI_NOT_READY MP Initialize Library is not initialized. + +**/ +EFI_STATUS +TdxMpInitLibGetNumberOfProcessors ( + OUT UINTN *NumberOfProcessors, OPTIONAL + OUT UINTN *NumberOfEnabledProcessors OPTIONAL + ) +{ + ASSERT (FALSE); + return EFI_UNSUPPORTED; +} diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index 5facf4db9499..894be0f8daab 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -24,10 +24,12 @@ [Sources.IA32] Ia32/AmdSev.c Ia32/MpFuncs.nasm + MpLibTdxNull.c =20 [Sources.X64] X64/AmdSev.c X64/MpFuncs.nasm + MpLibTdx.c =20 [Sources.common] AmdSev.c @@ -36,6 +38,7 @@ MpLib.c MpLib.h Microcode.c + MpIntelTdx.h =20 [Packages] MdePkg/MdePkg.dec --=20 2.29.2.windows.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#88223): https://edk2.groups.io/g/devel/message/88223 Mute This Topic: https://groups.io/mt/90121206/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-