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.web08.27582.1661225212593395865 for ; Mon, 22 Aug 2022 20:26:52 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ZUxsqBa0; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from [192.168.4.22] (unknown [47.195.228.134]) by linux.microsoft.com (Postfix) with ESMTPSA id 8F4B12174E29; Mon, 22 Aug 2022 20:26:51 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8F4B12174E29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1661225212; bh=KiNDYFAX+8YsJ8j07H2zrncbxP8xcrmmHv8iRSMSr5Q=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ZUxsqBa0fdh/evxNXhXB8Abchv1BRp9sp6VupUA1D2AzaoxvAMsKuSkm9iwtfmTuW 91rkWVo7fmKk26HUxiOVXuEb5XrL2MHj/FwyjDr25UPHgxZedlziSfHVFY07S6cNYl DH1Mi3AkIUCEV0C+Y0ciGIGDDjRLZMVTzrXZ6WU4= Message-ID: <698228da-5a9c-a4d3-fd03-ced556d0ca72@linux.microsoft.com> Date: Mon, 22 Aug 2022 23:26:50 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [edk2-devel] [edk2-platforms][PATCH v1 1/1] MinPlatformPkg: Add FspNvsBuffer compression option To: devel@edk2.groups.io, isaac.w.oram@intel.com Cc: "Chiu, Chasel" , "Desimone, Nathaniel L" , "Gao, Liming" , "Dong, Eric" References: <20220805194331.1007-1-mikuback@linux.microsoft.com> From: "Michael Kubacki" In-Reply-To: Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Isaac, Here's v2 rebased on 9769bf28d1fc. https://edk2.groups.io/g/devel/message/92644 I also pushed a copy to this branch on my fork in case it helps. https://github.com/makubacki/edk2-platforms/tree/add_mrcdata_compression Thanks, Michael On 8/16/2022 4:57 PM, Oram, Isaac W wrote: > Michael, > > I have not been able to apply this patch. Can you rebase and resend a V2? > > Thanks, > Isaac > > -----Original Message----- > From: mikuback@linux.microsoft.com > Sent: Friday, August 5, 2022 12:44 PM > To: devel@edk2.groups.io > Cc: Chiu, Chasel ; Desimone, Nathaniel L ; Oram, Isaac W ; Gao, Liming ; Dong, Eric > Subject: [edk2-platforms][PATCH v1 1/1] MinPlatformPkg: Add FspNvsBuffer compression option > > 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 > Signed-off-by: Michael Kubacki > --- > Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.c | 62 ++++++++++++++++---- > Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf | 4 ++ > Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec | 6 ++ > Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc | 1 + > 4 files changed, 60 insertions(+), 13 deletions(-) > > diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.c b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.c > index 0215e8eeddfb..95b8cef8b32b 100644 > --- a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.c > +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemo > +++ ryConfig.c > @@ -3,6 +3,7 @@ > exists, and saves the data to nvRAM. > > Copyright (c) 2017 - 2022, Intel Corporation. All rights reserved.
> +Copyright (c) Microsoft Corporation.
> SPDX-License-Identifier: BSD-2-Clause-Patent > > **/ > @@ -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 > > @@ -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; > > - DataSize = 0; > - BufferSize = 0; > - VariableData = NULL; > - GuidHob = NULL; > - HobData = NULL; > - DataIsIdentical = FALSE; > + DataSize = 0; > + BufferSize = 0; > + VariableData = NULL; > + GuidHob = NULL; > + HobData = NULL; > + DataIsIdentical = FALSE; > + CompressedData = NULL; > + CompressedSize = 0; > + CompressedAllocationPages = 0; > > // > // Search for the Memory Configuration GUID HOB. If it is not present, then @@ -73,6 +82,29 @@ SaveMemoryConfigEntryPoint ( > } > } > > + if (PcdGetBool (PcdEnableCompressedFspNvsBuffer)) { > + if (DataSize > 0) { > + CompressedAllocationPages = EFI_SIZE_TO_PAGES (DataSize); > + CompressedData = AllocatePages (CompressedAllocationPages); > + if (CompressedData == 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 = EFI_PAGES_TO_SIZE (CompressedAllocationPages); > + Status = Compress (HobData, DataSize, CompressedData, &CompressedSize); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "[%a] - failed to compress data. Status = %r\n", __FUNCTION__, Status)); > + ASSERT_EFI_ERROR (Status); > + return Status; > + } > + } > + > + HobData = CompressedData; > + DataSize = (UINTN)CompressedSize; > + } > + > if (HobData != 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")); > } > > + if (CompressedData != NULL) { > + FreePages (CompressedData, CompressedAllocationPages); } > + > // > // This driver does not produce any protocol services, so always unload it. > // > diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf > index 61e85a658693..0f12deb131ca 100644 > --- a/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf > +++ b/Platform/Intel/MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemo > +++ ryConfig.inf > @@ -26,6 +26,7 @@ [LibraryClasses] > LargeVariableReadLib > LargeVariableWriteLib > BaseLib > + CompressLib > > [Packages] > MdePkg/MdePkg.dec > @@ -45,6 +46,9 @@ [Guids] > gFspNonVolatileStorageHob2Guid ## CONSUMES > gFspNvsBufferVariableGuid ## PRODUCES > > +[Pcd] > + gMinPlatformPkgTokenSpaceGuid.PcdEnableCompressedFspNvsBuffer > + > [Depex] > gEfiVariableArchProtocolGuid AND > gEfiVariableWriteArchProtocolGuid > \ No newline at end of file > diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec > index db0a19066f11..49e1f070f9ab 100644 > --- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec > +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dec > @@ -305,6 +305,12 @@ [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] > > gMinPlatformPkgTokenSpaceGuid.PcdPlatformMemoryCheckLevel|0|UINT32|0x30000009 > > + ## 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 > + the variable data upon # extraction. > + > + gMinPlatformPkgTokenSpaceGuid.PcdEnableCompressedFspNvsBuffer|FALSE|BO > + OLEAN|0x30000010 > + > ## This PCD is to control which device is the potential trusted console 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 09aa6fe4d51c..ae170f87d548 100644 > --- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc > +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc > @@ -106,6 +106,7 @@ [LibraryClasses.common.DXE_DRIVER] > FspWrapperPlatformLib|MinPlatformPkg/FspWrapper/Library/DxeFspWrapperPlatformLib/DxeFspWrapperPlatformLib.inf > TestPointCheckLib|MinPlatformPkg/Test/Library/TestPointCheckLib/DxeTestPointCheckLib.inf > TestPointLib|MinPlatformPkg/Test/Library/TestPointLib/DxeTestPointLib.inf > + CompressLib|MinPlatformPkg/Library/CompressLib/CompressLib.inf > > [LibraryClasses.common.DXE_SMM_DRIVER] > TestPointCheckLib|MinPlatformPkg/Test/Library/TestPointCheckLib/SmmTestPointCheckLib.inf > -- > 2.28.0.windows.1 > > > > >