From: "Jiading Zhang" <jdzhang@kunluntech.com.cn>
To: gaoliming <gaoliming@byosoft.com.cn>,devel@edk2.groups.io
Subject: Re: [edk2-devel] 回复: [edk2-devel] 回复: [edk2-devel] [PATCH] MdeModulePkg VariablePei: Add Variable state check when find variable in IndexTable.
Date: Mon, 10 Oct 2022 01:36:25 -0700 [thread overview]
Message-ID: <28563.1665390985077437700@groups.io> (raw)
In-Reply-To: <01df01d8dc49$1a7b2130$4f716390$@byosoft.com.cn>
[-- Attachment #1: Type: text/plain, Size: 6017 bytes --]
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 IndexTable into a Hob in a special non-volatile memory, but after the code running 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 IndexTable from the Hob but not build the IndexTable again, so it read the deleted variable if hasn't the condition check. This is really a special case.
GuidHob = GetFirstGuidHob (&gEfiVariableIndexTableGuid);
if (GuidHob != NULL) {
StoreInfo->IndexTable = GET_GUID_HOB_DATA (GuidHob);
} else {
//
// If it's the first time to access variable region in flash, create 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 = (VARIABLE_INDEX_TABLE *) BuildGuidHob (&gEfiVariableIndexTableGuid, sizeof (VARIABLE_INDEX_TABLE));
StoreInfo->IndexTable->Length = 0;
StoreInfo->IndexTable->StartPtr = GetStartPointer (VariableStoreHeader);
StoreInfo->IndexTable->EndPtr = GetEndPointer (VariableStoreHeader);
StoreInfo->IndexTable->GoneThrough = 0;
}
On Mon, Oct 10, 2022 at 09:39 AM, gaoliming wrote:
>
>
>
> Jiading:
>
>
>
> Please check why NV variable data is required to be changed in PEI phase.
> This will be helpful for this issue.
>
>
>
>
>
>
>
> Thanks
>
>
>
> Liming
>
>
>
> *发件人 :* Jiading Zhang <jdzhang@kunluntech.com.cn>
> *发送时间 :* 2022 年 10 月 10 日 8:35
> *收件人 :* gaoliming <gaoliming@byosoft.com.cn>; devel@edk2.groups.io
> *主题 :* Re: [edk2-devel] 回复 : [edk2-devel] [PATCH] MdeModulePkg VariablePei:
> Add Variable state check when find variable in IndexTable.
>
>
>
>
>
>
>
>
> Hi liming:
> Yes, NV Variable Data is not changed in PEI phase in normal case. This
> issue 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 the following condition:
> "if ((VariableHeader->State == VAR_ADDED) || (VariableHeader->State ==
> (VAR_IN_DELETED_TRANSITION & VAR_ADDED)))"
>
> Maybe our specail coding had some defect , and 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 ’ t 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. Because NV Variable Data is not changed in PEI
>> phase, this check is not required by NV variable.
>>
>>
>>
>>
>>
>>
>>
>> Thanks
>>
>>
>>
>> Liming
>>
>>
>>
>> *发件人 :* devel@edk2.groups.io < devel@edk2.groups.io > *代表* Jiading Zhang
>> *发送时间 :* 2022 年 9 月 28 日 11:05
>> *收件人 :* devel@edk2.groups.io
>> *主题 :* [edk2-devel] [PATCH] MdeModulePkg VariablePei: Add Variable state
>> check when find variable in IndexTable.
>>
>>
>>
>>
>>
>>
>>
>>
>> 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
>> state, but find in HOB, it doesn't check the state, so if the variable was
>> changed, it will find the obsolete variable in the HOB.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> Signed-off-by: jdzhang < jdzhang@kunluntech.com.cn >
>>
>>
>>
>>
>> ---
>>
>>
>>
>>
>> MdeModulePkg/Universal/Variable/Pei/Variable.c | 12 +++++++-----
>>
>>
>>
>>
>> 1 file changed, 7 insertions(+), 5 deletions(-)
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> 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 += IndexTable->Index[Index];
>>
>>
>>
>>
>> MaxIndex = (VARIABLE_HEADER *)((UINT8 *)IndexTable->StartPtr + Offset);
>>
>>
>>
>>
>> GetVariableHeader (StoreInfo, MaxIndex, &VariableHeader);
>>
>>
>>
>>
>> - if (CompareWithValidVariable (StoreInfo, MaxIndex, VariableHeader,
>> VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {
>>
>>
>>
>>
>> - if (VariableHeader->State == (VAR_IN_DELETED_TRANSITION &
>> VAR_ADDED)) {
>>
>>
>>
>>
>> - InDeletedVariable = PtrTrack->CurrPtr;
>>
>>
>>
>>
>> - } else {
>>
>>
>>
>>
>> - return EFI_SUCCESS;
>>
>>
>>
>>
>> + if ((VariableHeader->State == VAR_ADDED) || (VariableHeader->State
>> == (VAR_IN_DELETED_TRANSITION & VAR_ADDED))) {
>>
>>
>>
>>
>> + if (CompareWithValidVariable (StoreInfo, MaxIndex,
>> VariableHeader, VariableName, VendorGuid, PtrTrack) == EFI_SUCCESS) {
>>
>>
>>
>>
>> + if (VariableHeader->State == (VAR_IN_DELETED_TRANSITION &
>> VAR_ADDED)) {
>>
>>
>>
>>
>> + InDeletedVariable = PtrTrack->CurrPtr;
>>
>>
>>
>>
>> + } else {
>>
>>
>>
>>
>> + return EFI_SUCCESS;
>>
>>
>>
>>
>> + }
>>
>>
>>
>>
>> }
>>
>>
>>
>>
>> }
>>
>>
>>
>>
>> }
>>
>>
>>
>>
>> --
>>
>>
>>
>>
>> 2.20.1.windows.1
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>
[-- Attachment #2: Type: text/html, Size: 13176 bytes --]
next prev parent reply other threads:[~2022-10-10 8:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-28 3:05 [PATCH] MdeModulePkg VariablePei: Add Variable state check when find variable in IndexTable Jiading Zhang
2022-09-30 2:46 ` 回复: [edk2-devel] " gaoliming
2022-10-10 0:35 ` [edk2-devel] " Jiading Zhang
2022-10-10 1:39 ` 回复: " gaoliming
2022-10-10 8:36 ` Jiading Zhang [this message]
2022-10-14 1:57 ` 回复: [edk2-devel] " gaoliming
2022-10-14 2:29 ` [edk2-devel] " Jiading Zhang
2022-10-08 0:20 ` Jiading Zhang
2022-10-08 1:29 ` 回复: " gaoliming
2022-10-08 10:05 ` [edk2-devel] " Jiading Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=28563.1665390985077437700@groups.io \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox