From nobody Sat May 18 23:15:03 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95164+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95164+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1665712656; cv=none; d=zohomail.com; s=zohoarc; b=lvGFn2kqk0W4DrhNcpMcC15T6FJRHIYuykST3P3eyJRkZCIfF4kQ7Xcwr8b9NXFXld2VcQj5k4rEqZQS17RSQDEBZBtxWJ74N5GvCa7MdX3d8Q+VSgeMUztb1QAT2nUAzker7RqKPlURNtRMSyugxsOE4UfbKSZwKiDr68H4LDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1665712656; h=Content-Type:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=p2p55RHX2lqJqZ2NIJbyq5JKGlyiJaXz+QBx5BQjEJQ=; b=SV7RgvOfcMqlTYiqFuWRKAvksP36hGX0KI4e1pHAJZ5K/hczmFlAyqzUJF8ai4TeQh0lXB+4B6++3uPhCuyd0HoLf2g4PMI8y8pFv/4lcxxnUHBlWUGRtXlY31wNbhA6/ChLTVhibGWPegKXMCY/ug+YGvYfXz1v65R3KXrcF3c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95164+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1665712656127600.0429206410212; Thu, 13 Oct 2022 18:57:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id KMVcYY1788612xaycQHCZqbM; Thu, 13 Oct 2022 18:57:35 -0700 X-Received: from walk.intel-email.com (walk.intel-email.com [101.227.64.242]) by mx.groups.io with SMTP id smtpd.web10.2677.1665712652674160632 for ; Thu, 13 Oct 2022 18:57:33 -0700 X-Received: from walk.intel-email.com (localhost [127.0.0.1]) by walk.intel-email.com (Postfix) with ESMTP id E3543CD1F7CA for ; Fri, 14 Oct 2022 09:57:27 +0800 (CST) X-Received: from localhost (localhost [127.0.0.1]) by walk.intel-email.com (Postfix) with ESMTP id DE54BCD1F7A3 for ; Fri, 14 Oct 2022 09:57:27 +0800 (CST) X-Received: from walk.intel-email.com (localhost [127.0.0.1]) by walk.intel-email.com (Postfix) with ESMTP id 900F5CD1F770 for ; Fri, 14 Oct 2022 09:57:27 +0800 (CST) X-Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by walk.intel-email.com (Postfix) with SMTP id 57B99CD1F7CA for ; Fri, 14 Oct 2022 09:57:24 +0800 (CST) X-Received: from DESKTOPS6D0PVI ([101.86.146.168]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Fri, 14 Oct 2022 09:57:21 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-Originating-IP: 101.86.146.168 X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming via groups.io" To: "'Jiading Zhang'" , References: <01df01d8dc49$1a7b2130$4f716390$@byosoft.com.cn> <28563.1665390985077437700@groups.io> In-Reply-To: <28563.1665390985077437700@groups.io> Subject: =?UTF-8?B?5Zue5aSNOiBbZWRrMi1kZXZlbF0g5Zue5aSNOiBbZWRrMi1kZXZlbF0g5Zue5aSNOiBbZWRrMi1kZXZlbF0gW1BBVENIXSBNZGVNb2R1bGVQa2cgVmFyaWFibGVQZWk6IEFkZCBWYXJpYWJsZSBzdGF0ZSBjaGVjayB3aGVuIGZpbmQgdmFyaWFibGUgaW4gSW5kZXhUYWJsZS4=?= Date: Fri, 14 Oct 2022 09:57:23 +0800 Message-ID: <03d301d8df70$4d789930$e869cb90$@byosoft.com.cn> MIME-Version: 1.0 Thread-Index: AQHz7EQdTw8ELNXB3a6vENYUgVlYsgN4UiSUrbtDR0A= Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gaoliming@byosoft.com.cn X-Gm-Message-State: xv5YJHt5Ruvi0xtpDXdjKrNax1787277AA= Content-Type: multipart/alternative; boundary="----=_NextPart_000_03D4_01D8DFB3.5B9D86E0" Content-Language: zh-cn DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1665712655; bh=Uv5HSoAWMi41YRdzTCcN22i0PrLg4WekX1tlZa2YfJU=; h=Content-Type:Date:From:Reply-To:Subject:To; b=LwYSFwImE4IDdBHxOKqzu3/WVsaihdTaF67TXgKtIEDxqWuv1HlIwFoNvzxJb5QLiYh 6Y2u5S1jxP5SrEBrZK6q2n2dRsRzASjlKlrDLVf4QeOh6PD09jwYulXuGgU/ZzwSti2Qj Ww14mZpW4DiJNjQm+cURXvBqsFW0OBzADAI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1665712658280100001 ------=_NextPart_000_03D4_01D8DFB3.5B9D86E0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Jiading: HOB is created in volatile memory (cache or physical memory). And, HOB is = re-created for every boot (normal boot, S3 boot). When the first call GetVa= riable, gEfiVariableIndexTableGuid guid hob should not exist. If this guid = hob exits, it should be created by other module. Please check.=20 =20 Thanks Liming =E5=8F=91=E4=BB=B6=E4=BA=BA: Jiading Zhang =20 =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2022=E5=B9=B410=E6=9C=8810=E6=97=A5 1= 6:36 =E6=94=B6=E4=BB=B6=E4=BA=BA: gaoliming ; devel@ed= k2.groups.io =E4=B8=BB=E9=A2=98: Re: [edk2-devel] =E5=9B=9E=E5=A4=8D: [edk2-devel] =E5= =9B=9E=E5=A4=8D: [edk2-devel] [PATCH] MdeModulePkg VariablePei: Add Variabl= e state check when find variable in IndexTable. =20 Hi liming: I checked the code, and found the root cause of the issue. As the following code in edk2, in my code, after the first time to = read the variable in PEI phase, it cached the variable store info IndexTa= ble into a Hob in a special non-volatile memory, but after the code runni= ng in dxe phase, the variable was changed. And after a warm reboot, maybe = call s3 sleep is more exactly, when read the variable, it first get the In= dexTable from the Hob but not build the IndexTable again, so it read the de= leted variable if hasn't the condition check. This is really a special cas= e. GuidHob =3D GetFirstGuidHob (&gEfiVariableIndexTableGuid); if (GuidHob !=3D NULL) { StoreInfo->IndexTable =3D GET_GUID_HOB_DATA (GuidHob); } else { // // If it's the first time to access variable region in flash, cre= ate a guid hob to record // VAR_ADDED type variable info. // Note that as the resource of PEI phase is limited, only store = the limited number of // VAR_ADDED type variables to reduce access time. // StoreInfo->IndexTable =3D (VARIABLE_INDEX_TABLE *) BuildGuidHob (= &gEfiVariableIndexTableGuid, sizeof (VARIABLE_INDEX_TABLE)); StoreInfo->IndexTable->Length =3D 0; StoreInfo->IndexTable->StartPtr =3D GetStartPointer (VariableS= toreHeader); StoreInfo->IndexTable->EndPtr =3D GetEndPointer (VariableS= toreHeader); StoreInfo->IndexTable->GoneThrough =3D 0; } =20 On Mon, Oct 10, 2022 at 09:39 AM, gaoliming wrote: Jiading:=20 Please check why NV variable data is required to be changed in PEI phase.= This will be helpful for this issue. =20 Thanks Liming =E5=8F=91=E4=BB=B6=E4=BA=BA: Jiading Zhang >=20 =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2022=E5=B9=B410=E6=9C=8810=E6=97=A5 8= :35 =E6=94=B6=E4=BB=B6=E4=BA=BA: gaoliming >; devel@edk2.groups.io =20 =E4=B8=BB=E9=A2=98: Re: [edk2-devel] =E5=9B=9E=E5=A4=8D: [edk2-devel] [PATC= H] MdeModulePkg VariablePei: Add Variable state check when find variable in= IndexTable. =20 Hi liming: Yes, NV Variable Data is not changed in PEI phase in normal case. This i= ssue was found when we did a special coding, and when found variable in the= IndexTable, it found the variable before the last changed if didn't add t= he following condition: "if ((VariableHeader->State =3D=3D VAR_ADDED) || (VariableHeader->State = =3D=3D (VAR_IN_DELETED_TRANSITION & VAR_ADDED)))" Maybe our specail coding had some defect=EF=BC=8Cand caused this issue. On Fri, Sep 30, 2022 at 10:46 AM, gaoliming wrote: Jiading: Hob Variable Store Info IndexTable is NULL. So, this logic doesn=E2=80=99t= work for HOB variable store. NV Variable Store Info has IndexTable. When i= ts IndexTable is initialized, its IndexTable will only record the variable = with VAR_ADDED attribute. Because NV Variable Data is not changed in PEI ph= ase, this check is not required by NV variable.=20 =20 Thanks Liming =E5=8F=91=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io > =E4=BB=A3=E8=A1= =A8 Jiading Zhang =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2022=E5=B9=B49=E6=9C=8828=E6=97=A5 11= :05 =E6=94=B6=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io =20 =E4=B8=BB=E9=A2=98: [edk2-devel] [PATCH] MdeModulePkg VariablePei: Add Vari= able state check when find variable in IndexTable. =20 When read a variable in PEI, it will find it first in the HOB, then find in= variable store. When find in variable store, it will check the variable st= ate, but find in HOB, it doesn't check the state, so if the variable was ch= anged, it will find the obsolete variable in the HOB. =20 Signed-off-by: jdzhang > --- MdeModulePkg/Universal/Variable/Pei/Variable.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) =20 diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/= Universal/Variable/Pei/Variable.c index 26a4c73b45..dffbd8cdb1 100644 --- a/MdeModulePkg/Universal/Variable/Pei/Variable.c +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c @@ -866,11 +866,13 @@ FindVariableEx ( Offset +=3D IndexTable->Index[Index]; MaxIndex =3D (VARIABLE_HEADER *)((UINT8 *)IndexTable->StartPtr + Off= set); GetVariableHeader (StoreInfo, MaxIndex, &VariableHeader); - if (CompareWithValidVariable (StoreInfo, MaxIndex, VariableHeader, V= ariableName, VendorGuid, PtrTrack) =3D=3D EFI_SUCCESS) { - if (VariableHeader->State =3D=3D (VAR_IN_DELETED_TRANSITION & VAR_= ADDED)) { - InDeletedVariable =3D PtrTrack->CurrPtr; - } else { - return EFI_SUCCESS; + if ((VariableHeader->State =3D=3D VAR_ADDED) || (VariableHeader->Sta= te =3D=3D (VAR_IN_DELETED_TRANSITION & VAR_ADDED))) { + if (CompareWithValidVariable (StoreInfo, MaxIndex, VariableHeader,= VariableName, VendorGuid, PtrTrack) =3D=3D EFI_SUCCESS) { + if (VariableHeader->State =3D=3D (VAR_IN_DELETED_TRANSITION & VA= R_ADDED)) { + InDeletedVariable =3D PtrTrack->CurrPtr; + } else { + return EFI_SUCCESS; + } } } } --=20 2.20.1.windows.1 =20 =20 -=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 (#95164): https://edk2.groups.io/g/devel/message/95164 Mute This Topic: https://groups.io/mt/94319103/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- ------=_NextPart_000_03D4_01D8DFB3.5B9D86E0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Jiading:

=C2= =A0HOB is created in volatile memory (cache or physical memory). And, HOB i= s re-created for every boot (normal boot, S3 boot). When the first call Get= Variable, gEfiVariableIndexTableGuid guid hob should not exist. If this gui= d hob exits, it should be created by other module. Please check.

 

Thanks

Liming

=E5=8F=91=E4=BB=B6=E4=BA= =BA: Jiading Zhang <jdzhang@kunlu= ntech.com.cn>
=E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4= : 2022=E5=B9=B410=E6=9C=8810=E6=97=A5 16:36
=E6=94= =B6=E4=BB=B6=E4=BA=BA: gao= liming <gaoliming@byosoft.com.cn>; devel@edk2.groups.io
= =E4=B8=BB=E9=A2=98: Re: [e= dk2-devel] =E5=9B=9E=E5=A4=8D: [edk2-devel] =E5=9B=9E=E5=A4=8D: [edk2-devel] [PATCH] MdeModulePkg = VariablePei: Add Variable state check when find variable in IndexTable.

 

Hi liming:
    I checked the code, a= nd found the root cause of the issue.
    As the following cod= e in edk2,   in my code,  after the  first time to= read the variable in PEI phase,  it cached the variable store info&nb= sp; IndexTable into  a Hob in a special non-volatile memory,  but= after the code running in dxe phase, the variable was changed.  And a= fter a warm reboot, maybe call s3 sleep is more exactly, when read the vari= able, it  first get the IndexTable from the Hob but not build the Inde= xTable again, so it read the deleted variable if hasn't the condition check= .  This is really a special case.

      GuidHob =3D GetFirstGu= idHob (&gEfiVariableIndexTableGuid);

        if (GuidH= ob !=3D NULL) {

          StoreInfo->IndexTable = =3D GET_GUID_HOB_DATA (GuidHob);

        } else {

  &n= bsp;       //

          // If it's the= first time to access variable region in flash, create a guid hob to record=

&n= bsp;         // VAR_ADDED type variable info.

   = ;       // Note that as the resource of PEI phase is limited= , only store the limited number of

          // VAR_A= DDED type variables to reduce access time.

=

          = //

=           StoreInfo->IndexTable =3D (VARIABLE_I= NDEX_TABLE *) BuildGuidHob (&gEfiVariableIndexTableGuid, sizeof (VARIAB= LE_INDEX_TABLE));

          StoreInfo->IndexTable-= >Length      =3D 0;

          Store= Info->IndexTable->StartPtr    =3D GetStartPointer (Variable= StoreHeader);

          StoreInfo->IndexTable->= EndPtr      =3D GetEndPointer   (VariableStoreHead= er);

          StoreInfo->IndexTable->GoneThrou= gh =3D 0;

        }

=

  =    

On Mon, Oct 10, 2022 at 09:39 AM, gaoliming wrote:

Jiading: =

  Please check why NV variable data is requir= ed to be changed in PEI phase. This will be helpful for this issue.<= span lang=3DEN-US>

 

<= p class=3Ddefangedmsonormal style=3D'margin:0cm'>Thanks

Liming

=E5=8F=91=E4=BB= =B6=E4=BA=BA: Jiading Zhang <= ;jdzhang@kunluntech.com.cn= >
=E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2022=E5=B9=B410=E6=9C=8810=E6=97=A5 8:35
=E6=94=B6=E4=BB=B6=E4=BA=BA:
gaoliming <gaoliming@byosoft.com.cn>;= devel@edk2.groups.io
=E4=B8=BB=E9=A2=98<= span lang=3DEN-US>:
Re: [edk2-dev= el] =E5=9B=9E=E5=A4=8D: [edk2-devel] [PATCH] MdeM= odulePkg VariablePei: Add Variable state check when find variable in IndexT= able.

 

Hi liming:
   Yes, NV Variable Data is not change= d in PEI phase in normal case. This issue was found when we did a special c= oding, and when found variable in the IndexTable, it found the variable bef= ore the last changed if  didn't add the following condition:
 = "if ((VariableHeader->State =3D=3D VAR_ADDED) || (VariableHeader-&= gt;State =3D=3D (VAR_IN_DELETED_TRANSITION & VAR_ADDED)))"

= Maybe our specail coding had some defect
=EF=BC=8C= and caused this issue.

On Fri, Sep 30, 2022 at 10:46 AM, gaoliming w= rote:

Jiading= :

 Hob Variable Store Info IndexTable is NULL.= So, this logic doesn=E2=80=99t work for HOB variable store.= NV Variable Store Info has IndexTable. When its IndexTable is initialized,= its IndexTable will only record the variable with VAR_ADDED attribute. Bec= ause NV Variable Data is not changed in PEI phase, this check is not requir= ed by NV variable.

<= p class=3Ddefangedmsonormal style=3D'margin:0cm'> 

Thanks

Liming

=E5=8F=91=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io= <devel@edk2.groups.io&g= t; =E4=BB=A3=E8=A1=A8 Jiading Zhang
=E5=8F=91= =E9=80=81=E6=97=B6=E9=97=B4: 20= 22= =E5=B9=B49=E6=9C=8828= =E6=97=A5 11:05
=E6=94=B6=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io
=E4=B8=BB=E9=A2=98: [edk2-devel] [PATCH] MdeModulePkg VariablePei: Ad= d Variable state check when find variable in IndexTable.

 

=

When r= ead a variable in PEI, it will find it first in the HOB, then find in varia= ble store. When find in variable store, it will check the variable state, b= ut find in HOB, it doesn't check the state, so if the variable was changed,= it will find the obsolete variable in the HOB.

=

&= nbsp;

Signed-off-by: jdzhang <jdzhang@kunluntech.com.cn>

---

 MdeModulePkg/Universal/Va= riable/Pei/Variable.c | 12 +++++++-----

 1 f= ile changed, 7 insertions(+), 5 deletions(-)

&nbs= p;

diff --git a/MdeModulePkg/Universal/Variable/P= ei/Variable.c b/MdeModulePkg/Universal/Variable/Pei/Variable.c

index 26a4c73b45..dffbd8cdb1 100644

--- a/MdeModulePkg/Universal/Variable/Pei/Variable.c

=

+++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c=

@@ -866,11 +866,13 @@ FindVariableEx (

=

&= nbsp;      Offset  +=3D IndexTable->Index[Index];

       MaxIndex =3D (VARIABLE_H= EADER *)((UINT8 *)IndexTable->StartPtr + Offset);

<= /div>

       GetVariableHeader (StoreInfo, MaxIndex, &= ;VariableHeader);

-      if (Compa= reWithValidVariable (StoreInfo, MaxIndex, VariableHeader, VariableName, Ven= dorGuid, PtrTrack) =3D=3D EFI_SUCCESS) {

-  =       if (VariableHeader->State =3D=3D (VAR_IN_DELETED_TR= ANSITION & VAR_ADDED)) {

-     = ;     InDeletedVariable =3D PtrTrack->CurrPtr;

-        } else {

= -          return EFI_SUCCESS;

+      if ((VariableHeader->State =3D=3D VAR_ADD= ED) || (VariableHeader->State =3D=3D (VAR_IN_DELETED_TRANSITION & VA= R_ADDED))) {

+        if (Com= pareWithValidVariable (StoreInfo, MaxIndex, VariableHeader, VariableName, V= endorGuid, PtrTrack) =3D=3D EFI_SUCCESS) {

=

+ = ;         if (VariableHeader->State =3D=3D (VAR_IN_D= ELETED_TRANSITION & VAR_ADDED)) {

+  &nb= sp;         InDeletedVariable =3D PtrTrack->CurrPtr;=

+          } else {

+            return EF= I_SUCCESS;

+          }<= o:p>

         }

       }

<= p class=3Ddefangedmsonormal style=3D'margin:0cm'>  =    }

-- 

2.20.1.windows.1

 

 

_._,_._,_

G= roups.io Links:

You receive all messages sent to this group.

Vi= ew/Reply Online (#95164) | | Mute This Topic | New Topic
Your Subscription | Contact Group Owner | Unsubscribe [importer@patchew.org]
_._,_._,_=20 ------=_NextPart_000_03D4_01D8DFB3.5B9D86E0--