From nobody Mon Feb 9 06:00:41 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+48074+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+48074+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1569473481; cv=none; d=zoho.com; s=zohoarc; b=bC5B4E0jxh0I3u9J0sffY2cVI63I5hnO56cIOsd62f7VSScw6IO7Foxh0KtYCEFFZhzt7k/CjSkGZ1EcXoel00iNVC6SyuGiNh9dOXy+YGEsgYBsTbOzwh4WJv8ZS+Uqlh7yf9OFrnYgmd3dYeiNvW1EPct/FG9Y46CeU3Pd/4c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569473481; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To:ARC-Authentication-Results; bh=SIr/FNzAbGcrN9pXHTKIVX/PfrUVJV2yOr5osXqtxCI=; b=mi80dAJkpTDowDmEGC0jMixkBFGWte3/vW2tTJY44KwgRV/Ao+ba9QdW9UH3+MSVK3WMy1xIDcF8L2ISPPxDuo0Sg5mslKmqAICfpjW+EziQCgz++aa4/RTbTc5fECxLV7cdqu51iQibRpt43pKgugIrBXxCC277mdBH82ma72E= 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+48074+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 1569473481601571.1859237331364; Wed, 25 Sep 2019 21:51:21 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FBP7YY1788612xrSRntSGKkB; Wed, 25 Sep 2019 21:51:21 -0700 X-Received: from mga02.intel.com (mga02.intel.com []) by groups.io with SMTP; Wed, 25 Sep 2019 21:51:20 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Sep 2019 21:51:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,550,1559545200"; d="scan'208";a="191570772" X-Received: from makuback-desk1.amr.corp.intel.com ([10.7.159.162]) by orsmga003.jf.intel.com with ESMTP; 25 Sep 2019 21:51:20 -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 V1 4/5] MdeModulePkg/Variable: Add RT GetNextVariableName() cache support Date: Wed, 25 Sep 2019 21:50:45 -0700 Message-Id: <20190926045046.34592-5-michael.a.kubacki@intel.com> In-Reply-To: <20190926045046.34592-1-michael.a.kubacki@intel.com> References: <20190926045046.34592-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: lFNSGgvtjR5Hsxm4hXzLm4lvx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1569473481; bh=EKST+rymNFCytl0Bhk98i0lRJ0UDV90fdsJSY1NIY3U=; h=Cc:Date:From:Reply-To:Subject:To; b=UOPn+I7wPw9uIUnvReVoW3Is3NUUstbimPMzVbODui/qvy7uJyXH28FPGX24bOaAif0 gOv37OscCjWZiUbGMQ2F0SgGgaM0p8OoxBrtIf72hUGIH+rVRDRuaR/UreJVheYLS3I3B HNVrEUiy9N4lZOLT7S2PIIBeRp1i3QtYESY= 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. 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 --- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c | 118 += ++++++++----------- 1 file changed, 50 insertions(+), 68 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD= xe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c index 237908e5a2..ff3c390a7d 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c @@ -799,87 +799,69 @@ RuntimeServiceGetNextVariableName ( IN OUT EFI_GUID *VendorGuid ) { - EFI_STATUS Status; - UINTN PayloadSize; - SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME *SmmGetNextVariableName; - UINTN OutVariableNameSize; - UINTN InVariableNameSize; + EFI_STATUS Status; + UINTN DelayIndex; + UINTN MaxLen; + UINTN VarNameSize; + VARIABLE_HEADER *VariablePtr; + VARIABLE_STORE_HEADER *VariableStoreHeader[VariableStoreTypeMax]; + + Status =3D EFI_NOT_FOUND; =20 if (VariableNameSize =3D=3D NULL || VariableName =3D=3D NULL || VendorGu= id =3D=3D NULL) { return EFI_INVALID_PARAMETER; } =20 - OutVariableNameSize =3D *VariableNameSize; - InVariableNameSize =3D StrSize (VariableName); - SmmGetNextVariableName =3D NULL; - // - // If input string exceeds SMM payload limit. Return failure + // Calculate the possible maximum length of name string, including the N= ull terminator. // - if (InVariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VAR= IABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) { + 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; } =20 - AcquireLockOnlyAtBootTime(&mVariableServicesLock); + AcquireLockOnlyAtBootTime (&mVariableServicesLock); =20 - // - // Init the communicate buffer. The buffer data size is: - // SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE + = PayloadSize. - // - if (OutVariableNameSize > mVariableBufferPayloadSize - OFFSET_OF (SMM_VA= RIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) { - // - // If output buffer exceed SMM payload limit. Trim output buffer to SM= M payload size - // - OutVariableNameSize =3D mVariableBufferPayloadSize - OFFSET_OF (SMM_VA= RIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name); + for (DelayIndex =3D 0; mVariableRuntimeCacheReadLock && DelayIndex < VAR= IABLE_RT_CACHE_READ_LOCK_TIMEOUT; DelayIndex++) { + MicroSecondDelay (10); } - // - // Payload should be Guid + NameSize + MAX of Input & Output buffer - // - PayloadSize =3D OFFSET_OF (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NA= ME, Name) + MAX (OutVariableNameSize, InVariableNameSize); - - Status =3D InitCommunicateBuffer ((VOID **)&SmmGetNextVariableName, Payl= oadSize, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME); - if (EFI_ERROR (Status)) { - goto Done; - } - ASSERT (SmmGetNextVariableName !=3D NULL); - - // - // SMM comm buffer->NameSize is buffer size for return string - // - SmmGetNextVariableName->NameSize =3D OutVariableNameSize; - - CopyGuid (&SmmGetNextVariableName->Guid, VendorGuid); - // - // Copy whole string - // - CopyMem (SmmGetNextVariableName->Name, VariableName, InVariableNameSize); - if (OutVariableNameSize > InVariableNameSize) { - ZeroMem ((UINT8 *) SmmGetNextVariableName->Name + InVariableNameSize, = OutVariableNameSize - InVariableNameSize); - } - - // - // Send data to SMM - // - Status =3D SendCommunicateBuffer (PayloadSize); - - // - // Get data from SMM. - // - if (Status =3D=3D EFI_SUCCESS || Status =3D=3D EFI_BUFFER_TOO_SMALL) { - // - // SMM CommBuffer NameSize can be a trimed value - // Only update VariableNameSize when needed - // - *VariableNameSize =3D SmmGetNextVariableName->NameSize; - } - if (EFI_ERROR (Status)) { - goto Done; + if (DelayIndex < VARIABLE_RT_CACHE_READ_LOCK_TIMEOUT) { + 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 Fi= ndVariable + // makes use of this mapping to implement search algorithm. + // + VariableStoreHeader[VariableStoreTypeVolatile] =3D mVariableRuntimeV= olatileCacheBuffer; + VariableStoreHeader[VariableStoreTypeHob] =3D mVariableRuntimeH= obCacheBuffer; + VariableStoreHeader[VariableStoreTypeNv] =3D mVariableRuntimeN= vCacheBuffer; + + Status =3D GetNextVariableEx (VariableName, VendorGuid, VariableStor= eHeader, &VariablePtr); + if (!EFI_ERROR (Status)) { + VarNameSize =3D NameSizeOfVariable (VariablePtr); + ASSERT (VarNameSize !=3D 0); + if (VarNameSize <=3D *VariableNameSize) { + CopyMem (VariableName, GetVariableNamePtr (VariablePtr), VarName= Size); + CopyMem (VendorGuid, GetVendorGuidPtr (VariablePtr), sizeof (EFI= _GUID)); + Status =3D EFI_SUCCESS; + } else { + Status =3D EFI_BUFFER_TOO_SMALL; + } + + *VariableNameSize =3D VarNameSize; + } + } } - - CopyGuid (VendorGuid, &SmmGetNextVariableName->Guid); - CopyMem (VariableName, SmmGetNextVariableName->Name, SmmGetNextVariableN= ame->NameSize); - -Done: + mVariableRuntimeCacheReadLock =3D FALSE; ReleaseLockOnlyAtBootTime (&mVariableServicesLock); return Status; } --=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 (#48074): https://edk2.groups.io/g/devel/message/48074 Mute This Topic: https://groups.io/mt/34295312/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-