Re: [edk2-devel] [PATCH v2 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support.

2022-02-28 Thread Ni, Ray
1. InitializeSmmCpuServices(): please keep the ASSERT_EFI_ERROR (Status) for 
CpuService protocol installation.
2. SmmWaitForApArrival (): Can you remove the BlockingMode parameter because I 
cannot find any invocation using FALSE as parameter.
3. mSmmMpSyncData->AllApArrivedWithException: where is this variable assigned 
to TRUE?
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?
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?

Thanks,
Ray

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Li, Zhihao
Sent: Wednesday, February 23, 2022 2:42 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Ni, Ray ; Kumar, Rahul1 
; Fu, Siyuan 
Subject: [edk2-devel] [PATCH v2 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 / (2)Add SmmCpuRendezvousLib.h in 
UefiCpuPkg.dec [Libraryclasses.IA32, Libraryclasses.x64] (3) Some 
UncrustifyCheck modifications.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Cc: Siyuan Fu 

Signed-off-by: Zhihao Li 
---
 UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c   | 98 

 UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 68 
+-
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c  | 15 ++-
 UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h   | 27 ++
 UefiCpuPkg/Include/Protocol/SmmCpuService.h| 36 ++-
 UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf | 35 +++
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 30 +-
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf   |  5 +-
 UefiCpuPkg/UefiCpuPkg.dec  |  8 +-
 UefiCpuPkg/UefiCpuPkg.dsc  |  2 +
 10 files changed, 314 insertions(+), 10 deletions(-)

diff --git a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c 
b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
new file mode 100644
index ..a53a5a8f301a
--- /dev/null
+++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
@@ -0,0 +1,98 @@
+/** @file

+  SMM CPU Rendezvous sevice implement.

+

+  Copyright (c) 2021 - 2022, Intel Corporation. All rights 
+ reserved.

+  SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#include 

+#include 

+#include 

+#include 

+#include 

+#include 

+#include 

+

+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 OTHERFail 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 (

+  &gEdkiiSmmCpuRendezvo

Re: [edk2-devel] [PATCH v2 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support.

2022-02-23 Thread Li, Zhihao
Send patch v4 following Siyuan comments.

> -Original Message-
> From: Fu, Siyuan 
> Sent: Wednesday, February 23, 2022 6:20 PM
> To: devel@edk2.groups.io; Li, Zhihao 
> Cc: Dong, Eric ; Ni, Ray ; Kumar,
> Rahul1 
> Subject: RE: [edk2-devel] [PATCH v2 1/1] UefiCpuPkg: Extend SMM CPU
> Service with rendezvous support.
> 
> Hi, Zhihao
> 
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of Li,
> > Zhihao
> > Sent: 2022年2月23日 14:42
> > To: devel@edk2.groups.io
> > Cc: Dong, Eric ; Ni, Ray ;
> > Kumar,
> > Rahul1 ; Fu, Siyuan 
> > Subject: [edk2-devel] [PATCH v2 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 / (2)Add
> > SmmCpuRendezvousLib.h in UefiCpuPkg.dec [Libraryclasses.IA32,
> > Libraryclasses.x64] (3) Some UncrustifyCheck modifications.
> >
> > Cc: Eric Dong 
> > Cc: Ray Ni 
> > Cc: Rahul Kumar 
> > Cc: Siyuan Fu 
> >
> > Signed-off-by: Zhihao Li 
> > ---
> >  UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c   |
> 98
> > 
> >  UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 68
> > +-
> >  UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c  | 15 ++-
> >  UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h   | 27 ++
> >  UefiCpuPkg/Include/Protocol/SmmCpuService.h| 36 ++-
> >  UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf |
> 35
> > +++
> >  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 30
> +-
> >  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf   |  5 +-
> >  UefiCpuPkg/UefiCpuPkg.dec  |  8 +-
> >  UefiCpuPkg/UefiCpuPkg.dsc  |  2 +
> >  10 files changed, 314 insertions(+), 10 deletions(-)
> >
> > diff --git
> > a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> > b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> > new file mode 100644
> > index ..a53a5a8f301a
> > --- /dev/null
> > +++
> b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> > @@ -0,0 +1,98 @@
> > +/** @file
> >
> > +  SMM CPU Rendezvous sevice implement.
> >
> > +
> >
> > +  Copyright (c) 2021 - 2022, Intel Corporation. All rights
> > + reserved.
> >
> > +  SPDX-License-Identifier: BSD-2-Clause-Patent
> >
> > +
> >
> > +**/
> >
> > +
> >
> > +#include 
> >
> > +#include 
> >
> > +#include 
> >
> > +#include 
> >
> > +#include 
> >
> > +#include 
> >
> > +#include 
> >
> > +
> >
> > +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,
> >
> > +   

Re: [edk2-devel] [PATCH v2 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support.

2022-02-23 Thread Siyuan, Fu
Hi, Zhihao

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Li, Zhihao
> Sent: 2022年2月23日 14:42
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Ni, Ray ; Kumar,
> Rahul1 ; Fu, Siyuan 
> Subject: [edk2-devel] [PATCH v2 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 / (2)Add
> SmmCpuRendezvousLib.h
> in UefiCpuPkg.dec [Libraryclasses.IA32, Libraryclasses.x64] (3) Some
> UncrustifyCheck modifications.
> 
> Cc: Eric Dong 
> Cc: Ray Ni 
> Cc: Rahul Kumar 
> Cc: Siyuan Fu 
> 
> Signed-off-by: Zhihao Li 
> ---
>  UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c   | 98
> 
>  UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 68
> +-
>  UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c  | 15 ++-
>  UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h   | 27 ++
>  UefiCpuPkg/Include/Protocol/SmmCpuService.h| 36 ++-
>  UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf | 35
> +++
>  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 30 +-
>  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf   |  5 +-
>  UefiCpuPkg/UefiCpuPkg.dec  |  8 +-
>  UefiCpuPkg/UefiCpuPkg.dsc  |  2 +
>  10 files changed, 314 insertions(+), 10 deletions(-)
> 
> diff --git
> a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> new file mode 100644
> index ..a53a5a8f301a
> --- /dev/null
> +++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> @@ -0,0 +1,98 @@
> +/** @file
> 
> +  SMM CPU Rendezvous sevice implement.
> 
> +
> 
> +  Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.
> 
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +
> 
> +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 OTHERFail 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
> fu

[edk2-devel] [PATCH v2 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support.

2022-02-22 Thread Li, Zhihao
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 / (2)Add SmmCpuRendezvousLib.h
in UefiCpuPkg.dec [Libraryclasses.IA32, Libraryclasses.x64] (3) Some
UncrustifyCheck modifications.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Cc: Siyuan Fu 

Signed-off-by: Zhihao Li 
---
 UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c   | 98 

 UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 68 
+-
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c  | 15 ++-
 UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h   | 27 ++
 UefiCpuPkg/Include/Protocol/SmmCpuService.h| 36 ++-
 UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf | 35 +++
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 30 +-
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf   |  5 +-
 UefiCpuPkg/UefiCpuPkg.dec  |  8 +-
 UefiCpuPkg/UefiCpuPkg.dsc  |  2 +
 10 files changed, 314 insertions(+), 10 deletions(-)

diff --git a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c 
b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
new file mode 100644
index ..a53a5a8f301a
--- /dev/null
+++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
@@ -0,0 +1,98 @@
+/** @file

+  SMM CPU Rendezvous sevice implement.

+

+  Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.

+  SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+#include 

+#include 

+#include 

+#include 

+#include 

+#include 

+#include 

+

+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 OTHERFail 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..fceb663fb74f 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.

+Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.

 SPDX-License-Identifier: 

[edk2-devel] [PATCH v2 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support.

2022-02-18 Thread Li, Zhihao
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.

Cc: Eric Dong 
Cc: Ray Ni 
Cc: Rahul Kumar 
Cc: Siyuan Fu 

Signed-off-by: Zhihao Li 
---
 UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c   | 95 

 UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c | 66 
+-
 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c  | 14 ++-
 UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h   | 27 ++
 UefiCpuPkg/Include/Protocol/SmmCpuService.h| 36 +++-
 UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf | 32 +++
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 30 ++-
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf   |  5 +-
 UefiCpuPkg/UefiCpuPkg.dec  |  5 +-
 9 files changed, 300 insertions(+), 10 deletions(-)

diff --git a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c 
b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
new file mode 100644
index ..03e507bf6b52
--- /dev/null
+++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
@@ -0,0 +1,95 @@
+/** @file

+SMM CPU Rendezvous library header file.

+

+Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.

+SPDX-License-Identifier: BSD-2-Clause-Patent

+

+**/

+

+

+#include 

+#include 

+#include 

+#include 

+#include 

+#include 

+#include 

+

+STATIC EDKII_SMM_CPU_RENDEZVOUS_PROTOCOL  *mSmmCpuRendezvous = NULL;

+STATIC VOID   *mSmmCpuRendezvousRegistration = 
NULL;

+

+/**

+  Register status code callback function only when Report Status Code protocol

+  is installed.

+

+  @param Protocol   Points to the protocol's unique identifier.

+  @param Interface  Points to the interface instance.

+  @param Handle The handle on which the interface was installed.

+

+  @retval EFI_SUCCESS   Notification runs successfully.

+

+**/

+EFI_STATUS

+EFIAPI

+SmmCpuServiceProtocolNotify (

+  IN CONST EFI_GUID*Protocol,

+  IN VOID  *Interface,

+  IN EFI_HANDLEHandle

+  )

+{

+  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  BlockingMode  Blocking mode or non-blocking mode.

+

+  @retval EFI_SUCCESSAll avaiable APs arrived.

+  @retval EFI_TIMEOUTWait for all APs until timeout.

+  @retval Other  Fail to register Smm cpu rendezvous services 
notify.

+**/

+EFI_STATUS

+EFIAPI

+SmmWaitForAllProcessor (

+  IN  BOOLEAN  BlockingMode

+  )

+{

+  EFI_STATUS  Status;

+

+  if (mSmmCpuRendezvousRegistration == 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,

+SmmCpuServiceProtocolNotify,

+&mSmmCpuRendezvousRegistration

+);

+  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..85c3c5c15a26 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.

+Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.

 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  mEdkiiSmmCpuRendezvousService = {

+  SmmWaitForAllProcessor

+};

+

 /**

   Gets processor information on the requested processor at