From patchwork Mon Apr 4 14:52:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 65009 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1233019lbc; Mon, 4 Apr 2016 07:55:57 -0700 (PDT) X-Received: by 10.66.139.137 with SMTP id qy9mr54227444pab.57.1459781756959; Mon, 04 Apr 2016 07:55:56 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id u67si42242589pfa.243.2016.04.04.07.55.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Apr 2016 07:55:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for 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; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org 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 1an5tz-0006Re-MA; Mon, 04 Apr 2016 14:54:51 +0000 Received: from mail-lf0-x235.google.com ([2a00:1450:4010:c07::235]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1an5sI-00057F-Qe for linux-arm-kernel@lists.infradead.org; Mon, 04 Apr 2016 14:53:10 +0000 Received: by mail-lf0-x235.google.com with SMTP id p188so147281819lfd.0 for ; Mon, 04 Apr 2016 07:52:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BQ9orp0MdOl1H6YoqKpKTSSDdyiXr1WYl9uIjDRBb74=; b=aV7S/vcBlPV8lbz2QToP4wHmuhbT+LSaNWbruRCr4ImBZZwubwzu9usnWLfkiBVmlt JJGZ5CYrYgN465yuDSNOFikxI9gm8A0REU93v+lveO1bE5YU5oM9+rmVitt6K0TbMdFW FGKrtrly9c7xn1bAA8sTY1OvV09CjgOEjNK3s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=BQ9orp0MdOl1H6YoqKpKTSSDdyiXr1WYl9uIjDRBb74=; b=CN0JB6l5aln15glCPKXMvD1o8L5v13sVA8GxdWyJU+ZKCnYRcBS4ndg5snEynBa4YI gCR3zxzYUILNYPUgsqD72y3IXSY7c8WyRtYs1V9Lc5e74kYl4FdxQp71sWCF6oV9MryY TV7cGMqmDmdDpzCYrK9rDBaT7uk/GCIKW0DfNq7GF+AdvTlIATTZIHbBbkGc8dG5uAZP cd+J13EYxZVQEGTGyIHtr/j3IR+RwsMOMow5wP64ExMF/O9crf2EMbwEpQLLfGinBSSD l/ObinhEHIjMbBFgCdONAUeVNZkuXEe9V6UlKWcSTPEBIsWNr3KEmefzOjCFFo1PL7t+ RfQw== X-Gm-Message-State: AD7BkJKsbuhMtmnAVDTo5CLv2HAjqMhreR1oudAfrT6wtvWhLZlwV+IttkdT/m2fyTmcA1eG X-Received: by 10.194.133.101 with SMTP id pb5mr9774802wjb.106.1459781564508; Mon, 04 Apr 2016 07:52:44 -0700 (PDT) Received: from localhost.localdomain ([195.55.142.58]) by smtp.gmail.com with ESMTPSA id cf6sm7922528wjc.12.2016.04.04.07.52.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Apr 2016 07:52:43 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, will.deacon@arm.com, catalin.marinas@arm.com, mark.rutland@arm.com Subject: [PATCH 8/8] arm64/kernel: drop global kaslr_offset in x23 from head.S Date: Mon, 4 Apr 2016 16:52:24 +0200 Message-Id: <1459781544-14310-9-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1459781544-14310-1-git-send-email-ard.biesheuvel@linaro.org> References: <1459781544-14310-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160404_075307_229610_AEBFA8F6 X-CRM114-Status: GOOD ( 15.16 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:4010:c07:0:0:0:235 listed in] [list.dnswl.org] -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.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 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: Ard Biesheuvel MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Instead of keeping a global kaslr_offset variable with file scope in head.S, pass the kaslr_offset as an argument to __create_page_tables() and __mmap_switched(), and return the new kaslr_offset from the latter if it returns to __enable_mmu() in order to configure KASLR. Signed-off-by: Ard Biesheuvel --- arch/arm64/kernel/head.S | 46 +++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) -- 2.5.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 23d03da7ecfe..02e37f052263 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -212,8 +212,9 @@ section_table: ENTRY(stext) bl preserve_boot_args bl el2_setup // Drop to EL1, w0=cpu_boot_mode - mov x23, xzr // KASLR offset, defaults to 0 bl set_cpu_boot_mode_flag + + mov x0, xzr // KASLR offset, defaults to 0 bl __create_page_tables /* * The following calls CPU setup code, see arch/arm64/mm/proc.S for @@ -305,14 +306,19 @@ ENDPROC(preserve_boot_args) .endm /* + * __create_page_tables(u64 kaslr_offset) + * * Setup the initial page tables. We only setup the barest amount which is * required to get the kernel running. The following sections are required: * - identity mapping to enable the MMU (low address, TTBR0) * - first few MB of the kernel linear mapping to jump to once the MMU has * been enabled + * + * Clobbers callee saved registers x27 and x28 */ __create_page_tables: mov x28, lr + mov x27, x0 /* * Invalidate the idmap and swapper page tables to avoid potential @@ -391,7 +397,7 @@ __create_page_tables: */ adrp x0, swapper_pg_dir ldr x5, =KIMAGE_VADDR - add x5, x5, x23 // add KASLR displacement + add x5, x5, x27 // add KASLR displacement create_pgd_entry x0, x5, x3, x6 ldr w6, kernel_img_size add x6, x6, x5 @@ -416,7 +422,10 @@ kernel_img_size: .ltorg /* - * __mmap_switched(u64 phys_offset) - virtual entry point for the boot CPU + * __mmap_switched(u64 phys_offset, u64 kaslr_offset) - virtual entry point for + * the boot CPU + * + * Clobbers callee saved register x26 */ __mmap_switched: adrp x4, init_thread_union @@ -431,6 +440,7 @@ __mmap_switched: isb #ifdef CONFIG_RELOCATABLE + mov x26, x1 // preserve kaslr_offset /* * Iterate over each entry in the relocation table, and apply the @@ -446,8 +456,8 @@ __mmap_switched: ldr x13, [x9, #-8] cmp w12, #R_AARCH64_RELATIVE b.ne 1f - add x13, x13, x23 // relocate - str x13, [x11, x23] + add x13, x13, x1 // relocate + str x13, [x11, x1] b 0b 1: cmp w12, #R_AARCH64_ABS64 @@ -457,10 +467,10 @@ __mmap_switched: ldrsh w14, [x12, #6] // Elf64_Sym::st_shndx ldr x15, [x12, #8] // Elf64_Sym::st_value cmp w14, #-0xf // SHN_ABS (0xfff1) ? - add x14, x15, x23 // relocate + add x14, x15, x1 // relocate csel x15, x14, x15, ne add x15, x13, x15 - str x15, [x11, x23] + str x15, [x11, x1] b 0b 2: adr_l x8, kimage_vaddr // make relocated kimage_vaddr @@ -485,11 +495,10 @@ __mmap_switched: bl kasan_early_init #endif #ifdef CONFIG_RANDOMIZE_BASE - cbnz x23, 0f // already running randomized? + cbnz x26, 0f // already running randomized? ldr_l x0, boot_args // pass FDT address in x0 bl kaslr_early_init // parse FDT for KASLR options cbz x0, 0f // KASLR disabled? just proceed - mov x23, x0 // record KASLR offset ldp x29, x30, [sp], #16 // we must enable KASLR, return ret // to __enable_mmu() 0: @@ -747,6 +756,8 @@ ENTRY(__early_cpu_boot_status) * * Checks if the selected granule size is supported by the CPU. * If it isn't, park the CPU + * + * Clobbers callee saved registers x22, x23, x24 and x25 */ .section ".idmap.text", "ax" __enable_mmu: @@ -771,30 +782,33 @@ __enable_mmu: ic iallu dsb nsh isb - mov x20, x1 // preserve branch target + mov x25, x1 // preserve branch target + mov x1, xzr #ifdef CONFIG_RANDOMIZE_BASE - mov x19, x0 // preserve new SCTLR_EL1 value + mov x24, x0 // preserve new SCTLR_EL1 value adrp x0, __PHYS_OFFSET - blr x1 + blr x25 /* - * If we return here, we have a KASLR displacement in x23 which we need + * If we return here, we have a KASLR displacement in x0 which we need * to take into account by discarding the current kernel mapping and * creating a new one. */ msr sctlr_el1, x22 // disable the MMU isb + mov x23, x0 // preserve new kaslr_offset bl __create_page_tables // recreate kernel mapping - msr sctlr_el1, x19 // re-enable the MMU + msr sctlr_el1, x24 // re-enable the MMU isb ic iallu // flush instructions fetched dsb nsh // via old mapping isb - add x20, x20, x23 // relocated __mmap_switched + add x25, x25, x23 // relocated __mmap_switched + mov x1, x23 #endif adrp x0, __PHYS_OFFSET - br x20 + br x25 ENDPROC(__enable_mmu) __no_granule_support: