From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 5927482214 for ; Fri, 3 Mar 2017 05:40:36 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Mar 2017 05:40:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,237,1484035200"; d="scan'208";a="72392357" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga006.fm.intel.com with ESMTP; 03 Mar 2017 05:40:35 -0800 Received: from fmsmsx158.amr.corp.intel.com (10.18.116.75) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.248.2; Fri, 3 Mar 2017 05:40:35 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx158.amr.corp.intel.com (10.18.116.75) with Microsoft SMTP Server (TLS) id 14.3.248.2; Fri, 3 Mar 2017 05:40:35 -0800 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.88]) by SHSMSX103.ccr.corp.intel.com ([10.239.4.69]) with mapi id 14.03.0248.002; Fri, 3 Mar 2017 21:40:33 +0800 From: "Yao, Jiewen" To: Ard Biesheuvel , "edk2-devel@lists.01.org" , "Gao, Liming" , "Zeng, Star" Thread-Topic: [edk2] [PATCH v3] MdeModulePkg/PeiCore: honour minimal runtime allocation granularity Thread-Index: AQHSlALEpmza7voUUEGAQdS9HLtMq6GDHLIw Date: Fri, 3 Mar 2017 13:40:32 +0000 Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503A8F904F@shsmsx102.ccr.corp.intel.com> References: <1488534218-25315-1-git-send-email-ard.biesheuvel@linaro.org> In-Reply-To: <1488534218-25315-1-git-send-email-ard.biesheuvel@linaro.org> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v3] MdeModulePkg/PeiCore: honour minimal runtime allocation granularity X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Mar 2017 13:40:36 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Ard Thanks to close the gap in PEI memory allocation. I found we use below in DXE core. The definition is slight different with t= he one you add in PEI core. Since the calling convention is defined in UEFI spec, do you think it will = be better if we can move below to MdePkg? Maybe in ProcessorBind.h, because we already define CPU_STACK_ALIGNMENT the= re. The benefit is that we do not need duplicate the same definition in PEI cor= e. In the future, new ARCH can also define same thing there, instead of checki= ng DXE/PEI core. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D #if defined (MDE_CPU_IPF) /// /// For Itanium machines make the default allocations 8K aligned /// #define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE * 2) #define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE * 2) #elif defined (MDE_CPU_AARCH64) /// /// 64-bit ARM systems allow the OS to execute with 64 KB page size, /// so for improved interoperability with the firmware, align the /// runtime regions to 64 KB as well /// #define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (SIZE_64KB) #define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE) #else /// /// For generic EFI machines make the default allocations 4K aligned /// #define EFI_ACPI_RUNTIME_PAGE_ALLOCATION_ALIGNMENT (EFI_PAGE_SIZE) #define DEFAULT_PAGE_ALLOCATION (EFI_PAGE_SIZE) #endif =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ar= d > Biesheuvel > Sent: Friday, March 3, 2017 5:44 PM > To: edk2-devel@lists.01.org; Gao, Liming ; Zeng, St= ar > > Cc: Ard Biesheuvel > Subject: [edk2] [PATCH v3] MdeModulePkg/PeiCore: honour minimal runtime > allocation granularity >=20 > Architectures such as AArch64 may run the OS with 16 KB or 64 KB sized > pages, and for this reason, the UEFI spec mandates a minimal allocation > granularity of 64 KB for regions that may require different memory > attributes at OS runtime. >=20 > So make PeiCore's implementation of AllocatePages () take this into > account as well. >=20 > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Ard Biesheuvel > --- > v3: allocate a memory allocation HOB to cover the memory lost to rounding >=20 > MdeModulePkg/Core/Pei/Memory/MemoryServices.c | 39 > +++++++++++++++++++- > MdeModulePkg/Core/Pei/PeiMain.h | 18 +++++++++ > 2 files changed, 55 insertions(+), 2 deletions(-) >=20 > diff --git a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c > b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c > index 4efe14313ca5..573fd606b4cc 100644 > --- a/MdeModulePkg/Core/Pei/Memory/MemoryServices.c > +++ b/MdeModulePkg/Core/Pei/Memory/MemoryServices.c > @@ -140,6 +140,8 @@ PeiAllocatePages ( > EFI_PHYSICAL_ADDRESS *FreeMemoryTop; > EFI_PHYSICAL_ADDRESS *FreeMemoryBottom; > UINTN RemainingPages; > + UINTN Granularity; > + UINTN Padding; >=20 > if ((MemoryType !=3D EfiLoaderCode) && > (MemoryType !=3D EfiLoaderData) && > @@ -153,6 +155,20 @@ PeiAllocatePages ( > return EFI_INVALID_PARAMETER; > } >=20 > + Granularity =3D DEFAULT_PAGE_ALLOCATION_GRANULARITY; > + > + if (RUNTIME_PAGE_ALLOCATION_GRANULARITY > > DEFAULT_PAGE_ALLOCATION_GRANULARITY && > + (MemoryType =3D=3D EfiACPIReclaimMemory || > + MemoryType =3D=3D EfiACPIMemoryNVS || > + MemoryType =3D=3D EfiRuntimeServicesCode || > + MemoryType =3D=3D EfiRuntimeServicesData)) { > + > + Granularity =3D RUNTIME_PAGE_ALLOCATION_GRANULARITY; > + > + DEBUG ((DEBUG_INFO, "AllocatePages: rounding up allocation to %d > KB\n", > + Granularity)); > + } > + > PrivateData =3D PEI_CORE_INSTANCE_FROM_PS_THIS (PeiServices); > Hob.Raw =3D PrivateData->HobList.Raw; >=20 > @@ -176,9 +192,27 @@ PeiAllocatePages ( > } >=20 > // > - // Check to see if on 4k boundary, If not aligned, make the allocation= aligned. > + // Check to see if on correct boundary for the memory type. > + // If not aligned, make the allocation aligned. > // > - *(FreeMemoryTop) -=3D *(FreeMemoryTop) & 0xFFF; > + Padding =3D *(FreeMemoryTop) & (Granularity - 1); > + if ((UINTN) (*FreeMemoryTop - *FreeMemoryBottom) < Padding) { > + DEBUG ((DEBUG_ERROR, "AllocatePages failed: Out of space after > padding.\n")); > + return EFI_OUT_OF_RESOURCES; > + } > + > + *(FreeMemoryTop) -=3D Padding; > + if (Padding >=3D EFI_PAGE_SIZE) { > + // > + // Create a memory allocation HOB to cover > + // the pages that we will lose to rounding > + // > + BuildMemoryAllocationHob ( > + *(FreeMemoryTop), > + Padding & ~((UINTN)EFI_PAGE_SIZE - 1), > + EfiConventionalMemory > + ); > + } >=20 > // > // Verify that there is sufficient memory to satisfy the allocation. > @@ -192,6 +226,7 @@ PeiAllocatePages ( > // > // The number of remaining pages needs to be greater than or equal to = that > of the request pages. > // > + Pages =3D ALIGN_VALUE (Pages, EFI_SIZE_TO_PAGES (Granularity)); > if (RemainingPages < Pages) { > DEBUG ((EFI_D_ERROR, "AllocatePages failed: No 0x%lx Pages is > available.\n", (UINT64) Pages)); > DEBUG ((EFI_D_ERROR, "There is only left 0x%lx pages memory resource= to > be allocated.\n", (UINT64) RemainingPages)); > diff --git a/MdeModulePkg/Core/Pei/PeiMain.h > b/MdeModulePkg/Core/Pei/PeiMain.h > index 69eea514920b..e8358d3c4e6d 100644 > --- a/MdeModulePkg/Core/Pei/PeiMain.h > +++ b/MdeModulePkg/Core/Pei/PeiMain.h > @@ -55,6 +55,24 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY > KIND, EITHER EXPRESS OR IMPLIED. > /// > #define PEI_CORE_INTERNAL_FFS_FILE_DISPATCH_TYPE 0xff >=20 > +#if defined (MDE_CPU_AARCH64) > +/// > +/// 64-bit ARM systems allow the OS to execute with 64 KB page size, > +/// so for improved interoperability with the firmware, align the > +/// runtime regions to 64 KB as well > +/// > +#define RUNTIME_PAGE_ALLOCATION_GRANULARITY (SIZE_64KB) > +#define DEFAULT_PAGE_ALLOCATION_GRANULARITY (EFI_PAGE_SIZE) > + > +#else > +/// > +/// For generic EFI machines make the default allocations 4K aligned > +/// > +#define RUNTIME_PAGE_ALLOCATION_GRANULARITY (EFI_PAGE_SIZE) > +#define DEFAULT_PAGE_ALLOCATION_GRANULARITY (EFI_PAGE_SIZE) > + > +#endif > + > /// > /// Pei Core private data structures > /// > -- > 2.7.4 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel