我在哪里可以检查 Linux 内核是在非安全 (EL2) 还是安全 (EL3) 模式下运行?
如何更改此模式?
我在 ARMv8 64 位上运行。
提前致谢
最佳答案
Where can I check to know if the Linux kernel is running in non-secure (EL2) or secure (EL3) mode ?
我要给出一个厚颜无耻的答案。
适应what is the current execution mode/exception level, etc?并破解您感兴趣的区域:
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();
启动时的输出。
EL = 1
默认的 Linux 内核 v4.19 引导日志还告诉我们默认情况下:
CPU: All CPU(s) started at EL1
How can I change this mode?
传统上,内核仅在 EL1 上运行,EL2 留给 Xen 等管理程序,EL3 留给 ARM Trusted Firmware 等引导加载程序。
然而,随着 ARMv8.1 VHE 扩展的引入,EL2 内核变得高效并被添加到 Linux 主线:What are Ring 0 and Ring 3 in the context of operating systems?虽然不确定哪个配置会打开它,请看一下。
EL3 我不认为有什么主线。有些人也试图将内核代码改编为 booloader,看看例如在:https://github.com/kexecboot/kexecboot
关于linux - 如何知道 linux 内核运行 EL2(非安全)或 EL3(安全)模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39614772/