From patchwork Thu Jan 8 18:48:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 42885 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6748326CFF for ; Thu, 8 Jan 2015 18:49:24 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id b13sf2235208wgh.1 for ; Thu, 08 Jan 2015 10:49:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=SngHLyR7YTyMUCN8/xOCaKbfOUfXiZzYMxL1NoyPSsw=; b=etB9A2lAIxkneV6Luzw7aktk4N5DVzQZmYEHj3T80XD6Eqkc8Rowz6+A772erAtZOO aCBGhn3uv89PgWERIrUWqCblNbfLUbpc1w8/bCtmBp4eIoUQ8UTDqxDh9wMbzAExhHzv ebfEn8Jje4uap4fD3/slVEmlzM/0aSj1xVF6XWFCGRjc/9pqHYqsenyoGYCMXWVMWLqz ZlqEGOglKxT/z4OODwPeBLf9b532inZlTFrmBW/PIWtzk7YxmyzFVCvHY5G/34Oilp9Z a3js5bc0CZX/fd2JFM3UUC9wsXqdfG5feCrZ51M1sCuBAimJgVTwbnh9mHnPfnki0lDu 1mWQ== X-Gm-Message-State: ALoCoQlbZq2/+oVHNdp7cSef9TnocgRNPba5bSPesf6fA8yk3INJv+/hEYKB6syy83R8ZegQeaOT X-Received: by 10.194.204.201 with SMTP id la9mr12507wjc.6.1420742963636; Thu, 08 Jan 2015 10:49:23 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.41 with SMTP id t9ls102766lal.99.gmail; Thu, 08 Jan 2015 10:49:23 -0800 (PST) X-Received: by 10.152.5.67 with SMTP id q3mr16404250laq.73.1420742963453; Thu, 08 Jan 2015 10:49:23 -0800 (PST) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id ci4si10074477lad.93.2015.01.08.10.49.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 08 Jan 2015 10:49:21 -0800 (PST) Received-SPF: temperror (google.com: error in processing during lookup of patch+caf_=patchwork-forward=linaro.org@linaro.org: DNS timeout) client-ip=209.85.215.49; Received: by mail-la0-f49.google.com with SMTP id hs14so10812984lab.8 for ; Thu, 08 Jan 2015 10:49:21 -0800 (PST) X-Received: by 10.152.87.12 with SMTP id t12mr16520716laz.31.1420742961328; Thu, 08 Jan 2015 10:49:21 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.9.200 with SMTP id c8csp89990lbb; Thu, 8 Jan 2015 10:49:20 -0800 (PST) X-Received: by 10.66.157.67 with SMTP id wk3mr17181100pab.95.1420742959122; Thu, 08 Jan 2015 10:49:19 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ao1si9843602pad.182.2015.01.08.10.49.18; Thu, 08 Jan 2015 10:49:19 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757265AbbAHStN (ORCPT + 27 others); Thu, 8 Jan 2015 13:49:13 -0500 Received: from mail-we0-f172.google.com ([74.125.82.172]:51408 "EHLO mail-we0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757244AbbAHStJ (ORCPT ); Thu, 8 Jan 2015 13:49:09 -0500 Received: by mail-we0-f172.google.com with SMTP id k11so4077807wes.3 for ; Thu, 08 Jan 2015 10:49:08 -0800 (PST) X-Received: by 10.194.177.193 with SMTP id cs1mr22609462wjc.124.1420742948371; Thu, 08 Jan 2015 10:49:08 -0800 (PST) Received: from ards-macbook-pro.local ([197.131.128.104]) by mx.google.com with ESMTPSA id gf6sm7204081wjc.11.2015.01.08.10.49.04 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 08 Jan 2015 10:49:07 -0800 (PST) From: Ard Biesheuvel To: leif.lindholm@linaro.org, roy.franz@linaro.org, matt.fleming@intel.com, will.deacon@arm.com, catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, bp@alien8.de, msalter@redhat.com, geoff.levand@linaro.org, dyoung@redhat.com, mark.rutland@arm.com, linux-kernel@vger.kernel.org Cc: Ard Biesheuvel Subject: [PATCH v5 4/8] efi: efistub: allow allocation alignment larger than EFI_PAGE_SIZE Date: Thu, 8 Jan 2015 18:48:30 +0000 Message-Id: <1420742914-2404-5-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1420742914-2404-1-git-send-email-ard.biesheuvel@linaro.org> References: <1420742914-2404-1-git-send-email-ard.biesheuvel@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=temperror (google.com: error in processing during lookup of patch+caf_=patchwork-forward=linaro.org@linaro.org: DNS timeout) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , On systems with 64 KB pages, it is preferable for UEFI memory map entries to be 64 KB aligned multiples of 64 KB, because it relieves us of having to deal with the residues. So, if EFI_ALLOC_ALIGN is #define'd by the platform, use it to round up all memory allocations made. Acked-by: Matt Fleming Acked-by: Borislav Petkov Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub-helper.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index a920fec8fe88..e766df60fbfb 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -32,6 +32,15 @@ static unsigned long __chunk_size = EFI_READ_CHUNK_SIZE; +/* + * Allow the platform to override the allocation granularity: this allows + * systems that have the capability to run with a larger page size to deal + * with the allocations for initrd and fdt more efficiently. + */ +#ifndef EFI_ALLOC_ALIGN +#define EFI_ALLOC_ALIGN EFI_PAGE_SIZE +#endif + struct file_info { efi_file_handle_t *handle; u64 size; @@ -150,10 +159,10 @@ efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg, * a specific address. We are doing page-based allocations, * so we must be aligned to a page. */ - if (align < EFI_PAGE_SIZE) - align = EFI_PAGE_SIZE; + if (align < EFI_ALLOC_ALIGN) + align = EFI_ALLOC_ALIGN; - nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; + nr_pages = round_up(size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE; again: for (i = 0; i < map_size / desc_size; i++) { efi_memory_desc_t *desc; @@ -235,10 +244,10 @@ efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, * a specific address. We are doing page-based allocations, * so we must be aligned to a page. */ - if (align < EFI_PAGE_SIZE) - align = EFI_PAGE_SIZE; + if (align < EFI_ALLOC_ALIGN) + align = EFI_ALLOC_ALIGN; - nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; + nr_pages = round_up(size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE; for (i = 0; i < map_size / desc_size; i++) { efi_memory_desc_t *desc; unsigned long m = (unsigned long)map; @@ -292,7 +301,7 @@ void efi_free(efi_system_table_t *sys_table_arg, unsigned long size, if (!size) return; - nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; + nr_pages = round_up(size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE; efi_call_early(free_pages, addr, nr_pages); } @@ -561,7 +570,7 @@ efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg, * to the preferred address. If that fails, allocate as low * as possible while respecting the required alignment. */ - nr_pages = round_up(alloc_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE; + nr_pages = round_up(alloc_size, EFI_ALLOC_ALIGN) / EFI_PAGE_SIZE; status = efi_call_early(allocate_pages, EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA, nr_pages, &efi_addr);