This patch is to check SMM Debug Agent support or not before InitializeDebugAgent.
Cc: Laszlo Ersek <ler...@redhat.com> Cc: Eric Dong <eric.d...@intel.com> Cc: Ray Ni <ray...@intel.com> Cc: Zeng Star <star.z...@intel.com> Cc: Gerd Hoffmann <kra...@redhat.com> Cc: Rahul Kumar <rahul1.ku...@intel.com> Signed-off-by: Jiaxin Wu <jiaxin...@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/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-