Commit ac1ad20f authored by Suzuki K Poulose's avatar Suzuki K Poulose Committed by Will Deacon

arm64: vhe: Verify CPU Exception Levels

With a VHE capable CPU, kernel can run at EL2 and is a decided at early
boot. If some of the CPUs didn't start it EL2 or doesn't have VHE, we
could have CPUs running at different exception levels, all in the same
kernel! This patch adds an early check for the secondary CPUs to detect
such situations.

For each non-boot CPU add a sanity check to make sure we don't have
different run levels w.r.t the boot CPU. We save the information on
whether the boot CPU is running in hyp mode or not and ensure the
remaining CPUs match it.

Cc: Marc Zyngier <>
Cc: Will Deacon <>
Cc: Mark Rutland <>
Cc: Catalin Marinas <>
Reviewed-by: default avatarChristoffer Dall <>
Signed-off-by: default avatarSuzuki K Poulose <>
[will: made boot_cpu_hyp_mode static]
Signed-off-by: default avatarWill Deacon <>
parent 17eebd1a
......@@ -60,6 +60,12 @@ static inline bool is_kernel_in_hyp_mode(void)
return el == CurrentEL_EL2;
extern void verify_cpu_run_el(void);
static inline void verify_cpu_run_el(void) {}
/* The section containing the hypervisor text */
extern char __hyp_text_start[];
extern char __hyp_text_end[];
......@@ -912,6 +912,7 @@ static u64 __raw_read_system_reg(u32 sys_id)
static void check_early_cpu_features(void)
......@@ -75,6 +75,43 @@ enum ipi_msg_type {
/* Whether the boot CPU is running in HYP mode or not*/
static bool boot_cpu_hyp_mode;
static inline void save_boot_cpu_run_el(void)
boot_cpu_hyp_mode = is_kernel_in_hyp_mode();
static inline bool is_boot_cpu_in_hyp_mode(void)
return boot_cpu_hyp_mode;
* Verify that a secondary CPU is running the kernel at the same
* EL as that of the boot CPU.
void verify_cpu_run_el(void)
bool in_el2 = is_kernel_in_hyp_mode();
bool boot_cpu_el2 = is_boot_cpu_in_hyp_mode();
if (in_el2 ^ boot_cpu_el2) {
pr_crit("CPU%d: mismatched Exception Level(EL%d) with boot CPU(EL%d)\n",
in_el2 ? 2 : 1,
boot_cpu_el2 ? 2 : 1);
static inline void save_boot_cpu_run_el(void) {}
static int op_cpu_kill(unsigned int cpu);
......@@ -401,6 +438,7 @@ void __init smp_cpus_done(unsigned int max_cpus)
void __init smp_prepare_boot_cpu(void)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment