Skip to contentSkip to conversation

HYP boot mode fixes

PATCH New Marc Zyngier 3 participants 9 messages Jan 4, 2013 – Jan 9, 2013 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

cover HYP boot mode fixes

Here's a couple of patches fixing issues that have been recently brought to my attention.

The first patch only affects configurations that are already broken (CPUs entering the kernel with different modes). The second one is a bit more serious, and potentially affects setups where the secondary core is brought up using an interrupt that is still pending when the kernel is entered.

Both patches have been tested on TC2, and are based on v3.8-rc2.

Marc Zyngier (2):
ARM: hyp: boot secondary CPUs through the right entry point
ARM: hyp: simplify __hyp_stub_install epilog

 arch/arm/kernel/head.S     |  2 +-
 arch/arm/kernel/hyp-stub.S | 12 +++---------
 2 files changed, 4 insertions(+), 10 deletions(-)
Signature · 1 line
1.8.1
#1 lore raw

PATCH 1/2 ARM: hyp: boot secondary CPUs through the right entry point

Secondary CPUs should use the __hyp_stub_install_secondary entry point, so boot mode inconsistencies can be detected.

---
 arch/arm/kernel/head.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/kernel/head.S +1 -1
index 4eee351..16abc83 100644
@@ -331,7 +331,7 @@ ENTRY(secondary_startup)
 	 * as it has already been validated by the primary processor.
 	 */
 #ifdef CONFIG_ARM_VIRT_EXT
-	bl	__hyp_stub_install
+	bl	__hyp_stub_install_secondary
 #endif
 	safe_svcmode_maskall r9
 
Signature · 1 line
1.8.1
#2 lore raw

PATCH 1/2 ARM: hyp: boot secondary CPUs through the right entry point

Quoted 5 lines · Marc Zyngier

Secondary CPUs should use the __hyp_stub_install_secondary entry point, so boot mode inconsistencies can be detected.

I was just going to report this, but I see I was beaten to it...

Cheers
---Dave

Quoted 26 lines
---
 arch/arm/kernel/head.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/kernel/head.S +1 -1
index 4eee351..16abc83 100644
@@ -331,7 +331,7 @@ ENTRY(secondary_startup)
 	 * as it has already been validated by the primary processor.
 	 */
 #ifdef CONFIG_ARM_VIRT_EXT
-	bl	__hyp_stub_install
+	bl	__hyp_stub_install_secondary
 #endif
 	safe_svcmode_maskall r9
 
Signature · 8 lines
1.8.1



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#3 lore raw

PATCH 2/2 ARM: hyp: simplify __hyp_stub_install epilog

In reply to Marc Zyngier

__hyp_stub_install duplicates quite a bit of safe_svcmode_maskall by forcing the CPU back to SVC. This is unnecessary, as safe_svcmode_maskall is called just after.

Furthermore, the way we build SPSR_hyp is buggy as we fail to mask the interrupts, leading to interesting behaviours on TC2 + UEFI.

The fix is to simply remove this code and rely on safe_svcmode_maskall to do the right thing.

---
 arch/arm/kernel/hyp-stub.S | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
arch/arm/kernel/hyp-stub.S +3 -9
index 65b2417..da7e19f 100644
@@ -120,7 +120,8 @@ ENTRY(__hyp_stub_install_secondary)
  * Eventually, CPU-specific code might be needed -- assume not for now
  *
  * This code relies on the "eret" instruction to synchronize the
- * various coprocessor accesses.
+ * various coprocessor accesses. This is done when we switch to SVC
+ * (see safe_svcmode_maskall).
  */
 	@ Now install the hypervisor stub:
 	adr	r7, __hyp_stub_vectors
@@ -155,14 +156,7 @@ THUMB(	orr	r7, #(1 << 30)	)	@ HSCTLR.TE
 1:
 #endif
 
-	bic	r7, r4, #MODE_MASK
-	orr	r7, r7, #SVC_MODE
-THUMB(	orr	r7, r7, #PSR_T_BIT	)
-	msr	spsr_cxsf, r7		@ This is SPSR_hyp.
-
-	__MSR_ELR_HYP(14)		@ msr elr_hyp, lr
-	__ERET				@ return, switching to SVC mode
-					@ The boot CPU mode is left in r4.
+	bx	lr			@ The boot CPU mode is left in r4.
 ENDPROC(__hyp_stub_install_secondary)
 
 __hyp_stub_do_trap:
Signature · 1 line
1.8.1
#4 lore raw

PATCH 2/2 ARM: hyp: simplify __hyp_stub_install epilog

Quoted 7 lines · Marc Zyngier

__hyp_stub_install duplicates quite a bit of safe_svcmode_maskall by forcing the CPU back to SVC. This is unnecessary, as safe_svcmode_maskall is called just after.

Furthermore, the way we build SPSR_hyp is buggy as we fail to mask the interrupts, leading to interesting behaviours on TC2 + UEFI.

Quoted 6 lines

The fix is to simply remove this code and rely on safe_svcmode_maskall to do the right thing.

Although there is clearly a bug here, it looks like interrupts will promptly get masked afterwards due to save_svcmode_maskall. This would only fail if there is an interrupts asserted during this hazard ...?

Anyway, There's certainly no sense in trying to drop down to SVC mode twice, so I agree that it is better to delegate that to the save_svcmode_maskall macro.

Cheers
---Dave

Quoted 38 lines
---
 arch/arm/kernel/hyp-stub.S | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
arch/arm/kernel/hyp-stub.S +3 -9
index 65b2417..da7e19f 100644
@@ -120,7 +120,8 @@ ENTRY(__hyp_stub_install_secondary)
  * Eventually, CPU-specific code might be needed -- assume not for now
  *
  * This code relies on the "eret" instruction to synchronize the
- * various coprocessor accesses.
+ * various coprocessor accesses. This is done when we switch to SVC
+ * (see safe_svcmode_maskall).
  */
 	@ Now install the hypervisor stub:
 	adr	r7, __hyp_stub_vectors
@@ -155,14 +156,7 @@ THUMB(	orr	r7, #(1 << 30)	)	@ HSCTLR.TE
 1:
 #endif
 
-	bic	r7, r4, #MODE_MASK
-	orr	r7, r7, #SVC_MODE
-THUMB(	orr	r7, r7, #PSR_T_BIT	)
-	msr	spsr_cxsf, r7		@ This is SPSR_hyp.
-
-	__MSR_ELR_HYP(14)		@ msr elr_hyp, lr
-	__ERET				@ return, switching to SVC mode
-					@ The boot CPU mode is left in r4.
+	bx	lr			@ The boot CPU mode is left in r4.
 ENDPROC(__hyp_stub_install_secondary)
 
 __hyp_stub_do_trap:
Signature · 1 line
1.8.1
#5 lore raw

PATCH 2/2 ARM: hyp: simplify __hyp_stub_install epilog

Quoted 11 lines · Dave Martin
Quoted 10 lines · Marc Zyngier

__hyp_stub_install duplicates quite a bit of safe_svcmode_maskall by forcing the CPU back to SVC. This is unnecessary, as safe_svcmode_maskall is called just after.

Furthermore, the way we build SPSR_hyp is buggy as we fail to mask the interrupts, leading to interesting behaviours on TC2 + UEFI.

The fix is to simply remove this code and rely on safe_svcmode_maskall to do the right thing.

Quoted 7 lines
Quoted 3 lines

Although there is clearly a bug here, it looks like interrupts will promptly get masked afterwards due to save_svcmode_maskall. This would only fail if there is an interrupts asserted during this hazard ...?

That's exactly the failure case. It's been observed on TC2 with UEFI, where the secondaries are woken up with a SGI. When they get out of WFI, the interrupt is still pending. After reaching this code and doing an eret, the interrupt fires immediately, with deadly consequences.

Quoted 5 lines

Anyway, There's certainly no sense in trying to drop down to SVC mode twice, so I agree that it is better to delegate that to the save_svcmode_maskall macro.

Thanks!

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#6 lore raw

PATCH 2/2 ARM: hyp: simplify __hyp_stub_install epilog

Quoted 16 lines · Marc Zyngier
Quoted 15 lines · Dave Martin
Quoted 13 lines · Marc Zyngier

__hyp_stub_install duplicates quite a bit of safe_svcmode_maskall by forcing the CPU back to SVC. This is unnecessary, as safe_svcmode_maskall is called just after.

Furthermore, the way we build SPSR_hyp is buggy as we fail to mask the interrupts, leading to interesting behaviours on TC2 + UEFI.

The fix is to simply remove this code and rely on safe_svcmode_maskall to do the right thing.

Quoted 8 lines
Quoted 3 lines

Although there is clearly a bug here, it looks like interrupts will promptly get masked afterwards due to save_svcmode_maskall. This would only fail if there is an interrupts asserted during this hazard ...?

That's exactly the failure case. It's been observed on TC2 with UEFI, where the secondaries are woken up with a SGI. When they get out of WFI, the interrupt is still pending. After reaching this code and doing an eret, the interrupt fires immediately, with deadly consequences.

Ah right. In which case we also have good evidence that the proposed fix fixes it.

Sounds good

Cheers
---Dave

#7 lore raw

cover HYP boot mode fixes

In reply to Marc Zyngier

Hi Marc,

Quoted 10 lines · Marc Zyngier

Here's a couple of patches fixing issues that have been recently brought to my attention.

The first patch only affects configurations that are already broken (CPUs entering the kernel with different modes). The second one is a bit more serious, and potentially affects setups where the secondary core is brought up using an interrupt that is still pending when the kernel is entered.

Both patches have been tested on TC2, and are based on v3.8-rc2.

I've been collecting hyp-boot patches since before Christmas so, if it's alright with you, I'll take these into the branch I currently have and send that lot via Russell. Check my virt/hyp-boot branch if you're interested.

Cheers,

Will

#8 lore raw

cover HYP boot mode fixes

Quoted 12 lines · Will Deacon

Hi Marc,

Quoted 9 lines · Marc Zyngier

Here's a couple of patches fixing issues that have been recently brought to my attention.

The first patch only affects configurations that are already broken (CPUs entering the kernel with different modes). The second one is a bit more serious, and potentially affects setups where the secondary core is brought up using an interrupt that is still pending when the kernel is entered.

Quoted 5 lines
Quoted 1 line

Both patches have been tested on TC2, and are based on v3.8-rc2.

I've been collecting hyp-boot patches since before Christmas so, if it's alright with you, I'll take these into the branch I currently have and send that lot via Russell. Check my virt/hyp-boot branch if you're interested.

Please do. You may want to Cc stable on the second one, as it fixes a observable issue.

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...