[edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: SmmCpuRendezvous ensure all Aps in Present.

Yuanhao Xie posted 1 patch 5 months, 3 weeks ago
Failed in applying to current master (apply log)
There is a newer version of this series
UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c     | 25 ++++++++++++++++++++++
UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 13 +++++++++++
2 files changed, 38 insertions(+)
[edk2-devel] [PATCH] UefiCpuPkg/PiSmmCpuDxeSmm: SmmCpuRendezvous ensure all Aps in Present.
Posted by Yuanhao Xie 5 months, 3 weeks ago
From: YuanhaoXie <yuanhao.xie@intel.com>

SmmCpuRendezvous has a issue in that it summons all APs
into SMM, but there is a time gap before they are set as "present."
During this window, if using the "setVariable" operation,
it can cause issues since "setVariable" requires all APs to be in SMM
and marked as "present."

Therefore, this patch adds extra logic to
"SmmCpuRendezvous" to check if the APs are already "present" before
proceeding.

Signed-off-by: Zhihao Li <zhihao.li@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
---
 UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c     | 25 ++++++++++++++++++++++
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 13 +++++++++++
 2 files changed, 38 insertions(+)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c
index 391b64e9f2..cdc7021ee9 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c
@@ -406,8 +406,15 @@ SmmCpuRendezvous (
   IN BOOLEAN                            BlockingMode
   )
 {
+  UINTN       Index;
+  UINTN       PresentCount;
+  UINT32      BlockedCount;
+  UINT32      DisabledCount;
   EFI_STATUS  Status;
 
+  BlockedCount  = 0;
+  DisabledCount = 0;
+
   //
   // Return success immediately if all CPUs are already synchronized.
   //
@@ -426,6 +433,24 @@ SmmCpuRendezvous (
     // There are some APs outside SMM, Wait for all avaiable APs to arrive.
     //
     SmmWaitForApArrival ();
+
+    //
+    // Make sure all APs have their Present flag set
+    //
+    while (TRUE) {
+      PresentCount = 0;
+      for (Index = 0; Index < mMaxNumberOfCpus; Index++) {
+        if (*(mSmmMpSyncData->CpuData[Index].Present)) {
+          PresentCount++;
+        }
+      }
+
+      GetSmmDelayedBlockedDisabledCount (NULL, &BlockedCount, &DisabledCount);
+      if (PresentCount == mMaxNumberOfCpus - BlockedCount - DisabledCount ) {
+        break;
+      }
+    }
+
     Status = mSmmMpSyncData->AllApArrivedWithException ? EFI_SUCCESS : EFI_TIMEOUT;
   } else {
     //
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
index 654935dc76..0a227d86b2 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
@@ -1552,6 +1552,19 @@ SmmWaitForApArrival (
   VOID
   );
 
+/**
+  Returns the Number of SMM Delayed & Blocked & Disabled Thread Count.
+  @param[in,out] DelayedCount  The Number of SMM Delayed Thread Count.
+  @param[in,out] BlockedCount  The Number of SMM Blocked Thread Count.
+  @param[in,out] DisabledCount The Number of SMM Disabled Thread Count.
+**/
+VOID
+GetSmmDelayedBlockedDisabledCount (
+  IN OUT UINT32  *DelayedCount,
+  IN OUT UINT32  *BlockedCount,
+  IN OUT UINT32  *DisabledCount
+  );
+
 /**
   Disable Write Protect on pages marked as read-only if Cr0.Bits.WP is 1.
 
-- 
2.39.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#110965): https://edk2.groups.io/g/devel/message/110965
Mute This Topic: https://groups.io/mt/102482983/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-