]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/ArmExceptionLib: use static buffer for sp_el0
authorHeyi Guo <guoheyi@linux.alibaba.com>
Tue, 9 Jun 2020 01:26:30 +0000 (09:26 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 10 Jun 2020 18:06:45 +0000 (18:06 +0000)
The exception library is also used in DxeMain before memory services
are available, and AllocatePages() will fail in this case and cause
sp_el0 remains 0. Then if any exception occurs before CpuDxe driver is
loaded, a recursive exception will be trigged by page translation
fault for sp = 0 - 0x130.

Use static buffer instead to fix this issue.

Signed-off-by: Heyi Guo <guoheyi@linux.alibaba.com>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
ArmPkg/Library/ArmExceptionLib/AArch64/AArch64Exception.c

index be1cdcf5ebc70310b1d81186d26e4625e7b1350d..514f80a2d47afa0686395c597b398df0b98e7d39 100644 (file)
@@ -19,7 +19,8 @@ EFI_EXCEPTION_CALLBACK  gDebuggerExceptionHandlers[MAX_AARCH64_EXCEPTION + 1] =
 PHYSICAL_ADDRESS        gExceptionVectorAlignmentMask = ARM_VECTOR_TABLE_ALIGNMENT;\r
 UINTN                   gDebuggerNoHandlerValue = 0; // todo: define for AArch64\r
 \r
-#define EL0_STACK_PAGES   2\r
+#define EL0_STACK_SIZE  EFI_PAGES_TO_SIZE(2)\r
+STATIC UINTN mNewStackBase[EL0_STACK_SIZE / sizeof (UINTN)];\r
 \r
 VOID\r
 RegisterEl0Stack (\r
@@ -31,14 +32,11 @@ RETURN_STATUS ArchVectorConfig(
   )\r
 {\r
   UINTN             HcrReg;\r
-  UINT8             *Stack;\r
 \r
-  Stack = AllocatePages (EL0_STACK_PAGES);\r
-  if (Stack == NULL) {\r
-    return RETURN_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  RegisterEl0Stack ((UINT8 *)Stack + EFI_PAGES_TO_SIZE (EL0_STACK_PAGES));\r
+  // Round down sp by 16 bytes alignment\r
+  RegisterEl0Stack (\r
+    (VOID *)(((UINTN)mNewStackBase + EL0_STACK_SIZE) & ~0xFUL)\r
+    );\r
 \r
   if (ArmReadCurrentEL() == AARCH64_EL2) {\r
     HcrReg = ArmReadHcr();\r