From nobody Wed Oct 30 19:55:53 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+105209+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+105209+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1684889315; cv=none; d=zohomail.com; s=zohoarc; b=jGMTafWJP3qDCrVOKP06tDPvPgFtvdNZ+sDf0k4b/p6jp/3qC7uJEmfv2SgKXJxpOGp+If2AB1zet1a5ICfB2tp9mkvUkk6LDXcxbvIiT88E3zptrwudMOV5gwucRYw9amR2sZTazYIVUVP/BXpzTq4SnK8DbckPuf1jAEs89T8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684889315; 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=52MBoh5YyCkFvm6DICVa6YIzxIgqwoz/oMvetApM+LU=; b=K88QBtPJ180o08Y4OlqBS5eJEtJlshTL1gmkWXZ1xOLcDDLnSLRzEYP3+NZe/82+tCCLwZ1kqkWY+Gi1NCKFQ41lUQBzHu8jta0qSnxQ8tmdBSxAceMFT3dMhW3OhWRPMuuR+08LFMeOp/vhjAGGxWpsbxrJrX6+iebiARYwoIw= 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+105209+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 1684889315824179.46907719180103; Tue, 23 May 2023 17:48:35 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id JJvhYY1788612x14o49jPTpN; Tue, 23 May 2023 17:48:35 -0700 X-Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.1309.1684889314120113380 for ; Tue, 23 May 2023 17:48:34 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10719"; a="355762694" X-IronPort-AV: E=Sophos;i="6.00,187,1681196400"; d="scan'208";a="355762694" X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2023 17:44:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10719"; a="1034269399" X-IronPort-AV: E=Sophos;i="6.00,187,1681196400"; d="scan'208";a="1034269399" X-Received: from mshindo-desk2.amr.corp.intel.com ([10.53.88.126]) by fmsmga005.fm.intel.com with ESMTP; 23 May 2023 17:44:10 -0700 From: "Miki Shindo" To: devel@edk2.groups.io Cc: Chasel Chiu , Nate DeSimone , Liming Gao , Eric Dong , Xiaoqiang Zhang Subject: [edk2-devel] [edk2-platforms:PATCH v2] MinPlatformPkg: Fix SetLargeVariable fail issue Date: Tue, 23 May 2023 17:44:03 -0700 Message-Id: <20230524004403.3338-1-miki.shindo@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,miki.shindo@intel.com X-Gm-Message-State: KCS6ouU3rxRxDuLu11MzNFvFx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1684889315; bh=da/FfhzvRr4iSIDAQXzEaV6H8QxGRhkzZ4yB8BGJ7gI=; h=Cc:Date:From:Reply-To:Subject:To; b=nfWC86J/7dV7IDNMWnu5W+jC/lTdQVr9eiukfaiaQ9rmQhi5rkqz4WUBu/9w87iQMdl bdrJN4eH5niW3Uie+i+DGIVwUv/laplQsgXLRkH7ZnJ2PeVPoNOWgKEtj5hHODEGyJ7dK xDZyOCl6aXyl6hCv+L+VjXpjq+iIzy/ykIQ= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1684889317238100001 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4454 On Server platform, when the large variable "FspNvsBuffer" is already in th= e UEFI variable store and the remaining variable storage space is less than= the large variable size, and also not in OS runtime, then we need to add t= he size of the current data that will end up being replaced by the new data= to the remaining space before we decide that there is not enough space to = store the large variable. Cc: Chasel Chiu Cc: Nate DeSimone Cc: Liming Gao Cc: Eric Dong Co-authored-by: Xiaoqiang Zhang Signed-off-by: Miki Shindo Reviewed-by: Chasel Chiu > Reviewed-by: Nate DeSimone > Reviewed-by: Nate DeSimone --- Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVariableWr= iteLib.c | 10 +++++++++- Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeRuntim= eVariableWriteLib.c | 15 +++++++++++++++ Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/SmmVariableWrite= Common.c | 16 ++++++++++++++++ Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/StandaloneMmVari= ableWriteLibConstructor.c | 30 ++++++++++++++++++++++++++++++ Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/TraditionalMmVar= iableWriteLibConstructor.c | 30 ++++++++++++++++++++++++++++++ Platform/Intel/MinPlatformPkg/Include/Library/VariableWriteLib.h = | 12 ++++++++++++ Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/BaseLargeVariab= leWriteLib.inf | 1 + Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/StandaloneMmVari= ableWriteLib.inf | 3 ++- Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/TraditionalMmVar= iableWriteLib.inf | 3 ++- 9 files changed, 117 insertions(+), 3 deletions(-) diff --git a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/Lar= geVariableWriteLib.c b/Platform/Intel/MinPlatformPkg/Library/BaseLargeVaria= bleLib/LargeVariableWriteLib.c index de23ae6160..4bf9a6994f 100644 --- a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVaria= bleWriteLib.c +++ b/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/LargeVaria= bleWriteLib.c @@ -22,7 +22,7 @@ #include #include #include - +#include #include "LargeVariableCommon.h" =20 /** @@ -270,6 +270,7 @@ SetLargeVariable ( UINT8 *OffsetPtr; UINTN BytesRemaining; UINTN SizeToSave; + UINTN BufferSize =3D 0; =20 // // Check input parameters. @@ -365,6 +366,13 @@ SetLargeVariable ( // Non-Volatile storage to store the data. // RemainingVariableStorage =3D GetRemainingVariableStorageSpace (); + // + // Check if current variable already existed in NV storage variable sp= ace + // + Status =3D GetLargeVariable (VariableName, VendorGuid, &BufferSize, NU= LL); + if ((Status =3D=3D EFI_BUFFER_TOO_SMALL) && (BufferSize !=3D 0) && !Va= rLibAtOsRuntime ()) { + RemainingVariableStorage =3D RemainingVariableStorage + BufferSize; + } if (DataSize > RemainingVariableStorage) { DEBUG ((DEBUG_ERROR, "SetLargeVariable: Not enough NV storage space = to store the data\n")); Status =3D EFI_OUT_OF_RESOURCES; diff --git a/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteL= ib/DxeRuntimeVariableWriteLib.c b/Platform/Intel/MinPlatformPkg/Library/Dxe= RuntimeVariableWriteLib/DxeRuntimeVariableWriteLib.c index 28730f858b..9ca4734f24 100644 --- a/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeR= untimeVariableWriteLib.c +++ b/Platform/Intel/MinPlatformPkg/Library/DxeRuntimeVariableWriteLib/DxeR= untimeVariableWriteLib.c @@ -195,6 +195,21 @@ VarLibVariableRequestToLock ( return Status; } =20 +/** + Indicator of whether it is runtime or not. + + @retval TRUE It is Runtime. + @retval FALSE It is not Runtime. +**/ +BOOLEAN +EFIAPI +VarLibAtOsRuntime ( + VOID + ) +{ + return (mVariableWriteLibVariablePolicy =3D=3D NULL) ? TRUE : FALSE; +} + /** Close events when driver unloaded. =20 diff --git a/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/SmmV= ariableWriteCommon.c b/Platform/Intel/MinPlatformPkg/Library/SmmVariableWri= teLib/SmmVariableWriteCommon.c index 50ebb544b8..cd7118d1fb 100644 --- a/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/SmmVariable= WriteCommon.c +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/SmmVariable= WriteCommon.c @@ -18,6 +18,7 @@ #include =20 EFI_SMM_VARIABLE_PROTOCOL *mVariableWriteLibSmmVariable =3D NULL; +BOOLEAN mEfiAtRuntime =3D FALSE; =20 /** Sets the value of a variable. @@ -169,3 +170,18 @@ VarLibVariableRequestToLock ( // return EFI_UNSUPPORTED; } + +/** + Indicator of whether it is runtime or not. + + @retval TRUE It is Runtime. + @retval FALSE It is not Runtime. +**/ +BOOLEAN +EFIAPI +VarLibAtOsRuntime ( + VOID + ) +{ + return mEfiAtRuntime; +} diff --git a/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/Stan= daloneMmVariableWriteLibConstructor.c b/Platform/Intel/MinPlatformPkg/Libra= ry/SmmVariableWriteLib/StandaloneMmVariableWriteLibConstructor.c index d39418abd2..8c2b7d18f5 100644 --- a/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/StandaloneM= mVariableWriteLibConstructor.c +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/StandaloneM= mVariableWriteLibConstructor.c @@ -20,6 +20,28 @@ #include =20 extern EFI_SMM_VARIABLE_PROTOCOL *mVariableWriteLibSmmVariable; +extern BOOLEAN mEfiAtRuntime; + +/** + Callback for ExitBootService, which is registered at the constructor. + This callback sets a global variable mEfiAtRuntime to indicate whether + it is after ExitBootService. + + @param[in] Protocol Protocol unique ID. + @param[in] Interface Interface instance. + @param[in] Handle The handle on which the interface is installe= d. +**/ +EFI_STATUS +EFIAPI +VarLibExitBootServicesCallback ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + mEfiAtRuntime =3D TRUE; + return EFI_SUCCESS; +} =20 /** The constructor function acquires the EFI SMM Variable Services @@ -41,11 +63,19 @@ StandaloneMmVariableWriteLibConstructor ( ) { EFI_STATUS Status; + VOID *Registration =3D NULL; =20 // // Locate SmmVariableProtocol. // Status =3D gMmst->MmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, = (VOID **) &mVariableWriteLibSmmVariable); ASSERT_EFI_ERROR (Status); + + // + // Register VarLibExitBootServicesCallback for gEdkiiSmmExitBootServices= ProtocolGuid. + // + Status =3D SmmRegisterProtocolNotify (&gEdkiiSmmExitBootServicesProtocol= Guid, VarLibExitBootServicesCallback, &Registration); + ASSERT_EFI_ERROR (Status); + return Status; } diff --git a/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/Trad= itionalMmVariableWriteLibConstructor.c b/Platform/Intel/MinPlatformPkg/Libr= ary/SmmVariableWriteLib/TraditionalMmVariableWriteLibConstructor.c index d142527e17..abc1e25cde 100644 --- a/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/Traditional= MmVariableWriteLibConstructor.c +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/Traditional= MmVariableWriteLibConstructor.c @@ -20,6 +20,28 @@ #include =20 extern EFI_SMM_VARIABLE_PROTOCOL *mVariableWriteLibSmmVariable; +extern BOOLEAN mEfiAtRuntime; + +/** + Callback for ExitBootService, which is registered at the constructor. + This callback sets a global variable mEfiAtRuntime to indicate whether + it is after ExitBootService. + + @param[in] Protocol Protocol unique ID. + @param[in] Interface Interface instance. + @param[in] Handle The handle on which the interface is installe= d. +**/ +EFI_STATUS +EFIAPI +VarLibExitBootServicesCallback ( + IN CONST EFI_GUID *Protocol, + IN VOID *Interface, + IN EFI_HANDLE Handle + ) +{ + mEfiAtRuntime =3D TRUE; + return EFI_SUCCESS; +} =20 /** The constructor function acquires the EFI SMM Variable Services @@ -41,11 +63,19 @@ TraditionalMmVariableWriteLibConstructor ( ) { EFI_STATUS Status; + VOID *Registration =3D NULL; =20 // // Locate SmmVariableProtocol. // Status =3D gSmst->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL,= (VOID **) &mVariableWriteLibSmmVariable); ASSERT_EFI_ERROR (Status); + + // + // Register VarLibExitBootServicesCallback for gEdkiiSmmExitBootServices= ProtocolGuid. + // + Status =3D SmmRegisterProtocolNotify (&gEdkiiSmmExitBootServicesProtocol= Guid, VarLibExitBootServicesCallback, &Registration); + ASSERT_EFI_ERROR (Status); + return Status; } diff --git a/Platform/Intel/MinPlatformPkg/Include/Library/VariableWriteLib= .h b/Platform/Intel/MinPlatformPkg/Include/Library/VariableWriteLib.h index fab87f2e48..bc0b52d782 100644 --- a/Platform/Intel/MinPlatformPkg/Include/Library/VariableWriteLib.h +++ b/Platform/Intel/MinPlatformPkg/Include/Library/VariableWriteLib.h @@ -135,4 +135,16 @@ VarLibVariableRequestToLock ( IN EFI_GUID *VendorGuid ); =20 +/** + Indicator of whether it is runtime or not. + + @retval TRUE It is Runtime. + @retval FALSE It is not Runtime. +**/ +BOOLEAN +EFIAPI +VarLibAtOsRuntime ( + VOID + ); + #endif // _VARIABLE_WRITE_LIB_H_ diff --git a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/Bas= eLargeVariableWriteLib.inf b/Platform/Intel/MinPlatformPkg/Library/BaseLarg= eVariableLib/BaseLargeVariableWriteLib.inf index 2493a94596..cbc2a5d93a 100644 --- a/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/BaseLargeV= ariableWriteLib.inf +++ b/Platform/Intel/MinPlatformPkg/Library/BaseLargeVariableLib/BaseLargeV= ariableWriteLib.inf @@ -49,3 +49,4 @@ PrintLib VariableReadLib VariableWriteLib + LargeVariableReadLib diff --git a/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/Stan= daloneMmVariableWriteLib.inf b/Platform/Intel/MinPlatformPkg/Library/SmmVar= iableWriteLib/StandaloneMmVariableWriteLib.inf index 0d1c63a297..868be49630 100644 --- a/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/StandaloneM= mVariableWriteLib.inf +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/StandaloneM= mVariableWriteLib.inf @@ -39,7 +39,8 @@ MmServicesTableLib =20 [Protocols] - gEfiSmmVariableProtocolGuid ## CONSUMES + gEfiSmmVariableProtocolGuid ## CONSUMES + gEdkiiSmmExitBootServicesProtocolGuid ## CONSUMES =20 [Depex] gEfiSmmVariableProtocolGuid diff --git a/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/Trad= itionalMmVariableWriteLib.inf b/Platform/Intel/MinPlatformPkg/Library/SmmVa= riableWriteLib/TraditionalMmVariableWriteLib.inf index 5d833b7e0f..4aaab069ab 100644 --- a/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/Traditional= MmVariableWriteLib.inf +++ b/Platform/Intel/MinPlatformPkg/Library/SmmVariableWriteLib/Traditional= MmVariableWriteLib.inf @@ -38,7 +38,8 @@ SmmServicesTableLib =20 [Protocols] - gEfiSmmVariableProtocolGuid ## CONSUMES + gEfiSmmVariableProtocolGuid ## CONSUMES + gEdkiiSmmExitBootServicesProtocolGuid ## CONSUMES =20 [Depex] gEfiSmmVariableProtocolGuid --=20 2.39.1.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 (#105209): https://edk2.groups.io/g/devel/message/105209 Mute This Topic: https://groups.io/mt/99099949/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-