Skip to contentSkip to conversation

arm64: Fix EL1/EL2 early init inconsistencies with VHE

RFC PATCH Applied Dave Martin 3 participants 3 messages Apr 18, 2016 – Apr 22, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 arm64: Fix EL1/EL2 early init inconsistencies with VHE

When using the Virtualisation Host Extensions, EL1 is not used in the host and requires no separate configuration.

In addition, with VHE enabled, non-hyp-specific EL2 configuration that does not need to be done early will be done anyway in __cpu_setup via the _EL1 system register aliases. In particular, the layout and definition of CPTR_EL2 are changed by enabling VHE so that they resemble CPACR_EL1, so existing code to initialise CPTR_EL2 becomes architecturally wrong in this case.

This patch simply skips the affected initialisation code in the non-VHE case.

---

Note -- not tested yet, and I'm still unclear on whether this is the correct architectural approach...

 arch/arm64/kernel/head.S | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/arm64/kernel/head.S +10 -0
index 4203d5f..67132c1 100644
@@ -588,6 +588,15 @@ 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
@@ -597,6 +606,7 @@ CPU_LE(	movk	x0, #0x30d0, lsl #16	)	// Clear EE and E0E on LE systems
 	/* 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
Signature · 1 line
2.1.4
Reviewed-by on v1 1/1
#1 lore raw

Hi Dave,

Quoted 10 lines · Dave Martin

When using the Virtualisation Host Extensions, EL1 is not used in the host and requires no separate configuration.

In addition, with VHE enabled, non-hyp-specific EL2 configuration that does not need to be done early will be done anyway in __cpu_setup via the _EL1 system register aliases. In particular, the layout and definition of CPTR_EL2 are changed by enabling VHE so that they resemble CPACR_EL1, so existing code to initialise CPTR_EL2 becomes architecturally wrong in this case.

Quoted 8 lines

This patch simply skips the affected initialisation code in the non-VHE case.

---

Note -- not tested yet, and I'm still unclear on whether this is the correct architectural approach...

This looks correct to me. Given that we're not leaving EL2, there is no reason to do things earlier than they are done at EL1, and this fixes an obvious bug on CPTR_EL2 access.

I've given it a go on a VHE model, and it ran just fine, so:

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
maintainer Applied
#2 lore raw
In reply to Dave Martin
Quoted 10 lines · Dave P Martin

When using the Virtualisation Host Extensions, EL1 is not used in the host and requires no separate configuration.

In addition, with VHE enabled, non-hyp-specific EL2 configuration that does not need to be done early will be done anyway in __cpu_setup via the _EL1 system register aliases. In particular, the layout and definition of CPTR_EL2 are changed by enabling VHE so that they resemble CPACR_EL1, so existing code to initialise CPTR_EL2 becomes architecturally wrong in this case.

Quoted 4 lines

This patch simply skips the affected initialisation code in the non-VHE case.

I queued this for 4.6 (with Marc's ack). Thanks.

Signature · 1 line
Catalin