UefiCpuPkg: rename and simplify IsAddressValid function

In this commit, we rename IsAddressValid function to
IsSmmProfilePFAddressAbove4GValid and remove unneeded
code logic in it.

Currently, IsAddressValid is only used in the function
RestorePageTableAbove4G. It's used to identify if a SMM
profile PF address above 4G is inside mProtectionMemRange
or not. So we can remove the PcdCpuSmmProfileEnable FALSE
condition related code logic in it. Also the function name
is change to be more detailed and specific.

Signed-off-by: Dun Tan <dun.tan@intel.com>
This commit is contained in:
Dun Tan 2024-08-02 11:45:49 +08:00 committed by mergify[bot]
parent cff0641360
commit 5d43165ff8
3 changed files with 31 additions and 34 deletions

View File

@ -298,41 +298,35 @@ IsInSmmRanges (
}
/**
Check if the memory address will be mapped by 4KB-page.
Check if the SMM profile page fault address above 4GB is in protected range or not.
@param Address The address of Memory.
@param Nx The flag indicates if the memory is execute-disable.
@param[in] Address The address of Memory.
@param[out] Nx The flag indicates if the memory is execute-disable.
@retval TRUE The input address is in protected range.
@retval FALSE The input address is not in protected range.
**/
BOOLEAN
IsAddressValid (
IN EFI_PHYSICAL_ADDRESS Address,
IN BOOLEAN *Nx
IsSmmProfilePFAddressAbove4GValid (
IN EFI_PHYSICAL_ADDRESS Address,
OUT BOOLEAN *Nx
)
{
UINTN Index;
if (FeaturePcdGet (PcdCpuSmmProfileEnable)) {
//
// Check configuration
//
for (Index = 0; Index < mProtectionMemRangeCount; Index++) {
if ((Address >= mProtectionMemRange[Index].Range.Base) && (Address < mProtectionMemRange[Index].Range.Top)) {
*Nx = mProtectionMemRange[Index].Nx;
return mProtectionMemRange[Index].Present;
}
//
// Check configuration
//
for (Index = 0; Index < mProtectionMemRangeCount; Index++) {
if ((Address >= mProtectionMemRange[Index].Range.Base) && (Address < mProtectionMemRange[Index].Range.Top)) {
*Nx = mProtectionMemRange[Index].Nx;
return mProtectionMemRange[Index].Present;
}
*Nx = TRUE;
return FALSE;
} else {
*Nx = TRUE;
if (IsInSmmRanges (Address)) {
*Nx = FALSE;
}
return TRUE;
}
*Nx = TRUE;
return FALSE;
}
/**

View File

@ -129,16 +129,19 @@ IsAddressSplit (
);
/**
Check if the memory address will be mapped by 4KB-page.
Check if the SMM profile page fault address above 4GB is in protected range or not.
@param Address The address of Memory.
@param Nx The flag indicates if the memory is execute-disable.
@param[in] Address The address of Memory.
@param[out] Nx The flag indicates if the memory is execute-disable.
@retval TRUE The input address is in protected range.
@retval FALSE The input address is not in protected range.
**/
BOOLEAN
IsAddressValid (
IN EFI_PHYSICAL_ADDRESS Address,
IN BOOLEAN *Nx
IsSmmProfilePFAddressAbove4GValid (
IN EFI_PHYSICAL_ADDRESS Address,
OUT BOOLEAN *Nx
);
/**

View File

@ -358,7 +358,7 @@ RestorePageTableAbove4G (
// If page entry does not existed in page table at all, create a new entry.
//
if (!Existed) {
if (IsAddressValid (PFAddress, &Nx)) {
if (IsSmmProfilePFAddressAbove4GValid (PFAddress, &Nx)) {
//
// If page fault address above 4GB is in protected range but it causes a page fault exception,
// Will create a page entry for this page fault address, make page table entry as present/rw and execution-disable.
@ -401,7 +401,7 @@ RestorePageTableAbove4G (
PageTable = (UINT64 *)(UINTN)(PageTable[PTIndex] & ~mAddressEncMask & PHYSICAL_ADDRESS_MASK);
for (Index = 0; Index < 512; Index++) {
PageTable[Index] = Address | mAddressEncMask | PAGE_ATTRIBUTE_BITS;
if (!IsAddressValid (Address, &Nx)) {
if (!IsSmmProfilePFAddressAbove4GValid (Address, &Nx)) {
PageTable[Index] = PageTable[Index] & (INTN)(INT32)(~PAGE_ATTRIBUTE_BITS);
}
@ -419,7 +419,7 @@ RestorePageTableAbove4G (
//
// Update 2MB page entry.
//
if (!IsAddressValid (Address, &Nx)) {
if (!IsSmmProfilePFAddressAbove4GValid (Address, &Nx)) {
//
// Patch to remove present flag and rw flag.
//