From nobody Sat May 4 22:49:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+68312+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+68312+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1607050130; cv=none; d=zohomail.com; s=zohoarc; b=m2zouFCrCxSeA/Y/dUVLBfXHdmIcFpUHUQcU1dtQ4gfiL08ze/ZM9tl2ssuMMXZFr3LQcqgq9/aqT/9wkUJbE2UJGn0+ilHkYZw4tkrsli+x27xl0AbrN0oi9XX/K8UHf9YeNuFJ0vd+TFz2CL0kTqmqRlXC1OkniE7Bu5kBLxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607050130; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=9gq8jPSDQddBJRSghcax3ODxrFe8N/tFb6TZj1Rbh5I=; b=ep1eVJqRzRbRVlbPZP3kQUhDiDUEHTjUr8FCrTUFBkuEFzUqxXYVKq99SGcr6D+GsOkjZGDBQIamK1OIRYpFg/XakxZblS2WWmAJh2RySUC4RyzmeFGpOHo+S6d/symnRTBpNYmseHPqrJ9Z5lcfd9rIC0IY7oCD0r37aPvhMWg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+68312+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1607050130784222.18777768685788; Thu, 3 Dec 2020 18:48:50 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 291NYY1788612xi1GhUurALy; Thu, 03 Dec 2020 18:48:50 -0800 X-Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by mx.groups.io with SMTP id smtpd.web10.8894.1607050128075666418 for ; Thu, 03 Dec 2020 18:48:49 -0800 X-Received: from localhost.localdomain ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Fri, 04 Dec 2020 10:48:44 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming" To: devel@edk2.groups.io Cc: zengzhi , Jian J Wang , Hao A Wu , Dandan Bi Subject: [edk2-devel] [PATCH] MdeModulePkg/Pcdpeim: Fixed PcdGetPtr() caused memory wasting. Date: Fri, 4 Dec 2020 10:48:32 +0800 Message-Id: <20201204024832.1384-1-gaoliming@byosoft.com.cn> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gaoliming@byosoft.com.cn X-Gm-Message-State: yss8Nc3sWn5LXXKIBUnSfZO7x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1607050130; bh=/Wd5cWriVSBrLdCULw5W7xU3olo8UQudZTv2N0GVazc=; h=Cc:Date:From:Reply-To:Subject:To; b=W4lRup4RltpJWNy8/DhdWKf3k1j+Eev9+KCdVrL6wwRJ5nx+6PcbtvCfnRgbRTCSZge v0i7f4Fgc9+X9rMg/WNIZPsFT1XRIfHSJBY+/CcwgLFGi65cLdP3lKxisrHWx9FVbXwPu vlwh3flC8sw67fASPJkkJ7pQa7TYl8mrUPU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: zengzhi REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2964 GuidHob was added to cache the VariableGuid,VariableName,VariableData. Cc: Jian J Wang Cc: Hao A Wu Cc: Dandan Bi Cc: Liming Gao Signed-off-by: zengzhi --- MdeModulePkg/Universal/PCD/Pei/Service.c | 55 ++++++++++++++++++++---- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/MdeModulePkg/Universal/PCD/Pei/Service.c b/MdeModulePkg/Univer= sal/PCD/Pei/Service.c index 5b037353ad..c13be25a31 100644 --- a/MdeModulePkg/Universal/PCD/Pei/Service.c +++ b/MdeModulePkg/Universal/PCD/Pei/Service.c @@ -452,6 +452,7 @@ BuildPcdDatabase ( return Database; } =20 +EFI_GUID mGetVariableGuid =3D { 0x2f5a9b0e, 0xc338, 0x4f95, { 0xa8, 0x39, = 0xf3, 0x8d, 0x27, 0xa2, 0x80, 0xc2 } }; /** The function is provided by PCD PEIM and PCD DXE driver to do the work of reading a HII variable from variable service. @@ -474,13 +475,36 @@ GetHiiVariable ( { UINTN Size; EFI_STATUS Status; - VOID *Buffer; + UINTN DataLength; + VOID *HobData; + UINT8 *GetGuidHobData; + EFI_HOB_GUID_TYPE *GuidHob; EFI_PEI_READ_ONLY_VARIABLE2_PPI *VariablePpi; - + // Get the variable from the Guid Hob first, return it if found, + // and use the getVarible() function if not found. + GuidHob =3D GetFirstGuidHob (&mGetVariableGuid); + while (GuidHob !=3D NULL) { + GetGuidHobData =3D GET_GUID_HOB_DATA (GuidHob); + if (CompareGuid((EFI_GUID *) (GetGuidHobData + sizeof(UINT32)), Variab= leGuid) && + StrnCmp((VOID *) (GetGuidHobData + sizeof(UINT32) + sizeof(EFI_GUID)= ), VariableName, StrLen(VariableName)) =3D=3D 0){ + // If the variableGuid and variableName in the HOB are the same as + // the input variableGuid and variableName, the VariableData and Si= ze + // in the HOB are returned as output values. + *VariableSize =3D *((UINT32 *) GetGuidHobData); + *VariableData =3D (VOID *) (GetGuidHobData + sizeof(UINT32) + sizeof= (EFI_GUID) + StrSize(VariableName)); + return EFI_SUCCESS; + } else { + GuidHob =3D GetNextGuidHob (&mGetVariableGuid, GET_NEXT_HOB (GuidHob= )); + } + } + // Load the PeiReadOnlyVariable2 PPI, which provides a service to read E= FI Variable. + // If the load is unsuccessful, the function cannot be continued. Status =3D PeiServicesLocatePpi (&gEfiPeiReadOnlyVariable2PpiGuid, 0, NU= LL, (VOID **) &VariablePpi); ASSERT_EFI_ERROR (Status); =20 Size =3D 0; + // EFI Variable is read with an empty Buffer, and if an EFI Variable exi= sts, + // it returns the actual required Buffer size. Status =3D VariablePpi->GetVariable ( VariablePpi, VariableName, @@ -491,22 +515,35 @@ GetHiiVariable ( ); =20 if (Status =3D=3D EFI_BUFFER_TOO_SMALL) { - Status =3D PeiServicesAllocatePool (Size, &Buffer); - ASSERT_EFI_ERROR (Status); - + // DataLength + // ------------------------------------------------------------- + // | VariableSize | VariableGuid | VariableName | VariableData | + // ------------------------------------------------------------- + DataLength =3D sizeof(UINT32) + sizeof(EFI_GUID) + StrSize(VariableNam= e) + Size; + HobData =3D BuildGuidHob( + &mGetVariableGuid, + DataLength + ); + // The VariableSize VariableGuid, VariableName, VariableData copy to G= uidHob in turn. + CopyMem (HobData, (VOID *) &Size, sizeof(Size)); + HobData =3D (VOID *) ((UINT8 *) HobData + sizeof(UINT32)); + CopyMem (HobData, VariableGuid, sizeof(EFI_GUID)); + HobData =3D (VOID *) ((UINT8 *) HobData + sizeof (EFI_GUID)); + CopyMem (HobData, VariableName, StrSize(VariableName)); + HobData =3D (VOID *) ((UINT8 *) HobData + StrSize(VariableName)); + // Read EFI Variable into Guidhob. After a successful read, + // the read data is returned as the output value. Status =3D VariablePpi->GetVariable ( VariablePpi, (UINT16 *) VariableName, (EFI_GUID *) VariableGuid, NULL, &Size, - Buffer + HobData ); ASSERT_EFI_ERROR (Status); - *VariableSize =3D Size; - *VariableData =3D Buffer; - + *VariableData =3D HobData; return EFI_SUCCESS; } =20 --=20 2.26.2.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#68312): https://edk2.groups.io/g/devel/message/68312 Mute This Topic: https://groups.io/mt/78701670/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-