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.web11.19820.1683730957873019256 for ; Wed, 10 May 2023 08:02:39 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=KMM2zzEZ; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from localhost.localdomain (unknown [47.201.8.94]) by linux.microsoft.com (Postfix) with ESMTPSA id 811D920AECFC; Wed, 10 May 2023 08:02:36 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 811D920AECFC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1683730957; bh=5PvJxsRLIcWBUb4llsjSiBJAEJSeleK1g4E+Cv1rpGo=; h=From:To:Cc:Subject:Date:From; b=KMM2zzEZgegDy8pa4sA9ufri3R7n2Pex+ZlZgEdTD1IPzKQPTbu1oMM3fB7dVPt12 fqunxz1+ko4ejG67apGo7H8to4G8ID49SeU+C+2Y2gV2fEdVDJaQzb7JOTVIOwnDDX uURnkOdZth/76+CpZ6FWU63VwUAcRsFa3pOPyxuU= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Chasel Chiu , Nate DeSimone , Isaac Oram , Liming Gao , Eric Dong , Raghava Gudla Subject: [edk2-platforms][PATCH v4 1/1] MinPlatformPkg: Add FspNvsBuffer compression option Date: Wed, 10 May 2023 11:02:16 -0400 Message-Id: <20230510150217.1716-1-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.40.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki Adds a PCD called "PcdEnableCompressedFspNvsBuffer" that allows the "FspNvsBuffer" UEFI variable data to be saved as compressed data. Especially due to the nature of the data saved in this variable, it compresses well. For example, it has been found to reduce ~63KB of data to ~13KB. Boot time impact has been found to be negligible. The default value is FALSE to keep default behavior consistent. Decompression can be performed on the variable data using the standard UefiDecompressLib. Cc: Chasel Chiu Cc: Nate DeSimone Cc: Isaac Oram Cc: Liming Gao Cc: Eric Dong Cc: Raghava Gudla Signed-off-by: Michael Kubacki --- Notes: v4: - Rebase onto 42a677e992d2 - Add CompressLib to MinPlatformPkg.dsc as well v3: - Rebase onto 7ac91ec277db - Add CompressLib instance to CoreCommonLib.dsc v2: Rebase onto 9769bf28d1fc Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConf= ig.c | 62 ++++++++++++++++---- Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConf= ig.inf | 4 ++ Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc = | 1 + Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec = | 6 ++ Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc = | 1 + 5 files changed, 61 insertions(+), 13 deletions(-) diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/Sa= veMemoryConfig.c b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryCon= fig/SaveMemoryConfig.c index 0215e8eeddfb..95b8cef8b32b 100644 --- a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemor= yConfig.c +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemor= yConfig.c @@ -3,6 +3,7 @@ exists, and saves the data to nvRAM. =20 Copyright (c) 2017 - 2022, Intel Corporation. All rights reserved.
+Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -10,6 +11,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include #include @@ -19,6 +21,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include #include #include =20 @@ -38,20 +41,26 @@ SaveMemoryConfigEntryPoint ( IN EFI_SYSTEM_TABLE *SystemTable ) { - EFI_STATUS Status; - EFI_HOB_GUID_TYPE *GuidHob; - VOID *HobData; - VOID *VariableData; - UINTN DataSize; - UINTN BufferSize; - BOOLEAN DataIsIdentical; + EFI_STATUS Status; + EFI_HOB_GUID_TYPE *GuidHob; + VOID *HobData; + VOID *VariableData; + UINTN DataSize; + UINTN BufferSize; + BOOLEAN DataIsIdentical; + VOID *CompressedData; + UINT64 CompressedSize; + UINTN CompressedAllocationPages; =20 - DataSize =3D 0; - BufferSize =3D 0; - VariableData =3D NULL; - GuidHob =3D NULL; - HobData =3D NULL; - DataIsIdentical =3D FALSE; + DataSize =3D 0; + BufferSize =3D 0; + VariableData =3D NULL; + GuidHob =3D NULL; + HobData =3D NULL; + DataIsIdentical =3D FALSE; + CompressedData =3D NULL; + CompressedSize =3D 0; + CompressedAllocationPages =3D 0; =20 // // Search for the Memory Configuration GUID HOB. If it is not present= , then @@ -73,6 +82,29 @@ SaveMemoryConfigEntryPoint ( } } =20 + if (PcdGetBool (PcdEnableCompressedFspNvsBuffer)) { + if (DataSize > 0) { + CompressedAllocationPages =3D EFI_SIZE_TO_PAGES (DataSize); + CompressedData =3D AllocatePages (CompressedAllocationP= ages); + if (CompressedData =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "[%a] - Failed to allocate compressed data = buffer.\n", __FUNCTION__)); + ASSERT_EFI_ERROR (EFI_OUT_OF_RESOURCES); + return EFI_OUT_OF_RESOURCES; + } + + CompressedSize =3D EFI_PAGES_TO_SIZE (CompressedAllocationPages); + Status =3D Compress (HobData, DataSize, CompressedData, &C= ompressedSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "[%a] - failed to compress data. Status =3D= %r\n", __FUNCTION__, Status)); + ASSERT_EFI_ERROR (Status); + return Status; + } + } + + HobData =3D CompressedData; + DataSize =3D (UINTN)CompressedSize; + } + if (HobData !=3D NULL) { DEBUG ((DEBUG_INFO, "FspNvsHob.NvsDataLength:%d\n", DataSize)); DEBUG ((DEBUG_INFO, "FspNvsHob.NvsDataPtr : 0x%x\n", HobData)); @@ -136,6 +168,10 @@ SaveMemoryConfigEntryPoint ( DEBUG((DEBUG_ERROR, "Memory S3 Data HOB was not found\n")); } =20 + if (CompressedData !=3D NULL) { + FreePages (CompressedData, CompressedAllocationPages); + } + // // This driver does not produce any protocol services, so always unloa= d it. // diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/Sa= veMemoryConfig.inf b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryC= onfig/SaveMemoryConfig.inf index 61e85a658693..0f12deb131ca 100644 --- a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemor= yConfig.inf +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemor= yConfig.inf @@ -26,6 +26,7 @@ [LibraryClasses] LargeVariableReadLib LargeVariableWriteLib BaseLib + CompressLib =20 [Packages] MdePkg/MdePkg.dec @@ -45,6 +46,9 @@ [Guids] gFspNonVolatileStorageHob2Guid ## CONSUMES gFspNvsBufferVariableGuid ## PRODUCES =20 +[Pcd] + gMinPlatformPkgTokenSpaceGuid.PcdEnableCompressedFspNvsBuffer + [Depex] gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid \ No newline at end of file diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc = b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc index 5ce21cf31e17..dfe7d836d32a 100644 --- a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc +++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc @@ -147,6 +147,7 @@ [LibraryClasses.common] BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib= .inf LargeVariableReadLib|MinPlatformPkg/Library/BaseLargeVariableLib/BaseL= argeVariableReadLib.inf LargeVariableWriteLib|MinPlatformPkg/Library/BaseLargeVariableLib/Base= LargeVariableWriteLib.inf + CompressLib|MinPlatformPkg/Library/CompressLib/CompressLib.inf =20 # # CryptLib diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec b/Platform/= Intel/MinPlatformPkg/MinPlatformPkg.dec index 784abb828e76..45c75f8ec2c9 100644 --- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec @@ -311,6 +311,12 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynami= c, PcdsDynamicEx] =20 gMinPlatformPkgTokenSpaceGuid.PcdPlatformMemoryCheckLevel|0|UINT32|0x3= 0000009 =20 + ## Controls whether the FSP NVS buffer is saved as compressed data. + # Data compression can significantly reduce variable storage usage for= FSP NVS buffer data. + # Platforms that choose to compress the data will need to decompress t= he variable data upon + # extraction. + gMinPlatformPkgTokenSpaceGuid.PcdEnableCompressedFspNvsBuffer|FALSE|BO= OLEAN|0x30000010 + ## This PCD is to control which device is the potential trusted consol= e input device.

# For example:
# USB Short Form: UsbHID(0xFFFF,0xFFFF,0x1,0x1)
diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc b/Platform/= Intel/MinPlatformPkg/MinPlatformPkg.dsc index 90127c16b59e..087fa48dd00a 100644 --- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc @@ -101,6 +101,7 @@ [LibraryClasses.common.DXE_DRIVER] # # DXE phase common # + CompressLib|MinPlatformPkg/Library/CompressLib/CompressLib.inf FspWrapperPlatformLib|MinPlatformPkg/FspWrapper/Library/DxeFspWrapperP= latformLib/DxeFspWrapperPlatformLib.inf TestPointCheckLib|MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTes= tPointCheckLib.inf TestPointLib|MinPlatformPkg/Test/Library/TestPointLib/DxeTestPointLib.= inf --=20 2.40.1.windows.1