arm64: kernel: add helper for booted at EL2 and not VHE
authorPasha Tatashin <pasha.tatashin@soleen.com>
Thu, 30 Sep 2021 14:30:59 +0000 (14:30 +0000)
committerWill Deacon <will@kernel.org>
Fri, 1 Oct 2021 12:30:59 +0000 (13:30 +0100)
Replace places that contain logic like this:
is_hyp_mode_available() && !is_kernel_in_hyp_mode()

With a dedicated boolean function  is_hyp_nvhe(). This will be needed
later in kexec in order to sooner switch back to EL2.

Suggested-by: James Morse <james.morse@arm.com>
Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/r/20210930143113.1502553-2-pasha.tatashin@soleen.com
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/include/asm/virt.h
arch/arm64/kernel/cpu-reset.h
arch/arm64/kernel/hibernate.c
arch/arm64/kernel/sdei.c

index 7379f35ae2c654c27e78588af298871eca4450ef..a9457e96203c07377b678dd7011990774d2f6649 100644 (file)
@@ -128,6 +128,11 @@ static __always_inline bool is_protected_kvm_enabled(void)
                return cpus_have_final_cap(ARM64_KVM_PROTECTED_MODE);
 }
 
+static inline bool is_hyp_nvhe(void)
+{
+       return is_hyp_mode_available() && !is_kernel_in_hyp_mode();
+}
+
 #endif /* __ASSEMBLY__ */
 
 #endif /* ! __ASM__VIRT_H */
index 9a7b1262ef17a3a6462ffc31d2974f199f5a31c1..81b3d0fe7a63339923ec217de501ed9317e7968d 100644 (file)
@@ -20,8 +20,7 @@ static inline void __noreturn __nocfi cpu_soft_restart(unsigned long entry,
 {
        typeof(__cpu_soft_restart) *restart;
 
-       unsigned long el2_switch = !is_kernel_in_hyp_mode() &&
-               is_hyp_mode_available();
+       unsigned long el2_switch = is_hyp_nvhe();
        restart = (void *)__pa_symbol(function_nocfi(__cpu_soft_restart));
 
        cpu_install_idmap();
index 46a0b4d6e2519768eaa86bc141f75f2efa698550..4c9533f4c0c4f084566f7c11823413af2c2ade93 100644 (file)
@@ -49,7 +49,7 @@
 extern int in_suspend;
 
 /* Do we need to reset el2? */
-#define el2_reset_needed() (is_hyp_mode_available() && !is_kernel_in_hyp_mode())
+#define el2_reset_needed() (is_hyp_nvhe())
 
 /* temporary el2 vectors in the __hibernate_exit_text section. */
 extern char hibernate_el2_vectors[];
index 47f77d1234cb6b3e5a6839fa9ce38437ef63c950..d20620a1c51a470ed3e43f0ac0370e8c68d9b8e0 100644 (file)
@@ -202,7 +202,7 @@ unsigned long sdei_arch_get_entry_point(int conduit)
         * dropped to EL1 because we don't support VHE, then we can't support
         * SDEI.
         */
-       if (is_hyp_mode_available() && !is_kernel_in_hyp_mode()) {
+       if (is_hyp_nvhe()) {
                pr_err("Not supported on this hardware/boot configuration\n");
                goto out_err;
        }