UefiCpuPkg/PiSmmCpuDxeSmm: Clarification for BSP & APs Sync Flow

This patch does not impact functionality. It aims to clarify the
synchronization flow between the BSP and APs to enhance code
readability and understanding:

Steps #6 and #11 are the basic synchronization requirements for all
cases.

Steps #1 is additional requirements if the MmCpuSyncModeTradition
mode is selected.

Steps #1, #2, #3, #4, #5, #7, #8, #9, and #10 are additional
requirements if the system needs to configure the MTRR.

Steps #9 and #10 are additional requirements if the system needs to
support the mSmmDebugAgentSupport.

Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
This commit is contained in:
Jiaxin Wu 2024-10-12 11:03:50 +08:00 committed by mergify[bot]
parent d2a41d1a7a
commit 2351165f1b

View File

@ -522,13 +522,13 @@ BSPHandler (
// //
// Wait for all APs to get ready for programming MTRRs // Wait for all APs to get ready for programming MTRRs
// //
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #1: Wait APs
if (SmmCpuFeaturesNeedConfigureMtrrs ()) { if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
// //
// Signal all APs it's time for backup MTRRs // Signal all APs it's time for backup MTRRs
// //
ReleaseAllAPs (); ReleaseAllAPs (); /// #2: Signal APs
// //
// SmmCpuSyncWaitForAPs() may wait for ever if an AP happens to enter SMM at // SmmCpuSyncWaitForAPs() may wait for ever if an AP happens to enter SMM at
@ -543,12 +543,12 @@ BSPHandler (
// //
// Wait for all APs to complete their MTRR saving // Wait for all APs to complete their MTRR saving
// //
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #3: Wait APs
// //
// Let all processors program SMM MTRRs together // Let all processors program SMM MTRRs together
// //
ReleaseAllAPs (); ReleaseAllAPs (); /// #4: Signal APs
// //
// SmmCpuSyncWaitForAPs() may wait for ever if an AP happens to enter SMM at // SmmCpuSyncWaitForAPs() may wait for ever if an AP happens to enter SMM at
@ -560,7 +560,7 @@ BSPHandler (
// //
// Wait for all APs to complete their MTRR programming // Wait for all APs to complete their MTRR programming
// //
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #5: Wait APs
} }
} }
@ -625,18 +625,18 @@ BSPHandler (
// Notify all APs to exit // Notify all APs to exit
// //
*mSmmMpSyncData->InsideSmm = FALSE; *mSmmMpSyncData->InsideSmm = FALSE;
ReleaseAllAPs (); ReleaseAllAPs (); /// #6: Signal APs
if (SmmCpuFeaturesNeedConfigureMtrrs ()) { if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
// //
// Wait for all APs the readiness to program MTRRs // Wait for all APs the readiness to program MTRRs
// //
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #7: Wait APs
// //
// Signal APs to restore MTRRs // Signal APs to restore MTRRs
// //
ReleaseAllAPs (); ReleaseAllAPs (); /// #8: Signal APs
// //
// Restore OS MTRRs // Restore OS MTRRs
@ -649,12 +649,12 @@ BSPHandler (
// //
// Wait for all APs to complete their pending tasks including MTRR programming if needed. // Wait for all APs to complete their pending tasks including MTRR programming if needed.
// //
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #9: Wait APs
// //
// Signal APs to Reset states/semaphore for this processor // Signal APs to Reset states/semaphore for this processor
// //
ReleaseAllAPs (); ReleaseAllAPs (); /// #10: Signal APs
} }
if (mSmmDebugAgentSupport) { if (mSmmDebugAgentSupport) {
@ -679,7 +679,7 @@ BSPHandler (
// Gather APs to exit SMM synchronously. Note the Present flag is cleared by now but // Gather APs to exit SMM synchronously. Note the Present flag is cleared by now but
// WaitForAllAps does not depend on the Present flag. // WaitForAllAps does not depend on the Present flag.
// //
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #11: Wait APs
// //
// At this point, all APs should have exited from APHandler(). // At this point, all APs should have exited from APHandler().
@ -805,14 +805,14 @@ APHandler (
// //
// Notify BSP of arrival at this point // Notify BSP of arrival at this point
// //
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #1: Signal BSP
} }
if (SmmCpuFeaturesNeedConfigureMtrrs ()) { if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
// //
// Wait for the signal from BSP to backup MTRRs // Wait for the signal from BSP to backup MTRRs
// //
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #2: Wait BSP
// //
// Backup OS MTRRs // Backup OS MTRRs
@ -822,12 +822,12 @@ APHandler (
// //
// Signal BSP the completion of this AP // Signal BSP the completion of this AP
// //
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #3: Signal BSP
// //
// Wait for BSP's signal to program MTRRs // Wait for BSP's signal to program MTRRs
// //
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #4: Wait BSP
// //
// Replace OS MTRRs with SMI MTRRs // Replace OS MTRRs with SMI MTRRs
@ -837,14 +837,14 @@ APHandler (
// //
// Signal BSP the completion of this AP // Signal BSP the completion of this AP
// //
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #5: Signal BSP
} }
while (TRUE) { while (TRUE) {
// //
// Wait for something to happen // Wait for something to happen
// //
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #6: Wait BSP
// //
// Check if BSP wants to exit SMM // Check if BSP wants to exit SMM
@ -884,12 +884,12 @@ APHandler (
// //
// Notify BSP the readiness of this AP to program MTRRs // Notify BSP the readiness of this AP to program MTRRs
// //
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #7: Signal BSP
// //
// Wait for the signal from BSP to program MTRRs // Wait for the signal from BSP to program MTRRs
// //
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #8: Wait BSP
// //
// Restore OS MTRRs // Restore OS MTRRs
@ -902,12 +902,12 @@ APHandler (
// //
// Notify BSP the readiness of this AP to Reset states/semaphore for this processor // Notify BSP the readiness of this AP to Reset states/semaphore for this processor
// //
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #9: Signal BSP
// //
// Wait for the signal from BSP to Reset states/semaphore for this processor // Wait for the signal from BSP to Reset states/semaphore for this processor
// //
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #10: Wait BSP
} }
// //
@ -918,7 +918,7 @@ APHandler (
// //
// Notify BSP the readiness of this AP to exit SMM // Notify BSP the readiness of this AP to exit SMM
// //
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #11: Signal BSP
} }
/** /**