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

2022-02-17 Thread Li, Zhihao
Hi, Michael
With your comment:
1. Decide to define a new Protocol with just the new 
services(gEdkiiSmmCpuRedezvousProtocolGuid)
2. Modified it to 0x00.
3. keep v1
4. keep v1
Other modification:
1. SmmCpuRendezvousLib.inf: add MM_STANDALONE support
2. SmmCpuRendezvousLib.c: remove *constructor function, move its
action into  SmmWaitForAllProcessor function.

> -Original Message-
> From: Fu, Siyuan 
> Sent: Thursday, February 10, 2022 4:19 PM
> To: devel@edk2.groups.io; Kinney, Michael D ;
> Li, Zhihao ; Ni, Ray 
> Cc: Dong, Eric ; Kumar, Rahul1
> 
> Subject: RE: [edk2-devel] [PATCH v1 1/2] UefiCpuPkg: Extend SMM CPU
> Service with rendezvous support.
> 
> Hi, Mike
> 
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of
> Michael
> > D Kinney
> > Sent: 2022年2月9日 0:31
> > To: devel@edk2.groups.io; Li, Zhihao ; Kinney,
> > Michael D 
> > Cc: Dong, Eric ; Ni, Ray ;
> > Kumar,
> > Rahul1 
> > Subject: Re: [edk2-devel] [PATCH v1 1/2] UefiCpuPkg: Extend SMM CPU
> > Service with rendezvous support.
> >
> > Hi Zhihao,
> >
> > gEfiSmmCpuServiceProtocolGuid is defined in the UefiCpuPkg and is
> > already an EDK II specific feature protocol.  Adding an Edkii names
> > version of the protocol does not make it clear that there is a
> > relationship between the two versions of this protocol.  You have
> > added one new service to the existing protocol.  The existing protocol
> > does not have a Revision field so we do have to create a new Protocol
> > Name/Protocol GUID.  Based on previous use cases, we have a few options:
> >
> > 1) If Revision field is present, add to end and increase Revision
> > value
> > 2) If Revision field not present
> >   a) Define an _2 or _Ex version of the protocol with new service(s) added
> >  to end of structure and implement original version of the protocol on
> >  top of the _2 version of the protocol.
> >   b) Define a new Protocol with just the new services. (e.g.
> > gEdkiiSmmCpuRedezvousProtocolGuid)
> We previously discussed with Ray when deciding the protocol name and
> choose the edk2 prefix.
> @Ni, Ray
> Any opinion on using an _Ex version protocol name or a separate protocol?
Decide to define a new Protocol with just the new 
services(gEdkiiSmmCpuRedezvousProtocolGuid)
> 
> >
> > The patch also changes the DEC default value of
> > gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmSyncMode
> > from 0x00 to 0x01.  Changing the default value of a PCD in a DEC file
> > is a non backwards compatible change.  This should not be done.
> > Instead, platforms that need the different sync mode should set that
> > PCD in their DSC file.
Modified it to 0x00.
> >
> > Is a new lib class really required at this time.  The reason to add a
> > new lib class is if there are multiple consumers.
> There are lots of consumers but no in edk2 repo, mostly inside platform code
> like edk2platforms.
> Technically the SMI handler which require all processors in SMM mode to
> complete its task (either due to security consideration or hardware/silicon
> restriction) will need to consume this library interface to complete the
> rendezvous in relax AP mode.
> 
> >
> > I see the lib instance uses a RegisterProtocolNotify in its
> > constructor.  Is it possible to use a Depex instead and eliminate the
> > additional complexity of a constructor and RegisterProtocolNotify?
> We can't use Depex since this is an optional protocol. It's not required to
> those platforms which only have traditional sync mode support.
> 
> Thanks,
> Siyuan
> 
> >
> > Best regards,
> >
> > Mike
> >
> > > -Original Message-
> > > From: devel@edk2.groups.io  On Behalf Of Li,
> > > Zhihao
> > > Sent: Monday, February 7, 2022 9:36 PM
> > > To: devel@edk2.groups.io
> > > Cc: Dong, Eric ; Ni, Ray ;
> > > Kumar,
> > Rahul1 
> > > Subject: [edk2-devel] [PATCH v1 1/2] UefiCpuPkg: Extend SMM CPU
> > > Service
> > with rendezvous support.
> > >
> > > From: Zhihao Li 
> > >
> > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3815
> > >
> > > This patch extends the SMM CPU Service protocol with new interface
> > > 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 
&

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

2022-02-17 Thread Li, Zhihao
Hi Marvin
With your comments:
1. According to granular of prototype (EFI_STATUS).
2. will delete assert and return status
3. Will delete assert and return first error(if so).
Other modification:
1. SmmCpuRendezvousLib.inf: add MM_STANDALONE support
2. SmmCpuRendezvousLib.c: remove *constructor function, move its
action into  SmmWaitForAllProcessor function.


> -Original Message-
> From: Marvin Häuser 
> Sent: Friday, February 11, 2022 6:30 PM
> To: devel@edk2.groups.io; Li, Zhihao 
> Cc: Dong, Eric ; Ni, Ray ; Kumar,
> Rahul1 
> Subject: Re: [edk2-devel] [PATCH v1 1/2] UefiCpuPkg: Extend SMM CPU
> Service with rendezvous support.
> 
> Good day,
> 
> On 08.02.22 06:35, Li, Zhihao wrote:
> > From: Zhihao Li 
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3815
> >
> > This patch extends the SMM CPU Service protocol with new interface
> > 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 
> >
> > Signed-off-by: Zhihao Li 
> > ---
> >   UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c   |
> 109 
> >   UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c |  65
> 
> >   UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c  |  14 ++-
> >   UefiCpuPkg/PiSmmCpuDxeSmm/SyncTimer.c  |   2 +-
> >   UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h   |  27 +
> >   UefiCpuPkg/Include/Protocol/SmmCpuService.h|  40 
> > +++
> >   UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf
> |  32 ++
> >   UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h |  28
> +
> >   UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf   |   3 +-
> >   UefiCpuPkg/UefiCpuPkg.dec  |   5 +-
> >   10 files changed, 318 insertions(+), 7 deletions(-)
> >
> > diff --git
> > a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> > b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> > new file mode 100644
> > index 00..3c5cd51d0c
> > --- /dev/null
> > +++
> b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> > @@ -0,0 +1,109 @@
> > +/** @file
> >
> > +SMM CPU Rendezvous library header file.
> >
> > +
> >
> > +Copyright (c) 2021, Intel Corporation. All rights reserved.
> >
> > +SPDX-License-Identifier: BSD-2-Clause-Patent
> >
> > +
> >
> > +**/
> >
> > +
> >
> > +
> >
> > +#include 
> >
> > +#include 
> >
> > +#include 
> >
> > +#include 
> >
> > +#include 
> >
> > +#include 
> >
> > +#include 
> >
> > +#include 
> >
> > +
> >
> > +STATIC EDKII_SMM_CPU_SERVICE_PROTOCOL  *mSmmCpuService =
> NULL;
> >
> > +
> >
> > +/**
> >
> > +  This routine wait for all AP processors to arrive in SMM.
> >
> > +
> >
> > +  @param  BlockingMode  Blocking mode or non-blocking mode.
> >
> > +
> >
> > +  @retval TRUE   All processors checked in to SMM
> >
> > +  @retval FALSE  Some processor not checked in to SMM
> >
> > +
> >
> > +**/
> >
> > +EFI_STATUS
> >
> > +EFIAPI
> >
> > +SmmWaitForAllProcessor (
> >
> > +  IN  BOOLEAN  BlockingMode
> >
> > +  )
> >
> > +{
> >
> > +  EFI_STATUS Status;
> >
> > +
> >
> > +  if (mSmmCpuService == NULL) {
> >
> > +return TRUE;
> >
> > +  }
> >
> > +
> >
> > +  Status = mSmmCpuService->WaitForAllProcessor (
> >
> > +  mSmmCpuService,
> >
> > +  BlockingMode
> >
> > +  );
> >
> > +  return EFI_ERROR(Status) ? FALSE : TRUE;
> 
> Hmm, if there is a granular error code, why make it less granular by
> conversion? Also the prototype says EFI_STATUS, and the docs say BOOLEAN.
According to granular of prototype (EFI_STATUS).
> 
> >
> > +}
> >
> > +
> >
> > +/**
> >
> > +  Register status code callback function only when Report Status Code
> > + protocol
> >
> &

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

2022-02-11 Thread Marvin Häuser

Good day,

On 08.02.22 06:35, Li, Zhihao wrote:

From: Zhihao Li 

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3815

This patch extends the SMM CPU Service protocol with new interface
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 

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

  UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c |  65 

  UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c  |  14 ++-
  UefiCpuPkg/PiSmmCpuDxeSmm/SyncTimer.c  |   2 +-
  UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h   |  27 +
  UefiCpuPkg/Include/Protocol/SmmCpuService.h|  40 +++
  UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf |  32 ++
  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h |  28 +
  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf   |   3 +-
  UefiCpuPkg/UefiCpuPkg.dec  |   5 +-
  10 files changed, 318 insertions(+), 7 deletions(-)

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

+SMM CPU Rendezvous library header file.

+

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

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

+

+**/

+

+

+#include 

+#include 

+#include 

+#include 

+#include 

+#include 

+#include 

+#include 

+

+STATIC EDKII_SMM_CPU_SERVICE_PROTOCOL  *mSmmCpuService = NULL;

+

+/**

+  This routine wait for all AP processors to arrive in SMM.

+

+  @param  BlockingMode  Blocking mode or non-blocking mode.

+

+  @retval TRUE   All processors checked in to SMM

+  @retval FALSE  Some processor not checked in to SMM

+

+**/

+EFI_STATUS

+EFIAPI

+SmmWaitForAllProcessor (

+  IN  BOOLEAN  BlockingMode

+  )

+{

+  EFI_STATUS Status;

+

+  if (mSmmCpuService == NULL) {

+return TRUE;

+  }

+

+  Status = mSmmCpuService->WaitForAllProcessor (

+  mSmmCpuService,

+  BlockingMode

+  );

+  return EFI_ERROR(Status) ? FALSE : TRUE;


Hmm, if there is a granular error code, why make it less granular by 
conversion? Also the prototype says EFI_STATUS, and the docs say BOOLEAN.




+}

+

+/**

+  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 = gSmst->SmmLocateProtocol (

+,

+NULL,

+(VOID **) 

+);

+  ASSERT_EFI_ERROR (Status);

+

+  return EFI_SUCCESS;

+}

+

+/**

+  The constructor function

+

+  @param[in]  ImageHandle  The firmware allocated handle for the EFI image.

+  @param[in]  SystemTable  A pointer to the EFI System Table.

+

+  @retval EFI_SUCCESS  The constructor always returns EFI_SUCCESS.

+

+**/

+EFI_STATUS

+EFIAPI

+SmmCpuRendezvousLibConstructor (

+  IN EFI_HANDLEImageHandle,

+  IN EFI_SYSTEM_TABLE  *SystemTable

+  )

+{

+  EFI_STATUS  Status;

+  VOID*Registration;

+

+  Status = gSmst->SmmLocateProtocol (, NULL, (VOID 
**) );

+  if (EFI_ERROR (Status)) {

+Status = gSmst->SmmRegisterProtocolNotify (

+,

+SmmCpuServiceProtocolNotify,

+

+);

+ASSERT_EFI_ERROR (Status);


This might as well fail, why ASSERT? This would be a good candidate for 
the upcoming panic API I guess. :)




+  }

+  return EFI_SUCCESS;

+}
\ No newline at end of file
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c 
b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c
index 5d624f8e9e..34019c24ff 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c
@@ -20,6 +20,19 @@ EFI_SMM_CPU_SERVICE_PROTOCOL  mSmmCpuService = {
SmmRegisterExceptionHandler

  };

  


+//

+// EDKII SMM CPU Service Protocol instance

+//

+EDKII_SMM_CPU_SERVICE_PROTOCOL  mEdkiiSmmCpuService = {

+  SmmGetProcessorInfo,

+  SmmSwitchBsp,

+  

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

2022-02-11 Thread Marvin Häuser

Hey all,

On 10.02.22 09:18, Siyuan, Fu wrote:

Hi, Mike


-Original Message-
From: devel@edk2.groups.io  On Behalf Of Michael D
Kinney
Sent: 2022年2月9日 0:31
To: devel@edk2.groups.io; Li, Zhihao ; Kinney, Michael D

Cc: Dong, Eric ; Ni, Ray ; Kumar,
Rahul1 
Subject: Re: [edk2-devel] [PATCH v1 1/2] UefiCpuPkg: Extend SMM CPU Service
with rendezvous support.

Hi Zhihao,

gEfiSmmCpuServiceProtocolGuid is defined in the UefiCpuPkg and is already an
EDK II specific feature protocol.  Adding an Edkii names version of the
protocol does not make it clear that there is a relationship between the
two versions of this protocol.  You have added one new service to the
existing protocol.  The existing protocol does not have a Revision field
so we do have to create a new Protocol Name/Protocol GUID.  Based on
previous use cases, we have a few options:

1) If Revision field is present, add to end and increase Revision value
2) If Revision field not present
   a) Define an _2 or _Ex version of the protocol with new service(s) added
  to end of structure and implement original version of the protocol on
  top of the _2 version of the protocol.
   b) Define a new Protocol with just the new services. (e.g.
gEdkiiSmmCpuRedezvousProtocolGuid)

We previously discussed with Ray when deciding the protocol name and choose
the edk2 prefix.
@Ni, Ray
Any opinion on using an _Ex version protocol name or a separate protocol?


I would strongly suggest to drop the "Ex" naming scheme entirely in the 
future for the simple reason of incrementing further. Some protocols 
already reached major version 3, and it would be awkward to have 
something like "ExExProtocol".


Best regards,
Marvin




The patch also changes the DEC default value of
gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmSyncMode
from 0x00 to 0x01.  Changing the default value of a PCD in a DEC file is a non
backwards compatible change.  This should not be done.  Instead, platforms that
need
the different sync mode should set that PCD in their DSC file.

Is a new lib class really required at this time.  The reason to add a new lib
class is if there are multiple consumers.

There are lots of consumers but no in edk2 repo, mostly inside platform code 
like edk2platforms.
Technically the SMI handler which require all processors in SMM mode to 
complete its task (either
due to security consideration or hardware/silicon restriction) will need to 
consume this library
interface to complete the rendezvous in relax AP mode.


I see the lib instance uses a RegisterProtocolNotify in its constructor.  Is it
possible to use a Depex instead and eliminate the additional complexity of a
constructor and RegisterProtocolNotify?

We can't use Depex since this is an optional protocol. It's not required to 
those platforms
which only have traditional sync mode support.

Thanks,
Siyuan


Best regards,

Mike


-Original Message-
From: devel@edk2.groups.io  On Behalf Of Li, Zhihao
Sent: Monday, February 7, 2022 9:36 PM
To: devel@edk2.groups.io
Cc: Dong, Eric ; Ni, Ray ; Kumar,

Rahul1 

Subject: [edk2-devel] [PATCH v1 1/2] UefiCpuPkg: Extend SMM CPU Service

with rendezvous support.

From: Zhihao Li 

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3815

This patch extends the SMM CPU Service protocol with new interface
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 

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



  UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c |  65



  UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c  |  14 ++-
  UefiCpuPkg/PiSmmCpuDxeSmm/SyncTimer.c  |   2 +-
  UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h   |  27 +
  UefiCpuPkg/Include/Protocol/SmmCpuService.h|  40 +++
  UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf |  32

++

  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h |  28 +
  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf   |   3 +-
  UefiCpuPkg/UefiCpuPkg.dec  |   5 +-
  10 files changed, 318 insertions(+), 7 deletions(-)

diff --git

a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c

b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
new file mode 100644
index 00..3c5cd51d0c
--- /dev/null
+++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
@@ -0,0 +1,109 @@
+/** @file

+SMM CPU Rendezvous library header file.

+

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

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

+

+**/

+

+

+#include 

+#include 

+

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

2022-02-10 Thread Siyuan, Fu
Hi, Mike

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Michael D
> Kinney
> Sent: 2022年2月9日 0:31
> To: devel@edk2.groups.io; Li, Zhihao ; Kinney, Michael D
> 
> Cc: Dong, Eric ; Ni, Ray ; Kumar,
> Rahul1 
> Subject: Re: [edk2-devel] [PATCH v1 1/2] UefiCpuPkg: Extend SMM CPU Service
> with rendezvous support.
> 
> Hi Zhihao,
> 
> gEfiSmmCpuServiceProtocolGuid is defined in the UefiCpuPkg and is already an
> EDK II specific feature protocol.  Adding an Edkii names version of the
> protocol does not make it clear that there is a relationship between the
> two versions of this protocol.  You have added one new service to the
> existing protocol.  The existing protocol does not have a Revision field
> so we do have to create a new Protocol Name/Protocol GUID.  Based on
> previous use cases, we have a few options:
> 
> 1) If Revision field is present, add to end and increase Revision value
> 2) If Revision field not present
>   a) Define an _2 or _Ex version of the protocol with new service(s) added
>  to end of structure and implement original version of the protocol on
>  top of the _2 version of the protocol.
>   b) Define a new Protocol with just the new services. (e.g.
> gEdkiiSmmCpuRedezvousProtocolGuid)
We previously discussed with Ray when deciding the protocol name and choose
the edk2 prefix.
@Ni, Ray
Any opinion on using an _Ex version protocol name or a separate protocol?

> 
> The patch also changes the DEC default value of
> gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmSyncMode
> from 0x00 to 0x01.  Changing the default value of a PCD in a DEC file is a non
> backwards compatible change.  This should not be done.  Instead, platforms 
> that
> need
> the different sync mode should set that PCD in their DSC file.
> 
> Is a new lib class really required at this time.  The reason to add a new lib
> class is if there are multiple consumers.
There are lots of consumers but no in edk2 repo, mostly inside platform code 
like edk2platforms.
Technically the SMI handler which require all processors in SMM mode to 
complete its task (either
due to security consideration or hardware/silicon restriction) will need to 
consume this library
interface to complete the rendezvous in relax AP mode.

> 
> I see the lib instance uses a RegisterProtocolNotify in its constructor.  Is 
> it
> possible to use a Depex instead and eliminate the additional complexity of a
> constructor and RegisterProtocolNotify?
We can't use Depex since this is an optional protocol. It's not required to 
those platforms
which only have traditional sync mode support.

Thanks,
Siyuan

> 
> Best regards,
> 
> Mike
> 
> > -Original Message-
> > From: devel@edk2.groups.io  On Behalf Of Li, Zhihao
> > Sent: Monday, February 7, 2022 9:36 PM
> > To: devel@edk2.groups.io
> > Cc: Dong, Eric ; Ni, Ray ; Kumar,
> Rahul1 
> > Subject: [edk2-devel] [PATCH v1 1/2] UefiCpuPkg: Extend SMM CPU Service
> with rendezvous support.
> >
> > From: Zhihao Li 
> >
> > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3815
> >
> > This patch extends the SMM CPU Service protocol with new interface
> > 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 
> >
> > Signed-off-by: Zhihao Li 
> > ---
> >  UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c   | 109
> 
> >  UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c |  65
> 
> >  UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c  |  14 ++-
> >  UefiCpuPkg/PiSmmCpuDxeSmm/SyncTimer.c  |   2 +-
> >  UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h   |  27 +
> >  UefiCpuPkg/Include/Protocol/SmmCpuService.h|  40 
> > +++
> >  UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf |  32
> ++
> >  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h |  28 +
> >  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf   |   3 +-
> >  UefiCpuPkg/UefiCpuPkg.dec  |   5 +-
> >  10 files changed, 318 insertions(+), 7 deletions(-)
> >
> > diff --git
> a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> > b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> > new file mode 100644
> > index 00..3c5cd5

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

2022-02-08 Thread Michael D Kinney
Hi Zhihao,

gEfiSmmCpuServiceProtocolGuid is defined in the UefiCpuPkg and is already an
EDK II specific feature protocol.  Adding an Edkii names version of the 
protocol does not make it clear that there is a relationship between the 
two versions of this protocol.  You have added one new service to the
existing protocol.  The existing protocol does not have a Revision field
so we do have to create a new Protocol Name/Protocol GUID.  Based on
previous use cases, we have a few options:

1) If Revision field is present, add to end and increase Revision value
2) If Revision field not present
  a) Define an _2 or _Ex version of the protocol with new service(s) added
 to end of structure and implement original version of the protocol on
 top of the _2 version of the protocol.
  b) Define a new Protocol with just the new services. (e.g. 
gEdkiiSmmCpuRedezvousProtocolGuid)

The patch also changes the DEC default value of 
gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmSyncMode
from 0x00 to 0x01.  Changing the default value of a PCD in a DEC file is a non
backwards compatible change.  This should not be done.  Instead, platforms that 
need
the different sync mode should set that PCD in their DSC file.

Is a new lib class really required at this time.  The reason to add a new lib
class is if there are multiple consumers.

I see the lib instance uses a RegisterProtocolNotify in its constructor.  Is it
possible to use a Depex instead and eliminate the additional complexity of a
constructor and RegisterProtocolNotify?

Best regards,

Mike

> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Li, Zhihao
> Sent: Monday, February 7, 2022 9:36 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric ; Ni, Ray ; Kumar, 
> Rahul1 
> Subject: [edk2-devel] [PATCH v1 1/2] UefiCpuPkg: Extend SMM CPU Service with 
> rendezvous support.
> 
> From: Zhihao Li 
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3815
> 
> This patch extends the SMM CPU Service protocol with new interface
> 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 
> 
> Signed-off-by: Zhihao Li 
> ---
>  UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c   | 109 
> 
>  UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c |  65 
> 
>  UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c  |  14 ++-
>  UefiCpuPkg/PiSmmCpuDxeSmm/SyncTimer.c  |   2 +-
>  UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h   |  27 +
>  UefiCpuPkg/Include/Protocol/SmmCpuService.h|  40 +++
>  UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf |  32 ++
>  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h |  28 +
>  UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf   |   3 +-
>  UefiCpuPkg/UefiCpuPkg.dec  |   5 +-
>  10 files changed, 318 insertions(+), 7 deletions(-)
> 
> diff --git a/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> new file mode 100644
> index 00..3c5cd51d0c
> --- /dev/null
> +++ b/UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.c
> @@ -0,0 +1,109 @@
> +/** @file
> 
> +SMM CPU Rendezvous library header file.
> 
> +
> 
> +Copyright (c) 2021, Intel Corporation. All rights reserved.
> 
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> +
> 
> +**/
> 
> +
> 
> +
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +#include 
> 
> +
> 
> +STATIC EDKII_SMM_CPU_SERVICE_PROTOCOL  *mSmmCpuService = NULL;
> 
> +
> 
> +/**
> 
> +  This routine wait for all AP processors to arrive in SMM.
> 
> +
> 
> +  @param  BlockingMode  Blocking mode or non-blocking mode.
> 
> +
> 
> +  @retval TRUE   All processors checked in to SMM
> 
> +  @retval FALSE  Some processor not checked in to SMM
> 
> +
> 
> +**/
> 
> +EFI_STATUS
> 
> +EFIAPI
> 
> +SmmWaitForAllProcessor (
> 
> +  IN  BOOLEAN  BlockingMode
> 
> +  )
> 
> +{
> 
> +  EFI_STATUS Status;
> 
> +
> 
> +  if (mSmmCpuService == NULL) {
> 
> +return TRUE;
> 
> +  }
> 
> +
> 
> +  Status = mSmmCpuService->WaitForAllProcessor (
> 
> +  mSmmCpuService,
> 
> +  BlockingMode
> 
>

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

2022-02-07 Thread Li, Zhihao
From: Zhihao Li 

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3815

This patch extends the SMM CPU Service protocol with new interface
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 

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

 UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c |  65 

 UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c  |  14 ++-
 UefiCpuPkg/PiSmmCpuDxeSmm/SyncTimer.c  |   2 +-
 UefiCpuPkg/Include/Library/SmmCpuRendezvousLib.h   |  27 +
 UefiCpuPkg/Include/Protocol/SmmCpuService.h|  40 +++
 UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf |  32 ++
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h |  28 +
 UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf   |   3 +-
 UefiCpuPkg/UefiCpuPkg.dec  |   5 +-
 10 files changed, 318 insertions(+), 7 deletions(-)

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

+SMM CPU Rendezvous library header file.

+

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

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

+

+**/

+

+

+#include 

+#include 

+#include 

+#include 

+#include 

+#include 

+#include 

+#include 

+

+STATIC EDKII_SMM_CPU_SERVICE_PROTOCOL  *mSmmCpuService = NULL;

+

+/**

+  This routine wait for all AP processors to arrive in SMM.

+

+  @param  BlockingMode  Blocking mode or non-blocking mode.

+

+  @retval TRUE   All processors checked in to SMM

+  @retval FALSE  Some processor not checked in to SMM

+

+**/

+EFI_STATUS

+EFIAPI

+SmmWaitForAllProcessor (

+  IN  BOOLEAN  BlockingMode

+  )

+{

+  EFI_STATUS Status;

+

+  if (mSmmCpuService == NULL) {

+return TRUE;

+  }

+

+  Status = mSmmCpuService->WaitForAllProcessor (

+  mSmmCpuService,

+  BlockingMode

+  );

+  return EFI_ERROR(Status) ? FALSE : TRUE;

+}

+

+/**

+  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 = gSmst->SmmLocateProtocol (

+,

+NULL,

+(VOID **) 

+);

+  ASSERT_EFI_ERROR (Status);

+

+  return EFI_SUCCESS;

+}

+

+/**

+  The constructor function

+

+  @param[in]  ImageHandle  The firmware allocated handle for the EFI image.

+  @param[in]  SystemTable  A pointer to the EFI System Table.

+

+  @retval EFI_SUCCESS  The constructor always returns EFI_SUCCESS.

+

+**/

+EFI_STATUS

+EFIAPI

+SmmCpuRendezvousLibConstructor (

+  IN EFI_HANDLEImageHandle,

+  IN EFI_SYSTEM_TABLE  *SystemTable

+  )

+{

+  EFI_STATUS  Status;

+  VOID*Registration;

+

+  Status = gSmst->SmmLocateProtocol (, NULL, 
(VOID **) );

+  if (EFI_ERROR (Status)) {

+Status = gSmst->SmmRegisterProtocolNotify (

+,

+SmmCpuServiceProtocolNotify,

+

+);

+ASSERT_EFI_ERROR (Status);

+  }

+  return EFI_SUCCESS;

+}
\ No newline at end of file
diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c 
b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c
index 5d624f8e9e..34019c24ff 100644
--- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c
+++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuService.c
@@ -20,6 +20,19 @@ EFI_SMM_CPU_SERVICE_PROTOCOL  mSmmCpuService = {
   SmmRegisterExceptionHandler

 };

 

+//

+// EDKII SMM CPU Service Protocol instance

+//

+EDKII_SMM_CPU_SERVICE_PROTOCOL  mEdkiiSmmCpuService = {

+  SmmGetProcessorInfo,

+  SmmSwitchBsp,

+  SmmAddProcessor,

+  SmmRemoveProcessor,

+  SmmWhoAmI,

+  SmmRegisterExceptionHandler,

+  SmmWaitForAllProcessor

+};

+

 /**

   Gets processor information on the requested processor at the instant this 
call is made.

 

@@ -365,5 +378,57 @@ InitializeSmmCpuServices (
 

 );