From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.151; helo=mga17.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E67D2208EB3E1 for ; Mon, 18 Feb 2019 21:33:48 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Feb 2019 21:33:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,387,1544515200"; d="scan'208";a="127507570" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga003.jf.intel.com with ESMTP; 18 Feb 2019 21:33:46 -0800 Received: from fmsmsx126.amr.corp.intel.com (10.18.125.43) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 18 Feb 2019 21:33:47 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX126.amr.corp.intel.com (10.18.125.43) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 18 Feb 2019 21:33:47 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.102]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.172]) with mapi id 14.03.0415.000; Tue, 19 Feb 2019 13:33:45 +0800 From: "Gao, Liming" To: "Zeng, Star" , "Bi, Dandan" , "edk2-devel@lists.01.org" CC: Max Knutsen , "Wang, Jian J" , "Wu, Hao A" , Michael Turner Thread-Topic: [patch V4] MdeModulePkg/ReportStatusCodeLib: Avoid using AllocatePool if possible Thread-Index: AQHUx48qMZKYkd/tIkGl9t5zvp7zwaXlFVyAgAGE1YA= Date: Tue, 19 Feb 2019 05:33:44 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E3E114E@SHSMSX104.ccr.corp.intel.com> References: <20190218133729.70284-1-dandan.bi@intel.com> <0C09AFA07DD0434D9E2A0C6AEB0483104026EFA6@shsmsx102.ccr.corp.intel.com> In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483104026EFA6@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZjQ5MzA5ZDAtYWRmYi00MWUwLTk2MjAtNTJlMGZlMzJjNmI0IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiNXdCREQxVFZidzNEN3c2c0d1NkVsbVlyQXBNTDRtNjIyWldURjM4anNvd1BhZ1RGeTZGUFJzMVBNbGhRZ2lXUCJ9 dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [patch V4] MdeModulePkg/ReportStatusCodeLib: Avoid using AllocatePool if possible X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Feb 2019 05:33:49 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao > -----Original Message----- > From: Zeng, Star > Sent: Monday, February 18, 2019 10:22 PM > To: Bi, Dandan ; edk2-devel@lists.01.org > Cc: Max Knutsen ; Wang, Jian J ; Wu, Hao A ; Michael Turner > ; Gao, Liming ; Zeng,= Star > Subject: RE: [patch V4] MdeModulePkg/ReportStatusCodeLib: Avoid using All= ocatePool if possible >=20 > Reviewed-by: Star Zeng . >=20 > -----Original Message----- > From: Bi, Dandan > Sent: Monday, February 18, 2019 9:37 PM > To: edk2-devel@lists.01.org > Cc: Max Knutsen ; Zeng, Star ; Wang, Jian J ; Wu, Hao A > ; Michael Turner ; Gao,= Liming > Subject: [patch V4] MdeModulePkg/ReportStatusCodeLib: Avoid using Allocat= ePool if possible >=20 > From: Max Knutsen >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1114 >=20 > V2: simplify the code logic. > update > if (!mHaveExitedBootServices && > (StatusCodeData !=3D (EFI_STATUS_CODE_DATA *) StatusCodeBuffer)) { > gBS->FreePool (StatusCodeData); > } > to > if (StatusCodeData !=3D (EFI_STATUS_CODE_DATA *) StatusCodeBuffer) { > gBS->FreePool (StatusCodeData); > } >=20 > V3: > And the code below into the else condition (stack buffer is not enough) i= n /DxeReportStatusCodeLib/ReportStatusCodeLib.c >=20 > if (gBS =3D=3D NULL || gBS->AllocatePool =3D=3D NULL || gBS->FreePool = =3D=3D NULL) { > return EFI_UNSUPPORTED; > } >=20 > V4: > Refine code logic. >=20 > When report status code with ExtendedData data, and the extended data can= fit in the local static buffer, there is no need to use > AllocatePool to hold the ExtendedData data. >=20 > This patch is just to do the enhancement to avoid using AllocatePool. >=20 > Cc: Star Zeng > Cc: Jian J Wang > Cc: Hao Wu > Cc: Michael Turner > Cc: Liming Gao > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Dandan Bi > --- > .../ReportStatusCodeLib.c | 45 +++++++++---------- > .../ReportStatusCodeLib.c | 14 +++--- > 2 files changed, 30 insertions(+), 29 deletions(-) >=20 > diff --git a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCode= Lib.c > b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c > index b28dc5c3bb..d3cf8b1de3 100644 > --- a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c > +++ b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c > @@ -494,41 +494,38 @@ ReportStatusCodeEx ( > UINT64 Buffer[(MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)= ) + 1]; >=20 > ASSERT (!((ExtendedData =3D=3D NULL) && (ExtendedDataSize !=3D 0))); > ASSERT (!((ExtendedData !=3D NULL) && (ExtendedDataSize =3D=3D 0))); >=20 > - if (gBS =3D=3D NULL || gBS->AllocatePool =3D=3D NULL || gBS->FreePool = =3D=3D NULL) { > - return EFI_UNSUPPORTED; > - } > - > - // > - // Retrieve the current TPL > - // > - Tpl =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); > - gBS->RestoreTPL (Tpl); > + if (ExtendedDataSize <=3D (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS= _CODE_DATA))) { > + // > + // Use Buffer instead of allocating if possible. > + // > + StatusCodeData =3D (EFI_STATUS_CODE_DATA *)Buffer; } else { > + if (gBS =3D=3D NULL || gBS->AllocatePool =3D=3D NULL || gBS->FreePoo= l =3D=3D NULL) { > + return EFI_UNSUPPORTED; > + } >=20 > - StatusCodeData =3D NULL; > - if (Tpl <=3D TPL_NOTIFY) { > // > - // Allocate space for the Status Code Header and its buffer > + // Retrieve the current TPL > // > - gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA= ) + ExtendedDataSize, (VOID **)&StatusCodeData); > - } > + Tpl =3D gBS->RaiseTPL (TPL_HIGH_LEVEL); > + gBS->RestoreTPL (Tpl); > + > + if (Tpl > TPL_NOTIFY) { > + return EFI_OUT_OF_RESOURCES; > + } >=20 > - if (StatusCodeData =3D=3D NULL) { > // > - // If a buffer could not be allocated, then see if the local variabl= e Buffer can be used > + // Allocate space for the Status Code Header and its buffer > // > - if (ExtendedDataSize > (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_= CODE_DATA))) { > - // > - // The local variable Buffer not large enough to hold the extended= data associated > - // with the status code being reported. > - // > - DEBUG ((EFI_D_ERROR, "Status code extended data is too large to be= reported!\n")); > + StatusCodeData =3D NULL; > + gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA= ) + ExtendedDataSize, (VOID **)&StatusCodeData); > + if (StatusCodeData =3D=3D NULL) { > return EFI_OUT_OF_RESOURCES; > } > - StatusCodeData =3D (EFI_STATUS_CODE_DATA *)Buffer; > } >=20 > // > // Fill in the extended data header > // > @@ -626,6 +623,6 @@ EFIAPI > ReportDebugCodeEnabled ( > VOID > ) > { > return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_= STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) !=3D 0); > -} > +} > \ No newline at end of file > diff --git a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportSta= tusCodeLib.c > b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.= c > index b73103517a..9b79854538 100644 > --- a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCode= Lib.c > +++ b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCod > +++ eLib.c > @@ -630,16 +630,20 @@ ReportStatusCodeEx ( > UINT64 StatusCodeBuffer[(MAX_EXTENDED_DATA_SIZE / sizeo= f (UINT64)) + 1]; >=20 > ASSERT (!((ExtendedData =3D=3D NULL) && (ExtendedDataSize !=3D 0))); > ASSERT (!((ExtendedData !=3D NULL) && (ExtendedDataSize =3D=3D 0))); >=20 > - if (mHaveExitedBootServices) { > - if (sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize > MAX_EXTENDED_= DATA_SIZE) { > + if (ExtendedDataSize <=3D (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS= _CODE_DATA))) { > + // > + // Use Buffer instead of allocating if possible. > + // > + StatusCodeData =3D (EFI_STATUS_CODE_DATA *) StatusCodeBuffer; } els= e > + { > + if (mHaveExitedBootServices) { > return EFI_OUT_OF_RESOURCES; > } > - StatusCodeData =3D (EFI_STATUS_CODE_DATA *) StatusCodeBuffer; > - } else { > + > if (gBS =3D=3D NULL || gBS->AllocatePool =3D=3D NULL || gBS->FreePoo= l =3D=3D NULL) { > return EFI_UNSUPPORTED; > } >=20 > // > @@ -678,11 +682,11 @@ ReportStatusCodeEx ( > Status =3D InternalReportStatusCode (Type, Value, Instance, CallerId, = StatusCodeData); >=20 > // > // Free the allocated buffer > // > - if (!mHaveExitedBootServices) { > + if (StatusCodeData !=3D (EFI_STATUS_CODE_DATA *) StatusCodeBuffer) { > gBS->FreePool (StatusCodeData); > } >=20 > return Status; > } > -- > 2.18.0.windows.1