From patchwork Mon Mar 16 15:23:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 45858 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3B29521523 for ; Mon, 16 Mar 2015 15:33:47 +0000 (UTC) Received: by labgm9 with SMTP id gm9sf27493894lab.1 for ; Mon, 16 Mar 2015 08:33:46 -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=OXZeUniK9bRiOObOX/miSYgU83Us6A7ZI2zvc9xV3w4=; b=TqXiVRgB0wU27AFDUdEXo9066UDEJROLPJRHxLsS0tZiuahPQKc6QBC4Xd7e8QvFlx bIlZosdrpv9i3G9WnoCIyBCO67OO2HpCH1fmQf2HStIYlQU4OpIwHJ1yrbi4Lk3gA1/B D2FeJ0Bqxc9+lYtsP+MegtMUN+lmDqm+TloQAW87scGf14S3CIuSu71Z7XkM1lg/LWYT kkaQCQMDsEVa05YBlk4XkSY8HehOKHQAgssLuwvuTZUtNVKE9UXCaahwdTSatUyShcMP gMyh9jFWf9ZtqWKFBeSg8MN9iv1znnUHzLQIVtyb3gbV51FbUJ66R751M15zuI1hrJrM Ut6Q== X-Gm-Message-State: ALoCoQl63qRoLJtKZ/5Aszs7w0OVT77HN8Io6Gql6Q9BCaQCvH35RDHrpgxkLnP0G3ZQTgI0rNXh X-Received: by 10.112.97.37 with SMTP id dx5mr627669lbb.15.1426520025968; Mon, 16 Mar 2015 08:33:45 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.33 with SMTP id s1ls760967lae.40.gmail; Mon, 16 Mar 2015 08:33:45 -0700 (PDT) X-Received: by 10.152.29.102 with SMTP id j6mr56879681lah.12.1426520025831; Mon, 16 Mar 2015 08:33:45 -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 wg10si6058711lbc.165.2015.03.16.08.33.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Mar 2015 08:33:45 -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 lagg8 with SMTP id g8so43269898lag.1 for ; Mon, 16 Mar 2015 08:33:45 -0700 (PDT) X-Received: by 10.112.130.195 with SMTP id og3mr54921318lbb.112.1426520025553; Mon, 16 Mar 2015 08:33:45 -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.35.133 with SMTP id h5csp2662192lbj; Mon, 16 Mar 2015 08:33:44 -0700 (PDT) X-Received: by 10.66.136.48 with SMTP id px16mr102646156pab.89.1426520023560; Mon, 16 Mar 2015 08:33:43 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id 5si9628879pdm.87.2015.03.16.08.33.42 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Mar 2015 08:33:43 -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 1YXX0D-0003R7-GD; Mon, 16 Mar 2015 15:32:25 +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 1YXX06-0003E5-9H for linux-arm-kernel@lists.infradead.org; Mon, 16 Mar 2015 15:32:19 +0000 Received: by wgra20 with SMTP id a20so43080622wgr.3 for ; Mon, 16 Mar 2015 08:31:55 -0700 (PDT) X-Received: by 10.194.237.34 with SMTP id uz2mr121418561wjc.157.1426519592337; Mon, 16 Mar 2015 08:26:32 -0700 (PDT) Received: from ards-macbook-pro.local ([90.174.4.220]) by mx.google.com with ESMTPSA id u16sm15876983wjr.5.2015.03.16.08.26.29 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 16 Mar 2015 08:26:31 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, lkml@vger.kernel.org, keescook@chromium.org, catalin.marinas@arm.com, will.deacon@arm.com, mark.rutland@arm.com, marc.zyngier@arm.com Subject: [RFC PATCH 1/3] arm64: head.S: replace early literals with constant immediates Date: Mon, 16 Mar 2015 16:23:41 +0100 Message-Id: <1426519423-28263-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1426519423-28263-1-git-send-email-ard.biesheuvel@linaro.org> References: <1426519423-28263-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150316_083218_522247_9E70D793 X-CRM114-Status: GOOD ( 10.48 ) 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: joakim.bech@linaro.org, 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 In preparation of making the kernel relocatable, replace literal symbol references with immediate constants. This is necessary, as the literals will not be populated with meaningful values until after the relocation code has executed. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/efi-entry.S | 2 +- arch/arm64/kernel/head.S | 36 +++++++++++++++--------------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/arch/arm64/kernel/efi-entry.S b/arch/arm64/kernel/efi-entry.S index 8ce9b0577442..f78e6a1de825 100644 --- a/arch/arm64/kernel/efi-entry.S +++ b/arch/arm64/kernel/efi-entry.S @@ -61,7 +61,7 @@ ENTRY(efi_stub_entry) */ mov x20, x0 // DTB address ldr x0, [sp, #16] // relocated _text address - ldr x21, =stext_offset + movz x21, #:abs_g0:stext_offset add x21, x0, x21 /* diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 9c856f2aa7a5..1ea3cd2aba34 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -46,11 +46,9 @@ #error TEXT_OFFSET must be less than 2MB #endif - .macro pgtbl, ttb0, ttb1, virt_to_phys - ldr \ttb1, =swapper_pg_dir - ldr \ttb0, =idmap_pg_dir - add \ttb1, \ttb1, \virt_to_phys - add \ttb0, \ttb0, \virt_to_phys + .macro pgtbl, ttb0, ttb1 + adrp \ttb1, swapper_pg_dir + adrp \ttb0, idmap_pg_dir .endm #ifdef CONFIG_ARM64_64K_PAGES @@ -63,7 +61,7 @@ #define TABLE_SHIFT PUD_SHIFT #endif -#define KERNEL_START KERNEL_RAM_VADDR +#define KERNEL_START _text #define KERNEL_END _end /* @@ -322,7 +320,7 @@ ENDPROC(stext) * been enabled */ __create_page_tables: - pgtbl x25, x26, x28 // idmap_pg_dir and swapper_pg_dir addresses + pgtbl x25, x26 // idmap_pg_dir and swapper_pg_dir addresses mov x27, lr /* @@ -351,8 +349,7 @@ __create_page_tables: * Create the identity mapping. */ mov x0, x25 // idmap_pg_dir - ldr x3, =KERNEL_START - add x3, x3, x28 // __pa(KERNEL_START) + adr_l x3, KERNEL_START // __pa(KERNEL_START) #ifndef CONFIG_ARM64_VA_BITS_48 #define EXTRA_SHIFT (PGDIR_SHIFT + PAGE_SHIFT - 3) @@ -391,9 +388,8 @@ __create_page_tables: #endif create_pgd_entry x0, x3, x5, x6 - ldr x6, =KERNEL_END mov x5, x3 // __pa(KERNEL_START) - add x6, x6, x28 // __pa(KERNEL_END) + adr_l x6, KERNEL_END // __pa(KERNEL_END) create_block_map x0, x7, x3, x5, x6 /* @@ -402,8 +398,10 @@ __create_page_tables: mov x0, x26 // swapper_pg_dir mov x5, #PAGE_OFFSET create_pgd_entry x0, x5, x3, x6 - ldr x6, =KERNEL_END + adr_l x6, KERNEL_END mov x3, x24 // phys offset + sub x6, x6, x3 // kernel memsize + add x6, x6, x5 // __va(KERNEL_END) create_block_map x0, x7, x3, x5, x6 /* @@ -538,8 +536,7 @@ ENDPROC(el2_setup) * in x20. See arch/arm64/include/asm/virt.h for more info. */ ENTRY(set_cpu_boot_mode_flag) - ldr x1, =__boot_cpu_mode // Compute __boot_cpu_mode - add x1, x1, x28 + adr_l x1, __boot_cpu_mode // Compute __boot_cpu_mode cmp w20, #BOOT_CPU_MODE_EL2 b.ne 1f add x1, x1, #4 @@ -598,7 +595,7 @@ ENTRY(secondary_startup) /* * Common entry point for secondary CPUs. */ - pgtbl x25, x26, x28 // x25=TTBR0, x26=TTBR1 + pgtbl x25, x26 // x25=TTBR0, x26=TTBR1 bl __cpu_setup // initialise processor ldr x21, =secondary_data @@ -655,17 +652,14 @@ ENDPROC(__turn_mmu_on) * Calculate the start of physical memory. */ __calc_phys_offset: - adr x0, 1f - ldp x1, x2, [x0] + adrp x0, KERNEL_START // __pa(KERNEL_START) + ldr x1, =KERNEL_RAM_VADDR // __va(KERNEL_START) + mov x2, PAGE_OFFSET sub x28, x0, x1 // x28 = PHYS_OFFSET - PAGE_OFFSET add x24, x2, x28 // x24 = PHYS_OFFSET ret ENDPROC(__calc_phys_offset) - .align 3 -1: .quad . - .quad PAGE_OFFSET - /* * Exception handling. Something went wrong and we can't proceed. We ought to * tell the user, but since we don't have any guarantee that we're even