From nobody Mon Feb 9 04:44:33 2026 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+48946+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+48946+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1571095845; cv=none; d=zoho.com; s=zohoarc; b=OfQ2gi4OkLPd0wVJDtxAAoW/g4mK01pJnbSbrgdh8FUINbvwhwuDFiKmoH/DnQWCsIaJYvSHdg2E7ZfuIENHuT66ySd6ZwX6fRVp9y2hBT1wDX0QAO+56pcO15j1bHgMgamybd3FfbJy3dRHWVJckslQtOoR7XfsNK76RvO4B/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571095845; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=IJlk5hY11V/aDZxDm2KQQtDQbT4zcCeMyoQVQ0SkiYs=; b=ldhdloa9+sz5HeNPhXq44yHZWTu7M6XHTVkcbVYrz1QI2EsTGwboDusCv9dXndbGWDz27GyLj9F2gnQoSysMgfy1eeUQBlJH7OZDUfxXmE3Lwc12lh4NW7RF2ptZZVNY09X+SbCMU8nygSN/bVqCSeJnlbrWrV382v6OQU9R8f4= 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+48946+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 1571095845287593.9519474560605; Mon, 14 Oct 2019 16:30:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id XG3LYY1788612xynTI9WkQCR; Mon, 14 Oct 2019 16:30:44 -0700 X-Received: from mga01.intel.com (mga01.intel.com []) by mx.groups.io with SMTP id smtpd.web11.1608.1571095843297982931 for ; Mon, 14 Oct 2019 16:30:44 -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; 14 Oct 2019 16:30:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,296,1566889200"; d="scan'208";a="346902643" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga004.jf.intel.com with ESMTP; 14 Oct 2019 16:30:34 -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 V4 08/10] MdeModulePkg/Variable: Add RT GetNextVariableName() cache support Date: Mon, 14 Oct 2019 16:29:59 -0700 Message-Id: <20191014233001.33024-9-michael.a.kubacki@intel.com> In-Reply-To: <20191014233001.33024-1-michael.a.kubacki@intel.com> References: <20191014233001.33024-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: CluzKnnv8iXtqcHEFgVhqZJxx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1571095844; bh=8b1XvMaHw7AFzWwO9Xwvah1Pv7qauReCrEXvQfFMU/4=; h=Cc:Date:From:Reply-To:Subject:To; b=slyfQ/8IXlymznBIW9FEYATFOsmRal21cHO3ClHpK0z0s0tlPiTTfbOEg/LAJyNn8yh 1WpsmnlAedL0oSCK/P2hcFkpJ7x5ElgwroTnsxULPG3cwsPqJzV9JA3gWNNWAFOlVUvTa lHp0Lzds9okFsdXZ8QRdrGMCKUvmWVQulqg= 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: Hao A Wu --- 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 e236ddff33..a795b9fcab 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 (#48946): https://edk2.groups.io/g/devel/message/48946 Mute This Topic: https://groups.io/mt/34540093/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-