From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mx.groups.io with SMTP id smtpd.web08.10746.1650475926014175887 for ; Wed, 20 Apr 2022 10:32:06 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=nYfI60JN; spf=pass (domain: intel.com, ip: 192.55.52.136, mailfrom: zhihao.li@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650475926; x=1682011926; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=iBTzrAMKpkvZYKV/nL80BhJBS4O3SYWw/2Stxe6EXnM=; b=nYfI60JNEZL0jhhQv3bgJBFYKfY8nmUIlOeIqtwZ30KTelWYoJYLKqVq Nw1bgwrQFKCiGC333t9wEph3Xq7bFvT462Wz/KsqnNhgYnr5Hsvs3bpM0 qofAXXUb12KiHFu/TJmiYJQ0//kRJHCZ337PNBgjPHAGmRuci35pA6V1G BHPy9AWTg4/EoO8dszQxYYH2wOfI+FhybDmf8Dlg8L//tnYMW9P74m4nR mln7dG3TPd0RhmtvTGyyuBl5K1VdroDB1cLz12grByhq6/yJNNB3JD5Ym 1e/CfnU2EShxsdgVqI2ZaHT58VC4Fxy5KIvsm9RYyzYvSlEC0k5IL1yWF g==; X-IronPort-AV: E=McAfee;i="6400,9594,10323"; a="244038204" X-IronPort-AV: E=Sophos;i="5.90,276,1643702400"; d="scan'208";a="244038204" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2022 10:32:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,276,1643702400"; d="scan'208";a="576706711" Received: from win_li.ccr.corp.intel.com ([10.239.157.34]) by orsmga008.jf.intel.com with ESMTP; 20 Apr 2022 10:32:01 -0700 From: "Li, Zhihao" To: devel@edk2.groups.io Cc: Jian J Wang , Liming Gao , Siyuan Fu , Ni Ray , Sami Mujawar , Ilias Apalodimas , Ard Biesheuvel , Leif Lindholm Subject: [PATCH v2 1/1] MdeModulePkg: Use SmmWaitForAllProcessor() in VariableSmm driver. Date: Thu, 21 Apr 2022 01:32:01 +0800 Message-Id: <20220420173201.1050-1-zhihao.li@intel.com> X-Mailer: git-send-email 2.26.2.windows.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable REF=EF=BC=9A https://bugzilla.tianocore.org/show_bug.cgi?id=3D3854 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 VariableSmm driver work normally in relaxed AP mode. Due to MdeModulePkg can not depend on UefiCpuPkg, use null version implementation in MdeModulePkg.dsc. Cc: Jian J Wang Cc: Liming Gao Cc: Siyuan Fu Cc: Ni Ray Cc: Sami Mujawar Cc: Ilias Apalodimas Cc: Ard Biesheuvel Cc: Leif Lindholm Signed-off-by: Zhihao Li --- MdeModulePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.c |= 29 ++++++++++++++++++++ MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c |= 10 ++++++- MdeModulePkg/Include/Library/SmmCpuRendezvousLib.h |= 27 ++++++++++++++++++ MdeModulePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf |= 27 ++++++++++++++++++ MdeModulePkg/MdeModulePkg.dec |= 5 +++- MdeModulePkg/MdeModulePkg.dsc |= 5 +++- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf |= 3 +- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf |= 3 +- 8 files changed, 104 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousL= ibNull.c b/MdeModulePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLib= Null.c new file mode 100644 index 000000000000..474195bbb374 --- /dev/null +++ b/MdeModulePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.c @@ -0,0 +1,29 @@ +/** @file=0D + SMM CPU Rendezvous sevice implement.=0D +=0D + Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +=0D +/**=0D + This routine wait for all AP processors to arrive in SMM.=0D +=0D + @param[in] BlockingMode Blocking mode or non-blocking mode.=0D +=0D + @retval EFI_SUCCESS All avaiable APs arrived.=0D + @retval EFI_TIMEOUT Wait for all APs until timeout.=0D + @retval OTHER Fail to register SMM CPU Rendezvous service Protoco= l.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +SmmWaitForAllProcessor (=0D + IN BOOLEAN BlockingMode=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return EFI_SUCCESS;=0D +}=0D diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/Mde= ModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c index 517cae7b00f8..52a9b0e6b202 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c @@ -14,7 +14,7 @@ VariableServiceSetVariable(), VariableServiceQueryVariableInfo(), Reclai= mForOS(),=0D SmmVariableGetStatistics() should also do validation based on its own kn= owledge.=0D =0D -Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.
=0D +Copyright (c) 2010 - 2022, Intel Corporation. All rights reserved.
=0D Copyright (c) 2018, Linaro, Ltd. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D @@ -28,6 +28,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =0D #include =0D #include =0D +#include =0D =0D #include =0D #include "Variable.h"=0D @@ -656,6 +657,13 @@ SmmVariableHandler ( goto EXIT;=0D }=0D =0D + if ((SmmVariableHeader->Attributes & EFI_VARIABLE_NON_VOLATILE) !=3D= 0) {=0D + if (EFI_ERROR (SmmWaitForAllProcessor (TRUE))) {=0D + DEBUG ((DEBUG_ERROR, "SetVariable: fail to wait for all AP check= in SMM!\n"));=0D + goto EXIT;=0D + }=0D + }=0D +=0D Status =3D VariableServiceSetVariable (=0D SmmVariableHeader->Name,=0D &SmmVariableHeader->Guid,=0D diff --git a/MdeModulePkg/Include/Library/SmmCpuRendezvousLib.h b/MdeModule= Pkg/Include/Library/SmmCpuRendezvousLib.h new file mode 100644 index 000000000000..82e459e9106e --- /dev/null +++ b/MdeModulePkg/Include/Library/SmmCpuRendezvousLib.h @@ -0,0 +1,27 @@ +/** @file=0D + SMM CPU Rendezvous library header file.=0D +=0D + Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#ifndef SMM_CPU_RENDEZVOUS_H_=0D +#define SMM_CPU_RENDEZVOUS_H_=0D +=0D +/**=0D + This routine wait for all AP processors to arrive in SMM.=0D +=0D + @param[in] BlockingMode Blocking mode or non-blocking mode.=0D +=0D + @retval EFI_SUCCESS All processors checked in to SMM.=0D + @retval EFI_TIMEOUT Wait for all APs until timeout.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +SmmWaitForAllProcessor (=0D + IN BOOLEAN BlockingMode=0D + );=0D +=0D +#endif=0D diff --git a/MdeModulePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousL= ibNull.inf b/MdeModulePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousL= ibNull.inf new file mode 100644 index 000000000000..0bd4f39e7277 --- /dev/null +++ b/MdeModulePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.= inf @@ -0,0 +1,27 @@ +## @file=0D +# SMM CPU Rendezvous service lib.=0D +#=0D +# This is SMM CPU rendezvous service lib that wait for all=0D +# APs to enter SMM mode.=0D +#=0D +# Copyright (c) 2022, Intel Corporation. All rights reserved.
=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D SmmCpuRendezvousLibNull=0D + FILE_GUID =3D 1e5790ea-d013-4d7b-9047-b4342a762027= =0D + MODULE_TYPE =3D DXE_SMM_DRIVER=0D + LIBRARY_CLASS =3D SmmCpuRendezvousLib|MM_STANDALONE DXE= _SMM_DRIVER=0D +=0D +[Sources]=0D + SmmCpuRendezvousLibNull.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 463e889e9a68..06ada41b7344 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -4,7 +4,7 @@ # and libraries instances, which are used for those modules.=0D #=0D # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.=0D -# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.
=0D +# Copyright (c) 2007 - 2022, Intel Corporation. All rights reserved.
=0D # Copyright (c) 2016, Linaro Ltd. All rights reserved.
=0D # (C) Copyright 2016 - 2019 Hewlett Packard Enterprise Development LP
= =0D # Copyright (c) 2017, AMD Incorporated. All rights reserved.
=0D @@ -154,6 +154,9 @@ #=0D VariablePolicyHelperLib|Include/Library/VariablePolicyHelperLib.h=0D =0D + ## @libraryclass Provides function for SMM CPU Rendezvous Library.=0D + SmmCpuRendezvousLib|Include/Library/SmmCpuRendezvousLib.h=0D +=0D [Guids]=0D ## MdeModule package token space guid=0D # Include/Guid/MdeModulePkgTokenSpace.h=0D diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index b1d83461865e..4580320a7230 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -2,7 +2,7 @@ # EFI/PI Reference Module Package for All Architectures=0D #=0D # (C) Copyright 2014 Hewlett-Packard Development Company, L.P.
=0D -# Copyright (c) 2007 - 2021, Intel Corporation. All rights reserved.
=0D +# Copyright (c) 2007 - 2022, Intel Corporation. All rights reserved.
=0D # Copyright (c) Microsoft Corporation.=0D #=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D @@ -152,6 +152,7 @@ SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableL= ib.inf=0D LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxSmmLib.inf=0D SmmMemLib|MdePkg/Library/SmmMemLib/SmmMemLib.inf=0D + SmmCpuRendezvousLib|MdeModulePkg/Library/SmmCpuRendezvousLibNull/SmmCpuR= endezvousLibNull.inf=0D =0D [LibraryClasses.common.UEFI_DRIVER]=0D HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf=0D @@ -172,6 +173,7 @@ MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/Standalon= eMmServicesTableLib.inf=0D LockBoxLib|MdeModulePkg/Library/SmmLockBoxLib/SmmLockBoxStandaloneMmLib.= inf=0D MemLib|StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf= =0D + SmmCpuRendezvousLib|MdeModulePkg/Library/SmmCpuRendezvousLibNull/SmmCpuR= endezvousLibNull.inf=0D =0D [LibraryClasses.ARM, LibraryClasses.AARCH64]=0D ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf=0D @@ -459,6 +461,7 @@ MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandalon= eMm.inf=0D MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf=0D !endif=0D + MdeModulePkg/Library/SmmCpuRendezvousLibNull/SmmCpuRendezvousLibNull.inf= =0D =0D [Components.IA32, Components.X64]=0D MdeModulePkg/Universal/DebugSupportDxe/DebugSupportDxe.inf=0D diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf b/M= deModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf index eaa97a01c6e5..0bebd92b1626 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf @@ -18,7 +18,7 @@ # may not be modified without authorization. If platform fails to protect= these resources,=0D # the authentication service provided in this driver will be broken, and = the behavior is undefined.=0D #=0D -# Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.
=0D +# Copyright (c) 2010 - 2022, Intel Corporation. All rights reserved.
=0D # Copyright (c) Microsoft Corporation.=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D @@ -82,6 +82,7 @@ UefiBootServicesTableLib=0D VariablePolicyLib=0D VariablePolicyHelperLib=0D + SmmCpuRendezvousLib=0D =0D [Protocols]=0D gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES=0D diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneM= m.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf index d8c4f77e7f1f..595baaf70164 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf @@ -18,7 +18,7 @@ # may not be modified without authorization. If platform fails to protect= these resources,=0D # the authentication service provided in this driver will be broken, and = the behavior is undefined.=0D #=0D -# Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.
=0D +# Copyright (c) 2010 - 2022, Intel Corporation. All rights reserved.
=0D # Copyright (c) 2018, Linaro, Ltd. All rights reserved.
=0D # Copyright (c) Microsoft Corporation.=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D @@ -78,6 +78,7 @@ VarCheckLib=0D VariablePolicyLib=0D VariablePolicyHelperLib=0D + SmmCpuRendezvousLib=0D =0D [Protocols]=0D gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES=0D --=20 2.26.2.windows.1