UefiCpuPkg/MpInitLib: put mReservedApLoopFunc in executable memory
if PcdDxeNxMemoryProtectionPolicy is enabled for EfiReservedMemoryType
of memory, #PF will be triggered for each APs after ExitBootServices
in SCRT test. The root cause is that AP wakeup code executed at that
time is stored in memory of type EfiReservedMemoryType (referenced by
global mReservedApLoopFunc), which is marked as non-executable.
This patch fixes this issue by setting memory of mReservedApLoopFunc to
be executable immediately after allocation.
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
(cherry picked from commit bc2288f59b
)
This commit is contained in:
@@ -388,9 +388,9 @@ InitMpGlobalData (
|
|||||||
// Allocating it in advance since memory services are not available in
|
// Allocating it in advance since memory services are not available in
|
||||||
// Exit Boot Services callback function.
|
// Exit Boot Services callback function.
|
||||||
//
|
//
|
||||||
ApSafeBufferSize = CpuMpData->AddressMap.RelocateApLoopFuncSize;
|
ApSafeBufferSize = EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (
|
||||||
ApSafeBufferSize += CpuMpData->CpuCount * AP_SAFE_STACK_SIZE;
|
CpuMpData->AddressMap.RelocateApLoopFuncSize
|
||||||
|
));
|
||||||
Address = BASE_4GB - 1;
|
Address = BASE_4GB - 1;
|
||||||
Status = gBS->AllocatePages (
|
Status = gBS->AllocatePages (
|
||||||
AllocateMaxAddress,
|
AllocateMaxAddress,
|
||||||
@@ -399,9 +399,39 @@ InitMpGlobalData (
|
|||||||
&Address
|
&Address
|
||||||
);
|
);
|
||||||
ASSERT_EFI_ERROR (Status);
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
mReservedApLoopFunc = (VOID *) (UINTN) Address;
|
mReservedApLoopFunc = (VOID *) (UINTN) Address;
|
||||||
ASSERT (mReservedApLoopFunc != NULL);
|
ASSERT (mReservedApLoopFunc != NULL);
|
||||||
mReservedTopOfApStack = (UINTN) Address + EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (ApSafeBufferSize));
|
|
||||||
|
//
|
||||||
|
// Make sure that the buffer memory is executable if NX protection is enabled
|
||||||
|
// for EfiReservedMemoryType.
|
||||||
|
//
|
||||||
|
// TODO: Check EFI_MEMORY_XP bit set or not once it's available in DXE GCD
|
||||||
|
// service.
|
||||||
|
//
|
||||||
|
Status = gDS->GetMemorySpaceDescriptor (Address, &MemDesc);
|
||||||
|
if (!EFI_ERROR (Status)) {
|
||||||
|
gDS->SetMemorySpaceAttributes (
|
||||||
|
Address,
|
||||||
|
ApSafeBufferSize,
|
||||||
|
MemDesc.Attributes & (~EFI_MEMORY_XP)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ApSafeBufferSize = EFI_PAGES_TO_SIZE (EFI_SIZE_TO_PAGES (
|
||||||
|
CpuMpData->CpuCount * AP_SAFE_STACK_SIZE
|
||||||
|
));
|
||||||
|
Address = BASE_4GB - 1;
|
||||||
|
Status = gBS->AllocatePages (
|
||||||
|
AllocateMaxAddress,
|
||||||
|
EfiReservedMemoryType,
|
||||||
|
EFI_SIZE_TO_PAGES (ApSafeBufferSize),
|
||||||
|
&Address
|
||||||
|
);
|
||||||
|
ASSERT_EFI_ERROR (Status);
|
||||||
|
|
||||||
|
mReservedTopOfApStack = (UINTN) Address + ApSafeBufferSize;
|
||||||
ASSERT ((mReservedTopOfApStack & (UINTN)(CPU_STACK_ALIGNMENT - 1)) == 0);
|
ASSERT ((mReservedTopOfApStack & (UINTN)(CPU_STACK_ALIGNMENT - 1)) == 0);
|
||||||
CopyMem (
|
CopyMem (
|
||||||
mReservedApLoopFunc,
|
mReservedApLoopFunc,
|
||||||
|
Reference in New Issue
Block a user