简体   繁体   English

`rmmod`或`modprobe -r`时的“分段错误”

[英]“Segmentation fault” when `rmmod` or `modprobe -r`

Trying the simplest kernel module from LDD3 without any modification on custom built kernel v4.1.0-rc6 for Beagle Bone board with BusyBox v1.23.0. 尝试使用LDD3中最简单的内核模块,而无需对带有BusyBox v1.23.0的Beagle Bone板的自定义内核v4.1.0- rc6进行任何修改。 The code for the module is as follows: 该模块的代码如下:

#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
    printk(KERN_ALERT "Hello, world\n");
    return 0;
}
static void hello_exit(void)
{
    printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);

The Makefile is: Makefile是:

ARCH := arm
CROSS_COMPILE := arm-cortex_a8-linux-gnueabi-
obj-m := hello.o
all:
        make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C /path/to/linux/source/tree M=$(PWD) modules
clean:
        make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C /path/to/linux/source/tree M=$(PWD) clean

The module is compiling and installing on the rootfs just fine. 该模块正在rootfs上编译和安装就好了。 also it is loading: 也正在加载:

$ insmod hello.ko 
[   30.692404] Hello, world

But when trying to remove it, I am getting: 但是当我试图删除它时,我得到:

$ rmmod hello.ko 
Segmentation fault
$modprobe -r hello.ko 
Segmentation fault
$ lsmod
hello 813 0 - Live 0xbf000000 (O)

The kernel is compiled with module unloading (both regular and forced) support enabled. 编译内核时启用了模块卸载(常规和强制)支持。

What can be the possible cause of this issue? 这个问题的可能原因是什么? What is the way to approach the investigation of it? 接受调查的方法是什么?

Update: 更新:

As suggested in the comments I have tried including linux/kernel.h , defining the MODULE , LINUX and __KERNEL__ symbols. 正如我在试验中所建议的那样,包括linux/kernel.h ,定义了MODULELINUX__KERNEL__符号。 Added the __init and __exit prefixes to the functions. 在函数中添加了__init__exit前缀。 Removed the static modifiers. 删除了static修饰符。 Removed the printk lines. 删除了printk行。 The result the same. 结果一样。 dmesg shows only the initial greeting. dmesg只显示初始问候语。 Loading and unloading of the kernel's modules such a gpio_keys or crypto/ccm is working, surprisingly. 令人惊讶的 ,加载和卸载内核模块(例如gpio_keyscrypto/ccm 正在起作用。 So the only thing remaining to suspect is the way the module is compiled.. 所以唯一值得怀疑的是编译模块的方式。

Update 2 更新2
Updating the kernel to the freshest snapshot didn't help. 将内核更新到最新鲜的快照没有帮助。 Compiled the module with different optimization settings didn't help. 用不同的优化设置编译模块没有帮助。 Next step, I guess, I am going to modify the BusyBox's rmmod to have some indication of the problem location.. 下一步,我想,我将修改BusyBox的rmmod以获得问题位置的一些指示。

Have a look at these tutorials: 看看这些教程:

http://www.tldp.org/HOWTO/Module-HOWTO/x839.html http://www.tldp.org/LDP/lkmpg/2.4/html/x281.htm http://www.tldp.org/HOWTO/Module-HOWTO/x839.html http://www.tldp.org/LDP/lkmpg/2.4/html/x281.htm

Try adding: 尝试添加:

#define MODULE
#define LINUX
#define __KERNEL__

#include <linux/kernel.h>      /* Needed for KERN_ALERT */

I have managed to work around this problem. 我设法解决了这个问题。 Using strace I've found out that the segfault is occurring somewhere when read ing the BusyBox specific modules.dep.bb file. 使用strace我发现当read BusyBox特定的modules.dep.bb文件时会发生段错误。 This file is used by BusyBox when it is compiled with the "Simplified modutils" option ( CONFIG_MODPROBE_SMALL ). BusyBox使用“Simplified modutils”选项( CONFIG_MODPROBE_SMALL )进行编译时,将使用此文件。 By disabling the option, selecting the utils to be installed and rebuilding BusybBox I've got the module unloading work. 通过禁用该选项,选择要安装的工具并重建BusybBox我已经让模块卸载工作。 I believe the problem root is near the fact the test module is compiled and stored outside the /lib/..../modules directory, so busybox with the simplified modutils is just getting confused. 我认为问题根就是测试模块被编译并存储在/lib/..../modules目录之外的/lib/..../modules ,因此使用简化的modutils busybox变得混乱。

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

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