简体   繁体   English

无法删除可加载的内核模块

[英]Not able to remove a loadable kernel module

I'm writing a loadable kernel module and trying to test it.我正在编写一个可加载的内核模块并尝试对其进行测试。 After inserting it I was trying to remove it using rmmod xxx command, but I get an error saying module xxx is in use and the module gets stuck and I can't remove it.插入后,我试图使用rmmod xxx命令将其删除,但我收到错误消息,提示module xxx is in use ,并且模块卡住了,我无法将其删除。 Any idea how to remove the module without rebooting the entire machine ?知道如何在不重新启动整个机器的情况下删除模块吗? (linux Kernel v. 3.5.0) (Linux 内核 v. 3.5.0)

Note: rmmod -f prints Error: device or resource busy注意: rmmod -f打印Error: device or resource busy

This only happens to me when there is a bug in my driver which is causing the code in the module to panic or crash in some way.这只发生在我的驱动程序中存在错误导致模块中的代码以某种方式恐慌或崩溃时。 In my experience once this happens reboot is the only possible course.根据我的经验,一旦发生这种情况,重新启动是唯一可能的过程。

As I said, the kernel usually panics so you should check out dmesg after inserting it or running you application to exercise it.正如我所说,内核通常会发生恐慌,因此您应该在插入或运行应用程序后检查 dmesg 以对其进行练习。 I'm not certain but it might be possible that if the driver doesn't release a mutex this behavior will happen as well.我不确定,但如果驱动程序不释放互斥锁,这种行为也可能发生。

Check your module_exit function is proper.检查您的 module_exit 功能是否正确。 You may need to compile your kernel to have "remove the module without rebooting the entire machine" with MODULE_FORCE_UNLOAD=yes.您可能需要编译内核以使用 MODULE_FORCE_UNLOAD=yes 来“删除模块而不重新启动整个机器”。

I fix the same error by using the same GCC version as which have compiled the running kernel to compile my module, both 8.3.1;我通过使用与编译正在运行的内核来编译我的模块相同的 GCC 版本来修复相同的错误,两者都是 8.3.1; Please check on yours.请检查你的。

    [root@centos fishing]# dmesg | grep gcc
    [    0.000000] Linux version 4.18.0-80.7.2.el7.aarch64 (mockbuild@aarch64-01.bsys.centos.org) (gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)) #1 SMP Thu Sep 12 16:13:20 UTC 2019
    [root@centos fishing]# gcc -v
    gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)
    [root@centos fishing]#

Otherwise, I had errors:否则,我有错误:

    [root@centos fishing]# rmmod fishing
    rmmod: ERROR: could not remove 'fishing': Device or resource busy
    rmmod: ERROR: could not remove module fishing: Device or resource busy
    [root@centos fishing]#

the kernel module, fishing code is from http://books.gigatux.nl/mirror/kerneldevelopment/0672327201/ch16lev2sec1.html内核模块,钓鱼代码来自http://books.gigatux.nl/mirror/kerneldevelopment/0672327201/ch16lev2sec1.html

一种可能性是您忘记提供 module_exit,因此您的模块不知道如何退出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM