]> xenbits.xensource.com Git - people/aperard/ovmf.git/commitdiff
UefiCpuPkg/PiSmmCpuDxeSmm: Always save and restore CR2
authorJiaxin Wu <jiaxin.wu@intel.com>
Mon, 2 Sep 2024 04:03:46 +0000 (12:03 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 6 Sep 2024 08:41:49 +0000 (08:41 +0000)
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>
UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c

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