From patchwork Mon May 11 06:42:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 48206 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 411CD2121F for ; Mon, 11 May 2015 06:48:05 +0000 (UTC) Received: by labgx2 with SMTP id gx2sf39070154lab.1 for ; Sun, 10 May 2015 23:48:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=5Mug1OUmFxE8i4bc/Adb1svAdDSxCOO4VGwC7+WgPMY=; b=gDkFxx4FB8oIp4Rphu31bTCIgE2vs9pmx0B8f0bAu7LFgQArWlaeSRPOGbTjPvXhaE OITdI47UZuNEJmEiHwj+yZj93zRx97so7EVMhBZPnVuuJlDJm7Wj8NC4CEjwvz6ChCyq /dHOCe1Y2nP+blaE3f6Plo79oD+55YxPLtFUUs96iqQooyl0BrvMxWJK+zkmTMBDCWgd A1q6U1JBwW736kMftGnck8iWj1lWZrsf1COIhnFi7wfaqX5Os2UtXwegfmDX11YvjoyO 395I4OSCx68BB/xORU/QExTjSZVhxSLZoCG3zmm+JQU8mWQUIPWUcMxYCZvQFot+UDZR HQbw== X-Gm-Message-State: ALoCoQl9j3JNCjp9mrF4hCHNrKwppb5G7/Pb1S4FGB1UtgqlqOeJ4NpbznPhrSszb9jTnWJgZUqE X-Received: by 10.180.105.226 with SMTP id gp2mr7076729wib.1.1431326884226; Sun, 10 May 2015 23:48:04 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.103 with SMTP id kx7ls606365lac.62.gmail; Sun, 10 May 2015 23:48:04 -0700 (PDT) X-Received: by 10.112.78.105 with SMTP id a9mr6930829lbx.70.1431326884069; Sun, 10 May 2015 23:48:04 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id lv6si7822925lac.86.2015.05.10.23.48.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 May 2015 23:48:03 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by labbd9 with SMTP id bd9so86631827lab.2 for ; Sun, 10 May 2015 23:48:03 -0700 (PDT) X-Received: by 10.152.236.40 with SMTP id ur8mr7022586lac.19.1431326883780; Sun, 10 May 2015 23:48:03 -0700 (PDT) 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.108.230 with SMTP id hn6csp1335650lbb; Sun, 10 May 2015 23:48:02 -0700 (PDT) X-Received: by 10.70.32.164 with SMTP id k4mr16985514pdi.138.1431326881885; Sun, 10 May 2015 23:48:01 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id x16si16808492pdi.8.2015.05.10.23.48.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 10 May 2015 23:48:01 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YrhT7-0001ea-8p; Mon, 11 May 2015 06:45:37 +0000 Received: from mail-wg0-f43.google.com ([74.125.82.43]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YrhQL-0007H2-SA for linux-arm-kernel@lists.infradead.org; Mon, 11 May 2015 06:42:48 +0000 Received: by wgbhc8 with SMTP id hc8so18122758wgb.2 for ; Sun, 10 May 2015 23:42:24 -0700 (PDT) X-Received: by 10.180.101.3 with SMTP id fc3mr16351044wib.47.1431326543965; Sun, 10 May 2015 23:42:23 -0700 (PDT) Received: from localhost.localdomain (cag06-7-83-153-85-71.fbx.proxad.net. [83.153.85.71]) by mx.google.com with ESMTPSA id wr2sm21173009wjb.45.2015.05.10.23.42.21 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 10 May 2015 23:42:23 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, grant.likely@linaro.org, leif.lindholm@linaro.org, roy.franz@linaro.org, catalin.marinas@arm.com, mark.rutland@arm.com, matt.fleming@intel.com Subject: [PATCH 8/8] arm64/efi: adapt to relaxed FDT placement requirements Date: Mon, 11 May 2015 08:42:00 +0200 Message-Id: <1431326520-17331-9-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1431326520-17331-1-git-send-email-ard.biesheuvel@linaro.org> References: <1431326520-17331-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150510_234246_227991_84BF8F09 X-CRM114-Status: GOOD ( 16.63 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.43 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.43 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Ganapatrao.Kulkarni@caviumnetworks.com, Ard Biesheuvel X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) 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 With the relaxed FDT placement requirements in place, we can change the allocation strategy used by the stub to put the FDT image higher up in memory. At the same time, reduce the minimal alignment to 8 bytes, and impose a 2 MB size limit, as per the new requirements. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/efi.h | 10 +++------- drivers/firmware/efi/libstub/arm-stub.c | 5 ++--- drivers/firmware/efi/libstub/efistub.h | 1 - drivers/firmware/efi/libstub/fdt.c | 18 +++++++++--------- 4 files changed, 14 insertions(+), 20 deletions(-) diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h index 635101f36720..43ea4ecbd361 100644 --- a/arch/arm64/include/asm/efi.h +++ b/arch/arm64/include/asm/efi.h @@ -1,6 +1,7 @@ #ifndef _ASM_EFI_H #define _ASM_EFI_H +#include #include #include @@ -38,13 +39,8 @@ extern void efi_init_fdt(void *fdt); /* arch specific definitions used by the stub code */ -/* - * AArch64 requires the DTB to be 8-byte aligned in the first 512MiB from - * start of kernel and may not cross a 2MiB boundary. We set alignment to - * 2MiB so we know it won't cross a 2MiB boundary. - */ -#define EFI_FDT_ALIGN SZ_2M /* used by allocate_new_fdt_and_exit_boot() */ -#define MAX_FDT_OFFSET SZ_512M +#define EFI_FDT_ALIGN MIN_FDT_ALIGN +#define EFI_FDT_MAX_SIZE MAX_FDT_SIZE #define efi_call_early(f, ...) sys_table_arg->boottime->f(__VA_ARGS__) diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c index e29560e6b40b..4e5ac133d1dc 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -268,9 +268,8 @@ unsigned long efi_entry(void *handle, efi_system_table_t *sys_table, new_fdt_addr = fdt_addr; status = allocate_new_fdt_and_exit_boot(sys_table, handle, - &new_fdt_addr, dram_base + MAX_FDT_OFFSET, - initrd_addr, initrd_size, cmdline_ptr, - fdt_addr, fdt_size); + &new_fdt_addr, initrd_addr, initrd_size, + cmdline_ptr, fdt_addr, fdt_size); /* * If all went well, we need to return the FDT address to the diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index e334a01cf92f..cf14dafc348a 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -35,7 +35,6 @@ efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt, efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table, void *handle, unsigned long *new_fdt_addr, - unsigned long max_addr, u64 initrd_addr, u64 initrd_size, char *cmdline_ptr, unsigned long fdt_addr, diff --git a/drivers/firmware/efi/libstub/fdt.c b/drivers/firmware/efi/libstub/fdt.c index a7e87cd582f2..ab6ecb22bd6e 100644 --- a/drivers/firmware/efi/libstub/fdt.c +++ b/drivers/firmware/efi/libstub/fdt.c @@ -134,10 +134,6 @@ fdt_set_fail: return EFI_LOAD_ERROR; } -#ifndef EFI_FDT_ALIGN -#define EFI_FDT_ALIGN EFI_PAGE_SIZE -#endif - /* * Allocate memory for a new FDT, then add EFI, commandline, and * initrd related fields to the FDT. This routine increases the @@ -155,7 +151,6 @@ fdt_set_fail: efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table, void *handle, unsigned long *new_fdt_addr, - unsigned long max_addr, u64 initrd_addr, u64 initrd_size, char *cmdline_ptr, unsigned long fdt_addr, @@ -192,8 +187,13 @@ efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table, */ new_fdt_size = fdt_size + EFI_PAGE_SIZE; while (1) { - status = efi_high_alloc(sys_table, new_fdt_size, EFI_FDT_ALIGN, - new_fdt_addr, max_addr); + if (new_fdt_size > EFI_FDT_MAX_SIZE) { + pr_efi_err(sys_table, "FDT size exceeds EFI_FDT_MAX_SIZE.\n"); + goto fail; + } + status = sys_table->boottime->allocate_pool(EFI_LOADER_DATA, + new_fdt_size, + (void **)new_fdt_addr); if (status != EFI_SUCCESS) { pr_efi_err(sys_table, "Unable to allocate memory for new device tree.\n"); goto fail; @@ -227,7 +227,7 @@ efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table, * to get new one that reflects the free/alloc we do * on the device tree buffer. */ - efi_free(sys_table, new_fdt_size, *new_fdt_addr); + sys_table->boottime->free_pool((void *)*new_fdt_addr); sys_table->boottime->free_pool(memory_map); new_fdt_size += EFI_PAGE_SIZE; } else { @@ -285,7 +285,7 @@ fail_free_mmap: sys_table->boottime->free_pool(memory_map); fail_free_new_fdt: - efi_free(sys_table, new_fdt_size, *new_fdt_addr); + sys_table->boottime->free_pool((void *)*new_fdt_addr); fail: sys_table->boottime->free_pool(runtime_map);