UefiCpuPkg/PiSmmCpuDxeSmm: Always save and restore CR2

Following the commit 9f29fbd3, full mapping SMM page table is always
created regardless the value of the PcdCpuSmmRestrictedMemoryAccess.
Consequently, a page fault (#PF) that triggers an update to the page
table occurs only when SmiProfile is enabled. Therefore, it is
necessary to save and restore the CR2 register when SmiProfile is
configured to be enabled.

And the operation of saving and restoring CR2 is considered to be
not heavy operation compared to the saving and restoring of CR3.
As a result, the condition check for SmiProfile has been removed,
and CR2 is now saved and restored unconditionally, without the need
for additional condition checks.

Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
This commit is contained in:
Jiaxin Wu 2024-09-02 12:03:46 +08:00 committed by mergify[bot]
parent 897284d47d
commit c8ce84d067
1 changed files with 4 additions and 14 deletions

View File

@ -845,7 +845,7 @@ Exit:
}
/**
This function reads CR2 register when on-demand paging is enabled.
This function reads CR2 register.
@param[out] *Cr2 Pointer to variable to hold CR2 register value.
**/
@ -854,16 +854,11 @@ SaveCr2 (
OUT UINTN *Cr2
)
{
if (!mCpuSmmRestrictedMemoryAccess) {
//
// On-demand paging is enabled when access to non-SMRAM is not restricted.
//
*Cr2 = AsmReadCr2 ();
}
}
/**
This function restores CR2 register when on-demand paging is enabled.
This function restores CR2 register.
@param[in] Cr2 Value to write into CR2 register.
**/
@ -872,12 +867,7 @@ RestoreCr2 (
IN UINTN Cr2
)
{
if (!mCpuSmmRestrictedMemoryAccess) {
//
// On-demand paging is enabled when access to non-SMRAM is not restricted.
//
AsmWriteCr2 (Cr2);
}
}
/**