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>
This commit is contained in:
Jiaxin Wu 2024-07-08 12:48:32 +08:00 committed by mergify[bot]
parent ae0d54cd43
commit 2e6ca59e33
12 changed files with 83 additions and 17 deletions

View File

@ -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

View File

@ -12,7 +12,6 @@
;
;-------------------------------------------------------------------------------
extern ASM_PFX(FeaturePcdGet (PcdCpuSmmProfileEnable))
extern ASM_PFX(SmiPFHandler)
extern ASM_PFX(mSetupDebugTrap)

View File

@ -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 ();
}

View File

@ -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;

View File

@ -1153,6 +1153,11 @@ PiSmmCpuEntryCommon (
//
InitializeSmmTimer ();
//
// Initialize mSmmProfileEnabled
//
mSmmProfileEnabled = IsSmmProfileEnabled ();
//
// Initialize MP globals
//

View File

@ -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.

View File

@ -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
//

View File

@ -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
//

View File

@ -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;

View File

@ -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)
{

View File

@ -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;

View File

@ -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.