Below piece of code is the BSP and AP sync logic for SMI exit.
1. AP after finish the scheduled procedure:
if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
SmmCpuSyncReleaseBsp ();
SmmCpuSyncWaitForBsp ();
...
}
SmmCpuSyncReleaseBsp ();
SmmCpuSyncWaitForBsp ();
SmmCpuSyncReleaseBsp ();
2. BSP after return from SmmCoreEntry:
SmmCpuSyncWaitForAPs ();
if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
ReleaseAllAPs ();
...
SmmCpuSyncWaitForAPs ();
}
ReleaseAllAPs ();
SmmCpuSyncWaitForAPs();
This patch is to make BSP same as AP sync logic:
if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
SmmCpuSyncWaitForAPs ();
ReleaseAllAPs ();
...
}
SmmCpuSyncWaitForAPs ();
ReleaseAllAPs ();
SmmCpuSyncWaitForAPs();
With the change, it will be easy to understand the sync flow as
below:
BSP: SmmCpuSyncWaitForAPs <-- AP: SmmCpuSyncReleaseBsp
BSP: ReleaseAllAPs --> AP: SmmCpuSyncWaitForBsp
This patch doesn't have function impact.
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Zeng Star <star.zeng@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
---
UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index 324e85d6b5..bd2c9f841b 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -625,33 +625,33 @@ BSPHandler (
// Notify all APs to exit
//
*mSmmMpSyncData->InsideSmm = FALSE;
ReleaseAllAPs ();
- //
- // Wait for all APs to complete their pending tasks
- //
- SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
-
if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
+ //
+ // Wait for all APs the readiness to program MTRRs
+ //
+ SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
+
//
// Signal APs to restore MTRRs
//
ReleaseAllAPs ();
//
// Restore OS MTRRs
//
SmmCpuFeaturesReenableSmrr ();
MtrrSetAllMtrrs (&Mtrrs);
-
- //
- // Wait for all APs to complete MTRR programming
- //
- SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
}
+ //
+ // Wait for all APs to complete their pending tasks including MTRR programming if needed.
+ //
+ SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
+
if (mSmmDebugAgentSupport) {
//
// Stop source level debug in BSP handler, the code below will not be
// debugged.
//
--
2.16.2.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112889): https://edk2.groups.io/g/devel/message/112889
Mute This Topic: https://groups.io/mt/103360805/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Reviewed-by: Ray Ni <ray.ni@Intel.com>
Thanks,
Ray
> -----Original Message-----
> From: Wu, Jiaxin <jiaxin.wu@intel.com>
> Sent: Tuesday, December 26, 2023 12:21 AM
> To: devel@edk2.groups.io
> Cc: Laszlo Ersek <lersek@redhat.com>; Dong, Eric <eric.dong@intel.com>; Ni,
> Ray <ray.ni@intel.com>; Zeng, Star <star.zeng@intel.com>; Gerd Hoffmann
> <kraxel@redhat.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>
> Subject: [PATCH v2 4/6] UefiCpuPkg/PiSmmCpuDxeSmm: Align BSP and AP
> sync logic for SMI exit
>
> Below piece of code is the BSP and AP sync logic for SMI exit.
> 1. AP after finish the scheduled procedure:
> if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
> SmmCpuSyncReleaseBsp ();
> SmmCpuSyncWaitForBsp ();
> ...
> }
> SmmCpuSyncReleaseBsp ();
> SmmCpuSyncWaitForBsp ();
> SmmCpuSyncReleaseBsp ();
>
> 2. BSP after return from SmmCoreEntry:
> SmmCpuSyncWaitForAPs ();
> if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
> ReleaseAllAPs ();
> ...
> SmmCpuSyncWaitForAPs ();
> }
> ReleaseAllAPs ();
> SmmCpuSyncWaitForAPs();
>
> This patch is to make BSP same as AP sync logic:
> if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
> SmmCpuSyncWaitForAPs ();
> ReleaseAllAPs ();
> ...
> }
> SmmCpuSyncWaitForAPs ();
> ReleaseAllAPs ();
> SmmCpuSyncWaitForAPs();
>
> With the change, it will be easy to understand the sync flow as
> below:
> BSP: SmmCpuSyncWaitForAPs <-- AP: SmmCpuSyncReleaseBsp
> BSP: ReleaseAllAPs --> AP: SmmCpuSyncWaitForBsp
>
> This patch doesn't have function impact.
>
> Cc: Laszlo Ersek <lersek@redhat.com>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Zeng Star <star.zeng@intel.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Rahul Kumar <rahul1.kumar@intel.com>
> Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
> ---
> UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 20 ++++++++++----------
> 1 file changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
> b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
> index 324e85d6b5..bd2c9f841b 100644
> --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
> +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
> @@ -625,33 +625,33 @@ BSPHandler (
> // Notify all APs to exit
> //
> *mSmmMpSyncData->InsideSmm = FALSE;
> ReleaseAllAPs ();
>
> - //
> - // Wait for all APs to complete their pending tasks
> - //
> - SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount,
> CpuIndex);
> -
> if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
> + //
> + // Wait for all APs the readiness to program MTRRs
> + //
> + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount,
> CpuIndex);
> +
> //
> // Signal APs to restore MTRRs
> //
> ReleaseAllAPs ();
>
> //
> // Restore OS MTRRs
> //
> SmmCpuFeaturesReenableSmrr ();
> MtrrSetAllMtrrs (&Mtrrs);
> -
> - //
> - // Wait for all APs to complete MTRR programming
> - //
> - SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount,
> CpuIndex);
> }
>
> + //
> + // Wait for all APs to complete their pending tasks including MTRR
> programming if needed.
> + //
> + SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount,
> CpuIndex);
> +
> if (mSmmDebugAgentSupport) {
> //
> // Stop source level debug in BSP handler, the code below will not be
> // debugged.
> //
> --
> 2.16.2.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112902): https://edk2.groups.io/g/devel/message/112902
Mute This Topic: https://groups.io/mt/103360805/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076/xyzzy [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2026 Red Hat, Inc.