If PcdDxeNxMemoryProtectionPolicy is set to enable protection for memory
of EfiBootServicesData, EfiConventionalMemory, the BIOS will reset after
timer initialized and started.

The root cause is that the memory used to hold the exception and interrupt
handler is allocated with type of EfiBootServicesData and marked as
non-executable due to NX feature enabled. This patch fixes it by allocating
EfiBootServicesCode type of memory for those handlers instead.

Cc: Jiewen Yao <jiewen....@intel.com>
Cc: Ruiyu Ni <ruiyu...@intel.com>
Cc: Eric Dong <eric.d...@intel.com>
Cc: Laszlo Ersek <ler...@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.w...@intel.com>
---
 .../Library/CpuExceptionHandlerLib/DxeException.c      | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c 
b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
index 9a72b37e77..6d1b54d31d 100644
--- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
+++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
@@ -16,6 +16,7 @@
 #include "CpuExceptionCommon.h"
 #include <Library/DebugLib.h>
 #include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
 
 CONST UINTN    mDoFarReturnFlag  = 0;
 
@@ -106,8 +107,12 @@ InitializeCpuInterruptHandlers (
   RESERVED_VECTORS_DATA              *ReservedVectors;
   EFI_CPU_INTERRUPT_HANDLER          *ExternalInterruptHandler;
 
-  ReservedVectors = AllocatePool (sizeof (RESERVED_VECTORS_DATA) * 
CPU_INTERRUPT_NUM);
-  ASSERT (ReservedVectors != NULL);
+  Status = gBS->AllocatePool (
+                  EfiBootServicesCode,
+                  sizeof (RESERVED_VECTORS_DATA) * CPU_INTERRUPT_NUM,
+                  (VOID **)&ReservedVectors
+                  );
+  ASSERT (!EFI_ERROR (Status) && ReservedVectors != NULL);
   SetMem ((VOID *) ReservedVectors, sizeof (RESERVED_VECTORS_DATA) * 
CPU_INTERRUPT_NUM, 0xff);
   if (VectorInfo != NULL) {
     Status = ReadAndVerifyVectorInfo (VectorInfo, ReservedVectors, 
CPU_INTERRUPT_NUM);
@@ -137,8 +142,13 @@ InitializeCpuInterruptHandlers (
 
   AsmGetTemplateAddressMap (&TemplateMap);
   ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);
-  InterruptEntryCode = AllocatePool (TemplateMap.ExceptionStubHeaderSize * 
CPU_INTERRUPT_NUM);
-  ASSERT (InterruptEntryCode != NULL);
+
+  Status = gBS->AllocatePool (
+                  EfiBootServicesCode,
+                  TemplateMap.ExceptionStubHeaderSize * CPU_INTERRUPT_NUM,
+                  (VOID **)&InterruptEntryCode
+                  );
+  ASSERT (!EFI_ERROR (Status) && InterruptEntryCode != NULL);
 
   InterruptEntry = (UINTN) InterruptEntryCode;
   for (Index = 0; Index < CPU_INTERRUPT_NUM; Index ++) {
-- 
2.15.1.windows.2

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to