]> git.proxmox.com Git - mirror_edk2.git/commitdiff
UefiCpuPkg/MpInitLib: Fix MemTest86 failure.
authorEric Dong <eric.dong@intel.com>
Wed, 3 Apr 2019 02:46:20 +0000 (10:46 +0800)
committerEric Dong <eric.dong@intel.com>
Thu, 4 Apr 2019 06:00:32 +0000 (14:00 +0800)
V2 changes:
  Update the commit message and comments in the code.

When waking vector buffer allocated by CpuDxe is tested by MemTest86
in MP mode, an error is reported because the same range of memory is
modified by both CpuDxe driver and MemTest86.

The waking vector buffer is not expected to be tested by MemTest86 if
it is allocated out because MemTest86 only tests free memory. But
current CpuDxe driver "borrows" buffer instead of allocate buffer for
waking vector buffer (through allocate & free to get the buffer
pointer, backup the buffer data before using it and restore it after
using). With this implementation, if the buffer borrowed is not used
by any other drivers, MemTest86 tool will treat it as free memory
and test it.

In order to fix the above issue, CpuDxe changes to allocate the
buffer below 1M instead of borrowing it. But directly allocating
memory below 1MB causes LegacyBios driver fails to start. LegacyBios
driver allocates memory range from
"0xA0000 - PcdEbdaReservedMemorySize" to 0xA0000 as Ebda Reserved
Memory. The minimum value for "0xA0000 - PcdEbdaReservedMemorySize"
is 0x88000. If LegacyBios driver allocate this range failed, it
asserts.

LegacyBios also reserves range from 0x60000 to
"0x60000 + PcdOpromReservedMemorySize", it will be used as Oprom
Reserve Memory. The maximum value for "0x60000 +
PcdOpromReservedMemorySize" is 0x88000. LegacyBios driver tries to
allocate these range page(4K size) by page. It just reports warning
message if some pages are already allocated by others.
Base on above investigation, one page in range 0x60000 ~ 0x88000 can
be used as the waking vector buffer.

LegacyBios driver only reports warning when page allocation in range
[0x60000, 0x88000) fails. This library is consumed by CpuDxe driver
to produce CPU Arch protocol. LagacyBios driver depends on CPU Arch
protocol which guarantees below allocation runs earlier than
LegacyBios driver.

Cc: Ray Ni <ray.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
UefiCpuPkg/Library/MpInitLib/DxeMpLib.c

index b2307cbb618db18205b9d065694a4630f8d74494..cef5b49dde4be0225b2b1fec4935c5032b13b206 100644 (file)
@@ -76,7 +76,7 @@ SaveCpuMpData (
 }\r
 \r
 /**\r
-  Get available system memory below 1MB by specified size.\r
+  Get available system memory below 0x88000 by specified size.\r
 \r
   @param[in] WakeupBufferSize   Wakeup buffer size required\r
 \r
@@ -91,7 +91,15 @@ GetWakeupBuffer (
   EFI_STATUS              Status;\r
   EFI_PHYSICAL_ADDRESS    StartAddress;\r
 \r
-  StartAddress = BASE_1MB;\r
+  //\r
+  // Try to allocate buffer below 1M for waking vector.\r
+  // LegacyBios driver only reports warning when page allocation in range\r
+  // [0x60000, 0x88000) fails.\r
+  // This library is consumed by CpuDxe driver to produce CPU Arch protocol.\r
+  // LagacyBios driver depends on CPU Arch protocol which guarantees below\r
+  // allocation runs earlier than LegacyBios driver.\r
+  //\r
+  StartAddress = 0x88000;\r
   Status = gBS->AllocatePages (\r
                   AllocateMaxAddress,\r
                   EfiBootServicesData,\r
@@ -99,17 +107,13 @@ GetWakeupBuffer (
                   &StartAddress\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
-  if (!EFI_ERROR (Status)) {\r
-    Status = gBS->FreePages(\r
-               StartAddress,\r
-               EFI_SIZE_TO_PAGES (WakeupBufferSize)\r
-               );\r
-    ASSERT_EFI_ERROR (Status);\r
-    DEBUG ((DEBUG_INFO, "WakeupBufferStart = %x, WakeupBufferSize = %x\n",\r
-                        (UINTN) StartAddress, WakeupBufferSize));\r
-  } else {\r
+  if (EFI_ERROR (Status)) {\r
     StartAddress = (EFI_PHYSICAL_ADDRESS) -1;\r
   }\r
+\r
+  DEBUG ((DEBUG_INFO, "WakeupBufferStart = %x, WakeupBufferSize = %x\n",\r
+                      (UINTN) StartAddress, WakeupBufferSize));\r
+\r
   return (UINTN) StartAddress;\r
 }\r
 \r