From patchwork Wed Jul 29 10:04:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 51623 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 patches.linaro.org (Postfix) with ESMTPS id 85BEF22DB5 for ; Wed, 29 Jul 2015 10:06:55 +0000 (UTC) Received: by lafd3 with SMTP id d3sf2046722laf.1 for ; Wed, 29 Jul 2015 03:06:54 -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:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:cc:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=LSgL2X7rF52KEcLVlUEBXJmasSZCoheX/DKFMTZt7VA=; b=N17PcKNqsVis/ONDwU5x3IicQsvoi21vBhXueKwaJJLHlMfHHJzJqPOAs30sImXcOg cd/AtmW5i5nsb8pFx2Yx1Bfg2IR69T8qm+9UWafqEudFu30Q8d0eQsc9AbdaxWb2DVFf 7Zx0kK2STc7IWkHDuFtgGtc83ilWL1N63HgGT4GT9cgdLQTywWwLL/rQa+ljfVXJnLk/ A0ysGSHflfg1tEDeErp8mDAOBIMPO5peEw45PKFCFW+z8GlhZYLcwJT9A6uYyXEXOi4M Nfx/RvQH4FhRWTZ13+jGzWIW02VeEA1EyLiCB+248PCID6AX9RUbhJiSglqFZlmXzuSK bTjQ== X-Gm-Message-State: ALoCoQmkkiwA413umebFaRdwnON3PGaJIm8222NnAR6dhMovRJ5yD7095TFQ5wYG6COKcC8kzBGG X-Received: by 10.113.11.3 with SMTP id ee3mr15818017lbd.9.1438164414454; Wed, 29 Jul 2015 03:06:54 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.70 with SMTP id x6ls23927laa.5.gmail; Wed, 29 Jul 2015 03:06:54 -0700 (PDT) X-Received: by 10.152.36.102 with SMTP id p6mr37956233laj.19.1438164414115; Wed, 29 Jul 2015 03:06:54 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id tp6si21107327lbb.97.2015.07.29.03.06.53 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jul 2015 03:06:53 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by lbbqi7 with SMTP id qi7so3512828lbb.3 for ; Wed, 29 Jul 2015 03:06:53 -0700 (PDT) X-Received: by 10.112.126.101 with SMTP id mx5mr38544425lbb.35.1438164413561; Wed, 29 Jul 2015 03:06:53 -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.7.198 with SMTP id l6csp2650717lba; Wed, 29 Jul 2015 03:06:52 -0700 (PDT) X-Received: by 10.66.159.68 with SMTP id xa4mr93998183pab.105.1438164411148; Wed, 29 Jul 2015 03:06:51 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id gs1si8518395pac.67.2015.07.29.03.06.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jul 2015 03:06:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) 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 1ZKOEg-0004ZW-Vv; Wed, 29 Jul 2015 10:05:18 +0000 Received: from mail-wi0-f174.google.com ([209.85.212.174]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZKOEI-0003Il-QW for linux-arm-kernel@lists.infradead.org; Wed, 29 Jul 2015 10:04:55 +0000 Received: by wicgb10 with SMTP id gb10so192906245wic.1 for ; Wed, 29 Jul 2015 03:04:33 -0700 (PDT) X-Received: by 10.194.192.72 with SMTP id he8mr75265873wjc.11.1438164273058; Wed, 29 Jul 2015 03:04:33 -0700 (PDT) Received: from localhost.localdomain ([185.13.106.66]) by smtp.gmail.com with ESMTPSA id ej5sm37648198wjd.22.2015.07.29.03.04.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Jul 2015 03:04:32 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux-efi@vger.kernel.org, matt.fleming@intel.com, mark.rutland@arm.com, msalter@redhat.com, will.deacon@arm.com Subject: [PATCH 1/2] efi: add 'offset' param to efi_low_alloc() Date: Wed, 29 Jul 2015 12:04:18 +0200 Message-Id: <1438164259-14470-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438164259-14470-1-git-send-email-ard.biesheuvel@linaro.org> References: <1438164259-14470-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150729_030455_013451_BBCE8277 X-CRM114-Status: GOOD ( 16.92 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.212.174 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.174 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Cc: leif.lindholm@linaro.org, Ard Biesheuvel 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.217.181 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 In some cases, e.g., when allocating memory for the arm64 kernel, we need memory at a certain offset from an aligned boundary. So add an offset parameter to efi_low_alloc(), and update the existing callers to pass zero by default. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi-stub.c | 2 +- arch/x86/boot/compressed/eboot.c | 4 ++-- drivers/firmware/efi/libstub/efi-stub-helper.c | 20 +++++++++++++++----- include/linux/efi.h | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c index f5374065ad53..d85a0b2098b3 100644 --- a/arch/arm64/kernel/efi-stub.c +++ b/arch/arm64/kernel/efi-stub.c @@ -29,7 +29,7 @@ efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table, if (*image_addr != (dram_base + TEXT_OFFSET)) { kernel_memsize = kernel_size + (_end - _edata); status = efi_low_alloc(sys_table, kernel_memsize + TEXT_OFFSET, - SZ_2M, reserve_addr); + SZ_2M, 0, reserve_addr); if (status != EFI_SUCCESS) { pr_efi_err(sys_table, "Failed to relocate kernel\n"); return status; diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index 2c82bd150d43..33d1a72f4266 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -1077,7 +1077,7 @@ struct boot_params *make_boot_params(struct efi_config *c) return NULL; } - status = efi_low_alloc(sys_table, 0x4000, 1, + status = efi_low_alloc(sys_table, 0x4000, 1, 0, (unsigned long *)&boot_params); if (status != EFI_SUCCESS) { efi_printk(sys_table, "Failed to alloc lowmem for boot params\n"); @@ -1424,7 +1424,7 @@ struct boot_params *efi_main(struct efi_config *c, } gdt->size = 0x800; - status = efi_low_alloc(sys_table, gdt->size, 8, + status = efi_low_alloc(sys_table, gdt->size, 8, 0, (unsigned long *)&gdt->address); if (status != EFI_SUCCESS) { efi_printk(sys_table, "Failed to alloc mem for gdt\n"); diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c index f07d4a67fa76..67d1759781c5 100644 --- a/drivers/firmware/efi/libstub/efi-stub-helper.c +++ b/drivers/firmware/efi/libstub/efi-stub-helper.c @@ -226,7 +226,7 @@ fail: */ efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, unsigned long size, unsigned long align, - unsigned long *addr) + unsigned long offset, unsigned long *addr) { unsigned long map_size, desc_size; efi_memory_desc_t *map; @@ -269,10 +269,19 @@ efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, * checks pointers against NULL. Skip the first 8 * bytes so we start at a nice even number. */ - if (start == 0x0) + if (start + offset == 0x0) start += 8; - start = round_up(start, align); + /* + * Check if the offset exceeds the misalignment of this region. + * In that case, we can round down instead of up, and the + * resulting start value will be correctly aligned and still + * point past the start of the region. + */ + if (offset >= (start & (align - 1))) + start = round_down(start, align) + offset; + else + start = round_up(start, align) + offset; if ((start + size) > end) continue; @@ -580,7 +589,7 @@ efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg, * possible. */ if (status != EFI_SUCCESS) { - status = efi_low_alloc(sys_table_arg, alloc_size, alignment, + status = efi_low_alloc(sys_table_arg, alloc_size, alignment, 0, &new_addr); } if (status != EFI_SUCCESS) { @@ -684,7 +693,8 @@ char *efi_convert_cmdline(efi_system_table_t *sys_table_arg, options_bytes++; /* NUL termination */ - status = efi_low_alloc(sys_table_arg, options_bytes, 0, &cmdline_addr); + status = efi_low_alloc(sys_table_arg, options_bytes, 0, 0, + &cmdline_addr); if (status != EFI_SUCCESS) return NULL; diff --git a/include/linux/efi.h b/include/linux/efi.h index faafa1ad6ea7..e738e97632ba 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1245,7 +1245,7 @@ efi_status_t efi_get_memory_map(efi_system_table_t *sys_table_arg, efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg, unsigned long size, unsigned long align, - unsigned long *addr); + unsigned long offset, unsigned long *addr); efi_status_t efi_high_alloc(efi_system_table_t *sys_table_arg, unsigned long size, unsigned long align,