Skip to content

Commit

Permalink
UefiCpuPkg/PiSmmCpuDxeSmm: Save and restore CR2 only if SmiProfile en…
Browse files Browse the repository at this point in the history
…able

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>
  • Loading branch information
jiaxinwu authored and mergify[bot] committed Oct 16, 2024
1 parent 92c1274 commit a232e0c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}
}

/**
Expand All @@ -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);
}
}

0 comments on commit a232e0c

Please sign in to comment.