Skip to content

Commit

Permalink
UefiCpuPkg/PiSmmCpuDxeSmm: Clarification for BSP & APs Sync Flow
Browse files Browse the repository at this point in the history
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 tianocore#6 and tianocore#11 are the basic synchronization requirements for all
cases.

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

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

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

Signed-off-by: Jiaxin Wu <[email protected]>
  • Loading branch information
jiaxinwu authored and mergify[bot] committed Oct 12, 2024
1 parent d2a41d1 commit 2351165
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,13 @@ BSPHandler (
//
// 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 ()) {
//
// 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
Expand All @@ -543,12 +543,12 @@ BSPHandler (
//
// 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
//
ReleaseAllAPs ();
ReleaseAllAPs (); /// #4: Signal APs

//
// SmmCpuSyncWaitForAPs() may wait for ever if an AP happens to enter SMM at
Expand All @@ -560,7 +560,7 @@ BSPHandler (
//
// Wait for all APs to complete their MTRR programming
//
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex); /// #5: Wait APs
}
}

Expand Down Expand Up @@ -625,18 +625,18 @@ BSPHandler (
// Notify all APs to exit
//
*mSmmMpSyncData->InsideSmm = FALSE;
ReleaseAllAPs ();
ReleaseAllAPs (); /// #6: Signal APs

if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
//
// 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
//
ReleaseAllAPs ();
ReleaseAllAPs (); /// #8: Signal APs

//
// Restore OS MTRRs
Expand All @@ -649,12 +649,12 @@ BSPHandler (
//
// 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
//
ReleaseAllAPs ();
ReleaseAllAPs (); /// #10: Signal APs
}

if (mSmmDebugAgentSupport) {
Expand All @@ -679,7 +679,7 @@ BSPHandler (
// Gather APs to exit SMM synchronously. Note the Present flag is cleared by now but
// 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().
Expand Down Expand Up @@ -805,14 +805,14 @@ APHandler (
//
// Notify BSP of arrival at this point
//
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #1: Signal BSP
}

if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
//
// 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
Expand All @@ -822,12 +822,12 @@ APHandler (
//
// 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
//
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #4: Wait BSP

//
// Replace OS MTRRs with SMI MTRRs
Expand All @@ -837,14 +837,14 @@ APHandler (
//
// Signal BSP the completion of this AP
//
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #5: Signal BSP
}

while (TRUE) {
//
// 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
Expand Down Expand Up @@ -884,12 +884,12 @@ APHandler (
//
// 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
//
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #8: Wait BSP

//
// Restore OS MTRRs
Expand All @@ -902,12 +902,12 @@ APHandler (
//
// 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
//
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #10: Wait BSP
}

//
Expand All @@ -918,7 +918,7 @@ APHandler (
//
// Notify BSP the readiness of this AP to exit SMM
//
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex); /// #11: Signal BSP
}

/**
Expand Down

0 comments on commit 2351165

Please sign in to comment.