From 28743ca0eeff27fa26d592ec98ff9df57e7d135b Mon Sep 17 00:00:00 2001 From: Mikhail Krichanov Date: Tue, 23 May 2023 16:17:14 +0300 Subject: [PATCH] UefiCpuPkg, OvmfPkg: Eliminated dependencies of PeiMpInitLib, DxeMpInitLib from DynamicPcds: PcdCpuMaxLogicalProcessorNumber, PcdCpuBootLogicalProcessorNumber, PcdGhcbBase, PcdConfidentialComputingGuestAttr. This information is now obtained from EFI_HOB_PLATFORM_INFO directly. --- OvmfPkg/Include/Library/PlatformInitLib.h | 2 ++ OvmfPkg/PlatformPei/AmdSev.c | 6 ++++ OvmfPkg/PlatformPei/IntelTdx.c | 4 ++- OvmfPkg/PlatformPei/Platform.c | 2 +- OvmfPkg/PlatformPei/Platform.h | 2 +- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 6 ++-- UefiCpuPkg/Library/MpInitLib/MpLib.c | 28 +++++++++++++------ UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 8 ++---- 8 files changed, 37 insertions(+), 21 deletions(-) diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Library/PlatformInitLib.h index 57b18b94d9..900f78a455 100644 --- a/OvmfPkg/Include/Library/PlatformInitLib.h +++ b/OvmfPkg/Include/Library/PlatformInitLib.h @@ -55,6 +55,8 @@ typedef struct { BOOLEAN QemuFwCfgChecked; BOOLEAN QemuFwCfgSupported; BOOLEAN QemuFwCfgDmaSupported; + + UINT64 GhcbBase; } EFI_HOB_PLATFORM_INFO; #pragma pack() diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index e6b602d79a..4b943cf900 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -258,6 +258,9 @@ AmdSevEsInitialize ( Status = PcdSet64S (PcdGhcbBase, GhcbBasePa); ASSERT_RETURN_ERROR (Status); + + PlatformInfoHob->GhcbBase = GhcbBasePa; + Status = PcdSet64S (PcdGhcbSize, EFI_PAGES_TO_SIZE (GhcbPageCount)); ASSERT_RETURN_ERROR (Status); @@ -428,10 +431,13 @@ AmdSevInitialize ( // if (MemEncryptSevSnpIsEnabled ()) { PcdStatus = PcdSet64S (PcdConfidentialComputingGuestAttr, CCAttrAmdSevSnp); + PlatformInfoHob->PcdConfidentialComputingGuestAttr = CCAttrAmdSevSnp; } else if (MemEncryptSevEsIsEnabled ()) { PcdStatus = PcdSet64S (PcdConfidentialComputingGuestAttr, CCAttrAmdSevEs); + PlatformInfoHob->PcdConfidentialComputingGuestAttr = CCAttrAmdSevEs; } else { PcdStatus = PcdSet64S (PcdConfidentialComputingGuestAttr, CCAttrAmdSev); + PlatformInfoHob->PcdConfidentialComputingGuestAttr = CCAttrAmdSev; } ASSERT_RETURN_ERROR (PcdStatus); diff --git a/OvmfPkg/PlatformPei/IntelTdx.c b/OvmfPkg/PlatformPei/IntelTdx.c index 3d625cabd8..5f575b1241 100644 --- a/OvmfPkg/PlatformPei/IntelTdx.c +++ b/OvmfPkg/PlatformPei/IntelTdx.c @@ -30,7 +30,7 @@ **/ VOID IntelTdxInitialize ( - VOID + IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob ) { #ifdef MDE_CPU_X64 @@ -45,6 +45,8 @@ IntelTdxInitialize ( PcdStatus = PcdSet64S (PcdConfidentialComputingGuestAttr, CCAttrIntelTdx); ASSERT_RETURN_ERROR (PcdStatus); + PlatformInfoHob->PcdConfidentialComputingGuestAttr = CCAttrIntelTdx; + PcdStatus = PcdSet64S (PcdTdxSharedBitMask, TdSharedPageMask ()); ASSERT_RETURN_ERROR (PcdStatus); diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index 148240342b..995821d034 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -395,7 +395,7 @@ InitializePlatform ( MiscInitialization (PlatformInfoHob); } - IntelTdxInitialize (); + IntelTdxInitialize (PlatformInfoHob); InstallFeatureControlCallback (PlatformInfoHob); return EFI_SUCCESS; diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h index 1cf44844a7..f8fa5a6b13 100644 --- a/OvmfPkg/PlatformPei/Platform.h +++ b/OvmfPkg/PlatformPei/Platform.h @@ -90,7 +90,7 @@ AmdSevInitialize ( **/ VOID IntelTdxInitialize ( - VOID + IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob ); /** diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf index 6e038a9fc9..1a58a06823 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -40,6 +40,7 @@ [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec UefiCpuPkg/UefiCpuPkg.dec [LibraryClasses] @@ -64,10 +65,9 @@ gEfiEventExitBootServicesGuid ## CONSUMES ## Event gEfiEventLegacyBootGuid ## SOMETIMES_CONSUMES ## Event gEdkiiMicrocodePatchHobGuid ## SOMETIMES_CONSUMES ## HOB + gUefiOvmfPkgPlatformInfoGuid ## CONSUMES ## HOB [Pcd] - gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## CONSUMES - gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber ## CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds ## SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize ## CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress ## CONSUMES @@ -78,5 +78,3 @@ gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures ## CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr ## CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c index e5dc852ed9..5d5eef0a23 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -9,11 +9,15 @@ **/ #include "MpLib.h" + #include +#include + #include #include -EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID; +EFI_GUID mCpuInitMpLibHobGuid = CPU_INIT_MP_LIB_HOB_GUID; +EFI_HOB_PLATFORM_INFO *mPlatformInfoHob = NULL; /** Save the volatile registers required to be restored following INIT IPI. @@ -521,7 +525,7 @@ CollectProcessorCount ( // FinishedCount is the number of check-in APs. // CpuMpData->CpuCount = CpuMpData->FinishedCount + 1; - ASSERT (CpuMpData->CpuCount <= PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + ASSERT (CpuMpData->CpuCount <= mPlatformInfoHob->PcdCpuMaxLogicalProcessorNumber); // // Enable x2APIC mode if @@ -1093,7 +1097,7 @@ AllocateResetVectorBelow1Mb ( // of processors for calculating the total stack area. // ApResetStackSize = (AP_RESET_STACK_SIZE * - PcdGet32 (PcdCpuMaxLogicalProcessorNumber)); + mPlatformInfoHob->PcdCpuMaxLogicalProcessorNumber); // // Invoke GetWakeupBuffer a second time to allocate the stack area @@ -1238,7 +1242,7 @@ WakeUpAP ( } if (CpuMpData->InitFlag == ApInitConfig) { - if (PcdGet32 (PcdCpuBootLogicalProcessorNumber) > 0) { + if (mPlatformInfoHob->PcdCpuBootLogicalProcessorNumber > 0) { // // The AP enumeration algorithm below is suitable only when the // platform can tell us the *exact* boot CPU count in advance. @@ -1254,7 +1258,7 @@ WakeUpAP ( // TimedWaitForApFinish ( CpuMpData, - PcdGet32 (PcdCpuBootLogicalProcessorNumber) - 1, + mPlatformInfoHob->PcdCpuBootLogicalProcessorNumber - 1, MAX_UINT32 // approx. 71 minutes ); } else { @@ -1292,7 +1296,7 @@ WakeUpAP ( // TimedWaitForApFinish ( CpuMpData, - PcdGet32 (PcdCpuMaxLogicalProcessorNumber) - 1, + mPlatformInfoHob->PcdCpuMaxLogicalProcessorNumber - 1, PcdGet32 (PcdCpuApInitTimeOutInMicroSeconds) ); @@ -1821,10 +1825,16 @@ MpInitLibInitialize ( UINTN ApResetVectorSizeAbove1Mb; UINTN BackupBufferAddr; UINTN ApIdtBase; + EFI_HOB_GUID_TYPE *GuidHob; + + GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid); + if (GuidHob != NULL) { + mPlatformInfoHob = (EFI_HOB_PLATFORM_INFO *)(GET_GUID_HOB_DATA (GuidHob)); + } OldCpuMpData = GetCpuMpDataFromGuidedHob (); if (OldCpuMpData == NULL) { - MaxLogicalProcessorNumber = PcdGet32 (PcdCpuMaxLogicalProcessorNumber); + MaxLogicalProcessorNumber = mPlatformInfoHob->PcdCpuMaxLogicalProcessorNumber; } else { MaxLogicalProcessorNumber = OldCpuMpData->CpuCount; } @@ -1901,7 +1911,7 @@ MpInitLibInitialize ( CpuMpData->SevEsIsEnabled = ConfidentialComputingGuestHas (CCAttrAmdSevEs); CpuMpData->SevSnpIsEnabled = ConfidentialComputingGuestHas (CCAttrAmdSevSnp); CpuMpData->SevEsAPBuffer = (UINTN)-1; - CpuMpData->GhcbBase = PcdGet64 (PcdGhcbBase); + CpuMpData->GhcbBase = mPlatformInfoHob->GhcbBase; CpuMpData->UseSevEsAPMethod = CpuMpData->SevEsIsEnabled && !CpuMpData->SevSnpIsEnabled; if (CpuMpData->SevSnpIsEnabled) { @@ -2887,7 +2897,7 @@ ConfidentialComputingGuestHas ( // // Get the current CC attribute. // - CurrentAttr = PcdGet64 (PcdConfidentialComputingGuestAttr); + CurrentAttr = mPlatformInfoHob->PcdConfidentialComputingGuestAttr; // // If attr is for the AMD group then call AMD specific checks. diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf index afd551bb0f..5984c74c47 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -39,8 +39,9 @@ [Packages] MdePkg/MdePkg.dec - UefiCpuPkg/UefiCpuPkg.dec MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec + UefiCpuPkg/UefiCpuPkg.dec [LibraryClasses] BaseLib @@ -57,8 +58,6 @@ MicrocodeLib [Pcd] - gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## CONSUMES - gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber ## CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApInitTimeOutInMicroSeconds ## SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize ## CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchAddress ## CONSUMES @@ -67,8 +66,6 @@ gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase ## SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdGhcbHypervisorFeatures ## CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## CONSUMES - gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr ## CONSUMES [Ppis] gEdkiiPeiShadowMicrocodePpiGuid ## SOMETIMES_CONSUMES @@ -76,3 +73,4 @@ [Guids] gEdkiiS3SmmInitDoneGuid gEdkiiMicrocodePatchHobGuid + gUefiOvmfPkgPlatformInfoGuid ## CONSUMES ## HOB