Skip to content

Commit

Permalink
UefiCpuPkg: rename and simplify IsAddressValid function
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
td36 authored and mergify[bot] committed Aug 5, 2024
1 parent cff0641 commit 5d43165
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 34 deletions.
44 changes: 19 additions & 25 deletions UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

*Nx = TRUE;
return FALSE;
} else {
*Nx = TRUE;
if (IsInSmmRanges (Address)) {
*Nx = FALSE;
//
// 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;
}

return TRUE;
}

*Nx = TRUE;
return FALSE;
}

/**
Expand Down
15 changes: 9 additions & 6 deletions UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfileInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

/**
Expand Down
6 changes: 3 additions & 3 deletions UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmProfileArch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}

Expand All @@ -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.
//
Expand Down

0 comments on commit 5d43165

Please sign in to comment.