UefiCpuPkg/PiSmmCpuDxeSmm: Save and restore CR2 only if SmiProfile enable

A page fault (#PF) that triggers an update to the page table only occurs
if SmiProfile is enabled. Therefore, it is necessary to save and restore
the CR2 register if SmiProfile is configured to be enabled.

Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
This commit is contained in:
Jiaxin Wu 2024-10-12 14:32:40 +08:00 committed by mergify[bot]
parent 92c1274467
commit a232e0cd2f
1 changed files with 18 additions and 2 deletions

View File

@ -851,7 +851,15 @@ SaveCr2 (
OUT UINTN *Cr2
)
{
*Cr2 = AsmReadCr2 ();
//
// A page fault (#PF) that triggers an update to the page
// table only occurs if SmiProfile is enabled. Therefore, it is
// necessary to save the CR2 register if SmiProfile is
// configured to be enabled.
//
if (mSmmProfileEnabled) {
*Cr2 = AsmReadCr2 ();
}
}
/**
@ -864,5 +872,13 @@ RestoreCr2 (
IN UINTN Cr2
)
{
AsmWriteCr2 (Cr2);
//
// A page fault (#PF) that triggers an update to the page
// table only occurs if SmiProfile is enabled. Therefore, it is
// necessary to restore the CR2 register if SmiProfile is
// configured to be enabled.
//
if (mSmmProfileEnabled) {
AsmWriteCr2 (Cr2);
}
}