All of lore.kernel.org
 help / color / mirror / Atom feed
From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 4/9] arm64: head.S: move KASLR processing out of __enable_mmu()
Date: Wed, 24 Aug 2016 16:36:01 +0200	[thread overview]
Message-ID: <1472049366-10922-5-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1472049366-10922-1-git-send-email-ard.biesheuvel@linaro.org>

The KASLR processing in __enable_mmu() is only used by the primary boot
path, and complements the processing that takes place in __primary_switch().
Move the two parts together, to make the code easier to understand.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 arch/arm64/kernel/head.S | 66 ++++++++++++--------
 1 file changed, 39 insertions(+), 27 deletions(-)

diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 2871271123e7..d390feb92730 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -222,9 +222,7 @@ ENTRY(stext)
 	 * the TCR will have been set.
 	 */
 	bl	__cpu_setup			// initialise processor
-	adr_l	x27, __primary_switch		// address to jump to after
-						// MMU has been enabled
-	b	__enable_mmu
+	b	__primary_switch
 ENDPROC(stext)
 
 /*
@@ -453,7 +451,7 @@ __primary_switched:
 	cbz	x0, 0f				// KASLR disabled? just proceed
 	orr	x23, x23, x0			// record KASLR offset
 	ret	x28				// we must enable KASLR, return
-						// to __enable_mmu()
+						// to __primary_switch()
 0:
 #endif
 	b	start_kernel
@@ -721,7 +719,6 @@ ENTRY(__early_cpu_boot_status)
  */
 	.section	".idmap.text", "ax"
 ENTRY(__enable_mmu)
-	mrs	x22, sctlr_el1			// preserve old SCTLR_EL1 value
 	mrs	x1, ID_AA64MMFR0_EL1
 	ubfx	x2, x1, #ID_AA64MMFR0_TGRAN_SHIFT, 4
 	cmp	x2, #ID_AA64MMFR0_TGRAN_SUPPORTED
@@ -742,25 +739,6 @@ ENTRY(__enable_mmu)
 	ic	iallu
 	dsb	nsh
 	isb
-#ifdef CONFIG_RANDOMIZE_BASE
-	mov	x19, x0				// preserve new SCTLR_EL1 value
-	blr	x27
-
-	/*
-	 * If we return here, we have a KASLR displacement in x23 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
-	bl	__create_page_tables		// recreate kernel mapping
-
-	msr	sctlr_el1, x19			// re-enable the MMU
-	isb
-	ic	iallu				// flush instructions fetched
-	dsb	nsh				// via old mapping
-	isb
-#endif
 	br	x27
 ENDPROC(__enable_mmu)
 
@@ -770,11 +748,11 @@ __no_granule_support:
 1:
 	wfe
 	wfi
-	b 1b
+	b	1b
 ENDPROC(__no_granule_support)
 
-__primary_switch:
 #ifdef CONFIG_RELOCATABLE
+__relocate_kernel:
 	/*
 	 * Iterate over each entry in the relocation table, and apply the
 	 * relocations in place.
@@ -796,8 +774,42 @@ __primary_switch:
 	add	x13, x13, x23			// relocate
 	str	x13, [x11, x23]
 	b	0b
+1:	ret
+ENDPROC(__relocate_kernel)
+#endif
 
-1:
+__primary_switch:
+#ifdef CONFIG_RANDOMIZE_BASE
+	mov	x19, x0				// preserve new SCTLR_EL1 value
+	mrs	x20, sctlr_el1			// preserve old SCTLR_EL1 value
+#endif
+
+	adr	x27, 0f
+	b	__enable_mmu
+0:
+#ifdef CONFIG_RELOCATABLE
+	bl	__relocate_kernel
+#ifdef CONFIG_RANDOMIZE_BASE
+	ldr	x8, =__primary_switched
+	blr	x8
+
+	/*
+	 * If we return here, we have a KASLR displacement in x23 which we need
+	 * to take into account by discarding the current kernel mapping and
+	 * creating a new one.
+	 */
+	msr	sctlr_el1, x20			// disable the MMU
+	isb
+	bl	__create_page_tables		// recreate kernel mapping
+
+	msr	sctlr_el1, x19			// re-enable the MMU
+	isb
+	ic	iallu				// flush instructions fetched
+	dsb	nsh				// via old mapping
+	isb
+
+	bl	__relocate_kernel
+#endif
 #endif
 	ldr	x8, =__primary_switched
 	br	x8
-- 
2.7.4

  parent reply	other threads:[~2016-08-24 14:36 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-24 14:35 [PATCH v2 0/9] arm64: clean up early boot function calls Ard Biesheuvel
2016-08-24 14:35 ` [PATCH v2 1/9] arm64: kernel: get rid of x25 and x26 with 'global' scope Ard Biesheuvel
2016-08-24 14:35 ` [PATCH v2 2/9] arm64: kernel: fix style issues in sleep.S Ard Biesheuvel
2016-08-24 16:13   ` Mark Rutland
2016-08-24 14:36 ` [PATCH v2 3/9] arm64: kernel: use ordinary return/argument register for el2_setup() Ard Biesheuvel
2016-08-24 16:20   ` Mark Rutland
2016-08-24 14:36 ` Ard Biesheuvel [this message]
2016-08-24 20:36   ` [PATCH v2 4/9] arm64: head.S: move KASLR processing out of __enable_mmu() Mark Rutland
2016-08-24 20:44     ` Ard Biesheuvel
2016-08-24 20:46     ` Mark Rutland
2016-08-25 13:59       ` Ard Biesheuvel
2016-08-30 10:24         ` Mark Rutland
2016-08-30 13:45   ` Mark Rutland
2016-08-24 14:36 ` [PATCH v2 5/9] arm64: kernel: use x30 for __enable_mmu return address Ard Biesheuvel
2016-08-24 14:36 ` [PATCH v2 6/9] arm64: call __enable_mmu as an ordinary function for secondary/resume Ard Biesheuvel
2016-08-30 14:07   ` Mark Rutland
2016-08-24 14:36 ` [PATCH v2 7/9] arm64: kernel: drop use of x24 from primary boot path Ard Biesheuvel
2016-08-30 14:26   ` Mark Rutland
2016-08-24 14:36 ` [PATCH v2 8/9] arm64: head.S: use ordinary stack frame for __primary_switched() Ard Biesheuvel
2016-08-30 14:38   ` Mark Rutland
2016-08-24 14:36 ` [PATCH v2 9/9] arm64: head.S: document the use of callee saved registers Ard Biesheuvel
2016-08-30 14:43   ` Mark Rutland
2016-08-30 14:48 ` [PATCH v2 0/9] arm64: clean up early boot function calls Mark Rutland
2016-08-30 14:50   ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1472049366-10922-5-git-send-email-ard.biesheuvel@linaro.org \
    --to=ard.biesheuvel@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.