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 代表 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 > --- 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