[英]Halt instruction from Linux kernel module is not working
I wrote a simple Linux kernel module to issue hlt
instruction我写了一个简单的 Linux 内核模块来发出
hlt
指令
#include <linux/kernel.h>
#include <linux/module.h>
MODULE_LICENSE("GPL");
static int __init test_hello_init(void)
{
asm("hlt");
return 0;
}
static void __exit test_hello_exit(void)
{
}
module_init(test_hello_init);
module_exit(test_hello_exit);
Loading this module on my Virtual Machine, I don't see my VM is halted.在我的虚拟机上加载这个模块,我没有看到我的虚拟机停止了。
Am I missing something?我错过了什么吗?
HLT
doesn't stop your machine, only make that core sleep (in C1 idle) until the next interrupt. HLT
不会停止您的机器,只会让内核休眠(在 C1 中空闲)直到下一个中断。
You can try adding cli
instruction before hlt
, so only an NMI can wake that CPU up and make the function return.您可以尝试在
hlt
之前添加cli
指令,这样只有 NMI 才能唤醒该 CPU 并使函数返回。
static int __init test_hello_init(void) {
asm("cli");
asm("hlt");
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.