From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from cxsh.intel-email.com (cxsh.intel-email.com [121.46.250.151]) by mx.groups.io with SMTP id smtpd.web10.9281.1687827224980327582 for ; Mon, 26 Jun 2023 17:53:47 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@byosoft.com.cn header.s=cloud-union header.b=WVvThKWW; spf=pass (domain: byosoft.com.cn, ip: 121.46.250.151, mailfrom: gaoliming@byosoft.com.cn) Received: from cxsh.intel-email.com (localhost [127.0.0.1]) by cxsh.intel-email.com (Postfix) with ESMTP id 58383DDA7A3 for ; Tue, 27 Jun 2023 08:53:43 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=byosoft.com.cn; s=cloud-union; t=1687827223; bh=B2S69kMO3TaVzn880i+jdPDx5tA4IkI6VTPWY5aP8K0=; h=From:To:Cc:References:In-Reply-To:Subject:Date; b=WVvThKWW7YenHMfYzr8ZmeTR7+J7hS4fIQISWMLuCKcOexsPaHW1UwOHJgPHlrto5 NcbyXWfc5AKKXcoSgBBlZMn+SWdTeoDfZMDCX3SXGohXSBaQC10Hr/K1KTu7qdXepa 2jB1Z3SwixXXatHkscodQFlvmyZaEBwBnTRu4Mxg= Received: from localhost (localhost [127.0.0.1]) by cxsh.intel-email.com (Postfix) with ESMTP id 534A3DDA7A1 for ; Tue, 27 Jun 2023 08:53:43 +0800 (CST) Received: from cxsh.intel-email.com (localhost [127.0.0.1]) by cxsh.intel-email.com (Postfix) with ESMTP id 06F29DDA79A for ; Tue, 27 Jun 2023 08:53:43 +0800 (CST) Authentication-Results: cxsh.intel-email.com; none Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by cxsh.intel-email.com (Postfix) with SMTP id 7764DDDA7AB for ; Tue, 27 Jun 2023 08:53:40 +0800 (CST) Received: from DESKTOPS6D0PVI ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Tue, 27 Jun 2023 08:53:38 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-Originating-IP: 58.246.60.130 X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming" To: , Cc: "'Hao A Wu'" , "'Jian J Wang'" , "'Ronny Hansen'" , "'Shriram Masanamuthu Chinnathurai'" , "'Preshit Harlikar'" References: <20230608204434.2325-1-kuqin12@gmail.com> <20230608204434.2325-3-kuqin12@gmail.com> <03c601d9a70b$f91bfc60$eb53f520$@byosoft.com.cn> In-Reply-To: Subject: =?UTF-8?B?5Zue5aSNOiDlm57lpI06IFtlZGsyLWRldmVsXSBbUEFUQ0ggdjEgMi8yXSBNZGVNb2R1bGVQa2c6IFZhcmlhYmxlOiBJbnRyb2R1Y2UgTU0gYmFzZWQgdmFyaWFibGUgcmVhZCBzZXJ2aWNlIGluIFBFSQ==?= Date: Tue, 27 Jun 2023 08:53:38 +0800 Message-ID: <00e701d9a891$cf6cab30$6e460190$@byosoft.com.cn> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQG+g+FsfZi87AfOydUXn847m31HOwI+cahAAXRIdagCi2gkb6+iKqbw Sender: "gaoliming" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Content-Language: zh-cn Kun: Thanks for your update. I have no other comments for this patch. Reviewed= -by: Liming Gao Thanks Liming > -----=E9=82=AE=E4=BB=B6=E5=8E=9F=E4=BB=B6----- > =E5=8F=91=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io = =E4=BB=A3=E8=A1=A8 Kun Qin > =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2023=E5=B9=B46=E6=9C=8827=E6=97=A5 = 4:11 > =E6=94=B6=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io; gaoliming@byosoft.com.= cn > =E6=8A=84=E9=80=81: 'Hao A Wu' ; 'Jian J Wang' > ; 'Ronny Hansen' ; > 'Shriram Masanamuthu Chinnathurai' ; 'Preshit > Harlikar' > =E4=B8=BB=E9=A2=98: Re: =E5=9B=9E=E5=A4=8D: [edk2-devel] [PATCH v1 2/2] M= deModulePkg: Variable: > Introduce MM based variable read service in PEI >=20 > Hi Liming, >=20 > Thanks for catching that. I have removed the PCD usage and resend the > patch here: > https://edk2.groups.io/g/devel/message/106372 >=20 > Could you please let me know if you have any other feedback? >=20 > Per your functionality question, yes, the functionality was verified on > both virtual > and physical ARM platforms. I also added this statement to the v2 cover > letter. >=20 > Thanks, > Kun >=20 > On 6/24/2023 7:23 PM, gaoliming via groups.io wrote: > > Kun: > > Seemly, PcdMaxVariableSize is not used by this module. It can be > removed. > > > > And, has its functionality been verified in the real platform? > > > > Thanks > > Liming > >> -----=E9=82=AE=E4=BB=B6=E5=8E=9F=E4=BB=B6----- > >> =E5=8F=91=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io =E4=BB=A3=E8=A1=A8 Kun Qin > >> =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2023=E5=B9=B46=E6=9C=889=E6=97= =A5 4:45 > >> =E6=94=B6=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io > >> =E6=8A=84=E9=80=81: Hao A Wu ; Liming Gao > >> ; Jian J Wang ; > Ronny > >> Hansen ; Shriram Masanamuthu > >> Chinnathurai ; Preshit Harlikar > >> > >> =E4=B8=BB=E9=A2=98: [edk2-devel] [PATCH v1 2/2] MdeModulePkg: Variable= : Introduce > MM > >> based variable read service in PEI > >> > >> From: Kun Qin > >> > >> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4464 > >> > >> This change introduced the Standalone MM based variable read capabilit= y > >> in PEI phase for applicable platforms (such as ARM platforms). > >> > >> Similar to the x86 counterpart, MM communicate PPI is used to request > >> variable information from Standalone MM environment. > >> > >> Cc: Hao A Wu > >> Cc: Liming Gao > >> Cc: Jian J Wang > >> > >> Co-authored-by: Ronny Hansen > >> Co-authored-by: Shriram Masanamuthu Chinnathurai > >> > >> Co-authored-by: Preshit Harlikar > >> Signed-off-by: Kun Qin > >> --- > >> MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c > | > >> 381 ++++++++++++++++++++ > >> MdeModulePkg/MdeModulePkg.dsc > >> | 1 + > >> MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h > | > >> 134 +++++++ > >> MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf > | > >> 43 +++ > >> 4 files changed, 559 insertions(+) > >> > >> diff --git > >> a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c > >> b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c > >> new file mode 100644 > >> index 000000000000..4f937e22e89e > >> --- /dev/null > >> +++ > b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.c > >> @@ -0,0 +1,381 @@ > >> +/** @file -- MmVariablePei.c > >> > >> + Provides interface for reading Secure System Variables during PEI. > >> > >> + > >> > >> + Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<= BR> > >> > >> + Copyright (c) Microsoft Corporation.
> >> > >> + SPDX-License-Identifier: BSD-2-Clause-Patent > >> > >> +**/ > >> > >> + > >> > >> +#include "MmVariablePei.h" > >> > >> + > >> > >> +#define MM_VARIABLE_COMM_BUFFER_OFFSET > >> (SMM_COMMUNICATE_HEADER_SIZE + > >> SMM_VARIABLE_COMMUNICATE_HEADER_SIZE) > >> > >> + > >> > >> +// > >> > >> +// Module globals > >> > >> +// > >> > >> +EFI_PEI_READ_ONLY_VARIABLE2_PPI mPeiSecureVariableRead =3D { > >> > >> + PeiMmGetVariable, > >> > >> + PeiMmGetNextVariableName > >> > >> +}; > >> > >> + > >> > >> +EFI_PEI_PPI_DESCRIPTOR mPeiMmVariablePpi =3D { > >> > >> + (EFI_PEI_PPI_DESCRIPTOR_PPI | > >> EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), > >> > >> + &gEfiPeiReadOnlyVariable2PpiGuid, > >> > >> + &mPeiSecureVariableRead > >> > >> +}; > >> > >> + > >> > >> +/** > >> > >> + Entry point of PEI Secure Variable read driver > >> > >> + > >> > >> + @param FileHandle Handle of the file being invoked. > >> > >> + Type EFI_PEI_FILE_HANDLE is defined in > >> FfsFindNextFile(). > >> > >> + @param PeiServices General purpose services available to every > >> PEIM. > >> > >> + > >> > >> + @retval EFI_SUCCESS If the interface could be successfully install= ed > >> > >> + @retval Others Returned from PeiServicesInstallPpi() > >> > >> +**/ > >> > >> +EFI_STATUS > >> > >> +EFIAPI > >> > >> +PeiMmVariableInitialize ( > >> > >> + IN EFI_PEI_FILE_HANDLE FileHandle, > >> > >> + IN CONST EFI_PEI_SERVICES **PeiServices > >> > >> + ) > >> > >> +{ > >> > >> + return PeiServicesInstallPpi (&mPeiMmVariablePpi); > >> > >> +} > >> > >> + > >> > >> +/** > >> > >> + Helper function to populate MM communicate header and variable > >> communicate header > >> > >> + and then communicate to PEI. > >> > >> + > >> > >> + @param[in, out] CommunicateBuffer Size of the variable > name. > >> > >> + @param[in] CommunicateBufferSize The entire buffer size to > be > >> sent to MM. > >> > >> + @param[in] Function The MM variable > function > >> value. > >> > >> + > >> > >> + @retval EFI_INVALID_PARAMETER Invalid parameter. > >> > >> + @retval EFI_SUCCESS Find the specified variable. > >> > >> + @retval Others Errors returned by MM > >> communicate or variable service. > >> > >> + > >> > >> +**/ > >> > >> +EFI_STATUS > >> > >> +PopulateHeaderAndCommunicate ( > >> > >> + IN OUT UINT8 *CommunicateBuffer, > >> > >> + IN UINTN CommunicateBufferSize, > >> > >> + IN UINTN Function > >> > >> + ) > >> > >> +{ > >> > >> + EFI_STATUS Status; > >> > >> + EFI_PEI_MM_COMMUNICATION_PPI *MmCommunicationPpi; > >> > >> + EFI_MM_COMMUNICATE_HEADER > *MmCommunicateHeader; > >> > >> + SMM_VARIABLE_COMMUNICATE_HEADER *MmVarCommsHeader; > >> > >> + > >> > >> + // Minimal sanity check > >> > >> + if ((CommunicateBuffer =3D=3D NULL) || > >> > >> + (CommunicateBufferSize < > >> MM_VARIABLE_COMM_BUFFER_OFFSET)) > >> > >> + { > >> > >> + Status =3D EFI_INVALID_PARAMETER; > >> > >> + DEBUG ((DEBUG_ERROR, "%a: Invalid incoming parameters: %p and > >> 0x%x\n", __func__, CommunicateBuffer, CommunicateBufferSize)); > >> > >> + goto Exit; > >> > >> + } > >> > >> + > >> > >> + if ((Function !=3D > >> SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME) && > >> > >> + (Function !=3D SMM_VARIABLE_FUNCTION_GET_VARIABLE)) > >> > >> + { > >> > >> + Status =3D EFI_INVALID_PARAMETER; > >> > >> + DEBUG ((DEBUG_ERROR, "%a: Invalid function value: 0x%x\n", > >> __func__, Function)); > >> > >> + goto Exit; > >> > >> + } > >> > >> + > >> > >> + Status =3D PeiServicesLocatePpi (&gEfiPeiMmCommunicationPpiGuid, 0, > >> NULL, (VOID **)&MmCommunicationPpi); > >> > >> + if (EFI_ERROR (Status)) { > >> > >> + DEBUG ((DEBUG_ERROR, "%a: Failed to locate PEI MM > Communication > >> PPI: %r\n", __func__, Status)); > >> > >> + goto Exit; > >> > >> + } > >> > >> + > >> > >> + // Zero the entire Communication Buffer Header > >> > >> + MmCommunicateHeader =3D (EFI_MM_COMMUNICATE_HEADER > >> *)CommunicateBuffer; > >> > >> + > >> > >> + ZeroMem (MmCommunicateHeader, > >> SMM_COMMUNICATE_HEADER_SIZE); > >> > >> + > >> > >> + // Use gEfiSmmVariableProtocolGuid to request the MM variable > service > >> in Standalone MM > >> > >> + CopyMem ((VOID *)&MmCommunicateHeader->HeaderGuid, > >> &gEfiSmmVariableProtocolGuid, sizeof (GUID)); > >> > >> + > >> > >> + // Program the MM header size > >> > >> + MmCommunicateHeader->MessageLength =3D CommunicateBufferSize - > >> SMM_COMMUNICATE_HEADER_SIZE; > >> > >> + > >> > >> + MmVarCommsHeader =3D (SMM_VARIABLE_COMMUNICATE_HEADER > >> *)(CommunicateBuffer + SMM_COMMUNICATE_HEADER_SIZE); > >> > >> + > >> > >> + // We are only supporting GetVariable and GetNextVariableName > >> > >> + MmVarCommsHeader->Function =3D Function; > >> > >> + > >> > >> + // Send the MM request using MmCommunicationPei > >> > >> + Status =3D MmCommunicationPpi->Communicate > (MmCommunicationPpi, > >> CommunicateBuffer, &CommunicateBufferSize); > >> > >> + if (EFI_ERROR (Status)) { > >> > >> + // Received an error from MM interface. > >> > >> + DEBUG ((DEBUG_ERROR, "%a - MM Interface Error: %r\n", > __func__, > >> Status)); > >> > >> + goto Exit; > >> > >> + } > >> > >> + > >> > >> + // MM request was successfully handled by the framework. > >> > >> + // Set status to the Variable Service Status Code > >> > >> + Status =3D MmVarCommsHeader->ReturnStatus; > >> > >> + if (EFI_ERROR (Status)) { > >> > >> + // We received an error from Variable Service. > >> > >> + // We cant do anymore so return Status > >> > >> + if (Status !=3D EFI_BUFFER_TOO_SMALL) { > >> > >> + DEBUG ((DEBUG_ERROR, "%a - Variable Service Error: %r\n", > >> __func__, Status)); > >> > >> + } > >> > >> + > >> > >> + goto Exit; > >> > >> + } > >> > >> + > >> > >> +Exit: > >> > >> + return Status; > >> > >> +} > >> > >> + > >> > >> +/** > >> > >> + This service retrieves a variable's value using its name and GUID. > >> > >> + > >> > >> + This function is using the Secure Variable Store. If the Data > >> > >> + buffer is too small to hold the contents of the variable, the error > >> > >> + EFI_BUFFER_TOO_SMALL is returned and DataSize is set to the > required > >> buffer > >> > >> + size to obtain the data. > >> > >> + > >> > >> + @param This A pointer to this instance of the > >> EFI_PEI_READ_ONLY_VARIABLE2_PPI. > >> > >> + @param VariableName A pointer to a null-terminated > string > >> that is the variable's name. > >> > >> + @param VariableGuid A pointer to an EFI_GUID that is > the > >> variable's GUID. The combination of > >> > >> + VariableGuid and VariableName > >> must be unique. > >> > >> + @param Attributes If non-NULL, on return, points to > the > >> variable's attributes. > >> > >> + @param DataSize On entry, points to the size in > bytes > >> of the Data buffer. > >> > >> + On return, points to the size of > the > >> data returned in Data. > >> > >> + @param Data Points to the buffer which will > hold > >> the returned variable value. > >> > >> + May be NULL with a zero > DataSize in > >> order to determine the size of the buffer needed. > >> > >> + > >> > >> + @retval EFI_SUCCESS The variable was read successfully. > >> > >> + @retval EFI_NOT_FOUND The variable was not found. > >> > >> + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the > >> resulting data. > >> > >> + DataSize is updated with the size > >> required for > >> > >> + the specified variable. > >> > >> + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid, > DataSize > >> or Data is NULL. > >> > >> + @retval EFI_DEVICE_ERROR The variable could not be retrieved > >> because of a device error. > >> > >> + > >> > >> +**/ > >> > >> +EFI_STATUS > >> > >> +EFIAPI > >> > >> +PeiMmGetVariable ( > >> > >> + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, > >> > >> + IN CONST CHAR16 *VariableName, > >> > >> + IN CONST EFI_GUID *VariableGuid, > >> > >> + OUT UINT32 *Attributes, OPTIONAL > >> > >> + IN OUT UINTN *DataSize, > >> > >> + OUT VOID *Data > OPTIONAL > >> > >> + ) > >> > >> +{ > >> > >> + EFI_STATUS Status; > >> > >> + UINTN MessageSize; > >> > >> + SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE > >> *MmVarAccessHeader; > >> > >> + UINT8 > >> *MmCommunicateBuffer; > >> > >> + UINTN RequiredPages; > >> > >> + > >> > >> + // Check input parameters > >> > >> + if ((VariableName =3D=3D NULL) || (VariableGuid =3D=3D NULL) || (Da= taSize =3D=3D > >> NULL)) { > >> > >> + return EFI_INVALID_PARAMETER; > >> > >> + } > >> > >> + > >> > >> + if (VariableName[0] =3D=3D 0) { > >> > >> + return EFI_NOT_FOUND; > >> > >> + } > >> > >> + > >> > >> + if ((*DataSize > 0) && (Data =3D=3D NULL)) { > >> > >> + return EFI_INVALID_PARAMETER; > >> > >> + } > >> > >> + > >> > >> + // Allocate required pages to send MM request > >> > >> + MessageSize =3D MM_VARIABLE_COMM_BUFFER_OFFSET + > >> > >> + OFFSET_OF > >> (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + > >> > >> + StrSize (VariableName) + *DataSize; > >> > >> + > >> > >> + RequiredPages =3D EFI_SIZE_TO_PAGES (MessageSize); > >> > >> + MmCommunicateBuffer =3D (UINT8 *)AllocatePages (RequiredPages); > >> > >> + > >> > >> + if (MmCommunicateBuffer =3D=3D NULL) { > >> > >> + Status =3D EFI_OUT_OF_RESOURCES; > >> > >> + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate memory: %r\n", > >> __func__, Status)); > >> > >> + return Status; > >> > >> + } > >> > >> + > >> > >> + // Zero the entire Communication Buffer > >> > >> + ZeroMem (MmCommunicateBuffer, (RequiredPages * EFI_PAGE_SIZE)); > >> > >> + > >> > >> + // > >> > >> + // Program all payload structure contents > >> > >> + // > >> > >> + MmVarAccessHeader =3D > >> (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE > >> *)(MmCommunicateBuffer + MM_VARIABLE_COMM_BUFFER_OFFSET); > >> > >> + > >> > >> + // Variable GUID > >> > >> + CopyMem ((VOID *)&MmVarAccessHeader->Guid, VariableGuid, sizeof > >> (GUID)); > >> > >> + > >> > >> + // Program the max amount of data we accept. > >> > >> + MmVarAccessHeader->DataSize =3D *DataSize; > >> > >> + > >> > >> + // Get size of the variable name > >> > >> + MmVarAccessHeader->NameSize =3D StrSize (VariableName); > >> > >> + > >> > >> + // Populate incoming variable name > >> > >> + CopyMem ((VOID *)&MmVarAccessHeader->Name, VariableName, > >> MmVarAccessHeader->NameSize); > >> > >> + > >> > >> + Status =3D PopulateHeaderAndCommunicate (MmCommunicateBuffer, > >> MessageSize, SMM_VARIABLE_FUNCTION_GET_VARIABLE); > >> > >> + if (EFI_ERROR (Status)) { > >> > >> + // We received an error from either communicate or Variable > Service. > >> > >> + if (Status !=3D EFI_BUFFER_TOO_SMALL) { > >> > >> + DEBUG ((DEBUG_ERROR, "%a - Communite to MM for variable > >> service errored: %r\n", __func__, Status)); > >> > >> + } > >> > >> + > >> > >> + goto Exit; > >> > >> + } > >> > >> + > >> > >> + Status =3D EFI_SUCCESS; > >> > >> + > >> > >> + // User provided buffer is too small > >> > >> + if (*DataSize < MmVarAccessHeader->DataSize) { > >> > >> + Status =3D EFI_BUFFER_TOO_SMALL; > >> > >> + } > >> > >> + > >> > >> +Exit: > >> > >> + // Check if we need to set Attributes > >> > >> + if (Attributes !=3D NULL) { > >> > >> + *Attributes =3D MmVarAccessHeader->Attributes; > >> > >> + } > >> > >> + > >> > >> + *DataSize =3D MmVarAccessHeader->DataSize; > >> > >> + > >> > >> + if (Status =3D=3D EFI_SUCCESS) { > >> > >> + CopyMem ((VOID *)Data, (UINT8 *)MmVarAccessHeader->Name + > >> MmVarAccessHeader->NameSize, *DataSize); > >> > >> + } > >> > >> + > >> > >> + // Free the Communication Buffer > >> > >> + if (MmCommunicateBuffer !=3D NULL) { > >> > >> + FreePages (MmCommunicateBuffer, RequiredPages); > >> > >> + } > >> > >> + > >> > >> + return Status; > >> > >> +} > >> > >> + > >> > >> +/** > >> > >> + Return the next variable name and GUID. > >> > >> + > >> > >> + This function is called multiple times to retrieve the VariableName > >> > >> + and VariableGuid of all variables currently available in the system= . > >> > >> + On each call, the previous results are passed into the interface, > >> > >> + and, on return, the interface returns the data for the next > >> > >> + interface. When the entire variable list has been returned, > >> > >> + EFI_NOT_FOUND is returned. > >> > >> + > >> > >> + @param This A pointer to this instance of the > >> EFI_PEI_READ_ONLY_VARIABLE2_PPI. > >> > >> + > >> > >> + @param VariableNameSize On entry, points to the size of the > buffer > >> pointed to by VariableName. > >> > >> + On return, the size of the variable > name > >> buffer. > >> > >> + @param VariableName On entry, a pointer to a > null-terminated > >> string that is the variable's name. > >> > >> + On return, points to the next variable's > >> null-terminated name string. > >> > >> + > >> > >> + @param VariableGuid On entry, a pointer to an EFI_GUID that > is > >> the variable's GUID. > >> > >> + On return, a pointer to the next > variable's > >> GUID. > >> > >> + > >> > >> + @retval EFI_SUCCESS The variable was read successfully. > >> > >> + @retval EFI_NOT_FOUND The variable could not be found. > >> > >> + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too > small > >> for the resulting > >> > >> + data. VariableNameSize is > updated > >> with the size > >> > >> + required for the specified > variable. > >> > >> + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid or > >> > >> + VariableNameSize is NULL. > >> > >> + @retval EFI_DEVICE_ERROR The variable could not be retrieved > >> because of a device error. > >> > >> +**/ > >> > >> +EFI_STATUS > >> > >> +EFIAPI > >> > >> +PeiMmGetNextVariableName ( > >> > >> + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, > >> > >> + IN OUT UINTN > *VariableNameSize, > >> > >> + IN OUT CHAR16 *VariableName, > >> > >> + IN OUT EFI_GUID *VariableGuid > >> > >> + ) > >> > >> +{ > >> > >> + EFI_STATUS Status; > >> > >> + UINTN > >> MessageSize; > >> > >> + UINT8 > >> *MmCommunicateBuffer; > >> > >> + SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME > >> *MmVarGetNextVarHeader; > >> > >> + UINTN > >> RequiredPages; > >> > >> + > >> > >> + // Check input parameters > >> > >> + if ((VariableName =3D=3D NULL) || > >> > >> + (VariableGuid =3D=3D NULL) || > >> > >> + (VariableNameSize =3D=3D NULL) || > >> > >> + (*VariableNameSize =3D=3D 0)) > >> > >> + { > >> > >> + return EFI_INVALID_PARAMETER; > >> > >> + } > >> > >> + > >> > >> + // Allocate required pages to send MM request > >> > >> + MessageSize =3D MM_VARIABLE_COMM_BUFFER_OFFSET + > >> > >> + OFFSET_OF > >> (SMM_VARIABLE_COMMUNICATE_ACCESS_VARIABLE, Name) + > >> > >> + StrSize (VariableName) + *VariableNameSize; > >> > >> + > >> > >> + RequiredPages =3D EFI_SIZE_TO_PAGES (MessageSize); > >> > >> + MmCommunicateBuffer =3D (UINT8 *)AllocatePages (RequiredPages); > >> > >> + > >> > >> + if (MmCommunicateBuffer =3D=3D NULL) { > >> > >> + Status =3D EFI_OUT_OF_RESOURCES; > >> > >> + DEBUG ((DEBUG_ERROR, "%a: Failed to allocate memory: %r\n", > >> __func__, Status)); > >> > >> + return Status; > >> > >> + } > >> > >> + > >> > >> + // Zero the entire Communication Buffer > >> > >> + ZeroMem (MmCommunicateBuffer, (RequiredPages * EFI_PAGE_SIZE)); > >> > >> + > >> > >> + // > >> > >> + // Program all payload structure contents > >> > >> + // > >> > >> + MmVarGetNextVarHeader =3D > >> (SMM_VARIABLE_COMMUNICATE_GET_NEXT_VARIABLE_NAME > >> *)(MmCommunicateBuffer + MM_VARIABLE_COMM_BUFFER_OFFSET); > >> > >> + > >> > >> + // Variable GUID > >> > >> + CopyMem ((VOID *)&MmVarGetNextVarHeader->Guid, VariableGuid, > >> sizeof (GUID)); > >> > >> + > >> > >> + // Program the maximal length of name we can accept. > >> > >> + MmVarGetNextVarHeader->NameSize =3D *VariableNameSize; > >> > >> + > >> > >> + // Populate incoming variable name > >> > >> + CopyMem ((VOID *)&MmVarGetNextVarHeader->Name, > VariableName, > >> MmVarGetNextVarHeader->NameSize); > >> > >> + > >> > >> + // Send the MM request using MmCommunicationPei > >> > >> + Status =3D PopulateHeaderAndCommunicate (MmCommunicateBuffer, > >> MessageSize, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME); > >> > >> + if (EFI_ERROR (Status)) { > >> > >> + // We received an error from either communicate or Variable > Service. > >> > >> + if (Status !=3D EFI_BUFFER_TOO_SMALL) { > >> > >> + DEBUG ((DEBUG_ERROR, "%a - Communite to MM for variable > >> service errored: %r\n", __func__, Status)); > >> > >> + } > >> > >> + > >> > >> + goto Exit; > >> > >> + } > >> > >> + > >> > >> + Status =3D EFI_SUCCESS; > >> > >> + > >> > >> + // User provided buffer is too small > >> > >> + if (*VariableNameSize < MmVarGetNextVarHeader->NameSize) { > >> > >> + Status =3D EFI_BUFFER_TOO_SMALL; > >> > >> + } > >> > >> + > >> > >> +Exit: > >> > >> + // Update the name size to be returned > >> > >> + *VariableNameSize =3D MmVarGetNextVarHeader->NameSize; > >> > >> + > >> > >> + if (Status =3D=3D EFI_SUCCESS) { > >> > >> + CopyMem ((VOID *)VariableName, (UINT8 > >> *)MmVarGetNextVarHeader->Name, *VariableNameSize); > >> > >> + CopyMem ((VOID *)VariableGuid, (UINT8 > >> *)&(MmVarGetNextVarHeader->Guid), sizeof (EFI_GUID)); > >> > >> + } > >> > >> + > >> > >> + // Free the Communication Buffer > >> > >> + if (MmCommunicateBuffer !=3D NULL) { > >> > >> + FreePages (MmCommunicateBuffer, RequiredPages); > >> > >> + } > >> > >> + > >> > >> + return Status; > >> > >> +} > >> > >> diff --git a/MdeModulePkg/MdeModulePkg.dsc > >> b/MdeModulePkg/MdeModulePkg.dsc > >> index 5b1f50e9c084..1aedfe280ae1 100644 > >> --- a/MdeModulePkg/MdeModulePkg.dsc > >> +++ b/MdeModulePkg/MdeModulePkg.dsc > >> @@ -400,6 +400,7 @@ [Components] > >> MdeModulePkg/Application/VariableInfo/VariableInfo.inf > >> > >> > >> > MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf > >> > >> MdeModulePkg/Universal/Variable/Pei/VariablePei.inf > >> > >> + MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf > >> > >> MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf > >> > >> MdeModulePkg/Universal/TimestampDxe/TimestampDxe.inf > >> > >> > >> > MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf > >> > >> diff --git > >> a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h > >> b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h > >> new file mode 100644 > >> index 000000000000..0feed8cd1cb6 > >> --- /dev/null > >> +++ > b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.h > >> @@ -0,0 +1,134 @@ > >> +/** @file -- MmVariablePei.h > >> > >> + Provides interface for reading Secure System Variables during PEI. > >> > >> + > >> > >> + Copyright (c) Microsoft Corporation. > >> > >> + SPDX-License-Identifier: BSD-2-Clause-Patent > >> > >> +**/ > >> > >> + > >> > >> +#ifndef PEI_MM_VARIABLE_LIB_H_ > >> > >> +#define PEI_MM_VARIABLE_LIB_H_ > >> > >> + > >> > >> +#include > >> > >> +#include > >> > >> + > >> > >> +#include > >> > >> +#include > >> > >> +#include > >> > >> +#include > >> > >> +#include > >> > >> +#include > >> > >> +#include > >> > >> + > >> > >> +#include > >> > >> + > >> > >> +#include > >> > >> +#include > >> > >> + > >> > >> +#include > >> > >> +#include > >> > >> + > >> > >> +/** > >> > >> + Entry point of PEI Secure Variable read driver > >> > >> + > >> > >> + @param FileHandle Handle of the file being invoked. > >> > >> + Type EFI_PEI_FILE_HANDLE is defined in > >> FfsFindNextFile(). > >> > >> + @param PeiServices General purpose services available to every > >> PEIM. > >> > >> + > >> > >> + @retval EFI_SUCCESS If the interface could be successfully install= ed > >> > >> + @retval Others Returned from PeiServicesInstallPpi() > >> > >> +**/ > >> > >> +EFI_STATUS > >> > >> +EFIAPI > >> > >> +PeiMmVariableInitialize ( > >> > >> + IN EFI_PEI_FILE_HANDLE FileHandle, > >> > >> + IN CONST EFI_PEI_SERVICES **PeiServices > >> > >> + ); > >> > >> + > >> > >> +/** > >> > >> + > >> > >> + This function enables the read of Secure Variables during PEI. > >> > >> + > >> > >> + This function is using the Secure Variable Store.If the Data > >> > >> + buffer is too small to hold the contents of the variable, the error > >> > >> + EFI_BUFFER_TOO_SMALL is returned and DataSize is set to the > required > >> buffer > >> > >> + size to obtain the data. > >> > >> + > >> > >> + The function performs the following: > >> > >> + > >> > >> + 1) Creates an MM request > >> > >> + 2) Fills out the following data structures for the Secure Variable > > Service > >> + > >> > SMM_VARIABLE_COMMUNICATE_HEADER/SMM_VARIABLE_COMMUNICAT > >> E_ACCESS_VARIABLE > >> > >> + 3) Adds the MM data structures to the MM request. > >> > >> + 4) Sends the MM request to EL3 using MmCommunicationPeiLib. > >> > >> + 5) The MM request is sent to S-EL0. > >> > >> + 6) The MM request is then handled by the registered handler with > GUID: > >> gEfiSmmVariableProtocolGuid > >> > >> + > >> > >> + @param This A pointer to this instance of the > >> EFI_PEI_READ_ONLY_VARIABLE2_PPI. > >> > >> + @param VariableName A pointer to a null-terminated > string > >> that is the variable's name. > >> > >> + @param VariableGuid A pointer to an EFI_GUID that is > the > >> variable's GUID. The combination of > >> > >> + VariableGuid and VariableName > >> must be unique. > >> > >> + @param Attributes If non-NULL, on return, points to > the > >> variable's attributes. > >> > >> + @param DataSize On entry, points to the size in > bytes > >> of the Data buffer. > >> > >> + On return, points to the size of > the > >> data returned in Data. > >> > >> + @param Data Points to the buffer which will > hold > >> the returned variable value. > >> > >> + May be NULL with a zero > DataSize in > >> order to determine the size of the buffer needed. > >> > >> + > >> > >> + @retval EFI_SUCCESS The variable was read successfully. > >> > >> + @retval EFI_NOT_FOUND The variable was not found. > >> > >> + @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the > >> resulting data. > >> > >> + DataSize is updated with the size > >> required for > >> > >> + the specified variable. > >> > >> + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid, > DataSize > >> or Data is NULL. > >> > >> + @retval EFI_DEVICE_ERROR The variable could not be retrieved > >> because of a device error. > >> > >> + > >> > >> +**/ > >> > >> +EFI_STATUS > >> > >> +EFIAPI > >> > >> +PeiMmGetVariable ( > >> > >> + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, > >> > >> + IN CONST CHAR16 *VariableName, > >> > >> + IN CONST EFI_GUID *VariableGuid, > >> > >> + OUT UINT32 *Attributes, > >> > >> + IN OUT UINTN *DataSize, > >> > >> + OUT VOID *Data > OPTIONAL > >> > >> + ); > >> > >> + > >> > >> +/** > >> > >> + Return the next variable name and GUID. > >> > >> + > >> > >> + This function is called multiple times to retrieve the VariableName > >> > >> + and VariableGuid of all variables currently available in the system= . > >> > >> + On each call, the previous results are passed into the interface, > >> > >> + and, on return, the interface returns the data for the next > >> > >> + interface. When the entire variable list has been returned, > >> > >> + EFI_NOT_FOUND is returned. > >> > >> + > >> > >> + @param This A pointer to this instance of the > >> EFI_PEI_READ_ONLY_VARIABLE2_PPI. > >> > >> + > >> > >> + @param VariableNameSize On entry, points to the size of the > buffer > >> pointed to by VariableName. > >> > >> + On return, the size of the variable > name > >> buffer. > >> > >> + @param VariableName On entry, a pointer to a > null-terminated > >> string that is the variable's name. > >> > >> + On return, points to the next variable's > >> null-terminated name string. > >> > >> + > >> > >> + @param VariableGuid On entry, a pointer to an EFI_GUID that > is > >> the variable's GUID. > >> > >> + On return, a pointer to the next > variable's > >> GUID. > >> > >> + > >> > >> + @retval EFI_SUCCESS The variable was read successfully. > >> > >> + @retval EFI_NOT_FOUND The variable could not be found. > >> > >> + @retval EFI_BUFFER_TOO_SMALL The VariableNameSize is too > small > >> for the resulting > >> > >> + data. VariableNameSize is > updated > >> with the size > >> > >> + required for the specified > variable. > >> > >> + @retval EFI_INVALID_PARAMETER VariableName, VariableGuid or > >> > >> + VariableNameSize is NULL. > >> > >> + @retval EFI_DEVICE_ERROR The variable could not be retrieved > >> because of a device error. > >> > >> +**/ > >> > >> +EFI_STATUS > >> > >> +EFIAPI > >> > >> +PeiMmGetNextVariableName ( > >> > >> + IN CONST EFI_PEI_READ_ONLY_VARIABLE2_PPI *This, > >> > >> + IN OUT UINTN > *VariableNameSize, > >> > >> + IN OUT CHAR16 *VariableName, > >> > >> + IN OUT EFI_GUID *VariableGuid > >> > >> + ); > >> > >> + > >> > >> +#endif /* PEI_MM_VARIABLE_LIB_H_ */ > >> > >> diff --git > >> a/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf > >> b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf > >> new file mode 100644 > >> index 000000000000..d122703e9b5d > >> --- /dev/null > >> +++ > b/MdeModulePkg/Universal/Variable/MmVariablePei/MmVariablePei.inf > >> @@ -0,0 +1,43 @@ > >> +## @file -- MmVariablePei.inf > >> > >> +# Provides interface for reading Secure System Variables during PEI. > >> > >> +# > >> > >> +# Copyright (c) Microsoft Corporation. > >> > >> +# SPDX-License-Identifier: BSD-2-Clause-Patent > >> > >> +## > >> > >> + > >> > >> + > >> > >> +[Defines] > >> > >> + INF_VERSION =3D 0x00010005 > >> > >> + BASE_NAME =3D MmVariablePei > >> > >> + FILE_GUID =3D > >> CD660A87-454B-4346-A35C-3D89BF8ECFAF > >> > >> + MODULE_TYPE =3D PEIM > >> > >> + VERSION_STRING =3D 1.0 > >> > >> + ENTRY_POINT =3D PeiMmVariableInitialize > >> > >> + > >> > >> +[Sources] > >> > >> + MmVariablePei.c > >> > >> + MmVariablePei.h > >> > >> + > >> > >> +[Packages] > >> > >> + MdePkg/MdePkg.dec > >> > >> + MdeModulePkg/MdeModulePkg.dec > >> > >> + > >> > >> +[LibraryClasses] > >> > >> + PcdLib > >> > >> + PeiServicesLib > >> > >> + PeimEntryPoint > >> > >> + MemoryAllocationLib > >> > >> + HobLib > >> > >> + > >> > >> +[Pcd] > >> > >> + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize > >> > >> + > >> > >> +[Protocols] > >> > >> + gEfiSmmVariableProtocolGuid ## CONSUMES > >> > >> + > >> > >> +[Ppis] > >> > >> + gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES > >> > >> + gEfiPeiMmCommunicationPpiGuid ## CONSUMES > >> > >> + > >> > >> +[Depex] > >> > >> + gEfiPeiMmCommunicationPpiGuid > >> > >> -- > >> 2.40.1.windows.1 > >> > >> > >> > >> -=3D-=3D-=3D-=3D-=3D-=3D > >> Groups.io Links: You receive all messages sent to this group. > >> View/Reply Online (#105956): > >> https://edk2.groups.io/g/devel/message/105956 > >> Mute This Topic: https://groups.io/mt/99415826/4905953 > >> Group Owner: devel+owner@edk2.groups.io > >> Unsubscribe: https://edk2.groups.io/g/devel/unsub > >> [gaoliming@byosoft.com.cn] > >> -=3D-=3D-=3D-=3D-=3D-=3D > >> > > > > > > > > > > > > > > >=20 >=20 >=20 >=20