]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c
UefiCpuPkg/PiSmmCpuDxeSmm: patch "XdSupported" with PatchInstructionX86()
[mirror_edk2.git] / UefiCpuPkg / PiSmmCpuDxeSmm / SmmProfile.c
index 2713b19dd2fa049c096d1b7236a2dc352997868f..b4fe0bc23b6cb6f9d0b0a53050d5255700366456 100644 (file)
@@ -31,6 +31,11 @@ UINTN                     mSmmProfileSize;
 //\r
 UINTN                     mMsrDsAreaSize   = SMM_PROFILE_DTS_SIZE;\r
 \r
+//\r
+// The flag indicates if execute-disable is supported by processor.\r
+//\r
+BOOLEAN                   mXdSupported     = TRUE;\r
+\r
 //\r
 // The flag indicates if execute-disable is enabled on processor.\r
 //\r
@@ -267,7 +272,7 @@ IsInSmmRanges (
 {\r
   UINTN  Index;\r
 \r
-  if ((Address < mCpuHotPlugData.SmrrBase) || (Address >= mCpuHotPlugData.SmrrBase + mCpuHotPlugData.SmrrSize)) {\r
+  if ((Address >= mCpuHotPlugData.SmrrBase) && (Address < mCpuHotPlugData.SmrrBase + mCpuHotPlugData.SmrrSize)) {\r
     return TRUE;\r
   }\r
   for (Index = 0; Index < mSmmCpuSmramRangeCount; Index++) {\r
@@ -1010,6 +1015,7 @@ CheckFeatureSupported (
       // Extended CPUID functions are not supported on this processor.\r
       //\r
       mXdSupported = FALSE;\r
+      PatchInstructionX86 (gPatchXdSupported, mXdSupported, 1);\r
     }\r
 \r
     AsmCpuid (CPUID_EXTENDED_CPU_SIG, NULL, NULL, NULL, &RegEdx);\r
@@ -1018,6 +1024,7 @@ CheckFeatureSupported (
       // Execute Disable Bit feature is not supported on this processor.\r
       //\r
       mXdSupported = FALSE;\r
+      PatchInstructionX86 (gPatchXdSupported, mXdSupported, 1);\r
     }\r
   }\r
 \r
@@ -1302,6 +1309,8 @@ SmmProfilePFHandler (
 {\r
   UINT64                *PageTable;\r
   UINT64                PFAddress;\r
+  UINT64                RestoreAddress;\r
+  UINTN                 RestorePageNumber;\r
   UINTN                 CpuIndex;\r
   UINTN                 Index;\r
   UINT64                InstructionAddress;\r
@@ -1331,10 +1340,21 @@ SmmProfilePFHandler (
   PFAddress         = AsmReadCr2 ();\r
   CpuIndex          = GetCpuIndex ();\r
 \r
-  if (PFAddress <= 0xFFFFFFFF) {\r
-    RestorePageTableBelow4G (PageTable, PFAddress, CpuIndex, ErrorCode);\r
-  } else {\r
-    RestorePageTableAbove4G (PageTable, PFAddress, CpuIndex, ErrorCode, &IsValidPFAddress);\r
+  //\r
+  // Memory operation cross pages, like "rep mov" instruction, will cause\r
+  // infinite loop between this and Debug Trap handler. We have to make sure\r
+  // that current page and the page followed are both in PRESENT state.\r
+  //\r
+  RestorePageNumber = 2;\r
+  RestoreAddress = PFAddress;\r
+  while (RestorePageNumber > 0) {\r
+    if (RestoreAddress <= 0xFFFFFFFF) {\r
+      RestorePageTableBelow4G (PageTable, RestoreAddress, CpuIndex, ErrorCode);\r
+    } else {\r
+      RestorePageTableAbove4G (PageTable, RestoreAddress, CpuIndex, ErrorCode, &IsValidPFAddress);\r
+    }\r
+    RestoreAddress += EFI_PAGE_SIZE;\r
+    RestorePageNumber--;\r
   }\r
 \r
   if (!IsValidPFAddress) {\r