diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c index 2fc55ea3c2..1294485c60 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c @@ -33,7 +33,7 @@ SmmInitPageTable ( mPhysicalAddressBits = 32; mPagingMode = PagingPae; - if (FeaturePcdGet (PcdCpuSmmProfileEnable) || + if (mSmmProfileEnabled || HEAP_GUARD_NONSTOP_MODE || NULL_DETECTION_NONSTOP_MODE) { @@ -187,7 +187,7 @@ SmiPFHandler ( } } - if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { + if (mSmmProfileEnabled) { SmmProfilePFHandler ( SystemContext.SystemContextIa32->Eip, SystemContext.SystemContextIa32->ExceptionData diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiException.nasm b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiException.nasm index e7b85a9949..208d6bc2ee 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiException.nasm +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiException.nasm @@ -12,7 +12,6 @@ ; ;------------------------------------------------------------------------------- -extern ASM_PFX(FeaturePcdGet (PcdCpuSmmProfileEnable)) extern ASM_PFX(SmiPFHandler) extern ASM_PFX(mSetupDebugTrap) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 819b35a35d..210b23af21 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1616,7 +1616,7 @@ SmiRendezvous ( InitializeSpinLock (mSmmMpSyncData->CpuData[CpuIndex].Busy); } - if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { + if (mSmmProfileEnabled) { ActivateSmmProfile (CpuIndex); } @@ -1677,7 +1677,7 @@ SmiRendezvous ( } } - if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { + if (mSmmProfileEnabled) { SmmProfileRecordSmiNum (); } diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c index 70e94a6b76..dba7db0d00 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c @@ -11,6 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent Get SmmProfileData. @param[in, out] Size Return Size of SmmProfileData. + 0 means the gMmProfileDataHobGuid does not exist. @return Address of SmmProfileData @@ -39,7 +40,10 @@ GetSmmProfileData ( SmmProfileDataHob.Raw = GetNextHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, GET_NEXT_HOB (SmmProfileDataHob)); } - ASSERT (SmmProfileDataHob.Raw != NULL); + if (SmmProfileDataHob.Raw == NULL) { + *Size = 0; + return 0; + } *Size = SmmProfileDataHob.MemoryAllocation->AllocDescriptor.MemoryLength; diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.c index c5921a6de8..c6df9358eb 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.c @@ -1153,6 +1153,11 @@ PiSmmCpuEntryCommon ( // InitializeSmmTimer (); + // + // Initialize mSmmProfileEnabled + // + mSmmProfileEnabled = IsSmmProfileEnabled (); + // // Initialize MP globals // diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h index d7a645fb5b..0dccf7ca65 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h @@ -830,6 +830,18 @@ SmiPFHandler ( IN EFI_SYSTEM_CONTEXT SystemContext ); +/** + Check SmmProfile is enabled or not. + + @return TRUE SmmProfile is enabled. + FALSE SmmProfile is not enabled. + +**/ +BOOLEAN +IsSmmProfileEnabled ( + VOID + ); + /** Perform the remaining tasks. diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c index f544858c19..50aeefb948 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c @@ -23,6 +23,21 @@ const BOOLEAN mIsStandaloneMm = FALSE; // BOOLEAN mSmmReadyToLock = FALSE; +/** + Check SmmProfile is enabled or not. + + @return TRUE SmmProfile is enabled. + FALSE SmmProfile is not enabled. + +**/ +BOOLEAN +IsSmmProfileEnabled ( + VOID + ) +{ + return FeaturePcdGet (PcdCpuSmmProfileEnable); +} + /** Perform the remaining tasks. @@ -40,7 +55,7 @@ PerformRemainingTasks ( // // Start SMM Profile feature // - if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { + if (mSmmProfileEnabled) { SmmProfileStart (); } @@ -60,7 +75,7 @@ PerformRemainingTasks ( // // Update Page Table for outside SMRAM. // - if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { + if (mSmmProfileEnabled) { SmmProfileUpdateMemoryAttributes (); } else { UpdateUefiMemMapAttributes (); @@ -157,7 +172,7 @@ SmmReadyToLockEventNotify ( // // Skip SMM profile initialization if feature is disabled // - if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { + if (mSmmProfileEnabled) { // // Get Software SMI from FADT // diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuStandaloneMm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuStandaloneMm.c index d8aaff811c..f81389463f 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuStandaloneMm.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuStandaloneMm.c @@ -20,6 +20,28 @@ const BOOLEAN mIsStandaloneMm = TRUE; // BOOLEAN mRemainingTasksDone = FALSE; +/** + Check SmmProfile is enabled or not. + + @return TRUE SmmProfile is enabled. + FALSE SmmProfile is not enabled. + +**/ +BOOLEAN +IsSmmProfileEnabled ( + VOID + ) +{ + UINT64 SmmProfileSize; + + GetSmmProfileData (&SmmProfileSize); + if (SmmProfileSize == 0) { + return FALSE; + } + + return TRUE; +} + /** Perform the remaining tasks. @@ -216,7 +238,7 @@ PiCpuStandaloneMmEntry ( ASSERT_EFI_ERROR (Status); - if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { + if (mSmmProfileEnabled) { // // Get Software SMI // diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c index 4022c45065..d1cfd72106 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c @@ -1494,7 +1494,7 @@ IfReadOnlyPageTableNeeded ( // if (!IsRestrictedMemoryAccess () || ((PcdGet8 (PcdHeapGuardPropertyMask) & (BIT3 | BIT2)) != 0) || - FeaturePcdGet (PcdCpuSmmProfileEnable)) + mSmmProfileEnabled) { if (sizeof (UINTN) == sizeof (UINT64)) { // @@ -1508,7 +1508,7 @@ IfReadOnlyPageTableNeeded ( // // Restriction on access to non-SMRAM memory and SMM profile could not be enabled at the same time. // - ASSERT (!(IsRestrictedMemoryAccess () && FeaturePcdGet (PcdCpuSmmProfileEnable))); + ASSERT (!(IsRestrictedMemoryAccess () && mSmmProfileEnabled)); } return FALSE; diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c index 44f67cc38b..164af20a4c 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c @@ -40,6 +40,11 @@ BOOLEAN mXdEnabled = FALSE; // BOOLEAN mBtsSupported = TRUE; +// +// The flag indicates if SMM profile is enabled. +// +BOOLEAN mSmmProfileEnabled = FALSE; + // // The flag indicates if SMM profile starts to record data. // @@ -342,7 +347,7 @@ IsAddressSplit ( { UINTN Index; - if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { + if (mSmmProfileEnabled) { // // Check configuration // @@ -1018,7 +1023,7 @@ InitSmmProfile ( // // Skip SMM profile initialization if feature is disabled // - if (!FeaturePcdGet (PcdCpuSmmProfileEnable) && + if (!mSmmProfileEnabled && !HEAP_GUARD_NONSTOP_MODE && !NULL_DETECTION_NONSTOP_MODE) { diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.h b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.h index feddf6eec3..2726840c0e 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.h @@ -137,6 +137,10 @@ extern BOOLEAN mXdSupported; // extern BOOLEAN mXdEnabled; // +// The flag indicates if SMM profile is enabled. +// +extern BOOLEAN mSmmProfileEnabled; +// // The flag indicates if #DB will be setup in #PF handler. // extern BOOLEAN mSetupDebugTrap; diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c index f56d2849de..15d53b1411 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c @@ -228,7 +228,7 @@ SmmInitPageTable ( // PageTable = GenSmmPageTable (mPagingMode, mPhysicalAddressBits); - if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { + if (mSmmProfileEnabled) { if (m5LevelPagingNeeded) { Pml5Entry = (UINT64 *)PageTable; // @@ -264,7 +264,7 @@ SmmInitPageTable ( } } - if (FeaturePcdGet (PcdCpuSmmProfileEnable) || + if (mSmmProfileEnabled || HEAP_GUARD_NONSTOP_MODE || NULL_DETECTION_NONSTOP_MODE) { @@ -820,7 +820,7 @@ SmiPFHandler ( } } - if (FeaturePcdGet (PcdCpuSmmProfileEnable)) { + if (mSmmProfileEnabled) { if (mIsStandaloneMm) { // // Only logging ranges shall run here in MM env.