yvo.engr
yvo.engr

Reputation: 141

How to know the linux kernel run either EL2 (non-secure) or EL3 (secure) mode?

Where can I check to know if the Linux kernel is running in non-secure (EL2) or secure (EL3) mode ?

How can I change this mode ?

I run on the ARMv8 64 bits.

Thanks in advance

Upvotes: 3

Views: 2926

Answers (1)

Ciro Santilli
Ciro Santilli

Reputation: 4043

Where can I check to know if the Linux kernel is running in non-secure (EL2) or secure (EL3) mode ?

I'm going to give a cheeky answer.

Adapt what is the current execution mode/exception level, etc? and hack your region of interest:

diff --git a/init/main.c b/init/main.c
index 18f8f0140fa0..840f886d17b3 100644
--- a/init/main.c
+++ b/init/main.c
@@ -533,6 +533,10 @@ asmlinkage __visible void __init start_kernel(void)
    char *command_line;
    char *after_dashes;

+   register u64 x0 __asm__ ("x0");
+   __asm__ ("mrs x0, CurrentEL;" : : : "%x0");
+   pr_info("EL = %llu\n", (unsigned long long)(x0 >> 2));
+
    set_task_stack_end_magic(&init_task);
    smp_setup_processor_id();
    debug_objects_early_init();

Output at the start of boot.

EL = 1

The default Linux kernel v4.19 boot logs also tell us that by default:

CPU: All CPU(s) started at EL1

How can I change this mode?

Traditionally the kernel ran on EL1 only, and EL2 was left for a hypervisor like Xen, and EL3 for a bootloader like ARM Trusted Firmware.

However, with the introduction of the ARMv8.1 VHE extension, EL2 kernel became efficient and was added into Linux mainline: What are Ring 0 and Ring 3 in the context of operating systems? Not sure which config turns it on though, have a look.

EL3 I don't think there's anything mainline. There are some people trying to adapt kernel code to be the booloader as well, have a look e.g. at: https://github.com/kexecboot/kexecboot

Upvotes: 5

Related Questions