From patchwork Wed Jul 29 10:04:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 51624 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id 9F8C422DB5 for ; Wed, 29 Jul 2015 10:06:58 +0000 (UTC) Received: by wixh2 with SMTP id h2sf5329289wix.0 for ; Wed, 29 Jul 2015 03:06:57 -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=1ba9A0zj0DONKXhnNYzP62fElbApw023788iZ5vAzKU=; b=Ph+8JD1ppFVWtC+1u2zfe3Q9wyDEcG2pYSQCXEnwP7Ic36n5iQChtoR+nrpB0J8rEJ JXcuXs90YyLrkOgB8qnMiRi4dY4shOM6ZmRApa8UsC67/+0bj6Per7TnG2s9nxUVn4eZ k+I1b13Mx4rowfW4mWuiAd+a380A99mPDOgaCgfrNpmpsjOemG9sRApo1fcBUfb1oaOr EN6eTxOJXyHVsnmzCZ/eJt+zLxgX208ibFGviqC+NKKsv5d1B4YFzTDNbt7bxpETNjoa s/Swb+uwNqRLfMwWaQNP9LfH2AT1Le4rxRpU8pItGfpQURIRcErxR97qswiruOPYxXZM WD9w== X-Gm-Message-State: ALoCoQk/kxtl0r9XguDRQY9o1kKx1HPf8dBkpTXgCx8rxxAVSFWg06oz5AWaaOv0+hjay9Dn/p1a X-Received: by 10.112.189.131 with SMTP id gi3mr15822954lbc.6.1438164417491; Wed, 29 Jul 2015 03:06:57 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.45.73 with SMTP id k9ls21295lam.66.gmail; Wed, 29 Jul 2015 03:06:57 -0700 (PDT) X-Received: by 10.153.6.44 with SMTP id cr12mr37388137lad.92.1438164417330; Wed, 29 Jul 2015 03:06:57 -0700 (PDT) Received: from mail-lb0-f169.google.com (mail-lb0-f169.google.com. [209.85.217.169]) by mx.google.com with ESMTPS id u11si19835560lal.142.2015.07.29.03.06.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Jul 2015 03:06:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.169 as permitted sender) client-ip=209.85.217.169; Received: by lbbst4 with SMTP id st4so3273043lbb.1 for ; Wed, 29 Jul 2015 03:06:56 -0700 (PDT) X-Received: by 10.152.207.76 with SMTP id lu12mr37804881lac.29.1438164416806; Wed, 29 Jul 2015 03:06:56 -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 l6csp2650748lba; Wed, 29 Jul 2015 03:06:55 -0700 (PDT) X-Received: by 10.66.66.163 with SMTP id g3mr69453991pat.85.1438164411404; 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 qp5si60563011pab.241.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 1ZKOES-0003V3-Mm; Wed, 29 Jul 2015 10:05:04 +0000 Received: from mail-wi0-f169.google.com ([209.85.212.169]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZKOEG-0003Iv-EV for linux-arm-kernel@lists.infradead.org; Wed, 29 Jul 2015 10:04:53 +0000 Received: by wicmv11 with SMTP id mv11so212165471wic.0 for ; Wed, 29 Jul 2015 03:04:35 -0700 (PDT) X-Received: by 10.194.95.132 with SMTP id dk4mr83123995wjb.88.1438164275455; Wed, 29 Jul 2015 03:04:35 -0700 (PDT) Received: from localhost.localdomain ([185.13.106.66]) by smtp.gmail.com with ESMTPSA id ej5sm37648198wjd.22.2015.07.29.03.04.33 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Jul 2015 03:04:34 -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 2/2] arm64/efi: use efi_low_alloc() with offset to allocate kernel Date: Wed, 29 Jul 2015 12:04:19 +0200 Message-Id: <1438164259-14470-3-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_030452_654394_830E2EBF X-CRM114-Status: GOOD ( 14.90 ) 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.169 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.212.169 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.169 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 Now that efi_low_alloc() supports an offset parameter, we can use it to allocate memory for the kernel at TEXT_OFFSET bytes above a 2 MB aligned boundary directly. This prevents issues when the base of DRAM is at 0x0, which efi_low_alloc() refuses to use as the address of an allocation. It also helps when fewer than TEXT_OFFSET bytes are occupied by the firmware at the base of DRAM, since efi_low_alloc() will now do the rounding for us, and return 'base of DRAM + TEXT_OFFSET' directly, regardless of whether any regions below it are in use. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi-stub.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/efi-stub.c b/arch/arm64/kernel/efi-stub.c index d85a0b2098b3..e3085b391570 100644 --- a/arch/arm64/kernel/efi-stub.c +++ b/arch/arm64/kernel/efi-stub.c @@ -23,21 +23,22 @@ efi_status_t __init handle_kernel_image(efi_system_table_t *sys_table, { efi_status_t status; unsigned long kernel_size, kernel_memsize = 0; + unsigned long new_image_addr; /* Relocate the image, if required. */ kernel_size = _edata - _text; 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, 0, reserve_addr); + status = efi_low_alloc(sys_table, kernel_memsize, SZ_2M, + TEXT_OFFSET, &new_image_addr); if (status != EFI_SUCCESS) { pr_efi_err(sys_table, "Failed to relocate kernel\n"); return status; } - memcpy((void *)*reserve_addr + TEXT_OFFSET, (void *)*image_addr, + memcpy((void *)new_image_addr, (void *)*image_addr, kernel_size); - *image_addr = *reserve_addr + TEXT_OFFSET; - *reserve_size = kernel_memsize + TEXT_OFFSET; + *image_addr = new_image_addr; + *image_size = kernel_memsize; }