From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web12.13343.1644337203175330721 for ; Tue, 08 Feb 2022 08:20:03 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=RVwVYrsG; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: chasel.chiu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644337203; x=1675873203; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/nvVJjB8sfTj1QMuUBFTDgaJj8xkJxjFA69a5owLZ4k=; b=RVwVYrsGqgUmdsJsR6B63OUqH/TQBHX7oB6dumMF5mY/9QFrDQ/JpURZ 4y7Xexnfh1XeSLjRp0WO1CVjA4uQN5l78KU2jRZPycBNRgOA7U2D6R/JR /xyT1U1ed8TPgTTbmLgRj0geqrUItjzIwHxkr7fKJ7NENEXTCAgq7gQSD 0nZpO2tvfZvFYiJGCXIAQl42TjoRCABQQ9yvxOIXKtBf03Hh8mBofyfBG PqiRcj0Ap6m/+K29JJZhGi4If2YXqwazOeH9WY2VCCuUA6pPbqeeY4h6F Tht6wvLeFkrYgEKgp34DXJVWL90OAy+MV33emFRmsPpweygwOjvsMdi5+ A==; X-IronPort-AV: E=McAfee;i="6200,9189,10252"; a="335386257" X-IronPort-AV: E=Sophos;i="5.88,353,1635231600"; d="scan'208";a="335386257" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2022 08:20:02 -0800 X-IronPort-AV: E=Sophos;i="5.88,353,1635231600"; d="scan'208";a="481987965" Received: from cchiu4-mobl.gar.corp.intel.com ([10.252.188.100]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Feb 2022 08:20:01 -0800 From: "Chiu, Chasel" To: devel@edk2.groups.io Cc: Chasel Chiu , Nate DeSimone , Liming Gao , Eric Dong Subject: [edk2-platforms: PATCH] MinPlatformPkg/SaveMemoryConfig: Variable may not be locked. Date: Wed, 9 Feb 2022 00:19:41 +0800 Message-Id: <20220208161941.1411-1-chasel.chiu@intel.com> X-Mailer: git-send-email 2.28.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3829 Fixed the bug that existing variable will not be locked when it is identical with hob data, also switch to VariablePolicyProtocol for locking variables. This patch also updated SaveMemoryConfig driver to be unloaded after execution because it does not produce any service protocol. To achieve this goal the DxeRuntimeVariableWriteLib should close registered ExitBootService events in its DESTRUCTOR. Cc: Nate DeSimone Cc: Liming Gao Cc: Eric Dong Signed-off-by: Chasel Chiu --- Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig= .c | 12 +++++++++--- Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeRuntim= eVariableWriteLib.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++--= -------------- Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeRuntim= eVariableWriteLib.inf | 8 +++++--- 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/Save= MemoryConfig.c b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/= SaveMemoryConfig.c index 820585f676..0ae5511fed 100644 --- a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryC= onfig.c +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryC= onfig.c @@ -2,7 +2,7 @@ This is the driver that locates the MemoryConfigurationData HOB, if it=0D exists, and saves the data to nvRAM.=0D =0D -Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
=0D +Copyright (c) 2017 - 2022, Intel Corporation. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D @@ -18,6 +18,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include =0D #include =0D #include =0D +#include =0D #include =0D =0D /**=0D @@ -86,6 +87,11 @@ SaveMemoryConfigEntryPoint ( Status =3D GetLargeVariable (L"FspNvsBuffer", &gFspNvsBufferVa= riableGuid, &BufferSize, VariableData);=0D if (!EFI_ERROR (Status) && (BufferSize =3D=3D DataSize) && (0 = =3D=3D CompareMem (HobData, VariableData, DataSize))) {=0D DataIsIdentical =3D TRUE;=0D + //=0D + // No need to update Variable, only lock it.=0D + //=0D + Status =3D VarLibVariableRequestToLock (L"FspNvsBuffer", &g= FspNvsBufferVariableGuid);=0D + ASSERT_EFI_ERROR (Status);=0D }=0D FreePool (VariableData);=0D }=0D @@ -106,7 +112,7 @@ SaveMemoryConfigEntryPoint ( }=0D =0D //=0D - // This driver cannot be unloaded because DxeRuntimeVariableWriteLib con= structor will register ExitBootServices callback.=0D + // This driver does not produce any protocol services, so always unload = it.=0D //=0D - return EFI_SUCCESS;=0D + return EFI_REQUEST_UNLOAD_IMAGE;=0D }=0D diff --git a/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteL= ib/DxeRuntimeVariableWriteLib.c b/Platform/Intel/MinPlatformPkg/Library/Dxe= RuntimeVariableWriteLib/DxeRuntimeVariableWriteLib.c index 9ed59f8827..e7d0c5ec34 100644 --- a/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeR= untimeVariableWriteLib.c +++ b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeR= untimeVariableWriteLib.c @@ -10,7 +10,7 @@ Using this library allows code to be written in a generic manner that ca= n be=0D used in DXE or SMM without modification.=0D =0D - Copyright (c) 2021, Intel Corporation. All rights reserved.
=0D + Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.
=0D SPDX-License-Identifier: BSD-2-Clause-Patent=0D =0D **/=0D @@ -18,14 +18,16 @@ #include =0D =0D #include =0D -#include =0D +#include =0D =0D #include =0D #include =0D #include =0D #include =0D =0D -STATIC EDKII_VARIABLE_LOCK_PROTOCOL *mVariableWriteLibVariableLock =3D NU= LL;=0D +STATIC EDKII_VARIABLE_POLICY_PROTOCOL *mVariableWriteLibVariablePolicy = =3D NULL;=0D +EFI_EVENT mExitBootServiceEvent;=0D +EFI_EVENT mLegacyBootEvent;=0D =0D /**=0D Sets the value of a variable.=0D @@ -144,7 +146,7 @@ VarLibIsVariableRequestToLockSupported ( VOID=0D )=0D {=0D - if (mVariableWriteLibVariableLock !=3D NULL) {=0D + if (mVariableWriteLibVariablePolicy !=3D NULL) {=0D return TRUE;=0D } else {=0D return FALSE;=0D @@ -178,16 +180,46 @@ VarLibVariableRequestToLock ( {=0D EFI_STATUS Status =3D EFI_UNSUPPORTED;=0D =0D - if (mVariableWriteLibVariableLock !=3D NULL) {=0D - Status =3D mVariableWriteLibVariableLock->RequestToLock (=0D - mVariableWriteLibVariableLoc= k,=0D - VariableName,=0D - VendorGuid=0D - );=0D + if (mVariableWriteLibVariablePolicy !=3D NULL) {=0D + Status =3D RegisterBasicVariablePolicy (=0D + mVariableWriteLibVariablePolicy,=0D + (CONST EFI_GUID*) VendorGuid,=0D + (CONST CHAR16 *) VariableName,=0D + VARIABLE_POLICY_NO_MIN_SIZE,=0D + VARIABLE_POLICY_NO_MAX_SIZE,=0D + VARIABLE_POLICY_NO_MUST_ATTR,=0D + VARIABLE_POLICY_NO_CANT_ATTR,=0D + VARIABLE_POLICY_TYPE_LOCK_NOW=0D + );=0D + ASSERT_EFI_ERROR (Status);=0D }=0D return Status;=0D }=0D =0D +/**=0D + Close events when driver unloaded.=0D +=0D + @param[in] ImageHandle A handle for the image that is initializing this= driver=0D + @param[in] SystemTable A pointer to the EFI system table=0D +=0D + @retval EFI_SUCCESS The initialization finished successfully.=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +DxeRuntimeVariableWriteLibDestructor (=0D + IN EFI_HANDLE ImageHandle,=0D + IN EFI_SYSTEM_TABLE *SystemTable=0D + )=0D +{=0D + if (mExitBootServiceEvent !=3D 0) {=0D + gBS->CloseEvent (mExitBootServiceEvent);=0D + }=0D + if (mLegacyBootEvent !=3D 0) {=0D + gBS->CloseEvent (mLegacyBootEvent);=0D + }=0D + return EFI_SUCCESS;=0D +}=0D +=0D /**=0D Exit Boot Services Event notification handler.=0D =0D @@ -202,7 +234,7 @@ DxeRuntimeVariableWriteLibOnExitBootServices ( IN VOID *Context=0D )=0D {=0D - mVariableWriteLibVariableLock =3D NULL;=0D + mVariableWriteLibVariablePolicy =3D NULL;=0D }=0D =0D /**=0D @@ -227,13 +259,11 @@ DxeRuntimeVariableWriteLibConstructor ( )=0D {=0D EFI_STATUS Status;=0D - EFI_EVENT ExitBootServiceEvent;=0D - EFI_EVENT LegacyBootEvent;=0D =0D //=0D // Locate VariableLockProtocol.=0D //=0D - Status =3D gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (= VOID **)&mVariableWriteLibVariableLock);=0D + Status =3D gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid, NULL,= (VOID **)&mVariableWriteLibVariablePolicy);=0D ASSERT_EFI_ERROR (Status);=0D =0D //=0D @@ -245,7 +275,7 @@ DxeRuntimeVariableWriteLibConstructor ( DxeRuntimeVariableWriteLibOnExitBootServices,=0D NULL,=0D &gEfiEventExitBootServicesGuid,=0D - &ExitBootServiceEvent=0D + &mExitBootServiceEvent=0D );=0D ASSERT_EFI_ERROR (Status);=0D =0D @@ -257,7 +287,7 @@ DxeRuntimeVariableWriteLibConstructor ( TPL_NOTIFY,=0D DxeRuntimeVariableWriteLibOnExitBootServices,=0D NULL,=0D - &LegacyBootEvent=0D + &mLegacyBootEvent=0D );=0D ASSERT_EFI_ERROR (Status);=0D =0D diff --git a/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteL= ib/DxeRuntimeVariableWriteLib.inf b/Platform/Intel/MinPlatformPkg/Library/D= xeRuntimeVariableWriteLib/DxeRuntimeVariableWriteLib.inf index 704a8ac7cc..f83090c847 100644 --- a/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeR= untimeVariableWriteLib.inf +++ b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeR= untimeVariableWriteLib.inf @@ -10,7 +10,7 @@ # Using this library allows code to be written in a generic manner that ca= n be=0D # used in DXE or SMM without modification.=0D #=0D -# Copyright (c) 2021, Intel Corporation. All rights reserved.
=0D +# Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.
=0D #=0D # SPDX-License-Identifier: BSD-2-Clause-Patent=0D #=0D @@ -24,6 +24,7 @@ MODULE_TYPE =3D DXE_RUNTIME_DRIVER=0D LIBRARY_CLASS =3D VariableWriteLib|DXE_CORE DXE_DRIVER = DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER=0D CONSTRUCTOR =3D DxeRuntimeVariableWriteLibConstructor= =0D + DESTRUCTOR =3D DxeRuntimeVariableWriteLibDestructor= =0D =0D [Packages]=0D MdePkg/MdePkg.dec=0D @@ -37,13 +38,14 @@ UefiLib=0D UefiBootServicesTableLib=0D UefiRuntimeServicesTableLib=0D + VariablePolicyHelperLib=0D =0D [Guids]=0D gEfiEventExitBootServicesGuid ## CONSUMES ## Event=0D =0D [Protocols]=0D gEfiVariableWriteArchProtocolGuid ## CONSUMES=0D - gEdkiiVariableLockProtocolGuid ## CONSUMES=0D + gEdkiiVariablePolicyProtocolGuid ## CONSUMES=0D =0D [Depex]=0D - gEfiVariableWriteArchProtocolGuid AND gEdkiiVariableLockProtocolGuid=0D + gEfiVariableWriteArchProtocolGuid AND gEdkiiVariablePolicyProtocolGuid=0D --=20 2.28.0.windows.1