]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/MpInitLib: fix wrong address set as Stack Guard for APs
authorJian J Wang <jian.j.wang@intel.com>
Mon, 8 Jan 2018 05:30:38 +0000 (13:30 +0800)
committerEric Dong <eric.dong@intel.com>
Wed, 10 Jan 2018 00:25:12 +0000 (08:25 +0800)
The reason is that DXE part initialization will reuse the stack allocated
at PEI phase, if MP was initialized before. Some code added to check this
situation and use stack base address saved in HOB passed from PEI.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
UefiCpuPkg/Library/MpInitLib/DxeMpLib.c

index 40c1bf407af2c42023fa6ff4ef2c252c7e6a3618..e832c16ecacec771b7a5be37a77520a9942b17c6 100644 (file)
@@ -295,6 +295,7 @@ InitMpGlobalData (
   UINTN                               Index;\r
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR     MemDesc;\r
   UINTN                               StackBase;\r
+  CPU_INFO_IN_HOB                     *CpuInfoInHob;\r
 \r
   SaveCpuMpData (CpuMpData);\r
 \r
@@ -314,8 +315,21 @@ InitMpGlobalData (
       ASSERT (FALSE);\r
     }\r
 \r
+    //\r
+    // DXE will reuse stack allocated for APs at PEI phase if it's available.\r
+    // Let's check it here.\r
+    //\r
+    // Note: BSP's stack guard is set at DxeIpl phase. But for the sake of\r
+    // BSP/AP exchange, stack guard for ApTopOfStack of cpu 0 will still be\r
+    // set here.\r
+    //\r
+    CpuInfoInHob = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob;\r
     for (Index = 0; Index < CpuMpData->CpuCount; ++Index) {\r
-      StackBase = CpuMpData->Buffer + Index * CpuMpData->CpuApStackSize;\r
+      if (CpuInfoInHob != NULL && CpuInfoInHob[Index].ApTopOfStack != 0) {\r
+        StackBase = CpuInfoInHob[Index].ApTopOfStack - CpuMpData->CpuApStackSize;\r
+      } else {\r
+        StackBase = CpuMpData->Buffer + Index * CpuMpData->CpuApStackSize;\r
+      }\r
 \r
       Status = gDS->GetMemorySpaceDescriptor (StackBase, &MemDesc);\r
       ASSERT_EFI_ERROR (Status);\r
@@ -326,6 +340,9 @@ InitMpGlobalData (
                       MemDesc.Attributes | EFI_MEMORY_RP\r
                       );\r
       ASSERT_EFI_ERROR (Status);\r
+\r
+      DEBUG ((DEBUG_INFO, "Stack Guard set at %lx [cpu%lu]!\n",\r
+              (UINT64)StackBase, (UINT64)Index));\r
     }\r
   }\r
 \r