From: Jeff Fan Date: Fri, 11 Nov 2016 08:56:44 +0000 (+0800) Subject: UefiCpuPkg/DxeMpLib: Allocate below 4GB mem for AsmRelocateApLoopFunc X-Git-Tag: edk2-stable201903~5220 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=ffd6b0b1b65e620816fb16fe551f92309f4b7269;hp=b1067637cf53fd55f34b6a6147988e06f8cb7e80 UefiCpuPkg/DxeMpLib: Allocate below 4GB mem for AsmRelocateApLoopFunc Current implementation just allocates reserve memory for AsmRelocateApLoopFunc. It not be safe because APs will be placed into 32bit protected mode on long mode DXE. This reserve memory must be located below 4GB memory. This fix is to allocate < 4GB memory for AsmRelocateApLoopFunc. Cc: Laszlo Ersek Cc: Paolo Bonzini Cc: Jiewen Yao Cc: Michael D Kinney Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Fan Reviewed-by: Laszlo Ersek Tested-by: Laszlo Ersek [lersek@redhat.com: strip whitespace at EOL] Signed-off-by: Laszlo Ersek --- diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c index eb36d6f78d..19fc2725ac 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -286,7 +286,8 @@ InitMpGlobalData ( IN CPU_MP_DATA *CpuMpData ) { - EFI_STATUS Status; + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS Address; SaveCpuMpData (CpuMpData); @@ -298,16 +299,28 @@ InitMpGlobalData ( } // - // Avoid APs access invalid buff data which allocated by BootServices, - // so we will allocate reserved data for AP loop code. + // Avoid APs access invalid buffer data which allocated by BootServices, + // so we will allocate reserved data for AP loop code. We also need to + // allocate this buffer below 4GB due to APs may be transferred to 32bit + // protected mode on long mode DXE. // Allocating it in advance since memory services are not available in // Exit Boot Services callback function. // - mReservedApLoopFunc = AllocateReservedCopyPool ( - CpuMpData->AddressMap.RelocateApLoopFuncSize, - CpuMpData->AddressMap.RelocateApLoopFuncAddress - ); + Address = BASE_4GB - 1; + Status = gBS->AllocatePages ( + AllocateMaxAddress, + EfiReservedMemoryType, + EFI_SIZE_TO_PAGES (sizeof (CpuMpData->AddressMap.RelocateApLoopFuncSize)), + &Address + ); + ASSERT_EFI_ERROR (Status); + mReservedApLoopFunc = (VOID *) (UINTN) Address; ASSERT (mReservedApLoopFunc != NULL); + CopyMem ( + mReservedApLoopFunc, + CpuMpData->AddressMap.RelocateApLoopFuncAddress, + CpuMpData->AddressMap.RelocateApLoopFuncSize + ); Status = gBS->CreateEvent ( EVT_TIMER | EVT_NOTIFY_SIGNAL,