From nobody Fri May 3 15:12:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1530181341087623.5263982912442; Thu, 28 Jun 2018 03:22:21 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3659C202E5452; Thu, 28 Jun 2018 03:22:19 -0700 (PDT) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5A00321B02845 for ; Thu, 28 Jun 2018 03:22:18 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jun 2018 03:22:18 -0700 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by fmsmga006.fm.intel.com with ESMTP; 28 Jun 2018 03:22:17 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,283,1526367600"; d="scan'208";a="241350784" From: Star Zeng To: edk2-devel@lists.01.org Date: Thu, 28 Jun 2018 18:22:14 +0800 Message-Id: <1530181335-174468-2-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1530181335-174468-1-git-send-email-star.zeng@intel.com> References: <1530181335-174468-1-git-send-email-star.zeng@intel.com> Subject: [edk2] [PATCH 1/2] MdeModulePkg Variable: Abstract GetHobVariableStore function X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Jiewen Yao , Liming Gao , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move getting HOB variable store code logic to a separated GetHobVariableStore function. Cc: Liming Gao Cc: Jiewen Yao Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Liming Gao --- MdeModulePkg/Universal/Variable/Pei/Variable.c | 40 +++++++--- .../Universal/Variable/RuntimeDxe/Variable.c | 93 +++++++++++++++---= ---- 2 files changed, 91 insertions(+), 42 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/= Universal/Variable/Pei/Variable.c index 4060f4711dd0..1bcab3b770a5 100644 --- a/MdeModulePkg/Universal/Variable/Pei/Variable.c +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c @@ -2,7 +2,7 @@ Implement ReadOnly Variable Services required by PEIM and install PEI ReadOnly Varaiable2 PPI. These services operates the non volatile st= orage space. =20 -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD = License which accompanies this distribution. The full text of the license may be = found at @@ -496,6 +496,31 @@ CompareWithValidVariable ( } =20 /** + Get HOB variable store. + +**/ +VOID +GetHobVariableStore ( + OUT VARIABLE_STORE_INFO *StoreInfo, + OUT VARIABLE_STORE_HEADER **VariableStoreHeader + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + + GuidHob =3D GetFirstGuidHob (&gEfiAuthenticatedVariableGuid); + if (GuidHob !=3D NULL) { + *VariableStoreHeader =3D (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (= GuidHob); + StoreInfo->AuthFlag =3D TRUE; + } else { + GuidHob =3D GetFirstGuidHob (&gEfiVariableGuid); + if (GuidHob !=3D NULL) { + *VariableStoreHeader =3D (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA= (GuidHob); + StoreInfo->AuthFlag =3D FALSE; + } + } +} + +/** Return the variable store header and the store info based on the Index. =20 @param Type The type of the variable store. @@ -523,17 +548,8 @@ GetVariableStore ( VariableStoreHeader =3D NULL; switch (Type) { case VariableStoreTypeHob: - GuidHob =3D GetFirstGuidHob (&gEfiAuthenticatedVariableGuid); - if (GuidHob !=3D NULL) { - VariableStoreHeader =3D (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DAT= A (GuidHob); - StoreInfo->AuthFlag =3D TRUE; - } else { - GuidHob =3D GetFirstGuidHob (&gEfiVariableGuid); - if (GuidHob !=3D NULL) { - VariableStoreHeader =3D (VARIABLE_STORE_HEADER *) GET_GUID_HOB_D= ATA (GuidHob); - StoreInfo->AuthFlag =3D FALSE; - } - } + GetHobVariableStore (StoreInfo, &VariableStoreHeader); + break; =20 case VariableStoreTypeNv: diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.c index 835a66bc3bc8..fca8d5380924 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -4169,6 +4169,64 @@ ConvertNormalVarStorageToAuthVarStorage ( mVariableModuleGlobal->VariableGlobal.AuthFormat =3D TRUE; return AuthVarStorage; } + +/** + Get HOB variable store. + + @param[out] VariableGuid NV variable store signature. + + @retval EFI_SUCCESS Function successfully executed. + @retval EFI_OUT_OF_RESOURCES Fail to allocate enough memory resource. + +**/ +EFI_STATUS +GetHobVariableStore ( + IN EFI_GUID *VariableGuid + ) +{ + VARIABLE_STORE_HEADER *VariableStoreHeader; + UINT64 VariableStoreLength; + EFI_HOB_GUID_TYPE *GuidHob; + BOOLEAN NeedConvertNormalToAuth; + + // + // Combinations supported: + // 1. Normal NV variable store + + // Normal HOB variable store + // 2. Auth NV variable store + + // Auth HOB variable store + // 3. Auth NV variable store + + // Normal HOB variable store (code will convert it to Auth Format) + // + NeedConvertNormalToAuth =3D FALSE; + GuidHob =3D GetFirstGuidHob (VariableGuid); + if (GuidHob =3D=3D NULL && VariableGuid =3D=3D &gEfiAuthenticatedVariabl= eGuid) { + // + // Try getting it from normal variable HOB + // + GuidHob =3D GetFirstGuidHob (&gEfiVariableGuid); + NeedConvertNormalToAuth =3D TRUE; + } + if (GuidHob !=3D NULL) { + VariableStoreHeader =3D GET_GUID_HOB_DATA (GuidHob); + VariableStoreLength =3D GuidHob->Header.HobLength - sizeof (EFI_HOB_GU= ID_TYPE); + if (GetVariableStoreStatus (VariableStoreHeader) =3D=3D EfiValid) { + if (!NeedConvertNormalToAuth) { + mVariableModuleGlobal->VariableGlobal.HobVariableBase =3D (EFI_PHY= SICAL_ADDRESS) (UINTN) AllocateRuntimeCopyPool ((UINTN) VariableStoreLength= , (VOID *) VariableStoreHeader); + } else { + mVariableModuleGlobal->VariableGlobal.HobVariableBase =3D (EFI_PHY= SICAL_ADDRESS) (UINTN) ConvertNormalVarStorageToAuthVarStorage ((VOID *) Va= riableStoreHeader); + } + if (mVariableModuleGlobal->VariableGlobal.HobVariableBase =3D=3D 0) { + return EFI_OUT_OF_RESOURCES; + } + } else { + DEBUG ((EFI_D_ERROR, "HOB Variable Store header is corrupted!\n")); + } + } + + return EFI_SUCCESS; +} + /** Initializes variable store area for non-volatile and volatile variable. =20 @@ -4183,13 +4241,9 @@ VariableCommonInitialize ( { EFI_STATUS Status; VARIABLE_STORE_HEADER *VolatileVariableStore; - VARIABLE_STORE_HEADER *VariableStoreHeader; - UINT64 VariableStoreLength; UINTN ScratchSize; - EFI_HOB_GUID_TYPE *GuidHob; EFI_GUID *VariableGuid; EFI_FIRMWARE_VOLUME_HEADER *NvFvHeader; - BOOLEAN IsNormalVariableHob; =20 // // Allocate runtime memory for variable driver global structure. @@ -4231,32 +4285,11 @@ VariableCommonInitialize ( // // Get HOB variable store. // - IsNormalVariableHob =3D FALSE; - GuidHob =3D GetFirstGuidHob (VariableGuid); - if (GuidHob =3D=3D NULL && VariableGuid =3D=3D &gEfiAuthenticatedVariabl= eGuid) { - // - // Try getting it from normal variable HOB - // - GuidHob =3D GetFirstGuidHob (&gEfiVariableGuid); - IsNormalVariableHob =3D TRUE; - } - if (GuidHob !=3D NULL) { - VariableStoreHeader =3D GET_GUID_HOB_DATA (GuidHob); - VariableStoreLength =3D GuidHob->Header.HobLength - sizeof (EFI_HOB_GU= ID_TYPE); - if (GetVariableStoreStatus (VariableStoreHeader) =3D=3D EfiValid) { - if (!IsNormalVariableHob) { - mVariableModuleGlobal->VariableGlobal.HobVariableBase =3D (EFI_PHY= SICAL_ADDRESS) (UINTN) AllocateRuntimeCopyPool ((UINTN) VariableStoreLength= , (VOID *) VariableStoreHeader); - } else { - mVariableModuleGlobal->VariableGlobal.HobVariableBase =3D (EFI_PHY= SICAL_ADDRESS) (UINTN) ConvertNormalVarStorageToAuthVarStorage ((VOID *) Va= riableStoreHeader); - } - if (mVariableModuleGlobal->VariableGlobal.HobVariableBase =3D=3D 0) { - FreePool (NvFvHeader); - FreePool (mVariableModuleGlobal); - return EFI_OUT_OF_RESOURCES; - } - } else { - DEBUG ((EFI_D_ERROR, "HOB Variable Store header is corrupted!\n")); - } + Status =3D GetHobVariableStore (VariableGuid); + if (EFI_ERROR (Status)) { + FreePool (NvFvHeader); + FreePool (mVariableModuleGlobal); + return Status; } =20 mVariableModuleGlobal->MaxVolatileVariableSize =3D ((PcdGet32 (PcdMaxVol= atileVariableSize) !=3D 0) ? --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Fri May 3 15:12:00 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1530181343715406.1757431689116; Thu, 28 Jun 2018 03:22:23 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 638EA202E5456; Thu, 28 Jun 2018 03:22:21 -0700 (PDT) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8C43721BADAB3 for ; Thu, 28 Jun 2018 03:22:19 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jun 2018 03:22:19 -0700 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.46]) by fmsmga006.fm.intel.com with ESMTP; 28 Jun 2018 03:22:18 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,283,1526367600"; d="scan'208";a="241350789" From: Star Zeng To: edk2-devel@lists.01.org Date: Thu, 28 Jun 2018 18:22:15 +0800 Message-Id: <1530181335-174468-3-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 In-Reply-To: <1530181335-174468-1-git-send-email-star.zeng@intel.com> References: <1530181335-174468-1-git-send-email-star.zeng@intel.com> Subject: [edk2] [PATCH 2/2] MdeModulePkg Variable: Make sure no more than one Variable HOB X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Jiewen Yao , Liming Gao , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" VariableHob may be built in PcdPeim (by PcdNvStoreDefaultValueBuffer) or some platform module (by some tool). The two solutions should not be co-exist. Cc: Liming Gao Cc: Jiewen Yao Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Liming Gao --- MdeModulePkg/Universal/Variable/Pei/Variable.c | 24 ++++++++++++++++++= ++++ .../Universal/Variable/RuntimeDxe/Variable.c | 24 ++++++++++++++++++= ++++ 2 files changed, 48 insertions(+) diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/= Universal/Variable/Pei/Variable.c index 1bcab3b770a5..d75a13e2b079 100644 --- a/MdeModulePkg/Universal/Variable/Pei/Variable.c +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c @@ -507,6 +507,30 @@ GetHobVariableStore ( { EFI_HOB_GUID_TYPE *GuidHob; =20 + // + // Make sure there is no more than one Variable HOB. + // + DEBUG_CODE ( + GuidHob =3D GetFirstGuidHob (&gEfiAuthenticatedVariableGuid); + if (GuidHob !=3D NULL) { + if ((GetNextGuidHob (&gEfiAuthenticatedVariableGuid, GET_NEXT_HOB (G= uidHob)) !=3D NULL)) { + DEBUG ((DEBUG_ERROR, "ERROR: Found two Auth Variable HOBs\n")); + ASSERT (FALSE); + } else if (GetFirstGuidHob (&gEfiVariableGuid) !=3D NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: Found one Auth + one Normal Variable = HOBs\n")); + ASSERT (FALSE); + } + } else { + GuidHob =3D GetFirstGuidHob (&gEfiVariableGuid); + if (GuidHob !=3D NULL) { + if ((GetNextGuidHob (&gEfiVariableGuid, GET_NEXT_HOB (GuidHob)) != =3D NULL)) { + DEBUG ((DEBUG_ERROR, "ERROR: Found two Normal Variable HOBs\n")); + ASSERT (FALSE); + } + } + } + ); + GuidHob =3D GetFirstGuidHob (&gEfiAuthenticatedVariableGuid); if (GuidHob !=3D NULL) { *VariableStoreHeader =3D (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (= GuidHob); diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c b/MdeMod= ulePkg/Universal/Variable/RuntimeDxe/Variable.c index fca8d5380924..42b0bfda570d 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c @@ -4190,6 +4190,30 @@ GetHobVariableStore ( BOOLEAN NeedConvertNormalToAuth; =20 // + // Make sure there is no more than one Variable HOB. + // + DEBUG_CODE ( + GuidHob =3D GetFirstGuidHob (&gEfiAuthenticatedVariableGuid); + if (GuidHob !=3D NULL) { + if ((GetNextGuidHob (&gEfiAuthenticatedVariableGuid, GET_NEXT_HOB (G= uidHob)) !=3D NULL)) { + DEBUG ((DEBUG_ERROR, "ERROR: Found two Auth Variable HOBs\n")); + ASSERT (FALSE); + } else if (GetFirstGuidHob (&gEfiVariableGuid) !=3D NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: Found one Auth + one Normal Variable = HOBs\n")); + ASSERT (FALSE); + } + } else { + GuidHob =3D GetFirstGuidHob (&gEfiVariableGuid); + if (GuidHob !=3D NULL) { + if ((GetNextGuidHob (&gEfiVariableGuid, GET_NEXT_HOB (GuidHob)) != =3D NULL)) { + DEBUG ((DEBUG_ERROR, "ERROR: Found two Normal Variable HOBs\n")); + ASSERT (FALSE); + } + } + } + ); + + // // Combinations supported: // 1. Normal NV variable store + // Normal HOB variable store --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel