arm64/relocate_kernel: remove redundant code
authorPingfan Liu <kernelfans@gmail.com>
Fri, 28 Aug 2020 13:39:57 +0000 (21:39 +0800)
committerWill Deacon <will@kernel.org>
Fri, 11 Sep 2020 18:06:25 +0000 (19:06 +0100)
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
Link: https://lore.kernel.org/r/1598621998-20563-1-git-send-email-kernelfans@gmail.com
To: linux-arm-kernel@lists.infradead.org
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/kernel/cpu-reset.S
arch/arm64/kernel/relocate_kernel.S

index 4a18055b2ff9d14bde58d4595107344829d2e2ce..37721eb6f9a145b592282b20154179d886d330d6 100644 (file)
@@ -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
 
index 542d6edc6806acaba0e57241c280336c9d90d462..84eec95ec06cc576de1f54b2d41b96bec4989e2e 100644 (file)
@@ -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