[edk2-devel] [PATCH v2 06/10] UefiCpuPkg/PiSmmCpuDxeSmm: initialize IsBsp

Ankur Arora ankur.a.arora at oracle.com
Thu Jan 7 19:55:11 UTC 2021


Initialize IsBsp early to ensure that this variable reflects the BSP
status correctly.

Also replace this check:
  if (mSmmMpSyncData->BspIndex == (UINT32)CpuIndex)

with:
  if (IsBsp)

Note that there's a window of time when these two diverge, when the BSP,
at exit from BSPHandler(), resets mSmmMpSyncData->BspIndex.

Cc: Eric Dong <eric.dong at intel.com>
Cc: Ray Ni <ray.ni at intel.com>
Cc: Laszlo Ersek <lersek at redhat.com>
Cc: Rahul Kumar <rahul1.kumar at intel.com>
Cc: Igor Mammedov <imammedo at redhat.com>
Cc: Boris Ostrovsky <boris.ostrovsky at oracle.com>
Cc: Aaron Young <aaron.young at oracle.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3132
Signed-off-by: Ankur Arora <ankur.a.arora at oracle.com>
---
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index 4bcd217917d7..e7ea44eb86fc 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -1565,7 +1565,12 @@ SmiRendezvous (
 {
   EFI_STATUS                     Status;
   BOOLEAN                        ValidSmi;
-  BOOLEAN                        IsBsp;
+
+  //
+  // IsBsp starts out as false. Once a CPU gets elected as BSP,
+  // it will transition its value to true.
+  //
+  BOOLEAN                        IsBsp = FALSE;
   BOOLEAN                        BspInProgress;
   UINTN                          Index;
   UINTN                          Cr2;
@@ -1656,7 +1661,6 @@ SmiRendezvous (
       //
       // Elect BSP
       //
-      IsBsp = FALSE;
       if (FeaturePcdGet (PcdCpuSmmEnableBspElection)) {
         if (!mSmmMpSyncData->SwitchBsp || mSmmMpSyncData->CandidateBsp[CpuIndex]) {
           //
@@ -1679,6 +1683,8 @@ SmiRendezvous (
               (UINT32)-1,
               (UINT32)CpuIndex
               );
+
+            IsBsp = mSmmMpSyncData->BspIndex == (UINT32)CpuIndex;
           }
         }
       }
@@ -1686,7 +1692,7 @@ SmiRendezvous (
       //
       // "mSmmMpSyncData->BspIndex == CpuIndex" means this is the BSP
       //
-      if (mSmmMpSyncData->BspIndex == CpuIndex) {
+      if (IsBsp) {
 
         //
         // Clear last request for SwitchBsp.
-- 
2.9.3



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#69973): https://edk2.groups.io/g/devel/message/69973
Mute This Topic: https://groups.io/mt/79507540/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-






More information about the edk2-devel-archive mailing list