public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v1 1/1] SecurityPkg: use SmmWaitForAllProcessor in TcgSmm and Tcg2Smm driver.
@ 2022-06-13  6:24 Li, Zhihao
  0 siblings, 0 replies; 3+ messages in thread
From: Li, Zhihao @ 2022-06-13  6:24 UTC (permalink / raw)
  To: devel; +Cc: Jiewen Yao, Jian J Wang, Rahul Kumar, Qi Zhang

From: Zhihao Li <zhihao.li@intel.com>

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

In UefiCpuPkg, there are a new Protocol with the new service
SmmWaitForAllProcessor(), which can be used by SMI handler
to optionally wait for other APs to complete SMM rendezvous in
relaxed AP mode.

This patch use the new service to let TcgSmm and Tcg2Smm driver work
normally in relaxed AP mode.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Qi Zhang <qi1.zhang@intel.com>

Signed-off-by: Zhihao Li <zhihao.li@intel.com>
---
 SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c            | 21 ++++++++++++++++++--
 SecurityPkg/Tcg/TcgSmm/TcgSmm.c              | 15 ++++++++++++--
 SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h            |  3 ++-
 SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf          |  3 ++-
 SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf |  1 +
 SecurityPkg/Tcg/TcgSmm/TcgSmm.h              |  3 ++-
 SecurityPkg/Tcg/TcgSmm/TcgSmm.inf            |  3 ++-
 7 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
index 498fb626bd9c..4367102fbd49 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
@@ -9,7 +9,7 @@
 
   PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check.
 
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR>
 Copyright (c) Microsoft Corporation.
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -42,6 +42,7 @@ EFI_HANDLE                 mReadyToLockHandle;
                                     should still be called.
   @retval EFI_UNSUPPORTED           An unknown test function was requested.
   @retval EFI_ACCESS_DENIED         Part of the communication buffer lies in an invalid region.
+  @retval EFI_ABORTED               Fail to wait for all AP check in SMM.
 
 **/
 EFI_STATUS
@@ -78,6 +79,11 @@ TpmNvsCommunciate (
     return EFI_ACCESS_DENIED;
   }
 
+  if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+    DEBUG ((DEBUG_ERROR, "TpmNvsCommunciate: fail to wait for all AP check in SMM!\n"));
+    return EFI_ABORTED;
+  }
+
   //
   // Farm out the job to individual functions based on what was requested.
   //
@@ -116,7 +122,7 @@ TpmNvsCommunciate (
   @param[in, out] CommBufferSize  The size of the CommBuffer.
 
   @retval EFI_SUCCESS             The interrupt was handled successfully.
-
+  @retval EFI_ABORTED             Fail to wait for all AP check in SMM.
 **/
 EFI_STATUS
 EFIAPI
@@ -132,6 +138,11 @@ PhysicalPresenceCallback (
   UINT32  OperationRequest;
   UINT32  RequestParameter;
 
+  if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+    DEBUG ((DEBUG_ERROR, "TpmPhysicalPresent: fail to wait for all AP check in SMM!\n"));
+    return EFI_ABORTED;
+  }
+
   if (mTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_RETURN_REQUEST_RESPONSE_TO_OS) {
     mTcgNvs->PhysicalPresence.ReturnCode = Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
                                              &MostRecentRequest,
@@ -173,6 +184,7 @@ PhysicalPresenceCallback (
   @param[in, out] CommBufferSize  The size of the CommBuffer.
 
   @retval EFI_SUCCESS             The interrupt was handled successfully.
+  @retval EFI_ABORTED             Fail to wait for all AP check in SMM.
 
 **/
 EFI_STATUS
@@ -217,6 +229,11 @@ MemoryClearCallback (
     return EFI_SUCCESS;
   }
 
+  if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+    DEBUG ((DEBUG_ERROR, "TpmMemoryClear: fail to wait for all AP check in SMM!\n"));
+    return EFI_ABORTED;
+  }
+
   DataSize = sizeof (UINT8);
   Status   = mSmmVariable->SmmSetVariable (
                              MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.c b/SecurityPkg/Tcg/TcgSmm/TcgSmm.c
index 96327a483ba9..e91567ca3169 100644
--- a/SecurityPkg/Tcg/TcgSmm/TcgSmm.c
+++ b/SecurityPkg/Tcg/TcgSmm/TcgSmm.c
@@ -8,7 +8,7 @@
 
   PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check.
 
-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -33,7 +33,7 @@ TCG_NVS                    *mTcgNvs;
   @param[in, out] CommBufferSize  The size of the CommBuffer.
 
   @retval EFI_SUCCESS             The interrupt was handled successfully.
-
+  @retval EFI_ABORTED             Fail to wait for all AP check in SMM.
 **/
 EFI_STATUS
 EFIAPI
@@ -92,6 +92,11 @@ PhysicalPresenceCallback (
       return EFI_SUCCESS;
     }
 
+    if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+      DEBUG ((DEBUG_ERROR, "TPMPhysicalPresent: fail to wait for all AP check in SMM!\n"));
+      return EFI_ABORTED;
+    }
+
     if (PpData.PPRequest != mTcgNvs->PhysicalPresence.Request) {
       PpData.PPRequest = (UINT8)mTcgNvs->PhysicalPresence.Request;
       DataSize         = sizeof (EFI_PHYSICAL_PRESENCE);
@@ -238,6 +243,7 @@ PhysicalPresenceCallback (
   @param[in, out] CommBufferSize  The size of the CommBuffer.
 
   @retval EFI_SUCCESS             The interrupt was handled successfully.
+  @retval EFI_ABORTED             Fail to wait for all AP check in SMM.
 
 **/
 EFI_STATUS
@@ -282,6 +288,11 @@ MemoryClearCallback (
     return EFI_SUCCESS;
   }
 
+  if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+    DEBUG ((DEBUG_ERROR, " TpmMemoryClear: fail to wait for all AP check in SMM!\n"));
+    return EFI_ABORTED;
+  }
+
   DataSize = sizeof (UINT8);
   Status   = mSmmVariable->SmmSetVariable (
                              MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h
index 84b65eb0897c..c0c0e9d91aeb 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h
@@ -1,7 +1,7 @@
 /** @file
   The header file for Tcg2 SMM driver.
 
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR>
 Copyright (c) Microsoft Corporation.
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -31,6 +31,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/IoLib.h>
 #include <Library/PcdLib.h>
 #include <Library/Tpm2DeviceLib.h>
+#include <Library/SmmCpuRendezvousLib.h>
 
 #include <IndustryStandard/TpmPtp.h>
 
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf
index 096338d0ef47..10b0629d506b 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf
@@ -20,7 +20,7 @@
 #  This driver will have external input - variable and ACPINvs data in SMM mode.
 #  This external input must be validated carefully to avoid security issue.
 #
-# Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR>
 # Copyright (c) Microsoft Corporation.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -59,6 +59,7 @@ [LibraryClasses]
   Tcg2PhysicalPresenceLib
   PcdLib
   SmmMemLib
+  SmmCpuRendezvousLib
 
 [Guids]
   ## SOMETIMES_PRODUCES ## Variable:L"MemoryOverwriteRequestControl"
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf b/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf
index 746eda3e9fed..6cf74803a12d 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf
@@ -55,6 +55,7 @@ [LibraryClasses]
   Tcg2PhysicalPresenceLib
   PcdLib
   MemLib
+  SmmCpuRendezvousLib
 
 [Guids]
   ## SOMETIMES_PRODUCES ## Variable:L"MemoryOverwriteRequestControl"
diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.h b/SecurityPkg/Tcg/TcgSmm/TcgSmm.h
index e348ad105499..dcc85ee3efbc 100644
--- a/SecurityPkg/Tcg/TcgSmm/TcgSmm.h
+++ b/SecurityPkg/Tcg/TcgSmm/TcgSmm.h
@@ -1,7 +1,7 @@
 /** @file
   The header file for TCG SMM driver.
 
-Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -31,6 +31,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/TpmMeasurementLib.h>
 #include <Library/PcdLib.h>
 #include <Library/TcgPpVendorLib.h>
+#include <Library/SmmCpuRendezvousLib.h>
 
 #pragma pack(1)
 typedef struct {
diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf b/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
index 9fac896dde8b..1d0f1c9170d4 100644
--- a/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
+++ b/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
@@ -9,7 +9,7 @@
 #  This driver will have external input - variable and ACPINvs data in SMM mode.
 #  This external input must be validated carefully to avoid security issue.
 #
-# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR>
 # Copyright (c) Microsoft Corporation.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -46,6 +46,7 @@ [LibraryClasses]
   TpmMeasurementLib
   PcdLib
   TcgPpVendorLib
+  SmmCpuRendezvousLib
 
 [Guids]
   ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresence"
-- 
2.26.2.windows.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v1 1/1] SecurityPkg: use SmmWaitForAllProcessor in TcgSmm and Tcg2Smm driver.
  2022-06-20  9:36 [PATCH v1 0/1] *** SUBJECT HERE *** Li, Zhihao
@ 2022-06-20  9:36 ` Li, Zhihao
  0 siblings, 0 replies; 3+ messages in thread
From: Li, Zhihao @ 2022-06-20  9:36 UTC (permalink / raw)
  To: devel; +Cc: Jiewen Yao, Jian J Wang, Rahul Kumar, Qi Zhang

From: Zhihao Li <zhihao.li@intel.com>

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

In UefiCpuPkg, there are a new Protocol with the new service
SmmWaitForAllProcessor(), which can be used by SMI handler
to optionally wait for other APs to complete SMM rendezvous in
relaxed AP mode.

This patch use the new service to let TcgSmm and Tcg2Smm driver work
normally in relaxed AP mode.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Qi Zhang <qi1.zhang@intel.com>

Signed-off-by: Zhihao Li <zhihao.li@intel.com>
---
 SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c            | 21 ++++++++++++++++++--
 SecurityPkg/Tcg/TcgSmm/TcgSmm.c              | 15 ++++++++++++--
 SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h            |  3 ++-
 SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf          |  3 ++-
 SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf |  1 +
 SecurityPkg/Tcg/TcgSmm/TcgSmm.h              |  3 ++-
 SecurityPkg/Tcg/TcgSmm/TcgSmm.inf            |  3 ++-
 7 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
index 498fb626bd9c..4367102fbd49 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
@@ -9,7 +9,7 @@
 
   PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check.
 
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR>
 Copyright (c) Microsoft Corporation.
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -42,6 +42,7 @@ EFI_HANDLE                 mReadyToLockHandle;
                                     should still be called.
   @retval EFI_UNSUPPORTED           An unknown test function was requested.
   @retval EFI_ACCESS_DENIED         Part of the communication buffer lies in an invalid region.
+  @retval EFI_ABORTED               Fail to wait for all AP check in SMM.
 
 **/
 EFI_STATUS
@@ -78,6 +79,11 @@ TpmNvsCommunciate (
     return EFI_ACCESS_DENIED;
   }
 
+  if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+    DEBUG ((DEBUG_ERROR, "TpmNvsCommunciate: fail to wait for all AP check in SMM!\n"));
+    return EFI_ABORTED;
+  }
+
   //
   // Farm out the job to individual functions based on what was requested.
   //
@@ -116,7 +122,7 @@ TpmNvsCommunciate (
   @param[in, out] CommBufferSize  The size of the CommBuffer.
 
   @retval EFI_SUCCESS             The interrupt was handled successfully.
-
+  @retval EFI_ABORTED             Fail to wait for all AP check in SMM.
 **/
 EFI_STATUS
 EFIAPI
@@ -132,6 +138,11 @@ PhysicalPresenceCallback (
   UINT32  OperationRequest;
   UINT32  RequestParameter;
 
+  if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+    DEBUG ((DEBUG_ERROR, "TpmPhysicalPresent: fail to wait for all AP check in SMM!\n"));
+    return EFI_ABORTED;
+  }
+
   if (mTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_RETURN_REQUEST_RESPONSE_TO_OS) {
     mTcgNvs->PhysicalPresence.ReturnCode = Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
                                              &MostRecentRequest,
@@ -173,6 +184,7 @@ PhysicalPresenceCallback (
   @param[in, out] CommBufferSize  The size of the CommBuffer.
 
   @retval EFI_SUCCESS             The interrupt was handled successfully.
+  @retval EFI_ABORTED             Fail to wait for all AP check in SMM.
 
 **/
 EFI_STATUS
@@ -217,6 +229,11 @@ MemoryClearCallback (
     return EFI_SUCCESS;
   }
 
+  if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+    DEBUG ((DEBUG_ERROR, "TpmMemoryClear: fail to wait for all AP check in SMM!\n"));
+    return EFI_ABORTED;
+  }
+
   DataSize = sizeof (UINT8);
   Status   = mSmmVariable->SmmSetVariable (
                              MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.c b/SecurityPkg/Tcg/TcgSmm/TcgSmm.c
index 96327a483ba9..e91567ca3169 100644
--- a/SecurityPkg/Tcg/TcgSmm/TcgSmm.c
+++ b/SecurityPkg/Tcg/TcgSmm/TcgSmm.c
@@ -8,7 +8,7 @@
 
   PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check.
 
-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -33,7 +33,7 @@ TCG_NVS                    *mTcgNvs;
   @param[in, out] CommBufferSize  The size of the CommBuffer.
 
   @retval EFI_SUCCESS             The interrupt was handled successfully.
-
+  @retval EFI_ABORTED             Fail to wait for all AP check in SMM.
 **/
 EFI_STATUS
 EFIAPI
@@ -92,6 +92,11 @@ PhysicalPresenceCallback (
       return EFI_SUCCESS;
     }
 
+    if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+      DEBUG ((DEBUG_ERROR, "TPMPhysicalPresent: fail to wait for all AP check in SMM!\n"));
+      return EFI_ABORTED;
+    }
+
     if (PpData.PPRequest != mTcgNvs->PhysicalPresence.Request) {
       PpData.PPRequest = (UINT8)mTcgNvs->PhysicalPresence.Request;
       DataSize         = sizeof (EFI_PHYSICAL_PRESENCE);
@@ -238,6 +243,7 @@ PhysicalPresenceCallback (
   @param[in, out] CommBufferSize  The size of the CommBuffer.
 
   @retval EFI_SUCCESS             The interrupt was handled successfully.
+  @retval EFI_ABORTED             Fail to wait for all AP check in SMM.
 
 **/
 EFI_STATUS
@@ -282,6 +288,11 @@ MemoryClearCallback (
     return EFI_SUCCESS;
   }
 
+  if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+    DEBUG ((DEBUG_ERROR, " TpmMemoryClear: fail to wait for all AP check in SMM!\n"));
+    return EFI_ABORTED;
+  }
+
   DataSize = sizeof (UINT8);
   Status   = mSmmVariable->SmmSetVariable (
                              MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h
index 84b65eb0897c..c0c0e9d91aeb 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h
@@ -1,7 +1,7 @@
 /** @file
   The header file for Tcg2 SMM driver.
 
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR>
 Copyright (c) Microsoft Corporation.
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -31,6 +31,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/IoLib.h>
 #include <Library/PcdLib.h>
 #include <Library/Tpm2DeviceLib.h>
+#include <Library/SmmCpuRendezvousLib.h>
 
 #include <IndustryStandard/TpmPtp.h>
 
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf
index 096338d0ef47..10b0629d506b 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf
@@ -20,7 +20,7 @@
 #  This driver will have external input - variable and ACPINvs data in SMM mode.
 #  This external input must be validated carefully to avoid security issue.
 #
-# Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR>
 # Copyright (c) Microsoft Corporation.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -59,6 +59,7 @@ [LibraryClasses]
   Tcg2PhysicalPresenceLib
   PcdLib
   SmmMemLib
+  SmmCpuRendezvousLib
 
 [Guids]
   ## SOMETIMES_PRODUCES ## Variable:L"MemoryOverwriteRequestControl"
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf b/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf
index 746eda3e9fed..6cf74803a12d 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf
@@ -55,6 +55,7 @@ [LibraryClasses]
   Tcg2PhysicalPresenceLib
   PcdLib
   MemLib
+  SmmCpuRendezvousLib
 
 [Guids]
   ## SOMETIMES_PRODUCES ## Variable:L"MemoryOverwriteRequestControl"
diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.h b/SecurityPkg/Tcg/TcgSmm/TcgSmm.h
index e348ad105499..dcc85ee3efbc 100644
--- a/SecurityPkg/Tcg/TcgSmm/TcgSmm.h
+++ b/SecurityPkg/Tcg/TcgSmm/TcgSmm.h
@@ -1,7 +1,7 @@
 /** @file
   The header file for TCG SMM driver.
 
-Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -31,6 +31,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/TpmMeasurementLib.h>
 #include <Library/PcdLib.h>
 #include <Library/TcgPpVendorLib.h>
+#include <Library/SmmCpuRendezvousLib.h>
 
 #pragma pack(1)
 typedef struct {
diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf b/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
index 9fac896dde8b..1d0f1c9170d4 100644
--- a/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
+++ b/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
@@ -9,7 +9,7 @@
 #  This driver will have external input - variable and ACPINvs data in SMM mode.
 #  This external input must be validated carefully to avoid security issue.
 #
-# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR>
 # Copyright (c) Microsoft Corporation.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -46,6 +46,7 @@ [LibraryClasses]
   TpmMeasurementLib
   PcdLib
   TcgPpVendorLib
+  SmmCpuRendezvousLib
 
 [Guids]
   ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresence"
-- 
2.26.2.windows.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v1 1/1] SecurityPkg: use SmmWaitForAllProcessor in TcgSmm and Tcg2Smm driver.
  2022-06-20  9:55 [PATCH 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support Li, Zhihao
@ 2022-06-20  9:55 ` Li, Zhihao
  0 siblings, 0 replies; 3+ messages in thread
From: Li, Zhihao @ 2022-06-20  9:55 UTC (permalink / raw)
  To: devel; +Cc: Jiewen Yao, Jian J Wang, Rahul Kumar, Qi Zhang

From: Zhihao Li <zhihao.li@intel.com>

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

In UefiCpuPkg, there are a new Protocol with the new service
SmmWaitForAllProcessor(), which can be used by SMI handler
to optionally wait for other APs to complete SMM rendezvous in
relaxed AP mode.

This patch use the new service to let TcgSmm and Tcg2Smm driver work
normally in relaxed AP mode.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Qi Zhang <qi1.zhang@intel.com>

Signed-off-by: Zhihao Li <zhihao.li@intel.com>
---
 SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c            | 21 ++++++++++++++++++--
 SecurityPkg/Tcg/TcgSmm/TcgSmm.c              | 15 ++++++++++++--
 SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h            |  3 ++-
 SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf          |  3 ++-
 SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf |  1 +
 SecurityPkg/Tcg/TcgSmm/TcgSmm.h              |  3 ++-
 SecurityPkg/Tcg/TcgSmm/TcgSmm.inf            |  3 ++-
 7 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
index 498fb626bd9c..4367102fbd49 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.c
@@ -9,7 +9,7 @@
 
   PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check.
 
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR>
 Copyright (c) Microsoft Corporation.
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -42,6 +42,7 @@ EFI_HANDLE                 mReadyToLockHandle;
                                     should still be called.
   @retval EFI_UNSUPPORTED           An unknown test function was requested.
   @retval EFI_ACCESS_DENIED         Part of the communication buffer lies in an invalid region.
+  @retval EFI_ABORTED               Fail to wait for all AP check in SMM.
 
 **/
 EFI_STATUS
@@ -78,6 +79,11 @@ TpmNvsCommunciate (
     return EFI_ACCESS_DENIED;
   }
 
+  if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+    DEBUG ((DEBUG_ERROR, "TpmNvsCommunciate: fail to wait for all AP check in SMM!\n"));
+    return EFI_ABORTED;
+  }
+
   //
   // Farm out the job to individual functions based on what was requested.
   //
@@ -116,7 +122,7 @@ TpmNvsCommunciate (
   @param[in, out] CommBufferSize  The size of the CommBuffer.
 
   @retval EFI_SUCCESS             The interrupt was handled successfully.
-
+  @retval EFI_ABORTED             Fail to wait for all AP check in SMM.
 **/
 EFI_STATUS
 EFIAPI
@@ -132,6 +138,11 @@ PhysicalPresenceCallback (
   UINT32  OperationRequest;
   UINT32  RequestParameter;
 
+  if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+    DEBUG ((DEBUG_ERROR, "TpmPhysicalPresent: fail to wait for all AP check in SMM!\n"));
+    return EFI_ABORTED;
+  }
+
   if (mTcgNvs->PhysicalPresence.Parameter == TCG_ACPI_FUNCTION_RETURN_REQUEST_RESPONSE_TO_OS) {
     mTcgNvs->PhysicalPresence.ReturnCode = Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (
                                              &MostRecentRequest,
@@ -173,6 +184,7 @@ PhysicalPresenceCallback (
   @param[in, out] CommBufferSize  The size of the CommBuffer.
 
   @retval EFI_SUCCESS             The interrupt was handled successfully.
+  @retval EFI_ABORTED             Fail to wait for all AP check in SMM.
 
 **/
 EFI_STATUS
@@ -217,6 +229,11 @@ MemoryClearCallback (
     return EFI_SUCCESS;
   }
 
+  if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+    DEBUG ((DEBUG_ERROR, "TpmMemoryClear: fail to wait for all AP check in SMM!\n"));
+    return EFI_ABORTED;
+  }
+
   DataSize = sizeof (UINT8);
   Status   = mSmmVariable->SmmSetVariable (
                              MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.c b/SecurityPkg/Tcg/TcgSmm/TcgSmm.c
index 96327a483ba9..e91567ca3169 100644
--- a/SecurityPkg/Tcg/TcgSmm/TcgSmm.c
+++ b/SecurityPkg/Tcg/TcgSmm/TcgSmm.c
@@ -8,7 +8,7 @@
 
   PhysicalPresenceCallback() and MemoryClearCallback() will receive untrusted input and do some check.
 
-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -33,7 +33,7 @@ TCG_NVS                    *mTcgNvs;
   @param[in, out] CommBufferSize  The size of the CommBuffer.
 
   @retval EFI_SUCCESS             The interrupt was handled successfully.
-
+  @retval EFI_ABORTED             Fail to wait for all AP check in SMM.
 **/
 EFI_STATUS
 EFIAPI
@@ -92,6 +92,11 @@ PhysicalPresenceCallback (
       return EFI_SUCCESS;
     }
 
+    if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+      DEBUG ((DEBUG_ERROR, "TPMPhysicalPresent: fail to wait for all AP check in SMM!\n"));
+      return EFI_ABORTED;
+    }
+
     if (PpData.PPRequest != mTcgNvs->PhysicalPresence.Request) {
       PpData.PPRequest = (UINT8)mTcgNvs->PhysicalPresence.Request;
       DataSize         = sizeof (EFI_PHYSICAL_PRESENCE);
@@ -238,6 +243,7 @@ PhysicalPresenceCallback (
   @param[in, out] CommBufferSize  The size of the CommBuffer.
 
   @retval EFI_SUCCESS             The interrupt was handled successfully.
+  @retval EFI_ABORTED             Fail to wait for all AP check in SMM.
 
 **/
 EFI_STATUS
@@ -282,6 +288,11 @@ MemoryClearCallback (
     return EFI_SUCCESS;
   }
 
+  if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {
+    DEBUG ((DEBUG_ERROR, " TpmMemoryClear: fail to wait for all AP check in SMM!\n"));
+    return EFI_ABORTED;
+  }
+
   DataSize = sizeof (UINT8);
   Status   = mSmmVariable->SmmSetVariable (
                              MEMORY_OVERWRITE_REQUEST_VARIABLE_NAME,
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h
index 84b65eb0897c..c0c0e9d91aeb 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.h
@@ -1,7 +1,7 @@
 /** @file
   The header file for Tcg2 SMM driver.
 
-Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR>
 Copyright (c) Microsoft Corporation.
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -31,6 +31,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/IoLib.h>
 #include <Library/PcdLib.h>
 #include <Library/Tpm2DeviceLib.h>
+#include <Library/SmmCpuRendezvousLib.h>
 
 #include <IndustryStandard/TpmPtp.h>
 
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf
index 096338d0ef47..10b0629d506b 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2Smm.inf
@@ -20,7 +20,7 @@
 #  This driver will have external input - variable and ACPINvs data in SMM mode.
 #  This external input must be validated carefully to avoid security issue.
 #
-# Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2015 - 2022, Intel Corporation. All rights reserved.<BR>
 # Copyright (c) Microsoft Corporation.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -59,6 +59,7 @@ [LibraryClasses]
   Tcg2PhysicalPresenceLib
   PcdLib
   SmmMemLib
+  SmmCpuRendezvousLib
 
 [Guids]
   ## SOMETIMES_PRODUCES ## Variable:L"MemoryOverwriteRequestControl"
diff --git a/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf b/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf
index 746eda3e9fed..6cf74803a12d 100644
--- a/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf
+++ b/SecurityPkg/Tcg/Tcg2Smm/Tcg2StandaloneMm.inf
@@ -55,6 +55,7 @@ [LibraryClasses]
   Tcg2PhysicalPresenceLib
   PcdLib
   MemLib
+  SmmCpuRendezvousLib
 
 [Guids]
   ## SOMETIMES_PRODUCES ## Variable:L"MemoryOverwriteRequestControl"
diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.h b/SecurityPkg/Tcg/TcgSmm/TcgSmm.h
index e348ad105499..dcc85ee3efbc 100644
--- a/SecurityPkg/Tcg/TcgSmm/TcgSmm.h
+++ b/SecurityPkg/Tcg/TcgSmm/TcgSmm.h
@@ -1,7 +1,7 @@
 /** @file
   The header file for TCG SMM driver.
 
-Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2012 - 2022, Intel Corporation. All rights reserved.<BR>
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -31,6 +31,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
 #include <Library/TpmMeasurementLib.h>
 #include <Library/PcdLib.h>
 #include <Library/TcgPpVendorLib.h>
+#include <Library/SmmCpuRendezvousLib.h>
 
 #pragma pack(1)
 typedef struct {
diff --git a/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf b/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
index 9fac896dde8b..1d0f1c9170d4 100644
--- a/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
+++ b/SecurityPkg/Tcg/TcgSmm/TcgSmm.inf
@@ -9,7 +9,7 @@
 #  This driver will have external input - variable and ACPINvs data in SMM mode.
 #  This external input must be validated carefully to avoid security issue.
 #
-# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR>
 # Copyright (c) Microsoft Corporation.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -46,6 +46,7 @@ [LibraryClasses]
   TpmMeasurementLib
   PcdLib
   TcgPpVendorLib
+  SmmCpuRendezvousLib
 
 [Guids]
   ## SOMETIMES_PRODUCES ## Variable:L"PhysicalPresence"
-- 
2.26.2.windows.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-20  9:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-13  6:24 [PATCH v1 1/1] SecurityPkg: use SmmWaitForAllProcessor in TcgSmm and Tcg2Smm driver Li, Zhihao
  -- strict thread matches above, loose matches on Subject: below --
2022-06-20  9:36 [PATCH v1 0/1] *** SUBJECT HERE *** Li, Zhihao
2022-06-20  9:36 ` [PATCH v1 1/1] SecurityPkg: use SmmWaitForAllProcessor in TcgSmm and Tcg2Smm driver Li, Zhihao
2022-06-20  9:55 [PATCH 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support Li, Zhihao
2022-06-20  9:55 ` [PATCH v1 1/1] SecurityPkg: use SmmWaitForAllProcessor in TcgSmm and Tcg2Smm driver Li, Zhihao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox