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 | 7 ++++++-
UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 1 +
4 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
index 0bae0e33f1..b14c289a27 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..324e85d6b5 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..9b230772cb 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 = FALSE;
+
//
// Global copy of the PcdPteMemoryEncryptionAddressOrMask
//
UINT64 mAddressEncMask = 0;
@@ -895,11 +900,11 @@ PiCpuSmmEntry (
PiSmmCpuSmiEntryFixupAddress ();
//
// Initialize Debug Agent to support source level debug in SMM code
//
- InitializeDebugAgent (DEBUG_AGENT_INIT_SMM, NULL, NULL);
+ 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..7f244ea803 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 (#112888): https://edk2.groups.io/g/devel/message/112888
Mute This Topic: https://groups.io/mt/103360804/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Reviewed-by: Ray Ni <ray.ni@Intel.com>
Thanks,
Ray
> -----Original Message-----
> From: Wu, Jiaxin <jiaxin.wu@intel.com>
> Sent: Tuesday, December 26, 2023 12:21 AM
> To: devel@edk2.groups.io
> Cc: Laszlo Ersek <lersek@redhat.com>; Dong, Eric <eric.dong@intel.com>; Ni,
> Ray <ray.ni@intel.com>; Zeng, Star <star.zeng@intel.com>; Gerd Hoffmann
> <kraxel@redhat.com>; Kumar, Rahul R <rahul.r.kumar@intel.com>
> Subject: [PATCH v2 3/6] UefiCpuPkg/PiSmmCpuDxeSmm: Check SMM Debug
> Agent support or not
>
> 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 | 7 ++++++-
> UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 1 +
> 4 files changed, 23 insertions(+), 11 deletions(-)
>
> diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
> b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c
> index 0bae0e33f1..b14c289a27 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..324e85d6b5 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..9b230772cb 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 = FALSE;
> +
> //
> // Global copy of the PcdPteMemoryEncryptionAddressOrMask
> //
> UINT64 mAddressEncMask = 0;
>
> @@ -895,11 +900,11 @@ PiCpuSmmEntry (
> PiSmmCpuSmiEntryFixupAddress ();
>
> //
> // Initialize Debug Agent to support source level debug in SMM code
> //
> - InitializeDebugAgent (DEBUG_AGENT_INIT_SMM, NULL, NULL);
> + 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..7f244ea803 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 (#112901): https://edk2.groups.io/g/devel/message/112901
Mute This Topic: https://groups.io/mt/103360804/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076/xyzzy [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2026 Red Hat, Inc.