Skip to content

Commit ccc2697

Browse files
niruiyumergify[bot]
authored andcommitted
MpInitLib: Move the Above1Mb vector allocation to MpInitLibInitialize
The AP vector consists of 2 parts: 1. the initial 16-bit code that should be under 1MB and page aligned. 2. the 32-bit/64-bit code that can be anywhere in the memory with any alignment. The need of part #2 is because the memory under 1MB is temporary "stolen" for use and will "give" back after all AP wake up. The range of memory is not marked as code page in page table. CPU may trigger exception as soon as NX is enabled. The part #2 memory allocation can be done in the MpInitLibInitialize. Signed-off-by: Ray Ni <ray.ni@intel.com> Reviewed-by: Eric Dong <eric.dong@intel.com>
1 parent 283ab94 commit ccc2697

1 file changed

Lines changed: 29 additions & 24 deletions

File tree

  • UefiCpuPkg/Library/MpInitLib

UefiCpuPkg/Library/MpInitLib/MpLib.c

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -955,18 +955,6 @@ FillExchangeInfoData (
955955
Size -= sizeof (IA32_SEGMENT_DESCRIPTOR);
956956
}
957957

958-
//
959-
// Copy all 32-bit code and 64-bit code into memory with type of
960-
// EfiBootServicesCode to avoid page fault if NX memory protection is enabled.
961-
//
962-
GetApResetVectorSize (&CpuMpData->AddressMap, NULL, &Size);
963-
CopyMem (
964-
(VOID *)CpuMpData->WakeupBufferHigh,
965-
CpuMpData->AddressMap.RendezvousFunnelAddress +
966-
CpuMpData->AddressMap.ModeTransitionOffset,
967-
Size
968-
);
969-
970958
ExchangeInfo->ModeTransitionMemory = (UINT32)CpuMpData->WakeupBufferHigh;
971959

972960
ExchangeInfo->ModeHighMemory = ExchangeInfo->ModeTransitionMemory +
@@ -1035,21 +1023,24 @@ RestoreWakeupBuffer (
10351023
@param[in, out] CpuMpData The pointer to CPU MP Data structure.
10361024
**/
10371025
VOID
1038-
AllocateResetVector (
1026+
AllocateResetVectorBelow1Mb (
10391027
IN OUT CPU_MP_DATA *CpuMpData
10401028
)
10411029
{
1042-
UINTN ApResetVectorSizeBelow1Mb;
1043-
UINTN ApResetVectorSizeAbove1Mb;
10441030
UINTN ApResetStackSize;
10451031

10461032
if (CpuMpData->WakeupBuffer == (UINTN)-1) {
1047-
GetApResetVectorSize (&CpuMpData->AddressMap, &ApResetVectorSizeBelow1Mb, &ApResetVectorSizeAbove1Mb);
1048-
1049-
CpuMpData->WakeupBuffer = GetWakeupBuffer (ApResetVectorSizeBelow1Mb);
1033+
CpuMpData->WakeupBuffer = GetWakeupBuffer (CpuMpData->BackupBufferSize);
10501034
CpuMpData->MpCpuExchangeInfo = (MP_CPU_EXCHANGE_INFO *)(UINTN)
1051-
(CpuMpData->WakeupBuffer + ApResetVectorSizeBelow1Mb - sizeof (MP_CPU_EXCHANGE_INFO));
1052-
CpuMpData->WakeupBufferHigh = AllocateCodeBuffer (ApResetVectorSizeAbove1Mb);
1035+
(CpuMpData->WakeupBuffer + CpuMpData->BackupBufferSize - sizeof (MP_CPU_EXCHANGE_INFO));
1036+
DEBUG ((
1037+
DEBUG_INFO,
1038+
"AP Vector: 16-bit = %p/%x, ExchangeInfo = %p/%x\n",
1039+
CpuMpData->WakeupBuffer,
1040+
CpuMpData->BackupBufferSize - sizeof (MP_CPU_EXCHANGE_INFO),
1041+
CpuMpData->MpCpuExchangeInfo,
1042+
sizeof (MP_CPU_EXCHANGE_INFO)
1043+
));
10531044
//
10541045
// The AP reset stack is only used by SEV-ES guests. Do not allocate it
10551046
// if SEV-ES is not enabled. An SEV-SNP guest is also considered
@@ -1148,7 +1139,7 @@ WakeUpAP (
11481139
(CpuMpData->InitFlag != ApInitDone))
11491140
{
11501141
ResetVectorRequired = TRUE;
1151-
AllocateResetVector (CpuMpData);
1142+
AllocateResetVectorBelow1Mb (CpuMpData);
11521143
AllocateSevEsAPMemory (CpuMpData);
11531144
FillExchangeInfoData (CpuMpData);
11541145
SaveLocalApicTimerSetting (CpuMpData);
@@ -1789,6 +1780,7 @@ MpInitLibInitialize (
17891780
UINT8 *MonitorBuffer;
17901781
UINTN Index;
17911782
UINTN ApResetVectorSizeBelow1Mb;
1783+
UINTN ApResetVectorSizeAbove1Mb;
17921784
UINTN BackupBufferAddr;
17931785
UINTN ApIdtBase;
17941786

@@ -1802,9 +1794,9 @@ MpInitLibInitialize (
18021794
ASSERT (MaxLogicalProcessorNumber != 0);
18031795

18041796
AsmGetAddressMap (&AddressMap);
1805-
GetApResetVectorSize (&AddressMap, &ApResetVectorSizeBelow1Mb, NULL);
1806-
ApStackSize = PcdGet32 (PcdCpuApStackSize);
1807-
ApLoopMode = GetApLoopMode (&MonitorFilterSize);
1797+
GetApResetVectorSize (&AddressMap, &ApResetVectorSizeBelow1Mb, &ApResetVectorSizeAbove1Mb);
1798+
ApStackSize = PcdGet32 (PcdCpuApStackSize);
1799+
ApLoopMode = GetApLoopMode (&MonitorFilterSize);
18081800

18091801
//
18101802
// Save BSP's Control registers for APs.
@@ -1913,6 +1905,19 @@ MpInitLibInitialize (
19131905
(UINT32 *)(MonitorBuffer + MonitorFilterSize * Index);
19141906
}
19151907

1908+
//
1909+
// Copy all 32-bit code and 64-bit code into memory with type of
1910+
// EfiBootServicesCode to avoid page fault if NX memory protection is enabled.
1911+
//
1912+
CpuMpData->WakeupBufferHigh = AllocateCodeBuffer (ApResetVectorSizeAbove1Mb);
1913+
CopyMem (
1914+
(VOID *)CpuMpData->WakeupBufferHigh,
1915+
CpuMpData->AddressMap.RendezvousFunnelAddress +
1916+
CpuMpData->AddressMap.ModeTransitionOffset,
1917+
ApResetVectorSizeAbove1Mb
1918+
);
1919+
DEBUG ((DEBUG_INFO, "AP Vector: non-16-bit = %p/%x\n", CpuMpData->WakeupBufferHigh, ApResetVectorSizeAbove1Mb));
1920+
19161921
//
19171922
// Enable the local APIC for Virtual Wire Mode.
19181923
//

0 commit comments

Comments
 (0)