From nobody Fri May 17 06:43:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+86450+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+86450+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1644337204; cv=none; d=zohomail.com; s=zohoarc; b=Xi3uL7AK8HuzlR8QbkcdAI4s7HVchIav9gX6nSJFyYe0b7F42gns6cf018xaOhT/AmCWa3oBTfIbFPWkwYvkrgmQAijrYBKX7Xzv7f7m8PK+T0OPrEgtiRroQMDXOXSgbDl9LkI4WUPm9c9t+8/n3bfkG3o2tkPeqg2wH0OOzWU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644337204; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=R3hgBFS32exR5LjLo175oKmrvnh+vPR2tWNwH8Wm5S4=; b=ezqkd2QrbzZW0aFPTrXQvctjg4u8gnWBvDgyp5fD2jHbv5Z51tB1Kf6mTEIUqOkV8/9tfeflhkWtytWGHswsolHxm3xo3Rf+tttQEOatJt6wpkPVuYrfq/6M6lRw41AJsSJPosHS2hAS8EHNjsdcOdq+fzMQyK2XAqodLA9FvAw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+86450+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1644337204503953.9779370553014; Tue, 8 Feb 2022 08:20:04 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id xtnWYY1788612xOd8z3v7aGT; Tue, 08 Feb 2022 08:20:03 -0800 X-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 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" X-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" X-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-devel] [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> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,chasel.chiu@intel.com X-Gm-Message-State: 3v7h7SwGtSCUTy8mo6x0LSxWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1644337203; bh=z5pQq0XZ+baC+iNQ0LjLaVIcuTLdOR+hsL1JOT10oX0=; h=Cc:Date:From:Reply-To:Subject:To; b=koqUcWl784vHIvnbggkk8UyUpyS3B893NrgZrbr9wk11PCHN/n7L6kMf31uX09pBDki ZAgu95pFx4nHfaHnqMHi83yn3K1HPN4TDcL4z2br2lrEoxyk6igmHg+sNfyAPfA0RhuCF aDNhbbx3AmslQVTPnPRieDjesSEuCRJqX9U= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1644337205283100001 Content-Type: text/plain; charset="utf-8" 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 exists, and saves the data to nvRAM. =20 -Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.
+Copyright (c) 2017 - 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -18,6 +18,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include =20 /** @@ -86,6 +87,11 @@ SaveMemoryConfigEntryPoint ( Status =3D GetLargeVariable (L"FspNvsBuffer", &gFspNvsBufferVa= riableGuid, &BufferSize, VariableData); if (!EFI_ERROR (Status) && (BufferSize =3D=3D DataSize) && (0 = =3D=3D CompareMem (HobData, VariableData, DataSize))) { DataIsIdentical =3D TRUE; + // + // No need to update Variable, only lock it. + // + Status =3D VarLibVariableRequestToLock (L"FspNvsBuffer", &g= FspNvsBufferVariableGuid); + ASSERT_EFI_ERROR (Status); } FreePool (VariableData); } @@ -106,7 +112,7 @@ SaveMemoryConfigEntryPoint ( } =20 // - // This driver cannot be unloaded because DxeRuntimeVariableWriteLib con= structor will register ExitBootServices callback. + // This driver does not produce any protocol services, so always unload = it. // - return EFI_SUCCESS; + return EFI_REQUEST_UNLOAD_IMAGE; } 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 used in DXE or SMM without modification. =20 - Copyright (c) 2021, Intel Corporation. All rights reserved.
+ Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -18,14 +18,16 @@ #include =20 #include -#include +#include =20 #include #include #include #include =20 -STATIC EDKII_VARIABLE_LOCK_PROTOCOL *mVariableWriteLibVariableLock =3D NU= LL; +STATIC EDKII_VARIABLE_POLICY_PROTOCOL *mVariableWriteLibVariablePolicy = =3D NULL; +EFI_EVENT mExitBootServiceEvent; +EFI_EVENT mLegacyBootEvent; =20 /** Sets the value of a variable. @@ -144,7 +146,7 @@ VarLibIsVariableRequestToLockSupported ( VOID ) { - if (mVariableWriteLibVariableLock !=3D NULL) { + if (mVariableWriteLibVariablePolicy !=3D NULL) { return TRUE; } else { return FALSE; @@ -178,16 +180,46 @@ VarLibVariableRequestToLock ( { EFI_STATUS Status =3D EFI_UNSUPPORTED; =20 - if (mVariableWriteLibVariableLock !=3D NULL) { - Status =3D mVariableWriteLibVariableLock->RequestToLock ( - mVariableWriteLibVariableLoc= k, - VariableName, - VendorGuid - ); + if (mVariableWriteLibVariablePolicy !=3D NULL) { + Status =3D RegisterBasicVariablePolicy ( + mVariableWriteLibVariablePolicy, + (CONST EFI_GUID*) VendorGuid, + (CONST CHAR16 *) VariableName, + VARIABLE_POLICY_NO_MIN_SIZE, + VARIABLE_POLICY_NO_MAX_SIZE, + VARIABLE_POLICY_NO_MUST_ATTR, + VARIABLE_POLICY_NO_CANT_ATTR, + VARIABLE_POLICY_TYPE_LOCK_NOW + ); + ASSERT_EFI_ERROR (Status); } return Status; } =20 +/** + Close events when driver unloaded. + + @param[in] ImageHandle A handle for the image that is initializing this= driver + @param[in] SystemTable A pointer to the EFI system table + + @retval EFI_SUCCESS The initialization finished successfully. +**/ +EFI_STATUS +EFIAPI +DxeRuntimeVariableWriteLibDestructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + if (mExitBootServiceEvent !=3D 0) { + gBS->CloseEvent (mExitBootServiceEvent); + } + if (mLegacyBootEvent !=3D 0) { + gBS->CloseEvent (mLegacyBootEvent); + } + return EFI_SUCCESS; +} + /** Exit Boot Services Event notification handler. =20 @@ -202,7 +234,7 @@ DxeRuntimeVariableWriteLibOnExitBootServices ( IN VOID *Context ) { - mVariableWriteLibVariableLock =3D NULL; + mVariableWriteLibVariablePolicy =3D NULL; } =20 /** @@ -227,13 +259,11 @@ DxeRuntimeVariableWriteLibConstructor ( ) { EFI_STATUS Status; - EFI_EVENT ExitBootServiceEvent; - EFI_EVENT LegacyBootEvent; =20 // // Locate VariableLockProtocol. // - Status =3D gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (= VOID **)&mVariableWriteLibVariableLock); + Status =3D gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid, NULL,= (VOID **)&mVariableWriteLibVariablePolicy); ASSERT_EFI_ERROR (Status); =20 // @@ -245,7 +275,7 @@ DxeRuntimeVariableWriteLibConstructor ( DxeRuntimeVariableWriteLibOnExitBootServices, NULL, &gEfiEventExitBootServicesGuid, - &ExitBootServiceEvent + &mExitBootServiceEvent ); ASSERT_EFI_ERROR (Status); =20 @@ -257,7 +287,7 @@ DxeRuntimeVariableWriteLibConstructor ( TPL_NOTIFY, DxeRuntimeVariableWriteLibOnExitBootServices, NULL, - &LegacyBootEvent + &mLegacyBootEvent ); ASSERT_EFI_ERROR (Status); =20 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 # used in DXE or SMM without modification. # -# Copyright (c) 2021, Intel Corporation. All rights reserved.
+# Copyright (c) 2021 - 2022, Intel Corporation. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -24,6 +24,7 @@ MODULE_TYPE =3D DXE_RUNTIME_DRIVER LIBRARY_CLASS =3D VariableWriteLib|DXE_CORE DXE_DRIVER = DXE_RUNTIME_DRIVER UEFI_APPLICATION UEFI_DRIVER CONSTRUCTOR =3D DxeRuntimeVariableWriteLibConstructor + DESTRUCTOR =3D DxeRuntimeVariableWriteLibDestructor =20 [Packages] MdePkg/MdePkg.dec @@ -37,13 +38,14 @@ UefiLib UefiBootServicesTableLib UefiRuntimeServicesTableLib + VariablePolicyHelperLib =20 [Guids] gEfiEventExitBootServicesGuid ## CONSUMES ## Event =20 [Protocols] gEfiVariableWriteArchProtocolGuid ## CONSUMES - gEdkiiVariableLockProtocolGuid ## CONSUMES + gEdkiiVariablePolicyProtocolGuid ## CONSUMES =20 [Depex] - gEfiVariableWriteArchProtocolGuid AND gEdkiiVariableLockProtocolGuid + gEfiVariableWriteArchProtocolGuid AND gEdkiiVariablePolicyProtocolGuid --=20 2.28.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#86450): https://edk2.groups.io/g/devel/message/86450 Mute This Topic: https://groups.io/mt/88999986/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-