[PATCH 0/2] arm64: head.S cleanup

STALE3466d

Revision v1 of 2 in this series.

8 messages, 3 authors, 2017-03-21 · open the first message on its own page

[PATCH 0/2] arm64: head.S cleanup

From: mark.rutland@arm.com (Mark Rutland)
Date: 2017-02-15 14:54:15

While looking at head.S, I saw that over time we've grown some
convoluted code paths that can be simplified.

These patches clean those up.

Thanks,
Mark.

Mark Rutland (2):
  arm64: reduce el2_setup branching
  arm64: move !VHE work to end of el2_setup

 arch/arm64/kernel/head.S | 52 ++++++++++++++++++++++--------------------------
 1 file changed, 24 insertions(+), 28 deletions(-)

-- 
1.9.1

[PATCH 1/2] arm64: reduce el2_setup branching

From: mark.rutland@arm.com (Mark Rutland)
Date: 2017-02-15 14:54:16

The early el2_setup code is a little convoluted, with two branches where
one would do. This makes the code more painful to read than is
necessary.

We can remove a branch and simplify the logic by moving the early return
in the booted-at-EL1 case earlier in the function. This separates it
from all the setup logic that only makes sense for EL2.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Marc Zyngier <redacted>
Cc: Will Deacon <redacted>
---
 arch/arm64/kernel/head.S | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 4fb6ccd..2c37334 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -534,13 +534,8 @@ ENTRY(kimage_vaddr)
 ENTRY(el2_setup)
 	mrs	x0, CurrentEL
 	cmp	x0, #CurrentEL_EL2
-	b.ne	1f
-	mrs	x0, sctlr_el2
-CPU_BE(	orr	x0, x0, #(1 << 25)	)	// Set the EE bit for EL2
-CPU_LE(	bic	x0, x0, #(1 << 25)	)	// Clear the EE bit for EL2
-	msr	sctlr_el2, x0
-	b	2f
-1:	mrs	x0, sctlr_el1
+	b.eq	1f
+	mrs	x0, sctlr_el1
 CPU_BE(	orr	x0, x0, #(3 << 24)	)	// Set the EE and E0E bits for EL1
 CPU_LE(	bic	x0, x0, #(3 << 24)	)	// Clear the EE and E0E bits for EL1
 	msr	sctlr_el1, x0
@@ -548,7 +543,11 @@ CPU_LE(	bic	x0, x0, #(3 << 24)	)	// Clear the EE and E0E bits for EL1
 	isb
 	ret
 
-2:
+1:	mrs	x0, sctlr_el2
+CPU_BE(	orr	x0, x0, #(1 << 25)	)	// Set the EE bit for EL2
+CPU_LE(	bic	x0, x0, #(1 << 25)	)	// Clear the EE bit for EL2
+	msr	sctlr_el2, x0
+
 #ifdef CONFIG_ARM64_VHE
 	/*
 	 * Check for VHE being present. For the rest of the EL2 setup,
-- 
1.9.1

[PATCH 2/2] arm64: move !VHE work to end of el2_setup

From: mark.rutland@arm.com (Mark Rutland)
Date: 2017-02-15 14:54:17

We only need to initialise sctlr_el1 if we're installing an EL2 stub, so
we may as well defer this until we're doing so. Similarly, we can defer
intialising CPTR_EL2 until then, as we do not access any trapped
functionality as part of el2_setup.

This patch modified el2_setup accordingly, allowing us to remove a
branch and simplify the code flow.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Marc Zyngier <redacted>
Cc: Will Deacon <redacted>
---
 arch/arm64/kernel/head.S | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 2c37334..0b13748 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -611,26 +611,6 @@ set_hcr:
 	msr	vpidr_el2, x0
 	msr	vmpidr_el2, x1
 
-	/*
-	 * When VHE is not in use, early init of EL2 and EL1 needs to be
-	 * done here.
-	 * When VHE _is_ in use, EL1 will not be used in the host and
-	 * requires no configuration, and all non-hyp-specific EL2 setup
-	 * will be done via the _EL1 system register aliases in __cpu_setup.
-	 */
-	cbnz	x2, 1f
-
-	/* sctlr_el1 */
-	mov	x0, #0x0800			// Set/clear RES{1,0} bits
-CPU_BE(	movk	x0, #0x33d0, lsl #16	)	// Set EE and E0E on BE systems
-CPU_LE(	movk	x0, #0x30d0, lsl #16	)	// Clear EE and E0E on LE systems
-	msr	sctlr_el1, x0
-
-	/* Coprocessor traps. */
-	mov	x0, #0x33ff
-	msr	cptr_el2, x0			// Disable copro. traps to EL2
-1:
-
 #ifdef CONFIG_COMPAT
 	msr	hstr_el2, xzr			// Disable CP15 traps to EL2
 #endif
@@ -667,6 +647,23 @@ CPU_LE(	movk	x0, #0x30d0, lsl #16	)	// Clear EE and E0E on LE systems
 	ret
 
 install_el2_stub:
+	/*
+	 * When VHE is not in use, early init of EL2 and EL1 needs to be
+	 * done here.
+	 * When VHE _is_ in use, EL1 will not be used in the host and
+	 * requires no configuration, and all non-hyp-specific EL2 setup
+	 * will be done via the _EL1 system register aliases in __cpu_setup.
+	 */
+	/* sctlr_el1 */
+	mov	x0, #0x0800			// Set/clear RES{1,0} bits
+CPU_BE(	movk	x0, #0x33d0, lsl #16	)	// Set EE and E0E on BE systems
+CPU_LE(	movk	x0, #0x30d0, lsl #16	)	// Clear EE and E0E on LE systems
+	msr	sctlr_el1, x0
+
+	/* Coprocessor traps. */
+	mov	x0, #0x33ff
+	msr	cptr_el2, x0			// Disable copro. traps to EL2
+
 	/* Hypervisor stub */
 	adr_l	x0, __hyp_stub_vectors
 	msr	vbar_el2, x0
-- 
1.9.1

[PATCH 0/2] arm64: head.S cleanup

From: catalin.marinas@arm.com (Catalin Marinas)
Date: 2017-03-21 15:37:11

On Wed, Feb 15, 2017 at 02:54:15PM +0000, Mark Rutland wrote:
Mark Rutland (2):
  arm64: reduce el2_setup branching
  arm64: move !VHE work to end of el2_setup
Mark, Marc, do these patches conflict with the hyp stub cleanup? If
there is some overlap, I'm happy for them to go via the kvm tree
together with the others.

-- 
Catalin

[PATCH 1/2] arm64: reduce el2_setup branching

From: Marc Zyngier <hidden>
Date: 2017-03-21 15:43:32

On 15/02/17 14:54, Mark Rutland wrote:
The early el2_setup code is a little convoluted, with two branches where
one would do. This makes the code more painful to read than is
necessary.

We can remove a branch and simplify the logic by moving the early return
in the booted-at-EL1 case earlier in the function. This separates it
from all the setup logic that only makes sense for EL2.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Marc Zyngier <redacted>
Cc: Will Deacon <redacted>
Acked-by: Marc Zyngier <redacted>

	M.
-- 
Jazz is not dead. It just smells funny...

[PATCH 2/2] arm64: move !VHE work to end of el2_setup

From: Marc Zyngier <hidden>
Date: 2017-03-21 15:47:49

On 15/02/17 14:54, Mark Rutland wrote:
We only need to initialise sctlr_el1 if we're installing an EL2 stub, so
we may as well defer this until we're doing so. Similarly, we can defer
intialising CPTR_EL2 until then, as we do not access any trapped
functionality as part of el2_setup.

This patch modified el2_setup accordingly, allowing us to remove a
branch and simplify the code flow.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Marc Zyngier <redacted>
Cc: Will Deacon <redacted>
Acked-by: Marc Zyngier <redacted>

	M.
-- 
Jazz is not dead. It just smells funny...

[PATCH 0/2] arm64: head.S cleanup

From: Marc Zyngier <hidden>
Date: 2017-03-21 15:51:55

On 21/03/17 15:37, Catalin Marinas wrote:
On Wed, Feb 15, 2017 at 02:54:15PM +0000, Mark Rutland wrote:
quoted
Mark Rutland (2):
  arm64: reduce el2_setup branching
  arm64: move !VHE work to end of el2_setup
Mark, Marc, do these patches conflict with the hyp stub cleanup? If
there is some overlap, I'm happy for them to go via the kvm tree
together with the others.
I don't think there is any overlap, my changes stay clear of head.S.

Thanks,

	M.
-- 
Jazz is not dead. It just smells funny...

[PATCH 0/2] arm64: head.S cleanup

From: catalin.marinas@arm.com (Catalin Marinas)
Date: 2017-03-21 16:03:32

On Tue, Mar 21, 2017 at 03:51:55PM +0000, Marc Zyngier wrote:
On 21/03/17 15:37, Catalin Marinas wrote:
quoted
On Wed, Feb 15, 2017 at 02:54:15PM +0000, Mark Rutland wrote:
quoted
Mark Rutland (2):
  arm64: reduce el2_setup branching
  arm64: move !VHE work to end of el2_setup
Mark, Marc, do these patches conflict with the hyp stub cleanup? If
there is some overlap, I'm happy for them to go via the kvm tree
together with the others.
I don't think there is any overlap, my changes stay clear of head.S.
Thanks (for the ack as well). Queued for 4.12.

-- 
Catalin
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help