* [PATCH v4 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support. @ 2022-02-23 12:59 Li, Zhihao [not found] ` <MWHPR11MB15989DD6418D50088C598AEFEB029@MWHPR11MB1598.namprd11.prod.outlook.com> 0 siblings, 1 reply; 3+ messages in thread From: Li, Zhihao @ 2022-02-23 12:59 UTC (permalink / raw) To: devel; +Cc: Eric Dong, Ray Ni, Rahul Kumar, Siyuan Fu REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3815 This patch define a new Protocol with the new services SmmWaitForAllProcessor(), which can be used by SMI handler to optionally wait for other APs to complete SMM rendezvous in relaxed AP mode. A new library SmmCpuRendezvousLib is provided to abstract the service into library API to simple SMI handler code. Patch_v3 modified to pass CI test. (1)Add SmmCpuRendezvousLib.inf into UefiCpuPkg.dsc <LibraryClasses>/<Component> (2)Add SmmCpuRendezvousLib.h in UefiCpuPkg.dec [Libraryclasses.IA32, Libraryclasses.x64] (3) Some UncrustifyCheck modifications. Cc: Eric Dong <eric.dong@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Rahul Kumar <rahul1.kumar@intel.com> Cc: Siyuan Fu <siyuan.fu@intel.com> Signed-off-by: Zhihao Li <zhihao.li@intel.com> --- UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c | 98 ++++++++++++++++++++ UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 68 +++++++++++++- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 20 +++- UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h | 27 ++++++ UefiCpuPkg/Include/Protocol/SmmCpuService.h | 36 ++++++- UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf | 35 +++++++ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 29 +++++- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 5 +- UefiCpuPkg/UefiCpuPkg.dec | 8 +- UefiCpuPkg/UefiCpuPkg.dsc | 2 + 10 files changed, 316 insertions(+), 12 deletions(-) diff --git a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c new file mode 100644 index 000000000000..22f694b77d51 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c @@ -0,0 +1,98 @@ +/** @file + SMM CPU Rendezvous sevice implement. + + Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Base.h> +#include <Uefi.h> +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/MmServicesTableLib.h> +#include <Protocol/SmmCpuService.h> +#include <Library/SmmCpuRendezvousLib.h> + +STATIC EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *mSmmCpuRendezvous = NULL; +STATIC VOID *mRegistration = NULL; + +/** + Register status code callback function only when Report Status Code protocol + is installed. + + @param[in] Protocol Points to the protocol's unique identifier. + @param[in] Interface Points to the interface instance. + @param[in] Handle The handle on which the interface was installed. + + @retval EFI_SUCCESS Notification runs successfully. + +**/ +EFI_STATUS +EFIAPI +SmmCpuRendezvousProtocolNotify ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + EFI_STATUS Status; + + Status = gMmst->MmLocateProtocol ( + &gEdkiiSmmCpuRendezvousProtocolGuid, + NULL, + (VOID **)&mSmmCpuRendezvous + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + +/** + This routine wait for all AP processors to arrive in SMM. + + @param[in] BlockingMode Blocking mode or non-blocking mode. + + @retval EFI_SUCCESS All avaiable APs arrived. + @retval EFI_TIMEOUT Wait for all APs until timeout. + @retval OTHER Fail to register SMM CPU Rendezvous service Protocol. +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN BOOLEAN BlockingMode + ) +{ + EFI_STATUS Status; + + if ((mRegistration == NULL) && (mSmmCpuRendezvous == NULL)) { + // + // Locate SMM cpu rendezvous protocol for the first time execute the function. + // + Status = gMmst->MmLocateProtocol ( + &gEdkiiSmmCpuRendezvousProtocolGuid, + NULL, + (VOID **)&mSmmCpuRendezvous + ); + if (EFI_ERROR (Status)) { + Status = gMmst->MmRegisterProtocolNotify ( + &gEdkiiSmmCpuRendezvousProtocolGuid, + SmmCpuRendezvousProtocolNotify, + &mRegistration + ); + if (EFI_ERROR (Status)) { + return Status; + } + } + } + + if (mSmmCpuRendezvous == NULL) { + return EFI_SUCCESS; + } + + Status = mSmmCpuRendezvous->WaitForAllProcessor ( + mSmmCpuRendezvous, + BlockingMode + ); + return Status; +} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c index 5d624f8e9ed6..e096970ac62e 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c @@ -1,7 +1,7 @@ /** @file Implementation of SMM CPU Services Protocol. -Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -20,6 +20,13 @@ EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService = { SmmRegisterExceptionHandler }; +// +// EDKII SMM CPU Rendezvous Service Protocol instance +// +EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL mSmmCpuRendezvousService = { + SmmWaitForAllProcessor +}; + /** Gets processor information on the requested processor at the instant this call is made. @@ -350,6 +357,7 @@ SmmRegisterExceptionHandler ( @param ImageHandle The firmware allocated handle for the EFI image. @retval EFI_SUCCESS EFI SMM CPU Services Protocol was installed successfully. + @retval OTHER Fail to install Protocol. **/ EFI_STATUS InitializeSmmCpuServices ( @@ -364,6 +372,64 @@ InitializeSmmCpuServices ( EFI_NATIVE_INTERFACE, &mSmmCpuService ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gSmst->SmmInstallProtocolInterface ( + &Handle, + &gEdkiiSmmCpuRendezvousProtocolGuid, + EFI_NATIVE_INTERFACE, + &mSmmCpuRendezvousService + ); ASSERT_EFI_ERROR (Status); return Status; } + +/** + Wait for all processors enterring SMM until all CPUs are already synchronized or not. + + If BlockingMode is False, timeout value is zero. + + @param This A pointer to the EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL instance. + @param BlockingMode Blocking mode or non-blocking mode. + + @retval EFI_SUCCESS All avaiable APs arrived. + @retval EFI_TIMEOUT Wait for all APs until timeout. + +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This, + IN BOOLEAN BlockingMode + ) +{ + EFI_STATUS Status; + + // + // Return success immediately if all CPUs are already synchronized. + // + if (mSmmMpSyncData->AllApArrivedWithException) { + Status = EFI_SUCCESS; + goto ON_EXIT; + } + + if (!BlockingMode) { + Status = EFI_TIMEOUT; + goto ON_EXIT; + } + + // + // There are some APs outside SMM, Wait for all avaiable APs to arrive. + // + SmmWaitForApArrival (); + Status = mSmmMpSyncData->AllApArrivedWithException ? EFI_SUCCESS : EFI_TIMEOUT; + +ON_EXIT: + if (!mSmmMpSyncData->AllApArrivedWithException) { + DEBUG ((DEBUG_INFO, "EdkiiSmmWaitForAllApArrival: Timeout to wait all APs arrival\n")); + } + + return Status; +} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 882dee4fe246..13c2cb8da4c3 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1,7 +1,7 @@ /** @file SMM MP service implementation -Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR> Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -293,10 +293,14 @@ SmmWaitForApArrival ( // Sync with APs 1st timeout // for (Timer = StartSyncTimer (); - !IsSyncTimerTimeout (Timer) && !(LmceEn && LmceSignal) && - !AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED); + !IsSyncTimerTimeout (Timer) && !(LmceEn && LmceSignal); ) { + mSmmMpSyncData->AllApArrivedWithException = AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED); + if (mSmmMpSyncData->AllApArrivedWithException) { + break; + } + CpuPause (); } @@ -330,10 +334,14 @@ SmmWaitForApArrival ( // Sync with APs 2nd timeout. // for (Timer = StartSyncTimer (); - !IsSyncTimerTimeout (Timer) && - !AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED); + !IsSyncTimerTimeout (Timer); ) { + mSmmMpSyncData->AllApArrivedWithException = AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED); + if (mSmmMpSyncData->AllApArrivedWithException) { + break; + } + CpuPause (); } } @@ -1887,6 +1895,8 @@ InitializeMpSyncData ( *mSmmMpSyncData->InsideSmm = FALSE; *mSmmMpSyncData->AllCpusInSync = FALSE; + mSmmMpSyncData->AllApArrivedWithException = FALSE; + for (CpuIndex = 0; CpuIndex < gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus; CpuIndex++) { mSmmMpSyncData->CpuData[CpuIndex].Busy = (SPIN_LOCK *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Busy + mSemaphoreSize * CpuIndex); diff --git a/UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h b/UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h new file mode 100644 index 000000000000..82e459e9106e --- /dev/null +++ b/UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h @@ -0,0 +1,27 @@ +/** @file + SMM CPU Rendezvous library header file. + + Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SMM_CPU_RENDEZVOUS_H_ +#define SMM_CPU_RENDEZVOUS_H_ + +/** + This routine wait for all AP processors to arrive in SMM. + + @param[in] BlockingMode Blocking mode or non-blocking mode. + + @retval EFI_SUCCESS All processors checked in to SMM. + @retval EFI_TIMEOUT Wait for all APs until timeout. + +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN BOOLEAN BlockingMode + ); + +#endif diff --git a/UefiCpuPkg/Include/Protocol/SmmCpuService.h b/UefiCpuPkg/Include/Protocol/SmmCpuService.h index 952767afce75..3d93d243409c 100644 --- a/UefiCpuPkg/Include/Protocol/SmmCpuService.h +++ b/UefiCpuPkg/Include/Protocol/SmmCpuService.h @@ -1,7 +1,7 @@ /** @file SMM CPU Service protocol definition. -Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2013 - 2022, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -200,4 +200,38 @@ struct _EFI_SMM_CPU_SERVICE_PROTOCOL { extern EFI_GUID gEfiSmmCpuServiceProtocolGuid; +// +// EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL provide SMM CPU +// rendezvous service support. +// +#define EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL_GUID \ + { \ + 0xaa00d50b, 0x4911, 0x428f, { 0xb9, 0x1a, 0xa5, 0x9d, 0xdb, 0x13, 0xe2, 0x4c } \ + } + +typedef struct _EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL; + +/** + Wait for all APs to arrive SMM mode in given timeout constraint. + + @param[in] This A pointer to the EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL instance. + @param[in] BlockingMode Block or non-block mode. + + @retval EFI_SUCCESS All APs have arrived SMM mode except SMI disabled APs. + @retval EFI_TIMEOUT There are APs not in SMM mode in given timeout constraint. + +**/ +typedef +EFI_STATUS +(EFIAPI *EDKII_WAIT_FOR_ALL_PROCESSOR)( + IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This, + IN BOOLEAN BlockingMode + ); + +struct _EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL { + EDKII_WAIT_FOR_ALL_PROCESSOR WaitForAllProcessor; +}; + +extern EFI_GUID gEdkiiSmmCpuRendezvousProtocolGuid; + #endif diff --git a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf new file mode 100644 index 000000000000..52374bf6e9b4 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf @@ -0,0 +1,35 @@ +## @file +# SMM CPU Rendezvous service lib. +# +# This is SMM CPU rendezvous service lib that wait for all +# APs to enter SMM mode. +# +# Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SmmCpuRendezvousLib + FILE_GUID = 1509Bb36-9Ba4-438B-B195-Ac5914Db14E2 + MODULE_TYPE = DXE_SMM_DRIVER + LIBRARY_CLASS = SmmCpuRendezvousLib|MM_STANDALONE DXE_SMM_DRIVER + +[Sources] + SmmCpuRendezvousLib.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + MmServicesTableLib + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmApSyncTimeout ## CONSUMES + +[Protocols] + gEdkiiSmmCpuRendezvousProtocolGuid diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h index 26d07c5b5ea0..c7f47a1d2fe5 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -1,7 +1,7 @@ /** @file Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU. -Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR> Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -428,6 +428,7 @@ typedef struct { volatile SMM_CPU_SYNC_MODE EffectiveSyncMode; volatile BOOLEAN SwitchBsp; volatile BOOLEAN *CandidateBsp; + volatile BOOLEAN AllApArrivedWithException; EFI_AP_PROCEDURE StartupProcedure; VOID *StartupProcArgs; } SMM_DISPATCHER_MP_SYNC_DATA; @@ -1488,4 +1489,30 @@ IsRestrictedMemoryAccess ( VOID ); +/** + Choose blocking or non-blocking mode to Wait for all APs. + + @param[in] This A pointer to the EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL instance. + @param[in] BlockingMode Blocking or non-blocking mode. + + @retval EFI_SUCCESS All APs have arrived SMM mode except SMI disabled APs. + @retval EFI_TIMEOUT There are APs not in SMM mode in given timeout constraint. + +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This, + IN BOOLEAN BlockingMode + ); + +/** + Insure when this function returns, no AP will execute normal mode code before entering SMM, except SMI disabled APs. + +**/ +VOID +SmmWaitForApArrival ( + VOID + ); + #endif diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf index 0e88071c7079..deef00f9c6e9 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -4,7 +4,7 @@ # This SMM driver performs SMM initialization, deploy SMM Entry Vector, # provides CPU specific services in SMM. # -# Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR> # Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -107,7 +107,8 @@ gEfiSmmReadyToLockProtocolGuid ## NOTIFY gEfiSmmCpuServiceProtocolGuid ## PRODUCES gEdkiiSmmMemoryAttributeProtocolGuid ## PRODUCES - gEfiMmMpProtocolGuid ## PRODUCES + gEfiMmMpProtocolGuid ## PRODUCES + gEdkiiSmmCpuRendezvousProtocolGuid ## PRODUCES [Guids] gEfiAcpiVariableGuid ## SOMETIMES_CONSUMES ## HOB # it is used for S3 boot. diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 7de66fde674c..525cde463435 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -1,7 +1,7 @@ ## @file UefiCpuPkg.dec # This Package provides UEFI compatible CPU modules and libraries. # -# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2007 - 2022, Intel Corporation. All rights reserved.<BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -62,6 +62,9 @@ ## @libraryclass Provides function for loading microcode. MicrocodeLib|Include/Library/MicrocodeLib.h + ## @libraryclass Provides function for SMM CPU Rendezvous Library. + SmmCpuRendezvousLib|Include/Library/SmmCpuRendezvousLib.h + [Guids] gUefiCpuPkgTokenSpaceGuid = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa, 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }} gMsegSmramGuid = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1, 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }} @@ -77,7 +80,8 @@ [Protocols] ## Include/Protocol/SmmCpuService.h - gEfiSmmCpuServiceProtocolGuid = { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94, 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }} + gEfiSmmCpuServiceProtocolGuid = { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94, 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }} + gEdkiiSmmCpuRendezvousProtocolGuid = { 0xaa00d50b, 0x4911, 0x428f, { 0xb9, 0x1a, 0xa5, 0x9d, 0xdb, 0x13, 0xe2, 0x4c }} ## Include/Protocol/SmMonitorInit.h gEfiSmMonitorInitProtocolGuid = { 0x228f344d, 0xb3de, 0x43bb, { 0xa4, 0xd7, 0xea, 0x20, 0xb, 0x1b, 0x14, 0x82 }} diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index d1d61dd6a03b..a0bbde9985d3 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -61,6 +61,7 @@ TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf + SmmCpuRendezvousLib|UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf [LibraryClasses.common.SEC] PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf @@ -173,6 +174,7 @@ } UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf + UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf [BuildOptions] *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES -- 2.26.2.windows.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
[parent not found: <MWHPR11MB15989DD6418D50088C598AEFEB029@MWHPR11MB1598.namprd11.prod.outlook.com>]
* FW: [edk2-devel] [PATCH v4 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support. [not found] ` <MWHPR11MB15989DD6418D50088C598AEFEB029@MWHPR11MB1598.namprd11.prod.outlook.com> @ 2022-03-01 8:10 ` Li, Zhihao 2022-03-01 8:48 ` Ni, Ray 0 siblings, 1 reply; 3+ messages in thread From: Li, Zhihao @ 2022-03-01 8:10 UTC (permalink / raw) To: Ni, Ray, devel@edk2.groups.io; +Cc: Dong, Eric, Kumar, Rahul1, Fu, Siyuan 1. InitializeSmmCpuServices(): please keep the ASSERT_EFI_ERROR (Status) for CpuService protocol installation. Will add assert. 2. SmmWaitForApArrival (): Can you remove the BlockingMode parameter because I cannot find any invocation using FALSE as parameter. Have removed in patchv4. 3. mSmmMpSyncData->AllApArrivedWithException: where is this variable assigned to TRUE? Have added in patchv4. 4. SmmCpuRendezvousProtocolNotify(): Function header is incorrect (I saw "Report Status Code"). Can you add comments to explain why protocol notification is needed instead of using library constructor to locate the protocol? Feature need to support MM_STANDALONE and DXE_SMM_DRIVER driver. They have different entry function parameter. Will add comment in function header. 5. Lib: SmmWaitForAllProcessor(): Can you add comments to explain why (mSmmCpuRendezvous == NULL) is a success? And this API is the same as the internal function name in PiSmmCpuDxe driver. It may cause confusing. Can you change that internal function to use a different name? 1) If SmmCpuRendezvous service do not locate, it means the platform have not setup and influence cpu rendezvous. Will add comment in function header. 2) For this, I plan to modified name of SmmWaitForAllProcessor in SmmCpuRendezvousLib to be SmmCpuRendezvous() and keep PiSmmCpuDxe driver the same. -----Original Message----- From: Fu, Siyuan <siyuan.fu@intel.com> Sent: Tuesday, March 1, 2022 3:46 PM To: Li, Zhihao <zhihao.li@intel.com> Subject: FW: [edk2-devel] [PATCH v4 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support. Best Regards Siyuan -----Original Message----- From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Li, Zhihao Sent: 2022年2月23日 20:59 To: devel@edk2.groups.io Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Kumar, Rahul1 <rahul1.kumar@intel.com>; Fu, Siyuan <siyuan.fu@intel.com> Subject: [edk2-devel] [PATCH v4 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3815 This patch define a new Protocol with the new services SmmWaitForAllProcessor(), which can be used by SMI handler to optionally wait for other APs to complete SMM rendezvous in relaxed AP mode. A new library SmmCpuRendezvousLib is provided to abstract the service into library API to simple SMI handler code. Patch_v3 modified to pass CI test. (1)Add SmmCpuRendezvousLib.inf into UefiCpuPkg.dsc <LibraryClasses>/<Component> (2)Add SmmCpuRendezvousLib.h in UefiCpuPkg.dec [Libraryclasses.IA32, Libraryclasses.x64] (3) Some UncrustifyCheck modifications. Cc: Eric Dong <eric.dong@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Rahul Kumar <rahul1.kumar@intel.com> Cc: Siyuan Fu <siyuan.fu@intel.com> Signed-off-by: Zhihao Li <zhihao.li@intel.com> --- UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c | 98 ++++++++++++++++++++ UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 68 +++++++++++++- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 20 +++- UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h | 27 ++++++ UefiCpuPkg/Include/Protocol/SmmCpuService.h | 36 ++++++- UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf | 35 +++++++ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 29 +++++- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 5 +- UefiCpuPkg/UefiCpuPkg.dec | 8 +- UefiCpuPkg/UefiCpuPkg.dsc | 2 + 10 files changed, 316 insertions(+), 12 deletions(-) diff --git a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c new file mode 100644 index 000000000000..22f694b77d51 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c @@ -0,0 +1,98 @@ +/** @file + SMM CPU Rendezvous sevice implement. + + Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Base.h> +#include <Uefi.h> +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/MmServicesTableLib.h> +#include <Protocol/SmmCpuService.h> +#include <Library/SmmCpuRendezvousLib.h> + +STATIC EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *mSmmCpuRendezvous = NULL; +STATIC VOID *mRegistration = NULL; + +/** + Register status code callback function only when Report Status Code + protocol + is installed. + + @param[in] Protocol Points to the protocol's unique identifier. + @param[in] Interface Points to the interface instance. + @param[in] Handle The handle on which the interface was installed. + + @retval EFI_SUCCESS Notification runs successfully. + +**/ +EFI_STATUS +EFIAPI +SmmCpuRendezvousProtocolNotify ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + EFI_STATUS Status; + + Status = gMmst->MmLocateProtocol ( + &gEdkiiSmmCpuRendezvousProtocolGuid, + NULL, + (VOID **)&mSmmCpuRendezvous + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + +/** + This routine wait for all AP processors to arrive in SMM. + + @param[in] BlockingMode Blocking mode or non-blocking mode. + + @retval EFI_SUCCESS All avaiable APs arrived. + @retval EFI_TIMEOUT Wait for all APs until timeout. + @retval OTHER Fail to register SMM CPU Rendezvous service Protocol. +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN BOOLEAN BlockingMode + ) +{ + EFI_STATUS Status; + + if ((mRegistration == NULL) && (mSmmCpuRendezvous == NULL)) { + // + // Locate SMM cpu rendezvous protocol for the first time execute the function. + // + Status = gMmst->MmLocateProtocol ( + &gEdkiiSmmCpuRendezvousProtocolGuid, + NULL, + (VOID **)&mSmmCpuRendezvous + ); + if (EFI_ERROR (Status)) { + Status = gMmst->MmRegisterProtocolNotify ( + &gEdkiiSmmCpuRendezvousProtocolGuid, + SmmCpuRendezvousProtocolNotify, + &mRegistration + ); + if (EFI_ERROR (Status)) { + return Status; + } + } + } + + if (mSmmCpuRendezvous == NULL) { + return EFI_SUCCESS; + } + + Status = mSmmCpuRendezvous->WaitForAllProcessor ( + mSmmCpuRendezvous, + BlockingMode + ); + return Status; +} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c index 5d624f8e9ed6..e096970ac62e 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c @@ -1,7 +1,7 @@ /** @file Implementation of SMM CPU Services Protocol. -Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -20,6 +20,13 @@ EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService = { SmmRegisterExceptionHandler }; +// +// EDKII SMM CPU Rendezvous Service Protocol instance +// +EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL mSmmCpuRendezvousService = { + SmmWaitForAllProcessor +}; + /** Gets processor information on the requested processor at the instant this call is made. @@ -350,6 +357,7 @@ SmmRegisterExceptionHandler ( @param ImageHandle The firmware allocated handle for the EFI image. @retval EFI_SUCCESS EFI SMM CPU Services Protocol was installed successfully. + @retval OTHER Fail to install Protocol. **/ EFI_STATUS InitializeSmmCpuServices ( @@ -364,6 +372,64 @@ InitializeSmmCpuServices ( EFI_NATIVE_INTERFACE, &mSmmCpuService ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gSmst->SmmInstallProtocolInterface ( + &Handle, + &gEdkiiSmmCpuRendezvousProtocolGuid, + EFI_NATIVE_INTERFACE, + &mSmmCpuRendezvousService + ); ASSERT_EFI_ERROR (Status); return Status; } + +/** + Wait for all processors enterring SMM until all CPUs are already synchronized or not. + + If BlockingMode is False, timeout value is zero. + + @param This A pointer to the EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL instance. + @param BlockingMode Blocking mode or non-blocking mode. + + @retval EFI_SUCCESS All avaiable APs arrived. + @retval EFI_TIMEOUT Wait for all APs until timeout. + +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This, + IN BOOLEAN BlockingMode + ) +{ + EFI_STATUS Status; + + // + // Return success immediately if all CPUs are already synchronized. + // + if (mSmmMpSyncData->AllApArrivedWithException) { + Status = EFI_SUCCESS; + goto ON_EXIT; + } + + if (!BlockingMode) { + Status = EFI_TIMEOUT; + goto ON_EXIT; + } + + // + // There are some APs outside SMM, Wait for all avaiable APs to arrive. + // + SmmWaitForApArrival (); + Status = mSmmMpSyncData->AllApArrivedWithException ? EFI_SUCCESS : + EFI_TIMEOUT; + +ON_EXIT: + if (!mSmmMpSyncData->AllApArrivedWithException) { + DEBUG ((DEBUG_INFO, "EdkiiSmmWaitForAllApArrival: Timeout to wait + all APs arrival\n")); + } + + return Status; +} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 882dee4fe246..13c2cb8da4c3 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1,7 +1,7 @@ /** @file SMM MP service implementation -Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR> Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -293,10 +293,14 @@ SmmWaitForApArrival ( // Sync with APs 1st timeout // for (Timer = StartSyncTimer (); - !IsSyncTimerTimeout (Timer) && !(LmceEn && LmceSignal) && - !AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED); + !IsSyncTimerTimeout (Timer) && !(LmceEn && LmceSignal); ) { + mSmmMpSyncData->AllApArrivedWithException = + AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | + ARRIVAL_EXCEPTION_SMI_DISABLED); + if (mSmmMpSyncData->AllApArrivedWithException) { + break; + } + CpuPause (); } @@ -330,10 +334,14 @@ SmmWaitForApArrival ( // Sync with APs 2nd timeout. // for (Timer = StartSyncTimer (); - !IsSyncTimerTimeout (Timer) && - !AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED); + !IsSyncTimerTimeout (Timer); ) { + mSmmMpSyncData->AllApArrivedWithException = + AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | + ARRIVAL_EXCEPTION_SMI_DISABLED); + if (mSmmMpSyncData->AllApArrivedWithException) { + break; + } + CpuPause (); } } @@ -1887,6 +1895,8 @@ InitializeMpSyncData ( *mSmmMpSyncData->InsideSmm = FALSE; *mSmmMpSyncData->AllCpusInSync = FALSE; + mSmmMpSyncData->AllApArrivedWithException = FALSE; + for (CpuIndex = 0; CpuIndex < gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus; CpuIndex++) { mSmmMpSyncData->CpuData[CpuIndex].Busy = (SPIN_LOCK *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Busy + mSemaphoreSize * CpuIndex); diff --git a/UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h b/UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h new file mode 100644 index 000000000000..82e459e9106e --- /dev/null +++ b/UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h @@ -0,0 +1,27 @@ +/** @file + SMM CPU Rendezvous library header file. + + Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SMM_CPU_RENDEZVOUS_H_ +#define SMM_CPU_RENDEZVOUS_H_ + +/** + This routine wait for all AP processors to arrive in SMM. + + @param[in] BlockingMode Blocking mode or non-blocking mode. + + @retval EFI_SUCCESS All processors checked in to SMM. + @retval EFI_TIMEOUT Wait for all APs until timeout. + +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN BOOLEAN BlockingMode + ); + +#endif diff --git a/UefiCpuPkg/Include/Protocol/SmmCpuService.h b/UefiCpuPkg/Include/Protocol/SmmCpuService.h index 952767afce75..3d93d243409c 100644 --- a/UefiCpuPkg/Include/Protocol/SmmCpuService.h +++ b/UefiCpuPkg/Include/Protocol/SmmCpuService.h @@ -1,7 +1,7 @@ /** @file SMM CPU Service protocol definition. -Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2013 - 2022, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -200,4 +200,38 @@ struct _EFI_SMM_CPU_SERVICE_PROTOCOL { extern EFI_GUID gEfiSmmCpuServiceProtocolGuid; +// +// EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL provide SMM CPU +// rendezvous service support. +// +#define EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL_GUID \ + { \ + 0xaa00d50b, 0x4911, 0x428f, { 0xb9, 0x1a, 0xa5, 0x9d, 0xdb, 0x13, + 0xe2, 0x4c } \ + } + +typedef struct _EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL +EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL; + +/** + Wait for all APs to arrive SMM mode in given timeout constraint. + + @param[in] This A pointer to the EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL instance. + @param[in] BlockingMode Block or non-block mode. + + @retval EFI_SUCCESS All APs have arrived SMM mode except SMI disabled APs. + @retval EFI_TIMEOUT There are APs not in SMM mode in given timeout constraint. + +**/ +typedef +EFI_STATUS +(EFIAPI *EDKII_WAIT_FOR_ALL_PROCESSOR)( + IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This, + IN BOOLEAN BlockingMode + ); + +struct _EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL { + EDKII_WAIT_FOR_ALL_PROCESSOR WaitForAllProcessor; +}; + +extern EFI_GUID gEdkiiSmmCpuRendezvousProtocolGuid; + #endif diff --git a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf new file mode 100644 index 000000000000..52374bf6e9b4 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf @@ -0,0 +1,35 @@ +## @file +# SMM CPU Rendezvous service lib. +# +# This is SMM CPU rendezvous service lib that wait for all +# APs to enter SMM mode. +# +# Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SmmCpuRendezvousLib + FILE_GUID = 1509Bb36-9Ba4-438B-B195-Ac5914Db14E2 + MODULE_TYPE = DXE_SMM_DRIVER + LIBRARY_CLASS = SmmCpuRendezvousLib|MM_STANDALONE DXE_SMM_DRIVER + +[Sources] + SmmCpuRendezvousLib.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + MmServicesTableLib + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmApSyncTimeout ## CONSUMES + +[Protocols] + gEdkiiSmmCpuRendezvousProtocolGuid diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h index 26d07c5b5ea0..c7f47a1d2fe5 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -1,7 +1,7 @@ /** @file Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU. -Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR> Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -428,6 +428,7 @@ typedef struct { volatile SMM_CPU_SYNC_MODE EffectiveSyncMode; volatile BOOLEAN SwitchBsp; volatile BOOLEAN *CandidateBsp; + volatile BOOLEAN AllApArrivedWithException; EFI_AP_PROCEDURE StartupProcedure; VOID *StartupProcArgs; } SMM_DISPATCHER_MP_SYNC_DATA; @@ -1488,4 +1489,30 @@ IsRestrictedMemoryAccess ( VOID ); +/** + Choose blocking or non-blocking mode to Wait for all APs. + + @param[in] This A pointer to the EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL instance. + @param[in] BlockingMode Blocking or non-blocking mode. + + @retval EFI_SUCCESS All APs have arrived SMM mode except SMI disabled APs. + @retval EFI_TIMEOUT There are APs not in SMM mode in given timeout constraint. + +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This, + IN BOOLEAN BlockingMode + ); + +/** + Insure when this function returns, no AP will execute normal mode code before entering SMM, except SMI disabled APs. + +**/ +VOID +SmmWaitForApArrival ( + VOID + ); + #endif diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf index 0e88071c7079..deef00f9c6e9 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -4,7 +4,7 @@ # This SMM driver performs SMM initialization, deploy SMM Entry Vector, # provides CPU specific services in SMM. # -# Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2009 - 2022, Intel Corporation. All rights +reserved.<BR> # Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -107,7 +107,8 @@ gEfiSmmReadyToLockProtocolGuid ## NOTIFY gEfiSmmCpuServiceProtocolGuid ## PRODUCES gEdkiiSmmMemoryAttributeProtocolGuid ## PRODUCES - gEfiMmMpProtocolGuid ## PRODUCES + gEfiMmMpProtocolGuid ## PRODUCES + gEdkiiSmmCpuRendezvousProtocolGuid ## PRODUCES [Guids] gEfiAcpiVariableGuid ## SOMETIMES_CONSUMES ## HOB # it is used for S3 boot. diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 7de66fde674c..525cde463435 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -1,7 +1,7 @@ ## @file UefiCpuPkg.dec # This Package provides UEFI compatible CPU modules and libraries. # -# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2007 - 2022, Intel Corporation. All rights +reserved.<BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -62,6 +62,9 @@ ## @libraryclass Provides function for loading microcode. MicrocodeLib|Include/Library/MicrocodeLib.h + ## @libraryclass Provides function for SMM CPU Rendezvous Library. + SmmCpuRendezvousLib|Include/Library/SmmCpuRendezvousLib.h + [Guids] gUefiCpuPkgTokenSpaceGuid = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa, 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }} gMsegSmramGuid = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1, 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }} @@ -77,7 +80,8 @@ [Protocols] ## Include/Protocol/SmmCpuService.h - gEfiSmmCpuServiceProtocolGuid = { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94, 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }} + gEfiSmmCpuServiceProtocolGuid = { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94, 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }} + gEdkiiSmmCpuRendezvousProtocolGuid = { 0xaa00d50b, 0x4911, 0x428f, { + 0xb9, 0x1a, 0xa5, 0x9d, 0xdb, 0x13, 0xe2, 0x4c }} ## Include/Protocol/SmMonitorInit.h gEfiSmMonitorInitProtocolGuid = { 0x228f344d, 0xb3de, 0x43bb, { 0xa4, 0xd7, 0xea, 0x20, 0xb, 0x1b, 0x14, 0x82 }} diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index d1d61dd6a03b..a0bbde9985d3 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -61,6 +61,7 @@ TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf + + SmmCpuRendezvousLib|UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRende + zvousLib.inf [LibraryClasses.common.SEC] PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf @@ -173,6 +174,7 @@ } UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf + UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf [BuildOptions] *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES -- 2.26.2.windows.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [edk2-devel] [PATCH v4 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support. 2022-03-01 8:10 ` FW: [edk2-devel] " Li, Zhihao @ 2022-03-01 8:48 ` Ni, Ray 0 siblings, 0 replies; 3+ messages in thread From: Ni, Ray @ 2022-03-01 8:48 UTC (permalink / raw) To: Li, Zhihao, devel@edk2.groups.io; +Cc: Dong, Eric, Kumar, Rahul1, Fu, Siyuan Please do not change the lib API name. You can choose a different name for driver internal function. -----Original Message----- From: Li, Zhihao <zhihao.li@intel.com> Sent: Tuesday, March 1, 2022 4:10 PM To: Ni, Ray <ray.ni@intel.com>; devel@edk2.groups.io Cc: Dong, Eric <eric.dong@intel.com>; Kumar, Rahul1 <rahul1.kumar@intel.com>; Fu, Siyuan <siyuan.fu@intel.com> Subject: FW: [edk2-devel] [PATCH v4 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support. 1. InitializeSmmCpuServices(): please keep the ASSERT_EFI_ERROR (Status) for CpuService protocol installation. Will add assert. 2. SmmWaitForApArrival (): Can you remove the BlockingMode parameter because I cannot find any invocation using FALSE as parameter. Have removed in patchv4. 3. mSmmMpSyncData->AllApArrivedWithException: where is this variable assigned to TRUE? Have added in patchv4. 4. SmmCpuRendezvousProtocolNotify(): Function header is incorrect (I saw "Report Status Code"). Can you add comments to explain why protocol notification is needed instead of using library constructor to locate the protocol? Feature need to support MM_STANDALONE and DXE_SMM_DRIVER driver. They have different entry function parameter. Will add comment in function header. 5. Lib: SmmWaitForAllProcessor(): Can you add comments to explain why (mSmmCpuRendezvous == NULL) is a success? And this API is the same as the internal function name in PiSmmCpuDxe driver. It may cause confusing. Can you change that internal function to use a different name? 1) If SmmCpuRendezvous service do not locate, it means the platform have not setup and influence cpu rendezvous. Will add comment in function header. 2) For this, I plan to modified name of SmmWaitForAllProcessor in SmmCpuRendezvousLib to be SmmCpuRendezvous() and keep PiSmmCpuDxe driver the same. -----Original Message----- From: Fu, Siyuan <siyuan.fu@intel.com> Sent: Tuesday, March 1, 2022 3:46 PM To: Li, Zhihao <zhihao.li@intel.com> Subject: FW: [edk2-devel] [PATCH v4 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support. Best Regards Siyuan -----Original Message----- From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Li, Zhihao Sent: 2022年2月23日 20:59 To: devel@edk2.groups.io Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Kumar, Rahul1 <rahul1.kumar@intel.com>; Fu, Siyuan <siyuan.fu@intel.com> Subject: [edk2-devel] [PATCH v4 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3815 This patch define a new Protocol with the new services SmmWaitForAllProcessor(), which can be used by SMI handler to optionally wait for other APs to complete SMM rendezvous in relaxed AP mode. A new library SmmCpuRendezvousLib is provided to abstract the service into library API to simple SMI handler code. Patch_v3 modified to pass CI test. (1)Add SmmCpuRendezvousLib.inf into UefiCpuPkg.dsc <LibraryClasses>/<Component> (2)Add SmmCpuRendezvousLib.h in UefiCpuPkg.dec [Libraryclasses.IA32, Libraryclasses.x64] (3) Some UncrustifyCheck modifications. Cc: Eric Dong <eric.dong@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: Rahul Kumar <rahul1.kumar@intel.com> Cc: Siyuan Fu <siyuan.fu@intel.com> Signed-off-by: Zhihao Li <zhihao.li@intel.com> --- UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c | 98 ++++++++++++++++++++ UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 68 +++++++++++++- UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 20 +++- UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h | 27 ++++++ UefiCpuPkg/Include/Protocol/SmmCpuService.h | 36 ++++++- UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf | 35 +++++++ UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 29 +++++- UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 5 +- UefiCpuPkg/UefiCpuPkg.dec | 8 +- UefiCpuPkg/UefiCpuPkg.dsc | 2 + 10 files changed, 316 insertions(+), 12 deletions(-) diff --git a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c new file mode 100644 index 000000000000..22f694b77d51 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c @@ -0,0 +1,98 @@ +/** @file + SMM CPU Rendezvous sevice implement. + + Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Base.h> +#include <Uefi.h> +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/MmServicesTableLib.h> +#include <Protocol/SmmCpuService.h> +#include <Library/SmmCpuRendezvousLib.h> + +STATIC EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *mSmmCpuRendezvous = NULL; +STATIC VOID *mRegistration = NULL; + +/** + Register status code callback function only when Report Status Code + protocol + is installed. + + @param[in] Protocol Points to the protocol's unique identifier. + @param[in] Interface Points to the interface instance. + @param[in] Handle The handle on which the interface was installed. + + @retval EFI_SUCCESS Notification runs successfully. + +**/ +EFI_STATUS +EFIAPI +SmmCpuRendezvousProtocolNotify ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + EFI_STATUS Status; + + Status = gMmst->MmLocateProtocol ( + &gEdkiiSmmCpuRendezvousProtocolGuid, + NULL, + (VOID **)&mSmmCpuRendezvous + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} + +/** + This routine wait for all AP processors to arrive in SMM. + + @param[in] BlockingMode Blocking mode or non-blocking mode. + + @retval EFI_SUCCESS All avaiable APs arrived. + @retval EFI_TIMEOUT Wait for all APs until timeout. + @retval OTHER Fail to register SMM CPU Rendezvous service Protocol. +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN BOOLEAN BlockingMode + ) +{ + EFI_STATUS Status; + + if ((mRegistration == NULL) && (mSmmCpuRendezvous == NULL)) { + // + // Locate SMM cpu rendezvous protocol for the first time execute the function. + // + Status = gMmst->MmLocateProtocol ( + &gEdkiiSmmCpuRendezvousProtocolGuid, + NULL, + (VOID **)&mSmmCpuRendezvous + ); + if (EFI_ERROR (Status)) { + Status = gMmst->MmRegisterProtocolNotify ( + &gEdkiiSmmCpuRendezvousProtocolGuid, + SmmCpuRendezvousProtocolNotify, + &mRegistration + ); + if (EFI_ERROR (Status)) { + return Status; + } + } + } + + if (mSmmCpuRendezvous == NULL) { + return EFI_SUCCESS; + } + + Status = mSmmCpuRendezvous->WaitForAllProcessor ( + mSmmCpuRendezvous, + BlockingMode + ); + return Status; +} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c index 5d624f8e9ed6..e096970ac62e 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c @@ -1,7 +1,7 @@ /** @file Implementation of SMM CPU Services Protocol. -Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -20,6 +20,13 @@ EFI_SMM_CPU_SERVICE_PROTOCOL mSmmCpuService = { SmmRegisterExceptionHandler }; +// +// EDKII SMM CPU Rendezvous Service Protocol instance +// +EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL mSmmCpuRendezvousService = { + SmmWaitForAllProcessor +}; + /** Gets processor information on the requested processor at the instant this call is made. @@ -350,6 +357,7 @@ SmmRegisterExceptionHandler ( @param ImageHandle The firmware allocated handle for the EFI image. @retval EFI_SUCCESS EFI SMM CPU Services Protocol was installed successfully. + @retval OTHER Fail to install Protocol. **/ EFI_STATUS InitializeSmmCpuServices ( @@ -364,6 +372,64 @@ InitializeSmmCpuServices ( EFI_NATIVE_INTERFACE, &mSmmCpuService ); + if (EFI_ERROR (Status)) { + return Status; + } + + Status = gSmst->SmmInstallProtocolInterface ( + &Handle, + &gEdkiiSmmCpuRendezvousProtocolGuid, + EFI_NATIVE_INTERFACE, + &mSmmCpuRendezvousService + ); ASSERT_EFI_ERROR (Status); return Status; } + +/** + Wait for all processors enterring SMM until all CPUs are already synchronized or not. + + If BlockingMode is False, timeout value is zero. + + @param This A pointer to the EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL instance. + @param BlockingMode Blocking mode or non-blocking mode. + + @retval EFI_SUCCESS All avaiable APs arrived. + @retval EFI_TIMEOUT Wait for all APs until timeout. + +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This, + IN BOOLEAN BlockingMode + ) +{ + EFI_STATUS Status; + + // + // Return success immediately if all CPUs are already synchronized. + // + if (mSmmMpSyncData->AllApArrivedWithException) { + Status = EFI_SUCCESS; + goto ON_EXIT; + } + + if (!BlockingMode) { + Status = EFI_TIMEOUT; + goto ON_EXIT; + } + + // + // There are some APs outside SMM, Wait for all avaiable APs to arrive. + // + SmmWaitForApArrival (); + Status = mSmmMpSyncData->AllApArrivedWithException ? EFI_SUCCESS : + EFI_TIMEOUT; + +ON_EXIT: + if (!mSmmMpSyncData->AllApArrivedWithException) { + DEBUG ((DEBUG_INFO, "EdkiiSmmWaitForAllApArrival: Timeout to wait + all APs arrival\n")); + } + + return Status; +} diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c index 882dee4fe246..13c2cb8da4c3 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c @@ -1,7 +1,7 @@ /** @file SMM MP service implementation -Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR> Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -293,10 +293,14 @@ SmmWaitForApArrival ( // Sync with APs 1st timeout // for (Timer = StartSyncTimer (); - !IsSyncTimerTimeout (Timer) && !(LmceEn && LmceSignal) && - !AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED); + !IsSyncTimerTimeout (Timer) && !(LmceEn && LmceSignal); ) { + mSmmMpSyncData->AllApArrivedWithException = + AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | + ARRIVAL_EXCEPTION_SMI_DISABLED); + if (mSmmMpSyncData->AllApArrivedWithException) { + break; + } + CpuPause (); } @@ -330,10 +334,14 @@ SmmWaitForApArrival ( // Sync with APs 2nd timeout. // for (Timer = StartSyncTimer (); - !IsSyncTimerTimeout (Timer) && - !AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | ARRIVAL_EXCEPTION_SMI_DISABLED); + !IsSyncTimerTimeout (Timer); ) { + mSmmMpSyncData->AllApArrivedWithException = + AllCpusInSmmWithExceptions (ARRIVAL_EXCEPTION_BLOCKED | + ARRIVAL_EXCEPTION_SMI_DISABLED); + if (mSmmMpSyncData->AllApArrivedWithException) { + break; + } + CpuPause (); } } @@ -1887,6 +1895,8 @@ InitializeMpSyncData ( *mSmmMpSyncData->InsideSmm = FALSE; *mSmmMpSyncData->AllCpusInSync = FALSE; + mSmmMpSyncData->AllApArrivedWithException = FALSE; + for (CpuIndex = 0; CpuIndex < gSmmCpuPrivate->SmmCoreEntryContext.NumberOfCpus; CpuIndex++) { mSmmMpSyncData->CpuData[CpuIndex].Busy = (SPIN_LOCK *)((UINTN)mSmmCpuSemaphores.SemaphoreCpu.Busy + mSemaphoreSize * CpuIndex); diff --git a/UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h b/UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h new file mode 100644 index 000000000000..82e459e9106e --- /dev/null +++ b/UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h @@ -0,0 +1,27 @@ +/** @file + SMM CPU Rendezvous library header file. + + Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SMM_CPU_RENDEZVOUS_H_ +#define SMM_CPU_RENDEZVOUS_H_ + +/** + This routine wait for all AP processors to arrive in SMM. + + @param[in] BlockingMode Blocking mode or non-blocking mode. + + @retval EFI_SUCCESS All processors checked in to SMM. + @retval EFI_TIMEOUT Wait for all APs until timeout. + +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN BOOLEAN BlockingMode + ); + +#endif diff --git a/UefiCpuPkg/Include/Protocol/SmmCpuService.h b/UefiCpuPkg/Include/Protocol/SmmCpuService.h index 952767afce75..3d93d243409c 100644 --- a/UefiCpuPkg/Include/Protocol/SmmCpuService.h +++ b/UefiCpuPkg/Include/Protocol/SmmCpuService.h @@ -1,7 +1,7 @@ /** @file SMM CPU Service protocol definition. -Copyright (c) 2013 - 2015, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2013 - 2022, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ @@ -200,4 +200,38 @@ struct _EFI_SMM_CPU_SERVICE_PROTOCOL { extern EFI_GUID gEfiSmmCpuServiceProtocolGuid; +// +// EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL provide SMM CPU +// rendezvous service support. +// +#define EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL_GUID \ + { \ + 0xaa00d50b, 0x4911, 0x428f, { 0xb9, 0x1a, 0xa5, 0x9d, 0xdb, 0x13, + 0xe2, 0x4c } \ + } + +typedef struct _EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL +EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL; + +/** + Wait for all APs to arrive SMM mode in given timeout constraint. + + @param[in] This A pointer to the EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL instance. + @param[in] BlockingMode Block or non-block mode. + + @retval EFI_SUCCESS All APs have arrived SMM mode except SMI disabled APs. + @retval EFI_TIMEOUT There are APs not in SMM mode in given timeout constraint. + +**/ +typedef +EFI_STATUS +(EFIAPI *EDKII_WAIT_FOR_ALL_PROCESSOR)( + IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This, + IN BOOLEAN BlockingMode + ); + +struct _EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL { + EDKII_WAIT_FOR_ALL_PROCESSOR WaitForAllProcessor; +}; + +extern EFI_GUID gEdkiiSmmCpuRendezvousProtocolGuid; + #endif diff --git a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf new file mode 100644 index 000000000000..52374bf6e9b4 --- /dev/null +++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf @@ -0,0 +1,35 @@ +## @file +# SMM CPU Rendezvous service lib. +# +# This is SMM CPU rendezvous service lib that wait for all +# APs to enter SMM mode. +# +# Copyright (c) 2022, Intel Corporation. All rights reserved.<BR> +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SmmCpuRendezvousLib + FILE_GUID = 1509Bb36-9Ba4-438B-B195-Ac5914Db14E2 + MODULE_TYPE = DXE_SMM_DRIVER + LIBRARY_CLASS = SmmCpuRendezvousLib|MM_STANDALONE DXE_SMM_DRIVER + +[Sources] + SmmCpuRendezvousLib.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + MmServicesTableLib + +[Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmApSyncTimeout ## CONSUMES + +[Protocols] + gEdkiiSmmCpuRendezvousProtocolGuid diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h index 26d07c5b5ea0..c7f47a1d2fe5 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h @@ -1,7 +1,7 @@ /** @file Agent Module to load other modules to deploy SMM Entry Vector for X86 CPU. -Copyright (c) 2009 - 2020, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2009 - 2022, Intel Corporation. All rights reserved.<BR> Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent @@ -428,6 +428,7 @@ typedef struct { volatile SMM_CPU_SYNC_MODE EffectiveSyncMode; volatile BOOLEAN SwitchBsp; volatile BOOLEAN *CandidateBsp; + volatile BOOLEAN AllApArrivedWithException; EFI_AP_PROCEDURE StartupProcedure; VOID *StartupProcArgs; } SMM_DISPATCHER_MP_SYNC_DATA; @@ -1488,4 +1489,30 @@ IsRestrictedMemoryAccess ( VOID ); +/** + Choose blocking or non-blocking mode to Wait for all APs. + + @param[in] This A pointer to the EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL instance. + @param[in] BlockingMode Blocking or non-blocking mode. + + @retval EFI_SUCCESS All APs have arrived SMM mode except SMI disabled APs. + @retval EFI_TIMEOUT There are APs not in SMM mode in given timeout constraint. + +**/ +EFI_STATUS +EFIAPI +SmmWaitForAllProcessor ( + IN EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL *This, + IN BOOLEAN BlockingMode + ); + +/** + Insure when this function returns, no AP will execute normal mode code before entering SMM, except SMI disabled APs. + +**/ +VOID +SmmWaitForApArrival ( + VOID + ); + #endif diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf index 0e88071c7079..deef00f9c6e9 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf @@ -4,7 +4,7 @@ # This SMM driver performs SMM initialization, deploy SMM Entry Vector, # provides CPU specific services in SMM. # -# Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2009 - 2022, Intel Corporation. All rights +reserved.<BR> # Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -107,7 +107,8 @@ gEfiSmmReadyToLockProtocolGuid ## NOTIFY gEfiSmmCpuServiceProtocolGuid ## PRODUCES gEdkiiSmmMemoryAttributeProtocolGuid ## PRODUCES - gEfiMmMpProtocolGuid ## PRODUCES + gEfiMmMpProtocolGuid ## PRODUCES + gEdkiiSmmCpuRendezvousProtocolGuid ## PRODUCES [Guids] gEfiAcpiVariableGuid ## SOMETIMES_CONSUMES ## HOB # it is used for S3 boot. diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 7de66fde674c..525cde463435 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -1,7 +1,7 @@ ## @file UefiCpuPkg.dec # This Package provides UEFI compatible CPU modules and libraries. # -# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.<BR> +# Copyright (c) 2007 - 2022, Intel Corporation. All rights +reserved.<BR> # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -62,6 +62,9 @@ ## @libraryclass Provides function for loading microcode. MicrocodeLib|Include/Library/MicrocodeLib.h + ## @libraryclass Provides function for SMM CPU Rendezvous Library. + SmmCpuRendezvousLib|Include/Library/SmmCpuRendezvousLib.h + [Guids] gUefiCpuPkgTokenSpaceGuid = { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa, 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }} gMsegSmramGuid = { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1, 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }} @@ -77,7 +80,8 @@ [Protocols] ## Include/Protocol/SmmCpuService.h - gEfiSmmCpuServiceProtocolGuid = { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94, 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }} + gEfiSmmCpuServiceProtocolGuid = { 0x1d202cab, 0xc8ab, 0x4d5c, { 0x94, 0xf7, 0x3c, 0xfc, 0xc0, 0xd3, 0xd3, 0x35 }} + gEdkiiSmmCpuRendezvousProtocolGuid = { 0xaa00d50b, 0x4911, 0x428f, { + 0xb9, 0x1a, 0xa5, 0x9d, 0xdb, 0x13, 0xe2, 0x4c }} ## Include/Protocol/SmMonitorInit.h gEfiSmMonitorInitProtocolGuid = { 0x228f344d, 0xb3de, 0x43bb, { 0xa4, 0xd7, 0xea, 0x20, 0xb, 0x1b, 0x14, 0x82 }} diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index d1d61dd6a03b..a0bbde9985d3 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -61,6 +61,7 @@ TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf MicrocodeLib|UefiCpuPkg/Library/MicrocodeLib/MicrocodeLib.inf + + SmmCpuRendezvousLib|UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRende + zvousLib.inf [LibraryClasses.common.SEC] PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.inf @@ -173,6 +174,7 @@ } UefiCpuPkg/Universal/Acpi/S3Resume2Pei/S3Resume2Pei.inf UefiCpuPkg/ResetVector/Vtf0/Bin/ResetVector.inf + UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf [BuildOptions] *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES -- 2.26.2.windows.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-01 8:48 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-02-23 12:59 [PATCH v4 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support Li, Zhihao [not found] ` <MWHPR11MB15989DD6418D50088C598AEFEB029@MWHPR11MB1598.namprd11.prod.outlook.com> 2022-03-01 8:10 ` FW: [edk2-devel] " Li, Zhihao 2022-03-01 8:48 ` Ni, Ray
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox