From nobody Wed Apr 24 23:27:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49722+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49722+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1572504324; cv=none; d=zoho.com; s=zohoarc; b=PwexdimkfyGB013CeCpGAbQzVwk3QvklxLQ+4ceuastgY50p8pY92C+8MfDRmamYiBoQ9/xvs39dBw6j77OiiouzESGQKh7OX12S+6/mBHoini24Diu2f11TqBHENetRluVYWXZxF3X3LqClL0xkFNx0qY7CB9RLvBIBFj26FKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572504324; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=Z7mwm+Zf/astreepxnJYHJz6XL5Hr7+Zja/YOt3GY/4=; b=G+PJhYY/c1g91p7rlRVFHvKCo3eVqryIUwMwlcHww3DFzVTCp5m5n7eCLuuvkRBFthdBQN/tYNiz5CVGvjKelSDA3c8RiQQIeTyccuNYrHyPsRbw8A5cCJEa0fqIAT2W7lJfjIjLITooXomYBtKtETUFvIWRuI8bgA6dxJM670c= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49722+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1572504324413710.8116238348106; Wed, 30 Oct 2019 23:45:24 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 1YoPYY1788612xep4xiMtELS; Wed, 30 Oct 2019 23:45:23 -0700 X-Received: from mga12.intel.com (mga12.intel.com []) by mx.groups.io with SMTP id smtpd.web11.2630.1572504319485870696 for ; Wed, 30 Oct 2019 23:45:23 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 23:45:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,250,1569308400"; d="scan'208";a="351547244" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga004.jf.intel.com with ESMTP; 30 Oct 2019 23:45:21 -0700 From: "Kubacki, Michael A" To: devel@edk2.groups.io Cc: Dandan Bi , Ard Biesheuvel , Eric Dong , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu , Jiewen Yao Subject: [edk2-devel] [PATCH V6 01/10] MdeModulePkg/Variable: Consolidate common parsing functions Date: Wed, 30 Oct 2019 23:45:01 -0700 Message-Id: <20191031064510.23948-2-michael.a.kubacki@intel.com> In-Reply-To: <20191031064510.23948-1-michael.a.kubacki@intel.com> References: <20191031064510.23948-1-michael.a.kubacki@intel.com> Precedence: Bulk List-Unsubscribe: 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,michael.a.kubacki@intel.com X-Gm-Message-State: pRQq7NNV0sBrjuxOeu3gczQ7x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572504323; bh=Ukfab4GXo1nDd04Cz2Eg3QApnFe5WmOTIGS9SETcNzg=; h=Cc:Date:From:Reply-To:Subject:To; b=cOHf3pMtKBWg6fXiGXPFk4duBEQWSTo4lG0ArpFN90ZH8UTnw8aRbQN16PMro2SFRWx UfWQusgbWS2ltayu/KbNTdMVtO04pOfEFAehBWTld/ArNSwN8W9l13qXZwfWxQBzAxB/M Iun8UUBWAP38Uo+K320KnD70G9dg/xmkrWs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This change moves the following functions into a dedicated file so they may be used in other variable files as needed. These are commonly needed for basic variable data structure parsing operations. The functions are grouped together in VariableParsing.c to support cohesiveness for these operations in the file. Furthermore, it reduces the overall size of the common Variable.c file. * DataSizeOfVariable () * FindVariableEx () * GetEndPointer () * GetNextVariablePtr () * GetStartPointer () * GetVariableDataOffset () * GetVariableDataPtr () * GetVariableHeaderSize () * GetVariableNamePtr () * GetVariableStoreStatus () * GetVendorGuidPtr () * IsValidVariableHeader () * NameSizeOfVariable () * SetDataSizeOfVariable () * SetNameSizeOfVariable () * UpdateVariableInfo () * VariableCompareTimeStampInternal () * VariableServiceGetNextVariableInternal () Cc: Dandan Bi Cc: Ard Biesheuvel Cc: Eric Dong Cc: Laszlo Ersek Cc: Liming Gao Cc: Michael D Kinney Cc: Ray Ni Cc: Jian J Wang Cc: Hao A Wu Cc: Jiewen Yao Signed-off-by: Michael Kubacki Reviewed-by: Jian J Wang --- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf | 2 + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf | 2 + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf | 2 + MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h | 119 = ---- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h | 306 = ++++++++ MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 726 = +------------------ MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c | 3 = +- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c | 731 = ++++++++++++++++++++ MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 1 + 9 files changed, 1047 insertions(+), 845 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.= inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf index 641376c9c5..c35e5fe787 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf @@ -36,6 +36,8 @@ Variable.c VariableDxe.c Variable.h + VariableParsing.c + VariableParsing.h PrivilegePolymorphic.h Measurement.c TcgMorLockDxe.c diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf b/M= deModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf index 0a160d269d..626738b9c7 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf @@ -45,6 +45,8 @@ Variable.c VariableTraditionalMm.c VariableSmm.c + VariableParsing.c + VariableParsing.h VarCheck.c Variable.h PrivilegePolymorphic.h diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneM= m.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf index 21bc81163b..ff714b193a 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf @@ -45,6 +45,8 @@ Variable.c VariableSmm.c VariableStandaloneMm.c + VariableParsing.c + VariableParsing.h VarCheck.c Variable.h PrivilegePolymorphic.h diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.h index 9eac43759f..fb574b2e32 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h @@ -179,89 +179,6 @@ FindVariable ( IN BOOLEAN IgnoreRtCheck ); =20 -/** - - Gets the pointer to the end of the variable storage area. - - This function gets pointer to the end of the variable storage - area, according to the input variable store header. - - @param VarStoreHeader Pointer to the Variable Store Header. - - @return Pointer to the end of the variable storage area. - -**/ -VARIABLE_HEADER * -GetEndPointer ( - IN VARIABLE_STORE_HEADER *VarStoreHeader - ); - -/** - This code gets the size of variable header. - - @return Size of variable header in bytes in type UINTN. - -**/ -UINTN -GetVariableHeaderSize ( - VOID - ); - -/** - - This code gets the pointer to the variable name. - - @param Variable Pointer to the Variable Header. - - @return Pointer to Variable Name which is Unicode encoding. - -**/ -CHAR16 * -GetVariableNamePtr ( - IN VARIABLE_HEADER *Variable - ); - -/** - This code gets the pointer to the variable guid. - - @param Variable Pointer to the Variable Header. - - @return A EFI_GUID* pointer to Vendor Guid. - -**/ -EFI_GUID * -GetVendorGuidPtr ( - IN VARIABLE_HEADER *Variable - ); - -/** - - This code gets the pointer to the variable data. - - @param Variable Pointer to the Variable Header. - - @return Pointer to Variable Data. - -**/ -UINT8 * -GetVariableDataPtr ( - IN VARIABLE_HEADER *Variable - ); - -/** - - This code gets the size of variable data. - - @param Variable Pointer to the Variable Header. - - @return Size of variable in bytes. - -**/ -UINTN -DataSizeOfVariable ( - IN VARIABLE_HEADER *Variable - ); - /** This function is to check if the remaining variable space is enough to s= et all Variables from argument list successfully. The purpose of the check @@ -450,17 +367,6 @@ ReclaimForOS( VOID ); =20 -/** - Get non-volatile maximum variable size. - - @return Non-volatile maximum variable size. - -**/ -UINTN -GetNonVolatileMaxVariableSize ( - VOID - ); - /** Get maximum variable size, covering both non-volatile and volatile varia= bles. =20 @@ -546,31 +452,6 @@ VariableServiceGetVariable ( OUT VOID *Data OPTIONAL ); =20 -/** - This code Finds the Next available variable. - - Caution: This function may receive untrusted input. - This function may be invoked in SMM mode. This function will do basic va= lidation, before parse the data. - - @param[in] VariableName Pointer to variable name. - @param[in] VendorGuid Variable Vendor Guid. - @param[out] VariablePtr Pointer to variable header address. - - @retval EFI_SUCCESS The function completed successfully. - @retval EFI_NOT_FOUND The next variable was not found. - @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, wh= ile VendorGuid is NULL. - @retval EFI_INVALID_PARAMETER The input values of VariableName and Vendo= rGuid are not a name and - GUID of an existing variable. - -**/ -EFI_STATUS -EFIAPI -VariableServiceGetNextVariableInternal ( - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - OUT VARIABLE_HEADER **VariablePtr - ); - /** =20 This code Finds the Next available variable. diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h b= /MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h new file mode 100644 index 0000000000..b0d7f76bd8 --- /dev/null +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h @@ -0,0 +1,306 @@ +/** @file + Functions in this module are associated with variable parsing operations= and + are intended to be usable across variable driver source files. + +Copyright (c) 2019, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _VARIABLE_PARSING_H_ +#define _VARIABLE_PARSING_H_ + +#include +#include "Variable.h" + +/** + + This code checks if variable header is valid or not. + + @param[in] Variable Pointer to the Variable Header. + @param[in] VariableStoreEnd Pointer to the Variable Store End. + + @retval TRUE Variable header is valid. + @retval FALSE Variable header is not valid. + +**/ +BOOLEAN +IsValidVariableHeader ( + IN VARIABLE_HEADER *Variable, + IN VARIABLE_HEADER *VariableStoreEnd + ); + +/** + + This code gets the current status of Variable Store. + + @param[in] VarStoreHeader Pointer to the Variable Store Header. + + @retval EfiRaw Variable store status is raw. + @retval EfiValid Variable store status is valid. + @retval EfiInvalid Variable store status is invalid. + +**/ +VARIABLE_STORE_STATUS +GetVariableStoreStatus ( + IN VARIABLE_STORE_HEADER *VarStoreHeader + ); + +/** + This code gets the size of variable header. + + @return Size of variable header in bytes in type UINTN. + +**/ +UINTN +GetVariableHeaderSize ( + VOID + ); + +/** + + This code gets the size of name of variable. + + @param Variable Pointer to the Variable Header. + + @return UINTN Size of variable in bytes. + +**/ +UINTN +NameSizeOfVariable ( + IN VARIABLE_HEADER *Variable + ); + +/** + This code sets the size of name of variable. + + @param[in] Variable Pointer to the Variable Header. + @param[in] NameSize Name size to set. + +**/ +VOID +SetNameSizeOfVariable ( + IN VARIABLE_HEADER *Variable, + IN UINTN NameSize + ); + +/** + + This code gets the size of variable data. + + @param Variable Pointer to the Variable Header. + + @return Size of variable in bytes. + +**/ +UINTN +DataSizeOfVariable ( + IN VARIABLE_HEADER *Variable + ); + +/** + This code sets the size of variable data. + + @param[in] Variable Pointer to the Variable Header. + @param[in] DataSize Data size to set. + +**/ +VOID +SetDataSizeOfVariable ( + IN VARIABLE_HEADER *Variable, + IN UINTN DataSize + ); + +/** + + This code gets the pointer to the variable name. + + @param Variable Pointer to the Variable Header. + + @return Pointer to Variable Name which is Unicode encoding. + +**/ +CHAR16 * +GetVariableNamePtr ( + IN VARIABLE_HEADER *Variable + ); + +/** + This code gets the pointer to the variable guid. + + @param Variable Pointer to the Variable Header. + + @return A EFI_GUID* pointer to Vendor Guid. + +**/ +EFI_GUID * +GetVendorGuidPtr ( + IN VARIABLE_HEADER *Variable + ); + +/** + + This code gets the pointer to the variable data. + + @param Variable Pointer to the Variable Header. + + @return Pointer to Variable Data. + +**/ +UINT8 * +GetVariableDataPtr ( + IN VARIABLE_HEADER *Variable + ); + +/** + This code gets the variable data offset related to variable header. + + @param Variable Pointer to the Variable Header. + + @return Variable Data offset. + +**/ +UINTN +GetVariableDataOffset ( + IN VARIABLE_HEADER *Variable + ); + +/** + + This code gets the pointer to the next variable header. + + @param Variable Pointer to the Variable Header. + + @return Pointer to next variable header. + +**/ +VARIABLE_HEADER * +GetNextVariablePtr ( + IN VARIABLE_HEADER *Variable + ); + +/** + + Gets the pointer to the first variable header in given variable store ar= ea. + + @param[in] VarStoreHeader Pointer to the Variable Store Header. + + @return Pointer to the first variable header. + +**/ +VARIABLE_HEADER * +GetStartPointer ( + IN VARIABLE_STORE_HEADER *VarStoreHeader + ); + +/** + + Gets the pointer to the end of the variable storage area. + + This function gets pointer to the end of the variable storage + area, according to the input variable store header. + + @param[in] VarStoreHeader Pointer to the Variable Store Header. + + @return Pointer to the end of the variable storage area. + +**/ +VARIABLE_HEADER * +GetEndPointer ( + IN VARIABLE_STORE_HEADER *VarStoreHeader + ); + +/** + Compare two EFI_TIME data. + + + @param[in] FirstTime A pointer to the first EFI_TIME data. + @param[in] SecondTime A pointer to the second EFI_TIME data. + + @retval TRUE The FirstTime is not later than the SecondTim= e. + @retval FALSE The FirstTime is later than the SecondTime. + +**/ +BOOLEAN +VariableCompareTimeStampInternal ( + IN EFI_TIME *FirstTime, + IN EFI_TIME *SecondTime + ); + +/** + Find the variable in the specified variable store. + + @param[in] VariableName Name of the variable to be found + @param[in] VendorGuid Vendor GUID to be found. + @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS = attribute + check at runtime when searching var= iable. + @param[in, out] PtrTrack Variable Track Pointer structure th= at contains Variable Information. + + @retval EFI_SUCCESS Variable found successfully + @retval EFI_NOT_FOUND Variable not found +**/ +EFI_STATUS +FindVariableEx ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + IN BOOLEAN IgnoreRtCheck, + IN OUT VARIABLE_POINTER_TRACK *PtrTrack + ); + +/** + This code Finds the Next available variable. + + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode. This function will do basic va= lidation, before parse the data. + + @param[in] VariableName Pointer to variable name. + @param[in] VendorGuid Variable Vendor Guid. + @param[out] VariablePtr Pointer to variable header address. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The next variable was not found. + @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, wh= ile VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER The input values of VariableName and Vendo= rGuid are not a name and + GUID of an existing variable. + +**/ +EFI_STATUS +EFIAPI +VariableServiceGetNextVariableInternal ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT VARIABLE_HEADER **VariablePtr + ); + +/** + Routine used to track statistical information about variable usage. + The data is stored in the EFI system table so it can be accessed later. + VariableInfo.efi can dump out the table. Only Boot Services variable + accesses are tracked by this code. The PcdVariableCollectStatistics + build flag controls if this feature is enabled. + + A read that hits in the cache will have Read and Cache true for + the transaction. Data is allocated by this routine, but never + freed. + + @param[in] VariableName Name of the Variable to track. + @param[in] VendorGuid Guid of the Variable to track. + @param[in] Volatile TRUE if volatile FALSE if non-volatile. + @param[in] Read TRUE if GetVariable() was called. + @param[in] Write TRUE if SetVariable() was called. + @param[in] Delete TRUE if deleted via SetVariable(). + @param[in] Cache TRUE for a cache hit. + +**/ +VOID +UpdateVariableInfo ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + IN BOOLEAN Volatile, + IN BOOLEAN Read, + IN BOOLEAN Write, + IN BOOLEAN Delete, + IN BOOLEAN Cache + ); + +#endif diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.c index f32c9c2808..76536308e6 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -23,6 +23,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #include "Variable.h" +#include "VariableParsing.h" =20 VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal; =20 @@ -92,131 +93,6 @@ AUTH_VAR_LIB_CONTEXT_IN mAuthContextIn =3D { =20 AUTH_VAR_LIB_CONTEXT_OUT mAuthContextOut; =20 -/** - Routine used to track statistical information about variable usage. - The data is stored in the EFI system table so it can be accessed later. - VariableInfo.efi can dump out the table. Only Boot Services variable - accesses are tracked by this code. The PcdVariableCollectStatistics - build flag controls if this feature is enabled. - - A read that hits in the cache will have Read and Cache true for - the transaction. Data is allocated by this routine, but never - freed. - - @param[in] VariableName Name of the Variable to track. - @param[in] VendorGuid Guid of the Variable to track. - @param[in] Volatile TRUE if volatile FALSE if non-volatile. - @param[in] Read TRUE if GetVariable() was called. - @param[in] Write TRUE if SetVariable() was called. - @param[in] Delete TRUE if deleted via SetVariable(). - @param[in] Cache TRUE for a cache hit. - -**/ -VOID -UpdateVariableInfo ( - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - IN BOOLEAN Volatile, - IN BOOLEAN Read, - IN BOOLEAN Write, - IN BOOLEAN Delete, - IN BOOLEAN Cache - ) -{ - VARIABLE_INFO_ENTRY *Entry; - - if (FeaturePcdGet (PcdVariableCollectStatistics)) { - - if (AtRuntime ()) { - // Don't collect statistics at runtime. - return; - } - - if (gVariableInfo =3D=3D NULL) { - // - // On the first call allocate a entry and place a pointer to it in - // the EFI System Table. - // - gVariableInfo =3D AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY)); - ASSERT (gVariableInfo !=3D NULL); - - CopyGuid (&gVariableInfo->VendorGuid, VendorGuid); - gVariableInfo->Name =3D AllocateZeroPool (StrSize (VariableName)); - ASSERT (gVariableInfo->Name !=3D NULL); - StrCpyS (gVariableInfo->Name, StrSize(VariableName)/sizeof(CHAR16), = VariableName); - gVariableInfo->Volatile =3D Volatile; - } - - - for (Entry =3D gVariableInfo; Entry !=3D NULL; Entry =3D Entry->Next) { - if (CompareGuid (VendorGuid, &Entry->VendorGuid)) { - if (StrCmp (VariableName, Entry->Name) =3D=3D 0) { - if (Read) { - Entry->ReadCount++; - } - if (Write) { - Entry->WriteCount++; - } - if (Delete) { - Entry->DeleteCount++; - } - if (Cache) { - Entry->CacheCount++; - } - - return; - } - } - - if (Entry->Next =3D=3D NULL) { - // - // If the entry is not in the table add it. - // Next iteration of the loop will fill in the data. - // - Entry->Next =3D AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY)); - ASSERT (Entry->Next !=3D NULL); - - CopyGuid (&Entry->Next->VendorGuid, VendorGuid); - Entry->Next->Name =3D AllocateZeroPool (StrSize (VariableName)); - ASSERT (Entry->Next->Name !=3D NULL); - StrCpyS (Entry->Next->Name, StrSize(VariableName)/sizeof(CHAR16), = VariableName); - Entry->Next->Volatile =3D Volatile; - } - - } - } -} - - -/** - - This code checks if variable header is valid or not. - - @param Variable Pointer to the Variable Header. - @param VariableStoreEnd Pointer to the Variable Store End. - - @retval TRUE Variable header is valid. - @retval FALSE Variable header is not valid. - -**/ -BOOLEAN -IsValidVariableHeader ( - IN VARIABLE_HEADER *Variable, - IN VARIABLE_HEADER *VariableStoreEnd - ) -{ - if ((Variable =3D=3D NULL) || (Variable >=3D VariableStoreEnd) || (Varia= ble->StartId !=3D VARIABLE_DATA)) { - // - // Variable is NULL or has reached the end of variable store, - // or the StartId is not correct. - // - return FALSE; - } - - return TRUE; -} - - /** =20 This function writes data to the FWH at the correct LBA even if the LBAs @@ -376,345 +252,6 @@ UpdateVariableStore ( return EFI_SUCCESS; } =20 - -/** - - This code gets the current status of Variable Store. - - @param VarStoreHeader Pointer to the Variable Store Header. - - @retval EfiRaw Variable store status is raw. - @retval EfiValid Variable store status is valid. - @retval EfiInvalid Variable store status is invalid. - -**/ -VARIABLE_STORE_STATUS -GetVariableStoreStatus ( - IN VARIABLE_STORE_HEADER *VarStoreHeader - ) -{ - if ((CompareGuid (&VarStoreHeader->Signature, &gEfiAuthenticatedVariable= Guid) || - CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid)) && - VarStoreHeader->Format =3D=3D VARIABLE_STORE_FORMATTED && - VarStoreHeader->State =3D=3D VARIABLE_STORE_HEALTHY - ) { - - return EfiValid; - } else if (((UINT32 *)(&VarStoreHeader->Signature))[0] =3D=3D 0xffffffff= && - ((UINT32 *)(&VarStoreHeader->Signature))[1] =3D=3D 0xffffffff= && - ((UINT32 *)(&VarStoreHeader->Signature))[2] =3D=3D 0xffffffff= && - ((UINT32 *)(&VarStoreHeader->Signature))[3] =3D=3D 0xffffffff= && - VarStoreHeader->Size =3D=3D 0xffffffff && - VarStoreHeader->Format =3D=3D 0xff && - VarStoreHeader->State =3D=3D 0xff - ) { - - return EfiRaw; - } else { - return EfiInvalid; - } -} - -/** - This code gets the size of variable header. - - @return Size of variable header in bytes in type UINTN. - -**/ -UINTN -GetVariableHeaderSize ( - VOID - ) -{ - UINTN Value; - - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { - Value =3D sizeof (AUTHENTICATED_VARIABLE_HEADER); - } else { - Value =3D sizeof (VARIABLE_HEADER); - } - - return Value; -} - -/** - - This code gets the size of name of variable. - - @param Variable Pointer to the Variable Header. - - @return UINTN Size of variable in bytes. - -**/ -UINTN -NameSizeOfVariable ( - IN VARIABLE_HEADER *Variable - ) -{ - AUTHENTICATED_VARIABLE_HEADER *AuthVariable; - - AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { - if (AuthVariable->State =3D=3D (UINT8) (-1) || - AuthVariable->DataSize =3D=3D (UINT32) (-1) || - AuthVariable->NameSize =3D=3D (UINT32) (-1) || - AuthVariable->Attributes =3D=3D (UINT32) (-1)) { - return 0; - } - return (UINTN) AuthVariable->NameSize; - } else { - if (Variable->State =3D=3D (UINT8) (-1) || - Variable->DataSize =3D=3D (UINT32) (-1) || - Variable->NameSize =3D=3D (UINT32) (-1) || - Variable->Attributes =3D=3D (UINT32) (-1)) { - return 0; - } - return (UINTN) Variable->NameSize; - } -} - -/** - This code sets the size of name of variable. - - @param[in] Variable Pointer to the Variable Header. - @param[in] NameSize Name size to set. - -**/ -VOID -SetNameSizeOfVariable ( - IN VARIABLE_HEADER *Variable, - IN UINTN NameSize - ) -{ - AUTHENTICATED_VARIABLE_HEADER *AuthVariable; - - AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { - AuthVariable->NameSize =3D (UINT32) NameSize; - } else { - Variable->NameSize =3D (UINT32) NameSize; - } -} - -/** - - This code gets the size of variable data. - - @param Variable Pointer to the Variable Header. - - @return Size of variable in bytes. - -**/ -UINTN -DataSizeOfVariable ( - IN VARIABLE_HEADER *Variable - ) -{ - AUTHENTICATED_VARIABLE_HEADER *AuthVariable; - - AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { - if (AuthVariable->State =3D=3D (UINT8) (-1) || - AuthVariable->DataSize =3D=3D (UINT32) (-1) || - AuthVariable->NameSize =3D=3D (UINT32) (-1) || - AuthVariable->Attributes =3D=3D (UINT32) (-1)) { - return 0; - } - return (UINTN) AuthVariable->DataSize; - } else { - if (Variable->State =3D=3D (UINT8) (-1) || - Variable->DataSize =3D=3D (UINT32) (-1) || - Variable->NameSize =3D=3D (UINT32) (-1) || - Variable->Attributes =3D=3D (UINT32) (-1)) { - return 0; - } - return (UINTN) Variable->DataSize; - } -} - -/** - This code sets the size of variable data. - - @param[in] Variable Pointer to the Variable Header. - @param[in] DataSize Data size to set. - -**/ -VOID -SetDataSizeOfVariable ( - IN VARIABLE_HEADER *Variable, - IN UINTN DataSize - ) -{ - AUTHENTICATED_VARIABLE_HEADER *AuthVariable; - - AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { - AuthVariable->DataSize =3D (UINT32) DataSize; - } else { - Variable->DataSize =3D (UINT32) DataSize; - } -} - -/** - - This code gets the pointer to the variable name. - - @param Variable Pointer to the Variable Header. - - @return Pointer to Variable Name which is Unicode encoding. - -**/ -CHAR16 * -GetVariableNamePtr ( - IN VARIABLE_HEADER *Variable - ) -{ - return (CHAR16 *) ((UINTN) Variable + GetVariableHeaderSize ()); -} - -/** - This code gets the pointer to the variable guid. - - @param Variable Pointer to the Variable Header. - - @return A EFI_GUID* pointer to Vendor Guid. - -**/ -EFI_GUID * -GetVendorGuidPtr ( - IN VARIABLE_HEADER *Variable - ) -{ - AUTHENTICATED_VARIABLE_HEADER *AuthVariable; - - AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { - return &AuthVariable->VendorGuid; - } else { - return &Variable->VendorGuid; - } -} - -/** - - This code gets the pointer to the variable data. - - @param Variable Pointer to the Variable Header. - - @return Pointer to Variable Data. - -**/ -UINT8 * -GetVariableDataPtr ( - IN VARIABLE_HEADER *Variable - ) -{ - UINTN Value; - - // - // Be careful about pad size for alignment. - // - Value =3D (UINTN) GetVariableNamePtr (Variable); - Value +=3D NameSizeOfVariable (Variable); - Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable)); - - return (UINT8 *) Value; -} - -/** - This code gets the variable data offset related to variable header. - - @param Variable Pointer to the Variable Header. - - @return Variable Data offset. - -**/ -UINTN -GetVariableDataOffset ( - IN VARIABLE_HEADER *Variable - ) -{ - UINTN Value; - - // - // Be careful about pad size for alignment - // - Value =3D GetVariableHeaderSize (); - Value +=3D NameSizeOfVariable (Variable); - Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable)); - - return Value; -} - -/** - - This code gets the pointer to the next variable header. - - @param Variable Pointer to the Variable Header. - - @return Pointer to next variable header. - -**/ -VARIABLE_HEADER * -GetNextVariablePtr ( - IN VARIABLE_HEADER *Variable - ) -{ - UINTN Value; - - Value =3D (UINTN) GetVariableDataPtr (Variable); - Value +=3D DataSizeOfVariable (Variable); - Value +=3D GET_PAD_SIZE (DataSizeOfVariable (Variable)); - - // - // Be careful about pad size for alignment. - // - return (VARIABLE_HEADER *) HEADER_ALIGN (Value); -} - -/** - - Gets the pointer to the first variable header in given variable store ar= ea. - - @param VarStoreHeader Pointer to the Variable Store Header. - - @return Pointer to the first variable header. - -**/ -VARIABLE_HEADER * -GetStartPointer ( - IN VARIABLE_STORE_HEADER *VarStoreHeader - ) -{ - // - // The start of variable store. - // - return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1); -} - -/** - - Gets the pointer to the end of the variable storage area. - - This function gets pointer to the end of the variable storage - area, according to the input variable store header. - - @param VarStoreHeader Pointer to the Variable Store Header. - - @return Pointer to the end of the variable storage area. - -**/ -VARIABLE_HEADER * -GetEndPointer ( - IN VARIABLE_STORE_HEADER *VarStoreHeader - ) -{ - // - // The end of variable store - // - return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarSto= reHeader->Size); -} - /** Record variable error flag. =20 @@ -1228,75 +765,6 @@ Done: return Status; } =20 -/** - Find the variable in the specified variable store. - - @param[in] VariableName Name of the variable to be found - @param[in] VendorGuid Vendor GUID to be found. - @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS = attribute - check at runtime when searching var= iable. - @param[in, out] PtrTrack Variable Track Pointer structure th= at contains Variable Information. - - @retval EFI_SUCCESS Variable found successfully - @retval EFI_NOT_FOUND Variable not found -**/ -EFI_STATUS -FindVariableEx ( - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - IN BOOLEAN IgnoreRtCheck, - IN OUT VARIABLE_POINTER_TRACK *PtrTrack - ) -{ - VARIABLE_HEADER *InDeletedVariable; - VOID *Point; - - PtrTrack->InDeletedTransitionPtr =3D NULL; - - // - // Find the variable by walk through HOB, volatile and non-volatile vari= able store. - // - InDeletedVariable =3D NULL; - - for ( PtrTrack->CurrPtr =3D PtrTrack->StartPtr - ; IsValidVariableHeader (PtrTrack->CurrPtr, PtrTrack->EndPtr) - ; PtrTrack->CurrPtr =3D GetNextVariablePtr (PtrTrack->CurrPtr) - ) { - if (PtrTrack->CurrPtr->State =3D=3D VAR_ADDED || - PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITION & VAR_A= DDED) - ) { - if (IgnoreRtCheck || !AtRuntime () || ((PtrTrack->CurrPtr->Attribute= s & EFI_VARIABLE_RUNTIME_ACCESS) !=3D 0)) { - if (VariableName[0] =3D=3D 0) { - if (PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITION &= VAR_ADDED)) { - InDeletedVariable =3D PtrTrack->CurrPtr; - } else { - PtrTrack->InDeletedTransitionPtr =3D InDeletedVariable; - return EFI_SUCCESS; - } - } else { - if (CompareGuid (VendorGuid, GetVendorGuidPtr (PtrTrack->CurrPtr= ))) { - Point =3D (VOID *) GetVariableNamePtr (PtrTrack->CurrPtr); - - ASSERT (NameSizeOfVariable (PtrTrack->CurrPtr) !=3D 0); - if (CompareMem (VariableName, Point, NameSizeOfVariable (PtrTr= ack->CurrPtr)) =3D=3D 0) { - if (PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITI= ON & VAR_ADDED)) { - InDeletedVariable =3D PtrTrack->CurrPtr; - } else { - PtrTrack->InDeletedTransitionPtr =3D InDeletedVariable; - return EFI_SUCCESS; - } - } - } - } - } - } - } - - PtrTrack->CurrPtr =3D InDeletedVariable; - return (PtrTrack->CurrPtr =3D=3D NULL) ? EFI_NOT_FOUND : EFI_SUCCESS; -} - - /** Finds variable in storage blocks of volatile and non-volatile storage ar= eas. =20 @@ -2078,38 +1546,6 @@ AutoUpdateLangVariable ( } } =20 -/** - Compare two EFI_TIME data. - - - @param FirstTime A pointer to the first EFI_TIME data. - @param SecondTime A pointer to the second EFI_TIME data. - - @retval TRUE The FirstTime is not later than the SecondTim= e. - @retval FALSE The FirstTime is later than the SecondTime. - -**/ -BOOLEAN -VariableCompareTimeStampInternal ( - IN EFI_TIME *FirstTime, - IN EFI_TIME *SecondTime - ) -{ - if (FirstTime->Year !=3D SecondTime->Year) { - return (BOOLEAN) (FirstTime->Year < SecondTime->Year); - } else if (FirstTime->Month !=3D SecondTime->Month) { - return (BOOLEAN) (FirstTime->Month < SecondTime->Month); - } else if (FirstTime->Day !=3D SecondTime->Day) { - return (BOOLEAN) (FirstTime->Day < SecondTime->Day); - } else if (FirstTime->Hour !=3D SecondTime->Hour) { - return (BOOLEAN) (FirstTime->Hour < SecondTime->Hour); - } else if (FirstTime->Minute !=3D SecondTime->Minute) { - return (BOOLEAN) (FirstTime->Minute < SecondTime->Minute); - } - - return (BOOLEAN) (FirstTime->Second <=3D SecondTime->Second); -} - /** Update the variable region with Variable information. If EFI_VARIABLE_AU= THENTICATED_WRITE_ACCESS is set, index of associated public key is needed. @@ -2885,166 +2321,6 @@ Done: return Status; } =20 -/** - This code Finds the Next available variable. - - Caution: This function may receive untrusted input. - This function may be invoked in SMM mode. This function will do basic va= lidation, before parse the data. - - @param[in] VariableName Pointer to variable name. - @param[in] VendorGuid Variable Vendor Guid. - @param[out] VariablePtr Pointer to variable header address. - - @retval EFI_SUCCESS The function completed successfully. - @retval EFI_NOT_FOUND The next variable was not found. - @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, wh= ile VendorGuid is NULL. - @retval EFI_INVALID_PARAMETER The input values of VariableName and Vendo= rGuid are not a name and - GUID of an existing variable. - -**/ -EFI_STATUS -EFIAPI -VariableServiceGetNextVariableInternal ( - IN CHAR16 *VariableName, - IN EFI_GUID *VendorGuid, - OUT VARIABLE_HEADER **VariablePtr - ) -{ - VARIABLE_STORE_TYPE Type; - VARIABLE_POINTER_TRACK Variable; - VARIABLE_POINTER_TRACK VariableInHob; - VARIABLE_POINTER_TRACK VariablePtrTrack; - EFI_STATUS Status; - VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax]; - - Status =3D FindVariable (VariableName, VendorGuid, &Variable, &mVariable= ModuleGlobal->VariableGlobal, FALSE); - if (Variable.CurrPtr =3D=3D NULL || EFI_ERROR (Status)) { - // - // For VariableName is an empty string, FindVariable() will try to fin= d and return - // the first qualified variable, and if FindVariable() returns error (= EFI_NOT_FOUND) - // as no any variable is found, still go to return the error (EFI_NOT_= FOUND). - // - if (VariableName[0] !=3D 0) { - // - // For VariableName is not an empty string, and FindVariable() retur= ns error as - // VariableName and VendorGuid are not a name and GUID of an existin= g variable, - // there is no way to get next variable, follow spec to return EFI_I= NVALID_PARAMETER. - // - Status =3D EFI_INVALID_PARAMETER; - } - goto Done; - } - - if (VariableName[0] !=3D 0) { - // - // If variable name is not NULL, get next variable. - // - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); - } - - // - // 0: Volatile, 1: HOB, 2: Non-Volatile. - // The index and attributes mapping must be kept in this order as FindVa= riable - // makes use of this mapping to implement search algorithm. - // - VariableStoreHeader[VariableStoreTypeVolatile] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase; - VariableStoreHeader[VariableStoreTypeHob] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase; - VariableStoreHeader[VariableStoreTypeNv] =3D mNvVariableCache; - - while (TRUE) { - // - // Switch from Volatile to HOB, to Non-Volatile. - // - while (!IsValidVariableHeader (Variable.CurrPtr, Variable.EndPtr)) { - // - // Find current storage index - // - for (Type =3D (VARIABLE_STORE_TYPE) 0; Type < VariableStoreTypeMax; = Type++) { - if ((VariableStoreHeader[Type] !=3D NULL) && (Variable.StartPtr = =3D=3D GetStartPointer (VariableStoreHeader[Type]))) { - break; - } - } - ASSERT (Type < VariableStoreTypeMax); - // - // Switch to next storage - // - for (Type++; Type < VariableStoreTypeMax; Type++) { - if (VariableStoreHeader[Type] !=3D NULL) { - break; - } - } - // - // Capture the case that - // 1. current storage is the last one, or - // 2. no further storage - // - if (Type =3D=3D VariableStoreTypeMax) { - Status =3D EFI_NOT_FOUND; - goto Done; - } - Variable.StartPtr =3D GetStartPointer (VariableStoreHeader[Type]); - Variable.EndPtr =3D GetEndPointer (VariableStoreHeader[Type]); - Variable.CurrPtr =3D Variable.StartPtr; - } - - // - // Variable is found - // - if (Variable.CurrPtr->State =3D=3D VAR_ADDED || Variable.CurrPtr->Stat= e =3D=3D (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) { - if (!AtRuntime () || ((Variable.CurrPtr->Attributes & EFI_VARIABLE_R= UNTIME_ACCESS) !=3D 0)) { - if (Variable.CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITION & VA= R_ADDED)) { - // - // If it is a IN_DELETED_TRANSITION variable, - // and there is also a same ADDED one at the same time, - // don't return it. - // - VariablePtrTrack.StartPtr =3D Variable.StartPtr; - VariablePtrTrack.EndPtr =3D Variable.EndPtr; - Status =3D FindVariableEx ( - GetVariableNamePtr (Variable.CurrPtr), - GetVendorGuidPtr (Variable.CurrPtr), - FALSE, - &VariablePtrTrack - ); - if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State =3D= =3D VAR_ADDED) { - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); - continue; - } - } - - // - // Don't return NV variable when HOB overrides it - // - if ((VariableStoreHeader[VariableStoreTypeHob] !=3D NULL) && (Vari= ableStoreHeader[VariableStoreTypeNv] !=3D NULL) && - (Variable.StartPtr =3D=3D GetStartPointer (VariableStoreHeader= [VariableStoreTypeNv])) - ) { - VariableInHob.StartPtr =3D GetStartPointer (VariableStoreHeader[= VariableStoreTypeHob]); - VariableInHob.EndPtr =3D GetEndPointer (VariableStoreHeader[= VariableStoreTypeHob]); - Status =3D FindVariableEx ( - GetVariableNamePtr (Variable.CurrPtr), - GetVendorGuidPtr (Variable.CurrPtr), - FALSE, - &VariableInHob - ); - if (!EFI_ERROR (Status)) { - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); - continue; - } - } - - *VariablePtr =3D Variable.CurrPtr; - Status =3D EFI_SUCCESS; - goto Done; - } - } - - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); - } - -Done: - return Status; -} - /** =20 This code Finds the Next available variable. diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c b/M= deModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c index cb6fcebe2d..dc78f68fa9 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c @@ -1,12 +1,13 @@ /** @file Provides variable driver extended services. =20 -Copyright (c) 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 #include "Variable.h" +#include "VariableParsing.h" =20 /** Finds variable in storage blocks of volatile and non-volatile storage ar= eas. diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c b= /MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c new file mode 100644 index 0000000000..5698a1a5e4 --- /dev/null +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c @@ -0,0 +1,731 @@ +/** @file + Functions in this module are associated with variable parsing operations= and + are intended to be usable across variable driver source files. + +Copyright (c) 2019, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "VariableParsing.h" + +/** + + This code checks if variable header is valid or not. + + @param[in] Variable Pointer to the Variable Header. + @param[in] VariableStoreEnd Pointer to the Variable Store End. + + @retval TRUE Variable header is valid. + @retval FALSE Variable header is not valid. + +**/ +BOOLEAN +IsValidVariableHeader ( + IN VARIABLE_HEADER *Variable, + IN VARIABLE_HEADER *VariableStoreEnd + ) +{ + if ((Variable =3D=3D NULL) || (Variable >=3D VariableStoreEnd) || (Varia= ble->StartId !=3D VARIABLE_DATA)) { + // + // Variable is NULL or has reached the end of variable store, + // or the StartId is not correct. + // + return FALSE; + } + + return TRUE; +} + +/** + + This code gets the current status of Variable Store. + + @param[in] VarStoreHeader Pointer to the Variable Store Header. + + @retval EfiRaw Variable store status is raw. + @retval EfiValid Variable store status is valid. + @retval EfiInvalid Variable store status is invalid. + +**/ +VARIABLE_STORE_STATUS +GetVariableStoreStatus ( + IN VARIABLE_STORE_HEADER *VarStoreHeader + ) +{ + if ((CompareGuid (&VarStoreHeader->Signature, &gEfiAuthenticatedVariable= Guid) || + CompareGuid (&VarStoreHeader->Signature, &gEfiVariableGuid)) && + VarStoreHeader->Format =3D=3D VARIABLE_STORE_FORMATTED && + VarStoreHeader->State =3D=3D VARIABLE_STORE_HEALTHY + ) { + + return EfiValid; + } else if (((UINT32 *)(&VarStoreHeader->Signature))[0] =3D=3D 0xffffffff= && + ((UINT32 *)(&VarStoreHeader->Signature))[1] =3D=3D 0xffffffff= && + ((UINT32 *)(&VarStoreHeader->Signature))[2] =3D=3D 0xffffffff= && + ((UINT32 *)(&VarStoreHeader->Signature))[3] =3D=3D 0xffffffff= && + VarStoreHeader->Size =3D=3D 0xffffffff && + VarStoreHeader->Format =3D=3D 0xff && + VarStoreHeader->State =3D=3D 0xff + ) { + + return EfiRaw; + } else { + return EfiInvalid; + } +} + +/** + This code gets the size of variable header. + + @return Size of variable header in bytes in type UINTN. + +**/ +UINTN +GetVariableHeaderSize ( + VOID + ) +{ + UINTN Value; + + if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + Value =3D sizeof (AUTHENTICATED_VARIABLE_HEADER); + } else { + Value =3D sizeof (VARIABLE_HEADER); + } + + return Value; +} + +/** + + This code gets the size of name of variable. + + @param Variable Pointer to the Variable Header. + + @return UINTN Size of variable in bytes. + +**/ +UINTN +NameSizeOfVariable ( + IN VARIABLE_HEADER *Variable + ) +{ + AUTHENTICATED_VARIABLE_HEADER *AuthVariable; + + AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; + if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthVariable->State =3D=3D (UINT8) (-1) || + AuthVariable->DataSize =3D=3D (UINT32) (-1) || + AuthVariable->NameSize =3D=3D (UINT32) (-1) || + AuthVariable->Attributes =3D=3D (UINT32) (-1)) { + return 0; + } + return (UINTN) AuthVariable->NameSize; + } else { + if (Variable->State =3D=3D (UINT8) (-1) || + Variable->DataSize =3D=3D (UINT32) (-1) || + Variable->NameSize =3D=3D (UINT32) (-1) || + Variable->Attributes =3D=3D (UINT32) (-1)) { + return 0; + } + return (UINTN) Variable->NameSize; + } +} + +/** + This code sets the size of name of variable. + + @param[in] Variable Pointer to the Variable Header. + @param[in] NameSize Name size to set. + +**/ +VOID +SetNameSizeOfVariable ( + IN VARIABLE_HEADER *Variable, + IN UINTN NameSize + ) +{ + AUTHENTICATED_VARIABLE_HEADER *AuthVariable; + + AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; + if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + AuthVariable->NameSize =3D (UINT32) NameSize; + } else { + Variable->NameSize =3D (UINT32) NameSize; + } +} + +/** + + This code gets the size of variable data. + + @param Variable Pointer to the Variable Header. + + @return Size of variable in bytes. + +**/ +UINTN +DataSizeOfVariable ( + IN VARIABLE_HEADER *Variable + ) +{ + AUTHENTICATED_VARIABLE_HEADER *AuthVariable; + + AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; + if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthVariable->State =3D=3D (UINT8) (-1) || + AuthVariable->DataSize =3D=3D (UINT32) (-1) || + AuthVariable->NameSize =3D=3D (UINT32) (-1) || + AuthVariable->Attributes =3D=3D (UINT32) (-1)) { + return 0; + } + return (UINTN) AuthVariable->DataSize; + } else { + if (Variable->State =3D=3D (UINT8) (-1) || + Variable->DataSize =3D=3D (UINT32) (-1) || + Variable->NameSize =3D=3D (UINT32) (-1) || + Variable->Attributes =3D=3D (UINT32) (-1)) { + return 0; + } + return (UINTN) Variable->DataSize; + } +} + +/** + This code sets the size of variable data. + + @param[in] Variable Pointer to the Variable Header. + @param[in] DataSize Data size to set. + +**/ +VOID +SetDataSizeOfVariable ( + IN VARIABLE_HEADER *Variable, + IN UINTN DataSize + ) +{ + AUTHENTICATED_VARIABLE_HEADER *AuthVariable; + + AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; + if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + AuthVariable->DataSize =3D (UINT32) DataSize; + } else { + Variable->DataSize =3D (UINT32) DataSize; + } +} + +/** + + This code gets the pointer to the variable name. + + @param Variable Pointer to the Variable Header. + + @return Pointer to Variable Name which is Unicode encoding. + +**/ +CHAR16 * +GetVariableNamePtr ( + IN VARIABLE_HEADER *Variable + ) +{ + return (CHAR16 *) ((UINTN) Variable + GetVariableHeaderSize ()); +} + +/** + This code gets the pointer to the variable guid. + + @param Variable Pointer to the Variable Header. + + @return A EFI_GUID* pointer to Vendor Guid. + +**/ +EFI_GUID * +GetVendorGuidPtr ( + IN VARIABLE_HEADER *Variable + ) +{ + AUTHENTICATED_VARIABLE_HEADER *AuthVariable; + + AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; + if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + return &AuthVariable->VendorGuid; + } else { + return &Variable->VendorGuid; + } +} + +/** + + This code gets the pointer to the variable data. + + @param Variable Pointer to the Variable Header. + + @return Pointer to Variable Data. + +**/ +UINT8 * +GetVariableDataPtr ( + IN VARIABLE_HEADER *Variable + ) +{ + UINTN Value; + + // + // Be careful about pad size for alignment. + // + Value =3D (UINTN) GetVariableNamePtr (Variable); + Value +=3D NameSizeOfVariable (Variable); + Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable)); + + return (UINT8 *) Value; +} + +/** + This code gets the variable data offset related to variable header. + + @param Variable Pointer to the Variable Header. + + @return Variable Data offset. + +**/ +UINTN +GetVariableDataOffset ( + IN VARIABLE_HEADER *Variable + ) +{ + UINTN Value; + + // + // Be careful about pad size for alignment + // + Value =3D GetVariableHeaderSize (); + Value +=3D NameSizeOfVariable (Variable); + Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable)); + + return Value; +} + +/** + + This code gets the pointer to the next variable header. + + @param Variable Pointer to the Variable Header. + + @return Pointer to next variable header. + +**/ +VARIABLE_HEADER * +GetNextVariablePtr ( + IN VARIABLE_HEADER *Variable + ) +{ + UINTN Value; + + Value =3D (UINTN) GetVariableDataPtr (Variable); + Value +=3D DataSizeOfVariable (Variable); + Value +=3D GET_PAD_SIZE (DataSizeOfVariable (Variable)); + + // + // Be careful about pad size for alignment. + // + return (VARIABLE_HEADER *) HEADER_ALIGN (Value); +} + +/** + + Gets the pointer to the first variable header in given variable store ar= ea. + + @param[in] VarStoreHeader Pointer to the Variable Store Header. + + @return Pointer to the first variable header. + +**/ +VARIABLE_HEADER * +GetStartPointer ( + IN VARIABLE_STORE_HEADER *VarStoreHeader + ) +{ + // + // The start of variable store. + // + return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1); +} + +/** + + Gets the pointer to the end of the variable storage area. + + This function gets pointer to the end of the variable storage + area, according to the input variable store header. + + @param[in] VarStoreHeader Pointer to the Variable Store Header. + + @return Pointer to the end of the variable storage area. + +**/ +VARIABLE_HEADER * +GetEndPointer ( + IN VARIABLE_STORE_HEADER *VarStoreHeader + ) +{ + // + // The end of variable store + // + return (VARIABLE_HEADER *) HEADER_ALIGN ((UINTN) VarStoreHeader + VarSto= reHeader->Size); +} + +/** + Compare two EFI_TIME data. + + + @param[in] FirstTime A pointer to the first EFI_TIME data. + @param[in] SecondTime A pointer to the second EFI_TIME data. + + @retval TRUE The FirstTime is not later than the SecondTim= e. + @retval FALSE The FirstTime is later than the SecondTime. + +**/ +BOOLEAN +VariableCompareTimeStampInternal ( + IN EFI_TIME *FirstTime, + IN EFI_TIME *SecondTime + ) +{ + if (FirstTime->Year !=3D SecondTime->Year) { + return (BOOLEAN) (FirstTime->Year < SecondTime->Year); + } else if (FirstTime->Month !=3D SecondTime->Month) { + return (BOOLEAN) (FirstTime->Month < SecondTime->Month); + } else if (FirstTime->Day !=3D SecondTime->Day) { + return (BOOLEAN) (FirstTime->Day < SecondTime->Day); + } else if (FirstTime->Hour !=3D SecondTime->Hour) { + return (BOOLEAN) (FirstTime->Hour < SecondTime->Hour); + } else if (FirstTime->Minute !=3D SecondTime->Minute) { + return (BOOLEAN) (FirstTime->Minute < SecondTime->Minute); + } + + return (BOOLEAN) (FirstTime->Second <=3D SecondTime->Second); +} + +/** + Find the variable in the specified variable store. + + @param[in] VariableName Name of the variable to be found + @param[in] VendorGuid Vendor GUID to be found. + @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS = attribute + check at runtime when searching var= iable. + @param[in, out] PtrTrack Variable Track Pointer structure th= at contains Variable Information. + + @retval EFI_SUCCESS Variable found successfully + @retval EFI_NOT_FOUND Variable not found +**/ +EFI_STATUS +FindVariableEx ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + IN BOOLEAN IgnoreRtCheck, + IN OUT VARIABLE_POINTER_TRACK *PtrTrack + ) +{ + VARIABLE_HEADER *InDeletedVariable; + VOID *Point; + + PtrTrack->InDeletedTransitionPtr =3D NULL; + + // + // Find the variable by walk through HOB, volatile and non-volatile vari= able store. + // + InDeletedVariable =3D NULL; + + for ( PtrTrack->CurrPtr =3D PtrTrack->StartPtr + ; IsValidVariableHeader (PtrTrack->CurrPtr, PtrTrack->EndPtr) + ; PtrTrack->CurrPtr =3D GetNextVariablePtr (PtrTrack->CurrPtr) + ) { + if (PtrTrack->CurrPtr->State =3D=3D VAR_ADDED || + PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITION & VAR_A= DDED) + ) { + if (IgnoreRtCheck || !AtRuntime () || ((PtrTrack->CurrPtr->Attribute= s & EFI_VARIABLE_RUNTIME_ACCESS) !=3D 0)) { + if (VariableName[0] =3D=3D 0) { + if (PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITION &= VAR_ADDED)) { + InDeletedVariable =3D PtrTrack->CurrPtr; + } else { + PtrTrack->InDeletedTransitionPtr =3D InDeletedVariable; + return EFI_SUCCESS; + } + } else { + if (CompareGuid (VendorGuid, GetVendorGuidPtr (PtrTrack->CurrPtr= ))) { + Point =3D (VOID *) GetVariableNamePtr (PtrTrack->CurrPtr); + + ASSERT (NameSizeOfVariable (PtrTrack->CurrPtr) !=3D 0); + if (CompareMem (VariableName, Point, NameSizeOfVariable (PtrTr= ack->CurrPtr)) =3D=3D 0) { + if (PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITI= ON & VAR_ADDED)) { + InDeletedVariable =3D PtrTrack->CurrPtr; + } else { + PtrTrack->InDeletedTransitionPtr =3D InDeletedVariable; + return EFI_SUCCESS; + } + } + } + } + } + } + } + + PtrTrack->CurrPtr =3D InDeletedVariable; + return (PtrTrack->CurrPtr =3D=3D NULL) ? EFI_NOT_FOUND : EFI_SUCCESS; +} + +/** + This code Finds the Next available variable. + + Caution: This function may receive untrusted input. + This function may be invoked in SMM mode. This function will do basic va= lidation, before parse the data. + + @param[in] VariableName Pointer to variable name. + @param[in] VendorGuid Variable Vendor Guid. + @param[out] VariablePtr Pointer to variable header address. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_NOT_FOUND The next variable was not found. + @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, wh= ile VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER The input values of VariableName and Vendo= rGuid are not a name and + GUID of an existing variable. + +**/ +EFI_STATUS +EFIAPI +VariableServiceGetNextVariableInternal ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT VARIABLE_HEADER **VariablePtr + ) +{ + VARIABLE_STORE_TYPE Type; + VARIABLE_POINTER_TRACK Variable; + VARIABLE_POINTER_TRACK VariableInHob; + VARIABLE_POINTER_TRACK VariablePtrTrack; + EFI_STATUS Status; + VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax]; + + Status =3D FindVariable (VariableName, VendorGuid, &Variable, &mVariable= ModuleGlobal->VariableGlobal, FALSE); + if (Variable.CurrPtr =3D=3D NULL || EFI_ERROR (Status)) { + // + // For VariableName is an empty string, FindVariable() will try to fin= d and return + // the first qualified variable, and if FindVariable() returns error (= EFI_NOT_FOUND) + // as no any variable is found, still go to return the error (EFI_NOT_= FOUND). + // + if (VariableName[0] !=3D 0) { + // + // For VariableName is not an empty string, and FindVariable() retur= ns error as + // VariableName and VendorGuid are not a name and GUID of an existin= g variable, + // there is no way to get next variable, follow spec to return EFI_I= NVALID_PARAMETER. + // + Status =3D EFI_INVALID_PARAMETER; + } + goto Done; + } + + if (VariableName[0] !=3D 0) { + // + // If variable name is not NULL, get next variable. + // + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); + } + + // + // 0: Volatile, 1: HOB, 2: Non-Volatile. + // The index and attributes mapping must be kept in this order as FindVa= riable + // makes use of this mapping to implement search algorithm. + // + VariableStoreHeader[VariableStoreTypeVolatile] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase; + VariableStoreHeader[VariableStoreTypeHob] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase; + VariableStoreHeader[VariableStoreTypeNv] =3D mNvVariableCache; + + while (TRUE) { + // + // Switch from Volatile to HOB, to Non-Volatile. + // + while (!IsValidVariableHeader (Variable.CurrPtr, Variable.EndPtr)) { + // + // Find current storage index + // + for (Type =3D (VARIABLE_STORE_TYPE) 0; Type < VariableStoreTypeMax; = Type++) { + if ((VariableStoreHeader[Type] !=3D NULL) && (Variable.StartPtr = =3D=3D GetStartPointer (VariableStoreHeader[Type]))) { + break; + } + } + ASSERT (Type < VariableStoreTypeMax); + // + // Switch to next storage + // + for (Type++; Type < VariableStoreTypeMax; Type++) { + if (VariableStoreHeader[Type] !=3D NULL) { + break; + } + } + // + // Capture the case that + // 1. current storage is the last one, or + // 2. no further storage + // + if (Type =3D=3D VariableStoreTypeMax) { + Status =3D EFI_NOT_FOUND; + goto Done; + } + Variable.StartPtr =3D GetStartPointer (VariableStoreHeader[Type]); + Variable.EndPtr =3D GetEndPointer (VariableStoreHeader[Type]); + Variable.CurrPtr =3D Variable.StartPtr; + } + + // + // Variable is found + // + if (Variable.CurrPtr->State =3D=3D VAR_ADDED || Variable.CurrPtr->Stat= e =3D=3D (VAR_IN_DELETED_TRANSITION & VAR_ADDED)) { + if (!AtRuntime () || ((Variable.CurrPtr->Attributes & EFI_VARIABLE_R= UNTIME_ACCESS) !=3D 0)) { + if (Variable.CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITION & VA= R_ADDED)) { + // + // If it is a IN_DELETED_TRANSITION variable, + // and there is also a same ADDED one at the same time, + // don't return it. + // + VariablePtrTrack.StartPtr =3D Variable.StartPtr; + VariablePtrTrack.EndPtr =3D Variable.EndPtr; + Status =3D FindVariableEx ( + GetVariableNamePtr (Variable.CurrPtr), + GetVendorGuidPtr (Variable.CurrPtr), + FALSE, + &VariablePtrTrack + ); + if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State =3D= =3D VAR_ADDED) { + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); + continue; + } + } + + // + // Don't return NV variable when HOB overrides it + // + if ((VariableStoreHeader[VariableStoreTypeHob] !=3D NULL) && (Vari= ableStoreHeader[VariableStoreTypeNv] !=3D NULL) && + (Variable.StartPtr =3D=3D GetStartPointer (VariableStoreHeader= [VariableStoreTypeNv])) + ) { + VariableInHob.StartPtr =3D GetStartPointer (VariableStoreHeader[= VariableStoreTypeHob]); + VariableInHob.EndPtr =3D GetEndPointer (VariableStoreHeader[= VariableStoreTypeHob]); + Status =3D FindVariableEx ( + GetVariableNamePtr (Variable.CurrPtr), + GetVendorGuidPtr (Variable.CurrPtr), + FALSE, + &VariableInHob + ); + if (!EFI_ERROR (Status)) { + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); + continue; + } + } + + *VariablePtr =3D Variable.CurrPtr; + Status =3D EFI_SUCCESS; + goto Done; + } + } + + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); + } + +Done: + return Status; +} + +/** + Routine used to track statistical information about variable usage. + The data is stored in the EFI system table so it can be accessed later. + VariableInfo.efi can dump out the table. Only Boot Services variable + accesses are tracked by this code. The PcdVariableCollectStatistics + build flag controls if this feature is enabled. + + A read that hits in the cache will have Read and Cache true for + the transaction. Data is allocated by this routine, but never + freed. + + @param[in] VariableName Name of the Variable to track. + @param[in] VendorGuid Guid of the Variable to track. + @param[in] Volatile TRUE if volatile FALSE if non-volatile. + @param[in] Read TRUE if GetVariable() was called. + @param[in] Write TRUE if SetVariable() was called. + @param[in] Delete TRUE if deleted via SetVariable(). + @param[in] Cache TRUE for a cache hit. + +**/ +VOID +UpdateVariableInfo ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + IN BOOLEAN Volatile, + IN BOOLEAN Read, + IN BOOLEAN Write, + IN BOOLEAN Delete, + IN BOOLEAN Cache + ) +{ + VARIABLE_INFO_ENTRY *Entry; + + if (FeaturePcdGet (PcdVariableCollectStatistics)) { + + if (AtRuntime ()) { + // Don't collect statistics at runtime. + return; + } + + if (gVariableInfo =3D=3D NULL) { + // + // On the first call allocate a entry and place a pointer to it in + // the EFI System Table. + // + gVariableInfo =3D AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY)); + ASSERT (gVariableInfo !=3D NULL); + + CopyGuid (&gVariableInfo->VendorGuid, VendorGuid); + gVariableInfo->Name =3D AllocateZeroPool (StrSize (VariableName)); + ASSERT (gVariableInfo->Name !=3D NULL); + StrCpyS (gVariableInfo->Name, StrSize(VariableName)/sizeof(CHAR16), = VariableName); + gVariableInfo->Volatile =3D Volatile; + } + + + for (Entry =3D gVariableInfo; Entry !=3D NULL; Entry =3D Entry->Next) { + if (CompareGuid (VendorGuid, &Entry->VendorGuid)) { + if (StrCmp (VariableName, Entry->Name) =3D=3D 0) { + if (Read) { + Entry->ReadCount++; + } + if (Write) { + Entry->WriteCount++; + } + if (Delete) { + Entry->DeleteCount++; + } + if (Cache) { + Entry->CacheCount++; + } + + return; + } + } + + if (Entry->Next =3D=3D NULL) { + // + // If the entry is not in the table add it. + // Next iteration of the loop will fill in the data. + // + Entry->Next =3D AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY)); + ASSERT (Entry->Next !=3D NULL); + + CopyGuid (&Entry->Next->VendorGuid, VendorGuid); + Entry->Next->Name =3D AllocateZeroPool (StrSize (VariableName)); + ASSERT (Entry->Next->Name !=3D NULL); + StrCpyS (Entry->Next->Name, StrSize(VariableName)/sizeof(CHAR16), = VariableName); + Entry->Next->Volatile =3D Volatile; + } + + } + } +} diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/Mde= ModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c index ec463d063e..ce409f22a3 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c @@ -30,6 +30,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include #include "Variable.h" +#include "VariableParsing.h" =20 BOOLEAN mAtRuntime = =3D FALSE; UINT8 *mVariableBufferPaylo= ad =3D NULL; --=20 2.16.2.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 (#49722): https://edk2.groups.io/g/devel/message/49722 Mute This Topic: https://groups.io/mt/40103007/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- From nobody Wed Apr 24 23:27:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49723+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49723+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1572504336; cv=none; d=zoho.com; s=zohoarc; b=LG7tKH/I1+CJuBlOdwwadPd4KCTI4oqrvimIkV6WAi0mwh3yRI4/X6A2hu06mbaS3HCpH30eN6xDjSVI/K3MJp3Y9rpp3242OGP+XkZLMTgN+C4BOead8bkrLiFNd1R/WtI+VmmyadkugAMrkxB/pqqFoVbtHEIabkq3ZDTgjXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572504336; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=7PvxuvGFHCFfnDIToIB3AZZfxONuSsjPtHpkEf1/GVI=; b=TOMOLdHLQt0AP/sJd1Az+9YmkiUnrGlVOuMwVNegS1DnmvBa2IzZ8yt8DC1qwR05SbRKBe2bvZiMi6jyQy0AJKPHVHB+igTvVVrN8DZF/M58ZRfCWg10p++auaEIOQNGnMs52vvUPX3G50BPX/KmleNxPKx3KP3Ms827/wNQb+w= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49723+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1572504336407395.94886363736805; Wed, 30 Oct 2019 23:45:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id DzpMYY1788612xjJLvfdXOyc; Wed, 30 Oct 2019 23:45:36 -0700 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web10.2575.1572504335480868589 for ; Wed, 30 Oct 2019 23:45:35 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 23:45:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,250,1569308400"; d="scan'208";a="351547308" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga004.jf.intel.com with ESMTP; 30 Oct 2019 23:45:35 -0700 From: "Kubacki, Michael A" To: devel@edk2.groups.io Cc: Dandan Bi , Ard Biesheuvel , Eric Dong , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu , Jiewen Yao Subject: [edk2-devel] [PATCH V6 02/10] MdeModulePkg/Variable: Parameterize GetNextVariableInternal () stores Date: Wed, 30 Oct 2019 23:45:02 -0700 Message-Id: <20191031064510.23948-3-michael.a.kubacki@intel.com> In-Reply-To: <20191031064510.23948-1-michael.a.kubacki@intel.com> References: <20191031064510.23948-1-michael.a.kubacki@intel.com> Precedence: Bulk List-Unsubscribe: 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,michael.a.kubacki@intel.com X-Gm-Message-State: kUt1QTyrRbVRXMqjhSZKiEEnx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572504336; bh=YA/qqJeD8WrLrvHpEgBOJRW+JsYl5UfHZ8DSUBPHDBA=; h=Cc:Date:From:Reply-To:Subject:To; b=sQBtDLP+IQ+Q/O5IfS3f67dlY0syqCeBecn/IrJYhBJTll3BKGSBV3S0rII8cmvVGJd xhEhfjuYnFl2U2AKyr/7O/Dxv6HFm9mVOrUT6Nxco1TvFAljjh9s6bi7APFZM41gt5mVJ NBO+IoOTV8zGBGfooowaGkZooN65PiwvyyA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The majority of logic related to GetNextVariableName () is currently implemented in VariableServiceGetNextVariableInternal (). The list of variable stores to search for the given variable name and variable GUID is defined in the function body. This change adds a new parameter so that the caller must pass in the list of variable stores to be used in the variable search. Cc: Dandan Bi Cc: Ard Biesheuvel Cc: Eric Dong Cc: Laszlo Ersek Cc: Liming Gao Cc: Michael D Kinney Cc: Ray Ni Cc: Jian J Wang Cc: Hao A Wu Cc: Jiewen Yao Signed-off-by: Michael Kubacki Reviewed-by: Jian J Wang --- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h | 13 ++-- MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 12 ++- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c | 6 ++ MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c | 82 ++++++++= ++++-------- 4 files changed, 73 insertions(+), 40 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h b= /MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h index b0d7f76bd8..6555316f52 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h @@ -248,18 +248,20 @@ FindVariableEx ( ); =20 /** - This code Finds the Next available variable. + This code finds the next available variable. =20 Caution: This function may receive untrusted input. This function may be invoked in SMM mode. This function will do basic va= lidation, before parse the data. =20 - @param[in] VariableName Pointer to variable name. - @param[in] VendorGuid Variable Vendor Guid. - @param[out] VariablePtr Pointer to variable header address. + @param[in] VariableName Pointer to variable name. + @param[in] VendorGuid Variable Vendor Guid. + @param[in] VariableStoreList A list of variable stores that should be u= sed to get the next variable. + The maximum number of entries is the max v= alue of VARIABLE_STORE_TYPE. + @param[out] VariablePtr Pointer to variable header address. =20 @retval EFI_SUCCESS The function completed successfully. @retval EFI_NOT_FOUND The next variable was not found. - @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, wh= ile VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER If VariableName is nt an empty string, whi= le VendorGuid is NULL. @retval EFI_INVALID_PARAMETER The input values of VariableName and Vendo= rGuid are not a name and GUID of an existing variable. =20 @@ -269,6 +271,7 @@ EFIAPI VariableServiceGetNextVariableInternal ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, + IN VARIABLE_STORE_HEADER **VariableStoreList, OUT VARIABLE_HEADER **VariablePtr ); =20 diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.c index 76536308e6..70af86db24 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -2358,6 +2358,7 @@ VariableServiceGetNextVariableName ( UINTN MaxLen; UINTN VarNameSize; VARIABLE_HEADER *VariablePtr; + VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax]; =20 if (VariableNameSize =3D=3D NULL || VariableName =3D=3D NULL || VendorGu= id =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -2377,7 +2378,16 @@ VariableServiceGetNextVariableName ( =20 AcquireLockOnlyAtBootTime(&mVariableModuleGlobal->VariableGlobal.Variabl= eServicesLock); =20 - Status =3D VariableServiceGetNextVariableInternal (VariableName, VendorG= uid, &VariablePtr); + // + // 0: Volatile, 1: HOB, 2: Non-Volatile. + // The index and attributes mapping must be kept in this order as FindVa= riable + // makes use of this mapping to implement search algorithm. + // + VariableStoreHeader[VariableStoreTypeVolatile] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase; + VariableStoreHeader[VariableStoreTypeHob] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase; + VariableStoreHeader[VariableStoreTypeNv] =3D mNvVariableCache; + + Status =3D VariableServiceGetNextVariableInternal (VariableName, VendorG= uid, VariableStoreHeader, &VariablePtr); if (!EFI_ERROR (Status)) { VarNameSize =3D NameSizeOfVariable (VariablePtr); ASSERT (VarNameSize !=3D 0); diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c b/M= deModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c index dc78f68fa9..c787ddba5b 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c @@ -98,10 +98,16 @@ VariableExLibFindNextVariable ( EFI_STATUS Status; VARIABLE_HEADER *VariablePtr; AUTHENTICATED_VARIABLE_HEADER *AuthVariablePtr; + VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax]; + + VariableStoreHeader[VariableStoreTypeVolatile] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase; + VariableStoreHeader[VariableStoreTypeHob] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase; + VariableStoreHeader[VariableStoreTypeNv] =3D mNvVariableCache; =20 Status =3D VariableServiceGetNextVariableInternal ( VariableName, VendorGuid, + VariableStoreHeader, &VariablePtr ); if (EFI_ERROR (Status)) { diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c b= /MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c index 5698a1a5e4..d6bb916e68 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c @@ -476,14 +476,16 @@ FindVariableEx ( } =20 /** - This code Finds the Next available variable. + This code finds the next available variable. =20 Caution: This function may receive untrusted input. This function may be invoked in SMM mode. This function will do basic va= lidation, before parse the data. =20 - @param[in] VariableName Pointer to variable name. - @param[in] VendorGuid Variable Vendor Guid. - @param[out] VariablePtr Pointer to variable header address. + @param[in] VariableName Pointer to variable name. + @param[in] VendorGuid Variable Vendor Guid. + @param[in] VariableStoreList A list of variable stores that should be u= sed to get the next variable. + The maximum number of entries is the max v= alue of VARIABLE_STORE_TYPE. + @param[out] VariablePtr Pointer to variable header address. =20 @retval EFI_SUCCESS The function completed successfully. @retval EFI_NOT_FOUND The next variable was not found. @@ -497,26 +499,47 @@ EFIAPI VariableServiceGetNextVariableInternal ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, + IN VARIABLE_STORE_HEADER **VariableStoreList, OUT VARIABLE_HEADER **VariablePtr ) { - VARIABLE_STORE_TYPE Type; + EFI_STATUS Status; + VARIABLE_STORE_TYPE StoreType; VARIABLE_POINTER_TRACK Variable; VARIABLE_POINTER_TRACK VariableInHob; VARIABLE_POINTER_TRACK VariablePtrTrack; - EFI_STATUS Status; - VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax]; =20 - Status =3D FindVariable (VariableName, VendorGuid, &Variable, &mVariable= ModuleGlobal->VariableGlobal, FALSE); + Status =3D EFI_NOT_FOUND; + + if (VariableStoreList =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // Check if the variable exists in the given variable store list + for (StoreType =3D (VARIABLE_STORE_TYPE) 0; StoreType < VariableStoreTyp= eMax; StoreType++) { + if (VariableStoreList[StoreType] =3D=3D NULL) { + continue; + } + + Variable.StartPtr =3D GetStartPointer (VariableStoreList[StoreType]); + Variable.EndPtr =3D GetEndPointer (VariableStoreList[StoreType]); + Variable.Volatile =3D (BOOLEAN) (StoreType =3D=3D VariableStoreTypeVol= atile); + + Status =3D FindVariableEx (VariableName, VendorGuid, FALSE, &Variable); + if (!EFI_ERROR (Status)) { + break; + } + } + if (Variable.CurrPtr =3D=3D NULL || EFI_ERROR (Status)) { // - // For VariableName is an empty string, FindVariable() will try to fin= d and return - // the first qualified variable, and if FindVariable() returns error (= EFI_NOT_FOUND) + // For VariableName is an empty string, FindVariableEx() will try to f= ind and return + // the first qualified variable, and if FindVariableEx() returns error= (EFI_NOT_FOUND) // as no any variable is found, still go to return the error (EFI_NOT_= FOUND). // if (VariableName[0] !=3D 0) { // - // For VariableName is not an empty string, and FindVariable() retur= ns error as + // For VariableName is not an empty string, and FindVariableEx() ret= urns error as // VariableName and VendorGuid are not a name and GUID of an existin= g variable, // there is no way to get next variable, follow spec to return EFI_I= NVALID_PARAMETER. // @@ -527,39 +550,30 @@ VariableServiceGetNextVariableInternal ( =20 if (VariableName[0] !=3D 0) { // - // If variable name is not NULL, get next variable. + // If variable name is not empty, get next variable. // Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); } =20 - // - // 0: Volatile, 1: HOB, 2: Non-Volatile. - // The index and attributes mapping must be kept in this order as FindVa= riable - // makes use of this mapping to implement search algorithm. - // - VariableStoreHeader[VariableStoreTypeVolatile] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileVariableBase; - VariableStoreHeader[VariableStoreTypeHob] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase; - VariableStoreHeader[VariableStoreTypeNv] =3D mNvVariableCache; - while (TRUE) { // - // Switch from Volatile to HOB, to Non-Volatile. + // Switch to the next variable store if needed // while (!IsValidVariableHeader (Variable.CurrPtr, Variable.EndPtr)) { // // Find current storage index // - for (Type =3D (VARIABLE_STORE_TYPE) 0; Type < VariableStoreTypeMax; = Type++) { - if ((VariableStoreHeader[Type] !=3D NULL) && (Variable.StartPtr = =3D=3D GetStartPointer (VariableStoreHeader[Type]))) { + for (StoreType =3D (VARIABLE_STORE_TYPE) 0; StoreType < VariableStor= eTypeMax; StoreType++) { + if ((VariableStoreList[StoreType] !=3D NULL) && (Variable.StartPtr= =3D=3D GetStartPointer (VariableStoreList[StoreType]))) { break; } } - ASSERT (Type < VariableStoreTypeMax); + ASSERT (StoreType < VariableStoreTypeMax); // // Switch to next storage // - for (Type++; Type < VariableStoreTypeMax; Type++) { - if (VariableStoreHeader[Type] !=3D NULL) { + for (StoreType++; StoreType < VariableStoreTypeMax; StoreType++) { + if (VariableStoreList[StoreType] !=3D NULL) { break; } } @@ -568,12 +582,12 @@ VariableServiceGetNextVariableInternal ( // 1. current storage is the last one, or // 2. no further storage // - if (Type =3D=3D VariableStoreTypeMax) { + if (StoreType =3D=3D VariableStoreTypeMax) { Status =3D EFI_NOT_FOUND; goto Done; } - Variable.StartPtr =3D GetStartPointer (VariableStoreHeader[Type]); - Variable.EndPtr =3D GetEndPointer (VariableStoreHeader[Type]); + Variable.StartPtr =3D GetStartPointer (VariableStoreList[StoreType]); + Variable.EndPtr =3D GetEndPointer (VariableStoreList[StoreType]); Variable.CurrPtr =3D Variable.StartPtr; } =20 @@ -605,11 +619,11 @@ VariableServiceGetNextVariableInternal ( // // Don't return NV variable when HOB overrides it // - if ((VariableStoreHeader[VariableStoreTypeHob] !=3D NULL) && (Vari= ableStoreHeader[VariableStoreTypeNv] !=3D NULL) && - (Variable.StartPtr =3D=3D GetStartPointer (VariableStoreHeader= [VariableStoreTypeNv])) + if ((VariableStoreList[VariableStoreTypeHob] !=3D NULL) && (Variab= leStoreList[VariableStoreTypeNv] !=3D NULL) && + (Variable.StartPtr =3D=3D GetStartPointer (VariableStoreList[V= ariableStoreTypeNv])) ) { - VariableInHob.StartPtr =3D GetStartPointer (VariableStoreHeader[= VariableStoreTypeHob]); - VariableInHob.EndPtr =3D GetEndPointer (VariableStoreHeader[= VariableStoreTypeHob]); + VariableInHob.StartPtr =3D GetStartPointer (VariableStoreList[Va= riableStoreTypeHob]); + VariableInHob.EndPtr =3D GetEndPointer (VariableStoreList[Va= riableStoreTypeHob]); Status =3D FindVariableEx ( GetVariableNamePtr (Variable.CurrPtr), GetVendorGuidPtr (Variable.CurrPtr), --=20 2.16.2.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 (#49723): https://edk2.groups.io/g/devel/message/49723 Mute This Topic: https://groups.io/mt/40103012/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- From nobody Wed Apr 24 23:27:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49724+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49724+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1572504340; cv=none; d=zoho.com; s=zohoarc; b=AQVWrxRDUzAzfJME4y2CSjsQST+wIBZn46ppIR3IoSPPjBGQECK5R9upFDvD+zwDqiaIU2STV5Fj9EeHAKyFmKihG1W7uyS3D50w6qikCfuMt9rLvOF9qG4OR+KZLaVBJrGDYWH+d255n+mF/xImZcGOLLELOZj4XUkQojulpmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572504340; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=2yfnHUd7BQ7USpwzTXvBKgdO50CF3TY6j44TEp2bhA4=; b=QBEpwxHItEFrCCIBdhc0lZFYUSIXfKg6ZdZjFGVpL+aEY35WZBW4F9NvNLVamn5gMgZq8n9DNYaIKKFbEP34V38E13k3WeAftX228+LDzi2vUlIm9OPLK/sSGQdR8XLhGSAie6wsIAMUlj/eQLdvVnzA1bSETJ34g5Vd57dDqpM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49724+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1572504340227701.7341793308065; Wed, 30 Oct 2019 23:45:40 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id bCp1YY1788612xalOLrepKCi; Wed, 30 Oct 2019 23:45:39 -0700 X-Received: from mga01.intel.com (mga01.intel.com []) by mx.groups.io with SMTP id smtpd.web10.2575.1572504335480868589 for ; Wed, 30 Oct 2019 23:45:39 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 23:45:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,250,1569308400"; d="scan'208";a="351547355" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga004.jf.intel.com with ESMTP; 30 Oct 2019 23:45:38 -0700 From: "Kubacki, Michael A" To: devel@edk2.groups.io Cc: Dandan Bi , Ard Biesheuvel , Eric Dong , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu , Jiewen Yao Subject: [edk2-devel] [PATCH V6 03/10] MdeModulePkg/Variable: Parameterize VARIABLE_INFO_ENTRY buffer Date: Wed, 30 Oct 2019 23:45:03 -0700 Message-Id: <20191031064510.23948-4-michael.a.kubacki@intel.com> In-Reply-To: <20191031064510.23948-1-michael.a.kubacki@intel.com> References: <20191031064510.23948-1-michael.a.kubacki@intel.com> Precedence: Bulk List-Unsubscribe: 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,michael.a.kubacki@intel.com X-Gm-Message-State: j9SzzIm0RGZL4hObqHCtCrckx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572504339; bh=/+15HUsG1JOKfEKJZE8txOdEUlX0B9EG9UzbV3B6r6k=; h=Cc:Date:From:Reply-To:Subject:To; b=wT23OUYjlKAmJtVyPu6f5T/xUpeWdOehGxxkQegVumfA0fNJ5QKqf9zq9aT6HCyAvV6 ICfHykZNHCjZXnhqZF244SWVBd8t6Jpon9NQP198umkWjBtlpmZ18m02SkzH4dLwg4huG LCSf0M1eGqlzONu4XYkgXNnTdu1IAjQ7aDA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" UpdateVariableInfo () currently accepts parameters regarding updates to be made to a global variable of type VARIABLE_INFO_ENTRY. This change passes the structure by pointer to UpdateVariableInfo () so structures other than the fixed global variable can be updated. Cc: Dandan Bi Cc: Ard Biesheuvel Cc: Eric Dong Cc: Laszlo Ersek Cc: Liming Gao Cc: Michael D Kinney Cc: Ray Ni Cc: Jian J Wang Cc: Hao A Wu Cc: Jiewen Yao Signed-off-by: Michael Kubacki Reviewed-by: Jian J Wang --- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h | 18 +++++---- MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 14 +++---- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c | 41 ++++++++= +++--------- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h b= /MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h index 6555316f52..1777ce0e69 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h @@ -286,13 +286,14 @@ VariableServiceGetNextVariableInternal ( the transaction. Data is allocated by this routine, but never freed. =20 - @param[in] VariableName Name of the Variable to track. - @param[in] VendorGuid Guid of the Variable to track. - @param[in] Volatile TRUE if volatile FALSE if non-volatile. - @param[in] Read TRUE if GetVariable() was called. - @param[in] Write TRUE if SetVariable() was called. - @param[in] Delete TRUE if deleted via SetVariable(). - @param[in] Cache TRUE for a cache hit. + @param[in] VariableName Name of the Variable to track. + @param[in] VendorGuid Guid of the Variable to track. + @param[in] Volatile TRUE if volatile FALSE if non-volatile. + @param[in] Read TRUE if GetVariable() was called. + @param[in] Write TRUE if SetVariable() was called. + @param[in] Delete TRUE if deleted via SetVariable(). + @param[in] Cache TRUE for a cache hit. + @param[in,out] VariableInfo Pointer to a pointer of VARIABLE_INFO_ENT= RY structures. =20 **/ VOID @@ -303,7 +304,8 @@ UpdateVariableInfo ( IN BOOLEAN Read, IN BOOLEAN Write, IN BOOLEAN Delete, - IN BOOLEAN Cache + IN BOOLEAN Cache, + IN OUT VARIABLE_INFO_ENTRY **VariableInfo ); =20 #endif diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.c index 70af86db24..5cc12c2ae0 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -1641,7 +1641,7 @@ UpdateVariable ( // go to delete this variable in variable HOB and // try to flush other variables from HOB to flash. // - UpdateVariableInfo (VariableName, VendorGuid, FALSE, FALSE, FALSE,= TRUE, FALSE); + UpdateVariableInfo (VariableName, VendorGuid, FALSE, FALSE, FALSE,= TRUE, FALSE, &gVariableInfo); FlushHobVariableToFlash (VariableName, VendorGuid); return EFI_SUCCESS; } @@ -1758,7 +1758,7 @@ UpdateVariable ( &State ); if (!EFI_ERROR (Status)) { - UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, = FALSE, FALSE, TRUE, FALSE); + UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, = FALSE, FALSE, TRUE, FALSE, &gVariableInfo); if (!Variable->Volatile) { CacheVariable->CurrPtr->State =3D State; FlushHobVariableToFlash (VariableName, VendorGuid); @@ -1777,7 +1777,7 @@ UpdateVariable ( // // Variable content unchanged and no need to update timestamp, just = return. // - UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FA= LSE, TRUE, FALSE, FALSE); + UpdateVariableInfo (VariableName, VendorGuid, Variable->Volatile, FA= LSE, TRUE, FALSE, FALSE, &gVariableInfo); Status =3D EFI_SUCCESS; goto Done; } else if ((CacheVariable->CurrPtr->State =3D=3D VAR_ADDED) || @@ -2006,7 +2006,7 @@ UpdateVariable ( CacheVariable->CurrPtr =3D (VARIABLE_HEADER *)((UINTN) CacheVari= able->StartPtr + ((UINTN) Variable->CurrPtr - (UINTN) Variable->StartPtr)); CacheVariable->InDeletedTransitionPtr =3D NULL; } - UpdateVariableInfo (VariableName, VendorGuid, FALSE, FALSE, TRUE, = FALSE, FALSE); + UpdateVariableInfo (VariableName, VendorGuid, FALSE, FALSE, TRUE, = FALSE, FALSE, &gVariableInfo); FlushHobVariableToFlash (VariableName, VendorGuid); } else { if (IsCommonUserVariable && ((VarSize + mVariableModuleGlobal->Com= monUserVariableTotalSize) > mVariableModuleGlobal->CommonMaxUserVariableSpa= ce)) { @@ -2156,7 +2156,7 @@ UpdateVariable ( CacheVariable->CurrPtr =3D (VARIABLE_HEADER *)((UINTN) CacheVari= able->StartPtr + ((UINTN) Variable->CurrPtr - (UINTN) Variable->StartPtr)); CacheVariable->InDeletedTransitionPtr =3D NULL; } - UpdateVariableInfo (VariableName, VendorGuid, TRUE, FALSE, TRUE, F= ALSE, FALSE); + UpdateVariableInfo (VariableName, VendorGuid, TRUE, FALSE, TRUE, F= ALSE, FALSE, &gVariableInfo); } goto Done; } @@ -2227,7 +2227,7 @@ UpdateVariable ( } =20 if (!EFI_ERROR (Status)) { - UpdateVariableInfo (VariableName, VendorGuid, Volatile, FALSE, TRUE, F= ALSE, FALSE); + UpdateVariableInfo (VariableName, VendorGuid, Volatile, FALSE, TRUE, F= ALSE, FALSE, &gVariableInfo); if (!Volatile) { FlushHobVariableToFlash (VariableName, VendorGuid); } @@ -2306,7 +2306,7 @@ VariableServiceGetVariable ( } =20 *DataSize =3D VarDataSize; - UpdateVariableInfo (VariableName, VendorGuid, Variable.Volatile, TRUE,= FALSE, FALSE, FALSE); + UpdateVariableInfo (VariableName, VendorGuid, Variable.Volatile, TRUE,= FALSE, FALSE, FALSE, &gVariableInfo); =20 Status =3D EFI_SUCCESS; goto Done; diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c b= /MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c index d6bb916e68..870c9e3742 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c @@ -660,13 +660,14 @@ Done: the transaction. Data is allocated by this routine, but never freed. =20 - @param[in] VariableName Name of the Variable to track. - @param[in] VendorGuid Guid of the Variable to track. - @param[in] Volatile TRUE if volatile FALSE if non-volatile. - @param[in] Read TRUE if GetVariable() was called. - @param[in] Write TRUE if SetVariable() was called. - @param[in] Delete TRUE if deleted via SetVariable(). - @param[in] Cache TRUE for a cache hit. + @param[in] VariableName Name of the Variable to track. + @param[in] VendorGuid Guid of the Variable to track. + @param[in] Volatile TRUE if volatile FALSE if non-volatile. + @param[in] Read TRUE if GetVariable() was called. + @param[in] Write TRUE if SetVariable() was called. + @param[in] Delete TRUE if deleted via SetVariable(). + @param[in] Cache TRUE for a cache hit. + @param[in,out] VariableInfo Pointer to a pointer of VARIABLE_INFO_ENT= RY structures. =20 **/ VOID @@ -677,35 +678,38 @@ UpdateVariableInfo ( IN BOOLEAN Read, IN BOOLEAN Write, IN BOOLEAN Delete, - IN BOOLEAN Cache + IN BOOLEAN Cache, + IN OUT VARIABLE_INFO_ENTRY **VariableInfo ) { VARIABLE_INFO_ENTRY *Entry; =20 if (FeaturePcdGet (PcdVariableCollectStatistics)) { - + if (VariableName =3D=3D NULL || VendorGuid =3D=3D NULL || VariableInfo= =3D=3D NULL) { + return; + } if (AtRuntime ()) { // Don't collect statistics at runtime. return; } =20 - if (gVariableInfo =3D=3D NULL) { + if (*VariableInfo =3D=3D NULL) { // // On the first call allocate a entry and place a pointer to it in // the EFI System Table. // - gVariableInfo =3D AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY)); - ASSERT (gVariableInfo !=3D NULL); + *VariableInfo =3D AllocateZeroPool (sizeof (VARIABLE_INFO_ENTRY)); + ASSERT (*VariableInfo !=3D NULL); =20 - CopyGuid (&gVariableInfo->VendorGuid, VendorGuid); - gVariableInfo->Name =3D AllocateZeroPool (StrSize (VariableName)); - ASSERT (gVariableInfo->Name !=3D NULL); - StrCpyS (gVariableInfo->Name, StrSize(VariableName)/sizeof(CHAR16), = VariableName); - gVariableInfo->Volatile =3D Volatile; + CopyGuid (&(*VariableInfo)->VendorGuid, VendorGuid); + (*VariableInfo)->Name =3D AllocateZeroPool (StrSize (VariableName)); + ASSERT ((*VariableInfo)->Name !=3D NULL); + StrCpyS ((*VariableInfo)->Name, StrSize(VariableName)/sizeof(CHAR16)= , VariableName); + (*VariableInfo)->Volatile =3D Volatile; } =20 =20 - for (Entry =3D gVariableInfo; Entry !=3D NULL; Entry =3D Entry->Next) { + for (Entry =3D (*VariableInfo); Entry !=3D NULL; Entry =3D Entry->Next= ) { if (CompareGuid (VendorGuid, &Entry->VendorGuid)) { if (StrCmp (VariableName, Entry->Name) =3D=3D 0) { if (Read) { @@ -739,7 +743,6 @@ UpdateVariableInfo ( StrCpyS (Entry->Next->Name, StrSize(VariableName)/sizeof(CHAR16), = VariableName); Entry->Next->Volatile =3D Volatile; } - } } } --=20 2.16.2.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 (#49724): https://edk2.groups.io/g/devel/message/49724 Mute This Topic: https://groups.io/mt/40103016/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- From nobody Wed Apr 24 23:27:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49725+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49725+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1572504343; cv=none; d=zoho.com; s=zohoarc; b=JoO/4ofqOx+pIvuCew6jGGQmSN8iUk/JBSylzoZ8CgANb1gk+zJKytcP+JPIi1rZIP02Vn6dahClK0A3PISt1GhIV1KrYZySIeCQO69yhz8AyW4yK7kjpX6Wi0RkLmvD83o6jKZtMYk21F36qqlOrIFqDJ8cojVl+a0JXp4vdyI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572504343; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=/y3lkxmx9eC9vT7XdGbexbZS3FUtd+xr8wcPcTzI1CQ=; b=HFMHDcRv1s0Rva2aq+R1BJDtYPzgdoOkRYce7YuM9m7WnMy8+azxBFcZ40akufO6HDYb3EJMYMYaPkUCze//bG0PUVzfLDqW2aJ3XwbmqmtEIVJa5K6w7s/r/LtT9pY7qZ0F1xqGaDM9tnip9cW7kyqa6Uz0luCBy3+AAyvHawc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49725+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1572504343576416.22278145540383; Wed, 30 Oct 2019 23:45:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id lKKUYY1788612xQIUfsRHP69; Wed, 30 Oct 2019 23:45:43 -0700 X-Received: from mga01.intel.com (mga01.intel.com []) by mx.groups.io with SMTP id smtpd.web10.2575.1572504335480868589 for ; Wed, 30 Oct 2019 23:45:42 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 23:45:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,250,1569308400"; d="scan'208";a="351547390" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga004.jf.intel.com with ESMTP; 30 Oct 2019 23:45:42 -0700 From: "Kubacki, Michael A" To: devel@edk2.groups.io Cc: Dandan Bi , Ard Biesheuvel , Eric Dong , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu , Jiewen Yao Subject: [edk2-devel] [PATCH V6 04/10] MdeModulePkg/Variable: Parameterize auth status in VariableParsing Date: Wed, 30 Oct 2019 23:45:04 -0700 Message-Id: <20191031064510.23948-5-michael.a.kubacki@intel.com> In-Reply-To: <20191031064510.23948-1-michael.a.kubacki@intel.com> References: <20191031064510.23948-1-michael.a.kubacki@intel.com> Precedence: Bulk List-Unsubscribe: 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,michael.a.kubacki@intel.com X-Gm-Message-State: AQkkOfn0ZYaUeIK2GFqtVb1jx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572504343; bh=PGxAUh6D8EO/+VwXi8Lgc0s89aNzkXHlYYyxB4hEvqc=; h=Cc:Date:From:Reply-To:Subject:To; b=d+J44Uf2V8DXOu0RVxpCBRjt7yFiIdmHdEHKugQmqVq0jstKZM4EunH+R1TDsZi69oP lzzd1a5xwHlfW6iiyq4ElGlP9qNPwefr05RcPzTmRwZf8ZqKVaVl9+2ijBkXXZux65iZM mLZ7fudFo3NM4gBRj7AHlu0Sz0XdT5dkdeI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The file VariableParsing.c provides generic functionality related to parsing variable related structures and information. In order to calculate offsets for certain operations, the functions must know if authenticated variables are enabled as this increases the size of variable headers. This change removes linking against a global variable in an external file in favor of passing the authenticated variable status as a parameter to the variable parsing functions. Cc: Dandan Bi Cc: Ard Biesheuvel Cc: Eric Dong Cc: Laszlo Ersek Cc: Liming Gao Cc: Michael D Kinney Cc: Ray Ni Cc: Jian J Wang Cc: Hao A Wu Cc: Jiewen Yao Signed-off-by: Michael Kubacki Reviewed-by: Jian J Wang --- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h | 82 +++++-- MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 258 +++++++= +++++++------ MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c | 15 +- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c | 146 +++++++= ---- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 5 +- 5 files changed, 339 insertions(+), 167 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h b= /MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h index 1777ce0e69..92a729d140 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.h @@ -49,53 +49,65 @@ GetVariableStoreStatus ( /** This code gets the size of variable header. =20 + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. + @return Size of variable header in bytes in type UINTN. =20 **/ UINTN GetVariableHeaderSize ( - VOID + IN BOOLEAN AuthFormat ); =20 /** =20 This code gets the size of name of variable. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the variable header. + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. =20 @return UINTN Size of variable in bytes. =20 **/ UINTN NameSizeOfVariable ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** This code sets the size of name of variable. =20 - @param[in] Variable Pointer to the Variable Header. - @param[in] NameSize Name size to set. + @param[in] Variable Pointer to the Variable Header. + @param[in] NameSize Name size to set. + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. =20 **/ VOID SetNameSizeOfVariable ( IN VARIABLE_HEADER *Variable, - IN UINTN NameSize + IN UINTN NameSize, + IN BOOLEAN AuthFormat ); =20 /** =20 This code gets the size of variable data. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. =20 @return Size of variable in bytes. =20 **/ UINTN DataSizeOfVariable ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** @@ -103,80 +115,98 @@ DataSizeOfVariable ( =20 @param[in] Variable Pointer to the Variable Header. @param[in] DataSize Data size to set. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not us= ed. =20 **/ VOID SetDataSizeOfVariable ( - IN VARIABLE_HEADER *Variable, - IN UINTN DataSize + IN VARIABLE_HEADER *Variable, + IN UINTN DataSize, + IN BOOLEAN AuthFormat ); =20 /** =20 This code gets the pointer to the variable name. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Pointer to Variable Name which is Unicode encoding. =20 **/ CHAR16 * GetVariableNamePtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** This code gets the pointer to the variable guid. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return A EFI_GUID* pointer to Vendor Guid. =20 **/ EFI_GUID * GetVendorGuidPtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** =20 This code gets the pointer to the variable data. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Pointer to Variable Data. =20 **/ UINT8 * GetVariableDataPtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** This code gets the variable data offset related to variable header. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Variable Data offset. =20 **/ UINTN GetVariableDataOffset ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** =20 This code gets the pointer to the next variable header. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Pointer to next variable header. =20 **/ VARIABLE_HEADER * GetNextVariablePtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ); =20 /** @@ -235,6 +265,8 @@ VariableCompareTimeStampInternal ( @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS = attribute check at runtime when searching var= iable. @param[in, out] PtrTrack Variable Track Pointer structure th= at contains Variable Information. + @param[in] AuthFormat TRUE indicates authenticated variab= les are used. + FALSE indicates authenticated varia= bles are not used. =20 @retval EFI_SUCCESS Variable found successfully @retval EFI_NOT_FOUND Variable not found @@ -244,7 +276,8 @@ FindVariableEx ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN BOOLEAN IgnoreRtCheck, - IN OUT VARIABLE_POINTER_TRACK *PtrTrack + IN OUT VARIABLE_POINTER_TRACK *PtrTrack, + IN BOOLEAN AuthFormat ); =20 /** @@ -258,10 +291,12 @@ FindVariableEx ( @param[in] VariableStoreList A list of variable stores that should be u= sed to get the next variable. The maximum number of entries is the max v= alue of VARIABLE_STORE_TYPE. @param[out] VariablePtr Pointer to variable header address. + @param[in] AuthFormat TRUE indicates authenticated variables are= used. + FALSE indicates authenticated variables ar= e not used. =20 @retval EFI_SUCCESS The function completed successfully. @retval EFI_NOT_FOUND The next variable was not found. - @retval EFI_INVALID_PARAMETER If VariableName is nt an empty string, whi= le VendorGuid is NULL. + @retval EFI_INVALID_PARAMETER If VariableName is not an empty string, wh= ile VendorGuid is NULL. @retval EFI_INVALID_PARAMETER The input values of VariableName and Vendo= rGuid are not a name and GUID of an existing variable. =20 @@ -272,7 +307,8 @@ VariableServiceGetNextVariableInternal ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN VARIABLE_STORE_HEADER **VariableStoreList, - OUT VARIABLE_HEADER **VariablePtr + OUT VARIABLE_HEADER **VariablePtr, + IN BOOLEAN AuthFormat ); =20 /** diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.c index 5cc12c2ae0..2e32905dfe 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -311,7 +311,7 @@ RecordVarErrorFlag ( FALSE ); if (!EFI_ERROR (Status)) { - VarErrFlag =3D (VAR_ERROR_FLAG *) GetVariableDataPtr (Variable.CurrPtr= ); + VarErrFlag =3D (VAR_ERROR_FLAG *) GetVariableDataPtr (Variable.CurrPtr= , mVariableModuleGlobal->VariableGlobal.AuthFormat); TempFlag =3D *VarErrFlag; TempFlag &=3D Flag; if (TempFlag =3D=3D *VarErrFlag) { @@ -369,7 +369,7 @@ InitializeVarErrorFlag ( FALSE ); if (!EFI_ERROR (Status)) { - VarErrFlag =3D *((VAR_ERROR_FLAG *) GetVariableDataPtr (Variable.CurrP= tr)); + VarErrFlag =3D *((VAR_ERROR_FLAG *) GetVariableDataPtr (Variable.CurrP= tr, mVariableModuleGlobal->VariableGlobal.AuthFormat)); if (VarErrFlag =3D=3D Flag) { return; } @@ -410,7 +410,11 @@ IsUserVariable ( // then no need to check if the variable is user variable or not special= ly. // if (mEndOfDxe && (mVariableModuleGlobal->CommonMaxUserVariableSpace !=3D= mVariableModuleGlobal->CommonVariableSpace)) { - if (VarCheckLibVariablePropertyGet (GetVariableNamePtr (Variable), Get= VendorGuidPtr (Variable), &Property) =3D=3D EFI_NOT_FOUND) { + if (VarCheckLibVariablePropertyGet ( + GetVariableNamePtr (Variable, mVariableModuleGlobal->VariableGlo= bal.AuthFormat), + GetVendorGuidPtr (Variable, mVariableModuleGlobal->VariableGloba= l.AuthFormat), + &Property + ) =3D=3D EFI_NOT_FOUND) { return TRUE; } } @@ -439,10 +443,14 @@ CalculateCommonUserVariableTotalSize ( if (mEndOfDxe && (mVariableModuleGlobal->CommonMaxUserVariableSpace !=3D= mVariableModuleGlobal->CommonVariableSpace)) { Variable =3D GetStartPointer (mNvVariableCache); while (IsValidVariableHeader (Variable, GetEndPointer (mNvVariableCach= e))) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, mVariableModuleGlobal= ->VariableGlobal.AuthFormat); VariableSize =3D (UINTN) NextVariable - (UINTN) Variable; if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) !=3D= EFI_VARIABLE_HARDWARE_ERROR_RECORD) { - if (VarCheckLibVariablePropertyGet (GetVariableNamePtr (Variable),= GetVendorGuidPtr (Variable), &Property) =3D=3D EFI_NOT_FOUND) { + if (VarCheckLibVariablePropertyGet ( + GetVariableNamePtr (Variable, mVariableModuleGlobal->Variabl= eGlobal.AuthFormat), + GetVendorGuidPtr (Variable, mVariableModuleGlobal->VariableG= lobal.AuthFormat), + &Property + ) =3D=3D EFI_NOT_FOUND) { // // No property, it is user variable. // @@ -518,7 +526,9 @@ Reclaim ( UINTN HwErrVariableTotalSize; VARIABLE_HEADER *UpdatingVariable; VARIABLE_HEADER *UpdatingInDeletedTransition; + BOOLEAN AuthFormat; =20 + AuthFormat =3D mVariableModuleGlobal->VariableGlobal.AuthFormat; UpdatingVariable =3D NULL; UpdatingInDeletedTransition =3D NULL; if (UpdatingPtrTrack !=3D NULL) { @@ -540,7 +550,7 @@ Reclaim ( MaximumBufferSize =3D sizeof (VARIABLE_STORE_HEADER); =20 while (IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHe= ader))) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, AuthFormat); if ((Variable->State =3D=3D VAR_ADDED || Variable->State =3D=3D (VAR= _IN_DELETED_TRANSITION & VAR_ADDED)) && Variable !=3D UpdatingVariable && Variable !=3D UpdatingInDeletedTransition @@ -590,7 +600,7 @@ Reclaim ( // Variable =3D GetStartPointer (VariableStoreHeader); while (IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHead= er))) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, AuthFormat); if (Variable !=3D UpdatingVariable && Variable->State =3D=3D VAR_ADDED= ) { VariableSize =3D (UINTN) NextVariable - (UINTN) Variable; CopyMem (CurrPtr, (UINT8 *) Variable, VariableSize); @@ -612,7 +622,7 @@ Reclaim ( // Variable =3D GetStartPointer (VariableStoreHeader); while (IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHead= er))) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, AuthFormat); if (Variable !=3D UpdatingVariable && Variable !=3D UpdatingInDeletedT= ransition && Variable->State =3D=3D (VAR_IN_DELETED_TRANSITION & VAR_ADDED)= ) { =20 // @@ -624,13 +634,14 @@ Reclaim ( FoundAdded =3D FALSE; AddedVariable =3D GetStartPointer ((VARIABLE_STORE_HEADER *) ValidBu= ffer); while (IsValidVariableHeader (AddedVariable, GetEndPointer ((VARIABL= E_STORE_HEADER *) ValidBuffer))) { - NextAddedVariable =3D GetNextVariablePtr (AddedVariable); - NameSize =3D NameSizeOfVariable (AddedVariable); - if (CompareGuid (GetVendorGuidPtr (AddedVariable), GetVendorGuidPt= r (Variable)) && - NameSize =3D=3D NameSizeOfVariable (Variable) - ) { - Point0 =3D (VOID *) GetVariableNamePtr (AddedVariable); - Point1 =3D (VOID *) GetVariableNamePtr (Variable); + NextAddedVariable =3D GetNextVariablePtr (AddedVariable, AuthForma= t); + NameSize =3D NameSizeOfVariable (AddedVariable, AuthFormat); + if (CompareGuid ( + GetVendorGuidPtr (AddedVariable, AuthFormat), + GetVendorGuidPtr (Variable, AuthFormat) + ) && NameSize =3D=3D NameSizeOfVariable (Variable, AuthFormat)= ) { + Point0 =3D (VOID *) GetVariableNamePtr (AddedVariable, AuthForma= t); + Point1 =3D (VOID *) GetVariableNamePtr (Variable, AuthFormat); if (CompareMem (Point0, Point1, NameSize) =3D=3D 0) { FoundAdded =3D TRUE; break; @@ -735,7 +746,7 @@ Reclaim ( mVariableModuleGlobal->CommonUserVariableTotalSize =3D 0; Variable =3D GetStartPointer ((VARIABLE_STORE_HEADER *)(UINTN)Variab= leBase); while (IsValidVariableHeader (Variable, GetEndPointer ((VARIABLE_STO= RE_HEADER *)(UINTN)VariableBase))) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, AuthFormat); VariableSize =3D (UINTN) NextVariable - (UINTN) Variable; if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) = =3D=3D EFI_VARIABLE_HARDWARE_ERROR_RECORD) { mVariableModuleGlobal->HwErrVariableTotalSize +=3D VariableSize; @@ -829,7 +840,13 @@ FindVariable ( PtrTrack->EndPtr =3D GetEndPointer (VariableStoreHeader[Type]); PtrTrack->Volatile =3D (BOOLEAN) (Type =3D=3D VariableStoreTypeVolatil= e); =20 - Status =3D FindVariableEx (VariableName, VendorGuid, IgnoreRtCheck, Pt= rTrack); + Status =3D FindVariableEx ( + VariableName, + VendorGuid, + IgnoreRtCheck, + PtrTrack, + mVariableModuleGlobal->VariableGlobal.AuthFormat + ); if (!EFI_ERROR (Status)) { return Status; } @@ -1199,7 +1216,11 @@ CheckRemainingSpaceForConsistencyInternal ( VarNameSize +=3D GET_PAD_SIZE (VarNameSize); VarDataSize =3D VariableEntry->VariableSize; VarDataSize +=3D GET_PAD_SIZE (VarDataSize); - VariableEntry->VariableSize =3D HEADER_ALIGN (GetVariableHeaderSize ()= + VarNameSize + VarDataSize); + VariableEntry->VariableSize =3D HEADER_ALIGN ( + GetVariableHeaderSize ( + mVariableModuleGlobal->VariableGloba= l.AuthFormat + ) + VarNameSize + VarDataSize + ); =20 TotalNeededSize +=3D VariableEntry->VariableSize; VariableEntry =3D VA_ARG (Args, VARIABLE_ENTRY_CONSISTENCY *); @@ -1232,13 +1253,14 @@ CheckRemainingSpaceForConsistencyInternal ( VariableEntry->Name, VariableEntry->Guid, FALSE, - &VariablePtrTrack + &VariablePtrTrack, + mVariableModuleGlobal->VariableGlobal.AuthFormat ); if (!EFI_ERROR (Status)) { // // Get size of Variable[Index]. // - NextVariable =3D GetNextVariablePtr (VariablePtrTrack.CurrPtr); + NextVariable =3D GetNextVariablePtr (VariablePtrTrack.CurrPtr, mVari= ableModuleGlobal->VariableGlobal.AuthFormat); OriginalVarSize =3D (UINTN) NextVariable - (UINTN) VariablePtrTrack.= CurrPtr; // // Add the original size of Variable[Index] to remaining variable st= orage size. @@ -1410,8 +1432,8 @@ AutoUpdateLangVariable ( // Update Lang // VariableName =3D EFI_PLATFORM_LANG_VARIABLE_NAME; - Data =3D GetVariableDataPtr (Variable.CurrPtr); - DataSize =3D DataSizeOfVariable (Variable.CurrPtr); + Data =3D GetVariableDataPtr (Variable.CurrPtr, mVariableModu= leGlobal->VariableGlobal.AuthFormat); + DataSize =3D DataSizeOfVariable (Variable.CurrPtr, mVariableModu= leGlobal->VariableGlobal.AuthFormat); } else { Status =3D FindVariable (EFI_LANG_VARIABLE_NAME, &gEfiGlobalVariable= Guid, &Variable, &mVariableModuleGlobal->VariableGlobal, FALSE); if (!EFI_ERROR (Status)) { @@ -1419,8 +1441,8 @@ AutoUpdateLangVariable ( // Update PlatformLang // VariableName =3D EFI_LANG_VARIABLE_NAME; - Data =3D GetVariableDataPtr (Variable.CurrPtr); - DataSize =3D DataSizeOfVariable (Variable.CurrPtr); + Data =3D GetVariableDataPtr (Variable.CurrPtr, mVariableMo= duleGlobal->VariableGlobal.AuthFormat); + DataSize =3D DataSizeOfVariable (Variable.CurrPtr, mVariableMo= duleGlobal->VariableGlobal.AuthFormat); } else { // // Neither PlatformLang nor Lang is set, directly return @@ -1598,6 +1620,7 @@ UpdateVariable ( BOOLEAN IsCommonVariable; BOOLEAN IsCommonUserVariable; AUTHENTICATED_VARIABLE_HEADER *AuthVariable; + BOOLEAN AuthFormat; =20 if (mVariableModuleGlobal->FvbInstance =3D=3D NULL && !mVariableModuleGl= obal->VariableGlobal.EmuNvMode) { // @@ -1619,6 +1642,8 @@ UpdateVariable ( } } =20 + AuthFormat =3D mVariableModuleGlobal->VariableGlobal.AuthFormat; + // // Check if CacheVariable points to the variable in variable HOB. // If yes, let CacheVariable points to the variable in NV variable cache. @@ -1630,7 +1655,7 @@ UpdateVariable ( CacheVariable->StartPtr =3D GetStartPointer (mNvVariableCache); CacheVariable->EndPtr =3D GetEndPointer (mNvVariableCache); CacheVariable->Volatile =3D FALSE; - Status =3D FindVariableEx (VariableName, VendorGuid, FALSE, CacheVaria= ble); + Status =3D FindVariableEx (VariableName, VendorGuid, FALSE, CacheVaria= ble, AuthFormat); if (CacheVariable->CurrPtr =3D=3D NULL || EFI_ERROR (Status)) { // // There is no matched variable in NV variable cache. @@ -1770,8 +1795,8 @@ UpdateVariable ( // If the variable is marked valid, and the same data has been passed = in, // then return to the caller immediately. // - if (DataSizeOfVariable (CacheVariable->CurrPtr) =3D=3D DataSize && - (CompareMem (Data, GetVariableDataPtr (CacheVariable->CurrPtr), Da= taSize) =3D=3D 0) && + if (DataSizeOfVariable (CacheVariable->CurrPtr, AuthFormat) =3D=3D Dat= aSize && + (CompareMem (Data, GetVariableDataPtr (CacheVariable->CurrPtr, Aut= hFormat), DataSize) =3D=3D 0) && ((Attributes & EFI_VARIABLE_APPEND_WRITE) =3D=3D 0) && (TimeStamp =3D=3D NULL)) { // @@ -1791,9 +1816,13 @@ UpdateVariable ( // NOTE: From 0 to DataOffset of NextVariable is reserved for Vari= able Header and Name. // From DataOffset of NextVariable is to save the existing variabl= e data. // - DataOffset =3D GetVariableDataOffset (CacheVariable->CurrPtr); + DataOffset =3D GetVariableDataOffset (CacheVariable->CurrPtr, Auth= Format); BufferForMerge =3D (UINT8 *) ((UINTN) NextVariable + DataOffset); - CopyMem (BufferForMerge, (UINT8 *) ((UINTN) CacheVariable->CurrPtr= + DataOffset), DataSizeOfVariable (CacheVariable->CurrPtr)); + CopyMem ( + BufferForMerge, + (UINT8 *) ((UINTN) CacheVariable->CurrPtr + DataOffset), + DataSizeOfVariable (CacheVariable->CurrPtr, AuthFormat) + ); =20 // // Set Max Auth/Non-Volatile/Volatile Variable Data Size as defaul= t MaxDataSize. @@ -1814,15 +1843,22 @@ UpdateVariable ( MaxDataSize =3D PcdGet32 (PcdMaxHardwareErrorVariableSize) - Dat= aOffset; } =20 - if (DataSizeOfVariable (CacheVariable->CurrPtr) + DataSize > MaxDa= taSize) { + if (DataSizeOfVariable (CacheVariable->CurrPtr, AuthFormat) + Data= Size > MaxDataSize) { // // Existing data size + new data size exceed maximum variable si= ze limitation. // Status =3D EFI_INVALID_PARAMETER; goto Done; } - CopyMem ((UINT8*) ((UINTN) BufferForMerge + DataSizeOfVariable (Ca= cheVariable->CurrPtr)), Data, DataSize); - MergedBufSize =3D DataSizeOfVariable (CacheVariable->CurrPtr) + Da= taSize; + CopyMem ( + (UINT8*) ( + (UINTN) BufferForMerge + DataSizeOfVariable (CacheVariable->Cu= rrPtr, AuthFormat) + ), + Data, + DataSize + ); + MergedBufSize =3D DataSizeOfVariable (CacheVariable->CurrPtr, Auth= Format) + + DataSize; =20 // // BufferForMerge(from DataOffset of NextVariable) has included th= e merged existing and new data. @@ -1925,7 +1961,7 @@ UpdateVariable ( // NextVariable->Attributes =3D Attributes & (~EFI_VARIABLE_APPEND_WRITE); =20 - VarNameOffset =3D GetVariableHeaderSize (); + VarNameOffset =3D GetVariableHeaderSize (AuthFormat); VarNameSize =3D StrSize (VariableName); CopyMem ( (UINT8 *) ((UINTN) NextVariable + VarNameOffset), @@ -1946,14 +1982,18 @@ UpdateVariable ( ); } =20 - CopyMem (GetVendorGuidPtr (NextVariable), VendorGuid, sizeof (EFI_GUID)); + CopyMem ( + GetVendorGuidPtr (NextVariable, AuthFormat), + VendorGuid, + sizeof (EFI_GUID) + ); // // There will be pad bytes after Data, the NextVariable->NameSize and // NextVariable->DataSize should not include pad size so that variable // service can get actual size in GetVariable. // - SetNameSizeOfVariable (NextVariable, VarNameSize); - SetDataSizeOfVariable (NextVariable, DataSize); + SetNameSizeOfVariable (NextVariable, VarNameSize, AuthFormat); + SetDataSizeOfVariable (NextVariable, DataSize, AuthFormat); =20 // // The actual size of the variable that stores in storage should @@ -2036,7 +2076,7 @@ UpdateVariable ( TRUE, Fvb, mVariableModuleGlobal->NonVolatileLastVariableOffset, - (UINT32) GetVariableHeaderSize (), + (UINT32) GetVariableHeaderSize (AuthFormat), (UINT8 *) NextVariable ); =20 @@ -2069,9 +2109,9 @@ UpdateVariable ( FALSE, TRUE, Fvb, - mVariableModuleGlobal->NonVolatileLastVariableOffset + Ge= tVariableHeaderSize (), - (UINT32) (VarSize - GetVariableHeaderSize ()), - (UINT8 *) NextVariable + GetVariableHeaderSize () + mVariableModuleGlobal->NonVolatileLastVariableOffset + Ge= tVariableHeaderSize (AuthFormat), + (UINT32) (VarSize - GetVariableHeaderSize (AuthFormat)), + (UINT8 *) NextVariable + GetVariableHeaderSize (AuthForma= t) ); =20 if (EFI_ERROR (Status)) { @@ -2291,7 +2331,7 @@ VariableServiceGetVariable ( // // Get data size // - VarDataSize =3D DataSizeOfVariable (Variable.CurrPtr); + VarDataSize =3D DataSizeOfVariable (Variable.CurrPtr, mVariableModuleGlo= bal->VariableGlobal.AuthFormat); ASSERT (VarDataSize !=3D 0); =20 if (*DataSize >=3D VarDataSize) { @@ -2300,7 +2340,7 @@ VariableServiceGetVariable ( goto Done; } =20 - CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr), VarDataSize); + CopyMem (Data, GetVariableDataPtr (Variable.CurrPtr, mVariableModuleGl= obal->VariableGlobal.AuthFormat), VarDataSize); if (Attributes !=3D NULL) { *Attributes =3D Variable.CurrPtr->Attributes; } @@ -2357,6 +2397,7 @@ VariableServiceGetNextVariableName ( EFI_STATUS Status; UINTN MaxLen; UINTN VarNameSize; + BOOLEAN AuthFormat; VARIABLE_HEADER *VariablePtr; VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax]; =20 @@ -2364,6 +2405,8 @@ VariableServiceGetNextVariableName ( return EFI_INVALID_PARAMETER; } =20 + AuthFormat =3D mVariableModuleGlobal->VariableGlobal.AuthFormat; + // // Calculate the possible maximum length of name string, including the N= ull terminator. // @@ -2387,13 +2430,27 @@ VariableServiceGetNextVariableName ( VariableStoreHeader[VariableStoreTypeHob] =3D (VARIABLE_STORE_HEADE= R *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVariableBase; VariableStoreHeader[VariableStoreTypeNv] =3D mNvVariableCache; =20 - Status =3D VariableServiceGetNextVariableInternal (VariableName, VendorG= uid, VariableStoreHeader, &VariablePtr); + Status =3D VariableServiceGetNextVariableInternal ( + VariableName, + VendorGuid, + VariableStoreHeader, + &VariablePtr, + AuthFormat + ); if (!EFI_ERROR (Status)) { - VarNameSize =3D NameSizeOfVariable (VariablePtr); + VarNameSize =3D NameSizeOfVariable (VariablePtr, AuthFormat); ASSERT (VarNameSize !=3D 0); if (VarNameSize <=3D *VariableNameSize) { - CopyMem (VariableName, GetVariableNamePtr (VariablePtr), VarNameSize= ); - CopyMem (VendorGuid, GetVendorGuidPtr (VariablePtr), sizeof (EFI_GUI= D)); + CopyMem ( + VariableName, + GetVariableNamePtr (VariablePtr, AuthFormat), + VarNameSize + ); + CopyMem ( + VendorGuid, + GetVendorGuidPtr (VariablePtr, AuthFormat), + sizeof (EFI_GUID) + ); Status =3D EFI_SUCCESS; } else { Status =3D EFI_BUFFER_TOO_SMALL; @@ -2446,6 +2503,9 @@ VariableServiceSetVariable ( VARIABLE_HEADER *NextVariable; EFI_PHYSICAL_ADDRESS Point; UINTN PayloadSize; + BOOLEAN AuthFormat; + + AuthFormat =3D mVariableModuleGlobal->VariableGlobal.AuthFormat; =20 // // Check input parameters. @@ -2544,7 +2604,8 @@ VariableServiceSetVariable ( // bytes for HwErrRec#### variable. // if ((Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) =3D=3D EFI_VARIABL= E_HARDWARE_ERROR_RECORD) { - if (StrSize (VariableName) + PayloadSize > PcdGet32 (PcdMaxHardwareErr= orVariableSize) - GetVariableHeaderSize ()) { + if (StrSize (VariableName) + PayloadSize > + PcdGet32 (PcdMaxHardwareErrorVariableSize) - GetVariableHeaderSize= (AuthFormat)) { return EFI_INVALID_PARAMETER; } } else { @@ -2553,7 +2614,9 @@ VariableServiceSetVariable ( // the DataSize is limited to maximum size of Max(Auth|Volatile)Varia= bleSize bytes. // if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) !=3D 0) { - if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->Ma= xAuthVariableSize - GetVariableHeaderSize ()) { + if (StrSize (VariableName) + PayloadSize > + mVariableModuleGlobal->MaxAuthVariableSize - + GetVariableHeaderSize (AuthFormat)) { DEBUG ((DEBUG_ERROR, "%a: Failed to set variable '%s' with Guid %g\n", __FUNCTION__, VariableName, VendorGuid)); @@ -2562,12 +2625,13 @@ VariableServiceSetVariable ( "MaxAuthVariableSize(0x%x) - HeaderSize(0x%x)\n", StrSize (VariableName), PayloadSize, mVariableModuleGlobal->MaxAuthVariableSize, - GetVariableHeaderSize () + GetVariableHeaderSize (AuthFormat) )); return EFI_INVALID_PARAMETER; } } else if ((Attributes & EFI_VARIABLE_NON_VOLATILE) !=3D 0) { - if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->Ma= xVariableSize - GetVariableHeaderSize ()) { + if (StrSize (VariableName) + PayloadSize > + mVariableModuleGlobal->MaxVariableSize - GetVariableHeaderSize (= AuthFormat)) { DEBUG ((DEBUG_ERROR, "%a: Failed to set variable '%s' with Guid %g\n", __FUNCTION__, VariableName, VendorGuid)); @@ -2576,12 +2640,13 @@ VariableServiceSetVariable ( "MaxVariableSize(0x%x) - HeaderSize(0x%x)\n", StrSize (VariableName), PayloadSize, mVariableModuleGlobal->MaxVariableSize, - GetVariableHeaderSize () + GetVariableHeaderSize (AuthFormat) )); return EFI_INVALID_PARAMETER; } } else { - if (StrSize (VariableName) + PayloadSize > mVariableModuleGlobal->Ma= xVolatileVariableSize - GetVariableHeaderSize ()) { + if (StrSize (VariableName) + PayloadSize > + mVariableModuleGlobal->MaxVolatileVariableSize - GetVariableHead= erSize (AuthFormat)) { DEBUG ((DEBUG_ERROR, "%a: Failed to set variable '%s' with Guid %g\n", __FUNCTION__, VariableName, VendorGuid)); @@ -2590,7 +2655,7 @@ VariableServiceSetVariable ( "MaxVolatileVariableSize(0x%x) - HeaderSize(0x%x)\n", StrSize (VariableName), PayloadSize, mVariableModuleGlobal->MaxVolatileVariableSize, - GetVariableHeaderSize () + GetVariableHeaderSize (AuthFormat) )); return EFI_INVALID_PARAMETER; } @@ -2629,7 +2694,7 @@ VariableServiceSetVariable ( // NextVariable =3D GetStartPointer ((VARIABLE_STORE_HEADER *) (UINTN) P= oint); while (IsValidVariableHeader (NextVariable, GetEndPointer ((VARIABLE_S= TORE_HEADER *) (UINTN) Point))) { - NextVariable =3D GetNextVariablePtr (NextVariable); + NextVariable =3D GetNextVariablePtr (NextVariable, AuthFormat); } mVariableModuleGlobal->NonVolatileLastVariableOffset =3D (UINTN) NextV= ariable - (UINTN) Point; } @@ -2754,7 +2819,8 @@ VariableServiceQueryVariableInfoInternal ( // if ((Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERR= OR_RECORD)) =3D=3D (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HARDWARE_ERROR= _RECORD)) { *MaximumVariableStorageSize =3D PcdGet32 (PcdHwErrStorageSize); - *MaximumVariableSize =3D PcdGet32 (PcdMaxHardwareErrorVariableSize) - = GetVariableHeaderSize (); + *MaximumVariableSize =3D PcdGet32 (PcdMaxHardwareErrorVariableSize) - + GetVariableHeaderSize (mVariableModuleGlobal= ->VariableGlobal.AuthFormat); } else { if ((Attributes & EFI_VARIABLE_NON_VOLATILE) !=3D 0) { if (AtRuntime ()) { @@ -2768,11 +2834,14 @@ VariableServiceQueryVariableInfoInternal ( // Let *MaximumVariableSize be Max(Auth|Volatile)VariableSize with the= exception of the variable header size. // if ((Attributes & VARIABLE_ATTRIBUTE_AT_AW) !=3D 0) { - *MaximumVariableSize =3D mVariableModuleGlobal->MaxAuthVariableSize = - GetVariableHeaderSize (); + *MaximumVariableSize =3D mVariableModuleGlobal->MaxAuthVariableSize= - + GetVariableHeaderSize (mVariableModuleGlob= al->VariableGlobal.AuthFormat); } else if ((Attributes & EFI_VARIABLE_NON_VOLATILE) !=3D 0) { - *MaximumVariableSize =3D mVariableModuleGlobal->MaxVariableSize - Ge= tVariableHeaderSize (); + *MaximumVariableSize =3D mVariableModuleGlobal->MaxVariableSize - + GetVariableHeaderSize (mVariableModuleGlob= al->VariableGlobal.AuthFormat); } else { - *MaximumVariableSize =3D mVariableModuleGlobal->MaxVolatileVariableS= ize - GetVariableHeaderSize (); + *MaximumVariableSize =3D mVariableModuleGlobal->MaxVolatileVariabl= eSize - + GetVariableHeaderSize (mVariableModuleGlob= al->VariableGlobal.AuthFormat); } } =20 @@ -2785,7 +2854,7 @@ VariableServiceQueryVariableInfoInternal ( // Now walk through the related variable store. // while (IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHead= er))) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, mVariableModuleGlobal->= VariableGlobal.AuthFormat); VariableSize =3D (UINT64) (UINTN) NextVariable - (UINT64) (UINTN) Vari= able; =20 if (AtRuntime ()) { @@ -2820,10 +2889,11 @@ VariableServiceQueryVariableInfoInternal ( VariablePtrTrack.StartPtr =3D GetStartPointer (VariableStoreHeader= ); VariablePtrTrack.EndPtr =3D GetEndPointer (VariableStoreHeader= ); Status =3D FindVariableEx ( - GetVariableNamePtr (Variable), - GetVendorGuidPtr (Variable), + GetVariableNamePtr (Variable, mVariableModuleGlobal->Va= riableGlobal.AuthFormat), + GetVendorGuidPtr (Variable, mVariableModuleGlobal->Vari= ableGlobal.AuthFormat), FALSE, - &VariablePtrTrack + &VariablePtrTrack, + mVariableModuleGlobal->VariableGlobal.AuthFormat ); if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State !=3D VA= R_ADDED) { if ((Variable->Attributes & EFI_VARIABLE_HARDWARE_ERROR_RECORD) = =3D=3D EFI_VARIABLE_HARDWARE_ERROR_RECORD) { @@ -2851,10 +2921,13 @@ VariableServiceQueryVariableInfoInternal ( } } =20 - if (*RemainingVariableStorageSize < GetVariableHeaderSize ()) { + if (*RemainingVariableStorageSize < GetVariableHeaderSize (mVariableModu= leGlobal->VariableGlobal.AuthFormat)) { *MaximumVariableSize =3D 0; - } else if ((*RemainingVariableStorageSize - GetVariableHeaderSize ()) < = *MaximumVariableSize) { - *MaximumVariableSize =3D *RemainingVariableStorageSize - GetVariableHe= aderSize (); + } else if ((*RemainingVariableStorageSize - GetVariableHeaderSize (mVari= ableModuleGlobal->VariableGlobal.AuthFormat)) < + *MaximumVariableSize + ) { + *MaximumVariableSize =3D *RemainingVariableStorageSize - + GetVariableHeaderSize (mVariableModuleGlobal-= >VariableGlobal.AuthFormat); } =20 return EFI_SUCCESS; @@ -3331,7 +3404,7 @@ InitNonVolatileVariableStore ( // Variable =3D GetStartPointer (mNvVariableCache); while (IsValidVariableHeader (Variable, GetEndPointer (mNvVariableCache)= )) { - NextVariable =3D GetNextVariablePtr (Variable); + NextVariable =3D GetNextVariablePtr (Variable, mVariableModuleGlobal->= VariableGlobal.AuthFormat); VariableSize =3D (UINTN) NextVariable - (UINTN) Variable; if ((Variable->Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_= HARDWARE_ERROR_RECORD)) =3D=3D (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HA= RDWARE_ERROR_RECORD)) { mVariableModuleGlobal->HwErrVariableTotalSize +=3D VariableSize; @@ -3365,8 +3438,10 @@ FlushHobVariableToFlash ( VOID *VariableData; VARIABLE_POINTER_TRACK VariablePtrTrack; BOOLEAN ErrorFlag; + BOOLEAN AuthFormat; =20 ErrorFlag =3D FALSE; + AuthFormat =3D mVariableModuleGlobal->VariableGlobal.AuthFormat; =20 // // Flush the HOB variable to flash. @@ -3379,7 +3454,7 @@ FlushHobVariableToFlash ( mVariableModuleGlobal->VariableGlobal.HobVariableBase =3D 0; for ( Variable =3D GetStartPointer (VariableStoreHeader) ; IsValidVariableHeader (Variable, GetEndPointer (VariableStoreHea= der)) - ; Variable =3D GetNextVariablePtr (Variable) + ; Variable =3D GetNextVariablePtr (Variable, AuthFormat) ) { if (Variable->State !=3D VAR_ADDED) { // @@ -3389,22 +3464,33 @@ FlushHobVariableToFlash ( } ASSERT ((Variable->Attributes & EFI_VARIABLE_NON_VOLATILE) !=3D 0); if (VendorGuid =3D=3D NULL || VariableName =3D=3D NULL || - !CompareGuid (VendorGuid, GetVendorGuidPtr (Variable)) || - StrCmp (VariableName, GetVariableNamePtr (Variable)) !=3D 0) { - VariableData =3D GetVariableDataPtr (Variable); - FindVariable (GetVariableNamePtr (Variable), GetVendorGuidPtr (Var= iable), &VariablePtrTrack, &mVariableModuleGlobal->VariableGlobal, FALSE); + !CompareGuid (VendorGuid, GetVendorGuidPtr (Variable, AuthFormat= )) || + StrCmp (VariableName, GetVariableNamePtr (Variable, AuthFormat))= !=3D 0) { + VariableData =3D GetVariableDataPtr (Variable, AuthFormat); + FindVariable ( + GetVariableNamePtr (Variable, AuthFormat), + GetVendorGuidPtr (Variable, AuthFormat), + &VariablePtrTrack, + &mVariableModuleGlobal->VariableGlobal, FALSE + ); Status =3D UpdateVariable ( - GetVariableNamePtr (Variable), - GetVendorGuidPtr (Variable), + GetVariableNamePtr (Variable, AuthFormat), + GetVendorGuidPtr (Variable, AuthFormat), VariableData, - DataSizeOfVariable (Variable), + DataSizeOfVariable (Variable, AuthFormat), Variable->Attributes, 0, 0, &VariablePtrTrack, NULL ); - DEBUG ((EFI_D_INFO, "Variable driver flush the HOB variable to fla= sh: %g %s %r\n", GetVendorGuidPtr (Variable), GetVariableNamePtr (Variable)= , Status)); + DEBUG (( + DEBUG_INFO, + "Variable driver flush the HOB variable to flash: %g %s %r\n", + GetVendorGuidPtr (Variable, AuthFormat), + GetVariableNamePtr (Variable, AuthFormat), + Status + )); } else { // // The updated or deleted variable is matched with this HOB variab= le. @@ -3418,7 +3504,12 @@ FlushHobVariableToFlash ( // If set variable successful, or the updated or deleted variable = is matched with the HOB variable, // set the HOB variable to DELETED state in local. // - DEBUG ((EFI_D_INFO, "Variable driver set the HOB variable to DELET= ED state in local: %g %s\n", GetVendorGuidPtr (Variable), GetVariableNamePt= r (Variable))); + DEBUG (( + DEBUG_INFO, + "Variable driver set the HOB variable to DELETED state in local:= %g %s\n", + GetVendorGuidPtr (Variable, AuthFormat), + GetVariableNamePtr (Variable, AuthFormat) + )); Variable->State &=3D VAR_DELETED; } else { ErrorFlag =3D TRUE; @@ -3495,7 +3586,8 @@ VariableWriteServiceInitialize ( // Authenticated variable initialize. // mAuthContextIn.StructSize =3D sizeof (AUTH_VAR_LIB_CONTEXT_IN); - mAuthContextIn.MaxAuthVariableSize =3D mVariableModuleGlobal->MaxAuthV= ariableSize - GetVariableHeaderSize (); + mAuthContextIn.MaxAuthVariableSize =3D mVariableModuleGlobal->MaxAuth= VariableSize - + GetVariableHeaderSize (mVariab= leModuleGlobal->VariableGlobal.AuthFormat); Status =3D AuthVariableLibInitialize (&mAuthContextIn, &mAuthContextOu= t); if (!EFI_ERROR (Status)) { DEBUG ((EFI_D_INFO, "Variable driver will work with auth variable su= pport!\n")); @@ -3574,7 +3666,7 @@ ConvertNormalVarStorageToAuthVarStorage ( AuthVarStroageSize +=3D StartPtr->NameSize + GET_PAD_SIZE (StartPtr-= >NameSize); AuthVarStroageSize +=3D StartPtr->DataSize + GET_PAD_SIZE (StartPtr-= >DataSize); } - StartPtr =3D GetNextVariablePtr (StartPtr); + StartPtr =3D GetNextVariablePtr (StartPtr, mVariableModuleGlobal->Var= iableGlobal.AuthFormat); } =20 // @@ -3608,18 +3700,22 @@ ConvertNormalVarStorageToAuthVarStorage ( // Copy Variable Name // NextPtr =3D (UINT8 *) (AuthStartPtr + 1); - CopyMem (NextPtr, GetVariableNamePtr (StartPtr), AuthStartPtr->NameS= ize); + CopyMem ( + NextPtr, + GetVariableNamePtr (StartPtr, mVariableModuleGlobal->VariableGloba= l.AuthFormat), + AuthStartPtr->NameSize + ); // // Copy Variable Data // NextPtr =3D NextPtr + AuthStartPtr->NameSize + GET_PAD_SIZE (AuthSta= rtPtr->NameSize); - CopyMem (NextPtr, GetVariableDataPtr (StartPtr), AuthStartPtr->DataS= ize); + CopyMem (NextPtr, GetVariableDataPtr (StartPtr, mVariableModuleGloba= l->VariableGlobal.AuthFormat), AuthStartPtr->DataSize); // // Go to next variable // AuthStartPtr =3D (AUTHENTICATED_VARIABLE_HEADER *) (NextPtr + AuthSt= artPtr->DataSize + GET_PAD_SIZE (AuthStartPtr->DataSize)); } - StartPtr =3D GetNextVariablePtr (StartPtr); + StartPtr =3D GetNextVariablePtr (StartPtr, mVariableModuleGlobal->Vari= ableGlobal.AuthFormat); } // // Update Auth Storage Header diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c b/M= deModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c index c787ddba5b..e865a089d1 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableExLib.c @@ -56,8 +56,8 @@ VariableExLibFindVariable ( return Status; } =20 - AuthVariableInfo->DataSize =3D DataSizeOfVariable (Variable.CurrP= tr); - AuthVariableInfo->Data =3D GetVariableDataPtr (Variable.CurrP= tr); + AuthVariableInfo->DataSize =3D DataSizeOfVariable (Variable.CurrP= tr, mVariableModuleGlobal->VariableGlobal.AuthFormat); + AuthVariableInfo->Data =3D GetVariableDataPtr (Variable.CurrP= tr, mVariableModuleGlobal->VariableGlobal.AuthFormat); AuthVariableInfo->Attributes =3D Variable.CurrPtr->Attributes; if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable.CurrPtr; @@ -108,7 +108,8 @@ VariableExLibFindNextVariable ( VariableName, VendorGuid, VariableStoreHeader, - &VariablePtr + &VariablePtr, + mVariableModuleGlobal->VariableGlobal.AuthFormat ); if (EFI_ERROR (Status)) { AuthVariableInfo->VariableName =3D NULL; @@ -122,10 +123,10 @@ VariableExLibFindNextVariable ( return Status; } =20 - AuthVariableInfo->VariableName =3D GetVariableNamePtr (VariablePtr); - AuthVariableInfo->VendorGuid =3D GetVendorGuidPtr (VariablePtr); - AuthVariableInfo->DataSize =3D DataSizeOfVariable (VariablePtr); - AuthVariableInfo->Data =3D GetVariableDataPtr (VariablePtr); + AuthVariableInfo->VariableName =3D GetVariableNamePtr (VariablePtr, m= VariableModuleGlobal->VariableGlobal.AuthFormat); + AuthVariableInfo->VendorGuid =3D GetVendorGuidPtr (VariablePtr, mVa= riableModuleGlobal->VariableGlobal.AuthFormat); + AuthVariableInfo->DataSize =3D DataSizeOfVariable (VariablePtr, m= VariableModuleGlobal->VariableGlobal.AuthFormat); + AuthVariableInfo->Data =3D GetVariableDataPtr (VariablePtr, m= VariableModuleGlobal->VariableGlobal.AuthFormat); AuthVariableInfo->Attributes =3D VariablePtr->Attributes; if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { AuthVariablePtr =3D (AUTHENTICATED_VARIABLE_HEADER *) VariablePtr; diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c b= /MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c index 870c9e3742..d458f1c608 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableParsing.c @@ -78,17 +78,20 @@ GetVariableStoreStatus ( /** This code gets the size of variable header. =20 + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. + @return Size of variable header in bytes in type UINTN. =20 **/ UINTN GetVariableHeaderSize ( - VOID + IN BOOLEAN AuthFormat ) { UINTN Value; =20 - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthFormat) { Value =3D sizeof (AUTHENTICATED_VARIABLE_HEADER); } else { Value =3D sizeof (VARIABLE_HEADER); @@ -101,20 +104,23 @@ GetVariableHeaderSize ( =20 This code gets the size of name of variable. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the variable header. + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. =20 @return UINTN Size of variable in bytes. =20 **/ UINTN NameSizeOfVariable ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { AUTHENTICATED_VARIABLE_HEADER *AuthVariable; =20 AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthFormat) { if (AuthVariable->State =3D=3D (UINT8) (-1) || AuthVariable->DataSize =3D=3D (UINT32) (-1) || AuthVariable->NameSize =3D=3D (UINT32) (-1) || @@ -136,20 +142,23 @@ NameSizeOfVariable ( /** This code sets the size of name of variable. =20 - @param[in] Variable Pointer to the Variable Header. - @param[in] NameSize Name size to set. + @param[in] Variable Pointer to the Variable Header. + @param[in] NameSize Name size to set. + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. =20 **/ VOID SetNameSizeOfVariable ( IN VARIABLE_HEADER *Variable, - IN UINTN NameSize + IN UINTN NameSize, + IN BOOLEAN AuthFormat ) { AUTHENTICATED_VARIABLE_HEADER *AuthVariable; =20 AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthFormat) { AuthVariable->NameSize =3D (UINT32) NameSize; } else { Variable->NameSize =3D (UINT32) NameSize; @@ -160,20 +169,23 @@ SetNameSizeOfVariable ( =20 This code gets the size of variable data. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are use= d. + FALSE indicates authenticated variables are no= t used. =20 @return Size of variable in bytes. =20 **/ UINTN DataSizeOfVariable ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { AUTHENTICATED_VARIABLE_HEADER *AuthVariable; =20 AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthFormat) { if (AuthVariable->State =3D=3D (UINT8) (-1) || AuthVariable->DataSize =3D=3D (UINT32) (-1) || AuthVariable->NameSize =3D=3D (UINT32) (-1) || @@ -197,18 +209,21 @@ DataSizeOfVariable ( =20 @param[in] Variable Pointer to the Variable Header. @param[in] DataSize Data size to set. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not us= ed. =20 **/ VOID SetDataSizeOfVariable ( - IN VARIABLE_HEADER *Variable, - IN UINTN DataSize + IN VARIABLE_HEADER *Variable, + IN UINTN DataSize, + IN BOOLEAN AuthFormat ) { AUTHENTICATED_VARIABLE_HEADER *AuthVariable; =20 AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthFormat) { AuthVariable->DataSize =3D (UINT32) DataSize; } else { Variable->DataSize =3D (UINT32) DataSize; @@ -219,36 +234,42 @@ SetDataSizeOfVariable ( =20 This code gets the pointer to the variable name. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Pointer to Variable Name which is Unicode encoding. =20 **/ CHAR16 * GetVariableNamePtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { - return (CHAR16 *) ((UINTN) Variable + GetVariableHeaderSize ()); + return (CHAR16 *) ((UINTN) Variable + GetVariableHeaderSize (AuthFormat)= ); } =20 /** This code gets the pointer to the variable guid. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return A EFI_GUID* pointer to Vendor Guid. =20 **/ EFI_GUID * GetVendorGuidPtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { AUTHENTICATED_VARIABLE_HEADER *AuthVariable; =20 AuthVariable =3D (AUTHENTICATED_VARIABLE_HEADER *) Variable; - if (mVariableModuleGlobal->VariableGlobal.AuthFormat) { + if (AuthFormat) { return &AuthVariable->VendorGuid; } else { return &Variable->VendorGuid; @@ -259,14 +280,17 @@ GetVendorGuidPtr ( =20 This code gets the pointer to the variable data. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Pointer to Variable Data. =20 **/ UINT8 * GetVariableDataPtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { UINTN Value; @@ -274,9 +298,9 @@ GetVariableDataPtr ( // // Be careful about pad size for alignment. // - Value =3D (UINTN) GetVariableNamePtr (Variable); - Value +=3D NameSizeOfVariable (Variable); - Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable)); + Value =3D (UINTN) GetVariableNamePtr (Variable, AuthFormat); + Value +=3D NameSizeOfVariable (Variable, AuthFormat); + Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable, AuthFormat)); =20 return (UINT8 *) Value; } @@ -284,14 +308,17 @@ GetVariableDataPtr ( /** This code gets the variable data offset related to variable header. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Variable Data offset. =20 **/ UINTN GetVariableDataOffset ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { UINTN Value; @@ -299,9 +326,9 @@ GetVariableDataOffset ( // // Be careful about pad size for alignment // - Value =3D GetVariableHeaderSize (); - Value +=3D NameSizeOfVariable (Variable); - Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable)); + Value =3D GetVariableHeaderSize (AuthFormat); + Value +=3D NameSizeOfVariable (Variable, AuthFormat); + Value +=3D GET_PAD_SIZE (NameSizeOfVariable (Variable, AuthFormat)); =20 return Value; } @@ -310,21 +337,24 @@ GetVariableDataOffset ( =20 This code gets the pointer to the next variable header. =20 - @param Variable Pointer to the Variable Header. + @param[in] Variable Pointer to the Variable Header. + @param[in] AuthFormat TRUE indicates authenticated variables are used. + FALSE indicates authenticated variables are not = used. =20 @return Pointer to next variable header. =20 **/ VARIABLE_HEADER * GetNextVariablePtr ( - IN VARIABLE_HEADER *Variable + IN VARIABLE_HEADER *Variable, + IN BOOLEAN AuthFormat ) { UINTN Value; =20 - Value =3D (UINTN) GetVariableDataPtr (Variable); - Value +=3D DataSizeOfVariable (Variable); - Value +=3D GET_PAD_SIZE (DataSizeOfVariable (Variable)); + Value =3D (UINTN) GetVariableDataPtr (Variable, AuthFormat); + Value +=3D DataSizeOfVariable (Variable, AuthFormat); + Value +=3D GET_PAD_SIZE (DataSizeOfVariable (Variable, AuthFormat)); =20 // // Be careful about pad size for alignment. @@ -415,6 +445,8 @@ VariableCompareTimeStampInternal ( @param[in] IgnoreRtCheck Ignore EFI_VARIABLE_RUNTIME_ACCESS = attribute check at runtime when searching var= iable. @param[in, out] PtrTrack Variable Track Pointer structure th= at contains Variable Information. + @param[in] AuthFormat TRUE indicates authenticated variab= les are used. + FALSE indicates authenticated varia= bles are not used. =20 @retval EFI_SUCCESS Variable found successfully @retval EFI_NOT_FOUND Variable not found @@ -424,7 +456,8 @@ FindVariableEx ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN BOOLEAN IgnoreRtCheck, - IN OUT VARIABLE_POINTER_TRACK *PtrTrack + IN OUT VARIABLE_POINTER_TRACK *PtrTrack, + IN BOOLEAN AuthFormat ) { VARIABLE_HEADER *InDeletedVariable; @@ -439,7 +472,7 @@ FindVariableEx ( =20 for ( PtrTrack->CurrPtr =3D PtrTrack->StartPtr ; IsValidVariableHeader (PtrTrack->CurrPtr, PtrTrack->EndPtr) - ; PtrTrack->CurrPtr =3D GetNextVariablePtr (PtrTrack->CurrPtr) + ; PtrTrack->CurrPtr =3D GetNextVariablePtr (PtrTrack->CurrPtr, AuthF= ormat) ) { if (PtrTrack->CurrPtr->State =3D=3D VAR_ADDED || PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITION & VAR_A= DDED) @@ -453,11 +486,11 @@ FindVariableEx ( return EFI_SUCCESS; } } else { - if (CompareGuid (VendorGuid, GetVendorGuidPtr (PtrTrack->CurrPtr= ))) { - Point =3D (VOID *) GetVariableNamePtr (PtrTrack->CurrPtr); + if (CompareGuid (VendorGuid, GetVendorGuidPtr (PtrTrack->CurrPtr= , AuthFormat))) { + Point =3D (VOID *) GetVariableNamePtr (PtrTrack->CurrPtr, Auth= Format); =20 - ASSERT (NameSizeOfVariable (PtrTrack->CurrPtr) !=3D 0); - if (CompareMem (VariableName, Point, NameSizeOfVariable (PtrTr= ack->CurrPtr)) =3D=3D 0) { + ASSERT (NameSizeOfVariable (PtrTrack->CurrPtr, AuthFormat) != =3D 0); + if (CompareMem (VariableName, Point, NameSizeOfVariable (PtrTr= ack->CurrPtr, AuthFormat)) =3D=3D 0) { if (PtrTrack->CurrPtr->State =3D=3D (VAR_IN_DELETED_TRANSITI= ON & VAR_ADDED)) { InDeletedVariable =3D PtrTrack->CurrPtr; } else { @@ -486,6 +519,8 @@ FindVariableEx ( @param[in] VariableStoreList A list of variable stores that should be u= sed to get the next variable. The maximum number of entries is the max v= alue of VARIABLE_STORE_TYPE. @param[out] VariablePtr Pointer to variable header address. + @param[in] AuthFormat TRUE indicates authenticated variables are= used. + FALSE indicates authenticated variables ar= e not used. =20 @retval EFI_SUCCESS The function completed successfully. @retval EFI_NOT_FOUND The next variable was not found. @@ -500,7 +535,8 @@ VariableServiceGetNextVariableInternal ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN VARIABLE_STORE_HEADER **VariableStoreList, - OUT VARIABLE_HEADER **VariablePtr + OUT VARIABLE_HEADER **VariablePtr, + IN BOOLEAN AuthFormat ) { EFI_STATUS Status; @@ -525,7 +561,7 @@ VariableServiceGetNextVariableInternal ( Variable.EndPtr =3D GetEndPointer (VariableStoreList[StoreType]); Variable.Volatile =3D (BOOLEAN) (StoreType =3D=3D VariableStoreTypeVol= atile); =20 - Status =3D FindVariableEx (VariableName, VendorGuid, FALSE, &Variable); + Status =3D FindVariableEx (VariableName, VendorGuid, FALSE, &Variable,= AuthFormat); if (!EFI_ERROR (Status)) { break; } @@ -552,7 +588,7 @@ VariableServiceGetNextVariableInternal ( // // If variable name is not empty, get next variable. // - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr, AuthFormat); } =20 while (TRUE) { @@ -605,13 +641,14 @@ VariableServiceGetNextVariableInternal ( VariablePtrTrack.StartPtr =3D Variable.StartPtr; VariablePtrTrack.EndPtr =3D Variable.EndPtr; Status =3D FindVariableEx ( - GetVariableNamePtr (Variable.CurrPtr), - GetVendorGuidPtr (Variable.CurrPtr), + GetVariableNamePtr (Variable.CurrPtr, AuthFormat), + GetVendorGuidPtr (Variable.CurrPtr, AuthFormat), FALSE, - &VariablePtrTrack + &VariablePtrTrack, + AuthFormat ); if (!EFI_ERROR (Status) && VariablePtrTrack.CurrPtr->State =3D= =3D VAR_ADDED) { - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr, Aut= hFormat); continue; } } @@ -625,13 +662,14 @@ VariableServiceGetNextVariableInternal ( VariableInHob.StartPtr =3D GetStartPointer (VariableStoreList[Va= riableStoreTypeHob]); VariableInHob.EndPtr =3D GetEndPointer (VariableStoreList[Va= riableStoreTypeHob]); Status =3D FindVariableEx ( - GetVariableNamePtr (Variable.CurrPtr), - GetVendorGuidPtr (Variable.CurrPtr), + GetVariableNamePtr (Variable.CurrPtr, AuthFormat), + GetVendorGuidPtr (Variable.CurrPtr, AuthFormat), FALSE, - &VariableInHob + &VariableInHob, + AuthFormat ); if (!EFI_ERROR (Status)) { - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr, Aut= hFormat); continue; } } @@ -642,7 +680,7 @@ VariableServiceGetNextVariableInternal ( } } =20 - Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr); + Variable.CurrPtr =3D GetNextVariablePtr (Variable.CurrPtr, AuthFormat); } =20 Done: diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/Mde= ModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c index ce409f22a3..5e24bc4a62 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c @@ -975,8 +975,9 @@ MmVariableServiceInitialize ( ); ASSERT_EFI_ERROR (Status); =20 - mVariableBufferPayloadSize =3D GetMaxVariableSize () + - OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_CHE= CK_VARIABLE_PROPERTY, Name) - GetVariableHeaderSize (); + mVariableBufferPayloadSize =3D GetMaxVariableSize () + + OFFSET_OF (SMM_VARIABLE_COMMUNICATE_VAR_= CHECK_VARIABLE_PROPERTY, Name) - + GetVariableHeaderSize (mVariableModuleGl= obal->VariableGlobal.AuthFormat); =20 Status =3D gMmst->MmAllocatePool ( EfiRuntimeServicesData, --=20 2.16.2.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 (#49725): https://edk2.groups.io/g/devel/message/49725 Mute This Topic: https://groups.io/mt/40103019/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- From nobody Wed Apr 24 23:27:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49726+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49726+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1572504348; cv=none; d=zoho.com; s=zohoarc; b=lR02mga8yXWlWthjh6atvDsfsFccmgRHfd0iwMuIAD8QyWi3GiH6MAlhxd11o6tooaGVeKZvm2yp6lBEjv3DhL8eztOcNmIZQGn4uMztzVc4FJOVSM14xXX+x9UyMO7vsXWKicLy1dGPMgi8RXV2WbHjAOuqfSwVdBnclIsP6Cs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572504348; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=BwUACLrGvO9njPtEgUB60ojrwO+/NpR5NmsGBLj8TY4=; b=dsJ9toSlP2NIOjl/7MvTgnBN9wqwfiTicqNdchYjSIIaYUPR0uFR5XnUu2wj8ktDm4JISH4vbrfh3nlRZ231s72oi2xhb8rv13Fqc2+l30Kch6SBcdVMBrnHPcJ1tR4NhZPfZDSJG0ng+xBFUq4c9jk1VRNcMIc49GaSnMd+8vE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49726+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1572504348463345.3733922134986; Wed, 30 Oct 2019 23:45:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id sBu6YY1788612xQRvyiZlncA; Wed, 30 Oct 2019 23:45:47 -0700 X-Received: from mga01.intel.com (mga01.intel.com []) by mx.groups.io with SMTP id smtpd.web10.2575.1572504335480868589 for ; Wed, 30 Oct 2019 23:45:47 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 23:45:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,250,1569308400"; d="scan'208";a="351547427" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga004.jf.intel.com with ESMTP; 30 Oct 2019 23:45:46 -0700 From: "Kubacki, Michael A" To: devel@edk2.groups.io Cc: Dandan Bi , Ard Biesheuvel , Eric Dong , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu , Jiewen Yao Subject: [edk2-devel] [PATCH V6 05/10] MdeModulePkg/Variable: Add a file for NV variable functions Date: Wed, 30 Oct 2019 23:45:05 -0700 Message-Id: <20191031064510.23948-6-michael.a.kubacki@intel.com> In-Reply-To: <20191031064510.23948-1-michael.a.kubacki@intel.com> References: <20191031064510.23948-1-michael.a.kubacki@intel.com> Precedence: Bulk List-Unsubscribe: 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,michael.a.kubacki@intel.com X-Gm-Message-State: 4bzjPoBPAnUs3aLZk5pvUnUhx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572504347; bh=yMCuaRPLvAbDrufHxC5uVzLMUhmiB42h1l3YfQEHI28=; h=Cc:Date:From:Reply-To:Subject:To; b=Kxuq6ga1n8ns+3FGeqbP2DrTobCW4wJiIyPt/0039BIh9c/u/ueUkGD16Z0tBReJNZL FZsOz9SZd0kMx8Nj4hPugsS5GRA/p8sVZeMlE+KrdmCnZ1gC0m7JGZf4VRVMd4vScm+nI 3aKBETEeUBVo3OH5tWKyiS8nQw9t7+uah7k= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This change adds a dedicated file for variable operations specific to non-volatile variables. This decreases the overall length of the relatively large Variable.c file. Cc: Dandan Bi Cc: Ard Biesheuvel Cc: Eric Dong Cc: Laszlo Ersek Cc: Liming Gao Cc: Michael D Kinney Cc: Ray Ni Cc: Jian J Wang Cc: Hao A Wu Cc: Jiewen Yao Signed-off-by: Michael Kubacki Reviewed-by: Jian J Wang --- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf | 2 + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf | 2 + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf | 2 + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.h | 67 = ++++ MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 317 = +------------------ MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c | 334 = ++++++++++++++++++++ 6 files changed, 408 insertions(+), 316 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.= inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf index c35e5fe787..08a5490787 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf @@ -36,6 +36,8 @@ Variable.c VariableDxe.c Variable.h + VariableNonVolatile.c + VariableNonVolatile.h VariableParsing.c VariableParsing.h PrivilegePolymorphic.h diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf b/M= deModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf index 626738b9c7..6dc2721b81 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf @@ -45,6 +45,8 @@ Variable.c VariableTraditionalMm.c VariableSmm.c + VariableNonVolatile.c + VariableNonVolatile.h VariableParsing.c VariableParsing.h VarCheck.c diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneM= m.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf index ff714b193a..f8a3742959 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf @@ -45,6 +45,8 @@ Variable.c VariableSmm.c VariableStandaloneMm.c + VariableNonVolatile.c + VariableNonVolatile.h VariableParsing.c VariableParsing.h VarCheck.c diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile= .h b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.h new file mode 100644 index 0000000000..43653f27e6 --- /dev/null +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.h @@ -0,0 +1,67 @@ +/** @file + Common variable non-volatile store routines. + +Copyright (c) 2019, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _VARIABLE_NON_VOLATILE_H_ +#define _VARIABLE_NON_VOLATILE_H_ + +#include "Variable.h" + +/** + Get non-volatile maximum variable size. + + @return Non-volatile maximum variable size. + +**/ +UINTN +GetNonVolatileMaxVariableSize ( + VOID + ); + +/** + Init emulated non-volatile variable store. + + @param[out] VariableStoreBase Output pointer to emulated non-volatile va= riable store base. + + @retval EFI_SUCCESS Function successfully executed. + @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource. + +**/ +EFI_STATUS +InitEmuNonVolatileVariableStore ( + EFI_PHYSICAL_ADDRESS *VariableStoreBase + ); + +/** + Init real non-volatile variable store. + + @param[out] VariableStoreBase Output pointer to real non-volatile variab= le store base. + + @retval EFI_SUCCESS Function successfully executed. + @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource. + @retval EFI_VOLUME_CORRUPTED Variable Store or Firmware Volume for Vari= able Store is corrupted. + +**/ +EFI_STATUS +InitRealNonVolatileVariableStore ( + OUT EFI_PHYSICAL_ADDRESS *VariableStoreBase + ); + +/** + Init non-volatile variable store. + + @retval EFI_SUCCESS Function successfully executed. + @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource. + @retval EFI_VOLUME_CORRUPTED Variable Store or Firmware Volume for Vari= able Store is corrupted. + +**/ +EFI_STATUS +InitNonVolatileVariableStore ( + VOID + ); + +#endif diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.c index 2e32905dfe..0bd2f22e1a 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -23,6 +23,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #include "Variable.h" +#include "VariableNonVolatile.h" #include "VariableParsing.h" =20 VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal; @@ -3079,25 +3080,6 @@ ReclaimForOS( } } =20 -/** - Get non-volatile maximum variable size. - - @return Non-volatile maximum variable size. - -**/ -UINTN -GetNonVolatileMaxVariableSize ( - VOID - ) -{ - if (PcdGet32 (PcdHwErrStorageSize) !=3D 0) { - return MAX (MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxAuthVa= riableSize)), - PcdGet32 (PcdMaxHardwareErrorVariableSize)); - } else { - return MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxAuthVariabl= eSize)); - } -} - /** Get maximum variable size, covering both non-volatile and volatile varia= bles. =20 @@ -3122,303 +3104,6 @@ GetMaxVariableSize ( return MaxVariableSize; } =20 -/** - Init real non-volatile variable store. - - @param[out] VariableStoreBase Output pointer to real non-volatile variab= le store base. - - @retval EFI_SUCCESS Function successfully executed. - @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource. - @retval EFI_VOLUME_CORRUPTED Variable Store or Firmware Volume for Vari= able Store is corrupted. - -**/ -EFI_STATUS -InitRealNonVolatileVariableStore ( - OUT EFI_PHYSICAL_ADDRESS *VariableStoreBase - ) -{ - EFI_FIRMWARE_VOLUME_HEADER *FvHeader; - VARIABLE_STORE_HEADER *VariableStore; - UINT32 VariableStoreLength; - EFI_HOB_GUID_TYPE *GuidHob; - EFI_PHYSICAL_ADDRESS NvStorageBase; - UINT8 *NvStorageData; - UINT32 NvStorageSize; - FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData; - UINT32 BackUpOffset; - UINT32 BackUpSize; - UINT32 HwErrStorageSize; - UINT32 MaxUserNvVariableSpaceSize; - UINT32 BoottimeReservedNvVariableSpaceSiz= e; - EFI_STATUS Status; - VOID *FtwProtocol; - - mVariableModuleGlobal->FvbInstance =3D NULL; - - // - // Allocate runtime memory used for a memory copy of the FLASH region. - // Keep the memory and the FLASH in sync as updates occur. - // - NvStorageSize =3D PcdGet32 (PcdFlashNvStorageVariableSize); - NvStorageData =3D AllocateRuntimeZeroPool (NvStorageSize); - if (NvStorageData =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - NvStorageBase =3D NV_STORAGE_VARIABLE_BASE; - ASSERT (NvStorageBase !=3D 0); - - // - // Copy NV storage data to the memory buffer. - // - CopyMem (NvStorageData, (UINT8 *) (UINTN) NvStorageBase, NvStorageSize); - - Status =3D GetFtwProtocol ((VOID **)&FtwProtocol); - // - // If FTW protocol has been installed, no need to check FTW last write d= ata hob. - // - if (EFI_ERROR (Status)) { - // - // Check the FTW last write data hob. - // - GuidHob =3D GetFirstGuidHob (&gEdkiiFaultTolerantWriteGuid); - if (GuidHob !=3D NULL) { - FtwLastWriteData =3D (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *) GET_GU= ID_HOB_DATA (GuidHob); - if (FtwLastWriteData->TargetAddress =3D=3D NvStorageBase) { - DEBUG ((EFI_D_INFO, "Variable: NV storage is backed up in spare bl= ock: 0x%x\n", (UINTN) FtwLastWriteData->SpareAddress)); - // - // Copy the backed up NV storage data to the memory buffer from sp= are block. - // - CopyMem (NvStorageData, (UINT8 *) (UINTN) (FtwLastWriteData->Spare= Address), NvStorageSize); - } else if ((FtwLastWriteData->TargetAddress > NvStorageBase) && - (FtwLastWriteData->TargetAddress < (NvStorageBase + NvSto= rageSize))) { - // - // Flash NV storage from the Offset is backed up in spare block. - // - BackUpOffset =3D (UINT32) (FtwLastWriteData->TargetAddress - NvSto= rageBase); - BackUpSize =3D NvStorageSize - BackUpOffset; - DEBUG ((EFI_D_INFO, "Variable: High partial NV storage from offset= : %x is backed up in spare block: 0x%x\n", BackUpOffset, (UINTN) FtwLastWri= teData->SpareAddress)); - // - // Copy the partial backed up NV storage data to the memory buffer= from spare block. - // - CopyMem (NvStorageData + BackUpOffset, (UINT8 *) (UINTN) FtwLastWr= iteData->SpareAddress, BackUpSize); - } - } - } - - FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *) NvStorageData; - - // - // Check if the Firmware Volume is not corrupted - // - if ((FvHeader->Signature !=3D EFI_FVH_SIGNATURE) || (!CompareGuid (&gEfi= SystemNvDataFvGuid, &FvHeader->FileSystemGuid))) { - FreePool (NvStorageData); - DEBUG ((EFI_D_ERROR, "Firmware Volume for Variable Store is corrupted\= n")); - return EFI_VOLUME_CORRUPTED; - } - - VariableStore =3D (VARIABLE_STORE_HEADER *) ((UINTN) FvHeader + FvHeader= ->HeaderLength); - VariableStoreLength =3D NvStorageSize - FvHeader->HeaderLength; - ASSERT (sizeof (VARIABLE_STORE_HEADER) <=3D VariableStoreLength); - ASSERT (VariableStore->Size =3D=3D VariableStoreLength); - - // - // Check if the Variable Store header is not corrupted - // - if (GetVariableStoreStatus (VariableStore) !=3D EfiValid) { - FreePool (NvStorageData); - DEBUG((EFI_D_ERROR, "Variable Store header is corrupted\n")); - return EFI_VOLUME_CORRUPTED; - } - - mNvFvHeaderCache =3D FvHeader; - - *VariableStoreBase =3D (EFI_PHYSICAL_ADDRESS) (UINTN) VariableStore; - - HwErrStorageSize =3D PcdGet32 (PcdHwErrStorageSize); - MaxUserNvVariableSpaceSize =3D PcdGet32 (PcdMaxUserNvVariableSpaceSize); - BoottimeReservedNvVariableSpaceSize =3D PcdGet32 (PcdBoottimeReservedNvV= ariableSpaceSize); - - // - // Note that in EdkII variable driver implementation, Hardware Error Rec= ord type variable - // is stored with common variable in the same NV region. So the platform= integrator should - // ensure that the value of PcdHwErrStorageSize is less than the value of - // (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)). - // - ASSERT (HwErrStorageSize < (VariableStoreLength - sizeof (VARIABLE_STORE= _HEADER))); - // - // Ensure that the value of PcdMaxUserNvVariableSpaceSize is less than t= he value of - // (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)) - PcdGet32 (Pc= dHwErrStorageSize). - // - ASSERT (MaxUserNvVariableSpaceSize < (VariableStoreLength - sizeof (VARI= ABLE_STORE_HEADER) - HwErrStorageSize)); - // - // Ensure that the value of PcdBoottimeReservedNvVariableSpaceSize is le= ss than the value of - // (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)) - PcdGet32 (Pc= dHwErrStorageSize). - // - ASSERT (BoottimeReservedNvVariableSpaceSize < (VariableStoreLength - siz= eof (VARIABLE_STORE_HEADER) - HwErrStorageSize)); - - mVariableModuleGlobal->CommonVariableSpace =3D ((UINTN) VariableStoreLen= gth - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize); - mVariableModuleGlobal->CommonMaxUserVariableSpace =3D ((MaxUserNvVariabl= eSpaceSize !=3D 0) ? MaxUserNvVariableSpaceSize : mVariableModuleGlobal->Co= mmonVariableSpace); - mVariableModuleGlobal->CommonRuntimeVariableSpace =3D mVariableModuleGlo= bal->CommonVariableSpace - BoottimeReservedNvVariableSpaceSize; - - DEBUG ((EFI_D_INFO, "Variable driver common space: 0x%x 0x%x 0x%x\n", mV= ariableModuleGlobal->CommonVariableSpace, mVariableModuleGlobal->CommonMaxU= serVariableSpace, mVariableModuleGlobal->CommonRuntimeVariableSpace)); - - // - // The max NV variable size should be < (VariableStoreLength - sizeof (V= ARIABLE_STORE_HEADER)). - // - ASSERT (GetNonVolatileMaxVariableSize () < (VariableStoreLength - sizeof= (VARIABLE_STORE_HEADER))); - - return EFI_SUCCESS; -} - -/** - Init emulated non-volatile variable store. - - @param[out] VariableStoreBase Output pointer to emulated non-volatile va= riable store base. - - @retval EFI_SUCCESS Function successfully executed. - @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource. - -**/ -EFI_STATUS -InitEmuNonVolatileVariableStore ( - EFI_PHYSICAL_ADDRESS *VariableStoreBase - ) -{ - VARIABLE_STORE_HEADER *VariableStore; - UINT32 VariableStoreLength; - BOOLEAN FullyInitializeStore; - UINT32 HwErrStorageSize; - - FullyInitializeStore =3D TRUE; - - VariableStoreLength =3D PcdGet32 (PcdVariableStoreSize); - ASSERT (sizeof (VARIABLE_STORE_HEADER) <=3D VariableStoreLength); - - // - // Allocate memory for variable store. - // - if (PcdGet64 (PcdEmuVariableNvStoreReserved) =3D=3D 0) { - VariableStore =3D (VARIABLE_STORE_HEADER *) AllocateRuntimePool (Varia= bleStoreLength); - if (VariableStore =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - } else { - // - // A memory location has been reserved for the NV variable store. Cer= tain - // platforms may be able to preserve a memory range across system rese= ts, - // thereby providing better NV variable emulation. - // - VariableStore =3D - (VARIABLE_STORE_HEADER *)(VOID*)(UINTN) - PcdGet64 (PcdEmuVariableNvStoreReserved); - if ((VariableStore->Size =3D=3D VariableStoreLength) && - (CompareGuid (&VariableStore->Signature, &gEfiAuthenticatedVariabl= eGuid) || - CompareGuid (&VariableStore->Signature, &gEfiVariableGuid)) && - (VariableStore->Format =3D=3D VARIABLE_STORE_FORMATTED) && - (VariableStore->State =3D=3D VARIABLE_STORE_HEALTHY)) { - DEBUG(( - DEBUG_INFO, - "Variable Store reserved at %p appears to be valid\n", - VariableStore - )); - FullyInitializeStore =3D FALSE; - } - } - - if (FullyInitializeStore) { - SetMem (VariableStore, VariableStoreLength, 0xff); - // - // Use gEfiAuthenticatedVariableGuid for potential auth variable suppo= rt. - // - CopyGuid (&VariableStore->Signature, &gEfiAuthenticatedVariableGuid); - VariableStore->Size =3D VariableStoreLength; - VariableStore->Format =3D VARIABLE_STORE_FORMATTED; - VariableStore->State =3D VARIABLE_STORE_HEALTHY; - VariableStore->Reserved =3D 0; - VariableStore->Reserved1 =3D 0; - } - - *VariableStoreBase =3D (EFI_PHYSICAL_ADDRESS) (UINTN) VariableStore; - - HwErrStorageSize =3D PcdGet32 (PcdHwErrStorageSize); - - // - // Note that in EdkII variable driver implementation, Hardware Error Rec= ord type variable - // is stored with common variable in the same NV region. So the platform= integrator should - // ensure that the value of PcdHwErrStorageSize is less than the value of - // (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)). - // - ASSERT (HwErrStorageSize < (VariableStoreLength - sizeof (VARIABLE_STORE= _HEADER))); - - mVariableModuleGlobal->CommonVariableSpace =3D ((UINTN) VariableStoreLen= gth - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize); - mVariableModuleGlobal->CommonMaxUserVariableSpace =3D mVariableModuleGlo= bal->CommonVariableSpace; - mVariableModuleGlobal->CommonRuntimeVariableSpace =3D mVariableModuleGlo= bal->CommonVariableSpace; - - return EFI_SUCCESS; -} - -/** - Init non-volatile variable store. - - @retval EFI_SUCCESS Function successfully executed. - @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource. - @retval EFI_VOLUME_CORRUPTED Variable Store or Firmware Volume for Vari= able Store is corrupted. - -**/ -EFI_STATUS -InitNonVolatileVariableStore ( - VOID - ) -{ - VARIABLE_HEADER *Variable; - VARIABLE_HEADER *NextVariable; - EFI_PHYSICAL_ADDRESS VariableStoreBase; - UINTN VariableSize; - EFI_STATUS Status; - - if (PcdGetBool (PcdEmuVariableNvModeEnable)) { - Status =3D InitEmuNonVolatileVariableStore (&VariableStoreBase); - if (EFI_ERROR (Status)) { - return Status; - } - mVariableModuleGlobal->VariableGlobal.EmuNvMode =3D TRUE; - DEBUG ((DEBUG_INFO, "Variable driver will work at emulated non-volatil= e variable mode!\n")); - } else { - Status =3D InitRealNonVolatileVariableStore (&VariableStoreBase); - if (EFI_ERROR (Status)) { - return Status; - } - mVariableModuleGlobal->VariableGlobal.EmuNvMode =3D FALSE; - } - - mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase =3D Variab= leStoreBase; - mNvVariableCache =3D (VARIABLE_STORE_HEADER *) (UINTN) VariableStoreBase; - mVariableModuleGlobal->VariableGlobal.AuthFormat =3D (BOOLEAN)(CompareGu= id (&mNvVariableCache->Signature, &gEfiAuthenticatedVariableGuid)); - - mVariableModuleGlobal->MaxVariableSize =3D PcdGet32 (PcdMaxVariableSize); - mVariableModuleGlobal->MaxAuthVariableSize =3D ((PcdGet32 (PcdMaxAuthVar= iableSize) !=3D 0) ? PcdGet32 (PcdMaxAuthVariableSize) : mVariableModuleGlo= bal->MaxVariableSize); - - // - // Parse non-volatile variable data and get last variable offset. - // - Variable =3D GetStartPointer (mNvVariableCache); - while (IsValidVariableHeader (Variable, GetEndPointer (mNvVariableCache)= )) { - NextVariable =3D GetNextVariablePtr (Variable, mVariableModuleGlobal->= VariableGlobal.AuthFormat); - VariableSize =3D (UINTN) NextVariable - (UINTN) Variable; - if ((Variable->Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_= HARDWARE_ERROR_RECORD)) =3D=3D (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HA= RDWARE_ERROR_RECORD)) { - mVariableModuleGlobal->HwErrVariableTotalSize +=3D VariableSize; - } else { - mVariableModuleGlobal->CommonVariableTotalSize +=3D VariableSize; - } - - Variable =3D NextVariable; - } - mVariableModuleGlobal->NonVolatileLastVariableOffset =3D (UINTN) Variabl= e - (UINTN) mNvVariableCache; - - return EFI_SUCCESS; -} - /** Flush the HOB variable to flash. =20 diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile= .c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c new file mode 100644 index 0000000000..0637a828b3 --- /dev/null +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c @@ -0,0 +1,334 @@ +/** @file + Common variable non-volatile store routines. + +Copyright (c) 2019, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "VariableNonVolatile.h" +#include "VariableParsing.h" + +extern VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal; + +/** + Get non-volatile maximum variable size. + + @return Non-volatile maximum variable size. + +**/ +UINTN +GetNonVolatileMaxVariableSize ( + VOID + ) +{ + if (PcdGet32 (PcdHwErrStorageSize) !=3D 0) { + return MAX (MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxAuthVa= riableSize)), + PcdGet32 (PcdMaxHardwareErrorVariableSize)); + } else { + return MAX (PcdGet32 (PcdMaxVariableSize), PcdGet32 (PcdMaxAuthVariabl= eSize)); + } +} + +/** + Init emulated non-volatile variable store. + + @param[out] VariableStoreBase Output pointer to emulated non-volatile va= riable store base. + + @retval EFI_SUCCESS Function successfully executed. + @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource. + +**/ +EFI_STATUS +InitEmuNonVolatileVariableStore ( + OUT EFI_PHYSICAL_ADDRESS *VariableStoreBase + ) +{ + VARIABLE_STORE_HEADER *VariableStore; + UINT32 VariableStoreLength; + BOOLEAN FullyInitializeStore; + UINT32 HwErrStorageSize; + + FullyInitializeStore =3D TRUE; + + VariableStoreLength =3D PcdGet32 (PcdVariableStoreSize); + ASSERT (sizeof (VARIABLE_STORE_HEADER) <=3D VariableStoreLength); + + // + // Allocate memory for variable store. + // + if (PcdGet64 (PcdEmuVariableNvStoreReserved) =3D=3D 0) { + VariableStore =3D (VARIABLE_STORE_HEADER *) AllocateRuntimePool (Varia= bleStoreLength); + if (VariableStore =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + } else { + // + // A memory location has been reserved for the NV variable store. Cer= tain + // platforms may be able to preserve a memory range across system rese= ts, + // thereby providing better NV variable emulation. + // + VariableStore =3D + (VARIABLE_STORE_HEADER *)(VOID*)(UINTN) + PcdGet64 (PcdEmuVariableNvStoreReserved); + if ((VariableStore->Size =3D=3D VariableStoreLength) && + (CompareGuid (&VariableStore->Signature, &gEfiAuthenticatedVariabl= eGuid) || + CompareGuid (&VariableStore->Signature, &gEfiVariableGuid)) && + (VariableStore->Format =3D=3D VARIABLE_STORE_FORMATTED) && + (VariableStore->State =3D=3D VARIABLE_STORE_HEALTHY)) { + DEBUG(( + DEBUG_INFO, + "Variable Store reserved at %p appears to be valid\n", + VariableStore + )); + FullyInitializeStore =3D FALSE; + } + } + + if (FullyInitializeStore) { + SetMem (VariableStore, VariableStoreLength, 0xff); + // + // Use gEfiAuthenticatedVariableGuid for potential auth variable suppo= rt. + // + CopyGuid (&VariableStore->Signature, &gEfiAuthenticatedVariableGuid); + VariableStore->Size =3D VariableStoreLength; + VariableStore->Format =3D VARIABLE_STORE_FORMATTED; + VariableStore->State =3D VARIABLE_STORE_HEALTHY; + VariableStore->Reserved =3D 0; + VariableStore->Reserved1 =3D 0; + } + + *VariableStoreBase =3D (EFI_PHYSICAL_ADDRESS) (UINTN) VariableStore; + + HwErrStorageSize =3D PcdGet32 (PcdHwErrStorageSize); + + // + // Note that in EdkII variable driver implementation, Hardware Error Rec= ord type variable + // is stored with common variable in the same NV region. So the platform= integrator should + // ensure that the value of PcdHwErrStorageSize is less than the value of + // (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)). + // + ASSERT (HwErrStorageSize < (VariableStoreLength - sizeof (VARIABLE_STORE= _HEADER))); + + mVariableModuleGlobal->CommonVariableSpace =3D ((UINTN) VariableStoreLen= gth - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize); + mVariableModuleGlobal->CommonMaxUserVariableSpace =3D mVariableModuleGlo= bal->CommonVariableSpace; + mVariableModuleGlobal->CommonRuntimeVariableSpace =3D mVariableModuleGlo= bal->CommonVariableSpace; + + return EFI_SUCCESS; +} + +/** + Init real non-volatile variable store. + + @param[out] VariableStoreBase Output pointer to real non-volatile variab= le store base. + + @retval EFI_SUCCESS Function successfully executed. + @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource. + @retval EFI_VOLUME_CORRUPTED Variable Store or Firmware Volume for Vari= able Store is corrupted. + +**/ +EFI_STATUS +InitRealNonVolatileVariableStore ( + OUT EFI_PHYSICAL_ADDRESS *VariableStoreBase + ) +{ + EFI_FIRMWARE_VOLUME_HEADER *FvHeader; + VARIABLE_STORE_HEADER *VariableStore; + UINT32 VariableStoreLength; + EFI_HOB_GUID_TYPE *GuidHob; + EFI_PHYSICAL_ADDRESS NvStorageBase; + UINT8 *NvStorageData; + UINT32 NvStorageSize; + FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData; + UINT32 BackUpOffset; + UINT32 BackUpSize; + UINT32 HwErrStorageSize; + UINT32 MaxUserNvVariableSpaceSize; + UINT32 BoottimeReservedNvVariableSpaceSiz= e; + EFI_STATUS Status; + VOID *FtwProtocol; + + mVariableModuleGlobal->FvbInstance =3D NULL; + + // + // Allocate runtime memory used for a memory copy of the FLASH region. + // Keep the memory and the FLASH in sync as updates occur. + // + NvStorageSize =3D PcdGet32 (PcdFlashNvStorageVariableSize); + NvStorageData =3D AllocateRuntimeZeroPool (NvStorageSize); + if (NvStorageData =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + NvStorageBase =3D NV_STORAGE_VARIABLE_BASE; + ASSERT (NvStorageBase !=3D 0); + + // + // Copy NV storage data to the memory buffer. + // + CopyMem (NvStorageData, (UINT8 *) (UINTN) NvStorageBase, NvStorageSize); + + Status =3D GetFtwProtocol ((VOID **)&FtwProtocol); + // + // If FTW protocol has been installed, no need to check FTW last write d= ata hob. + // + if (EFI_ERROR (Status)) { + // + // Check the FTW last write data hob. + // + GuidHob =3D GetFirstGuidHob (&gEdkiiFaultTolerantWriteGuid); + if (GuidHob !=3D NULL) { + FtwLastWriteData =3D (FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *) GET_GU= ID_HOB_DATA (GuidHob); + if (FtwLastWriteData->TargetAddress =3D=3D NvStorageBase) { + DEBUG ((DEBUG_INFO, "Variable: NV storage is backed up in spare bl= ock: 0x%x\n", (UINTN) FtwLastWriteData->SpareAddress)); + // + // Copy the backed up NV storage data to the memory buffer from sp= are block. + // + CopyMem (NvStorageData, (UINT8 *) (UINTN) (FtwLastWriteData->Spare= Address), NvStorageSize); + } else if ((FtwLastWriteData->TargetAddress > NvStorageBase) && + (FtwLastWriteData->TargetAddress < (NvStorageBase + NvSto= rageSize))) { + // + // Flash NV storage from the Offset is backed up in spare block. + // + BackUpOffset =3D (UINT32) (FtwLastWriteData->TargetAddress - NvSto= rageBase); + BackUpSize =3D NvStorageSize - BackUpOffset; + DEBUG ((DEBUG_INFO, "Variable: High partial NV storage from offset= : %x is backed up in spare block: 0x%x\n", BackUpOffset, (UINTN) FtwLastWri= teData->SpareAddress)); + // + // Copy the partial backed up NV storage data to the memory buffer= from spare block. + // + CopyMem (NvStorageData + BackUpOffset, (UINT8 *) (UINTN) FtwLastWr= iteData->SpareAddress, BackUpSize); + } + } + } + + FvHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *) NvStorageData; + + // + // Check if the Firmware Volume is not corrupted + // + if ((FvHeader->Signature !=3D EFI_FVH_SIGNATURE) || (!CompareGuid (&gEfi= SystemNvDataFvGuid, &FvHeader->FileSystemGuid))) { + FreePool (NvStorageData); + DEBUG ((DEBUG_ERROR, "Firmware Volume for Variable Store is corrupted\= n")); + return EFI_VOLUME_CORRUPTED; + } + + VariableStore =3D (VARIABLE_STORE_HEADER *) ((UINTN) FvHeader + FvHeader= ->HeaderLength); + VariableStoreLength =3D NvStorageSize - FvHeader->HeaderLength; + ASSERT (sizeof (VARIABLE_STORE_HEADER) <=3D VariableStoreLength); + ASSERT (VariableStore->Size =3D=3D VariableStoreLength); + + // + // Check if the Variable Store header is not corrupted + // + if (GetVariableStoreStatus (VariableStore) !=3D EfiValid) { + FreePool (NvStorageData); + DEBUG((DEBUG_ERROR, "Variable Store header is corrupted\n")); + return EFI_VOLUME_CORRUPTED; + } + + mNvFvHeaderCache =3D FvHeader; + + *VariableStoreBase =3D (EFI_PHYSICAL_ADDRESS) (UINTN) VariableStore; + + HwErrStorageSize =3D PcdGet32 (PcdHwErrStorageSize); + MaxUserNvVariableSpaceSize =3D PcdGet32 (PcdMaxUserNvVariableSpaceSize); + BoottimeReservedNvVariableSpaceSize =3D PcdGet32 (PcdBoottimeReservedNvV= ariableSpaceSize); + + // + // Note that in EdkII variable driver implementation, Hardware Error Rec= ord type variable + // is stored with common variable in the same NV region. So the platform= integrator should + // ensure that the value of PcdHwErrStorageSize is less than the value of + // (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)). + // + ASSERT (HwErrStorageSize < (VariableStoreLength - sizeof (VARIABLE_STORE= _HEADER))); + // + // Ensure that the value of PcdMaxUserNvVariableSpaceSize is less than t= he value of + // (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)) - PcdGet32 (Pc= dHwErrStorageSize). + // + ASSERT (MaxUserNvVariableSpaceSize < (VariableStoreLength - sizeof (VARI= ABLE_STORE_HEADER) - HwErrStorageSize)); + // + // Ensure that the value of PcdBoottimeReservedNvVariableSpaceSize is le= ss than the value of + // (VariableStoreLength - sizeof (VARIABLE_STORE_HEADER)) - PcdGet32 (Pc= dHwErrStorageSize). + // + ASSERT (BoottimeReservedNvVariableSpaceSize < (VariableStoreLength - siz= eof (VARIABLE_STORE_HEADER) - HwErrStorageSize)); + + mVariableModuleGlobal->CommonVariableSpace =3D ((UINTN) VariableStoreLen= gth - sizeof (VARIABLE_STORE_HEADER) - HwErrStorageSize); + mVariableModuleGlobal->CommonMaxUserVariableSpace =3D ((MaxUserNvVariabl= eSpaceSize !=3D 0) ? MaxUserNvVariableSpaceSize : mVariableModuleGlobal->Co= mmonVariableSpace); + mVariableModuleGlobal->CommonRuntimeVariableSpace =3D mVariableModuleGlo= bal->CommonVariableSpace - BoottimeReservedNvVariableSpaceSize; + + DEBUG (( + DEBUG_INFO, + "Variable driver common space: 0x%x 0x%x 0x%x\n", + mVariableModuleGlobal->CommonVariableSpace, + mVariableModuleGlobal->CommonMaxUserVariableSpace, + mVariableModuleGlobal->CommonRuntimeVariableSpace + )); + + // + // The max NV variable size should be < (VariableStoreLength - sizeof (V= ARIABLE_STORE_HEADER)). + // + ASSERT (GetNonVolatileMaxVariableSize () < (VariableStoreLength - sizeof= (VARIABLE_STORE_HEADER))); + + return EFI_SUCCESS; +} + +/** + Init non-volatile variable store. + + @retval EFI_SUCCESS Function successfully executed. + @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource. + @retval EFI_VOLUME_CORRUPTED Variable Store or Firmware Volume for Vari= able Store is corrupted. + +**/ +EFI_STATUS +InitNonVolatileVariableStore ( + VOID + ) +{ + VARIABLE_HEADER *Variable; + VARIABLE_HEADER *NextVariable; + EFI_PHYSICAL_ADDRESS VariableStoreBase; + UINTN VariableSize; + EFI_STATUS Status; + + if (PcdGetBool (PcdEmuVariableNvModeEnable)) { + Status =3D InitEmuNonVolatileVariableStore (&VariableStoreBase); + if (EFI_ERROR (Status)) { + return Status; + } + mVariableModuleGlobal->VariableGlobal.EmuNvMode =3D TRUE; + DEBUG ((DEBUG_INFO, "Variable driver will work at emulated non-volatil= e variable mode!\n")); + } else { + Status =3D InitRealNonVolatileVariableStore (&VariableStoreBase); + if (EFI_ERROR (Status)) { + return Status; + } + mVariableModuleGlobal->VariableGlobal.EmuNvMode =3D FALSE; + } + + mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase =3D Variab= leStoreBase; + mNvVariableCache =3D (VARIABLE_STORE_HEADER *) (UINTN) VariableStoreBase; + mVariableModuleGlobal->VariableGlobal.AuthFormat =3D (BOOLEAN)(CompareGu= id (&mNvVariableCache->Signature, &gEfiAuthenticatedVariableGuid)); + + mVariableModuleGlobal->MaxVariableSize =3D PcdGet32 (PcdMaxVariableSize); + mVariableModuleGlobal->MaxAuthVariableSize =3D ((PcdGet32 (PcdMaxAuthVar= iableSize) !=3D 0) ? PcdGet32 (PcdMaxAuthVariableSize) : mVariableModuleGlo= bal->MaxVariableSize); + + // + // Parse non-volatile variable data and get last variable offset. + // + Variable =3D GetStartPointer (mNvVariableCache); + while (IsValidVariableHeader (Variable, GetEndPointer (mNvVariableCache)= )) { + NextVariable =3D GetNextVariablePtr (Variable, mVariableModuleGlobal->= VariableGlobal.AuthFormat); + VariableSize =3D (UINTN) NextVariable - (UINTN) Variable; + if ((Variable->Attributes & (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_= HARDWARE_ERROR_RECORD)) =3D=3D (EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_HA= RDWARE_ERROR_RECORD)) { + mVariableModuleGlobal->HwErrVariableTotalSize +=3D VariableSize; + } else { + mVariableModuleGlobal->CommonVariableTotalSize +=3D VariableSize; + } + + Variable =3D NextVariable; + } + mVariableModuleGlobal->NonVolatileLastVariableOffset =3D (UINTN) Variabl= e - (UINTN) mNvVariableCache; + + return EFI_SUCCESS; +} --=20 2.16.2.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 (#49726): https://edk2.groups.io/g/devel/message/49726 Mute This Topic: https://groups.io/mt/40103020/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- From nobody Wed Apr 24 23:27:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49727+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49727+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1572504353; cv=none; d=zoho.com; s=zohoarc; b=K7+FJim4oLaFBZzbMj1FBSzBA5I5A8azqccpA8JGUtTEEfmBClbrj0Cgc0DRafT+6mWFcZnnC91BmZXUmRMmmEQMs6+ObjOEsPogAA5lDQu9BTBahktUI/v52HpcinFGljTirpG7D/5zZ/VFc0xCoQwOTIWtxnubFcJB4SQQJZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572504353; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=zAzWoMV367dRUZySBZJhGjcdaiokE/uhhZ2MHJbh6vc=; b=M+fjKdiZCbitMYrEu1aLXtwLHFrvo0ByLXsesiLN8pvb5Cbi+9Y//h4nWn6TNYedCHI5yjfhMbMl6yfGxCPA2XpUFN6RNT2l9HVvPizYWdG5Ejxo9KztqXuHjXOxf/C/K2SLeg52iYLn4ofMe0hpFOMLTUEcDmaPhJAlq2IVPrE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49727+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1572504353510237.66298206049612; Wed, 30 Oct 2019 23:45:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id f1czYY1788612xfrQnObvLHm; Wed, 30 Oct 2019 23:45:52 -0700 X-Received: from mga01.intel.com (mga01.intel.com []) by mx.groups.io with SMTP id smtpd.web10.2575.1572504335480868589 for ; Wed, 30 Oct 2019 23:45:51 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 23:45:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,250,1569308400"; d="scan'208";a="351547469" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga004.jf.intel.com with ESMTP; 30 Oct 2019 23:45:51 -0700 From: "Kubacki, Michael A" To: devel@edk2.groups.io Cc: Dandan Bi , Ard Biesheuvel , Eric Dong , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu , Jiewen Yao Subject: [edk2-devel] [PATCH V6 06/10] MdeModulePkg VariableInfo: Always consider RT DXE and SMM stats Date: Wed, 30 Oct 2019 23:45:06 -0700 Message-Id: <20191031064510.23948-7-michael.a.kubacki@intel.com> In-Reply-To: <20191031064510.23948-1-michael.a.kubacki@intel.com> References: <20191031064510.23948-1-michael.a.kubacki@intel.com> Precedence: Bulk List-Unsubscribe: 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,michael.a.kubacki@intel.com X-Gm-Message-State: 51ovJYZqmoHNf9DQr01gd29ex1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572504352; bh=XY3/mccKEFd0M5hJl+pswmyzsrzlbexOKZPH1BHTKq0=; h=Cc:Date:From:Reply-To:Subject:To; b=kyf6Vh1is04xxj1JovaT/FZMRxH1WPIoS+jGvluetjdhum+hTa2V7CA14a/0bMpzwXZ KajEXKoCezQP27tIgu3fqP/1E3iVMOfW/ZOVR4YgFqfyZ5/IRMfUKuzyO+STtE1c92X6A 9XFqNh7R7So/zhh4sRfJJfIE/HrTS30cL/U= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2220 The current VariableInfo application only checks for variable statistics from SMM if the variable information entries are not present in the UEFI System Configuration table as published by the DXE UEFI variable driver (VariableRuntimeDxe). This change first checks for variable information entries in the UEFI System Configuration but always checks for entries in SMM as well. If the SMM variable driver is not present, an instance of EFI_SMM_VARIABLE_PROTOCOL will not be found and the search for SMM variable statistics will be aborted (an SW SMI to get variable statistics will not be triggered). In the case variable statistics are provided by both a Runtime DXE driver (e.g. VariableSmmRuntimeDxe) and a SMM driver (VariableSmm), this change will clearly identify statistics from each respective driver. Cc: Dandan Bi Cc: Ard Biesheuvel Cc: Eric Dong Cc: Laszlo Ersek Cc: Liming Gao Cc: Michael D Kinney Cc: Ray Ni Cc: Jian J Wang Cc: Hao A Wu Cc: Jiewen Yao Signed-off-by: Michael Kubacki Reviewed-by: Jian J Wang --- MdeModulePkg/Application/VariableInfo/VariableInfo.c | 37 ++++++++++------= ---- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/MdeModulePkg/Application/VariableInfo/VariableInfo.c b/MdeModu= lePkg/Application/VariableInfo/VariableInfo.c index f213471e9a..c04ba18213 100644 --- a/MdeModulePkg/Application/VariableInfo/VariableInfo.c +++ b/MdeModulePkg/Application/VariableInfo/VariableInfo.c @@ -3,7 +3,7 @@ this utility will print out the statistics information. You can use cons= ole redirection to capture the data. =20 - Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -126,7 +126,7 @@ PrintInfoFromSmm ( ASSERT (CommBuffer !=3D NULL); ZeroMem (CommBuffer, RealCommSize); =20 - Print (L"Non-Volatile SMM Variables:\n"); + Print (L"SMM Driver Non-Volatile Variables:\n"); do { CommSize =3D RealCommSize; Status =3D GetVariableStatisticsData (CommBuffer, &CommSize); @@ -155,7 +155,7 @@ PrintInfoFromSmm ( } } while (TRUE); =20 - Print (L"Volatile SMM Variables:\n"); + Print (L"SMM Driver Volatile Variables:\n"); ZeroMem (CommBuffer, RealCommSize); do { CommSize =3D RealCommSize; @@ -207,24 +207,18 @@ UefiMain ( IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; + EFI_STATUS RuntimeDxeStatus; + EFI_STATUS SmmStatus; VARIABLE_INFO_ENTRY *VariableInfo; VARIABLE_INFO_ENTRY *Entry; =20 - Status =3D EfiGetSystemConfigurationTable (&gEfiVariableGuid, (VOID **)&= Entry); - if (EFI_ERROR (Status) || (Entry =3D=3D NULL)) { - Status =3D EfiGetSystemConfigurationTable (&gEfiAuthenticatedVariableG= uid, (VOID **)&Entry); + RuntimeDxeStatus =3D EfiGetSystemConfigurationTable (&gEfiVariableGuid, = (VOID **) &Entry); + if (EFI_ERROR (RuntimeDxeStatus) || (Entry =3D=3D NULL)) { + RuntimeDxeStatus =3D EfiGetSystemConfigurationTable (&gEfiAuthenticate= dVariableGuid, (VOID **) &Entry); } =20 - if (EFI_ERROR (Status) || (Entry =3D=3D NULL)) { - Status =3D PrintInfoFromSmm (); - if (!EFI_ERROR (Status)) { - return Status; - } - } - - if (!EFI_ERROR (Status) && (Entry !=3D NULL)) { - Print (L"Non-Volatile EFI Variables:\n"); + if (!EFI_ERROR (RuntimeDxeStatus) && (Entry !=3D NULL)) { + Print (L"Runtime DXE Driver Non-Volatile EFI Variables:\n"); VariableInfo =3D Entry; do { if (!VariableInfo->Volatile) { @@ -242,7 +236,7 @@ UefiMain ( VariableInfo =3D VariableInfo->Next; } while (VariableInfo !=3D NULL); =20 - Print (L"Volatile EFI Variables:\n"); + Print (L"Runtime DXE Driver Volatile EFI Variables:\n"); VariableInfo =3D Entry; do { if (VariableInfo->Volatile) { @@ -258,14 +252,19 @@ UefiMain ( } VariableInfo =3D VariableInfo->Next; } while (VariableInfo !=3D NULL); + } =20 - } else { + SmmStatus =3D PrintInfoFromSmm (); + + if (EFI_ERROR (RuntimeDxeStatus) && EFI_ERROR (SmmStatus)) { Print (L"Warning: Variable Dxe/Smm driver doesn't enable the feature o= f statistical information!\n"); Print (L"If you want to see this info, please:\n"); Print (L" 1. Set PcdVariableCollectStatistics as TRUE\n"); Print (L" 2. Rebuild Variable Dxe/Smm driver\n"); Print (L" 3. Run \"VariableInfo\" cmd again\n"); + + return EFI_NOT_FOUND; } =20 - return Status; + return EFI_SUCCESS; } --=20 2.16.2.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 (#49727): https://edk2.groups.io/g/devel/message/49727 Mute This Topic: https://groups.io/mt/40103023/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- From nobody Wed Apr 24 23:27:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49728+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49728+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1572504358; cv=none; d=zoho.com; s=zohoarc; b=n5YoTQmczjSXyYgJeXVYwQJikoI+Qd2JBUbz29wimvX00nU/i+ebbvSOacnfmSH+uv5i6BwzrSk6uIMJkFZXnR9uam201wPHqaT7G7x1Ws6GxvJ4eyzBm14Omxkr4feooP42lSgdn0jGPQ66zsH+WzjaFDfjLb5cKTBJnNKiq+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572504358; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=Kqw7a10DUruP9CwSXtMAE0oAkNgP2ZTlfFDFL1FIMWM=; b=EwJvCOcAFYvFCvlm4/tsiY2y3GSdRbOXEJA1aFDRHwVih2OXJeF0Z/gHOEU30MFck3WPyquDgHLXLIhFAuJmyqiYsNla5+yx5aslZkk20u8Jr5bv7N8urNp90ovH7P9NZfBEY9kZD3c6UyWUY9QRKaDgb0EwY9UuUF1XNgI02nw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49728+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1572504358932800.6960240946014; Wed, 30 Oct 2019 23:45:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id h1PdYY1788612xwWSN6HphwV; Wed, 30 Oct 2019 23:45:58 -0700 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web10.2581.1572504357840732993 for ; Wed, 30 Oct 2019 23:45:57 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 23:45:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,250,1569308400"; d="scan'208";a="351547489" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga004.jf.intel.com with ESMTP; 30 Oct 2019 23:45:57 -0700 From: "Kubacki, Michael A" To: devel@edk2.groups.io Cc: Dandan Bi , Ard Biesheuvel , Eric Dong , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu , Jiewen Yao Subject: [edk2-devel] [PATCH V6 07/10] MdeModulePkg/Variable: Add RT GetVariable() cache support Date: Wed, 30 Oct 2019 23:45:07 -0700 Message-Id: <20191031064510.23948-8-michael.a.kubacki@intel.com> In-Reply-To: <20191031064510.23948-1-michael.a.kubacki@intel.com> References: <20191031064510.23948-1-michael.a.kubacki@intel.com> Precedence: Bulk List-Unsubscribe: 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,michael.a.kubacki@intel.com X-Gm-Message-State: f2eSpPIjdhHqTAzwsQphUTPbx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572504358; bh=Wfphk30JgjgjcTv+uFCk1y2dWrTPdJoEhWFAuG10CKU=; h=Cc:Date:From:Reply-To:Subject:To; b=Pzk7FVpu5DqpXBh+RQ8TiDXIc3gSUDioax4DQky4l0zJgnoloIDmsKSX5U28y1oXL9U t5/3d+htDGV6OLc6dVBYGqQs6+5cGDko74F2nMTAsZ9l7COC9h7xqx/ucCaZ+k9i7Wzj2 GS8NiiVkynlA3EmRAszpNMlagp9fFf07zh4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2220 This change reduces SMIs for GetVariable () by maintaining a UEFI variable cache in Runtime DXE in addition to the pre- existing cache in SMRAM. When the Runtime Service GetVariable() is invoked, a Runtime DXE cache is used instead of triggering an SMI to VariableSmm. This can improve overall system performance by servicing variable read requests without rendezvousing all cores into SMM. The runtime cache can be disabled with by setting the FeaturePCD gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache to FALSE. If the PCD is set to FALSE, the runtime cache will not be used and an SMI will be triggered for Runtime Service GetVariable () and GetNextVariableName () invocations. The following are important points regarding the behavior of the variable drivers when the variable runtime cache is enabled. 1. All of the non-volatile storage contents are loaded into the cache upon driver load. This one time load operation from storage is preferred as opposed to building the cache on demand. An on- demand cache would require a fallback SMI to load data into the cache as variables are requested. 2. SetVariable () requests will continue to always trigger an SMI. This occurs regardless of whether the variable is volatile or non-volatile. 3. Both volatile and non-volatile variables are cached in a runtime buffer. As is the case in the current EDK II variable driver, they continue to be cached in separate buffers. 4. The cache in Runtime DXE and SMM are intended to be exact copies of one another. All SMM variable accesses only return data from the SMM cache. The runtime caches are only updated after the variable I/O operation is successful in SMM. The runtime caches are only updated from SMM. 5. Synchronization mechanisms are in place to ensure the runtime cache content integrity with the SMM cache. These may result in updates to runtime cache that are the same in content but different in offset and size from updates to the SMM cache. When using SMM variables with runtime cache enabled, two caches will now be present. 1. "Runtime Cache" - Maintained in VariableSmmRuntimeDxe. Used to service Runtime Services GetVariable () and GetNextVariableName () callers. 2. "SMM Cache" - Maintained in VariableSmm to service SMM GetVariable () and GetNextVariableName () callers. a. This cache is retained so SMM modules do not operate on data outside SMRAM. Because a race condition can occur if an SMI occurs during the execution of runtime code reading from the runtime cache, a runtime cache read lock is introduced that explicitly moves pending updates from SMM to the runtime cache if an SMM update occurs while the runtime cache is locked. Note that it is not expected a Runtime services call will interrupt SMM processing since all CPU cores rendezvous in SMM. It is possible to view UEFI variable read and write statistics by setting the gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics FeaturePcd to TRUE and using the VariableInfo UEFI application in MdeModulePkg to dump variable statistics to the console. By doing so, a user can view the number of GetVariable () hits from the Runtime DXE variable driver (Runtime Cache hits) and the SMM variable driver (SMM Cache hits). SMM Cache hits for GetVariable () will occur when SMM modules invoke GetVariable (). Cc: Dandan Bi Cc: Ard Biesheuvel Cc: Eric Dong Cc: Laszlo Ersek Cc: Liming Gao Cc: Michael D Kinney Cc: Ray Ni Cc: Jian J Wang Cc: Hao A Wu Cc: Jiewen Yao Signed-off-by: Michael Kubacki Reviewed-by: Jian J Wang --- MdeModulePkg/MdeModulePkg.dec | 12= + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf | 2= + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf | 2= + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf | 20= +- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf | 2= + MdeModulePkg/Include/Guid/SmmVariableCommon.h | 29= +- MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h | 32= +- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeCache.h | 51= ++ MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c | 50= +- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeCache.c | 153= ++++++ MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 189= +++++++- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c | 512= +++++++++++++++++++- 12 files changed, 1013 insertions(+), 41 deletions(-) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index d6bac974da..3ef8fe7644 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -641,6 +641,18 @@ # @Prompt Enable Device Path From Text support. gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText|TR= UE|BOOLEAN|0x00010038 =20 + ## Indicates if the UEFI variable runtime cache should be enabled. + # This setting only applies if SMM variables are enabled. When enabled,= all variable + # data for Runtime Service GetVariable () and GetNextVariableName () ca= lls is retrieved + # from a runtime data buffer referred to as the "runtime cache". An SMI= is not triggered + # at all for these requests. Variables writes still trigger an SMI. Thi= s can greatly + # reduce overall system SMM usage as most boots tend to issue far more = variable reads + # than writes.

+ # TRUE - The UEFI variable runtime cache is enabled.
+ # FALSE - The UEFI variable runtime cache is disabled.
+ # @Prompt Enable the UEFI variable runtime cache. + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache|FALSE|BOOLE= AN|0x00010039 + ## Indicates if the statistics about variable usage will be collected. T= his information is # stored as a vendor configuration table into the EFI system table. # Set this PCD to TRUE to use VariableInfo application in MdeModulePkg\= Application directory to get diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.= inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf index 08a5490787..ceea5d1ff9 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf @@ -40,6 +40,8 @@ VariableNonVolatile.h VariableParsing.c VariableParsing.h + VariableRuntimeCache.c + VariableRuntimeCache.h PrivilegePolymorphic.h Measurement.c TcgMorLockDxe.c diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf b/M= deModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf index 6dc2721b81..bc3033588d 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf @@ -49,6 +49,8 @@ VariableNonVolatile.h VariableParsing.c VariableParsing.h + VariableRuntimeCache.c + VariableRuntimeCache.h VarCheck.c Variable.h PrivilegePolymorphic.h diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD= xe.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.i= nf index 14894e6f13..b5a779a233 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf @@ -13,7 +13,7 @@ # may not be modified without authorization. If platform fails to protect= these resources, # the authentication service provided in this driver will be broken, and = the behavior is undefined. # -# Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -39,6 +39,10 @@ VariableSmmRuntimeDxe.c PrivilegePolymorphic.h Measurement.c + VariableParsing.c + VariableParsing.h + VariableRuntimeCache.c + VariableRuntimeCache.h =20 [Packages] MdePkg/MdePkg.dec @@ -65,7 +69,21 @@ gEdkiiVariableLockProtocolGuid ## PRODUCES gEdkiiVarCheckProtocolGuid ## PRODUCES =20 +[FeaturePcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache #= # CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdVariableCollectStatistics #= # CONSUMES + [Guids] + ## PRODUCES ## GUID # Signature of Variable store header + ## CONSUMES ## GUID # Signature of Variable store header + ## SOMETIMES_PRODUCES ## SystemTable + gEfiAuthenticatedVariableGuid + + ## PRODUCES ## GUID # Signature of Variable store header + ## CONSUMES ## GUID # Signature of Variable store header + ## SOMETIMES_PRODUCES ## SystemTable + gEfiVariableGuid + gEfiEventVirtualAddressChangeGuid ## CONSUMES ## Event gEfiEventExitBootServicesGuid ## CONSUMES ## Event ## CONSUMES ## GUID # Locate protocol diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneM= m.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf index f8a3742959..6e17f6cdf5 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf @@ -49,6 +49,8 @@ VariableNonVolatile.h VariableParsing.c VariableParsing.h + VariableRuntimeCache.c + VariableRuntimeCache.h VarCheck.c Variable.h PrivilegePolymorphic.h diff --git a/MdeModulePkg/Include/Guid/SmmVariableCommon.h b/MdeModulePkg/I= nclude/Guid/SmmVariableCommon.h index c527a59891..ceef44dfd2 100644 --- a/MdeModulePkg/Include/Guid/SmmVariableCommon.h +++ b/MdeModulePkg/Include/Guid/SmmVariableCommon.h @@ -1,7 +1,7 @@ /** @file The file defined some common structures used for communicating between S= MM variable module and SMM variable wrapper module. =20 -Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2011 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -9,6 +9,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #ifndef _SMM_VARIABLE_COMMON_H_ #define _SMM_VARIABLE_COMMON_H_ =20 +#include #include =20 #define EFI_SMM_VARIABLE_WRITE_GUID \ @@ -66,6 +67,16 @@ typedef struct { #define SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET 10 =20 #define SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE 11 +// +// The payload for this function is SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIA= BLE_CACHE_CONTEXT +// +#define SMM_VARIABLE_FUNCTION_INIT_RUNTIME_VARIABLE_CACHE_CONTEXT 12 + +#define SMM_VARIABLE_FUNCTION_SYNC_RUNTIME_CACHE 13 +// +// The payload for this function is SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_C= ACHE_INFO +// +#define SMM_VARIABLE_FUNCTION_GET_RUNTIME_CACHE_INFO 14 =20 /// /// Size of SMM communicate header, without including the payload. @@ -120,4 +131,20 @@ typedef struct { UINTN VariablePayloadSize; } SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE; =20 +typedef struct { + BOOLEAN *ReadLock; + BOOLEAN *PendingUpdate; + BOOLEAN *HobFlushComplete; + VARIABLE_STORE_HEADER *RuntimeHobCache; + VARIABLE_STORE_HEADER *RuntimeNvCache; + VARIABLE_STORE_HEADER *RuntimeVolatileCache; +} SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT; + +typedef struct { + UINTN TotalHobStorageSize; + UINTN TotalNvStorageSize; + UINTN TotalVolatileStorageSize; + BOOLEAN AuthenticatedVariableUsage; +} SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO; + #endif // _SMM_VARIABLE_COMMON_H_ diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.h index fb574b2e32..0b2bb6ae66 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h @@ -64,6 +64,21 @@ typedef enum { VariableStoreTypeMax } VARIABLE_STORE_TYPE; =20 +typedef struct { + UINT32 PendingUpdateOffset; + UINT32 PendingUpdateLength; + VARIABLE_STORE_HEADER *Store; +} VARIABLE_RUNTIME_CACHE; + +typedef struct { + BOOLEAN *ReadLock; + BOOLEAN *PendingUpdate; + BOOLEAN *HobFlushComplete; + VARIABLE_RUNTIME_CACHE VariableRuntimeHobCache; + VARIABLE_RUNTIME_CACHE VariableRuntimeNvCache; + VARIABLE_RUNTIME_CACHE VariableRuntimeVolatileCache; +} VARIABLE_RUNTIME_CACHE_CONTEXT; + typedef struct { VARIABLE_HEADER *CurrPtr; // @@ -79,14 +94,15 @@ typedef struct { } VARIABLE_POINTER_TRACK; =20 typedef struct { - EFI_PHYSICAL_ADDRESS HobVariableBase; - EFI_PHYSICAL_ADDRESS VolatileVariableBase; - EFI_PHYSICAL_ADDRESS NonVolatileVariableBase; - EFI_LOCK VariableServicesLock; - UINT32 ReentrantState; - BOOLEAN AuthFormat; - BOOLEAN AuthSupport; - BOOLEAN EmuNvMode; + EFI_PHYSICAL_ADDRESS HobVariableBase; + EFI_PHYSICAL_ADDRESS VolatileVariableBase; + EFI_PHYSICAL_ADDRESS NonVolatileVariableBase; + VARIABLE_RUNTIME_CACHE_CONTEXT VariableRuntimeCacheContext; + EFI_LOCK VariableServicesLock; + UINT32 ReentrantState; + BOOLEAN AuthFormat; + BOOLEAN AuthSupport; + BOOLEAN EmuNvMode; } VARIABLE_GLOBAL; =20 typedef struct { diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeCach= e.h b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeCache.h new file mode 100644 index 0000000000..f9804a1d69 --- /dev/null +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeCache.h @@ -0,0 +1,51 @@ +/** @file + The common variable volatile store routines shared by the DXE_RUNTIME va= riable + module and the DXE_SMM variable module. + +Copyright (c) 2019, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef _VARIABLE_RUNTIME_CACHE_H_ +#define _VARIABLE_RUNTIME_CACHE_H_ + +#include "Variable.h" + +/** + Copies any pending updates to runtime variable caches. + + @retval EFI_UNSUPPORTED The volatile store to be updated is not = initialized properly. + @retval EFI_SUCCESS The volatile store was updated successfu= lly. + +**/ +EFI_STATUS +FlushPendingRuntimeVariableCacheUpdates ( + VOID + ); + +/** + Synchronizes the runtime variable caches with all pending updates outsid= e runtime. + + Ensures all conditions are met to maintain coherency for runtime cache u= pdates. This function will attempt + to write the given update (and any other pending updates) if the ReadLoc= k is available. Otherwise, the + update is added as a pending update for the given variable store and it = will be flushed to the runtime cache + at the next opportunity the ReadLock is available. + + @param[in] VariableRuntimeCache Variable runtime cache structure for the= runtime cache being synchronized. + @param[in] Offset Offset in bytes to apply the update. + @param[in] Length Length of data in bytes of the update. + + @retval EFI_SUCCESS The update was added as a pending update= successfully. If the variable runtime + cache ReadLock was available, the runtim= e cache was updated successfully. + @retval EFI_UNSUPPORTED The volatile store to be updated is not = initialized properly. + +**/ +EFI_STATUS +SynchronizeRuntimeVariableCache ( + IN VARIABLE_RUNTIME_CACHE *VariableRuntimeCache, + IN UINTN Offset, + IN UINTN Length + ); + +#endif diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.c index 0bd2f22e1a..29d6aca993 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -25,6 +25,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include "Variable.h" #include "VariableNonVolatile.h" #include "VariableParsing.h" +#include "VariableRuntimeCache.h" =20 VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal; =20 @@ -332,6 +333,12 @@ RecordVarErrorFlag ( // Update the data in NV cache. // *VarErrFlag =3D TempFlag; + Status =3D SynchronizeRuntimeVariableCache ( + &mVariableModuleGlobal->VariableGlobal.VariableRuntimeCa= cheContext.VariableRuntimeNvCache, + (UINTN) VarErrFlag - (UINTN) mNvVariableCache + (UINTN) = mVariableModuleGlobal->VariableGlobal.NonVolatileVariableBase, + sizeof (TempFlag) + ); + ASSERT_EFI_ERROR (Status); } } } @@ -766,12 +773,24 @@ Reclaim ( =20 Done: if (IsVolatile || mVariableModuleGlobal->VariableGlobal.EmuNvMode) { + Status =3D SynchronizeRuntimeVariableCache ( + &mVariableModuleGlobal->VariableGlobal.VariableRuntimeCach= eContext.VariableRuntimeVolatileCache, + 0, + VariableStoreHeader->Size + ); + ASSERT_EFI_ERROR (Status); FreePool (ValidBuffer); } else { // // For NV variable reclaim, we use mNvVariableCache as the buffer, so = copy the data back. // - CopyMem (mNvVariableCache, (UINT8 *)(UINTN)VariableBase, VariableStore= Header->Size); + CopyMem (mNvVariableCache, (UINT8 *) (UINTN) VariableBase, VariableSto= reHeader->Size); + Status =3D SynchronizeRuntimeVariableCache ( + &mVariableModuleGlobal->VariableGlobal.VariableRuntimeCach= eContext.VariableRuntimeNvCache, + 0, + VariableStoreHeader->Size + ); + ASSERT_EFI_ERROR (Status); } =20 return Status; @@ -1614,6 +1633,7 @@ UpdateVariable ( VARIABLE_POINTER_TRACK *Variable; VARIABLE_POINTER_TRACK NvVariable; VARIABLE_STORE_HEADER *VariableStoreHeader; + VARIABLE_RUNTIME_CACHE *VolatileCacheInstance; UINT8 *BufferForMerge; UINTN MergedBufSize; BOOLEAN DataReady; @@ -2275,6 +2295,23 @@ UpdateVariable ( } =20 Done: + if (!EFI_ERROR (Status)) { + if (Variable->Volatile) { + VolatileCacheInstance =3D &(mVariableModuleGlobal->VariableGlobal.Va= riableRuntimeCacheContext.VariableRuntimeVolatileCache); + } else { + VolatileCacheInstance =3D &(mVariableModuleGlobal->VariableGlobal.Va= riableRuntimeCacheContext.VariableRuntimeNvCache); + } + + if (VolatileCacheInstance->Store !=3D NULL) { + Status =3D SynchronizeRuntimeVariableCache ( + VolatileCacheInstance, + 0, + VolatileCacheInstance->Store->Size + ); + ASSERT_EFI_ERROR (Status); + } + } + return Status; } =20 @@ -3200,6 +3237,14 @@ FlushHobVariableToFlash ( ErrorFlag =3D TRUE; } } + if (mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.= VariableRuntimeHobCache.Store !=3D NULL) { + Status =3D SynchronizeRuntimeVariableCache ( + &mVariableModuleGlobal->VariableGlobal.VariableRuntimeCa= cheContext.VariableRuntimeHobCache, + 0, + mVariableModuleGlobal->VariableGlobal.VariableRuntimeCac= heContext.VariableRuntimeHobCache.Store->Size + ); + ASSERT_EFI_ERROR (Status); + } if (ErrorFlag) { // // We still have HOB variable(s) not flushed in flash. @@ -3210,6 +3255,9 @@ FlushHobVariableToFlash ( // All HOB variables have been flushed in flash. // DEBUG ((EFI_D_INFO, "Variable driver: all HOB variables have been fl= ushed in flash.\n")); + if (mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContex= t.HobFlushComplete !=3D NULL) { + *(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContex= t.HobFlushComplete) =3D TRUE; + } if (!AtRuntime ()) { FreePool ((VOID *) VariableStoreHeader); } diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeCach= e.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeCache.c new file mode 100644 index 0000000000..bc93cc07d2 --- /dev/null +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeCache.c @@ -0,0 +1,153 @@ +/** @file + Functions related to managing the UEFI variable runtime cache. This file= should only include functions + used by the SMM UEFI variable driver. + + Caution: This module requires additional review when modified. + This driver will have external input - variable data. They may be input = in SMM mode. + This external input must be validated carefully to avoid security issue = like + buffer overflow, integer overflow. + +Copyright (c) 2019, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "VariableParsing.h" +#include "VariableRuntimeCache.h" + +extern VARIABLE_MODULE_GLOBAL *mVariableModuleGlobal; +extern VARIABLE_STORE_HEADER *mNvVariableCache; + +/** + Copies any pending updates to runtime variable caches. + + @retval EFI_UNSUPPORTED The volatile store to be updated is not = initialized properly. + @retval EFI_SUCCESS The volatile store was updated successfu= lly. + +**/ +EFI_STATUS +FlushPendingRuntimeVariableCacheUpdates ( + VOID + ) +{ + VARIABLE_RUNTIME_CACHE_CONTEXT *VariableRuntimeCacheContext; + + VariableRuntimeCacheContext =3D &mVariableModuleGlobal->VariableGlobal.V= ariableRuntimeCacheContext; + + if (VariableRuntimeCacheContext->VariableRuntimeNvCache.Store =3D=3D NUL= L || + VariableRuntimeCacheContext->VariableRuntimeVolatileCache.Store =3D= =3D NULL || + VariableRuntimeCacheContext->PendingUpdate =3D=3D NULL) { + return EFI_UNSUPPORTED; + } + + if (*(VariableRuntimeCacheContext->PendingUpdate)) { + if (VariableRuntimeCacheContext->VariableRuntimeHobCache.Store !=3D NU= LL && + mVariableModuleGlobal->VariableGlobal.HobVariableBase > 0) { + CopyMem ( + (VOID *) ( + ((UINT8 *) (UINTN) VariableRuntimeCacheContext->VariableRuntimeH= obCache.Store) + + VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpda= teOffset + ), + (VOID *) ( + ((UINT8 *) (UINTN) mVariableModuleGlobal->VariableGlobal.HobVari= ableBase) + + VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpda= teOffset + ), + VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdate= Length + ); + VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdateLe= ngth =3D 0; + VariableRuntimeCacheContext->VariableRuntimeHobCache.PendingUpdateOf= fset =3D 0; + } + + CopyMem ( + (VOID *) ( + ((UINT8 *) (UINTN) VariableRuntimeCacheContext->VariableRuntimeNvC= ache.Store) + + VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateO= ffset + ), + (VOID *) ( + ((UINT8 *) (UINTN) mNvVariableCache) + + VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateO= ffset + ), + VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateLen= gth + ); + VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateLengt= h =3D 0; + VariableRuntimeCacheContext->VariableRuntimeNvCache.PendingUpdateOffse= t =3D 0; + + CopyMem ( + (VOID *) ( + ((UINT8 *) (UINTN) VariableRuntimeCacheContext->VariableRuntimeVol= atileCache.Store) + + VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingU= pdateOffset + ), + (VOID *) ( + ((UINT8 *) (UINTN) mVariableModuleGlobal->VariableGlobal.VolatileV= ariableBase) + + VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingU= pdateOffset + ), + VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpd= ateLength + ); + VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdat= eLength =3D 0; + VariableRuntimeCacheContext->VariableRuntimeVolatileCache.PendingUpdat= eOffset =3D 0; + *(VariableRuntimeCacheContext->PendingUpdate) =3D FALSE; + } + + return EFI_SUCCESS; +} + +/** + Synchronizes the runtime variable caches with all pending updates outsid= e runtime. + + Ensures all conditions are met to maintain coherency for runtime cache u= pdates. This function will attempt + to write the given update (and any other pending updates) if the ReadLoc= k is available. Otherwise, the + update is added as a pending update for the given variable store and it = will be flushed to the runtime cache + at the next opportunity the ReadLock is available. + + @param[in] VariableRuntimeCache Variable runtime cache structure for the= runtime cache being synchronized. + @param[in] Offset Offset in bytes to apply the update. + @param[in] Length Length of data in bytes of the update. + + @retval EFI_SUCCESS The update was added as a pending update= successfully. If the variable runtime + cache ReadLock was available, the runtim= e cache was updated successfully. + @retval EFI_UNSUPPORTED The volatile store to be updated is not = initialized properly. + +**/ +EFI_STATUS +SynchronizeRuntimeVariableCache ( + IN VARIABLE_RUNTIME_CACHE *VariableRuntimeCache, + IN UINTN Offset, + IN UINTN Length + ) +{ + if (VariableRuntimeCache =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } else if (VariableRuntimeCache->Store =3D=3D NULL) { + // The runtime cache may not be active or allocated yet. + // In either case, return EFI_SUCCESS instead of EFI_NOT_AVAILABLE_YET. + return EFI_SUCCESS; + } + + if (mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.Pe= ndingUpdate =3D=3D NULL || + mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.Re= adLock =3D=3D NULL) { + return EFI_UNSUPPORTED; + } + + if (*(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.= PendingUpdate) && + VariableRuntimeCache->PendingUpdateLength > 0) { + VariableRuntimeCache->PendingUpdateLength =3D + (UINT32) ( + MAX ( + (UINTN) (VariableRuntimeCache->PendingUpdateOffset + VariableRun= timeCache->PendingUpdateLength), + Offset + Length + ) - MIN ((UINTN) VariableRuntimeCache->PendingUpdateOffset, Offset) + ); + VariableRuntimeCache->PendingUpdateOffset =3D + (UINT32) MIN ((UINTN) VariableRuntimeCache->PendingUpdateOffset, Off= set); + } else { + VariableRuntimeCache->PendingUpdateLength =3D (UINT32) Length; + VariableRuntimeCache->PendingUpdateOffset =3D (UINT32) Offset; + } + *(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.Pend= ingUpdate) =3D TRUE; + + if (*(mVariableModuleGlobal->VariableGlobal.VariableRuntimeCacheContext.= ReadLock) =3D=3D FALSE) { + return FlushPendingRuntimeVariableCacheUpdates (); + } + + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/Mde= ModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c index 5e24bc4a62..caca5c3241 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c @@ -31,6 +31,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include "Variable.h" #include "VariableParsing.h" +#include "VariableRuntimeCache.h" + +extern VARIABLE_STORE_HEADER *mNvVariableCache; =20 BOOLEAN mAtRuntime = =3D FALSE; UINT8 *mVariableBufferPaylo= ad =3D NULL; @@ -451,25 +454,29 @@ SmmVariableGetStatistics ( EFI_STATUS EFIAPI SmmVariableHandler ( - IN EFI_HANDLE DispatchHandle, - IN CONST VOID *RegisterContext, - IN OUT VOID *CommBuffer, - IN OUT UINTN *CommBufferSize + IN EFI_HANDLE DispatchHandle, + IN CONST VOID *RegisterContext, + IN OUT VOID *CommBuffer, + IN OUT UINTN *CommBufferSize ) { - EFI_STATUS Status; - SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunctionHea= der; - SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *SmmVariableHeader; - SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *GetNextVariableName; - SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *QueryVariableInfo; - SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *GetPayloadSize; - VARIABLE_INFO_ENTRY *VariableInfo; - SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *VariableToLock; - SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *CommVariableProper= ty; - UINTN InfoSize; - UINTN NameBufferSize; - UINTN CommBufferPayloadSize; - UINTN TempCommBufferSize; + EFI_STATUS Status; + SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunc= tionHeader; + SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE *SmmVariableHead= er; + SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *GetNextVariable= Name; + SMM_VARIABLE_COMMUNICATE_QUERY_VARIABLE_INFO *QueryVariableIn= fo; + SMM_VARIABLE_COMMUNICATE_GET_PAYLOAD_SIZE *GetPayloadSize; + SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *RuntimeVariable= CacheContext; + SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO *GetRuntimeCache= Info; + SMM_VARIABLE_COMMUNICATE_LOCK_VARIABLE *VariableToLock; + SMM_VARIABLE_COMMUNICATE_VAR_CHECK_VARIABLE_PROPERTY *CommVariablePro= perty; + VARIABLE_INFO_ENTRY *VariableInfo; + VARIABLE_RUNTIME_CACHE_CONTEXT *VariableCacheCo= ntext; + VARIABLE_STORE_HEADER *VariableCache; + UINTN InfoSize; + UINTN NameBufferSize; + UINTN CommBufferPayloa= dSize; + UINTN TempCommBufferSi= ze; =20 // // If input is invalid, stop processing this SMI @@ -789,6 +796,154 @@ SmmVariableHandler ( ); CopyMem (SmmVariableFunctionHeader->Data, mVariableBufferPayload, Co= mmBufferPayloadSize); break; + case SMM_VARIABLE_FUNCTION_INIT_RUNTIME_VARIABLE_CACHE_CONTEXT: + if (CommBufferPayloadSize < sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME= _VARIABLE_CACHE_CONTEXT)) { + DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: SMM communi= cation buffer size invalid!\n")); + Status =3D EFI_ACCESS_DENIED; + goto EXIT; + } + if (mEndOfDxe) { + DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Cannot init= context after end of DXE!\n")); + Status =3D EFI_ACCESS_DENIED; + goto EXIT; + } + + // + // Copy the input communicate buffer payload to the pre-allocated SM= M variable payload buffer. + // + CopyMem (mVariableBufferPayload, SmmVariableFunctionHeader->Data, Co= mmBufferPayloadSize); + RuntimeVariableCacheContext =3D (SMM_VARIABLE_COMMUNICATE_RUNTIME_VA= RIABLE_CACHE_CONTEXT *) mVariableBufferPayload; + + // + // Verify required runtime cache buffers are provided. + // + if (RuntimeVariableCacheContext->RuntimeVolatileCache =3D=3D NULL || + RuntimeVariableCacheContext->RuntimeNvCache =3D=3D NULL || + RuntimeVariableCacheContext->PendingUpdate =3D=3D NULL || + RuntimeVariableCacheContext->ReadLock =3D=3D NULL || + RuntimeVariableCacheContext->HobFlushComplete =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Required ru= ntime cache buffer is NULL!\n")); + Status =3D EFI_ACCESS_DENIED; + goto EXIT; + } + + // + // Verify minimum size requirements for the runtime variable store b= uffers. + // + if ((RuntimeVariableCacheContext->RuntimeHobCache !=3D NULL && + RuntimeVariableCacheContext->RuntimeHobCache->Size < sizeof (VAR= IABLE_STORE_HEADER)) || + RuntimeVariableCacheContext->RuntimeVolatileCache->Size < sizeof= (VARIABLE_STORE_HEADER) || + RuntimeVariableCacheContext->RuntimeNvCache->Size < sizeof (VARI= ABLE_STORE_HEADER)) { + DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: A runtime c= ache buffer size is invalid!\n")); + Status =3D EFI_ACCESS_DENIED; + goto EXIT; + } + + // + // Verify runtime buffers do not overlap with SMRAM ranges. + // + if (RuntimeVariableCacheContext->RuntimeHobCache !=3D NULL && + !VariableSmmIsBufferOutsideSmmValid ( + (UINTN) RuntimeVariableCacheContext->RuntimeHobCache, + (UINTN) RuntimeVariableCacheContext->RuntimeHobCache->Size)) { + DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Runtime HOB= cache buffer in SMRAM or overflow!\n")); + Status =3D EFI_ACCESS_DENIED; + goto EXIT; + } + if (!VariableSmmIsBufferOutsideSmmValid ( + (UINTN) RuntimeVariableCacheContext->RuntimeVolatileCache, + (UINTN) RuntimeVariableCacheContext->RuntimeVolatileCache->Siz= e)) { + DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Runtime vol= atile cache buffer in SMRAM or overflow!\n")); + Status =3D EFI_ACCESS_DENIED; + goto EXIT; + } + if (!VariableSmmIsBufferOutsideSmmValid ( + (UINTN) RuntimeVariableCacheContext->RuntimeNvCache, + (UINTN) RuntimeVariableCacheContext->RuntimeNvCache->Size)) { + DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Runtime non= -volatile cache buffer in SMRAM or overflow!\n")); + Status =3D EFI_ACCESS_DENIED; + goto EXIT; + } + if (!VariableSmmIsBufferOutsideSmmValid ( + (UINTN) RuntimeVariableCacheContext->PendingUpdate, + sizeof (*(RuntimeVariableCacheContext->PendingUpdate)))) { + DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Runtime cac= he pending update buffer in SMRAM or overflow!\n")); + Status =3D EFI_ACCESS_DENIED; + goto EXIT; + } + if (!VariableSmmIsBufferOutsideSmmValid ( + (UINTN) RuntimeVariableCacheContext->ReadLock, + sizeof (*(RuntimeVariableCacheContext->ReadLock)))) { + DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Runtime cac= he read lock buffer in SMRAM or overflow!\n")); + Status =3D EFI_ACCESS_DENIED; + goto EXIT; + } + if (!VariableSmmIsBufferOutsideSmmValid ( + (UINTN) RuntimeVariableCacheContext->HobFlushComplete, + sizeof (*(RuntimeVariableCacheContext->HobFlushComplete)))) { + DEBUG ((DEBUG_ERROR, "InitRuntimeVariableCacheContext: Runtime cac= he HOB flush complete buffer in SMRAM or overflow!\n")); + Status =3D EFI_ACCESS_DENIED; + goto EXIT; + } + + VariableCacheContext =3D &mVariableModuleGlobal->VariableGlobal.Vari= ableRuntimeCacheContext; + VariableCacheContext->VariableRuntimeHobCache.Store =3D Runtime= VariableCacheContext->RuntimeHobCache; + VariableCacheContext->VariableRuntimeVolatileCache.Store =3D Runtime= VariableCacheContext->RuntimeVolatileCache; + VariableCacheContext->VariableRuntimeNvCache.Store =3D Runtime= VariableCacheContext->RuntimeNvCache; + VariableCacheContext->PendingUpdate =3D Runtime= VariableCacheContext->PendingUpdate; + VariableCacheContext->ReadLock =3D Runtime= VariableCacheContext->ReadLock; + VariableCacheContext->HobFlushComplete =3D Runtime= VariableCacheContext->HobFlushComplete; + + // Set up the intial pending request since the RT cache needs to be = in sync with SMM cache + VariableCacheContext->VariableRuntimeHobCache.PendingUpdateOffset = =3D 0; + VariableCacheContext->VariableRuntimeHobCache.PendingUpdateLength = =3D 0; + if (mVariableModuleGlobal->VariableGlobal.HobVariableBase > 0 && + VariableCacheContext->VariableRuntimeHobCache.Store !=3D NULL) { + VariableCache =3D (VARIABLE_STORE_HEADER *) (UINTN) mVariableModul= eGlobal->VariableGlobal.HobVariableBase; + VariableCacheContext->VariableRuntimeHobCache.PendingUpdateLength = =3D (UINT32) ((UINTN) GetEndPointer (VariableCache) - (UINTN) VariableCache= ); + CopyGuid (&(VariableCacheContext->VariableRuntimeHobCache.Store->S= ignature), &(VariableCache->Signature)); + } + VariableCache =3D (VARIABLE_STORE_HEADER *) (UINTN) mVariableModule= Global->VariableGlobal.VolatileVariableBase; + VariableCacheContext->VariableRuntimeVolatileCache.PendingUpdateOffs= et =3D 0; + VariableCacheContext->VariableRuntimeVolatileCache.PendingUpdateLeng= th =3D (UINT32) ((UINTN) GetEndPointer (VariableCache) - (UINTN) Variable= Cache); + CopyGuid (&(VariableCacheContext->VariableRuntimeVolatileCache.Store= ->Signature), &(VariableCache->Signature)); + + VariableCache =3D (VARIABLE_STORE_HEADER *) (UINTN) mNvVariableCach= e; + VariableCacheContext->VariableRuntimeNvCache.PendingUpdateOffset =3D= 0; + VariableCacheContext->VariableRuntimeNvCache.PendingUpdateLength =3D= (UINT32) ((UINTN) GetEndPointer (VariableCache) - (UINTN) VariableCache); + CopyGuid (&(VariableCacheContext->VariableRuntimeNvCache.Store->Sign= ature), &(VariableCache->Signature)); + + *(VariableCacheContext->PendingUpdate) =3D TRUE; + *(VariableCacheContext->ReadLock) =3D FALSE; + *(VariableCacheContext->HobFlushComplete) =3D FALSE; + + Status =3D EFI_SUCCESS; + break; + case SMM_VARIABLE_FUNCTION_SYNC_RUNTIME_CACHE: + Status =3D FlushPendingRuntimeVariableCacheUpdates (); + break; + case SMM_VARIABLE_FUNCTION_GET_RUNTIME_CACHE_INFO: + if (CommBufferPayloadSize < sizeof (SMM_VARIABLE_COMMUNICATE_GET_RUN= TIME_CACHE_INFO)) { + DEBUG ((DEBUG_ERROR, "GetRuntimeCacheInfo: SMM communication buffe= r size invalid!\n")); + return EFI_SUCCESS; + } + GetRuntimeCacheInfo =3D (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_= INFO *) SmmVariableFunctionHeader->Data; + + if (mVariableModuleGlobal->VariableGlobal.HobVariableBase > 0) { + VariableCache =3D (VARIABLE_STORE_HEADER *) (UINTN) mVariableModul= eGlobal->VariableGlobal.HobVariableBase; + GetRuntimeCacheInfo->TotalHobStorageSize =3D VariableCache->Size; + } else { + GetRuntimeCacheInfo->TotalHobStorageSize =3D 0; + } + + VariableCache =3D (VARIABLE_STORE_HEADER *) (UINTN) mVariableModule= Global->VariableGlobal.VolatileVariableBase; + GetRuntimeCacheInfo->TotalVolatileStorageSize =3D VariableCache->Siz= e; + VariableCache =3D (VARIABLE_STORE_HEADER *) (UINTN) mNvVariableCach= e; + GetRuntimeCacheInfo->TotalNvStorageSize =3D (UINTN) VariableCache->S= ize; + GetRuntimeCacheInfo->AuthenticatedVariableUsage =3D mVariableModuleG= lobal->VariableGlobal.AuthFormat; + + Status =3D EFI_SUCCESS; + break; =20 default: Status =3D EFI_UNSUPPORTED; diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD= xe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c index 0a1888e5ef..3dee05fded 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c @@ -13,7 +13,7 @@ =20 InitCommunicateBuffer() is really function to check the variable data si= ze. =20 -Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
+Copyright (c) 2010 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -39,6 +39,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include =20 #include "PrivilegePolymorphic.h" +#include "VariableParsing.h" =20 EFI_HANDLE mHandle =3D NULL; EFI_SMM_VARIABLE_PROTOCOL *mSmmVariable =3D NULL; @@ -46,8 +47,19 @@ EFI_EVENT mVirtualAddressChangeEv= ent =3D NULL; EFI_SMM_COMMUNICATION_PROTOCOL *mSmmCommunication =3D NULL; UINT8 *mVariableBuffer =3D NULL; UINT8 *mVariableBufferPhysical =3D NULL; +VARIABLE_INFO_ENTRY *mVariableInfo =3D NULL; +VARIABLE_STORE_HEADER *mVariableRuntimeHobCacheBuffer = =3D NULL; +VARIABLE_STORE_HEADER *mVariableRuntimeNvCacheBuffer = =3D NULL; +VARIABLE_STORE_HEADER *mVariableRuntimeVolatileCacheBuffer = =3D NULL; UINTN mVariableBufferSize; +UINTN mVariableRuntimeHobCacheBufferSize; +UINTN mVariableRuntimeNvCacheBufferSize; +UINTN mVariableRuntimeVolatileCacheBufferSize; UINTN mVariableBufferPayloadSize; +BOOLEAN mVariableRuntimeCachePendingUpdate; +BOOLEAN mVariableRuntimeCacheReadLock; +BOOLEAN mVariableAuthFormat; +BOOLEAN mHobFlushComplete; EFI_LOCK mVariableServicesLock; EDKII_VARIABLE_LOCK_PROTOCOL mVariableLock; EDKII_VAR_CHECK_PROTOCOL mVarCheck; @@ -107,6 +119,72 @@ ReleaseLockOnlyAtBootTime ( } } =20 +/** + Return TRUE if ExitBootServices () has been called. + + @retval TRUE If ExitBootServices () has been called. FALSE if ExitBootSe= rvices () has not been called. +**/ +BOOLEAN +AtRuntime ( + VOID + ) +{ + return EfiAtRuntime (); +} + +/** + Initialize the variable cache buffer as an empty variable store. + + @param[out] VariableCacheBuffer A pointer to pointer of a cache = variable store. + @param[in,out] TotalVariableCacheSize On input, the minimum size neede= d for the UEFI variable store cache + buffer that is allocated. On out= put, the actual size of the buffer allocated. + If TotalVariableCacheSize is zer= o, a buffer will not be allocated and the + function will return with EFI_SU= CCESS. + + @retval EFI_SUCCESS The variable cache was allocated and ini= tialized successfully. + @retval EFI_INVALID_PARAMETER A given pointer is NULL or an invalid va= riable store size was specified. + @retval EFI_OUT_OF_RESOURCES Insufficient resources are available to = allocate the variable store cache buffer. + +**/ +EFI_STATUS +InitVariableCache ( + OUT VARIABLE_STORE_HEADER **VariableCacheBuffer, + IN OUT UINTN *TotalVariableCacheSize + ) +{ + VARIABLE_STORE_HEADER *VariableCacheStorePtr; + + if (TotalVariableCacheSize =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + if (*TotalVariableCacheSize =3D=3D 0) { + return EFI_SUCCESS; + } + if (VariableCacheBuffer =3D=3D NULL || *TotalVariableCacheSize < sizeof = (VARIABLE_STORE_HEADER)) { + return EFI_INVALID_PARAMETER; + } + *TotalVariableCacheSize =3D ALIGN_VALUE (*TotalVariableCacheSize, sizeof= (UINT32)); + + // + // Allocate NV Storage Cache and initialize it to all 1's (like an erase= d FV) + // + *VariableCacheBuffer =3D (VARIABLE_STORE_HEADER *) AllocateRuntimePages= ( + EFI_SIZE_TO_PAGES (*TotalVariableCacheSize) + ); + if (*VariableCacheBuffer =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + VariableCacheStorePtr =3D *VariableCacheBuffer; + SetMem32 ((VOID *) VariableCacheStorePtr, *TotalVariableCacheSize, (UINT= 32) 0xFFFFFFFF); + + ZeroMem ((VOID *) VariableCacheStorePtr, sizeof (VARIABLE_STORE_HEADER)); + VariableCacheStorePtr->Size =3D (UINT32) *TotalVariableCacheSize; + VariableCacheStorePtr->Format =3D VARIABLE_STORE_FORMATTED; + VariableCacheStorePtr->State =3D VARIABLE_STORE_HEALTHY; + + return EFI_SUCCESS; +} + /** Initialize the communicate buffer using DataSize and Function. =20 @@ -425,7 +503,169 @@ Done: } =20 /** - This code finds variable in storage blocks (Volatile or Non-Volatile). + Signals SMM to synchronize any pending variable updates with the runtime= cache(s). + +**/ +VOID +SyncRuntimeCache ( + VOID + ) +{ + // + // Init the communicate buffer. The buffer data size is: + // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE. + // + InitCommunicateBuffer (NULL, 0, SMM_VARIABLE_FUNCTION_SYNC_RUNTIME_CACHE= ); + + // + // Send data to SMM. + // + SendCommunicateBuffer (0); +} + +/** + Check whether a SMI must be triggered to retrieve pending cache updates. + + If the variable HOB was finished being flushed since the last check for = a runtime cache update, this function + will prevent the HOB cache from being used for future runtime cache hits. + +**/ +VOID +CheckForRuntimeCacheSync ( + VOID + ) +{ + if (mVariableRuntimeCachePendingUpdate) { + SyncRuntimeCache (); + } + ASSERT (!mVariableRuntimeCachePendingUpdate); + + // + // The HOB variable data may have finished being flushed in the runtime = cache sync update + // + if (mHobFlushComplete && mVariableRuntimeHobCacheBuffer !=3D NULL) { + if (!EfiAtRuntime ()) { + FreePages (mVariableRuntimeHobCacheBuffer, EFI_SIZE_TO_PAGES (mVaria= bleRuntimeHobCacheBufferSize)); + } + mVariableRuntimeHobCacheBuffer =3D NULL; + } +} + +/** + Finds the given variable in a runtime cache variable store. + + Caution: This function may receive untrusted input. + The data size is external input, so this function will validate it caref= ully to avoid buffer overflow. + + @param[in] VariableName Name of Variable to be found. + @param[in] VendorGuid Variable vendor GUID. + @param[out] Attributes Attribute value of the variable found. + @param[in, out] DataSize Size of Data found. If size is less t= han the + data, this value contains the require= d size. + @param[out] Data Data pointer. + + @retval EFI_SUCCESS Found the specified variable. + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_NOT_FOUND The specified variable could not be f= ound. + +**/ +EFI_STATUS +FindVariableInRuntimeCache ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT UINT32 *Attributes OPTIONAL, + IN OUT UINTN *DataSize, + OUT VOID *Data OPTIONAL + ) +{ + EFI_STATUS Status; + UINTN TempDataSize; + VARIABLE_POINTER_TRACK RtPtrTrack; + VARIABLE_STORE_TYPE StoreType; + VARIABLE_STORE_HEADER *VariableStoreList[VariableStoreTypeMax]; + + Status =3D EFI_NOT_FOUND; + + if (VariableName =3D=3D NULL || VendorGuid =3D=3D NULL || DataSize =3D= =3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // The UEFI specification restricts Runtime Services callers from invoki= ng the same or certain other Runtime Service + // functions prior to completion and return from a previous Runtime Serv= ice call. These restrictions prevent + // a GetVariable () or GetNextVariable () call from being issued until a= prior call has returned. The runtime + // cache read lock should always be free when entering this function. + // + ASSERT (!mVariableRuntimeCacheReadLock); + + mVariableRuntimeCacheReadLock =3D TRUE; + CheckForRuntimeCacheSync (); + + if (!mVariableRuntimeCachePendingUpdate) { + // + // 0: Volatile, 1: HOB, 2: Non-Volatile. + // The index and attributes mapping must be kept in this order as Find= Variable + // makes use of this mapping to implement search algorithm. + // + VariableStoreList[VariableStoreTypeVolatile] =3D mVariableRuntimeVolat= ileCacheBuffer; + VariableStoreList[VariableStoreTypeHob] =3D mVariableRuntimeHobCa= cheBuffer; + VariableStoreList[VariableStoreTypeNv] =3D mVariableRuntimeNvCac= heBuffer; + + for (StoreType =3D (VARIABLE_STORE_TYPE) 0; StoreType < VariableStoreT= ypeMax; StoreType++) { + if (VariableStoreList[StoreType] =3D=3D NULL) { + continue; + } + + RtPtrTrack.StartPtr =3D GetStartPointer (VariableStoreList[StoreType= ]); + RtPtrTrack.EndPtr =3D GetEndPointer (VariableStoreList[StoreType= ]); + RtPtrTrack.Volatile =3D (BOOLEAN) (StoreType =3D=3D VariableStoreTyp= eVolatile); + + Status =3D FindVariableEx (VariableName, VendorGuid, FALSE, &RtPtrTr= ack, mVariableAuthFormat); + if (!EFI_ERROR (Status)) { + break; + } + } + + if (!EFI_ERROR (Status)) { + // + // Get data size + // + TempDataSize =3D DataSizeOfVariable (RtPtrTrack.CurrPtr, mVariableAu= thFormat); + ASSERT (TempDataSize !=3D 0); + + if (*DataSize >=3D TempDataSize) { + if (Data =3D=3D NULL) { + Status =3D EFI_INVALID_PARAMETER; + goto Done; + } + + CopyMem (Data, GetVariableDataPtr (RtPtrTrack.CurrPtr, mVariableAu= thFormat), TempDataSize); + if (Attributes !=3D NULL) { + *Attributes =3D RtPtrTrack.CurrPtr->Attributes; + } + + *DataSize =3D TempDataSize; + + UpdateVariableInfo (VariableName, VendorGuid, RtPtrTrack.Volatile,= TRUE, FALSE, FALSE, TRUE, &mVariableInfo); + + Status =3D EFI_SUCCESS; + goto Done; + } else { + *DataSize =3D TempDataSize; + Status =3D EFI_BUFFER_TOO_SMALL; + goto Done; + } + } + } + +Done: + mVariableRuntimeCacheReadLock =3D FALSE; + + return Status; +} + +/** + Finds the given variable in a variable store in SMM. =20 Caution: This function may receive untrusted input. The data size is external input, so this function will validate it caref= ully to avoid buffer overflow. @@ -437,20 +677,18 @@ Done: data, this value contains the require= d size. @param[out] Data Data pointer. =20 + @retval EFI_SUCCESS Found the specified variable. @retval EFI_INVALID_PARAMETER Invalid parameter. - @retval EFI_SUCCESS Find the specified variable. - @retval EFI_NOT_FOUND Not found. - @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result. + @retval EFI_NOT_FOUND The specified variable could not be f= ound. =20 **/ EFI_STATUS -EFIAPI -RuntimeServiceGetVariable ( +FindVariableInSmm ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT UINT32 *Attributes OPTIONAL, IN OUT UINTN *DataSize, - OUT VOID *Data + OUT VOID *Data OPTIONAL ) { EFI_STATUS Status; @@ -474,8 +712,6 @@ RuntimeServiceGetVariable ( return EFI_INVALID_PARAMETER; } =20 - AcquireLockOnlyAtBootTime(&mVariableServicesLock); - // // Init the communicate buffer. The buffer data size is: // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + = PayloadSize. @@ -488,7 +724,7 @@ RuntimeServiceGetVariable ( } PayloadSize =3D OFFSET_OF (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Nam= e) + VariableNameSize + TempDataSize; =20 - Status =3D InitCommunicateBuffer ((VOID **)&SmmVariableHeader, PayloadSi= ze, SMM_VARIABLE_FUNCTION_GET_VARIABLE); + Status =3D InitCommunicateBuffer ((VOID **) &SmmVariableHeader, PayloadS= ize, SMM_VARIABLE_FUNCTION_GET_VARIABLE); if (EFI_ERROR (Status)) { goto Done; } @@ -534,11 +770,58 @@ RuntimeServiceGetVariable ( } =20 Done: + return Status; +} + +/** + This code finds variable in storage blocks (Volatile or Non-Volatile). + + Caution: This function may receive untrusted input. + The data size is external input, so this function will validate it caref= ully to avoid buffer overflow. + + @param[in] VariableName Name of Variable to be found. + @param[in] VendorGuid Variable vendor GUID. + @param[out] Attributes Attribute value of the variable found. + @param[in, out] DataSize Size of Data found. If size is less t= han the + data, this value contains the require= d size. + @param[out] Data Data pointer. + + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_SUCCESS Find the specified variable. + @retval EFI_NOT_FOUND Not found. + @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result. + +**/ +EFI_STATUS +EFIAPI +RuntimeServiceGetVariable ( + IN CHAR16 *VariableName, + IN EFI_GUID *VendorGuid, + OUT UINT32 *Attributes OPTIONAL, + IN OUT UINTN *DataSize, + OUT VOID *Data + ) +{ + EFI_STATUS Status; + + if (VariableName =3D=3D NULL || VendorGuid =3D=3D NULL || DataSize =3D= =3D NULL) { + return EFI_INVALID_PARAMETER; + } + if (VariableName[0] =3D=3D 0) { + return EFI_NOT_FOUND; + } + + AcquireLockOnlyAtBootTime (&mVariableServicesLock); + if (FeaturePcdGet (PcdEnableVariableRuntimeCache)) { + Status =3D FindVariableInRuntimeCache (VariableName, VendorGuid, Attri= butes, DataSize, Data); + } else { + Status =3D FindVariableInSmm (VariableName, VendorGuid, Attributes, Da= taSize, Data); + } ReleaseLockOnlyAtBootTime (&mVariableServicesLock); + return Status; } =20 - /** This code Finds the Next available variable. =20 @@ -870,6 +1153,17 @@ OnReadyToBoot ( // SendCommunicateBuffer (0); =20 + // + // Install the system configuration table for variable info data captured + // + if (FeaturePcdGet (PcdEnableVariableRuntimeCache) && FeaturePcdGet (PcdV= ariableCollectStatistics)) { + if (mVariableAuthFormat) { + gBS->InstallConfigurationTable (&gEfiAuthenticatedVariableGuid, mVar= iableInfo); + } else { + gBS->InstallConfigurationTable (&gEfiVariableGuid, mVariableInfo); + } + } + gBS->CloseEvent (Event); } =20 @@ -893,6 +1187,9 @@ VariableAddressChangeEvent ( { EfiConvertPointer (0x0, (VOID **) &mVariableBuffer); EfiConvertPointer (0x0, (VOID **) &mSmmCommunication); + EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **) &mVariableRuntimeHobCache= Buffer); + EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **) &mVariableRuntimeNvCacheB= uffer); + EfiConvertPointer (EFI_OPTIONAL_PTR, (VOID **) &mVariableRuntimeVolatile= CacheBuffer); } =20 /** @@ -969,6 +1266,159 @@ Done: return Status; } =20 +/** + This code gets information needed from SMM for runtime cache initializat= ion. + + @param[out] TotalHobStorageSize Output pointer for the total HOB= storage size in bytes. + @param[out] TotalNvStorageSize Output pointer for the total non= -volatile storage size in bytes. + @param[out] TotalVolatileStorageSize Output pointer for the total vol= atile storage size in bytes. + @param[out] AuthenticatedVariableUsage Output pointer that indicates if= authenticated variables are to be used. + + @retval EFI_SUCCESS Retrieved the size successfully. + @retval EFI_INVALID_PARAMETER TotalNvStorageSize parameter is = NULL. + @retval EFI_OUT_OF_RESOURCES The memory resources needed for = a CommBuffer are not available. + @retval Others Could not retrieve the size succ= essfully. + +**/ +EFI_STATUS +GetRuntimeCacheInfo ( + OUT UINTN *TotalHobStorageSize, + OUT UINTN *TotalNvStorageSize, + OUT UINTN *TotalVolatileStorageSize, + OUT BOOLEAN *AuthenticatedVariableUsage + ) +{ + EFI_STATUS Status; + SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO *SmmGetRuntimeCacheI= nfo; + EFI_SMM_COMMUNICATE_HEADER *SmmCommunicateHeade= r; + SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFunction= Header; + UINTN CommSize; + UINT8 *CommBuffer; + + SmmGetRuntimeCacheInfo =3D NULL; + CommBuffer =3D mVariableBuffer; + + if (TotalHobStorageSize =3D=3D NULL || TotalNvStorageSize =3D=3D NULL ||= TotalVolatileStorageSize =3D=3D NULL || AuthenticatedVariableUsage =3D=3D = NULL) { + return EFI_INVALID_PARAMETER; + } + + if (CommBuffer =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + AcquireLockOnlyAtBootTime (&mVariableServicesLock); + + CommSize =3D SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEAD= ER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO); + ZeroMem (CommBuffer, CommSize); + + SmmCommunicateHeader =3D (EFI_SMM_COMMUNICATE_HEADER *) CommBuffer; + CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGui= d); + SmmCommunicateHeader->MessageLength =3D SMM_VARIABLE_COMMUNICATE_HEADER_= SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_INFO); + + SmmVariableFunctionHeader =3D (SMM_VARIABLE_COMMUNICATE_HEADER *) SmmCom= municateHeader->Data; + SmmVariableFunctionHeader->Function =3D SMM_VARIABLE_FUNCTION_GET_RUNTIM= E_CACHE_INFO; + SmmGetRuntimeCacheInfo =3D (SMM_VARIABLE_COMMUNICATE_GET_RUNTIME_CACHE_I= NFO *) SmmVariableFunctionHeader->Data; + + // + // Send data to SMM. + // + Status =3D mSmmCommunication->Communicate (mSmmCommunication, CommBuffer= , &CommSize); + ASSERT_EFI_ERROR (Status); + if (CommSize <=3D SMM_VARIABLE_COMMUNICATE_HEADER_SIZE) { + Status =3D EFI_BAD_BUFFER_SIZE; + goto Done; + } + + Status =3D SmmVariableFunctionHeader->ReturnStatus; + if (EFI_ERROR (Status)) { + goto Done; + } + + // + // Get data from SMM. + // + *TotalHobStorageSize =3D SmmGetRuntimeCacheInfo->TotalHobStorageSize; + *TotalNvStorageSize =3D SmmGetRuntimeCacheInfo->TotalNvStorageSize; + *TotalVolatileStorageSize =3D SmmGetRuntimeCacheInfo->TotalVolatileStora= geSize; + *AuthenticatedVariableUsage =3D SmmGetRuntimeCacheInfo->AuthenticatedVar= iableUsage; + +Done: + ReleaseLockOnlyAtBootTime (&mVariableServicesLock); + return Status; +} + +/** + Sends the runtime variable cache context information to SMM. + + @retval EFI_SUCCESS Retrieved the size successfully. + @retval EFI_INVALID_PARAMETER TotalNvStorageSize parameter is NULL. + @retval EFI_OUT_OF_RESOURCES The memory resources needed for a Comm= Buffer are not available. + @retval Others Could not retrieve the size successful= ly.; + +**/ +EFI_STATUS +SendRuntimeVariableCacheContextToSmm ( + VOID + ) +{ + EFI_STATUS Status; + SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT *SmmRuntimeVar= CacheContext; + EFI_SMM_COMMUNICATE_HEADER *SmmCommunicat= eHeader; + SMM_VARIABLE_COMMUNICATE_HEADER *SmmVariableFu= nctionHeader; + UINTN CommSize; + UINT8 *CommBuffer; + + SmmRuntimeVarCacheContext =3D NULL; + CommBuffer =3D mVariableBuffer; + + if (CommBuffer =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + AcquireLockOnlyAtBootTime (&mVariableServicesLock); + + // + // Init the communicate buffer. The buffer data size is: + // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + = sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT); + // + CommSize =3D SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEAD= ER_SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT); + ZeroMem (CommBuffer, CommSize); + + SmmCommunicateHeader =3D (EFI_SMM_COMMUNICATE_HEADER *) CommBuffer; + CopyGuid (&SmmCommunicateHeader->HeaderGuid, &gEfiSmmVariableProtocolGui= d); + SmmCommunicateHeader->MessageLength =3D SMM_VARIABLE_COMMUNICATE_HEADER_= SIZE + sizeof (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE_CACHE_CONTEXT); + + SmmVariableFunctionHeader =3D (SMM_VARIABLE_COMMUNICATE_HEADER *) SmmCom= municateHeader->Data; + SmmVariableFunctionHeader->Function =3D SMM_VARIABLE_FUNCTION_INIT_RUNTI= ME_VARIABLE_CACHE_CONTEXT; + SmmRuntimeVarCacheContext =3D (SMM_VARIABLE_COMMUNICATE_RUNTIME_VARIABLE= _CACHE_CONTEXT *) SmmVariableFunctionHeader->Data; + + SmmRuntimeVarCacheContext->RuntimeHobCache =3D mVariableRuntimeHobCacheB= uffer; + SmmRuntimeVarCacheContext->RuntimeVolatileCache =3D mVariableRuntimeVola= tileCacheBuffer; + SmmRuntimeVarCacheContext->RuntimeNvCache =3D mVariableRuntimeNvCacheBuf= fer; + SmmRuntimeVarCacheContext->PendingUpdate =3D &mVariableRuntimeCachePendi= ngUpdate; + SmmRuntimeVarCacheContext->ReadLock =3D &mVariableRuntimeCacheReadLock; + SmmRuntimeVarCacheContext->HobFlushComplete =3D &mHobFlushComplete; + + // + // Send data to SMM. + // + Status =3D mSmmCommunication->Communicate (mSmmCommunication, CommBuffer= , &CommSize); + ASSERT_EFI_ERROR (Status); + if (CommSize <=3D SMM_VARIABLE_COMMUNICATE_HEADER_SIZE) { + Status =3D EFI_BAD_BUFFER_SIZE; + goto Done; + } + + Status =3D SmmVariableFunctionHeader->ReturnStatus; + if (EFI_ERROR (Status)) { + goto Done; + } + +Done: + ReleaseLockOnlyAtBootTime (&mVariableServicesLock); + return Status; +} + /** Initialize variable service and install Variable Architectural protocol. =20 @@ -985,7 +1435,7 @@ SmmVariableReady ( { EFI_STATUS Status; =20 - Status =3D gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOI= D **)&mSmmVariable); + Status =3D gBS->LocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOI= D **) &mSmmVariable); if (EFI_ERROR (Status)) { return; } @@ -1007,6 +1457,42 @@ SmmVariableReady ( // mVariableBufferPhysical =3D mVariableBuffer; =20 + if (FeaturePcdGet (PcdEnableVariableRuntimeCache)) { + DEBUG ((DEBUG_INFO, "Variable driver runtime cache is enabled.\n")); + // + // Allocate runtime variable cache memory buffers. + // + Status =3D GetRuntimeCacheInfo ( + &mVariableRuntimeHobCacheBufferSize, + &mVariableRuntimeNvCacheBufferSize, + &mVariableRuntimeVolatileCacheBufferSize, + &mVariableAuthFormat + ); + if (!EFI_ERROR (Status)) { + Status =3D InitVariableCache (&mVariableRuntimeHobCacheBuffer, &mVar= iableRuntimeHobCacheBufferSize); + if (!EFI_ERROR (Status)) { + Status =3D InitVariableCache (&mVariableRuntimeNvCacheBuffer, &mVa= riableRuntimeNvCacheBufferSize); + if (!EFI_ERROR (Status)) { + Status =3D InitVariableCache (&mVariableRuntimeVolatileCacheBuff= er, &mVariableRuntimeVolatileCacheBufferSize); + if (!EFI_ERROR (Status)) { + Status =3D SendRuntimeVariableCacheContextToSmm (); + if (!EFI_ERROR (Status)) { + SyncRuntimeCache (); + } + } + } + } + if (EFI_ERROR (Status)) { + mVariableRuntimeHobCacheBuffer =3D NULL; + mVariableRuntimeNvCacheBuffer =3D NULL; + mVariableRuntimeVolatileCacheBuffer =3D NULL; + } + } + ASSERT_EFI_ERROR (Status); + } else { + DEBUG ((DEBUG_INFO, "Variable driver runtime cache is disabled.\n")); + } + gRT->GetVariable =3D RuntimeServiceGetVariable; gRT->GetNextVariableName =3D RuntimeServiceGetNextVariableName; gRT->SetVariable =3D RuntimeServiceSetVariable; --=20 2.16.2.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 (#49728): https://edk2.groups.io/g/devel/message/49728 Mute This Topic: https://groups.io/mt/40103026/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- From nobody Wed Apr 24 23:27:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49729+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49729+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1572504365; cv=none; d=zoho.com; s=zohoarc; b=CTCTTFXBihmgNol547V3TJHCS+xwEFQiF/KVUGOvQVVdEc0v/4vd/v7b2Uk0ZtNzLHf6ZOoGI66/CsqgXoxog+au7swh6frdMK9KarazKc3DiK66R3U+8gZWKctGYCyZuLvLZC+8aZ+3DBcgLyo2utk/oTcLcJNdh9Oyca//nW0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572504365; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=asWMURgfQ4xaaN+R5RDOT0o9obpRBtgI4azWjMwt9EM=; b=EH2Ns8BdalNSHrnNm+/IA2BoXfcjzwNLoSGJweavMyQ86NJBl5Ufabdx48J/Bl0fTbXM5OOeTWUxWk09Bh2+VMCVHWY+CGYa8qMritX8KXMmIAM0SeIUbCAQiL5fB/915N7rr94IRGWhUTVGCojkBMWpbdtDQTNYoHQ0Nf6kRII= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49729+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1572504365117256.53940052674716; Wed, 30 Oct 2019 23:46:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uADZYY1788612xjqDTxMyyhr; Wed, 30 Oct 2019 23:46:04 -0700 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web11.2637.1572504363643893802 for ; Wed, 30 Oct 2019 23:46:03 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 23:46:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,250,1569308400"; d="scan'208";a="351547503" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga004.jf.intel.com with ESMTP; 30 Oct 2019 23:46:03 -0700 From: "Kubacki, Michael A" To: devel@edk2.groups.io Cc: Dandan Bi , Ard Biesheuvel , Eric Dong , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu , Jiewen Yao Subject: [edk2-devel] [PATCH V6 08/10] MdeModulePkg/Variable: Add RT GetNextVariableName() cache support Date: Wed, 30 Oct 2019 23:45:08 -0700 Message-Id: <20191031064510.23948-9-michael.a.kubacki@intel.com> In-Reply-To: <20191031064510.23948-1-michael.a.kubacki@intel.com> References: <20191031064510.23948-1-michael.a.kubacki@intel.com> Precedence: Bulk List-Unsubscribe: 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,michael.a.kubacki@intel.com X-Gm-Message-State: 8dH4thAMvKqn5owCWsLhhBFZx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572504364; bh=jjfYTat4bvoRWvPfo26mclMHCIPQbVp5im4s8e3SkBc=; h=Cc:Date:From:Reply-To:Subject:To; b=ehvAO6LIrcWKE7RqWQHM6MxDKNwOTJr+KbDsRj4DOd7eZVAXhdfk6AQy76/eZaqeX7X mIiIwWGgVJpdkTeQUIUgcHvRxIyLdr+ru1sXWBB2f24E3DTTmN+zDdqH8rQGBe+qqX6Os cZ9/m+C8O8WQdYIE1LOJwKY1T6SFbMa0Q+E= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" https://bugzilla.tianocore.org/show_bug.cgi?id=3D2220 This change implements the Runtime Service GetNextVariableName() using the runtime cache in VariableSmmRuntimeDxe. Runtime Service calls to GetNextVariableName() will no longer trigger a SW SMI when gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache is set to TRUE (default value). Overall system performance and stability will be improved by eliminating an SMI for these calls as they typically result in a relatively large number of invocations to retrieve all variable names in all variable stores present. Cc: Dandan Bi Cc: Ard Biesheuvel Cc: Eric Dong Cc: Laszlo Ersek Cc: Liming Gao Cc: Michael D Kinney Cc: Ray Ni Cc: Jian J Wang Cc: Hao A Wu Cc: Jiewen Yao Signed-off-by: Michael Kubacki Reviewed-by: Jian J Wang --- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c | 137 += +++++++++++++++++-- 1 file changed, 128 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD= xe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c index 3dee05fded..d525998ae3 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c @@ -823,7 +823,7 @@ RuntimeServiceGetVariable ( } =20 /** - This code Finds the Next available variable. + Finds the next available variable in a runtime cache variable store. =20 @param[in, out] VariableNameSize Size of the variable name. @param[in, out] VariableName Pointer to variable name. @@ -836,8 +836,81 @@ RuntimeServiceGetVariable ( =20 **/ EFI_STATUS -EFIAPI -RuntimeServiceGetNextVariableName ( +GetNextVariableNameInRuntimeCache ( + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VendorGuid + ) +{ + EFI_STATUS Status; + UINTN VarNameSize; + VARIABLE_HEADER *VariablePtr; + VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax]; + + Status =3D EFI_NOT_FOUND; + + // + // The UEFI specification restricts Runtime Services callers from invoki= ng the same or certain other Runtime Service + // functions prior to completion and return from a previous Runtime Serv= ice call. These restrictions prevent + // a GetVariable () or GetNextVariable () call from being issued until a= prior call has returned. The runtime + // cache read lock should always be free when entering this function. + // + ASSERT (!mVariableRuntimeCacheReadLock); + + CheckForRuntimeCacheSync (); + + mVariableRuntimeCacheReadLock =3D TRUE; + if (!mVariableRuntimeCachePendingUpdate) { + // + // 0: Volatile, 1: HOB, 2: Non-Volatile. + // The index and attributes mapping must be kept in this order as Find= Variable + // makes use of this mapping to implement search algorithm. + // + VariableStoreHeader[VariableStoreTypeVolatile] =3D mVariableRuntimeVol= atileCacheBuffer; + VariableStoreHeader[VariableStoreTypeHob] =3D mVariableRuntimeHob= CacheBuffer; + VariableStoreHeader[VariableStoreTypeNv] =3D mVariableRuntimeNvC= acheBuffer; + + Status =3D VariableServiceGetNextVariableInternal ( + VariableName, + VendorGuid, + VariableStoreHeader, + &VariablePtr, + mVariableAuthFormat + ); + if (!EFI_ERROR (Status)) { + VarNameSize =3D NameSizeOfVariable (VariablePtr, mVariableAuthFormat= ); + ASSERT (VarNameSize !=3D 0); + if (VarNameSize <=3D *VariableNameSize) { + CopyMem (VariableName, GetVariableNamePtr (VariablePtr, mVariableA= uthFormat), VarNameSize); + CopyMem (VendorGuid, GetVendorGuidPtr (VariablePtr, mVariableAuthF= ormat), sizeof (EFI_GUID)); + Status =3D EFI_SUCCESS; + } else { + Status =3D EFI_BUFFER_TOO_SMALL; + } + + *VariableNameSize =3D VarNameSize; + } + } + mVariableRuntimeCacheReadLock =3D FALSE; + + return Status; +} + +/** + Finds the next available variable in a SMM variable store. + + @param[in, out] VariableNameSize Size of the variable name. + @param[in, out] VariableName Pointer to variable name. + @param[in, out] VendorGuid Variable Vendor Guid. + + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_SUCCESS Find the specified variable. + @retval EFI_NOT_FOUND Not found. + @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result. + +**/ +EFI_STATUS +GetNextVariableNameInSmm ( IN OUT UINTN *VariableNameSize, IN OUT CHAR16 *VariableName, IN OUT EFI_GUID *VendorGuid @@ -849,10 +922,6 @@ RuntimeServiceGetNextVariableName ( UINTN OutVariableNameSize; UINTN InVariableNameSize; =20 - if (VariableNameSize =3D=3D NULL || VariableName =3D=3D NULL || VendorGu= id =3D=3D NULL) { - return EFI_INVALID_PARAMETER; - } - OutVariableNameSize =3D *VariableNameSize; InVariableNameSize =3D StrSize (VariableName); SmmGetNextVariableName =3D NULL; @@ -864,8 +933,6 @@ RuntimeServiceGetNextVariableName ( return EFI_INVALID_PARAMETER; } =20 - AcquireLockOnlyAtBootTime(&mVariableServicesLock); - // // Init the communicate buffer. The buffer data size is: // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + = PayloadSize. @@ -924,7 +991,59 @@ RuntimeServiceGetNextVariableName ( CopyMem (VariableName, SmmGetNextVariableName->Name, SmmGetNextVariableN= ame->NameSize); =20 Done: + return Status; +} + +/** + This code Finds the Next available variable. + + @param[in, out] VariableNameSize Size of the variable name. + @param[in, out] VariableName Pointer to variable name. + @param[in, out] VendorGuid Variable Vendor Guid. + + @retval EFI_INVALID_PARAMETER Invalid parameter. + @retval EFI_SUCCESS Find the specified variable. + @retval EFI_NOT_FOUND Not found. + @retval EFI_BUFFER_TO_SMALL DataSize is too small for the result. + +**/ +EFI_STATUS +EFIAPI +RuntimeServiceGetNextVariableName ( + IN OUT UINTN *VariableNameSize, + IN OUT CHAR16 *VariableName, + IN OUT EFI_GUID *VendorGuid + ) +{ + EFI_STATUS Status; + UINTN MaxLen; + + Status =3D EFI_NOT_FOUND; + + if (VariableNameSize =3D=3D NULL || VariableName =3D=3D NULL || VendorGu= id =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Calculate the possible maximum length of name string, including the N= ull terminator. + // + MaxLen =3D *VariableNameSize / sizeof (CHAR16); + if ((MaxLen =3D=3D 0) || (StrnLenS (VariableName, MaxLen) =3D=3D MaxLen)= ) { + // + // Null-terminator is not found in the first VariableNameSize bytes of= the input VariableName buffer, + // follow spec to return EFI_INVALID_PARAMETER. + // + return EFI_INVALID_PARAMETER; + } + + AcquireLockOnlyAtBootTime (&mVariableServicesLock); + if (FeaturePcdGet (PcdEnableVariableRuntimeCache)) { + Status =3D GetNextVariableNameInRuntimeCache (VariableNameSize, Variab= leName, VendorGuid); + } else { + Status =3D GetNextVariableNameInSmm (VariableNameSize, VariableName, V= endorGuid); + } ReleaseLockOnlyAtBootTime (&mVariableServicesLock); + return Status; } =20 --=20 2.16.2.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 (#49729): https://edk2.groups.io/g/devel/message/49729 Mute This Topic: https://groups.io/mt/40103029/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- From nobody Wed Apr 24 23:27:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49730+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49730+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1572504369; cv=none; d=zoho.com; s=zohoarc; b=UpabdxPGTAUspg6Knh/gOFaSIrNTCoiBUwZ8eUyxFggc8CFZYuwaEku8PbqEcB1HqPCB+Mc2rYNIp0V62ZI18wDqFK0X/Inh7Xfm95qwiuAZan5dr+irGPHpte7jdv+ProCn2sxAnZg64mw4DxHvSeBZaE2NzY0mjURsiFwfyRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572504369; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=Lp3YkUIHevr3s08elj3SCJ0hBtRkqz0z321A3DfUtiE=; b=DD1JZ4URW+EkXma7LMcvBv551awEf6LsaVv/GosfIPvZUa8yB20i5HGTY79LbYiVCHsxY4xBjhtfPalilaMenEcob7PRBSMnydsTrD52Iyp+I1MLSvkEDqfITiMwXZ0HAyW+gwrxuqrJuL/ZixXAStUDxoojvAZO7259AYp2GkY= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49730+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1572504369391141.24821755545395; Wed, 30 Oct 2019 23:46:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3UBVYY1788612xPY7GYriPks; Wed, 30 Oct 2019 23:46:08 -0700 X-Received: from mga01.intel.com (mga01.intel.com []) by mx.groups.io with SMTP id smtpd.web11.2637.1572504363643893802 for ; Wed, 30 Oct 2019 23:46:08 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 23:46:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,250,1569308400"; d="scan'208";a="351547517" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga004.jf.intel.com with ESMTP; 30 Oct 2019 23:46:08 -0700 From: "Kubacki, Michael A" To: devel@edk2.groups.io Cc: Ard Biesheuvel , Laszlo Ersek , Liming Gao , Jordan Justen , Hao A Wu Subject: [edk2-devel] [PATCH V6 09/10] OvmfPkg: Disable variable runtime cache Date: Wed, 30 Oct 2019 23:45:09 -0700 Message-Id: <20191031064510.23948-10-michael.a.kubacki@intel.com> In-Reply-To: <20191031064510.23948-1-michael.a.kubacki@intel.com> References: <20191031064510.23948-1-michael.a.kubacki@intel.com> Precedence: Bulk List-Unsubscribe: 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,michael.a.kubacki@intel.com X-Gm-Message-State: pQBX4xPgqfoC3tAxvt5zEPYXx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572504368; bh=TcZGoqVSQnY54M0z+eQOS5eXVLnjZN67GoMAYmH8Krg=; h=Cc:Date:From:Reply-To:Subject:To; b=Xj3eLABV8PMoqomydjGLhMFjHj1DSAxsAMdZcHPUPFWstOJQ2g30KvolJaYS7p9EUHi rsyIjiv5a+gu/xIUJ2uLwa8W30UdZyroMt9YQCx9kclREHsaIb2T2uPNW6DXnnkoI8j/D 1uif3kxV4eBq9AVJeOjZWxo/F226RlQeZWE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Sets gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache to FALSE in OvmfPkgIa32.dsc, OvmfPkgIa32X64.dsc, and OvmfPkgX64.dsc so that when SMM_REQUIRE is TRUE, the SMM variable driver will not use the runtime variable cache. This is done for OvmfPkg because it currently depends upon a SMM variable GetVariable ()implementation as a simple method to exercise the SMM driver stack. This allows the following commands to be used for variables such as Boot####, BootOrder, and BootNext to test SMM timing and stability differences on the BSP (e.g. CPU#0) vs an AP (e.g. CPU#1). # taskset -c 0 efibootmgr # taskset -c 1 efibootmgr Cc: Ard Biesheuvel Cc: Laszlo Ersek Cc: Liming Gao Cc: Jordan Justen Cc: Hao A Wu Signed-off-by: Michael Kubacki Reviewed-by: Jian J Wang --- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + 3 files changed, 3 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 05bb6ae136..d350b75630 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -431,6 +431,7 @@ !if $(SMM_REQUIRE) =3D=3D TRUE gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire|TRUE gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmEnableBspElection|FALSE + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache|FALSE !endif =20 [PcdsFixedAtBuild] diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 4a75a0332e..1ef82cafe4 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -436,6 +436,7 @@ !if $(SMM_REQUIRE) =3D=3D TRUE gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire|TRUE gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmEnableBspElection|FALSE + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache|FALSE !endif =20 [PcdsFixedAtBuild] diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index ed54181180..232815c08e 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -436,6 +436,7 @@ !if $(SMM_REQUIRE) =3D=3D TRUE gUefiOvmfPkgTokenSpaceGuid.PcdSmmSmramRequire|TRUE gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmEnableBspElection|FALSE + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache|FALSE !endif =20 [PcdsFixedAtBuild] --=20 2.16.2.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 (#49730): https://edk2.groups.io/g/devel/message/49730 Mute This Topic: https://groups.io/mt/40103030/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- From nobody Wed Apr 24 23:27:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49731+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49731+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1572504374; cv=none; d=zoho.com; s=zohoarc; b=aKRpB+3mp+mScBEUrVM2BU0YHCCTcrVnY+KAeQclNMZuX89VsgIE0kuj/F3RnT+oTHezT+P/8evmheA91YbcB9OJ6QaVGgxRGn2VHKSjXpxQy4EYNfLxQfkAJLIQXGGCLACktfhsYRUtUG9ETPtUaPQ22xL8uwf01e78lY8c1wk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1572504374; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=pwlBsLmILuYfkhL9m0Ah2bHUqiGqIYp6rW8iMEbR4BM=; b=dSgO60AX32XP0uDyLFa8hCVnwKBNv/RpJq4XiP4pDL1sedAF5o9bDy96+7q9NB1xI7BO3EtKG15+FN/wxW++6Rie8uNHHkmqFQ9yVRNwG2af19iEp1O0+337hBvFCdt4zgIjp2HZ/Ac9JlwjoOEwoFY/ZjK3isN5iOt7q/qv/24= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49731+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1572504374351729.7056557479002; Wed, 30 Oct 2019 23:46:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id pyVTYY1788612xj2DKWwwpwu; Wed, 30 Oct 2019 23:46:13 -0700 X-Received: from mga01.intel.com (mga01.intel.com []) by mx.groups.io with SMTP id smtpd.web11.2637.1572504363643893802 for ; Wed, 30 Oct 2019 23:46:13 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 30 Oct 2019 23:46:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,250,1569308400"; d="scan'208";a="351547530" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga004.jf.intel.com with ESMTP; 30 Oct 2019 23:46:13 -0700 From: "Kubacki, Michael A" To: devel@edk2.groups.io Cc: Dandan Bi , Ard Biesheuvel , Eric Dong , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu , Jiewen Yao Subject: [edk2-devel] [PATCH V6 10/10] MdeModulePkg: Enable variable runtime cache by default Date: Wed, 30 Oct 2019 23:45:10 -0700 Message-Id: <20191031064510.23948-11-michael.a.kubacki@intel.com> In-Reply-To: <20191031064510.23948-1-michael.a.kubacki@intel.com> References: <20191031064510.23948-1-michael.a.kubacki@intel.com> Precedence: Bulk List-Unsubscribe: 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,michael.a.kubacki@intel.com X-Gm-Message-State: JX9IbdgJdHbPoeuP7A5rRjDIx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1572504373; bh=fe8Xix3sZ0eQwLNSC+HxIf361sbGI7vmkXEf9t7uXr4=; h=Cc:Date:From:Reply-To:Subject:To; b=P2EJ4OpXxX96t3x8uANaZLlYkxk2+rZgZ+6D5q6+AdePWz9Ri8AVZT1TL3YVxmOdqml s2Bw2ogLQG+ok57Wi5iVTxGDLzml5wj+BKzZQxGCc9vv/yLwqeseSscj0hu1LknLO5K8l KHpuEy94ggYzl4MfAP80DMTbtmM0nYKR9AY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This change enables the variable runtime cache by default by setting gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache in MdeModulePkg.dec to TRUE. Cc: Dandan Bi Cc: Ard Biesheuvel Cc: Eric Dong Cc: Laszlo Ersek Cc: Liming Gao Cc: Michael D Kinney Cc: Ray Ni Cc: Jian J Wang Cc: Hao A Wu Cc: Jiewen Yao Signed-off-by: Michael Kubacki Reviewed-by: Jian J Wang --- MdeModulePkg/MdeModulePkg.dec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 3ef8fe7644..1e964f5903 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -651,7 +651,7 @@ # TRUE - The UEFI variable runtime cache is enabled.
# FALSE - The UEFI variable runtime cache is disabled.
# @Prompt Enable the UEFI variable runtime cache. - gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache|FALSE|BOOLE= AN|0x00010039 + gEfiMdeModulePkgTokenSpaceGuid.PcdEnableVariableRuntimeCache|TRUE|BOOLEA= N|0x00010039 =20 ## Indicates if the statistics about variable usage will be collected. T= his information is # stored as a vendor configuration table into the EFI system table. --=20 2.16.2.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 (#49731): https://edk2.groups.io/g/devel/message/49731 Mute This Topic: https://groups.io/mt/40103035/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-