linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 1/2] arm64/relocate_kernel: remove redundant code
@ 2020-08-28 13:39 Pingfan Liu
  2020-08-28 13:39 ` [PATCHv2 2/2] Documentation/kvm/arm: improve description of HVC_SOFT_RESTART Pingfan Liu
  2020-09-11 18:16 ` [PATCHv2 1/2] arm64/relocate_kernel: remove redundant code Will Deacon
  0 siblings, 2 replies; 4+ messages in thread
From: Pingfan Liu @ 2020-08-28 13:39 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Mark Rutland, Kees Cook, Geoff Levand, Catalin Marinas,
	Remi Denis-Courmont, Pingfan Liu, kvmarm, Mark Brown,
	James Morse, Marc Zyngier, Will Deacon, Ard Biesheuvel

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

Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: James Morse <james.morse@arm.com>
Cc: Geoff Levand <geoff@infradead.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Remi Denis-Courmont <remi.denis.courmont@huawei.com>
Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: kvmarm@lists.cs.columbia.edu
To: linux-arm-kernel@lists.infradead.org
---
 arch/arm64/kernel/cpu-reset.S       |  4 ++++
 arch/arm64/kernel/relocate_kernel.S | 12 ------------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/arch/arm64/kernel/cpu-reset.S b/arch/arm64/kernel/cpu-reset.S
index 4a18055..37721eb 100644
--- a/arch/arm64/kernel/cpu-reset.S
+++ b/arch/arm64/kernel/cpu-reset.S
@@ -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
 
diff --git a/arch/arm64/kernel/relocate_kernel.S b/arch/arm64/kernel/relocate_kernel.S
index 542d6ed..84eec95 100644
--- a/arch/arm64/kernel/relocate_kernel.S
+++ b/arch/arm64/kernel/relocate_kernel.S
@@ -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
 
-- 
2.7.5


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCHv2 2/2] Documentation/kvm/arm: improve description of HVC_SOFT_RESTART
  2020-08-28 13:39 [PATCHv2 1/2] arm64/relocate_kernel: remove redundant code Pingfan Liu
@ 2020-08-28 13:39 ` Pingfan Liu
  2020-09-11 18:32   ` Will Deacon
  2020-09-11 18:16 ` [PATCHv2 1/2] arm64/relocate_kernel: remove redundant code Will Deacon
  1 sibling, 1 reply; 4+ messages in thread
From: Pingfan Liu @ 2020-08-28 13:39 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Suzuki K Poulose, Geoff Levand, Marc Zyngier, linux-doc,
	Pingfan Liu, James Morse, Catalin Marinas, Will Deacon, kvmarm,
	Julien Thierry

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

Signed-off-by: Pingfan Liu <kernelfans@gmail.com>
Cc: James Morse <james.morse@arm.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Geoff Levand <geoff@infradead.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Julien Thierry <julien.thierry.kdev@gmail.com>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: linux-doc@vger.kernel.org
Cc: kvmarm@lists.cs.columbia.edu
To: linux-arm-kernel@lists.infradead.org
---
 Documentation/virt/kvm/arm/hyp-abi.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Documentation/virt/kvm/arm/hyp-abi.rst b/Documentation/virt/kvm/arm/hyp-abi.rst
index d9eba93..83cadd8 100644
--- a/Documentation/virt/kvm/arm/hyp-abi.rst
+++ b/Documentation/virt/kvm/arm/hyp-abi.rst
@@ -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.
-- 
2.7.5


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCHv2 1/2] arm64/relocate_kernel: remove redundant code
  2020-08-28 13:39 [PATCHv2 1/2] arm64/relocate_kernel: remove redundant code Pingfan Liu
  2020-08-28 13:39 ` [PATCHv2 2/2] Documentation/kvm/arm: improve description of HVC_SOFT_RESTART Pingfan Liu
@ 2020-09-11 18:16 ` Will Deacon
  1 sibling, 0 replies; 4+ messages in thread
From: Will Deacon @ 2020-09-11 18:16 UTC (permalink / raw)
  To: Pingfan Liu, linux-arm-kernel
  Cc: Marc Zyngier, Kees Cook, Will Deacon, Geoff Levand,
	catalin.marinas, kvmarm, Mark Brown, Remi Denis-Courmont,
	kernel-team, Ard Biesheuvel

On Fri, 28 Aug 2020 21:39:57 +0800, Pingfan Liu wrote:
> 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,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCHv2 2/2] Documentation/kvm/arm: improve description of HVC_SOFT_RESTART
  2020-08-28 13:39 ` [PATCHv2 2/2] Documentation/kvm/arm: improve description of HVC_SOFT_RESTART Pingfan Liu
@ 2020-09-11 18:32   ` Will Deacon
  0 siblings, 0 replies; 4+ messages in thread
From: Will Deacon @ 2020-09-11 18:32 UTC (permalink / raw)
  To: Pingfan Liu, linux-arm-kernel
  Cc: Will Deacon, linux-doc, Geoff Levand, catalin.marinas,
	Marc Zyngier, kernel-team, kvmarm

On Fri, 28 Aug 2020 21:39:58 +0800, Pingfan Liu wrote:
> 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,
-- 
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-11 18:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-28 13:39 [PATCHv2 1/2] arm64/relocate_kernel: remove redundant code Pingfan Liu
2020-08-28 13:39 ` [PATCHv2 2/2] Documentation/kvm/arm: improve description of HVC_SOFT_RESTART Pingfan Liu
2020-09-11 18:32   ` Will Deacon
2020-09-11 18:16 ` [PATCHv2 1/2] arm64/relocate_kernel: remove redundant code Will Deacon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).