Hi Liming: My case is special, the HOB is created in a special memory, neither cache nor normal memory, and it is non-volatile for a warm reboot, so the change works in my code. Maybe I should try to create the hob in a volatile cache or memory, so I needn't change the open source code.
Thanks very much. Jiading On Fri, Oct 14, 2022 at 09:57 AM, gaoliming wrote: > > > > 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 > GetVariable, gEfiVariableIndexTableGuid guid hob should not exist. If this > guid hob exits, it should be created by other module. Please check. > > > > > > > > Thanks > > > > Liming > > > > *发件人 :* Jiading Zhang <jdzh...@kunluntech.com.cn> > *发送时间 :* 2022 年 10 月 10 日 16:36 > *收件人 :* gaoliming <gaolim...@byosoft.com.cn>; devel@edk2.groups.io > *主题 :* Re: [edk2-devel] 回复 : [edk2-devel] 回复 : [edk2-devel] [PATCH] > MdeModulePkg VariablePei: Add Variable state check when find variable in > IndexTable. > > > > > > > > > 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 < jdzh...@kunluntech.com.cn > >> *发送时间 :* 2022 年 10 月 10 日 8:35 >> *收件人 :* gaoliming < gaolim...@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 < jdzh...@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 >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >> >> > > On Fri, Oct 14, 2022 at 09:57 AM, gaoliming wrote: > > > > 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 > GetVariable, gEfiVariableIndexTableGuid guid hob should not exist. If this > guid hob exits, it should be created by other module. Please check. > > > > > > > > Thanks > > > > Liming > > > > *发件人 :* Jiading Zhang <jdzh...@kunluntech.com.cn> > *发送时间 :* 2022 年 10 月 10 日 16:36 > *收件人 :* gaoliming <gaolim...@byosoft.com.cn>; devel@edk2.groups.io > *主题 :* Re: [edk2-devel] 回复 : [edk2-devel] 回复 : [edk2-devel] [PATCH] > MdeModulePkg VariablePei: Add Variable state check when find variable in > IndexTable. > > > > > > > > > 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 < jdzh...@kunluntech.com.cn > >> *发送时间 :* 2022 年 10 月 10 日 8:35 >> *收件人 :* gaoliming < gaolim...@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 < jdzh...@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 >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >> >> > > -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95170): https://edk2.groups.io/g/devel/message/95170 Mute This Topic: https://groups.io/mt/94319103/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-