]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/PiSmmCpuDxeSmm: Place AP to 32bit protected mode on S3 path
authorJeff Fan <jeff.fan@intel.com>
Fri, 11 Nov 2016 05:11:22 +0000 (13:11 +0800)
committerJeff Fan <jeff.fan@intel.com>
Tue, 15 Nov 2016 01:47:32 +0000 (09:47 +0800)
On S3 path, we may transfer to long mode (if DXE is long mode) to restore CPU
contexts with CR3 = SmmS3Cr3 (in SMM). AP will execute hlt-loop after CPU
contexts restoration. Once one NMI or SMI happens, APs may exit from hlt state
and execute the instruction after HLT instruction. If APs are running on long
mode, page table is required to fetch the instruction. However, CR3 pointer to
page table in SMM. APs will crash.

This fix is to disable long mode on APs and transfer to 32bit protected mode to
execute hlt-loop. Then CR3 and page table will no longer be required.

https://bugzilla.tianocore.org/show_bug.cgi?id=216

Reported-by: Laszlo Ersek <lersek@redhat.com>
Analyzed-by: Paolo Bonzini <pbonzini@redhat.com>
Analyzed-by: Laszlo Ersek <lersek@redhat.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c

index bd465c7a067b6414865b4f7334351bdd544b9231..62338b79bd1f32d3c99886920d1c62130ec84b86 100644 (file)
@@ -69,6 +69,37 @@ InitGdt (
   return GdtTssTables;\r
 }\r
 \r
+/**\r
+  Get Protected mode code segment from current GDT table.\r
+\r
+  @return  Protected mode code segment value.\r
+**/\r
+UINT16\r
+GetProtectedModeCS (\r
+  VOID\r
+  )\r
+{\r
+  IA32_DESCRIPTOR          GdtrDesc;\r
+  IA32_SEGMENT_DESCRIPTOR  *GdtEntry;\r
+  UINTN                    GdtEntryCount;\r
+  UINT16                   Index;\r
+\r
+  Index = (UINT16) -1;\r
+  AsmReadGdtr (&GdtrDesc);\r
+  GdtEntryCount = (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR);\r
+  GdtEntry = (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base;\r
+  for (Index = 0; Index < GdtEntryCount; Index++) {\r
+    if (GdtEntry->Bits.L == 0) {\r
+      if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.L == 0) {\r
+        break;\r
+      }\r
+    }\r
+    GdtEntry++;\r
+  }\r
+  ASSERT (Index != -1);\r
+  return Index * 8;\r
+}\r
+\r
 /**\r
   Transfer AP to safe hlt-loop after it finished restore CPU features on S3 patch.\r
 \r
@@ -82,11 +113,12 @@ TransferApToSafeState (
   IN UINT32             TopOfStack\r
   )\r
 {\r
-  SwitchStack (\r
-    (SWITCH_STACK_ENTRY_POINT) (UINTN) ApHltLoopCode,\r
-    NULL,\r
-    NULL,\r
-    (VOID *) (UINTN) TopOfStack\r
+  AsmDisablePaging64 (\r
+    GetProtectedModeCS (),\r
+    (UINT32) (UINTN) ApHltLoopCode,\r
+    0,\r
+    0,\r
+    TopOfStack\r
     );\r
   //\r
   // It should never reach here\r