From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@apple.com header.s=20180706 header.b=t/l2QIYi; spf=pass (domain: apple.com, ip: 17.151.62.67, mailfrom: afish@apple.com) Received: from nwk-aaemail-lapp02.apple.com (nwk-aaemail-lapp02.apple.com [17.151.62.67]) by groups.io with SMTP; Thu, 03 Oct 2019 11:59:39 -0700 Received: from pps.filterd (nwk-aaemail-lapp02.apple.com [127.0.0.1]) by nwk-aaemail-lapp02.apple.com (8.16.0.27/8.16.0.27) with SMTP id x93IqJiR045645; Thu, 3 Oct 2019 11:59:36 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=sender : from : message-id : content-type : mime-version : subject : date : in-reply-to : cc : to : references; s=20180706; bh=fVmvGjVpStO1kXf14Webt2qGT/R8a+23XPs5FDuHXXE=; b=t/l2QIYiDjJtJE1rqu1xMZSbNkOmoAArhlOS+rHoEkv2AqOw4a6fBFt2faxSyjzeRo3A nMcIC1Kg7Rv4sTkZGM4wrjbvrCLlWGXIkpASSJzft4QbdqMhkm6BV3GRZKNm/yCr4e9s ifq3oW31vzSeQzkMc+CT4dRSlw3qDiEDtz3CR37K+5ig6XXJFvWEK1r2kYAesuyvI6j9 DewajV86ZYSUJ9kn1zm4zB/cMOqHv8QnHdznUTaaVpw+5sArE7M369wbDAVHFvZIKmND eof175le7vsy6FBC9tblN5hDuzcafk06DBRzFW6izEF1tFtswG+oklFWAR97C6pdCijx FA== Received: from ma1-mtap-s01.corp.apple.com (ma1-mtap-s01.corp.apple.com [17.40.76.5]) by nwk-aaemail-lapp02.apple.com with ESMTP id 2va43k136g-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Thu, 03 Oct 2019 11:59:36 -0700 Received: from nwk-mmpp-sz09.apple.com (nwk-mmpp-sz09.apple.com [17.128.115.80]) by ma1-mtap-s01.corp.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPS id <0PYT00IICBF9E280@ma1-mtap-s01.corp.apple.com>; Thu, 03 Oct 2019 11:59:35 -0700 (PDT) Received: from process_milters-daemon.nwk-mmpp-sz09.apple.com by nwk-mmpp-sz09.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) id <0PYT00A00BEEI600@nwk-mmpp-sz09.apple.com>; Thu, 03 Oct 2019 11:59:34 -0700 (PDT) X-Va-CD: 0 X-Va-ID: 98e937ba-5b56-4fa0-abbf-33bec4918322 X-V-A: X-V-T-CD: f0178fbe912c7da515175cdd596b2d6a X-V-E-CD: b4ab379426ec148898566e8352fdac12 X-V-R-CD: 442ac31e367a8798a3985b5265ec060b X-V-CD: 0 X-V-ID: d3d06195-fe5a-4a63-8e5c-7cbd18d8d5a5 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-03_07:,, signatures=0 Received: from [17.103.11.227] (unknown [17.103.11.227]) by nwk-mmpp-sz09.apple.com (Oracle Communications Messaging Server 8.0.2.4.20190507 64bit (built May 7 2019)) with ESMTPSA id <0PYT00MH8BF73O70@nwk-mmpp-sz09.apple.com>; Thu, 03 Oct 2019 11:59:33 -0700 (PDT) Sender: afish@apple.com From: "Andrew Fish" Message-id: MIME-version: 1.0 (Mac OS X Mail 13.0 \(3594.4.17\)) Subject: Re: [edk2-devel] [PATCH V2 8/9] MdeModulePkg/Variable: Add RT GetNextVariableName() cache support Date: Thu, 03 Oct 2019 13:59:30 -0500 In-reply-to: Cc: "Wu, Hao A" , "Bi, Dandan" , Ard Biesheuvel , "Dong, Eric" , Laszlo Ersek , "Gao, Liming" , Mike Kinney , "Ni, Ray" , "Wang, Jian J" , "Yao, Jiewen" To: devel@edk2.groups.io, michael.a.kubacki@intel.com References: <20190928014717.31372-1-michael.a.kubacki@intel.com> <20190928014717.31372-9-michael.a.kubacki@intel.com> X-Mailer: Apple Mail (2.3594.4.17) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-10-03_07:,, signatures=0 Content-type: multipart/alternative; boundary="Apple-Mail=_E4722BA3-7A7D-4FCE-AA56-79865C172DA4" --Apple-Mail=_E4722BA3-7A7D-4FCE-AA56-79865C172DA4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Oct 3, 2019, at 1:52 PM, Kubacki, Michael A wrote: >=20 >>> -Done: >>> + mVariableRuntimeCacheReadLock =3D FALSE; >>=20 >>=20 >> Similar to the previous patch (7/9), >> if timeout occurs when acquiring the read lock, should this flag be set= to >> FALSE in such case? >>=20 >=20 > Given that the runtime service can be invoked in a multi-threaded OS env= ironment, > it is possible that one thread could be stuck with the lock while anothe= r thread times > out waiting to acquire the lock. In that case, I believe the global lock= should not be > released. I can move setting the flag to FALSE within the same condition= al block in > which it is set. >=20 UEFI Spec sets the rules is 8.1 ... All callers of Runtime Services are restricted from calling the same or ce= rtain other Runtime Service functions prior to the completion and return of= a previous Runtime Service call. These restrictions apply to: =E2=80=A2 Runtime Services that have been interrupted =E2=80=A2 Runtime Services that are active on another processor. Callers are prohibited from using certain other services from another proc= essor or on the same processor following an interrupt as specified in Table= 35. For this table =E2=80=98Busy=E2=80=99 is defined as the state when a R= untime Service has been entered and has not returned to the caller. The consequence of a caller violating these restrictions is undefined exce= pt for certain special cases described below. Table 35 variable info: If previous call is busy in: GetVariable() GetNextVariableName() SetVariable() QueryVariableInfo() Upda= teCapsule() QueryCapsuleCapabilities() GetNextHighMonotonicCount() Forbidden to call: GetVariable(), GetNextVariableName(), SetVariable(), QueryVariableInfo(), = UpdateCapsule(), QueryCapsuleCapabilities(), GetNextHighMonotonicCount() Thanks, Andrew Fish > Thanks, > Michael >=20 >> -----Original Message----- >> From: Wu, Hao A > >> Sent: Thursday, October 3, 2019 1:05 AM >> To: Kubacki, Michael A >; >> devel@edk2.groups.io >> Cc: Bi, Dandan >; Ard = Biesheuvel >> >; Dong, E= ric >; Laszlo Ersek >> >; Gao, Liming >; Kinney, Michael >> D >; Ni,= Ray >; Wang, Jian J >> >; Yao, Jiewen > >> Subject: RE: [PATCH V2 8/9] MdeModulePkg/Variable: Add RT >> GetNextVariableName() cache support >>=20 >>> -----Original Message----- >>> From: Kubacki, Michael A >>> Sent: Saturday, September 28, 2019 9:47 AM >>> To: devel@edk2.groups.io >>> Cc: Bi, Dandan; Ard Biesheuvel; Dong, Eric; Laszlo Ersek; Gao, Liming; >>> Kinney, Michael D; Ni, Ray; Wang, Jian J; Wu, Hao A; Yao, Jiewen >>> Subject: [PATCH V2 8/9] MdeModulePkg/Variable: Add RT >>> GetNextVariableName() cache support >>>=20 >>> https://bugzilla.tianocore.org/show_bug.cgi?id=3D2220 >>>=20 >>> 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. >>>=20 >>> 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. >>>=20 >>> 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 >>> --- >>>=20 >>>=20 >> MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe >>> .c | 118 +++++++++----------- >>> 1 file changed, 50 insertions(+), 68 deletions(-) >>>=20 >>> diff --git >>>=20 >> a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD >>> xe.c >>>=20 >> b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD >>> xe.c >>> index 46f69765a4..bc3b56b0ce 100644 >>> --- >>>=20 >> a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD >>> xe.c >>> +++ >>>=20 >> b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD >>> xe.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 || Vend= orGuid >>> =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 >>> Null terminator. >>> // >>> - if (InVariableNameSize > mVariableBufferPayloadSize - OFFSET_OF >>> (SMM_VARIABLE_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_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)) >> { >>> - // >>> - // If output buffer exceed SMM payload limit. Trim output buffer = to >> SMM >>> payload size >>> - // >>> - OutVariableNameSize =3D mVariableBufferPayloadSize - OFFSET_OF >>> (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name); >>> + for (DelayIndex =3D 0; mVariableRuntimeCacheReadLock && DelayIndex = < >>> VARIABLE_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_NAME, Name) >> + MAX >>> (OutVariableNameSize, InVariableNameSize); >>> - >>> - Status =3D InitCommunicateBuffer ((VOID >> **)&SmmGetNextVariableName, >>> PayloadSize, 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 >>> FindVariable >>> + // makes use of this mapping to implement search algorithm. >>> + // >>> + VariableStoreHeader[VariableStoreTypeVolatile] =3D >>> mVariableRuntimeVolatileCacheBuffer; >>> + VariableStoreHeader[VariableStoreTypeHob] =3D >>> mVariableRuntimeHobCacheBuffer; >>> + VariableStoreHeader[VariableStoreTypeNv] =3D >>> mVariableRuntimeNvCacheBuffer; >>> + >>> + Status =3D GetNextVariableEx (VariableName, VendorGuid, >>> VariableStoreHeader, &VariablePtr); >>> + if (!EFI_ERROR (Status)) { >>> + VarNameSize =3D NameSizeOfVariable (VariablePtr); >>> + ASSERT (VarNameSize !=3D 0); >>> + if (VarNameSize <=3D *VariableNameSize) { >>> + CopyMem (VariableName, GetVariableNamePtr (VariablePtr), >>> VarNameSize); >>> + 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, >>> SmmGetNextVariableName->NameSize); >>> - >>> -Done: >>> + mVariableRuntimeCacheReadLock =3D FALSE; >>=20 >>=20 >> Similar to the previous patch (7/9), >> if timeout occurs when acquiring the read lock, should this flag be set= to >> FALSE in such case? >>=20 >> Best Regards, >> Hao Wu >>=20 >>=20 >>> ReleaseLockOnlyAtBootTime (&mVariableServicesLock); >>> return Status; >>> } >>> -- >>> 2.16.2.windows.1 >>=20 >=20 >=20 >=20 --Apple-Mail=_E4722BA3-7A7D-4FCE-AA56-79865C172DA4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On Oct 3, 20= 19, at 1:52 PM, Kubacki, Michael A <michael.a.kubacki@intel.com> wrote:

-Done:
+  mVariableRunt= imeCacheReadLock =3D FALSE;


Similar to the previous patch (7/9),
if timeout occ= urs when acquiring the read lock, should this flag be set to
= FALSE in such case?


Given that the runtime service can be invo= ked in a multi-threaded OS environment,
it is possible that one thread could be stuck with the loc= k while another thread times
<= span style=3D"caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size:= 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; = letter-spacing: normal; text-align: start; text-indent: 0px; text-transform= : none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: = 0px; text-decoration: none; float: none; display: inline !important;" class= = =3D"">out waiting to acquire the lock. In that case, I believe the global = lock should not be
rel= eased. I can move setting the flag to FALSE within the same conditional blo= ck in
which it is set.<= /span>


UEFI Spec sets t= he rules is 8.1 ...

All callers of= Runtime Services are restricted from calling the same or certain other Run= time Service functions prior to the completion and return of a previous Run= time Service call. These restrictions apply to:
=E2=80=A2 Runtime= Services that have been interrupted
=E2=80=A2 Runtime Services t= hat are active on another processor.
Callers are prohibited from = using certain other services from another processor or on the same processo= r following an interrupt as specified in Table 35. For this table =E2=80=98= Busy=E2=80=99 is defined as the state when a Runtime Service has been enter= ed and has not returned to the caller.
The consequence of a calle= r violating these restrictions is undefined except for certain special case= s described below.

Table 35 variable in= fo:
If previous call is busy in:
GetVariable() GetNextV= ariableName() SetVariable() QueryVariableInfo() UpdateCapsule() QueryCapsul= eCapabilities() GetNextHighMonotonicCount()

=
Forbidden to call:
GetVariable(), GetNextVariableName(), Set= Variable(), QueryVariableInfo(), UpdateCapsule(), QueryCapsuleCapabilities(= ), GetNextHighMonotonicCount()

Th= anks,

Andrew Fish

<= blockquote type=3D"cite" class=3D"">
Thanks,Michael

-----Original Message-----
From: Wu, Hao A <hao.a.wu@intel.com>
Sent: Thursday, October 3, 2019 1:05 AM
To: Kubacki,= Michael A <mi= chael.a.kubacki@intel.com>;
devel@edk2.groups.io
Cc: Bi, Dan= dan <dandan.bi@intel.c= om>; Ard Biesheuvel
<ard.biesheuvel@linaro.org>; Dong, Eric <= ;eric.dong@intel.com&= gt;; Laszlo Ersek
<lersek@redhat.com>; Gao, Liming <liming.gao@intel.com>; Kinney, MichaelD <michael.d.kinney@intel.com>; Ni, Ray <ray.ni@intel.com>; Wang, Jian J
&= lt;jian.j.wang@intel.co= m>; Yao, Jiewen <jiewen.yao@intel.com>
Subject: RE: [PATCH V2 8/9] M= deModulePkg/Variable: Add RT
GetNextVariableName() cache supp= ort

-----= Original Message-----
From: Kubacki, Michael A
= Sent: Saturday, September 28, 2019 9:47 AM
To: devel@edk2.groups.io
Cc: Bi, Dandan; Ard Biesheuvel; Dong, Eric; Laszlo Ersek; Gao, Liming;
Kinney, Michael D; Ni, Ray; Wang, Jian J; Wu, Hao A; Yao, Jiewen=
Subject: [PATCH V2 8/9] MdeModulePkg/Variable: Add RT
GetNextVariableName() cache support

= https://bugzilla.tianocore.org/show_bug.cgi?id=3D2220
This change implements the Runtime Service GetNextVariableName(= )
using
the Runtime Cache in VariableSmmRuntimeDxe. Runtime Service call= s to
GetNextVariableName() will no longer trigger a SW SMI.
Overall system performance and stability will b= e improved by
eliminating an SMI for these calls as they typi= cally result in a
relatively large number of invocations to r= etrieve all variable names
in all variable stores present.
Cc: Dandan Bi <dandan.bi@intel.com>
Cc: Ard Biesh= euvel <ard.biesh= euvel@linaro.org>
Cc: Eric Dong <eric.dong@intel.com>
C= c: Laszlo Ersek <lersek@= redhat.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: = Michael D Kinney <michael.d.kinney@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Michael Ku= backi <michael= .a.kubacki@intel.com>
---


MdeModulePkg/Universal/Variable/RuntimeDxe/Var= iableSmmRuntimeDxe
.c | = 118 +++++++++-----------
1 file changed, 50 insertions(+), 68= deletions(-)

diff --git

a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableS= mmRuntimeD
xe.c

b/MdeModulePkg/Universal/Variable/Runtim= eDxe/VariableSmmRuntimeD
xe.c
index 46f69765a4..bc3b56b0ce 100644
---
a/MdeModulePkg/Universal/Variable/= RuntimeDxe/VariableSmmRuntimeD
xe.c
+++

b/M= deModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD
xe.c
@@ -799,87 +799,69= @@ RuntimeServiceGetNextVariableName (
  IN OUT &n= bsp;EFI_GUID           &n= bsp;            = ;  *VendorGuid
  )
{
-  EFI_STATUS         =             &nb= sp;            =     Status;
-  UINTN   &nb= sp;            =             &nb= sp;            =   PayloadSize;
-  SMM_VARIABLE_COMMUNICATE_GET= _NEXT_VARIABLE_NAME
*SmmGetNextVariableName;
- =  UINTN           &nb= sp;            =             &nb= sp;      OutVariableNameSize;
-=  UINTN           &n= bsp;            = ;            &n= bsp;      InVariableNameSize;
+=  EFI_STATUS          &nb= sp;   Status;
+  UINTN    =             &nb= sp;  DelayIndex;
+  UINTN    &n= bsp;            = ;  MaxLen;
+  UINTN     &n= bsp;            = ; VarNameSize;
+  VARIABLE_HEADER    = ;     *VariablePtr;
+  VARIABLE= _STORE_HEADER
*VariableStoreHeader[VariableStoreTypeMax];
+
+  Status =3D EFI_NOT_FOUND;
=
  if (VariableNameSize =3D=3D NULL || VariableName= =3D=3D NULL || VendorGuid
=3D=3D
NULL) {
    return EFI_INVALID_PARAMETER;
  }

-  OutVariableNameSize &n= bsp; =3D *VariableNameSize;
-  InVariableNameSize &= nbsp;  =3D StrSize (VariableName);
-  SmmGetNe= xtVariableName =3D NULL;
-
  //
-  // If input string exceeds SMM payload limit. Return failu= re
+  // Calculate the possible maximum length of name s= tring, including
+ the
Null terminator.
  //
-  if (InVariableNameSize > mVa= riableBufferPayloadSize - OFFSET_OF
(SMM_VARIABLE_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 Va= riableName buffer,
+    // follow spec to retu= rn EFI_INVALID_PARAMETER.
+    //
    return EFI_INVALID_PARAMETER;
 = ; }

-  AcquireLockOnlyAtBootTime(&am= p;mVariableServicesLock);
+  AcquireLockOnlyAtBootTime (= &mVariableServicesLock);

-  //
-  // Init the communicate buffer. The buffer data size is:-  // SMM_COMMUNICATE_HEADER_SIZE +
SMM_VARI= ABLE_COMMUNICATE_HEADER_SIZE + PayloadSize.
-  //
-  if (OutVariableNameSize > mVariableBufferPayloadSize - O= FFSET_OF
(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Na= me))
{
-    //
-    // If ou= tput buffer exceed SMM payload limit. Trim output buffer to
<= /blockquote>SMM
payload = size
-    //
-    = ;OutVariableNameSize =3D mVariableBufferPayloadSize - OFFSET_OF
(SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name);
+=  for (DelayIndex =3D 0; mVariableRuntimeCacheReadLock && Dela= yIndex <
VARIABLE_RT_CACHE_READ_LOCK_TIMEOUT; DelayIndex++= ) {
+    MicroSecondDelay (10);
=   }
-  //
-  // Payload sho= uld be Guid + NameSize + MAX of Input & Output buffer
- &= nbsp;//
-  PayloadSize =3D OFFSET_OF
(SMM_= VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME, Name)
+ MAX
(OutVariableNam= eSize, InVariableNameSize);
-
-  Status = =3D InitCommunicateBuffer ((VOID
**)&SmmGet= NextVariableName,
Payloa= dSize, 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 (&= amp;SmmGetNextVariableName->Guid, VendorGuid);
-  //<= br class=3D"">-  // Copy whole string
-  //
-  CopyMem (SmmGetNextVariableName->Name, VariableName,
InVariableNameSize);
-  if (OutVariableNameSiz= e > InVariableNameSize) {
-    ZeroMem ((UI= NT8 *) SmmGetNextVariableName->Name +
InVariableNameSize, = OutVariableNameSize - InVariableNameSize);
-  }
-
-  //
-  // Send data to SMM=
-  //
-  Status =3D SendCommunicateB= uffer (PayloadSize);
-
-  //
-  // Get data from SMM.
-  //
- &nb= sp;if (Status =3D=3D EFI_SUCCESS || Status =3D=3D EFI_BUFFER_TOO_SMALL) {-    //
-    // SM= M CommBuffer NameSize can be a trimed value
-   &nb= sp;// Only update VariableNameSize when needed
-   =  //
-    *VariableNameSize =3D SmmGetNext= VariableName->NameSize;
-  }
-  if= (EFI_ERROR (Status)) {
-    goto Done;
+  if (DelayIndex < VARIABLE_RT_CACHE_READ_LOCK_TIMEOUT) {<= br class=3D"">+    ASSERT (!mVariableRuntimeCacheReadLock);<= br class=3D"">+
+    CheckForRuntimeCacheSync = ();
+    mVariableRuntimeCacheReadLock =3D TRU= E;
+
+    if (!mVariableRuntimeC= achePendingUpdate) {
+      //
+      // 0: Volatile, 1: HOB, 2: Non-Vol= atile.
+      // The index and attri= butes mapping must be kept in this order
+ as
F= indVariable
+      // makes use of t= his mapping to implement search algorithm.
+   &nbs= p;  //
+      VariableStor= eHeader[VariableStoreTypeVolatile] =3D
mVariableRuntimeVolati= leCacheBuffer;
+      VariableStoreH= eader[VariableStoreTypeHob]      =3D
mVariableRuntimeHobCacheBuffer;
+     &n= bsp;VariableStoreHeader[VariableStoreTypeNv]      =  =3D
mVariableRuntimeNvCacheBuffer;
+
+      Status =3D GetNextVariableEx (Var= iableName, VendorGuid,
VariableStoreHeader, &VariablePtr)= ;
+      if (!EFI_ERROR (Status)) {<= br class=3D"">+        VarNameSize =3D N= ameSizeOfVariable (VariablePtr);
+     &n= bsp;  ASSERT (VarNameSize !=3D 0);
+   &n= bsp;    if (VarNameSize <=3D *VariableNameSize) {+          CopyMem= (VariableName, GetVariableNamePtr (VariablePtr),
VarNameSize= );
+          Co= pyMem (VendorGuid, GetVendorGuidPtr (VariablePtr), sizeof
(EF= I_GUID));
+         &= nbsp;Status =3D EFI_SUCCESS;
+      =   } else {
+       &n= bsp;  Status =3D EFI_BUFFER_TOO_SMALL;
+  &nbs= p;     }
+
+  &nb= sp;     *VariableNameSize =3D VarNameSize;
+      }
+    = }
  }
-
-  CopyGui= d (VendorGuid, &SmmGetNextVariableName->Guid);
-  = ;CopyMem (VariableName, SmmGetNextVariableName->Name,
SmmG= etNextVariableName->NameSize);
-
-Done:
+  mVariableRuntimeCacheReadLock =3D FALSE;


Similar to the previous patch (7/9= ),
if timeout occurs when acquiring the read lock, should thi= s flag be set to
FALSE in such case?

Best Regards,
Hao Wu


  ReleaseLockOnly= AtBootTime (&mVariableServicesLock);
  return S= tatus;
}
--
2.16.2.windows.1



<= /blockquote>
--Apple-Mail=_E4722BA3-7A7D-4FCE-AA56-79865C172DA4--