From patchwork Mon Jul 21 15:16:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 33977 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B853E20672 for ; Mon, 21 Jul 2014 15:18:49 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id tr6sf60869433ieb.6 for ; Mon, 21 Jul 2014 08:18:49 -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:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=4nB18HZUavp0rKkqYD5sj2SU8WR8QhgbMRyLBSdtfxs=; b=QEkDaADWjQUP8i6hNhAkn9RDyiw+I/1x+MGthqvBC7W86oaVj9hWqWSe9sTlMeR66g +iykIQVKYj88wd8yuK4QBtfQdB8NApccGrRMKoH6ZjxeHb0OD+ZzH18Q0y4n+nIg9saS 9Jv+nOdN3xSCzf1Hpr9sE3R2UdTUUBRLAXEyDq/d/3F6eEMSw3B1ig7ToLL/RA+cVpNO NgFl8vffEL673oGBxzdOmxD2pipVxf357B2COA+YLhO6TEqjqD+TEWp4/77grc/X6oW6 bP/VCUkG8AWXF38fdnXRdqF7y+j1q7ZSr2KTDc6S4qO4z4stDU3RrofuiDtQJYGXlwbv q2qA== X-Gm-Message-State: ALoCoQlCNQonzEjbi1Qsgw/7qPiWCo7jJLB/50/zxeSwgMYCIIS8XviVIDzPV2bsaPQJPqLH0KDq X-Received: by 10.50.49.33 with SMTP id r1mr1767762ign.3.1405955929105; Mon, 21 Jul 2014 08:18:49 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.24.228 with SMTP id 91ls798537qgr.70.gmail; Mon, 21 Jul 2014 08:18:48 -0700 (PDT) X-Received: by 10.221.28.71 with SMTP id rt7mr2923731vcb.75.1405955928808; Mon, 21 Jul 2014 08:18:48 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id yy7si11553522vdb.10.2014.07.21.08.18.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Jul 2014 08:18:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id hy4so12313728vcb.41 for ; Mon, 21 Jul 2014 08:18:48 -0700 (PDT) X-Received: by 10.221.34.13 with SMTP id sq13mr30513985vcb.16.1405955927742; Mon, 21 Jul 2014 08:18: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.221.37.5 with SMTP id tc5csp120956vcb; Mon, 21 Jul 2014 08:18:47 -0700 (PDT) X-Received: by 10.70.128.2 with SMTP id nk2mr2925148pdb.155.1405955926625; Mon, 21 Jul 2014 08:18:46 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id of3si14539323pbc.65.2014.07.21.08.18.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jul 2014 08:18:46 -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 1X9FL0-000720-Vw; Mon, 21 Jul 2014 15:17:14 +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 1X9FKo-0006U8-K7 for linux-arm-kernel@lists.infradead.org; Mon, 21 Jul 2014 15:17:03 +0000 Received: by mail-wg0-f43.google.com with SMTP id l18so6532278wgh.26 for ; Mon, 21 Jul 2014 08:16:38 -0700 (PDT) X-Received: by 10.180.81.103 with SMTP id z7mr5208843wix.23.1405955798481; Mon, 21 Jul 2014 08:16:38 -0700 (PDT) Received: from ards-macbook-pro.local ([212.91.105.246]) by mx.google.com with ESMTPSA id ft17sm38327602wjc.14.2014.07.21.08.16.36 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Jul 2014 08:16:37 -0700 (PDT) From: Ard Biesheuvel To: matt.fleming@intel.com, linux-efi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, will.deacon@arm.com, leif.lindholm@linaro.org Subject: [RFC PATCH 01/10] arm64/efi: efistub: jump to 'stext' directly, not through the header Date: Mon, 21 Jul 2014 17:16:16 +0200 Message-Id: <1405955785-13477-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1405955785-13477-1-git-send-email-ard.biesheuvel@linaro.org> References: <1405955785-13477-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140721_081702_879307_6BAD12BC X-CRM114-Status: GOOD ( 12.16 ) 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 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [74.125.82.43 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: roy.franz@linaro.org, victor.kamensky@linaro.org, steve.capper@linaro.org, Ard Biesheuvel , msalter@redhat.com 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.220.182 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 After the EFI stub has done its business, it jumps into the kernel by branching to offset #0 of the loaded Image, which is where it expects to find the header containing a 'branch to stext' instruction. However, the header is not covered by any PE/COFF section, so the header may not actually be loaded at the expected offset. So instead, jump to 'stext' directly, which is at the base of the PE/COFF .text section, by supplying a symbol 'stext_offset' to efi-entry.o which contains the relative offset of stext into the Image. Also replace other open coded calculations of the same value with a reference to 'stext_offset' Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi-entry.S | 3 ++- arch/arm64/kernel/head.S | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/efi-entry.S b/arch/arm64/kernel/efi-entry.S index 619b1dd7bcde..a0016d3a17da 100644 --- a/arch/arm64/kernel/efi-entry.S +++ b/arch/arm64/kernel/efi-entry.S @@ -61,7 +61,8 @@ ENTRY(efi_stub_entry) */ mov x20, x0 // DTB address ldr x0, [sp, #16] // relocated _text address - mov x21, x0 + ldr x21, =stext_offset + add x21, x0, x21 /* * Flush dcache covering current runtime addresses diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 69dafe9621fd..5cd1f3491df5 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -129,6 +129,8 @@ efi_head: #endif #ifdef CONFIG_EFI + .globl stext_offset + .set stext_offset, stext - efi_head .align 3 pe_header: .ascii "PE" @@ -152,7 +154,7 @@ optional_header: .long 0 // SizeOfInitializedData .long 0 // SizeOfUninitializedData .long efi_stub_entry - efi_head // AddressOfEntryPoint - .long stext - efi_head // BaseOfCode + .long stext_offset // BaseOfCode extra_header_fields: .quad 0 // ImageBase @@ -169,7 +171,7 @@ extra_header_fields: .long _edata - efi_head // SizeOfImage // Everything before the kernel image is considered part of the header - .long stext - efi_head // SizeOfHeaders + .long stext_offset // SizeOfHeaders .long 0 // CheckSum .short 0xa // Subsystem (EFI application) .short 0 // DllCharacteristics @@ -214,9 +216,9 @@ section_table: .byte 0 .byte 0 // end of 0 padding of section name .long _edata - stext // VirtualSize - .long stext - efi_head // VirtualAddress + .long stext_offset // VirtualAddress .long _edata - stext // SizeOfRawData - .long stext - efi_head // PointerToRawData + .long stext_offset // PointerToRawData .long 0 // PointerToRelocations (0 for executables) .long 0 // PointerToLineNumbers (0 for executables)