public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH v1 0/6] Reduce one round BSP & AP sync
@ 2023-12-21  2:21 Wu, Jiaxin
  2023-12-21  2:21 ` [edk2-devel] [PATCH v1 1/6] SourceLevelDebugPkg/Library: Indicate SMM Debug Agent support or not Wu, Jiaxin
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Wu, Jiaxin @ 2023-12-21  2:21 UTC (permalink / raw)
  To: devel

Jiaxin Wu (6):
  SourceLevelDebugPkg/Library: Indicate SMM Debug Agent support or not
  MdeModulePkg/DebugAgentLibNull: Indicate SMM Debug Agent support or
    not
  UefiCpuPkg/PiSmmCpuDxeSmm: Check SMM Debug Agent support or not
  UefiCpuPkg/PiSmmCpuDxeSmm: Align MTRR sync logic between BSP and AP
  UefiCpuPkg/PiSmmCpuDxeSmm: Invert ReleaseAllAPs & InitializeDebugAgent
  UefiCpuPkg/PiSmmCpuDxeSmm: Reduce one round BSP & AP sync

 .../Library/DebugAgentLibNull/DebugAgentLibNull.c  |  9 +++
 .../DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c    | 14 +++--
 UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c                  |  4 +-
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c              | 64 ++++++++++++----------
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c         | 14 ++++-
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h         |  1 +
 6 files changed, 72 insertions(+), 34 deletions(-)

-- 
2.16.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112791): https://edk2.groups.io/g/devel/message/112791
Mute This Topic: https://groups.io/mt/103293797/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [edk2-devel] [PATCH v1 1/6] SourceLevelDebugPkg/Library: Indicate SMM Debug Agent support or not
  2023-12-21  2:21 [edk2-devel] [PATCH v1 0/6] Reduce one round BSP & AP sync Wu, Jiaxin
@ 2023-12-21  2:21 ` Wu, Jiaxin
  2023-12-21  2:21 ` [edk2-devel] [PATCH v1 2/6] MdeModulePkg/DebugAgentLibNull: " Wu, Jiaxin
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Wu, Jiaxin @ 2023-12-21  2:21 UTC (permalink / raw)
  To: devel; +Cc: Ray Ni

This patch use the Context to indicate SMM Debug Agent support or
not if InitFlag is DEBUG_AGENT_INIT_SMM. Context must be the pointer
to the BOOLEAN value if it's not NULL.

Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
---
 .../Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c    | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c b/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
index f49a592d27..1648c2b33e 100644
--- a/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
+++ b/SourceLevelDebugPkg/Library/DebugAgent/SmmDebugAgent/SmmDebugAgentLib.c
@@ -157,12 +157,13 @@ RestoreDebugRegister (
   in SMM code.
 
   If InitFlag is DEBUG_AGENT_INIT_SMM, it will override IDT table entries
   and initialize debug port. It will get debug agent Mailbox from GUIDed HOB,
   it it exists, debug agent wiil copied it into the local Mailbox in SMM space.
-  it will override IDT table entries and initialize debug port. Context will be
-  NULL.
+  it will override IDT table entries and initialize debug port. Context must be
+  the pointer to the BOOLEAN value if it's not NULL, which indicates SMM Debug
+  Agent supported or not.
   If InitFlag is DEBUG_AGENT_INIT_ENTER_SMI, debug agent will save Debug
   Registers and get local Mailbox in SMM space. Context will be NULL.
   If InitFlag is DEBUG_AGENT_INIT_EXIT_SMI, debug agent will restore Debug
   Registers. Context will be NULL.
 
@@ -203,29 +204,32 @@ InitializeDebugAgent (
                         (VOID *)&mVectorHandoffInfoDebugAgent[0],
                         sizeof (EFI_VECTOR_HANDOFF_INFO) * mVectorHandoffInfoCount
                         );
       if (EFI_ERROR (Status)) {
         DEBUG ((DEBUG_ERROR, "DebugAgent: Cannot install configuration table for persisted vector handoff info!\n"));
+        *(BOOLEAN *)Context = FALSE;
         CpuDeadLoop ();
       }
 
       //
       // Check if Debug Agent initialized in DXE phase
       //
       Status = EfiGetSystemConfigurationTable (&gEfiDebugAgentGuid, (VOID **)&Mailbox);
       if ((Status == EFI_SUCCESS) && (Mailbox != NULL)) {
         VerifyMailboxChecksum (Mailbox);
-        mMailboxPointer = Mailbox;
+        mMailboxPointer     = Mailbox;
+        *(BOOLEAN *)Context = TRUE;
         break;
       }
 
       //
       // Check if Debug Agent initialized in SEC/PEI phase
       //
       Mailbox = GetMailboxFromHob ();
       if (Mailbox != NULL) {
-        mMailboxPointer = Mailbox;
+        mMailboxPointer     = Mailbox;
+        *(BOOLEAN *)Context = TRUE;
         break;
       }
 
       //
       // Debug Agent was not initialized before, use the local mailbox.
@@ -273,10 +277,12 @@ InitializeDebugAgent (
       //
       // Restore saved IDT entries
       //
       CopyMem ((VOID *)IdtDescriptor.Base, &IdtEntry, 33 * sizeof (IA32_IDT_GATE_DESCRIPTOR));
 
+      *(BOOLEAN *)Context = TRUE;
+
       break;
 
     case DEBUG_AGENT_INIT_ENTER_SMI:
       SaveDebugRegister ();
       if (!mSmmDebugIdtInitFlag) {
-- 
2.16.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112792): https://edk2.groups.io/g/devel/message/112792
Mute This Topic: https://groups.io/mt/103293798/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [edk2-devel] [PATCH v1 2/6] MdeModulePkg/DebugAgentLibNull: Indicate SMM Debug Agent support or not
  2023-12-21  2:21 [edk2-devel] [PATCH v1 0/6] Reduce one round BSP & AP sync Wu, Jiaxin
  2023-12-21  2:21 ` [edk2-devel] [PATCH v1 1/6] SourceLevelDebugPkg/Library: Indicate SMM Debug Agent support or not Wu, Jiaxin
@ 2023-12-21  2:21 ` Wu, Jiaxin
  2023-12-21  2:21 ` [edk2-devel] [PATCH v1 3/6] UefiCpuPkg/PiSmmCpuDxeSmm: Check " Wu, Jiaxin
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Wu, Jiaxin @ 2023-12-21  2:21 UTC (permalink / raw)
  To: devel; +Cc: Ray Ni, Liming Gao

This patch use the Context to indicate SMM Debug Agent support or
not if InitFlag is DEBUG_AGENT_INIT_SMM. Context must be the pointer
to the BOOLEAN value if it's not NULL.

Cc: Ray Ni <ray.ni@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Jiaxin Wu <jiaxin.wu@intel.com>
---
 MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.c b/MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.c
index 8e70705eb6..a7f4945c03 100644
--- a/MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.c
+++ b/MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.c
@@ -22,10 +22,13 @@
   passing in the Context to be its parameter.
 
   If Function() is NULL, Debug Agent Library instance will return after setup debug
   environment.
 
+  If InitFlag is DEBUG_AGENT_INIT_SMM, Context must be the pointer to the BOOLEAN
+  value if it's not NULL, which indicates SMM Debug Agent supported or not.
+
   @param[in] InitFlag     Init flag is used to decide the initialize process.
   @param[in] Context      Context needed according to InitFlag; it was optional.
   @param[in] Function     Continue function called by debug agent library; it was
                           optional.
 
@@ -36,10 +39,16 @@ InitializeDebugAgent (
   IN UINT32                InitFlag,
   IN VOID                  *Context  OPTIONAL,
   IN DEBUG_AGENT_CONTINUE  Function  OPTIONAL
   )
 {
+  switch (InitFlag) {
+    case DEBUG_AGENT_INIT_SMM:
+      *(BOOLEAN *)Context = FALSE;
+      return;
+  }
+
   if (Function != NULL) {
     Function (Context);
   }
 }
 
-- 
2.16.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112793): https://edk2.groups.io/g/devel/message/112793
Mute This Topic: https://groups.io/mt/103293799/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [edk2-devel] [PATCH v1 3/6] UefiCpuPkg/PiSmmCpuDxeSmm: Check SMM Debug Agent support or not
  2023-12-21  2:21 [edk2-devel] [PATCH v1 0/6] Reduce one round BSP & AP sync Wu, Jiaxin
  2023-12-21  2:21 ` [edk2-devel] [PATCH v1 1/6] SourceLevelDebugPkg/Library: Indicate SMM Debug Agent support or not Wu, Jiaxin
  2023-12-21  2:21 ` [edk2-devel] [PATCH v1 2/6] MdeModulePkg/DebugAgentLibNull: " Wu, Jiaxin
@ 2023-12-21  2:21 ` Wu, Jiaxin
  2023-12-21  2:21 ` [edk2-devel] [PATCH v1 4/6] UefiCpuPkg/PiSmmCpuDxeSmm: Align MTRR sync logic between BSP and AP Wu, Jiaxin
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Wu, Jiaxin @ 2023-12-21  2:21 UTC (permalink / raw)
  To: devel
  Cc: Laszlo Ersek, Eric Dong, Ray Ni, Zeng Star, Gerd Hoffmann,
	Rahul Kumar

This patch is to check SMM Debug Agent support or not before
InitializeDebugAgent.

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/CpuS3.c          |  4 +++-
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c      | 22 +++++++++++++---------
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 14 +++++++++++++-
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h |  1 +
 4 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
index 0bae0e33f1..13b5a302ee 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
@@ -835,11 +835,13 @@ SmmRestoreCpu (
     ASSERT_EFI_ERROR (Status);
 
     //
     // Initialize Debug Agent to support source level debug
     //
-    InitializeDebugAgent (DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64, (VOID *)&Ia32Idtr, NULL);
+    if (*mSmmDebugAgentSupport) {
+      InitializeDebugAgent (DEBUG_AGENT_INIT_THUNK_PEI_IA32TOX64, (VOID *)&Ia32Idtr, NULL);
+    }
   }
 
   mBspApicId = GetApicId ();
   //
   // Skip AP initialization if mAcpiCpuData is not valid
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index 4fbb0bba87..408ee8a87d 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -474,14 +474,16 @@ BSPHandler (
   //
   // Flag BSP's presence
   //
   *mSmmMpSyncData->InsideSmm = TRUE;
 
-  //
-  // Initialize Debug Agent to start source level debug in BSP handler
-  //
-  InitializeDebugAgent (DEBUG_AGENT_INIT_ENTER_SMI, NULL, NULL);
+  if (*mSmmDebugAgentSupport) {
+    //
+    // Initialize Debug Agent to start source level debug in BSP handler
+    //
+    InitializeDebugAgent (DEBUG_AGENT_INIT_ENTER_SMI, NULL, NULL);
+  }
 
   //
   // Mark this processor's presence
   //
   *(mSmmMpSyncData->CpuData[CpuIndex].Present) = TRUE;
@@ -646,15 +648,17 @@ BSPHandler (
     // Wait for all APs to complete MTRR programming
     //
     SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
   }
 
-  //
-  // Stop source level debug in BSP handler, the code below will not be
-  // debugged.
-  //
-  InitializeDebugAgent (DEBUG_AGENT_INIT_EXIT_SMI, NULL, NULL);
+  if (*mSmmDebugAgentSupport) {
+    //
+    // Stop source level debug in BSP handler, the code below will not be
+    // debugged.
+    //
+    InitializeDebugAgent (DEBUG_AGENT_INIT_EXIT_SMI, NULL, NULL);
+  }
 
   //
   // Signal APs to Reset states/semaphore for this processor
   //
   ReleaseAllAPs ();
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
index 209a2e4810..006aa038bb 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c
@@ -110,10 +110,15 @@ BOOLEAN  mSmmReadyToLock = FALSE;
 //
 // Global used to cache PCD for SMM Code Access Check enable
 //
 BOOLEAN  mSmmCodeAccessCheckEnable = FALSE;
 
+//
+// Global used to cache SMM Debug Agent Supported ot not
+//
+BOOLEAN  *mSmmDebugAgentSupport = NULL;
+
 //
 // Global copy of the PcdPteMemoryEncryptionAddressOrMask
 //
 UINT64  mAddressEncMask = 0;
 
@@ -894,12 +899,19 @@ PiCpuSmmEntry (
   PiSmmCpuSmmInitFixupAddress ();
   PiSmmCpuSmiEntryFixupAddress ();
 
   //
   // Initialize Debug Agent to support source level debug in SMM code
+  // Allocate the memory for SMM Debug Agent Support check, and to make sure it
+  // survives from S3.
   //
-  InitializeDebugAgent (DEBUG_AGENT_INIT_SMM, NULL, NULL);
+  mSmmDebugAgentSupport = AllocatePool (sizeof (BOOLEAN));
+  if (mSmmDebugAgentSupport == NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  InitializeDebugAgent (DEBUG_AGENT_INIT_SMM, mSmmDebugAgentSupport, NULL);
 
   //
   // Report the start of CPU SMM initialization.
   //
   REPORT_STATUS_CODE (
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
index a2fa4f6734..cf452ea3c2 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h
@@ -481,10 +481,11 @@ extern UINTN                         mSemaphoreSize;
 extern SPIN_LOCK                     *mPFLock;
 extern SPIN_LOCK                     *mConfigSmmCodeAccessCheckLock;
 extern EFI_SMRAM_DESCRIPTOR          *mSmmCpuSmramRanges;
 extern UINTN                         mSmmCpuSmramRangeCount;
 extern UINT8                         mPhysicalAddressBits;
+extern BOOLEAN                       *mSmmDebugAgentSupport;
 
 //
 // Copy of the PcdPteMemoryEncryptionAddressOrMask
 //
 extern UINT64  mAddressEncMask;
-- 
2.16.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112794): https://edk2.groups.io/g/devel/message/112794
Mute This Topic: https://groups.io/mt/103293800/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [edk2-devel] [PATCH v1 4/6] UefiCpuPkg/PiSmmCpuDxeSmm: Align MTRR sync logic between BSP and AP
  2023-12-21  2:21 [edk2-devel] [PATCH v1 0/6] Reduce one round BSP & AP sync Wu, Jiaxin
                   ` (2 preceding siblings ...)
  2023-12-21  2:21 ` [edk2-devel] [PATCH v1 3/6] UefiCpuPkg/PiSmmCpuDxeSmm: Check " Wu, Jiaxin
@ 2023-12-21  2:21 ` Wu, Jiaxin
  2023-12-21  2:21 ` [edk2-devel] [PATCH v1 5/6] UefiCpuPkg/PiSmmCpuDxeSmm: Invert ReleaseAllAPs & InitializeDebugAgent Wu, Jiaxin
  2023-12-21  2:21 ` [edk2-devel] [PATCH v1 6/6] UefiCpuPkg/PiSmmCpuDxeSmm: Reduce one round BSP & AP sync Wu, Jiaxin
  5 siblings, 0 replies; 7+ messages in thread
From: Wu, Jiaxin @ 2023-12-21  2:21 UTC (permalink / raw)
  To: devel
  Cc: Laszlo Ersek, Eric Dong, Ray Ni, Zeng Star, Gerd Hoffmann,
	Rahul Kumar

Below piece of code is to sync logic in AP for MTRR programming:
  if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
    SmmCpuSyncReleaseBsp ();
    SmmCpuSyncWaitForBsp ();
    ...
  }
  SmmCpuSyncReleaseBsp ();
  SmmCpuSyncWaitForBsp ();

This patch is to make BSP sync logic same as above coding style:
  if (SmmCpuFeaturesNeedConfigureMtrrs ()) {
    SmmCpuSyncWaitForAPs ();
    ReleaseAllAPs ();
    ...
  }
  SmmCpuSyncWaitForAPs ();
  ReleaseAllAPs ();

With the changes, 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 408ee8a87d..8e525ce3b3 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 (#112795): https://edk2.groups.io/g/devel/message/112795
Mute This Topic: https://groups.io/mt/103293801/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [edk2-devel] [PATCH v1 5/6] UefiCpuPkg/PiSmmCpuDxeSmm: Invert ReleaseAllAPs & InitializeDebugAgent
  2023-12-21  2:21 [edk2-devel] [PATCH v1 0/6] Reduce one round BSP & AP sync Wu, Jiaxin
                   ` (3 preceding siblings ...)
  2023-12-21  2:21 ` [edk2-devel] [PATCH v1 4/6] UefiCpuPkg/PiSmmCpuDxeSmm: Align MTRR sync logic between BSP and AP Wu, Jiaxin
@ 2023-12-21  2:21 ` Wu, Jiaxin
  2023-12-21  2:21 ` [edk2-devel] [PATCH v1 6/6] UefiCpuPkg/PiSmmCpuDxeSmm: Reduce one round BSP & AP sync Wu, Jiaxin
  5 siblings, 0 replies; 7+ messages in thread
From: Wu, Jiaxin @ 2023-12-21  2:21 UTC (permalink / raw)
  To: devel
  Cc: Laszlo Ersek, Eric Dong, Ray Ni, Zeng Star, Gerd Hoffmann,
	Rahul Kumar

Below BSP & AP sync flow before exit SMI is to:
1. Make sure BSP and all APs finish the MTRR programming and start
later executing the same start line. This is the MTRR programming
requirement.
2. Make sure all APs finish the pending tasks, then BSP can stop
source level debug.
BSP: SmmCpuSyncWaitForAPs  <--  AP: SmmCpuSyncReleaseBsp
BSP: ReleaseAllAPs         -->  AP: SmmCpuSyncWaitForBsp

For SMM source level debug, it doesn't depend on the AP Present flag
set. So we can invert ReleaseAllAPs & InitializeDebugAgent.

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 | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index 8e525ce3b3..04622c66a2 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -648,23 +648,23 @@ BSPHandler (
   //
   // Wait for all APs to complete their pending tasks including MTRR programming if needed.
   //
   SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
 
+  //
+  // Signal APs to Reset states/semaphore for this processor
+  //
+  ReleaseAllAPs ();
+
   if (*mSmmDebugAgentSupport) {
     //
     // Stop source level debug in BSP handler, the code below will not be
     // debugged.
     //
     InitializeDebugAgent (DEBUG_AGENT_INIT_EXIT_SMI, NULL, NULL);
   }
 
-  //
-  // Signal APs to Reset states/semaphore for this processor
-  //
-  ReleaseAllAPs ();
-
   //
   // Perform pending operations for hot-plug
   //
   SmmCpuUpdate ();
 
-- 
2.16.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112796): https://edk2.groups.io/g/devel/message/112796
Mute This Topic: https://groups.io/mt/103293802/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [edk2-devel] [PATCH v1 6/6] UefiCpuPkg/PiSmmCpuDxeSmm: Reduce one round BSP & AP sync
  2023-12-21  2:21 [edk2-devel] [PATCH v1 0/6] Reduce one round BSP & AP sync Wu, Jiaxin
                   ` (4 preceding siblings ...)
  2023-12-21  2:21 ` [edk2-devel] [PATCH v1 5/6] UefiCpuPkg/PiSmmCpuDxeSmm: Invert ReleaseAllAPs & InitializeDebugAgent Wu, Jiaxin
@ 2023-12-21  2:21 ` Wu, Jiaxin
  5 siblings, 0 replies; 7+ messages in thread
From: Wu, Jiaxin @ 2023-12-21  2:21 UTC (permalink / raw)
  To: devel
  Cc: Laszlo Ersek, Eric Dong, Ray Ni, Zeng Star, Gerd Hoffmann,
	Rahul Kumar

One round BSP & AP sync for exit SMI is shown as below:
BSP: SmmCpuSyncWaitForAPs  <--  AP: SmmCpuSyncReleaseBsp
BSP: ReleaseAllAPs         -->  AP: SmmCpuSyncWaitForBsp

Above is only required if need configure MTRR and support
SMM source level debug, So, reduce one round BSP & AP sync
if both are unsupported.

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 | 36 +++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
index 04622c66a2..d0139228bb 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c
@@ -643,19 +643,21 @@ BSPHandler (
     //
     SmmCpuFeaturesReenableSmrr ();
     MtrrSetAllMtrrs (&Mtrrs);
   }
 
-  //
-  // Wait for all APs to complete their pending tasks including MTRR programming if needed.
-  //
-  SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
+  if (SmmCpuFeaturesNeedConfigureMtrrs () || *mSmmDebugAgentSupport) {
+    //
+    // Wait for all APs to complete their pending tasks including MTRR programming if needed.
+    //
+    SmmCpuSyncWaitForAPs (mSmmMpSyncData->SyncContext, ApCount, CpuIndex);
 
-  //
-  // Signal APs to Reset states/semaphore for this processor
-  //
-  ReleaseAllAPs ();
+    //
+    // Signal APs to Reset states/semaphore for this processor
+    //
+    ReleaseAllAPs ();
+  }
 
   if (*mSmmDebugAgentSupport) {
     //
     // Stop source level debug in BSP handler, the code below will not be
     // debugged.
@@ -894,19 +896,21 @@ APHandler (
     //
     SmmCpuFeaturesReenableSmrr ();
     MtrrSetAllMtrrs (&Mtrrs);
   }
 
-  //
-  // Notify BSP the readiness of this AP to Reset states/semaphore for this processor
-  //
-  SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
+  if (SmmCpuFeaturesNeedConfigureMtrrs () || *mSmmDebugAgentSupport) {
+    //
+    // Notify BSP the readiness of this AP to Reset states/semaphore for this processor
+    //
+    SmmCpuSyncReleaseBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
 
-  //
-  // Wait for the signal from BSP to Reset states/semaphore for this processor
-  //
-  SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
+    //
+    // Wait for the signal from BSP to Reset states/semaphore for this processor
+    //
+    SmmCpuSyncWaitForBsp (mSmmMpSyncData->SyncContext, CpuIndex, BspIndex);
+  }
 
   //
   // Reset states/semaphore for this processor
   //
   *(mSmmMpSyncData->CpuData[CpuIndex].Present) = FALSE;
-- 
2.16.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112797): https://edk2.groups.io/g/devel/message/112797
Mute This Topic: https://groups.io/mt/103293803/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-12-21  2:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-21  2:21 [edk2-devel] [PATCH v1 0/6] Reduce one round BSP & AP sync Wu, Jiaxin
2023-12-21  2:21 ` [edk2-devel] [PATCH v1 1/6] SourceLevelDebugPkg/Library: Indicate SMM Debug Agent support or not Wu, Jiaxin
2023-12-21  2:21 ` [edk2-devel] [PATCH v1 2/6] MdeModulePkg/DebugAgentLibNull: " Wu, Jiaxin
2023-12-21  2:21 ` [edk2-devel] [PATCH v1 3/6] UefiCpuPkg/PiSmmCpuDxeSmm: Check " Wu, Jiaxin
2023-12-21  2:21 ` [edk2-devel] [PATCH v1 4/6] UefiCpuPkg/PiSmmCpuDxeSmm: Align MTRR sync logic between BSP and AP Wu, Jiaxin
2023-12-21  2:21 ` [edk2-devel] [PATCH v1 5/6] UefiCpuPkg/PiSmmCpuDxeSmm: Invert ReleaseAllAPs & InitializeDebugAgent Wu, Jiaxin
2023-12-21  2:21 ` [edk2-devel] [PATCH v1 6/6] UefiCpuPkg/PiSmmCpuDxeSmm: Reduce one round BSP & AP sync Wu, Jiaxin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox