【Linux 菜鸡中心】驱动模块卸载,rmmod 报错 “Segmentation fault (core dumped)”
【引子】开此专栏主要记录,Linux开发过程中遇到的各种菜鸡问题,常执鞭大笑以策之。
【菜鸡简述】:写一个linux驱动模块时,insmod正常,rmmod时卸载总是失败,报错:
Segmentation fault (core dumped)
【菜鸡原因】:“懒得写,所以拷贝了一下”
写过驱动模块程序的,应该熟悉以下内容:
static int __init module_init(void)
{...
}
static void __init module_exit(void)
{...
}
...
...
...
module_init(module_init);
module_exit(module_exit);
是不是一眼就看出来错误在哪了,TAT,题主还各种找了半天。
【菜鸡纠正】:
static void __init module_exit(void)
修改为:
static void __exit module_exit(void)
问题解决。
注:报错时,使用 dmesg 命令查看有如下打印:
[ 202.575701] Unable to handle kernel paging request at virtual address ffffff8000f7b100
[ 202.575884] Mem abort info:
[ 202.575972] ESR = 0x86000007
[ 202.576054] Exception class = IABT (current EL), IL = 32 bits
[ 202.576164] SET = 0, FnV = 0
[ 202.576226] EA = 0, S1PTW = 0
[ 202.576292] swapper pgtable: 4k pages, 39-bit VAs, pgd = ffffff800a1c9000
[ 202.576423] [ffffff8000f7b100] *pgd=000000027fffe003, *pud=000000027fffe003, *pmd=000000026049d003, *pte=0000000000000000
[ 202.576675] Internal error: Oops: 86000007 [#1] PREEMPT SMP
[ 202.576778] Modules linked in: test(O-) fuse bnep zram overlay btusb btrtl btbcm btintel ath10k_pci ath10k_core ath mac80211 spidev cfg80211 nvgpu bluedroid_pm ip_tables x_tables
[ 202.577223] CPU: 0 PID: 8637 Comm: rmmod Tainted: G O 4.9.140-tegra #1
[ 202.577415] Hardware name: NVIDIA Jetson Xavier NX Developer Kit (DT)
[ 202.577940] task: ffffffc18d161c00 task.stack: ffffffc15677c000
[ 202.578367] PC is at 0xffffff8000f7b100
[ 202.578681] LR is at SyS_delete_module+0x15c/0x208
[ 202.580466] pc : [<ffffff8000f7b100>] lr : [<ffffff80081554dc>] pstate: 20400145
[ 202.587824] sp : ffffffc15677fe50
[ 202.591232] x29: ffffffc15677fe50 x28: ffffffc18d161c00
[ 202.596492] x27: ffffff8008f72000 x26: 000000000000006a
[ 202.602338] x25: 0000000000000123 x24: 0000000000000015
[ 202.607763] x23: 0000000000000000 x22: ffffff800a165000
[ 202.612806] x21: ffffffffffffffff x20: ffffff8000f79300
[ 202.618348] x19: ffffff8009e77000 x18: 0000007f90480a70
[ 202.623948] x17: 0000007f903fdc90 x16: ffffff8008155380
[ 202.629477] x15: 0000000000000000 x14: 0000000000000000
[ 202.635409] x13: ffffffff00000000 x12: ffffffffffffffff
[ 202.641010] x11: 0000000000000020 x10: 7f7f7f7f7f7f7f7f
[ 202.646363] x9 : fefefeff73726473 x8 : 0000000000000000
[ 202.652383] x7 : ffffffffffffffff x6 : 00000000ffffffff
[ 202.657896] x5 : 0000000000000000 x4 : 0000000000000000
[ 202.663234] x3 : ffffff8000f79608 x2 : 0000000000000020
[ 202.668572] x1 : ffffff8009e77750 x0 : ffffff8000f7b100 [ 202.675321] Process rmmod (pid: 8637, stack limit = 0xffffffc15677c000)
[ 202.681440] Call trace:
[ 202.684063] [<ffffff8000f7b100>] 0xffffff8000f7b100
[ 202.688359] [<ffffff8008083900>] el0_svc_naked+0x34/0x38
[ 202.693435] ---[ end trace e0fd7e6d506f82f2 ]---