diff options
author | Jiaxin Wu <jiaxin.wu@intel.com> | 2024-07-08 12:48:32 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-08-28 15:25:27 +0000 |
commit | 2e6ca59e332f691195be869e87a8737c20bc25a8 (patch) | |
tree | bf996b9f8d5dc7a62469974d562fda39c2943b78 | |
parent | ae0d54cd4362b1a2788226a2fecf4cff6bfb453d (diff) | |
download | edk2-2e6ca59e332f691195be869e87a8737c20bc25a8.tar.gz edk2-2e6ca59e332f691195be869e87a8737c20bc25a8.tar.bz2 edk2-2e6ca59e332f691195be869e87a8737c20bc25a8.zip |
UefiCpuPkg/PiSmmCpuDxeSmm: Avoid PcdCpuSmmProfileEnable check in MM
For MM, gMmProfileDataHobGuid Memory Allocation HOB is defined to
indicate SMM profile feature enabled or not. If the HOB exist, SMM
profile base address and size will be returned in the HOB, so no need
to consume the PcdCpuSmmProfileEnable feature PCD to check enable or
disable.
To achieve above purpose, Add the IsSmmProfileEnabled () function.
With this change, Both MM and SMM can use the new function for
SMM profile feature check.
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Dun Tan <dun.tan@intel.com>
Cc: Hongbin1 Zhang <hongbin1.zhang@intel.com>
Cc: Wei6 Xu <wei6.xu@intel.com>
Cc: Yuanhao Xie <yuanhao.xie@intel.com>
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c | 4 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmiException.nasm | 1 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 4 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/NonMmramMapStandaloneMm.c | 6 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.c | 5 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuCommon.h | 12 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 21 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuStandaloneMm.c | 24 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 4 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c | 9 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.h | 4 | ||||
-rw-r--r-- | UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 6 |
12 files changed, 83 insertions, 17 deletions
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 @@ -1154,6 +1154,11 @@ PiSmmCpuEntryCommon ( InitializeSmmTimer ();
//
+ // Initialize mSmmProfileEnabled
+ //
+ mSmmProfileEnabled = IsSmmProfileEnabled ();
+
+ //
// Initialize MP globals
//
Cr3 = InitializeMpServiceData (Stacks, mSmmStackSize, mSmmShadowStackSize);
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 @@ -831,6 +831,18 @@ SmiPFHandler ( );
/**
+ 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 @@ -24,6 +24,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 @@ -21,6 +21,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 @@ -41,6 +41,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.
//
BOOLEAN mSmmProfileStart = FALSE;
@@ -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.
|