summaryrefslogtreecommitdiffstats
path: root/UefiCpuPkg/Library
diff options
context:
space:
mode:
authorJian J Wang <jian.j.wang@intel.com>2017-12-21 09:25:51 +0800
committerStar Zeng <star.zeng@intel.com>2017-12-22 14:16:51 +0800
commit15720a6cde27343e732dbe81aaee1764e26d20e0 (patch)
tree33c025c7992c677c1438b60b017ab8d04cea8e58 /UefiCpuPkg/Library
parent3d0ebaa8d88773a116bcbd840128ab25977ec174 (diff)
downloadedk2-15720a6cde27343e732dbe81aaee1764e26d20e0.tar.gz
edk2-15720a6cde27343e732dbe81aaee1764e26d20e0.tar.bz2
edk2-15720a6cde27343e732dbe81aaee1764e26d20e0.zip
UefiCpuPkg/MpInitLib: Add missing Guard page setup for APs
AP has its own stack for code execution. If PcdCpuStackGuard is enabled, the page at the bottom of stack of AP will be disabled (NOT PRESENT) to monitor the stack overflow issue. This requires PcdCpuApStackSize to be set with value more than one page of memory. 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: Jiewen Yao <jiewen.yao@intel.com>
Diffstat (limited to 'UefiCpuPkg/Library')
-rw-r--r--UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf1
-rw-r--r--UefiCpuPkg/Library/MpInitLib/DxeMpLib.c34
2 files changed, 32 insertions, 3 deletions
diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
index 805641b516..e7b9eb4462 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf
@@ -73,4 +73,5 @@
gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize ## CONSUMES
gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## CONSUMES
gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## SOMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## CONSUMES
diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
index 479f8189f6..40c1bf407a 100644
--- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
@@ -17,6 +17,7 @@
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DebugAgentLib.h>
+#include <Library/DxeServicesTableLib.h>
#include <Protocol/Timer.h>
@@ -288,9 +289,12 @@ InitMpGlobalData (
IN CPU_MP_DATA *CpuMpData
)
{
- EFI_STATUS Status;
- EFI_PHYSICAL_ADDRESS Address;
- UINTN ApSafeBufferSize;
+ EFI_STATUS Status;
+ EFI_PHYSICAL_ADDRESS Address;
+ UINTN ApSafeBufferSize;
+ UINTN Index;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR MemDesc;
+ UINTN StackBase;
SaveCpuMpData (CpuMpData);
@@ -301,6 +305,30 @@ InitMpGlobalData (
return;
}
+ if (PcdGetBool (PcdCpuStackGuard)) {
+ //
+ // One extra page at the bottom of the stack is needed for Guard page.
+ //
+ if (CpuMpData->CpuApStackSize <= EFI_PAGE_SIZE) {
+ DEBUG ((DEBUG_ERROR, "PcdCpuApStackSize is not big enough for Stack Guard!\n"));
+ ASSERT (FALSE);
+ }
+
+ for (Index = 0; Index < CpuMpData->CpuCount; ++Index) {
+ StackBase = CpuMpData->Buffer + Index * CpuMpData->CpuApStackSize;
+
+ Status = gDS->GetMemorySpaceDescriptor (StackBase, &MemDesc);
+ ASSERT_EFI_ERROR (Status);
+
+ Status = gDS->SetMemorySpaceAttributes (
+ StackBase,
+ EFI_PAGES_TO_SIZE (1),
+ MemDesc.Attributes | EFI_MEMORY_RP
+ );
+ ASSERT_EFI_ERROR (Status);
+ }
+ }
+
//
// Avoid APs access invalid buffer data which allocated by BootServices,
// so we will allocate reserved data for AP loop code. We also need to