UefiCpuPkg/PiSmmCpuDxeSmm: Move SMM profile data allocation into func

MM can not use the gBS service, so move SMM profile data allocation
into function. This can make InitSmmProfileInternal() to a common
function for both SMM and MM.

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-06-24 23:34:45 +08:00 committed by mergify[bot]
parent 89fe9c5d79
commit 5547d1487c
3 changed files with 67 additions and 29 deletions

View File

@ -423,6 +423,43 @@ SetUefiMemMapAttributes (
PERF_FUNCTION_END ();
}
/**
Get SmmProfileData.
@param[in, out] Size Return Size of SmmProfileData.
@return Address of SmmProfileData
**/
EFI_PHYSICAL_ADDRESS
GetSmmProfileData (
IN OUT UINT64 *Size
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS Base;
ASSERT (Size != NULL);
if (mBtsSupported) {
*Size = PcdGet32 (PcdCpuSmmProfileSize) + mMsrDsAreaSize;
} else {
*Size = PcdGet32 (PcdCpuSmmProfileSize);
}
Base = 0xFFFFFFFF;
Status = gBS->AllocatePages (
AllocateMaxAddress,
EfiReservedMemoryType,
(UINTN)EFI_SIZE_TO_PAGES (*Size),
&Base
);
ASSERT_EFI_ERROR (Status);
ZeroMem ((VOID *)(UINTN)Base, (UINTN)*Size);
return Base;
}
/**
Return if the Address is forbidden as SMM communication buffer.

View File

@ -267,6 +267,9 @@ extern UINTN mSmmShadowStackSize;
///
extern UINT8 mSmmSaveStateRegisterLma;
extern BOOLEAN mBtsSupported;
extern UINTN mMsrDsAreaSize;
#define PAGE_TABLE_POOL_ALIGNMENT BASE_128KB
#define PAGE_TABLE_POOL_UNIT_SIZE BASE_128KB
#define PAGE_TABLE_POOL_UNIT_PAGES EFI_SIZE_TO_PAGES (PAGE_TABLE_POOL_UNIT_SIZE)
@ -910,6 +913,19 @@ SetUefiMemMapAttributes (
VOID
);
/**
Get SmmProfileData.
@param[in, out] Size Return Size of SmmProfileData.
@return Address of SmmProfileData
**/
EFI_PHYSICAL_ADDRESS
GetSmmProfileData (
IN OUT UINT64 *Size
);
/**
Return if the Address is forbidden as SMM communication buffer.

View File

@ -795,12 +795,11 @@ InitSmmProfileInternal (
VOID
)
{
EFI_STATUS Status;
EFI_PHYSICAL_ADDRESS Base;
VOID *Registration;
UINTN Index;
UINTN MsrDsAreaSizePerCpu;
UINTN TotalSize;
EFI_STATUS Status;
VOID *Registration;
UINTN Index;
UINTN MsrDsAreaSizePerCpu;
UINT64 SmmProfileSize;
mPFEntryCount = (UINTN *)AllocateZeroPool (sizeof (UINTN) * mMaxNumberOfCpus);
ASSERT (mPFEntryCount != NULL);
@ -813,29 +812,15 @@ InitSmmProfileInternal (
);
ASSERT (mLastPFEntryPointer != NULL);
//
// Allocate memory for SmmProfile below 4GB.
// The base address
//
mSmmProfileSize = PcdGet32 (PcdCpuSmmProfileSize);
mSmmProfileSize = FixedPcdGet32 (PcdCpuSmmProfileSize);
ASSERT ((mSmmProfileSize & 0xFFF) == 0);
if (mBtsSupported) {
TotalSize = mSmmProfileSize + mMsrDsAreaSize;
} else {
TotalSize = mSmmProfileSize;
}
Base = 0xFFFFFFFF;
Status = gBS->AllocatePages (
AllocateMaxAddress,
EfiReservedMemoryType,
EFI_SIZE_TO_PAGES (TotalSize),
&Base
);
ASSERT_EFI_ERROR (Status);
ZeroMem ((VOID *)(UINTN)Base, TotalSize);
mSmmProfileBase = (SMM_PROFILE_HEADER *)(UINTN)Base;
//
// Get Smm Profile Base
//
mSmmProfileBase = (SMM_PROFILE_HEADER *)(UINTN)GetSmmProfileData (&SmmProfileSize);
DEBUG ((DEBUG_ERROR, "SmmProfileBase = 0x%016x.\n", (UINTN)mSmmProfileBase));
DEBUG ((DEBUG_ERROR, "SmmProfileSize = 0x%016x.\n", (UINTN)SmmProfileSize));
//
// Initialize SMM profile data header.
@ -858,7 +843,7 @@ InitSmmProfileInternal (
mMsrPEBSRecord = (PEBS_RECORD **)AllocateZeroPool (sizeof (PEBS_RECORD *) * mMaxNumberOfCpus);
ASSERT (mMsrPEBSRecord != NULL);
mMsrDsAreaBase = (MSR_DS_AREA_STRUCT *)((UINTN)Base + mSmmProfileSize);
mMsrDsAreaBase = (MSR_DS_AREA_STRUCT *)((UINTN)mSmmProfileBase + mSmmProfileSize);
MsrDsAreaSizePerCpu = mMsrDsAreaSize / mMaxNumberOfCpus;
mBTSRecordNumber = (MsrDsAreaSizePerCpu - sizeof (PEBS_RECORD) * PEBS_RECORD_NUMBER - sizeof (MSR_DS_AREA_STRUCT)) / sizeof (BRANCH_TRACE_RECORD);
for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
@ -891,7 +876,7 @@ InitSmmProfileInternal (
// Update SMM profile entry.
//
mProtectionMemRange[1].Range.Base = (EFI_PHYSICAL_ADDRESS)(UINTN)mSmmProfileBase;
mProtectionMemRange[1].Range.Top = (EFI_PHYSICAL_ADDRESS)(UINTN)mSmmProfileBase + TotalSize;
mProtectionMemRange[1].Range.Top = (EFI_PHYSICAL_ADDRESS)(UINTN)mSmmProfileBase + SmmProfileSize;
//
// Allocate memory reserved for creating 4KB pages.