From nobody Fri Apr 26 07:40:07 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+70097+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+70097+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1610330066; cv=none; d=zohomail.com; s=zohoarc; b=GHAbEHU+PK+EHFDeRkQU960J3iS2/ZihjqslLkP1Gg3f1g8L/uM+FPDAmZcyWGgf0N7WOgUlcBtK8m+0DAMKsZD1MrgHTzo9XeTENUTt482qp4XiXugPZawtVRPWvM9xulvK6BsLe8nzldzM8RkNNQLZXY8bhpD+cyE4zXiCgZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610330066; h=Content-Transfer-Encoding:Cc:Date:From:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=o+XWRvE2cm6Kf1U5bSJdepSGQI1Q36yfi6E7SXVLtNc=; b=HDemSJs5qum2xpaNF/uTkgysSqr7j31Q5cUpnt4Dz/3ElGmlQSR2UJPkFXZYRzxxwKZ9baqYJJrItm9l3ufyacBQNy4AMhvSOnHpK4PbVxFmkkza8+rlOmTvSG2S7170ICaXbLMW9ANGp2oI1PNm+gAzWq4ALpx2n+U4ddnGBoE= 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+70097+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1610330066013414.2698183482705; Sun, 10 Jan 2021 17:54:26 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id mshrYY1788612xrZashedCsZ; Sun, 10 Jan 2021 17:54:25 -0800 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web08.27782.1610330064871386011 for ; Sun, 10 Jan 2021 17:54:25 -0800 IronPort-SDR: OTCLxbumqLHueQDCH5pCiCjjhAzBp1HGhLFGc0IXFULndwGzdeENEId1qvDTDPEuAxp42JDKyE FIYmnUwolmqA== X-IronPort-AV: E=McAfee;i="6000,8403,9860"; a="196374501" X-IronPort-AV: E=Sophos;i="5.79,337,1602572400"; d="scan'208";a="196374501" X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2021 17:54:23 -0800 IronPort-SDR: pNA5/rBq8jmaR8MT18GoetkMb/B78JJ9HV4Q0f9rmVsWC27eQeUdUkFY9xR86Jvslrqcv756Dt e5N7sE+q+oAQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,337,1602572400"; d="scan'208";a="403956814" X-Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.158.37]) by FMSMGA003.fm.intel.com with ESMTP; 10 Jan 2021 17:54:21 -0800 From: "Zeng, Star" To: devel@edk2.groups.io Cc: Star Zeng , Ray Ni , Laszlo Ersek , Eric Dong Subject: [edk2-devel] [PATCH V4] UefiCpuPkg PiSmmCpuDxeSmm: Reduce SMRAM consumption in CpuS3.c Date: Mon, 11 Jan 2021 09:54:19 +0800 Message-Id: <20210111015419.28368-1-star.zeng@intel.com> 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,star.zeng@intel.com X-Gm-Message-State: qm9WF8CEnHCFhpyXUdvHEwxCx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1610330065; bh=Pvp0O6GiQEw/RZ9KouDP9Cl4NMlmEEZIIMB+0ehfp4A=; h=Cc:Date:From:Reply-To:Subject:To; b=smuVb0rOM/ksFvF8SQHB/T7HFjpvm25GA60gG6H4XVMBCQBfoysJgc95vezCIEsnSxL eMJ9SnKe7yUBhyA4x3UTVSiWTx2ZPitg4lljqiDdP/P09WS9OSbXrjeBmPVNX1Nd7pZAg APKcjFaMFqBZuyWOFtQ6be8Qdtn1OZVV1c0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" This patch makes two refinements to reduce SMRAM consumption in CpuS3.c. 1. Only do CopyRegisterTable() when register table is not empty, IsRegisterTableEmpty() is created to check whether the register table is empty or not. Take empty PreSmmInitRegisterTable as example, about 24K SMRAM consumption could be reduced when mAcpiCpuData.NumberOfCpus=3D1024. sizeof (CPU_REGISTER_TABLE) =3D 24 mAcpiCpuData.NumberOfCpus =3D 1024 =3D 1K mAcpiCpuData.NumberOfCpus * sizeof (CPU_REGISTER_TABLE) =3D 24K 2. Only copy table entries buffer instead of whole buffer. AllocatedSize in SourceRegisterTableList is the whole buffer size. Actually, only the table entries buffer needs to be copied, and the size is TableLength * sizeof (CPU_REGISTER_TABLE_ENTRY). Take AllocatedSize=3D0x1000=3D4096, TableLength=3D100 and NumberOfCpus=3D= 1024 as example, about 1696K SMRAM consumption could be reduced. sizeof (CPU_REGISTER_TABLE_ENTRY) =3D 24 TableLength =3D 100 TableLength * sizeof (CPU_REGISTER_TABLE_ENTRY) =3D 2400 AllocatedSize =3D 0x1000 =3D 4096 AllocatedSize - TableLength * sizeof (CPU_REGISTER_TABLE_ENTRY) =3D 4096 = - 2400 =3D 1696 NumberOfCpus =3D 1024 =3D 1K NumberOfCpus * (AllocatedSize - TableLength * sizeof (CPU_REGISTER_TABLE_= ENTRY)) =3D 1696K This patch also corrects the CopyRegisterTable() function description. Signed-off-by: Star Zeng Reviewed-by: Ray Ni Reviewed-by: Laszlo Ersek Cc: Ray Ni Cc: Eric Dong Cc: Laszlo Ersek --- Notes: V2: Use "DestinationRegisterTableList[Index].TableLength * sizeof (CPU_R= EGISTER_TABLE_ENTRY)" directly to cover Ray's comment. V3: Handle "RegisterTable =3D=3D NULL" case to cover Laszlo's comment. V4: Add @param[in] for NumberOfCpus parameter of IsRegisterTableEmpty(). UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c | 74 ++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c b/UefiCpuPkg/PiSmmCpuDxeSmm/= CpuS3.c index 9592430636ec..ab7f39aa2bd4 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/CpuS3.c @@ -1,7 +1,7 @@ /** @file Code for Processor S3 restoration =20 -Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ @@ -487,6 +487,9 @@ SetRegister ( } else { RegisterTables =3D (CPU_REGISTER_TABLE *)(UINTN)mAcpiCpuData.RegisterT= able; } + if (RegisterTables =3D=3D NULL) { + return; + } =20 InitApicId =3D GetInitialApicId (); RegisterTable =3D NULL; @@ -948,7 +951,7 @@ InitSmmS3ResumeState ( } =20 /** - Copy register table from ACPI NVS memory into SMRAM. + Copy register table from non-SMRAM into SMRAM. =20 @param[in] DestinationRegisterTableList Points to destination register = table. @param[in] SourceRegisterTableList Points to source register table. @@ -967,7 +970,8 @@ CopyRegisterTable ( =20 CopyMem (DestinationRegisterTableList, SourceRegisterTableList, NumberOf= Cpus * sizeof (CPU_REGISTER_TABLE)); for (Index =3D 0; Index < NumberOfCpus; Index++) { - if (DestinationRegisterTableList[Index].AllocatedSize !=3D 0) { + if (DestinationRegisterTableList[Index].TableLength !=3D 0) { + DestinationRegisterTableList[Index].AllocatedSize =3D DestinationReg= isterTableList[Index].TableLength * sizeof (CPU_REGISTER_TABLE_ENTRY); RegisterTableEntry =3D AllocateCopyPool ( DestinationRegisterTableList[Index].AllocatedSize, (VOID *)(UINTN)SourceRegisterTableList[Index].RegisterTableEntry @@ -978,6 +982,34 @@ CopyRegisterTable ( } } =20 +/** + Check whether the register table is empty or not. + + @param[in] RegisterTable Point to the register table. + @param[in] NumberOfCpus Number of CPUs. + + @retval TRUE The register table is empty. + @retval FALSE The register table is not empty. +**/ +BOOLEAN +IsRegisterTableEmpty ( + IN CPU_REGISTER_TABLE *RegisterTable, + IN UINT32 NumberOfCpus + ) +{ + UINTN Index; + + if (RegisterTable !=3D NULL) { + for (Index =3D 0; Index < NumberOfCpus; Index++) { + if (RegisterTable[Index].TableLength !=3D 0) { + return FALSE; + } + } + } + + return TRUE; +} + /** Get ACPI CPU data. =20 @@ -1032,23 +1064,31 @@ GetAcpiCpuData ( =20 CopyMem ((VOID *)(UINTN)mAcpiCpuData.IdtrProfile, (VOID *)(UINTN)AcpiCpu= Data->IdtrProfile, sizeof (IA32_DESCRIPTOR)); =20 - mAcpiCpuData.PreSmmInitRegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)Al= locatePool (mAcpiCpuData.NumberOfCpus * sizeof (CPU_REGISTER_TABLE)); - ASSERT (mAcpiCpuData.PreSmmInitRegisterTable !=3D 0); + if (!IsRegisterTableEmpty ((CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->Pre= SmmInitRegisterTable, mAcpiCpuData.NumberOfCpus)) { + mAcpiCpuData.PreSmmInitRegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)= AllocatePool (mAcpiCpuData.NumberOfCpus * sizeof (CPU_REGISTER_TABLE)); + ASSERT (mAcpiCpuData.PreSmmInitRegisterTable !=3D 0); =20 - CopyRegisterTable ( - (CPU_REGISTER_TABLE *)(UINTN)mAcpiCpuData.PreSmmInitRegisterTable, - (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->PreSmmInitRegisterTable, - mAcpiCpuData.NumberOfCpus - ); + CopyRegisterTable ( + (CPU_REGISTER_TABLE *)(UINTN)mAcpiCpuData.PreSmmInitRegisterTable, + (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->PreSmmInitRegisterTable, + mAcpiCpuData.NumberOfCpus + ); + } else { + mAcpiCpuData.PreSmmInitRegisterTable =3D 0; + } =20 - mAcpiCpuData.RegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePool= (mAcpiCpuData.NumberOfCpus * sizeof (CPU_REGISTER_TABLE)); - ASSERT (mAcpiCpuData.RegisterTable !=3D 0); + if (!IsRegisterTableEmpty ((CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->Reg= isterTable, mAcpiCpuData.NumberOfCpus)) { + mAcpiCpuData.RegisterTable =3D (EFI_PHYSICAL_ADDRESS)(UINTN)AllocatePo= ol (mAcpiCpuData.NumberOfCpus * sizeof (CPU_REGISTER_TABLE)); + ASSERT (mAcpiCpuData.RegisterTable !=3D 0); =20 - CopyRegisterTable ( - (CPU_REGISTER_TABLE *)(UINTN)mAcpiCpuData.RegisterTable, - (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->RegisterTable, - mAcpiCpuData.NumberOfCpus - ); + CopyRegisterTable ( + (CPU_REGISTER_TABLE *)(UINTN)mAcpiCpuData.RegisterTable, + (CPU_REGISTER_TABLE *)(UINTN)AcpiCpuData->RegisterTable, + mAcpiCpuData.NumberOfCpus + ); + } else { + mAcpiCpuData.RegisterTable =3D 0; + } =20 // // Copy AP's GDT, IDT and Machine Check handler into SMRAM. --=20 2.21.0.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 (#70097): https://edk2.groups.io/g/devel/message/70097 Mute This Topic: https://groups.io/mt/79586940/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-