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

问题描述 投票:6回答:3

我正在编写一个可加载的内核模块并尝试对其进行测试。插入后,我试图使用rmmod xxx命令将其删除,但出现错误消息module xxx is in use,模块卡住,无法删除。知道如何在不重新启动整个计算机的情况下删除模块吗? (Linux Kernel v.3.0.5)

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

c kernel-module insmod
3个回答
10
投票

这仅在驱动程序中存在错误导致模块中的代码以某种方式崩溃或崩溃时发生。以我的经验,一旦发生这种情况,重启是唯一可能的方法。

正如我说的那样,内核通常会惊慌,因此您应在插入dmesg或运行应用程序以执行dmesg之后将其检出。我不确定,但是如果驱动程序不释放互斥锁,则也可能会发生这种情况。


0
投票

检查您的module_exit函数是否正确。您可能需要使用MODULE_FORCE_UNLOAD = yes来编译内核以“删除模块而不重新引导整个计算机”。


0
投票

我通过使用与编译运行中的内核来编译我的模块的GCC版本相同的GCC版本来修复相同的错误,两者均是8.3.1;请检查您的。

    [root@centos fishing]# dmesg | grep gcc
    [    0.000000] Linux version 4.18.0-80.7.2.el7.aarch64 ([email protected]) (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]#

否则,我有错误:

    [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]#

内核模块,钓鱼代码来自http://books.gigatux.nl/mirror/kerneldevelopment/0672327201/ch16lev2sec1.html

© www.soinside.com 2019 - 2024. All rights reserved.