The DXE stage's Microcode loading process has been elimincated by:
1. Let ShadowMicrocodeUpdatePatch and MicrocodeDetect for BSP performed
only during the PEI phase. DXE skip those actions.
2. BSP in DXE WakeUpAp only for synchronizing MTRR settings, not loading
microcode.
Synchronizing the MTRR table to the AP is always essential.
During the DXE phase, it cannot be omitted like loading microcode,
as the PEI and DXE may be in different bit modes.
Cc: Ray Ni <ray.ni@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
---
UefiCpuPkg/Library/MpInitLib/MpLib.c | 38 +++++++++++++++++++++++---------------
1 file changed, 23 insertions(+), 15 deletions(-)
diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpInitLib/MpLib.c
index 9a6ec5db5c..c26a17e1db 100644
--- a/UefiCpuPkg/Library/MpInitLib/MpLib.c
+++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c
@@ -451,12 +451,19 @@ ApInitializeSync (
CpuMpData = (CPU_MP_DATA *)Buffer;
Status = GetProcessorNumber (CpuMpData, &ProcessorNumber);
ASSERT_EFI_ERROR (Status);
+ ASSERT (CpuMpData->InitFlag == ApInitReconfig || CpuMpData->InitFlag == ApInitDone);
+ if (CpuMpData->InitFlag != ApInitReconfig) {
+ //
+ // Load microcode on AP for PEI phase.
+ // During the DXE phase, it cannot omitted.
+ //
+ MicrocodeDetect (CpuMpData, ProcessorNumber);
+ }
+
//
- // Load microcode on AP
- //
- MicrocodeDetect (CpuMpData, ProcessorNumber);
- //
- // Sync BSP's MTRR table to AP
+ // Synchronizing the MTRR table to the AP is always essential.
+ // During the DXE phase, it cannot be omitted like loading microcode,
+ // as the PEI and DXE may be in different bit modes.
//
MtrrSetAllMtrrs (&CpuMpData->MtrrTable);
}
@@ -2224,29 +2231,25 @@ MpInitLibInitialize (
}
}
- if (!GetMicrocodePatchInfoFromHob (
- &CpuMpData->MicrocodePatchAddress,
- &CpuMpData->MicrocodePatchRegionSize
- ))
- {
+ if (MpHandOff == NULL) {
//
// The microcode patch information cache HOB does not exist, which means
// the microcode patches data has not been loaded into memory yet
//
ShadowMicrocodeUpdatePatch (CpuMpData);
+ //
+ // Detect and apply Microcode on BSP
+ //
+ MicrocodeDetect (CpuMpData, CpuMpData->BspNumber);
}
- //
- // Detect and apply Microcode on BSP
- //
- MicrocodeDetect (CpuMpData, CpuMpData->BspNumber);
//
// Store BSP's MTRR setting
//
MtrrGetAllMtrrs (&CpuMpData->MtrrTable);
//
- // Wakeup APs to do some AP initialize sync (Microcode & MTRR)
+ // Wakeup APs to do some AP initialize sync (MTRR and/or Microcode).
//
if (CpuMpData->CpuCount > 1) {
if (MpHandOff != NULL) {
@@ -2258,6 +2261,11 @@ MpInitLibInitialize (
CpuMpData->InitFlag = ApInitReconfig;
}
+ //
+ // Wake up the AP to perform some AP initialization synchronization.
+ // 1. For PEI stage, load microcode and synchronize MTRR,
+ // 2. For the DXE phase, only synchronize MTRR.
+ //
WakeUpAP (CpuMpData, TRUE, 0, ApInitializeSync, CpuMpData, TRUE);
//
// Wait for all APs finished initialization
--
2.39.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111595): https://edk2.groups.io/g/devel/message/111595
Mute This Topic: https://groups.io/mt/102744598/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
> - MicrocodeDetect (CpuMpData, ProcessorNumber); > - // > - // Sync BSP's MTRR table to AP > + // Synchronizing the MTRR table to the AP is always essential. > + // During the DXE phase, it cannot be omitted like loading microcode, > + // as the PEI and DXE may be in different bit modes. "as the PEI and DXE may be in different bit modes" is not the reason that MTRR sync needs to be performed in DXE phase. The reason is some code might change MTRR on BSP only after CpuMp PPI service is not available and before CpuMp Protocol is available. That is in early DXE phase before CpuMp protocol is installed. > // > MtrrSetAllMtrrs (&CpuMpData->MtrrTable); > } -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111634): https://edk2.groups.io/g/devel/message/111634 Mute This Topic: https://groups.io/mt/102744598/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076/xyzzy [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
>
> - if (!GetMicrocodePatchInfoFromHob (
> - &CpuMpData->MicrocodePatchAddress,
> - &CpuMpData->MicrocodePatchRegionSize
> - ))
> - {
Can you delete the GetMicrocodePathInfoFromHob() in this patch instead of the 3rd patch?
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111635): https://edk2.groups.io/g/devel/message/111635
Mute This Topic: https://groups.io/mt/102744598/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076/xyzzy [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Hi Ray,
In V4, the GetMicrocodePathInfoFromHob() removal is in patch 1 instead of the patch 3.
Comments of MTRRs syncing is a updated.
Thanks
Yuanhao
-----Original Message-----
From: Ni, Ray <ray.ni@intel.com>
Sent: Thursday, November 23, 2023 9:18 AM
To: Xie, Yuanhao <yuanhao.xie@intel.com>; devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@intel.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>; Tom Lendacky <thomas.lendacky@amd.com>; Laszlo Ersek <lersek@redhat.com>
Subject: RE: [Patch V3 1/3] UefiCpuPkg/MpInitLib: Eliminate redundant microcode loading in DXE.
> - MicrocodeDetect (CpuMpData, ProcessorNumber);
> - //
> - // Sync BSP's MTRR table to AP
> + // Synchronizing the MTRR table to the AP is always essential.
> + // During the DXE phase, it cannot be omitted like loading
> + microcode, // as the PEI and DXE may be in different bit modes.
"as the PEI and DXE may be in different bit modes" is not the reason that MTRR sync needs to be performed in DXE phase.
The reason is some code might change MTRR on BSP only after CpuMp PPI service is not available and before CpuMp Protocol is available.
That is in early DXE phase before CpuMp protocol is installed.
> //
> MtrrSetAllMtrrs (&CpuMpData->MtrrTable); }
-----Original Message-----
From: Ni, Ray <ray.ni@intel.com>
Sent: Thursday, November 23, 2023 9:19 AM
To: Xie, Yuanhao <yuanhao.xie@intel.com>; devel@edk2.groups.io
Cc: Dong, Eric <eric.dong@intel.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>; Tom Lendacky <thomas.lendacky@amd.com>; Laszlo Ersek <lersek@redhat.com>
Subject: RE: [Patch V3 1/3] UefiCpuPkg/MpInitLib: Eliminate redundant microcode loading in DXE.
>
> - if (!GetMicrocodePatchInfoFromHob (
> - &CpuMpData->MicrocodePatchAddress,
> - &CpuMpData->MicrocodePatchRegionSize
> - ))
> - {
Can you delete the GetMicrocodePathInfoFromHob() in this patch instead of the 3rd patch?
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111692): https://edk2.groups.io/g/devel/message/111692
Mute This Topic: https://groups.io/mt/102744598/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2026 Red Hat, Inc.