From patchwork Wed Apr 15 15:34:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 47203 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 889562121F for ; Wed, 15 Apr 2015 15:38:48 +0000 (UTC) Received: by wghm4 with SMTP id m4sf10755612wgh.2 for ; Wed, 15 Apr 2015 08:38:47 -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=INHH0E38PQYZRSkDJl3YorEKFQpu1u3DtwYlMaJOePM=; b=NVYf1bzV9bbh9xtFkEQfsvT3VVzJsu3pPYKNSeNiNEiSm7iO4T3tBkuqyEPr42TuSg VXkHuwn5mZV0EC4wSeCg16JdopsMRLLD6AwfPT9F7kzxdkcXlWDaxS0nMeMjVt352p1Q uL6TsjPLZQER8WOU0LHkuyE+uArs0apbYOIbbh91Sh0raYacM5Mrdz0QKrk0/aog/dLS RghDRoEi0Lnpt7ocmaODvOze1Bri2Uq9YPawsbcl8vMvaPldQgFAAjMGsCm7UVqXQCFb EMciGlqszQCdwe9EgfSPMIe5NFRLSJrf8gyPGI7kBYfdq8RkCVbiPpN7Amk7Ntr+B7uA 5H+Q== X-Gm-Message-State: ALoCoQnArAcIQJtqrPlgcJiP98+6HmYnlVHdRKhmBEe7utyK30Ki0Pm3+Nkt4zyrDEHplJKY78vg X-Received: by 10.180.96.6 with SMTP id do6mr5092886wib.4.1429112327907; Wed, 15 Apr 2015 08:38:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.204.39 with SMTP id kv7ls209779lac.63.gmail; Wed, 15 Apr 2015 08:38:47 -0700 (PDT) X-Received: by 10.112.16.196 with SMTP id i4mr24060272lbd.72.1429112327745; Wed, 15 Apr 2015 08:38:47 -0700 (PDT) Received: from mail-la0-f48.google.com (mail-la0-f48.google.com. [209.85.215.48]) by mx.google.com with ESMTPS id db1si4158390lac.147.2015.04.15.08.38.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Apr 2015 08:38:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.48 as permitted sender) client-ip=209.85.215.48; Received: by layy10 with SMTP id y10so35780015lay.0 for ; Wed, 15 Apr 2015 08:38:47 -0700 (PDT) X-Received: by 10.152.163.35 with SMTP id yf3mr24421441lab.86.1429112327622; Wed, 15 Apr 2015 08:38:47 -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.67.65 with SMTP id l1csp2592244lbt; Wed, 15 Apr 2015 08:38:46 -0700 (PDT) X-Received: by 10.70.93.36 with SMTP id cr4mr46791754pdb.68.1429112325486; Wed, 15 Apr 2015 08:38:45 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ag7si7587821pad.120.2015.04.15.08.38.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Apr 2015 08:38:45 -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 1YiPMu-0001U6-Gz; Wed, 15 Apr 2015 15:36:48 +0000 Received: from mail-wg0-f49.google.com ([74.125.82.49]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YiPLm-0000sg-A4 for linux-arm-kernel@lists.infradead.org; Wed, 15 Apr 2015 15:35:39 +0000 Received: by wgyo15 with SMTP id o15so51269961wgy.2 for ; Wed, 15 Apr 2015 08:35:16 -0700 (PDT) X-Received: by 10.180.75.243 with SMTP id f19mr42923637wiw.94.1429112116236; Wed, 15 Apr 2015 08:35:16 -0700 (PDT) Received: from ards-macbook-pro.local ([90.174.5.175]) by mx.google.com with ESMTPSA id eh5sm7674765wic.20.2015.04.15.08.35.08 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 15 Apr 2015 08:35:15 -0700 (PDT) From: Ard Biesheuvel To: mark.rutland@arm.com, catalin.marinas@arm.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 05/13] arm64/efi: adapt to relaxed FDT placement requirements Date: Wed, 15 Apr 2015 17:34:16 +0200 Message-Id: <1429112064-19952-6-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1429112064-19952-1-git-send-email-ard.biesheuvel@linaro.org> References: <1429112064-19952-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150415_083538_559136_32E4EDFB X-CRM114-Status: GOOD ( 18.82 ) 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.49 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.49 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: 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.48 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 | 23 +++++++++++++---------- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/arch/arm64/include/asm/efi.h b/arch/arm64/include/asm/efi.h index ef572206f1c3..825c85666b6b 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(void); /* 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 dcae482a9a17..f54c76a4fd32 100644 --- a/drivers/firmware/efi/libstub/arm-stub.c +++ b/drivers/firmware/efi/libstub/arm-stub.c @@ -269,9 +269,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 47437b16b186..c8e096094ea9 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 91da56c4fd54..ace5ed70a88e 100644 --- a/drivers/firmware/efi/libstub/fdt.c +++ b/drivers/firmware/efi/libstub/fdt.c @@ -165,10 +165,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 @@ -186,7 +182,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, @@ -197,6 +192,7 @@ efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table, unsigned long mmap_key; efi_memory_desc_t *memory_map, *runtime_map; unsigned long new_fdt_size; + void *fdt_alloc; efi_status_t status; int runtime_entry_count = 0; @@ -221,14 +217,21 @@ efi_status_t allocate_new_fdt_and_exit_boot(efi_system_table_t *sys_table, * will allocate a bigger buffer if this ends up being too * small, so a rough guess is OK here. */ - new_fdt_size = fdt_size + EFI_PAGE_SIZE; + new_fdt_size = fdt_size + EFI_PAGE_SIZE + EFI_FDT_ALIGN; 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, + &fdt_alloc); if (status != EFI_SUCCESS) { pr_efi_err(sys_table, "Unable to allocate memory for new device tree.\n"); goto fail; } + *new_fdt_addr = round_up((unsigned long)fdt_alloc, + EFI_FDT_ALIGN); /* * Now that we have done our final memory allocation (and free) @@ -258,7 +261,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(&fdt_alloc); sys_table->boottime->free_pool(memory_map); new_fdt_size += EFI_PAGE_SIZE; } else { @@ -316,7 +319,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(&fdt_alloc); fail: sys_table->boottime->free_pool(runtime_map);