[PATCH v1 1/1] CryptPkg: Enable CryptoPkg BaseCryptLib ParallelHash for PEI and DXE
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4097
The BaseCryptLib in the CryptoPkg currently supports ParallelHash
algorithm for SMM. The MP Services PPI and MP Services Protocol
could be used to enable ParallelHash in PEI and DXE
versions of the BaseCryptLib.
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jian J Wang <jian.j.wang@...>
Signed-off-by: Zhihao Li <zhihao.li@...>
---
CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c | 49 ++++++++++++=
++++++
CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c | 35 +++++++++++++
CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c | 54 ++++++++++++=
++++++++
CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c | 26 +---------
CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf | 11 +++-
CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h | 23 +++++++++
CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf | 11 +++-
CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf | 1 +
8 files changed, 183 insertions(+), 27 deletions(-)
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c b/Cry=
ptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c
new file mode 100644
index 000000000000..607aa7cd48d2
--- /dev/null
+++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c
@@ -0,0 +1,49 @@
+/** @file=0D
+ Dispatch Block to Aps in Dxe phase for parallelhash algorithm.=0D
+=0D
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>=0D
+SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#include "CryptParallelHash.h"=0D
+#include <Library/UefiBootServicesTableLib.h>=0D
+#include <Protocol/MpService.h>=0D
+=0D
+/**=0D
+ Dispatch the block task to each AP in PEI phase.=0D
+=0D
+**/=0D
+VOID=0D
+EFIAPI=0D
+DispatchBlockToAp (=0D
+ VOID=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ EFI_MP_SERVICES_PROTOCOL *MpServices;=0D
+=0D
+ Status =3D gBS->LocateProtocol (=0D
+ &gEfiMpServiceProtocolGuid,=0D
+ NULL,=0D
+ (VOID **)&MpServices=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ //=0D
+ // Failed to locate MpServices Protocol, do parallel hash by one core.=
=0D
+ //=0D
+ DEBUG ((DEBUG_ERROR, "[DispatchBlockToApDxe] Failed to locate MpServic=
es Protocol. Status =3D %r\n", Status));=0D
+ return;=0D
+ }=0D
+=0D
+ Status =3D MpServices->StartupAllAPs (=0D
+ MpServices,=0D
+ ParallelHashApExecute,=0D
+ FALSE,=0D
+ NULL,=0D
+ 0,=0D
+ NULL,=0D
+ NULL=0D
+ );=0D
+ return;=0D
+}=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c b/Cryp=
toPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c
new file mode 100644
index 000000000000..0237fb38bcb6
--- /dev/null
+++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c
@@ -0,0 +1,35 @@
+/** @file=0D
+ Dispatch the block task to each AP in Smm mode for parallelhash algorith=
m.=0D
+=0D
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>=0D
+SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#include "CryptParallelHash.h"=0D
+#include <Library/MmServicesTableLib.h>=0D
+=0D
+/**=0D
+ Dispatch the block task to each AP in SMM mode.=0D
+=0D
+**/=0D
+VOID=0D
+EFIAPI=0D
+DispatchBlockToAp (=0D
+ VOID=0D
+ )=0D
+{=0D
+ UINTN Index;=0D
+=0D
+ if (gMmst =3D=3D NULL) {=0D
+ return;=0D
+ }=0D
+=0D
+ for (Index =3D 0; Index < gMmst->NumberOfCpus; Index++) {=0D
+ if (Index !=3D gMmst->CurrentlyExecutingCpu) {=0D
+ gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL);=0D
+ }=0D
+ }=0D
+=0D
+ return;=0D
+}=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c b/Cry=
ptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c
new file mode 100644
index 000000000000..9ddd23d32048
--- /dev/null
+++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c
@@ -0,0 +1,54 @@
+/** @file=0D
+ Dispatch Block to Aps in Pei phase for parallelhash algorithm.=0D
+=0D
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>=0D
+SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#include "CryptParallelHash.h"=0D
+#include <Library/PeiServicesTablePointerLib.h>=0D
+#include <PiPei.h>=0D
+#include <Ppi/MpServices.h>=0D
+#include <Library/PeiServicesLib.h>=0D
+=0D
+/**=0D
+ Dispatch the block task to each AP in PEI phase.=0D
+=0D
+**/=0D
+VOID=0D
+EFIAPI=0D
+DispatchBlockToAp (=0D
+ VOID=0D
+ )=0D
+{=0D
+ EFI_STATUS Status;=0D
+ CONST EFI_PEI_SERVICES **PeiServices;=0D
+ EFI_PEI_MP_SERVICES_PPI *MpServicesPpi;=0D
+=0D
+ PeiServices =3D GetPeiServicesTablePointer ();=0D
+ Status =3D (*PeiServices)->LocatePpi (=0D
+ PeiServices,=0D
+ &gEfiPeiMpServicesPpiGuid,=0D
+ 0,=0D
+ NULL,=0D
+ (VOID **)&MpServicesPpi=0D
+ );=0D
+ if (EFI_ERROR (Status)) {=0D
+ //=0D
+ // Failed to locate MpServices Ppi, do parallel hash by one core.=0D
+ //=0D
+ DEBUG ((DEBUG_ERROR, "[DispatchBlockToApPei] Failed to locate MpServic=
es Ppi. Status =3D %r\n", Status));=0D
+ return;=0D
+ }=0D
+=0D
+ Status =3D MpServicesPpi->StartupAllAPs (=0D
+ (CONST EFI_PEI_SERVICES **)PeiServices,=0D
+ MpServicesPpi,=0D
+ ParallelHashApExecute,=0D
+ FALSE,=0D
+ 0,=0D
+ NULL=0D
+ );=0D
+ return;=0D
+}=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c b/Cryp=
toPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
index f7ce9dbf523e..2931123736e3 100644
--- a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
+++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
@@ -7,7 +7,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/=0D
=0D
#include "CryptParallelHash.h"=0D
-#include <Library/MmServicesTableLib.h>=0D
#include <Library/SynchronizationLib.h>=0D
=0D
#define PARALLELHASH_CUSTOMIZATION "ParallelHash"=0D
@@ -69,27 +68,6 @@ ParallelHashApExecute (
}=0D
}=0D
=0D
-/**=0D
- Dispatch the block task to each AP in SMM mode.=0D
-=0D
-**/=0D
-VOID=0D
-EFIAPI=0D
-MmDispatchBlockToAP (=0D
- VOID=0D
- )=0D
-{=0D
- UINTN Index;=0D
-=0D
- for (Index =3D 0; Index < gMmst->NumberOfCpus; Index++) {=0D
- if (Index !=3D gMmst->CurrentlyExecutingCpu) {=0D
- gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL);=0D
- }=0D
- }=0D
-=0D
- return;=0D
-}=0D
-=0D
/**=0D
Parallel hash function ParallelHash256, as defined in NIST's Special Pub=
lication 800-185,=0D
published December 2016.=0D
@@ -197,9 +175,7 @@ ParallelHash256HashAll (
//=0D
// Dispatch blocklist to each AP.=0D
//=0D
- if (gMmst !=3D NULL) {=0D
- MmDispatchBlockToAP ();=0D
- }=0D
+ DispatchBlockToAp ();=0D
=0D
//=0D
// Wait until all block hash completed.=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf b/CryptoPkg/Li=
brary/BaseCryptLib/BaseCryptLib.inf
index 213813cad971..5be1724f0852 100644
--- a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
@@ -35,7 +35,11 @@
Hash/CryptSha256.c=0D
Hash/CryptSha512.c=0D
Hash/CryptSm3.c=0D
- Hash/CryptParallelHashNull.c=0D
+ Hash/CryptSha3.c=0D
+ Hash/CryptXkcp.c=0D
+ Hash/CryptCShake256.c=0D
+ Hash/CryptParallelHash.c=0D
+ Hash/CryptDispatchApDxe.c=0D
Hmac/CryptHmac.c=0D
Kdf/CryptHkdf.c=0D
Cipher/CryptAes.c=0D
@@ -93,6 +97,11 @@
OpensslLib=0D
IntrinsicLib=0D
PrintLib=0D
+ UefiBootServicesTableLib=0D
+ SynchronizationLib=0D
+=0D
+[Protocols]=0D
+ gEfiMpServiceProtocolGuid=0D
=0D
#=0D
# Remove these [BuildOptions] after this library is cleaned up=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h b/Cryp=
toPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
index dcfe200e5829..03a1a58cb8e7 100644
--- a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
+++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
@@ -201,3 +201,26 @@ CShake256HashAll (
IN UINTN CustomizationLen,=0D
OUT UINT8 *HashValue=0D
);=0D
+=0D
+/**=0D
+ Complete computation of digest of each block.=0D
+=0D
+ Each AP perform the function called by BSP.=0D
+=0D
+ @param[in] ProcedureArgument Argument of the procedure.=0D
+**/=0D
+VOID=0D
+EFIAPI=0D
+ParallelHashApExecute (=0D
+ IN VOID *ProcedureArgument=0D
+ );=0D
+=0D
+/**=0D
+ Dispatch the block task to each AP.=0D
+=0D
+**/=0D
+VOID=0D
+EFIAPI=0D
+DispatchBlockToAp (=0D
+ VOID=0D
+ );=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf b/CryptoPkg/Lib=
rary/BaseCryptLib/PeiCryptLib.inf
index b1629647f9c6..2aafa5f0ac9a 100644
--- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
@@ -40,7 +40,11 @@
Hash/CryptSha256.c=0D
Hash/CryptSm3.c=0D
Hash/CryptSha512.c=0D
- Hash/CryptParallelHashNull.c=0D
+ Hash/CryptSha3.c=0D
+ Hash/CryptXkcp.c=0D
+ Hash/CryptCShake256.c=0D
+ Hash/CryptParallelHash.c=0D
+ Hash/CryptDispatchApPei.c=0D
Hmac/CryptHmac.c=0D
Kdf/CryptHkdf.c=0D
Cipher/CryptAesNull.c=0D
@@ -80,7 +84,12 @@
OpensslLib=0D
IntrinsicLib=0D
PrintLib=0D
+ PeiServicesTablePointerLib=0D
+ PeiServicesLib=0D
+ SynchronizationLib=0D
=0D
+[Ppis]=0D
+ gEfiPeiMpServicesPpiGuid=0D
#=0D
# Remove these [BuildOptions] after this library is cleaned up=0D
#=0D
diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf b/CryptoPkg/Lib=
rary/BaseCryptLib/SmmCryptLib.inf
index 0af7a3f96e8f..00ea7bf4c5df 100644
--- a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
@@ -42,6 +42,7 @@
Hash/CryptXkcp.c=0D
Hash/CryptCShake256.c=0D
Hash/CryptParallelHash.c=0D
+ Hash/CryptDispatchApMm.c=0D
Hmac/CryptHmac.c=0D
Kdf/CryptHkdfNull.c=0D
Cipher/CryptAes.c=0D
--=20
2.26.2.windows.1
Would you please share what test you have run for this?
-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Li,
Zhihao
Sent: Wednesday, November 30, 2022 10:21 PM
To: devel@edk2.groups.io
Cc: Yao, Jiewen <jiewen.yao@...>; Wang, Jian J
<jian.j.wang@...>
Subject: [edk2-devel] [PATCH v1 1/1] CryptPkg: Enable CryptoPkg
BaseCryptLib ParallelHash for PEI and DXE
From: Zhihao Li <zhihao.li@...>
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4097
The BaseCryptLib in the CryptoPkg currently supports ParallelHash
algorithm for SMM. The MP Services PPI and MP Services Protocol
could be used to enable ParallelHash in PEI and DXE
versions of the BaseCryptLib.
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jian J Wang <jian.j.wang@...>
Signed-off-by: Zhihao Li <zhihao.li@...>
---
CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c | 49
++++++++++++++++++
CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c | 35
+++++++++++++
CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c | 54
++++++++++++++++++++
CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c | 26 +---------
CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf | 11 +++-
CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h | 23
+++++++++
CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf | 11 +++-
CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf | 1 +
8 files changed, 183 insertions(+), 27 deletions(-)
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c
b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c
new file mode 100644
index 000000000000..607aa7cd48d2
--- /dev/null
+++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c
@@ -0,0 +1,49 @@
+/** @file
+ Dispatch Block to Aps in Dxe phase for parallelhash algorithm.
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "CryptParallelHash.h"
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/MpService.h>
+
+/**
+ Dispatch the block task to each AP in PEI phase.
+
+**/
+VOID
+EFIAPI
+DispatchBlockToAp (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ EFI_MP_SERVICES_PROTOCOL *MpServices;
+
+ Status = gBS->LocateProtocol (
+ &gEfiMpServiceProtocolGuid,
+ NULL,
+ (VOID **)&MpServices
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // Failed to locate MpServices Protocol, do parallel hash by one core.
+ //
+ DEBUG ((DEBUG_ERROR, "[DispatchBlockToApDxe] Failed to locate
MpServices Protocol. Status = %r\n", Status));
+ return;
+ }
+
+ Status = MpServices->StartupAllAPs (
+ MpServices,
+ ParallelHashApExecute,
+ FALSE,
+ NULL,
+ 0,
+ NULL,
+ NULL
+ );
+ return;
+}
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c
b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c
new file mode 100644
index 000000000000..0237fb38bcb6
--- /dev/null
+++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c
@@ -0,0 +1,35 @@
+/** @file
+ Dispatch the block task to each AP in Smm mode for parallelhash
algorithm.
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "CryptParallelHash.h"
+#include <Library/MmServicesTableLib.h>
+
+/**
+ Dispatch the block task to each AP in SMM mode.
+
+**/
+VOID
+EFIAPI
+DispatchBlockToAp (
+ VOID
+ )
+{
+ UINTN Index;
+
+ if (gMmst == NULL) {
+ return;
+ }
+
+ for (Index = 0; Index < gMmst->NumberOfCpus; Index++) {
+ if (Index != gMmst->CurrentlyExecutingCpu) {
+ gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL);
+ }
+ }
+
+ return;
+}
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c
b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c
new file mode 100644
index 000000000000..9ddd23d32048
--- /dev/null
+++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c
@@ -0,0 +1,54 @@
+/** @file
+ Dispatch Block to Aps in Pei phase for parallelhash algorithm.
+
+Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "CryptParallelHash.h"
+#include <Library/PeiServicesTablePointerLib.h>
+#include <PiPei.h>
+#include <Ppi/MpServices.h>
+#include <Library/PeiServicesLib.h>
+
+/**
+ Dispatch the block task to each AP in PEI phase.
+
+**/
+VOID
+EFIAPI
+DispatchBlockToAp (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ CONST EFI_PEI_SERVICES **PeiServices;
+ EFI_PEI_MP_SERVICES_PPI *MpServicesPpi;
+
+ PeiServices = GetPeiServicesTablePointer ();
+ Status = (*PeiServices)->LocatePpi (
+ PeiServices,
+ &gEfiPeiMpServicesPpiGuid,
+ 0,
+ NULL,
+ (VOID **)&MpServicesPpi
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // Failed to locate MpServices Ppi, do parallel hash by one core.
+ //
+ DEBUG ((DEBUG_ERROR, "[DispatchBlockToApPei] Failed to locate
MpServices Ppi. Status = %r\n", Status));
+ return;
+ }
+
+ Status = MpServicesPpi->StartupAllAPs (
+ (CONST EFI_PEI_SERVICES **)PeiServices,
+ MpServicesPpi,
+ ParallelHashApExecute,
+ FALSE,
+ 0,
+ NULL
+ );
+ return;
+}
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
index f7ce9dbf523e..2931123736e3 100644
--- a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
+++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
@@ -7,7 +7,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "CryptParallelHash.h"
-#include <Library/MmServicesTableLib.h>
#include <Library/SynchronizationLib.h>
#define PARALLELHASH_CUSTOMIZATION "ParallelHash"
@@ -69,27 +68,6 @@ ParallelHashApExecute (
}
}
-/**
- Dispatch the block task to each AP in SMM mode.
-
-**/
-VOID
-EFIAPI
-MmDispatchBlockToAP (
- VOID
- )
-{
- UINTN Index;
-
- for (Index = 0; Index < gMmst->NumberOfCpus; Index++) {
- if (Index != gMmst->CurrentlyExecutingCpu) {
- gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL);
- }
- }
-
- return;
-}
-
/**
Parallel hash function ParallelHash256, as defined in NIST's Special
Publication 800-185,
published December 2016.
@@ -197,9 +175,7 @@ ParallelHash256HashAll (
//
// Dispatch blocklist to each AP.
//
- if (gMmst != NULL) {
- MmDispatchBlockToAP ();
- }
+ DispatchBlockToAp ();
//
// Wait until all block hash completed.
diff --git a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
index 213813cad971..5be1724f0852 100644
--- a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
@@ -35,7 +35,11 @@
Hash/CryptSha256.c
Hash/CryptSha512.c
Hash/CryptSm3.c
- Hash/CryptParallelHashNull.c
+ Hash/CryptSha3.c
+ Hash/CryptXkcp.c
+ Hash/CryptCShake256.c
+ Hash/CryptParallelHash.c
+ Hash/CryptDispatchApDxe.c
Hmac/CryptHmac.c
Kdf/CryptHkdf.c
Cipher/CryptAes.c
@@ -93,6 +97,11 @@
OpensslLib
IntrinsicLib
PrintLib
+ UefiBootServicesTableLib
+ SynchronizationLib
+
+[Protocols]
+ gEfiMpServiceProtocolGuid
#
# Remove these [BuildOptions] after this library is cleaned up
diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
index dcfe200e5829..03a1a58cb8e7 100644
--- a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
+++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
@@ -201,3 +201,26 @@ CShake256HashAll (
IN UINTN CustomizationLen,
OUT UINT8 *HashValue
);
+
+/**
+ Complete computation of digest of each block.
+
+ Each AP perform the function called by BSP.
+
+ @param[in] ProcedureArgument Argument of the procedure.
+**/
+VOID
+EFIAPI
+ParallelHashApExecute (
+ IN VOID *ProcedureArgument
+ );
+
+/**
+ Dispatch the block task to each AP.
+
+**/
+VOID
+EFIAPI
+DispatchBlockToAp (
+ VOID
+ );
diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
index b1629647f9c6..2aafa5f0ac9a 100644
--- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
@@ -40,7 +40,11 @@
Hash/CryptSha256.c
Hash/CryptSm3.c
Hash/CryptSha512.c
- Hash/CryptParallelHashNull.c
+ Hash/CryptSha3.c
+ Hash/CryptXkcp.c
+ Hash/CryptCShake256.c
+ Hash/CryptParallelHash.c
+ Hash/CryptDispatchApPei.c
Hmac/CryptHmac.c
Kdf/CryptHkdf.c
Cipher/CryptAesNull.c
@@ -80,7 +84,12 @@
OpensslLib
IntrinsicLib
PrintLib
+ PeiServicesTablePointerLib
+ PeiServicesLib
+ SynchronizationLib
+[Ppis]
+ gEfiPeiMpServicesPpiGuid
#
# Remove these [BuildOptions] after this library is cleaned up
#
diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
index 0af7a3f96e8f..00ea7bf4c5df 100644
--- a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
+++ b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
@@ -42,6 +42,7 @@
Hash/CryptXkcp.c
Hash/CryptCShake256.c
Hash/CryptParallelHash.c
+ Hash/CryptDispatchApMm.c
Hmac/CryptHmac.c
Kdf/CryptHkdfNull.c
Cipher/CryptAes.c
--
2.26.2.windows.1
-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#96736):
https://edk2.groups.io/g/devel/message/96736
Mute This Topic: https://groups.io/mt/95358558/1772286
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [jiewen.yao@...]
-=-=-=-=-=-=
Yes. I tested parallelhash of CryptoProtocol/CryptoLib in Pei and Dxe phase. I find the log of the test. The file contains logs of many boot processes. Please check from the end of file.
I hope it can be used.
DXE phase:
Pei phase:
From: Yao, Jiewen <jiewen.yao@...>
Sent: Thursday, December 1, 2022 4:37 PM
To: devel@edk2.groups.io; Li, Zhihao <zhihao.li@...>
Cc: Wang, Jian J <jian.j.wang@...>
Subject: RE: [edk2-devel] [PATCH v1 1/1] CryptPkg: Enable CryptoPkg BaseCryptLib ParallelHash for PEI and DXE
Thanks.
Would you please share what test you have run for this?
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Li,
> Zhihao
> Sent: Wednesday, November 30, 2022 10:21 PM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen <jiewen.yao@...>; Wang, Jian J
> <jian.j.wang@...>
> Subject: [edk2-devel] [PATCH v1 1/1] CryptPkg: Enable CryptoPkg
> BaseCryptLib ParallelHash for PEI and DXE
>
> From: Zhihao Li <zhihao.li@...>
>
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4097
>
> The BaseCryptLib in the CryptoPkg currently supports ParallelHash
> algorithm for SMM. The MP Services PPI and MP Services Protocol could
> be used to enable ParallelHash in PEI and DXE versions of the
> BaseCryptLib.
>
> Cc: Jiewen Yao <jiewen.yao@...>
> Cc: Jian J Wang <jian.j.wang@...>
>
> Signed-off-by: Zhihao Li <zhihao.li@...>
> ---
> CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c | 49
> ++++++++++++++++++
> CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c | 35
> +++++++++++++
> CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c | 54
> ++++++++++++++++++++
> CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c | 26 +---------
> CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf | 11 +++-
> CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h | 23
> +++++++++
> CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf | 11 +++-
> CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf | 1 +
> 8 files changed, 183 insertions(+), 27 deletions(-)
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c
> b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c
> new file mode 100644
> index 000000000000..607aa7cd48d2
> --- /dev/null
> +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c
> @@ -0,0 +1,49 @@
> +/** @file
>
> + Dispatch Block to Aps in Dxe phase for parallelhash algorithm.
>
> +
>
> +Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +
>
> +**/
>
> +
>
> +#include "CryptParallelHash.h"
>
> +#include <Library/UefiBootServicesTableLib.h>
>
> +#include <Protocol/MpService.h>
>
> +
>
> +/**
>
> + Dispatch the block task to each AP in PEI phase.
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +DispatchBlockToAp (
>
> + VOID
>
> + )
>
> +{
>
> + EFI_STATUS Status;
>
> + EFI_MP_SERVICES_PROTOCOL *MpServices;
>
> +
>
> + Status = gBS->LocateProtocol (
>
> + &gEfiMpServiceProtocolGuid,
>
> + NULL,
>
> + (VOID **)&MpServices
>
> + );
>
> + if (EFI_ERROR (Status)) {
>
> + //
>
> + // Failed to locate MpServices Protocol, do parallel hash by one core.
>
> + //
>
> + DEBUG ((DEBUG_ERROR, "[DispatchBlockToApDxe] Failed to locate
> MpServices Protocol. Status = %r\n", Status));
>
> + return;
>
> + }
>
> +
>
> + Status = MpServices->StartupAllAPs (
>
> + MpServices,
>
> + ParallelHashApExecute,
>
> + FALSE,
>
> + NULL,
>
> + 0,
>
> + NULL,
>
> + NULL
>
> + );
>
> + return;
>
> +}
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c
> b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c
> new file mode 100644
> index 000000000000..0237fb38bcb6
> --- /dev/null
> +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c
> @@ -0,0 +1,35 @@
> +/** @file
>
> + Dispatch the block task to each AP in Smm mode for parallelhash
> algorithm.
>
> +
>
> +Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +
>
> +**/
>
> +
>
> +#include "CryptParallelHash.h"
>
> +#include <Library/MmServicesTableLib.h>
>
> +
>
> +/**
>
> + Dispatch the block task to each AP in SMM mode.
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +DispatchBlockToAp (
>
> + VOID
>
> + )
>
> +{
>
> + UINTN Index;
>
> +
>
> + if (gMmst == NULL) {
>
> + return;
>
> + }
>
> +
>
> + for (Index = 0; Index < gMmst->NumberOfCpus; Index++) {
>
> + if (Index != gMmst->CurrentlyExecutingCpu) {
>
> + gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL);
>
> + }
>
> + }
>
> +
>
> + return;
>
> +}
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c
> b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c
> new file mode 100644
> index 000000000000..9ddd23d32048
> --- /dev/null
> +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c
> @@ -0,0 +1,54 @@
> +/** @file
>
> + Dispatch Block to Aps in Pei phase for parallelhash algorithm.
>
> +
>
> +Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +
>
> +**/
>
> +
>
> +#include "CryptParallelHash.h"
>
> +#include <Library/PeiServicesTablePointerLib.h>
>
> +#include <PiPei.h>
>
> +#include <Ppi/MpServices.h>
>
> +#include <Library/PeiServicesLib.h>
>
> +
>
> +/**
>
> + Dispatch the block task to each AP in PEI phase.
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +DispatchBlockToAp (
>
> + VOID
>
> + )
>
> +{
>
> + EFI_STATUS Status;
>
> + CONST EFI_PEI_SERVICES **PeiServices;
>
> + EFI_PEI_MP_SERVICES_PPI *MpServicesPpi;
>
> +
>
> + PeiServices = GetPeiServicesTablePointer ();
>
> + Status = (*PeiServices)->LocatePpi (
>
> + PeiServices,
>
> + &gEfiPeiMpServicesPpiGuid,
>
> + 0,
>
> + NULL,
>
> + (VOID **)&MpServicesPpi
>
> + );
>
> + if (EFI_ERROR (Status)) {
>
> + //
>
> + // Failed to locate MpServices Ppi, do parallel hash by one core.
>
> + //
>
> + DEBUG ((DEBUG_ERROR, "[DispatchBlockToApPei] Failed to locate
> MpServices Ppi. Status = %r\n", Status));
>
> + return;
>
> + }
>
> +
>
> + Status = MpServicesPpi->StartupAllAPs (
>
> + (CONST EFI_PEI_SERVICES **)PeiServices,
>
> + MpServicesPpi,
>
> + ParallelHashApExecute,
>
> + FALSE,
>
> + 0,
>
> + NULL
>
> + );
>
> + return;
>
> +}
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
> b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
> index f7ce9dbf523e..2931123736e3 100644
> --- a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
> +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
> @@ -7,7 +7,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
>
>
>
> #include "CryptParallelHash.h"
>
> -#include <Library/MmServicesTableLib.h>
>
> #include <Library/SynchronizationLib.h>
>
>
>
> #define PARALLELHASH_CUSTOMIZATION "ParallelHash"
>
> @@ -69,27 +68,6 @@ ParallelHashApExecute (
> }
>
> }
>
>
>
> -/**
>
> - Dispatch the block task to each AP in SMM mode.
>
> -
>
> -**/
>
> -VOID
>
> -EFIAPI
>
> -MmDispatchBlockToAP (
>
> - VOID
>
> - )
>
> -{
>
> - UINTN Index;
>
> -
>
> - for (Index = 0; Index < gMmst->NumberOfCpus; Index++) {
>
> - if (Index != gMmst->CurrentlyExecutingCpu) {
>
> - gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL);
>
> - }
>
> - }
>
> -
>
> - return;
>
> -}
>
> -
>
> /**
>
> Parallel hash function ParallelHash256, as defined in NIST's
> Special Publication 800-185,
>
> published December 2016.
>
> @@ -197,9 +175,7 @@ ParallelHash256HashAll (
> //
>
> // Dispatch blocklist to each AP.
>
> //
>
> - if (gMmst != NULL) {
>
> - MmDispatchBlockToAP ();
>
> - }
>
> + DispatchBlockToAp ();
>
>
>
> //
>
> // Wait until all block hash completed.
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
> b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
> index 213813cad971..5be1724f0852 100644
> --- a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
> +++ b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
> @@ -35,7 +35,11 @@
> Hash/CryptSha256.c
>
> Hash/CryptSha512.c
>
> Hash/CryptSm3.c
>
> - Hash/CryptParallelHashNull.c
>
> + Hash/CryptSha3.c
>
> + Hash/CryptXkcp.c
>
> + Hash/CryptCShake256.c
>
> + Hash/CryptParallelHash.c
>
> + Hash/CryptDispatchApDxe.c
>
> Hmac/CryptHmac.c
>
> Kdf/CryptHkdf.c
>
> Cipher/CryptAes.c
>
> @@ -93,6 +97,11 @@
> OpensslLib
>
> IntrinsicLib
>
> PrintLib
>
> + UefiBootServicesTableLib
>
> + SynchronizationLib
>
> +
>
> +[Protocols]
>
> + gEfiMpServiceProtocolGuid
>
>
>
> #
>
> # Remove these [BuildOptions] after this library is cleaned up
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
> b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
> index dcfe200e5829..03a1a58cb8e7 100644
> --- a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
> +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
> @@ -201,3 +201,26 @@ CShake256HashAll (
> IN UINTN CustomizationLen,
>
> OUT UINT8 *HashValue
>
> );
>
> +
>
> +/**
>
> + Complete computation of digest of each block.
>
> +
>
> + Each AP perform the function called by BSP.
>
> +
>
> + @param[in] ProcedureArgument Argument of the procedure.
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +ParallelHashApExecute (
>
> + IN VOID *ProcedureArgument
>
> + );
>
> +
>
> +/**
>
> + Dispatch the block task to each AP.
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +DispatchBlockToAp (
>
> + VOID
>
> + );
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
> b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
> index b1629647f9c6..2aafa5f0ac9a 100644
> --- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
> +++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
> @@ -40,7 +40,11 @@
> Hash/CryptSha256.c
>
> Hash/CryptSm3.c
>
> Hash/CryptSha512.c
>
> - Hash/CryptParallelHashNull.c
>
> + Hash/CryptSha3.c
>
> + Hash/CryptXkcp.c
>
> + Hash/CryptCShake256.c
>
> + Hash/CryptParallelHash.c
>
> + Hash/CryptDispatchApPei.c
>
> Hmac/CryptHmac.c
>
> Kdf/CryptHkdf.c
>
> Cipher/CryptAesNull.c
>
> @@ -80,7 +84,12 @@
> OpensslLib
>
> IntrinsicLib
>
> PrintLib
>
> + PeiServicesTablePointerLib
>
> + PeiServicesLib
>
> + SynchronizationLib
>
>
>
> +[Ppis]
>
> + gEfiPeiMpServicesPpiGuid
>
> #
>
> # Remove these [BuildOptions] after this library is cleaned up
>
> #
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
> b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
> index 0af7a3f96e8f..00ea7bf4c5df 100644
> --- a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
> +++ b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
> @@ -42,6 +42,7 @@
> Hash/CryptXkcp.c
>
> Hash/CryptCShake256.c
>
> Hash/CryptParallelHash.c
>
> + Hash/CryptDispatchApMm.c
>
> Hmac/CryptHmac.c
>
> Kdf/CryptHkdfNull.c
>
> Cipher/CryptAes.c
>
> --
> 2.26.2.windows.1
>
>
>
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#96736):
> https://edk2.groups.io/g/devel/message/96736
> Mute This Topic: https://groups.io/mt/95358558/1772286
> Group Owner: devel+owner@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub
> [jiewen.yao@...] -=-=-=-=-=-=
>
Sent: Thursday, December 1, 2022 7:43 PM
To: Yao, Jiewen <jiewen.yao@...>; devel@edk2.groups.io
Cc: Wang, Jian J <jian.j.wang@...>
Subject: RE: [edk2-devel] [PATCH v1 1/1] CryptPkg: Enable CryptoPkg BaseCryptLib ParallelHash for PEI and DXE
Yes. I tested parallelhash of CryptoProtocol/CryptoLib in Pei and Dxe phase. I find the log of the test. The file contains logs of many boot processes. Please check from the end of file.
I hope it can be used.
DXE phase:
Pei phase:
-----Original Message-----
From: Yao, Jiewen <jiewen.yao@...>
Sent: Thursday, December 1, 2022 4:37 PM
To: devel@edk2.groups.io; Li, Zhihao <zhihao.li@...>
Cc: Wang, Jian J <jian.j.wang@...>
Subject: RE: [edk2-devel] [PATCH v1 1/1] CryptPkg: Enable CryptoPkg BaseCryptLib ParallelHash for PEI and DXE
Thanks.
Would you please share what test you have run for this?
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Li,
> Zhihao
> Sent: Wednesday, November 30, 2022 10:21 PM
> To: devel@edk2.groups.io
> Cc: Yao, Jiewen <jiewen.yao@...>; Wang, Jian J
> <jian.j.wang@...>
> Subject: [edk2-devel] [PATCH v1 1/1] CryptPkg: Enable CryptoPkg
> BaseCryptLib ParallelHash for PEI and DXE
>
> From: Zhihao Li <zhihao.li@...>
>
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4097
>
> The BaseCryptLib in the CryptoPkg currently supports ParallelHash
> algorithm for SMM. The MP Services PPI and MP Services Protocol could
> be used to enable ParallelHash in PEI and DXE versions of the
> BaseCryptLib.
>
> Cc: Jiewen Yao <jiewen.yao@...>
> Cc: Jian J Wang <jian.j.wang@...>
>
> Signed-off-by: Zhihao Li <zhihao.li@...>
> ---
> CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c | 49
> ++++++++++++++++++
> CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c | 35
> +++++++++++++
> CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c | 54
> ++++++++++++++++++++
> CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c | 26 +---------
> CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf | 11 +++-
> CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h | 23
> +++++++++
> CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf | 11 +++-
> CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf | 1 +
> 8 files changed, 183 insertions(+), 27 deletions(-)
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c
> b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c
> new file mode 100644
> index 000000000000..607aa7cd48d2
> --- /dev/null
> +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApDxe.c
> @@ -0,0 +1,49 @@
> +/** @file
>
> + Dispatch Block to Aps in Dxe phase for parallelhash algorithm.
>
> +
>
> +Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +
>
> +**/
>
> +
>
> +#include "CryptParallelHash.h"
>
> +#include <Library/UefiBootServicesTableLib.h>
>
> +#include <Protocol/MpService.h>
>
> +
>
> +/**
>
> + Dispatch the block task to each AP in PEI phase.
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +DispatchBlockToAp (
>
> + VOID
>
> + )
>
> +{
>
> + EFI_STATUS Status;
>
> + EFI_MP_SERVICES_PROTOCOL *MpServices;
>
> +
>
> + Status = gBS->LocateProtocol (
>
> + &gEfiMpServiceProtocolGuid,
>
> + NULL,
>
> + (VOID **)&MpServices
>
> + );
>
> + if (EFI_ERROR (Status)) {
>
> + //
>
> + // Failed to locate MpServices Protocol, do parallel hash by one core.
>
> + //
>
> + DEBUG ((DEBUG_ERROR, "[DispatchBlockToApDxe] Failed to locate
> MpServices Protocol. Status = %r\n", Status));
>
> + return;
>
> + }
>
> +
>
> + Status = MpServices->StartupAllAPs (
>
> + MpServices,
>
> + ParallelHashApExecute,
>
> + FALSE,
>
> + NULL,
>
> + 0,
>
> + NULL,
>
> + NULL
>
> + );
>
> + return;
>
> +}
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c
> b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c
> new file mode 100644
> index 000000000000..0237fb38bcb6
> --- /dev/null
> +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApMm.c
> @@ -0,0 +1,35 @@
> +/** @file
>
> + Dispatch the block task to each AP in Smm mode for parallelhash
> algorithm.
>
> +
>
> +Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +
>
> +**/
>
> +
>
> +#include "CryptParallelHash.h"
>
> +#include <Library/MmServicesTableLib.h>
>
> +
>
> +/**
>
> + Dispatch the block task to each AP in SMM mode.
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +DispatchBlockToAp (
>
> + VOID
>
> + )
>
> +{
>
> + UINTN Index;
>
> +
>
> + if (gMmst == NULL) {
>
> + return;
>
> + }
>
> +
>
> + for (Index = 0; Index < gMmst->NumberOfCpus; Index++) {
>
> + if (Index != gMmst->CurrentlyExecutingCpu) {
>
> + gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL);
>
> + }
>
> + }
>
> +
>
> + return;
>
> +}
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c
> b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c
> new file mode 100644
> index 000000000000..9ddd23d32048
> --- /dev/null
> +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptDispatchApPei.c
> @@ -0,0 +1,54 @@
> +/** @file
>
> + Dispatch Block to Aps in Pei phase for parallelhash algorithm.
>
> +
>
> +Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
>
> +SPDX-License-Identifier: BSD-2-Clause-Patent
>
> +
>
> +**/
>
> +
>
> +#include "CryptParallelHash.h"
>
> +#include <Library/PeiServicesTablePointerLib.h>
>
> +#include <PiPei.h>
>
> +#include <Ppi/MpServices.h>
>
> +#include <Library/PeiServicesLib.h>
>
> +
>
> +/**
>
> + Dispatch the block task to each AP in PEI phase.
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +DispatchBlockToAp (
>
> + VOID
>
> + )
>
> +{
>
> + EFI_STATUS Status;
>
> + CONST EFI_PEI_SERVICES **PeiServices;
>
> + EFI_PEI_MP_SERVICES_PPI *MpServicesPpi;
>
> +
>
> + PeiServices = GetPeiServicesTablePointer ();
>
> + Status = (*PeiServices)->LocatePpi (
>
> + PeiServices,
>
> + &gEfiPeiMpServicesPpiGuid,
>
> + 0,
>
> + NULL,
>
> + (VOID **)&MpServicesPpi
>
> + );
>
> + if (EFI_ERROR (Status)) {
>
> + //
>
> + // Failed to locate MpServices Ppi, do parallel hash by one core.
>
> + //
>
> + DEBUG ((DEBUG_ERROR, "[DispatchBlockToApPei] Failed to locate
> MpServices Ppi. Status = %r\n", Status));
>
> + return;
>
> + }
>
> +
>
> + Status = MpServicesPpi->StartupAllAPs (
>
> + (CONST EFI_PEI_SERVICES **)PeiServices,
>
> + MpServicesPpi,
>
> + ParallelHashApExecute,
>
> + FALSE,
>
> + 0,
>
> + NULL
>
> + );
>
> + return;
>
> +}
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
> b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
> index f7ce9dbf523e..2931123736e3 100644
> --- a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
> +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.c
> @@ -7,7 +7,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/
>
>
>
> #include "CryptParallelHash.h"
>
> -#include <Library/MmServicesTableLib.h>
>
> #include <Library/SynchronizationLib.h>
>
>
>
> #define PARALLELHASH_CUSTOMIZATION "ParallelHash"
>
> @@ -69,27 +68,6 @@ ParallelHashApExecute (
> }
>
> }
>
>
>
> -/**
>
> - Dispatch the block task to each AP in SMM mode.
>
> -
>
> -**/
>
> -VOID
>
> -EFIAPI
>
> -MmDispatchBlockToAP (
>
> - VOID
>
> - )
>
> -{
>
> - UINTN Index;
>
> -
>
> - for (Index = 0; Index < gMmst->NumberOfCpus; Index++) {
>
> - if (Index != gMmst->CurrentlyExecutingCpu) {
>
> - gMmst->MmStartupThisAp (ParallelHashApExecute, Index, NULL);
>
> - }
>
> - }
>
> -
>
> - return;
>
> -}
>
> -
>
> /**
>
> Parallel hash function ParallelHash256, as defined in NIST's
> Special Publication 800-185,
>
> published December 2016.
>
> @@ -197,9 +175,7 @@ ParallelHash256HashAll (
> //
>
> // Dispatch blocklist to each AP.
>
> //
>
> - if (gMmst != NULL) {
>
> - MmDispatchBlockToAP ();
>
> - }
>
> + DispatchBlockToAp ();
>
>
>
> //
>
> // Wait until all block hash completed.
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
> b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
> index 213813cad971..5be1724f0852 100644
> --- a/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
> +++ b/CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
> @@ -35,7 +35,11 @@
> Hash/CryptSha256.c
>
> Hash/CryptSha512.c
>
> Hash/CryptSm3.c
>
> - Hash/CryptParallelHashNull.c
>
> + Hash/CryptSha3.c
>
> + Hash/CryptXkcp.c
>
> + Hash/CryptCShake256.c
>
> + Hash/CryptParallelHash.c
>
> + Hash/CryptDispatchApDxe.c
>
> Hmac/CryptHmac.c
>
> Kdf/CryptHkdf.c
>
> Cipher/CryptAes.c
>
> @@ -93,6 +97,11 @@
> OpensslLib
>
> IntrinsicLib
>
> PrintLib
>
> + UefiBootServicesTableLib
>
> + SynchronizationLib
>
> +
>
> +[Protocols]
>
> + gEfiMpServiceProtocolGuid
>
>
>
> #
>
> # Remove these [BuildOptions] after this library is cleaned up
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
> b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
> index dcfe200e5829..03a1a58cb8e7 100644
> --- a/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
> +++ b/CryptoPkg/Library/BaseCryptLib/Hash/CryptParallelHash.h
> @@ -201,3 +201,26 @@ CShake256HashAll (
> IN UINTN CustomizationLen,
>
> OUT UINT8 *HashValue
>
> );
>
> +
>
> +/**
>
> + Complete computation of digest of each block.
>
> +
>
> + Each AP perform the function called by BSP.
>
> +
>
> + @param[in] ProcedureArgument Argument of the procedure.
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +ParallelHashApExecute (
>
> + IN VOID *ProcedureArgument
>
> + );
>
> +
>
> +/**
>
> + Dispatch the block task to each AP.
>
> +
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +DispatchBlockToAp (
>
> + VOID
>
> + );
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
> b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
> index b1629647f9c6..2aafa5f0ac9a 100644
> --- a/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
> +++ b/CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
> @@ -40,7 +40,11 @@
> Hash/CryptSha256.c
>
> Hash/CryptSm3.c
>
> Hash/CryptSha512.c
>
> - Hash/CryptParallelHashNull.c
>
> + Hash/CryptSha3.c
>
> + Hash/CryptXkcp.c
>
> + Hash/CryptCShake256.c
>
> + Hash/CryptParallelHash.c
>
> + Hash/CryptDispatchApPei.c
>
> Hmac/CryptHmac.c
>
> Kdf/CryptHkdf.c
>
> Cipher/CryptAesNull.c
>
> @@ -80,7 +84,12 @@
> OpensslLib
>
> IntrinsicLib
>
> PrintLib
>
> + PeiServicesTablePointerLib
>
> + PeiServicesLib
>
> + SynchronizationLib
>
>
>
> +[Ppis]
>
> + gEfiPeiMpServicesPpiGuid
>
> #
>
> # Remove these [BuildOptions] after this library is cleaned up
>
> #
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
> b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
> index 0af7a3f96e8f..00ea7bf4c5df 100644
> --- a/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
> +++ b/CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
> @@ -42,6 +42,7 @@
> Hash/CryptXkcp.c
>
> Hash/CryptCShake256.c
>
> Hash/CryptParallelHash.c
>
> + Hash/CryptDispatchApMm.c
>
> Hmac/CryptHmac.c
>
> Kdf/CryptHkdfNull.c
>
> Cipher/CryptAes.c
>
> --
> 2.26.2.windows.1
>
>
>
> -=-=-=-=-=-=
> Groups.io Links: You receive all messages sent to this group.
> View/Reply Online (#96736):
> https://edk2.groups.io/g/devel/message/96736
> Mute This Topic: https://groups.io/mt/95358558/1772286
> Group Owner: devel+owner@edk2.groups.io
> Unsubscribe: https://edk2.groups.io/g/devel/unsub
> [jiewen.yao@...] -=-=-=-=-=-=
>