]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/PiSmmCore: remove NX attr for SMM RAM
authorJian J Wang <jian.j.wang@intel.com>
Mon, 15 Jan 2018 02:21:08 +0000 (10:21 +0800)
committerRuiyu Ni <ruiyu.ni@intel.com>
Thu, 18 Jan 2018 09:03:25 +0000 (17:03 +0800)
If PcdDxeNxMemoryProtectionPolicy is set to enable protection for memory
of EfiReservedMemoryType, the BIOS will hang at a page fault exception
during starting SMM driver.

The root cause is that SMM RAM is type of EfiReservedMemoryType and
marked as non-executable. The fix is simply removing NX attribute for
those memory.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c

index a7663ca291c488504223ed22fc13a055245cc961..94d671bd747d15c0d31f10d99e16ee277fabbd40 100644 (file)
@@ -1550,6 +1550,7 @@ SmmIplEntry (
   EFI_CPU_ARCH_PROTOCOL           *CpuArch;\r
   EFI_STATUS                      SetAttrStatus;\r
   EFI_SMRAM_DESCRIPTOR            *SmramRangeSmmDriver;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc;\r
 \r
   //\r
   // Fill in the image handle of the SMM IPL so the SMM Core can use this as the \r
@@ -1616,7 +1617,8 @@ SmmIplEntry (
 \r
     GetSmramCacheRange (mCurrentSmramRange, &mSmramCacheBase, &mSmramCacheSize);\r
     //\r
-    // If CPU AP is present, attempt to set SMRAM cacheability to WB\r
+    // If CPU AP is present, attempt to set SMRAM cacheability to WB and clear\r
+    // XP if it's set.\r
     // Note that it is expected that cacheability of SMRAM has been set to WB if CPU AP\r
     // is not available here.\r
     //\r
@@ -1630,7 +1632,19 @@ SmmIplEntry (
                       );\r
       if (EFI_ERROR (Status)) {\r
         DEBUG ((DEBUG_WARN, "SMM IPL failed to set SMRAM window to EFI_MEMORY_WB\n"));\r
-      }  \r
+      }\r
+\r
+      Status = gDS->GetMemorySpaceDescriptor(\r
+                      mCurrentSmramRange->PhysicalStart,\r
+                      &MemDesc\r
+                      );\r
+      if (!EFI_ERROR (Status) && (MemDesc.Attributes & EFI_MEMORY_XP) != 0) {\r
+        gDS->SetMemorySpaceAttributes (\r
+               mCurrentSmramRange->PhysicalStart,\r
+               mCurrentSmramRange->PhysicalSize,\r
+               MemDesc.Attributes & (~EFI_MEMORY_XP)\r
+               );\r
+      }\r
     }\r
     //\r
     // if Loading module at Fixed Address feature is enabled, save the SMRAM base to Load\r