From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web09.333.1649698970706886564 for ; Mon, 11 Apr 2022 10:42:50 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=OBvt/XJy; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from localhost.localdomain (unknown [47.201.46.36]) by linux.microsoft.com (Postfix) with ESMTPSA id B2CE020BA5AC; Mon, 11 Apr 2022 10:42:49 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B2CE020BA5AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1649698970; bh=Zi66yLZbA1+kA0rS+C05JRfIQCw1XlAeBCbVFBvXSTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OBvt/XJybjmiFm8PD0UYjtnKzFAB8qHcd/J+DBXsdU1lPz3Ot0GcH+VKF+gmlvCUm DWp7iWLaT8LLG6QvdxQo53oSXu6GNQBQs4UEoFolCKllXxATNL67uRohE1VWXh85lI EKxmxv8hzP0g4+doQJat3QAert92lluMAtUXOTEs= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Jian J Wang , Hao A Wu , Liming Gao Subject: [PATCH v3 3/8] MdeModulePkg/Variable: Consume Variable Flash Info Date: Mon, 11 Apr 2022 13:42:04 -0400 Message-Id: <20220411174209.2804-4-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220411174209.2804-1-mikuback@linux.microsoft.com> References: <20220411174209.2804-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3479 Updates VariableRuntimeDxe, VariableSmm, and VariableStandaloneMm to acquire variable flash information from the Variable Flash Information library. Cc: Jian J Wang Cc: Hao A Wu Cc: Liming Gao Signed-off-by: Michael Kubacki --- MdeModulePkg/Universal/Variable/Pei/Variable.c | 14= +++++++++----- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c | 16= ++++++++++++---- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c | 14= ++++++++++---- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 17= +++++++++++++---- MdeModulePkg/Universal/Variable/Pei/Variable.h | 2= ++ MdeModulePkg/Universal/Variable/Pei/VariablePei.inf | 5= ++--- MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h | 7= ++----- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf | 5= ++--- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf | 5= ++--- MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf | 5= ++--- 10 files changed, 56 insertions(+), 34 deletions(-) diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePk= g/Universal/Variable/Pei/Variable.c index b36dd0de67b2..26a4c73b45a5 100644 --- a/MdeModulePkg/Universal/Variable/Pei/Variable.c +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c @@ -567,11 +567,13 @@ GetVariableStore ( OUT VARIABLE_STORE_INFO *StoreInfo ) { + EFI_STATUS Status; EFI_HOB_GUID_TYPE *GuidHob; EFI_FIRMWARE_VOLUME_HEADER *FvHeader; VARIABLE_STORE_HEADER *VariableStoreHeader; EFI_PHYSICAL_ADDRESS NvStorageBase; UINT32 NvStorageSize; + UINT64 NvStorageSize64; FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData; UINT32 BackUpOffset; =20 @@ -591,11 +593,13 @@ GetVariableStore ( // Emulated non-volatile variable mode is not enabled. // =20 - NvStorageSize =3D PcdGet32 (PcdFlashNvStorageVariableSize); - NvStorageBase =3D (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvSto= rageVariableBase64) !=3D 0 ? - PcdGet64 (PcdFlashNvStora= geVariableBase64) : - PcdGet32 (PcdFlashNvStora= geVariableBase) - ); + Status =3D GetVariableFlashNvStorageInfo (&NvStorageBase, &NvSto= rageSize64); + ASSERT_EFI_ERROR (Status); + + Status =3D SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize); + // This driver currently assumes the size will be UINT32 so asse= rt the value is safe for now. + ASSERT_EFI_ERROR (Status); + ASSERT (NvStorageBase !=3D 0); =20 // diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c b/M= deModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c index 03fec3048dc4..d5c409c914d1 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c @@ -423,6 +423,8 @@ FtwNotificationEvent ( EFI_PHYSICAL_ADDRESS VariableStoreBase; UINT64 VariableStoreLength; UINTN FtwMaxBlockSize; + UINT32 NvStorageVariableSize; + UINT64 NvStorageVariableSize64; =20 // // Ensure FTW protocol is installed. @@ -432,14 +434,20 @@ FtwNotificationEvent ( return; } =20 + Status =3D GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvS= torageVariableSize64); + ASSERT_EFI_ERROR (Status); + + Status =3D SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVari= ableSize); + // This driver currently assumes the size will be UINT32 so assert the= value is safe for now. + ASSERT_EFI_ERROR (Status); + + VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache->Header= Length; + Status =3D FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize= ); if (!EFI_ERROR (Status)) { - ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <=3D FtwMaxBlockSiz= e); + ASSERT (NvStorageVariableSize <=3D FtwMaxBlockSize); } =20 - NvStorageVariableBase =3D NV_STORAGE_VARIABLE_BASE; - VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache->He= aderLength; - // // Let NonVolatileVariableBase point to flash variable store base dire= ctly after FTW ready. // diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolati= le.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c index 5e9d40b67ac2..9e2d8fe0fe0c 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c @@ -142,6 +142,7 @@ InitRealNonVolatileVariableStore ( EFI_PHYSICAL_ADDRESS NvStorageBase; UINT8 *NvStorageData; UINT32 NvStorageSize; + UINT64 NvStorageSize64; FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData; UINT32 BackUpOffset; UINT32 BackUpSize; @@ -153,19 +154,24 @@ InitRealNonVolatileVariableStore ( =20 mVariableModuleGlobal->FvbInstance =3D NULL; =20 + Status =3D GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSi= ze64); + ASSERT_EFI_ERROR (Status); + + Status =3D SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize); + // This driver currently assumes the size will be UINT32 so assert the= value is safe for now. + ASSERT_EFI_ERROR (Status); + + ASSERT (NvStorageBase !=3D 0); + // // Allocate runtime memory used for a memory copy of the FLASH region. // Keep the memory and the FLASH in sync as updates occur. // - NvStorageSize =3D PcdGet32 (PcdFlashNvStorageVariableSize); NvStorageData =3D AllocateRuntimeZeroPool (NvStorageSize); if (NvStorageData =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } =20 - NvStorageBase =3D NV_STORAGE_VARIABLE_BASE; - ASSERT (NvStorageBase !=3D 0); - // // Copy NV storage data to the memory buffer. // diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/M= deModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c index 517cae7b00f8..5253c328dcd9 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c @@ -1084,6 +1084,8 @@ SmmFtwNotificationEvent ( EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol; EFI_PHYSICAL_ADDRESS NvStorageVariableBase; UINTN FtwMaxBlockSize; + UINT32 NvStorageVariableSize; + UINT64 NvStorageVariableSize64; =20 if (mVariableModuleGlobal->FvbInstance !=3D NULL) { return EFI_SUCCESS; @@ -1097,14 +1099,21 @@ SmmFtwNotificationEvent ( return Status; } =20 + Status =3D GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvS= torageVariableSize64); + ASSERT_EFI_ERROR (Status); + + Status =3D SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVari= ableSize); + // This driver currently assumes the size will be UINT32 so assert the= value is safe for now. + ASSERT_EFI_ERROR (Status); + + ASSERT (NvStorageVariableBase !=3D 0); + VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache->Header= Length; + Status =3D FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize= ); if (!EFI_ERROR (Status)) { - ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <=3D FtwMaxBlockSiz= e); + ASSERT (NvStorageVariableSize <=3D FtwMaxBlockSize); } =20 - NvStorageVariableBase =3D NV_STORAGE_VARIABLE_BASE; - VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache->He= aderLength; - // // Let NonVolatileVariableBase point to flash variable store base dire= ctly after FTW ready. // diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.h b/MdeModulePk= g/Universal/Variable/Pei/Variable.h index 7f9ad5bfc357..51effbf79987 100644 --- a/MdeModulePkg/Universal/Variable/Pei/Variable.h +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.h @@ -20,6 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include +#include =20 #include #include diff --git a/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf b/MdeMod= ulePkg/Universal/Variable/Pei/VariablePei.inf index 7cbdd2385e8f..7264a24bdf71 100644 --- a/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf +++ b/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf @@ -39,6 +39,8 @@ [LibraryClasses] DebugLib PeiServicesTablePointerLib PeiServicesLib + SafeIntLib + VariableFlashInfoLib =20 [Guids] ## CONSUMES ## GUID # Variable store header @@ -59,9 +61,6 @@ [Ppis] gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES =20 [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## S= OMETIMES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## C= ONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## C= ONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable ## S= OMETIMES_CONSUMES =20 [Depex] diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h b/MdeM= odulePkg/Universal/Variable/RuntimeDxe/Variable.h index 31e408976a35..a668abb82b15 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h @@ -31,6 +31,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include +#include #include #include #include @@ -40,11 +42,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "PrivilegePolymorphic.h" =20 -#define NV_STORAGE_VARIABLE_BASE (EFI_PHYSICAL_ADDRESS)\ - (PcdGet64 (PcdFlashNvStorageVariableB= ase64) !=3D 0 ? \ - PcdGet64 (PcdFlashNvStorageVariableB= ase64) : \ - PcdGet32 (PcdFlashNvStorageVariableB= ase)) - #define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE |\ EFI_VARIABLE_BOOTSERVICE_ACCESS | = \ EFI_VARIABLE_RUNTIME_ACCESS | \ diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDx= e.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf index c9434df631ee..3858adf6739d 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf @@ -71,8 +71,10 @@ [LibraryClasses] TpmMeasurementLib AuthVariableLib VarCheckLib + VariableFlashInfoLib VariablePolicyLib VariablePolicyHelperLib + SafeIntLib =20 [Protocols] gEfiFirmwareVolumeBlockProtocolGuid ## CONSUMES @@ -125,9 +127,6 @@ [Guids] gEfiImageSecurityDatabaseGuid =20 [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## C= ONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## S= OMETIMES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## C= ONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## C= ONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## C= ONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## C= ONSUMES diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf b= /MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf index eaa97a01c6e5..8c552b87e080 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf @@ -80,8 +80,10 @@ [LibraryClasses] AuthVariableLib VarCheckLib UefiBootServicesTableLib + VariableFlashInfoLib VariablePolicyLib VariablePolicyHelperLib + SafeIntLib =20 [Protocols] gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES @@ -127,9 +129,6 @@ [Guids] gEdkiiVarErrorFlagGuid =20 [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## = CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## = SOMETIMES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## = CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## = CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## = CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## = CONSUMES diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandalon= eMm.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm= .inf index d8c4f77e7f1f..f09bed40cf51 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf @@ -73,9 +73,11 @@ [LibraryClasses] HobLib MemoryAllocationLib MmServicesTableLib + SafeIntLib StandaloneMmDriverEntryPoint SynchronizationLib VarCheckLib + VariableFlashInfoLib VariablePolicyLib VariablePolicyHelperLib =20 @@ -120,9 +122,6 @@ [Guids] gEdkiiVarErrorFlagGuid =20 [Pcd] - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## = SOMETIMES_CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## = CONSUMES - gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## = CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## = CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## = CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## = CONSUMES --=20 2.28.0.windows.1