public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Li, Zhihao" <zhihao.li@intel.com>
To: devel@edk2.groups.io
Cc: Jiewen Yao <jiewen.yao@intel.com>,
	Jian J Wang <jian.j.wang@intel.com>,
	Rahul Kumar <rahul1.kumar@intel.com>,
	Qi Zhang <qi1.zhang@intel.com>
Subject: [PATCH v1 1/1] SecurityPkg: use SmmWaitForAllProcessor in TcgSmm and Tcg2Smm driver.
Date: Mon, 20 Jun 2022 17:36:15 +0800	[thread overview]
Message-ID: <20220620093615.1535-7-zhihao.li@intel.com> (raw)
In-Reply-To: <20220620093615.1535-1-zhihao.li@intel.com>

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


  parent reply	other threads:[~2022-06-20  9:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20  9:36 [PATCH v1 0/1] *** SUBJECT HERE *** Li, Zhihao
2022-06-20  9:36 ` [PATCH 1/1] UefiCpuPkg: Extend SMM CPU Service with rendezvous support Li, Zhihao
2022-06-20  9:36 ` [PATCH 1/1] OvmfPkg: Add dependency of VariableSmm driver to make it work normally Li, Zhihao
2022-06-20  9:36 ` [PATCH 1/1] UefiPayloadPkg: Add dependency of VariableSmm driver Li, Zhihao
2022-06-20  9:36 ` [PATCH 1/1] MdePkg: add SmmCpuRendezvousLib.h and SmmCpuRendezvousLibNull implement Li, Zhihao
2022-06-20  9:36 ` [PATCH 1/1] MdePkg: Remove "assert" from SmmCpuRendevousLibNull.c Li, Zhihao
2022-06-20 15:31   ` 回复: [edk2-devel] " gaoliming
2022-06-20  9:36 ` Li, Zhihao [this message]
  -- strict thread matches above, loose matches on Subject: below --
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
2022-06-13  6:24 Li, Zhihao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220620093615.1535-7-zhihao.li@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox