]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CpuException: Avoid allocating code pages for DXE instance
authorRay Ni <ray.ni@intel.com>
Wed, 18 May 2022 05:44:24 +0000 (13:44 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 10 Jun 2022 07:54:48 +0000 (07:54 +0000)
Today the DXE instance allocates code page and then copies the IDT
vectors to the allocated code page. Then it fixes up the vector number
in the IDT vector.

But if we update the NASM file to generate 256 IDT vectors, there is
no need to do the copy and fix-up.

A side effect is 4096 bytes (HOOKAFTER_STUB_SIZE * 256) is used for
256 IDT vectors while 32 IDT vectors only require 512 bytes without
this change, in following library instances:
1. 32bit SecPeiCpuExceptionHandlerLib and PeiCpuExceptionHandlerLib
2. 64bit PeiCpuExceptionHandlerLib

But considering the code logic simplification, 3.5K extra space is
not a big deal.
If 3.5K is too much, we can enhance the code further to generate 32
vectors for above mentioned library instances.

Signed-off-by: Ray Ni <ray.ni@intel.com>
Reviewed-by: Jian J Wang <jian.j.wang@intel.com>
Acked-by: Eric Dong <eric.dong@intel.com>
UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeException.c
UefiCpuPkg/Library/CpuExceptionHandlerLib/Ia32/ExceptionHandlerAsm.nasm
UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm
UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerAsm.nasm

index 61f11e98f8dc6ecdd9561b8d506c72da28a30958..5083c4b8e8cee9c51b683d04f5754e72c01efb37 100644 (file)
@@ -95,9 +95,6 @@ InitializeCpuInterruptHandlers (
   IA32_DESCRIPTOR                 IdtDescriptor;\r
   UINTN                           IdtEntryCount;\r
   EXCEPTION_HANDLER_TEMPLATE_MAP  TemplateMap;\r
-  UINTN                           Index;\r
-  UINTN                           InterruptEntry;\r
-  UINT8                           *InterruptEntryCode;\r
   RESERVED_VECTORS_DATA           *ReservedVectors;\r
   EFI_CPU_INTERRUPT_HANDLER       *ExternalInterruptHandler;\r
 \r
@@ -138,25 +135,6 @@ InitializeCpuInterruptHandlers (
   AsmGetTemplateAddressMap (&TemplateMap);\r
   ASSERT (TemplateMap.ExceptionStubHeaderSize <= HOOKAFTER_STUB_SIZE);\r
 \r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesCode,\r
-                  TemplateMap.ExceptionStubHeaderSize * CPU_INTERRUPT_NUM,\r
-                  (VOID **)&InterruptEntryCode\r
-                  );\r
-  ASSERT (!EFI_ERROR (Status) && InterruptEntryCode != NULL);\r
-\r
-  InterruptEntry = (UINTN)InterruptEntryCode;\r
-  for (Index = 0; Index < CPU_INTERRUPT_NUM; Index++) {\r
-    CopyMem (\r
-      (VOID *)InterruptEntry,\r
-      (VOID *)TemplateMap.ExceptionStart,\r
-      TemplateMap.ExceptionStubHeaderSize\r
-      );\r
-    AsmVectorNumFixup ((VOID *)InterruptEntry, (UINT8)Index, (VOID *)TemplateMap.ExceptionStart);\r
-    InterruptEntry += TemplateMap.ExceptionStubHeaderSize;\r
-  }\r
-\r
-  TemplateMap.ExceptionStart                     = (UINTN)InterruptEntryCode;\r
   mExceptionHandlerData.IdtEntryCount            = CPU_INTERRUPT_NUM;\r
   mExceptionHandlerData.ReservedVectors          = ReservedVectors;\r
   mExceptionHandlerData.ExternalInterruptHandler = ExternalInterruptHandler;\r
index 3fe9aed1e8485e2fc8e9af5a9682d864c3d5c3c6..8ed2b8f45500fe3e2243b489b40b748119294905 100644 (file)
@@ -33,7 +33,7 @@ ALIGN   8
 ;\r
 AsmIdtVectorBegin:\r
 %assign Vector 0\r
-%rep  32\r
+%rep  256\r
     push    byte %[Vector];\r
     push    eax\r
     mov     eax, ASM_PFX(CommonInterruptEntry)\r
@@ -439,7 +439,7 @@ ASM_PFX(AsmGetTemplateAddressMap):
 \r
     mov ebx, dword [ebp + 0x8]\r
     mov dword [ebx],      AsmIdtVectorBegin\r
-    mov dword [ebx + 0x4], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32\r
+    mov dword [ebx + 0x4], (AsmIdtVectorEnd - AsmIdtVectorBegin) / 256\r
     mov dword [ebx + 0x8], HookAfterStubBegin\r
 \r
     popad\r
index 9a806d1f8644226a9852152bb9a1e3386fdea216..aaf8d622e6f3b8f1b512bde7079b448bd06cd9ac 100644 (file)
@@ -31,6 +31,8 @@ SECTION .text
 \r
 ALIGN   8\r
 \r
+; Generate 32 IDT vectors.\r
+; 32 IDT vectors are enough because interrupts (32+) are not enabled in SEC and PEI phase.\r
 AsmIdtVectorBegin:\r
 %assign Vector 0\r
 %rep  32\r
index 9c72fa5815fed90535d3405bc7df4e500d99ecc6..7c0e3d3b0bb47aa95ab606452c3747c9e60eedfe 100644 (file)
@@ -53,9 +53,10 @@ SECTION .text
 \r
 ALIGN   8\r
 \r
+; Generate 256 IDT vectors.\r
 AsmIdtVectorBegin:\r
 %assign Vector 0\r
-%rep  32\r
+%rep  256\r
     push    byte %[Vector]\r
     push    rax\r
     mov     rax, strict qword 0 ;    mov     rax, ASM_PFX(CommonInterruptEntry)\r
@@ -453,16 +454,16 @@ global ASM_PFX(AsmGetTemplateAddressMap)
 ASM_PFX(AsmGetTemplateAddressMap):\r
     lea     rax, [AsmIdtVectorBegin]\r
     mov     qword [rcx], rax\r
-    mov     qword [rcx + 0x8],  (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32\r
+    mov     qword [rcx + 0x8],  (AsmIdtVectorEnd - AsmIdtVectorBegin) / 256\r
     lea     rax, [HookAfterStubHeaderBegin]\r
     mov     qword [rcx + 0x10], rax\r
 \r
 ; Fix up CommonInterruptEntry address\r
     lea    rax, [ASM_PFX(CommonInterruptEntry)]\r
     lea    rcx, [AsmIdtVectorBegin]\r
-%rep  32\r
+%rep  256\r
     mov    qword [rcx + (JmpAbsoluteAddress - 8 - HookAfterStubHeaderBegin)], rax\r
-    add    rcx, (AsmIdtVectorEnd - AsmIdtVectorBegin) / 32\r
+    add    rcx, (AsmIdtVectorEnd - AsmIdtVectorBegin) / 256\r
 %endrep\r
 ; Fix up HookAfterStubHeaderEnd\r
     lea    rax, [HookAfterStubHeaderEnd]\r