gpt4 book ai didi

c - 如何理解此 dmesg 错误消息?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:27:22 29 4
gpt4 key购买 nike

我编写了这个简单的模块来处理设备并调用它的一些电源管理方法,例如 .suspend.resume。在初始化时,模块简单查找特定设备并尝试调用其方法。

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/pci.h>

static int __init mfps_driver_init(void){

struct pci_dev *dev = NULL;
struct pci_driver *driver = NULL;
struct device *device = NULL;

dev = pci_get_device(0x8086, 0x15a2, NULL);

if((dev == NULL) || (dev == 0)){

printk(KERN_INFO "LEONZO: NOTHING FOUND SIZE %ld\n", sizeof(dev));

} else {

driver = dev->driver;

printk(KERN_INFO "LEONZO: I FOUND THE DEVICE OF THE SIZE %ld\n", sizeof(dev));
printk(KERN_INFO "LEONZO: HERE IS ITS DRIVER NAME %s\n", driver->name);
printk(KERN_INFO "LEONZO: CALLING IT SUSPEND METHOD\n");

*device = dev->dev;

device_lock(device);

device_unlock(device);
}

return 0;

}

static void __exit mfps_driver_exit(void){

}


module_init(mfps_driver_init);
module_exit(mfps_driver_exit);

代码编译成功。但是当我加载模块时我得到了一个内核错误:

sudo insmod MyFirstPowerState.ko

dmesg 显示以下输出

[   59.545180] MyFirstPowerState: module license 'unspecified' taints   kernel. 
[ 59.545183] Disabling lock debugging due to kernel taint
[ 59.546010] LEONZO: I FOUND THE DEVICE OF THE SIZE 8
[ 59.546012] LEONZO: HERE IS ITS DRIVER NAME e1000e
[ 59.546013] LEONZO: CALLING IT SUSPEND METHOD
[ 59.546021] BUG: unable to handle kernel NULL pointer dereference at (null)
[ 59.546051] IP: [<ffffffffc011907e>] mfps_driver_init+0x7e/0x1000 [MyFirstPowerState]
[ 59.546077] PGD 0
[ 59.546085] Oops: 0002 [#1] SMP
[ 59.546097] Modules linked in: MyFirstPowerState(POE+) xt_CHECKSUM arc4 iwlmvm mac80211 snd_hda_codec_hdmi snd_hda_codec_realtek iwlwifi snd_hda_codec_generic rtsx_pci_ms memstick cfg80211 nf_conntrack_netbios_ns nf_conntrack_broadcast ipt_MASQUERADE nf_nat_masquerade_ipv4 xt_tcpudp ip6t_REJECT nf_reject_ipv6 ipt_REJECT nf_reject_ipv4 xt_conntrack ebtable_nat ebtable_broute bridge stp llc ebtable_filter ebtables ip6table_nat nf_conntrack_ipv6 nf_defrag_ipv6 nf_nat_ipv6 ip6table_mangle ip6table_security ip6table_raw ip6table_filter ip6_tables iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack iptable_mangle iptable_security iptable_raw iptable_filter ip_tables x_tables dm_crypt hp_wmi sparse_keymap intel_rapl iosf_mbi x86_pkg_temp_thermal intel_powerclamp coretemp kvm_intel kvm crct10dif_pclmul dm_multipath crc32_pclmul scsi_dh aesni_intel aes_x86_64 lrw gf128mul glue_helper ablk_helper cryptd joydev serio_raw lpc_ich uvcvideo snd_seq_midi snd_seq_midi_event snd_rawmidi snd_hda_intel snd_hda_controller snd_hda_codec videobuf2_vmalloc snd_hwdep shpchp snd_pcm videobuf2_memops videobuf2_core v4l2_common snd_seq e1000e(OE) i915_bpo ptp mei_me pps_core mei videodev media snd_seq_device intel_ips snd_timer drm_kms_helper drm btusb snd i2c_algo_bit soundcore 8250_fintek hp_accel lis3lv02d input_polldev tpm_infineon hp_wireless mac_hid parport_pc ppdev lp parport rfcomm bnep bluetooth binfmt_misc btrfs xor raid6_pq dm_mirror dm_region_hash dm_log uas usb_storage hid_generic usbhid hid rtsx_pci_sdmmc ahci psmouse libahci rtsx_pci wmi video
[ 59.546577] CPU: 1 PID: 4180 Comm: insmod Tainted: P OE 3.19.0-51-generic #58~14.04.1-Ubuntu
[ 59.546613] Hardware name: Hewlett-Packard HP EliteBook 840 G2/2216, BIOS M71 Ver. 01.05 03/26/2015
[ 59.546648] task: ffff880241a7b110 ti: ffff880242f68000 task.ti: ffff880242f68000
[ 59.546678] RIP: 0010:[<ffffffffc011907e>] [<ffffffffc011907e>] mfps_driver_init+0x7e/0x1000 [MyFirstPowerState]
[ 59.546720] RSP: 0018:ffff880242f6bd18 EFLAGS: 00010246
[ 59.546741] RAX: 0000000000000000 RBX: ffff880245b4d000 RCX: 00000000000000ae
[ 59.546772] RDX: 0000000000000000 RSI: ffff880245b4d098 RDI: 0000000000000000
[ 59.546807] RBP: ffff880242f6bd28 R08: 000000000000000a R09: 0000000000000000
[ 59.546839] R10: 0000000000000d53 R11: ffff880242f6b9de R12: ffffffffc06a8000
[ 59.546868] R13: 0000000000000000 R14: ffffffffc0119000 R15: ffff880242f6bef8
[ 59.546900] FS: 00007f8787aa6740(0000) GS:ffff88024f440000(0000) knlGS:0000000000000000
[ 59.546921] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 59.546936] CR2: 0000000000000000 CR3: 0000000244393000 CR4: 00000000003407e0
[ 59.546955] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 59.546978] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 59.547006] Stack:
[ 59.547014] ffffffff81c1d060 ffff880204cd3280 ffff880242f6bda8 ffffffff81002144
[ 59.547046] 0000000000000001 0000000000000002 ffff8801f8ddc4c0 0000000000000001
[ 59.547079] ffff880242f6bd88 ffffffff811cef19 ffffffff810f7aac 0000000000000018
[ 59.547114] Call Trace:
[ 59.547131] [<ffffffff81002144>] do_one_initcall+0xd4/0x210
[ 59.547162] [<ffffffff811cef19>] ? kmem_cache_alloc_trace+0x199/0x220
[ 59.547194] [<ffffffff810f7aac>] ? load_module+0x164c/0x1cc0
[ 59.547222] [<ffffffff810f7ae5>] load_module+0x1685/0x1cc0
[ 59.547247] [<ffffffff810f3380>] ? store_uevent+0x40/0x40
[ 59.547274] [<ffffffff810f8296>] SyS_finit_module+0x86/0xb0
[ 59.547298] [<ffffffff817b788d>] system_call_fastpath+0x16/0x1b
[ 59.547314] Code: c7 80 c0 4b c0 31 c0 e8 19 14 69 c1 48 c7 c7 a8 c0 4b c0 31 c0 e8 0b 14 69 c1 31 c0 48 8d b3 98 00 00 00 b9 ae 00 00 00 48 89 c7 <f3> a5 bf 60 00 00 00 e8 26 c7 69 c1 bf 60 00 00 00 e8 ac c5 69
[ 59.547393] RIP [<ffffffffc011907e>] mfps_driver_init+0x7e/0x1000 [MyFirstPowerState]
[ 59.547416] RSP <ffff880242f6bd18>
[ 59.547425] CR2: 0000000000000000
[ 59.554577] ---[ end trace 42e3b1c73677cdfa ]---

我还注意到,因此无法删除该模块:

sudo rmmod MyFirstPowerState.ko 
rmmod: ERROR: Module MyFirstPowerState is in use

知道这段代码的含义以及如何更正错误吗?

最佳答案

我将尝试解释下面的 dmesg 的大量文本。请注意,左侧括号中的值是我忘记了它们究竟与什么相关的时间,但对您来说它们并不重要。

[ 59.545180] MyFirstPowerState: module license 'unspecified' taints kernel. [ 59.545183] Disabling lock debugging due to kernel taint

这是因为您没有声明模块许可。通常你会看到人们在他们的代码中将类似的东西放在与 module_init 相同的部分。

MODULE_LICENSE("GPL");

[ 59.546010] LEONZO: I FOUND THE DEVICE OF THE SIZE 8 [ 59.546012] LEONZO: HERE IS ITS DRIVER NAME e1000e [ 59.546013] LEONZO: CALLING IT SUSPEND METHOD

这些是您的 printk 消息,这里没什么特别的。

[ 59.546021] BUG: unable to handle kernel NULL pointer dereference at (null)

这里是导致崩溃的实际原因。内核试图取消引用 NULL 指针,这会导致段错误。有关其确切含义的更多详细信息,请参阅 here .正如伊恩在之前的评论中指出的那样,看起来你崩溃的原因是你把 *device=dev->dev 而不是 device=dev->dev. 在您尝试将设备指向的值分配给 dev->dev 的代码,但是由于 device=NULL 当前您尝试取消引用 NULL 导致崩溃。

[ 59.546051] IP: [] mfps_driver_init+0x7e/0x1000 [MyFirstPowerState] [ 59.546648] task: ffff880241a7b110 ti: ffff880242f68000 task.ti: ffff880242f68000

上述错误中包含的大量错误目前对您没有太大值(value),对于部署了某些东西的人和某些特定用户有问题的人来说更多。它列出了安装的硬件、导致崩溃的模块以及也在调用您的情况下众所周知的所有事物的模块。

[ 59.546678] RIP: 0010:[] [] mfps_driver_init+0x7e/0x1000 [MyFirstPowerState][ 59.547079] ffff880242f6bd88 ffffffff811cef19 ffffffff810f7aac 0000000000000018

本节中的所有内容都是装配信息,如果您没有装配经验,这对您来说毫无意义,但我建议您了解一些基础知识,这在这些情况下确实有帮助。上半部分是寄存器及其当前值,下半部分是当前堆栈帧。

> [   59.547114] Call Trace:
[ 59.547131] [<ffffffff81002144>] do_one_initcall+0xd4/0x210
[ 59.547162] [<ffffffff811cef19>] ? kmem_cache_alloc_trace+0x199/0x220
[ 59.547194] [<ffffffff810f7aac>] ? load_module+0x164c/0x1cc0

调用跟踪中的所有内容都非常有用,尤其是当模块变得很长并且难以通过中断等方式进行调试时。基本上,它列出了系统导致崩溃的每一个函数调用(或其他)。在您的情况下,因为您从加载模块直接进入崩溃,跟踪实际上只有您的 load_module 以及一些包装器和一些深层系统调用。但是,如果说您的加载模块调用了另一个函数并导致崩溃,您可以在此处看到此调用路径。

最后一点似乎是更多的寄存器。

希望这解释了当您导致内核问题时从 dmesg 获得的文本墙(不确定这是否是 panic ,请有人纠正我)。如果有任何内容仍然含糊不清,我会尝试解释,尽管我绝不是这方面的专家。

关于c - 如何理解此 dmesg 错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36153619/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com