]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg: Enable Tdx support in MpInitLib
authorMin Xu <min.m.xu@intel.com>
Mon, 19 Jul 2021 01:35:39 +0000 (09:35 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sat, 2 Apr 2022 08:15:12 +0000 (08:15 +0000)
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429

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 <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
UefiCpuPkg/Library/MpInitLib/MpIntelTdx.h [new file with mode: 0644]
UefiCpuPkg/Library/MpInitLib/MpLib.c
UefiCpuPkg/Library/MpInitLib/MpLibTdx.c [new file with mode: 0644]
UefiCpuPkg/Library/MpInitLib/MpLibTdxNull.c [new file with mode: 0644]
UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf

index e1cd0b35000831560d736a10b8f017597bbcae48..159b4d16ed0e9f3270b2a67065f88adaca529154 100644 (file)
 [Sources.IA32]\r
   Ia32/AmdSev.c\r
   Ia32/MpFuncs.nasm\r
+  MpLibTdxNull.c\r
 \r
 [Sources.X64]\r
   X64/AmdSev.c\r
   X64/MpFuncs.nasm\r
+  MpLibTdx.c\r
 \r
 [Sources.common]\r
   AmdSev.c\r
@@ -36,6 +38,7 @@
   MpLib.c\r
   MpLib.h\r
   Microcode.c\r
+  MpIntelTdx.h\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
diff --git a/UefiCpuPkg/Library/MpInitLib/MpIntelTdx.h b/UefiCpuPkg/Library/MpInitLib/MpIntelTdx.h
new file mode 100644 (file)
index 0000000..8a26f6c
--- /dev/null
@@ -0,0 +1,69 @@
+/** @file\r
+  CPU MP Initialize Library header file for Td guest.\r
+\r
+  Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.<BR>\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#ifndef MP_INTEL_TDX_H_\r
+#define MP_INTEL_TDX_H_\r
+\r
+#include <PiPei.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Uefi/UefiBaseType.h>\r
+#include <Protocol/MpService.h>\r
+\r
+/**\r
+  Gets detailed MP-related information on the requested processor at the\r
+  instant this call is made. This service may only be called from the BSP.\r
+\r
+  @param[in]  ProcessorNumber       The handle number of processor.\r
+  @param[out] ProcessorInfoBuffer   A pointer to the buffer where information for\r
+                                    the requested processor is deposited.\r
+  @param[out]  HealthData            Return processor health data.\r
+\r
+  @retval EFI_SUCCESS             Processor information was returned.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_INVALID_PARAMETER   ProcessorInfoBuffer is NULL.\r
+  @retval EFI_NOT_FOUND           The processor with the handle specified by\r
+                                  ProcessorNumber does not exist in the platform.\r
+  @retval EFI_NOT_READY           MP Initialize Library is not initialized.\r
+\r
+**/\r
+EFI_STATUS\r
+TdxMpInitLibGetProcessorInfo (\r
+  IN  UINTN                      ProcessorNumber,\r
+  OUT EFI_PROCESSOR_INFORMATION  *ProcessorInfoBuffer,\r
+  OUT EFI_HEALTH_FLAGS           *HealthData  OPTIONAL\r
+  );\r
+\r
+/**\r
+  Retrieves the number of logical processor in the platform and the number of\r
+  those logical processors that are enabled on this boot. This service may only\r
+  be called from the BSP.\r
+\r
+  @param[out] NumberOfProcessors          Pointer to the total number of logical\r
+                                          processors in the system, including the BSP\r
+                                          and disabled APs.\r
+  @param[out] NumberOfEnabledProcessors   Pointer to the number of enabled logical\r
+                                          processors that exist in system, including\r
+                                          the BSP.\r
+\r
+  @retval EFI_SUCCESS             The number of logical processors and enabled\r
+                                  logical processors was retrieved.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_INVALID_PARAMETER   NumberOfProcessors is NULL and NumberOfEnabledProcessors\r
+                                  is NULL.\r
+  @retval EFI_NOT_READY           MP Initialize Library is not initialized.\r
+\r
+**/\r
+EFI_STATUS\r
+TdxMpInitLibGetNumberOfProcessors (\r
+  OUT UINTN *NumberOfProcessors, OPTIONAL\r
+  OUT UINTN *NumberOfEnabledProcessors  OPTIONAL\r
+  );\r
+\r
+#endif\r
index 4a73787ee43a649548e05964f6b04f24b059c83f..91c7afaeb2ada642d1ce24be22608f1e266a3026 100644 (file)
@@ -9,9 +9,11 @@
 **/\r
 \r
 #include "MpLib.h"\r
+#include "MpIntelTdx.h"\r
 #include <Library/VmgExitLib.h>\r
 #include <Register/Amd/Fam17Msr.h>\r
 #include <Register/Amd/Ghcb.h>\r
+#include <ConfidentialComputingGuestAttr.h>\r
 \r
 EFI_GUID  mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID;\r
 \r
@@ -1803,6 +1805,10 @@ MpInitLibInitialize (
   UINTN                    BackupBufferAddr;\r
   UINTN                    ApIdtBase;\r
 \r
+  if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
   OldCpuMpData = GetCpuMpDataFromGuidedHob ();\r
   if (OldCpuMpData == NULL) {\r
     MaxLogicalProcessorNumber = PcdGet32 (PcdCpuMaxLogicalProcessorNumber);\r
@@ -2073,6 +2079,10 @@ MpInitLibGetProcessorInfo (
   CPU_INFO_IN_HOB  *CpuInfoInHob;\r
   UINTN            OriginalProcessorNumber;\r
 \r
+  if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) {\r
+    return TdxMpInitLibGetProcessorInfo (ProcessorNumber, ProcessorInfoBuffer, HealthData);\r
+  }\r
+\r
   CpuMpData    = GetCpuMpData ();\r
   CpuInfoInHob = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob;\r
 \r
@@ -2167,6 +2177,10 @@ SwitchBSPWorker (
   BOOLEAN                      OldInterruptState;\r
   BOOLEAN                      OldTimerInterruptState;\r
 \r
+  if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   //\r
   // Save and Disable Local APIC timer interrupt\r
   //\r
@@ -2307,6 +2321,10 @@ EnableDisableApWorker (
   CPU_MP_DATA  *CpuMpData;\r
   UINTN        CallerNumber;\r
 \r
+  if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   CpuMpData = GetCpuMpData ();\r
 \r
   //\r
@@ -2367,6 +2385,11 @@ MpInitLibWhoAmI (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) {\r
+    *ProcessorNumber = 0;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
   CpuMpData = GetCpuMpData ();\r
 \r
   return GetProcessorNumber (CpuMpData, ProcessorNumber);\r
@@ -2405,12 +2428,16 @@ MpInitLibGetNumberOfProcessors (
   UINTN        EnabledProcessorNumber;\r
   UINTN        Index;\r
 \r
-  CpuMpData = GetCpuMpData ();\r
-\r
   if ((NumberOfProcessors == NULL) && (NumberOfEnabledProcessors == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) {\r
+    return TdxMpInitLibGetNumberOfProcessors (NumberOfProcessors, NumberOfEnabledProcessors);\r
+  }\r
+\r
+  CpuMpData = GetCpuMpData ();\r
+\r
   //\r
   // Check whether caller processor is BSP\r
   //\r
@@ -2490,13 +2517,16 @@ StartupAllCPUsWorker (
   BOOLEAN      HasEnabledAp;\r
   CPU_STATE    ApState;\r
 \r
-  CpuMpData = GetCpuMpData ();\r
-\r
   if (FailedCpuList != NULL) {\r
     *FailedCpuList = NULL;\r
   }\r
 \r
-  if ((CpuMpData->CpuCount == 1) && ExcludeBsp) {\r
+  Status = MpInitLibGetNumberOfProcessors (&ProcessorCount, NULL);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if ((ProcessorCount == 1) && ExcludeBsp) {\r
     return EFI_NOT_STARTED;\r
   }\r
 \r
@@ -2504,6 +2534,22 @@ StartupAllCPUsWorker (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) {\r
+    //\r
+    // For Td guest ExcludeBsp must be FALSE. Otherwise it will return in above checks.\r
+    //\r
+    ASSERT (!ExcludeBsp);\r
+\r
+    //\r
+    // Start BSP.\r
+    //\r
+    Procedure (ProcedureArgument);\r
+\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  CpuMpData = GetCpuMpData ();\r
+\r
   //\r
   // Check whether caller processor is BSP\r
   //\r
@@ -2643,6 +2689,13 @@ StartupThisAPWorker (
   CPU_AP_DATA  *CpuData;\r
   UINTN        CallerNumber;\r
 \r
+  //\r
+  // In Td guest, startup of AP is not supported in current stage.\r
+  //\r
+  if (CC_GUEST_IS_TDX (PcdGet64 (PcdConfidentialComputingGuestAttr))) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   CpuMpData = GetCpuMpData ();\r
 \r
   if (Finished != NULL) {\r
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLibTdx.c b/UefiCpuPkg/Library/MpInitLib/MpLibTdx.c
new file mode 100644 (file)
index 0000000..fdb58fb
--- /dev/null
@@ -0,0 +1,106 @@
+/** @file\r
+  CPU MP Initialize Library common functions for Td guest.\r
+\r
+  Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.<BR>\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include "MpLib.h"\r
+#include "MpIntelTdx.h"\r
+\r
+/**\r
+  Gets detailed MP-related information on the requested processor at the\r
+  instant this call is made. This service may only be called from the BSP.\r
+\r
+  In current stage only the BSP is workable. So ProcessorNumber should be 0.\r
+\r
+  @param[in]  ProcessorNumber       The handle number of processor.\r
+  @param[out] ProcessorInfoBuffer   A pointer to the buffer where information for\r
+                                    the requested processor is deposited.\r
+  @param[out]  HealthData            Return processor health data.\r
+\r
+  @retval EFI_SUCCESS             Processor information was returned.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_INVALID_PARAMETER   ProcessorInfoBuffer is NULL or ProcessorNumber is not 0.\r
+  @retval EFI_NOT_FOUND           The processor with the handle specified by\r
+                                  ProcessorNumber does not exist in the platform.\r
+  @retval EFI_NOT_READY           MP Initialize Library is not initialized.\r
+\r
+**/\r
+EFI_STATUS\r
+TdxMpInitLibGetProcessorInfo (\r
+  IN  UINTN                      ProcessorNumber,\r
+  OUT EFI_PROCESSOR_INFORMATION  *ProcessorInfoBuffer,\r
+  OUT EFI_HEALTH_FLAGS           *HealthData  OPTIONAL\r
+  )\r
+{\r
+  UINTN  OriginalProcessorNumber;\r
+\r
+  //\r
+  // Lower 24 bits contains the actual processor number.\r
+  //\r
+  OriginalProcessorNumber = ProcessorNumber;\r
+  ProcessorNumber        &= BIT24 - 1;\r
+\r
+  if ((ProcessorInfoBuffer == NULL) || (ProcessorNumber != 0)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  ProcessorInfoBuffer->ProcessorId = 0;\r
+  ProcessorInfoBuffer->StatusFlag  = PROCESSOR_AS_BSP_BIT | PROCESSOR_ENABLED_BIT;\r
+  ZeroMem (&ProcessorInfoBuffer->Location, sizeof (EFI_CPU_PHYSICAL_LOCATION));\r
+\r
+  if ((OriginalProcessorNumber & CPU_V2_EXTENDED_TOPOLOGY) != 0) {\r
+    ZeroMem (&ProcessorInfoBuffer->ExtendedInformation.Location2, sizeof (EFI_CPU_PHYSICAL_LOCATION2));\r
+  }\r
+\r
+  if (HealthData != NULL) {\r
+    HealthData->Uint32 = 0;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieves the number of logical processor in the platform and the number of\r
+  those logical processors that are enabled on this boot. This service may only\r
+  be called from the BSP.\r
+\r
+  @param[out] NumberOfProcessors          Pointer to the total number of logical\r
+                                          processors in the system, including the BSP\r
+                                          and disabled APs.\r
+  @param[out] NumberOfEnabledProcessors   Pointer to the number of enabled logical\r
+                                          processors that exist in system, including\r
+                                          the BSP.\r
+\r
+  @retval EFI_SUCCESS             The number of logical processors and enabled\r
+                                  logical processors was retrieved.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_INVALID_PARAMETER   NumberOfProcessors is NULL and NumberOfEnabledProcessors\r
+                                  is NULL.\r
+  @retval EFI_NOT_READY           MP Initialize Library is not initialized.\r
+\r
+**/\r
+EFI_STATUS\r
+TdxMpInitLibGetNumberOfProcessors (\r
+  OUT UINTN *NumberOfProcessors, OPTIONAL\r
+  OUT UINTN *NumberOfEnabledProcessors OPTIONAL\r
+  )\r
+{\r
+  ASSERT (NumberOfProcessors != NULL || NumberOfEnabledProcessors != NULL);\r
+  //\r
+  // In current stage only the BSP is workable. So NumberOfProcessors\r
+  // & NumberOfEnableddProcessors are both 1.\r
+  //\r
+  if (NumberOfProcessors != NULL) {\r
+    *NumberOfProcessors = 1;\r
+  }\r
+\r
+  if (NumberOfEnabledProcessors != NULL) {\r
+    *NumberOfEnabledProcessors = 1;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLibTdxNull.c b/UefiCpuPkg/Library/MpInitLib/MpLibTdxNull.c
new file mode 100644 (file)
index 0000000..b5aaf6d
--- /dev/null
@@ -0,0 +1,69 @@
+/** @file\r
+  CPU MP Initialize Library common functions (NULL instance) for Td guest.\r
+\r
+  Copyright (c) 2020 - 2022, Intel Corporation. All rights reserved.<BR>\r
+\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
+**/\r
+\r
+#include "MpLib.h"\r
+#include "MpIntelTdx.h"\r
+\r
+/**\r
+  Gets detailed MP-related information on the requested processor at the\r
+  instant this call is made. This service may only be called from the BSP.\r
+\r
+  @param[in]  ProcessorNumber       The handle number of processor.\r
+  @param[out] ProcessorInfoBuffer   A pointer to the buffer where information for\r
+                                    the requested processor is deposited.\r
+  @param[out]  HealthData            Return processor health data.\r
+\r
+  @retval EFI_SUCCESS             Processor information was returned.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_INVALID_PARAMETER   ProcessorInfoBuffer is NULL.\r
+  @retval EFI_NOT_FOUND           The processor with the handle specified by\r
+                                  ProcessorNumber does not exist in the platform.\r
+  @retval EFI_NOT_READY           MP Initialize Library is not initialized.\r
+\r
+**/\r
+EFI_STATUS\r
+TdxMpInitLibGetProcessorInfo (\r
+  IN  UINTN                      ProcessorNumber,\r
+  OUT EFI_PROCESSOR_INFORMATION  *ProcessorInfoBuffer,\r
+  OUT EFI_HEALTH_FLAGS           *HealthData  OPTIONAL\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+/**\r
+  Retrieves the number of logical processor in the platform and the number of\r
+  those logical processors that are enabled on this boot. This service may only\r
+  be called from the BSP.\r
+\r
+  @param[out] NumberOfProcessors          Pointer to the total number of logical\r
+                                          processors in the system, including the BSP\r
+                                          and disabled APs.\r
+  @param[out] NumberOfEnabledProcessors   Pointer to the number of enabled logical\r
+                                          processors that exist in system, including\r
+                                          the BSP.\r
+\r
+  @retval EFI_SUCCESS             The number of logical processors and enabled\r
+                                  logical processors was retrieved.\r
+  @retval EFI_DEVICE_ERROR        The calling processor is an AP.\r
+  @retval EFI_INVALID_PARAMETER   NumberOfProcessors is NULL and NumberOfEnabledProcessors\r
+                                  is NULL.\r
+  @retval EFI_NOT_READY           MP Initialize Library is not initialized.\r
+\r
+**/\r
+EFI_STATUS\r
+TdxMpInitLibGetNumberOfProcessors (\r
+  OUT UINTN *NumberOfProcessors, OPTIONAL\r
+  OUT UINTN                     *NumberOfEnabledProcessors OPTIONAL\r
+  )\r
+{\r
+  ASSERT (FALSE);\r
+  return EFI_UNSUPPORTED;\r
+}\r
index 5facf4db94997beb879e3ff5cfbae37b35b3c425..894be0f8daabfac886be6a8d1330f7c993984476 100644 (file)
 [Sources.IA32]\r
   Ia32/AmdSev.c\r
   Ia32/MpFuncs.nasm\r
+  MpLibTdxNull.c\r
 \r
 [Sources.X64]\r
   X64/AmdSev.c\r
   X64/MpFuncs.nasm\r
+  MpLibTdx.c\r
 \r
 [Sources.common]\r
   AmdSev.c\r
@@ -36,6 +38,7 @@
   MpLib.c\r
   MpLib.h\r
   Microcode.c\r
+  MpIntelTdx.h\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r