Skip to contentSkip to conversation

arm64/relocate_kernel: remove redundant code

PATCH In review Pingfan Liu 2 participants 4 messages Aug 28, 2020 – Sep 11, 2020

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

PATCH v2 1/2 arm64/relocate_kernel: remove redundant code

Kernel startup entry point requires disabling MMU and D-cache.

As for kexec-reboot, taking a close look at "msr sctlr_el1, x12" in __cpu_soft_restart as the following:

-1. booted at EL1
The instruction is enough to disable MMU and I/D cache for EL1 regime.

-2. booted at EL2, using VHE
Access to SCTLR_EL1 is redirected to SCTLR_EL2 in EL2. So the instruction is enough to disable MMU and clear I+C bits for EL2 regime.

-3. booted at EL2, not using VHE
The instruction itself can not affect EL2 regime. But The hyp-stub doesn't enable the MMU and I/D cache for EL2 regime. And KVM also disable them for EL2 regime when its unloaded, or execute a HVC_SOFT_RESTART call. So when kexec-reboot, the code in KVM has prepare the requirement.

As a conclusion, disabling MMU and clearing I+C bits in SYM_CODE_START(arm64_relocate_new_kernel) is redundant, and can be removed

Cc James Morse <[email protected]>
Cc Geoff Levand <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Mark Brown <[email protected]>
Cc Kees Cook <[email protected]>
Cc Remi Denis-Courmont <[email protected]>
Cc Ard Biesheuvel <[email protected]>

To: [email protected]

---
 arch/arm64/kernel/cpu-reset.S       |  4 ++++
 arch/arm64/kernel/relocate_kernel.S | 12 ------------
 2 files changed, 4 insertions(+), 12 deletions(-)
arch/arm64/kernel/cpu-reset.S +4 -0
index 4a18055..37721eb 100644
@@ -35,6 +35,10 @@ SYM_CODE_START(__cpu_soft_restart)
 	mov_q	x13, SCTLR_ELx_FLAGS
 	bic	x12, x12, x13
 	pre_disable_mmu_workaround
+	/*
+	 * either disable EL1&0 translation regime or disable EL2&0 translation
+	 * regime if HCR_EL2.E2H == 1
+	 */
 	msr	sctlr_el1, x12
 	isb
 
arch/arm64/kernel/relocate_kernel.S +0 -12
index 542d6ed..84eec95 100644
@@ -36,18 +36,6 @@ SYM_CODE_START(arm64_relocate_new_kernel)
 	mov	x14, xzr			/* x14 = entry ptr */
 	mov	x13, xzr			/* x13 = copy dest */
 
-	/* Clear the sctlr_el2 flags. */
-	mrs	x0, CurrentEL
-	cmp	x0, #CurrentEL_EL2
-	b.ne	1f
-	mrs	x0, sctlr_el2
-	mov_q	x1, SCTLR_ELx_FLAGS
-	bic	x0, x0, x1
-	pre_disable_mmu_workaround
-	msr	sctlr_el2, x0
-	isb
-1:
-
 	/* Check if the new image needs relocation. */
 	tbnz	x16, IND_DONE_BIT, .Ldone
 
Signature · 7 lines
2.7.5


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

PATCH v2 2/2 Documentation/kvm/arm: improve description of HVC_SOFT_RESTART

Besides disabling MMU, HVC_SOFT_RESTART also clears I+D bits. These behaviors are what kexec-reboot expects, so describe it more precisely.

Cc James Morse <[email protected]>
Cc Marc Zyngier <[email protected]>
Cc Geoff Levand <[email protected]>
Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Julien Thierry <[email protected]>
Cc Suzuki K Poulose <[email protected]>

To: [email protected]

---
 Documentation/virt/kvm/arm/hyp-abi.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/virt/kvm/arm/hyp-abi.rst +3 -3
index d9eba93..83cadd8 100644
@@ -54,9 +54,9 @@ these functions (see arch/arm{,64}/include/asm/virt.h):
     x3 = x1's value when entering the next payload (arm64)
     x4 = x2's value when entering the next payload (arm64)
 
-  Mask all exceptions, disable the MMU, move the arguments into place
-  (arm64 only), and jump to the restart address while at HYP/EL2. This
-  hypercall is not expected to return to its caller.
+  Mask all exceptions, disable the MMU, clear I+D bits, move the arguments
+  into place (arm64 only), and jump to the restart address while at HYP/EL2.
+  This hypercall is not expected to return to its caller.
 
 Any other value of r0/x0 triggers a hypervisor-specific handling,
 which is not documented here.
Signature · 7 lines
2.7.5


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer
#2 lore raw

Re: [PATCHv2 2/2] Documentation/kvm/arm: improve description of HVC_SOFT_RESTART

Quoted 2 lines · Pingfan Liu

Besides disabling MMU, HVC_SOFT_RESTART also clears I+D bits. These behaviors are what kexec-reboot expects, so describe it more precisely.

Applied to arm64 (for-next/boot), thanks!

[1/1] Documentation/kvm/arm: improve description of HVC_SOFT_RESTART

      https://git.kernel.org/arm64/c/3a1793066fdf

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
maintainer
#3 lore raw
In reply to Pingfan Liu
Quoted 10 lines · Pingfan Liu

Kernel startup entry point requires disabling MMU and D-cache.

As for kexec-reboot, taking a close look at "msr sctlr_el1, x12" in __cpu_soft_restart as the following:

-1. booted at EL1
The instruction is enough to disable MMU and I/D cache for EL1 regime.

[...]

Applied to arm64 (for-next/boot), thanks!

[1/1] arm64/relocate_kernel: remove redundant code

      https://git.kernel.org/arm64/c/72789a4a6a91

Cheers,

Signature · 9 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm