public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] UefiCpuPkg/MpInitLib: fix wrong base address set as Stack Guard
@ 2017-12-29  8:36 Jian J Wang
  2018-01-03  7:05 ` Wang, Jian J
  2018-01-03 17:33 ` Laszlo Ersek
  0 siblings, 2 replies; 19+ messages in thread
From: Jian J Wang @ 2017-12-29  8:36 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jiewen Yao, Eric Dong, Laszlo Ersek

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>
---
 UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 40c1bf407a..05484c9ff3 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -295,6 +295,7 @@ InitMpGlobalData (
   UINTN                               Index;
   EFI_GCD_MEMORY_SPACE_DESCRIPTOR     MemDesc;
   UINTN                               StackBase;
+  CPU_INFO_IN_HOB                     *CpuInfoInHob;
 
   SaveCpuMpData (CpuMpData);
 
@@ -314,9 +315,18 @@ InitMpGlobalData (
       ASSERT (FALSE);
     }
 
-    for (Index = 0; Index < CpuMpData->CpuCount; ++Index) {
-      StackBase = CpuMpData->Buffer + Index * CpuMpData->CpuApStackSize;
+    //
+    // DXE will reuse stack allocated for APs at PEI phase if it's available.
+    // Let's check it here.
+    //
+    CpuInfoInHob = (CPU_INFO_IN_HOB *)(UINTN)CpuMpData->CpuInfoInHob;
+    if (CpuInfoInHob != NULL && CpuInfoInHob->ApTopOfStack != 0) {
+      StackBase = CpuInfoInHob->ApTopOfStack;
+    } else {
+      StackBase = CpuMpData->Buffer;
+    }
 
+    for (Index = 0; Index < CpuMpData->CpuCount; ++Index) {
       Status = gDS->GetMemorySpaceDescriptor (StackBase, &MemDesc);
       ASSERT_EFI_ERROR (Status);
 
@@ -326,6 +336,9 @@ InitMpGlobalData (
                       MemDesc.Attributes | EFI_MEMORY_RP
                       );
       ASSERT_EFI_ERROR (Status);
+
+      DEBUG ((DEBUG_VERBOSE, "Stack Guard set at %x [cpu%d]!\n", StackBase, Index));
+      StackBase += CpuMpData->CpuApStackSize;
     }
   }
 
-- 
2.15.1.windows.2



^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2018-01-05  3:01 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-29  8:36 [PATCH] UefiCpuPkg/MpInitLib: fix wrong base address set as Stack Guard Jian J Wang
2018-01-03  7:05 ` Wang, Jian J
2018-01-03 17:33 ` Laszlo Ersek
2018-01-04  0:41   ` Wang, Jian J
2018-01-04  1:09     ` Wang, Jian J
2018-01-04  1:45       ` Wang, Jian J
2018-01-04 12:21         ` Laszlo Ersek
2018-01-05  0:52           ` Wang, Jian J
2018-01-05  1:40           ` 答复: " Fan Jeff
2018-01-05  1:57             ` Wang, Jian J
2018-01-05  2:48               ` 答复: " Fan Jeff
2018-01-05  2:49                 ` Fan Jeff
2018-01-05  2:54                   ` Chaganty, Rangasai V
2018-01-05  2:56                     ` Wang, Jian J
2018-01-05  2:55                   ` Wang, Jian J
2018-01-05  2:57                     ` Yao, Jiewen
2018-01-05  3:04                       ` 答复: " Fan Jeff
2018-01-05  3:06                         ` Wang, Jian J
2018-01-04 12:18       ` Laszlo Ersek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox