6

I'm developing a network driver for Raspbian (kernel version 4.9.24) on a Raspberry Pi and each time I load my module it crashes.

Using the logs in /var/log/messages I've been able to tell which method fails, but still I'm not able to know why it fails.

May  7 17:15:29 raspberrypi kernel: [  228.384164] CPU: 0 PID: 1163 Comm: insmod Tainted: P           O    4.9.24+ #993
May  7 17:15:29 raspberrypi kernel: [  228.388503] Hardware name: BCM2835
May  7 17:15:29 raspberrypi kernel: [  228.390701] task: d888ed00 task.stack: da696000
May  7 17:15:29 raspberrypi kernel: [  228.392901] PC is at register_netdevice+0x20/0x4cc
May  7 17:15:29 raspberrypi kernel: [  228.395064] LR is at register_netdev+0x24/0x34
May  7 17:15:29 raspberrypi kernel: [  228.397106] pc : [<c04eea38>]    lr : [<c04eef08>]    psr: 60000013
May  7 17:15:29 raspberrypi kernel: [  228.397106] sp : da697d48  ip : da697d90  fp : da697d8c
May  7 17:15:29 raspberrypi kernel: [  228.401178] r10: 00000000  r9 : 00000001  r8 : da69bac0
May  7 17:15:29 raspberrypi kernel: [  228.403177] r7 : bf38b4c0  r6 : da6b22c0  r5 : 00000000  r4 : 00000000
May  7 17:15:29 raspberrypi kernel: [  228.405203] r3 : c090bd50  r2 : 00000000  r1 : c08b262c  r0 : 00000000
May  7 17:15:29 raspberrypi kernel: [  228.407187] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
May  7 17:15:29 raspberrypi kernel: [  228.409194] Control: 00c5387d  Table: 188a8008  DAC: 00000055
May  7 17:15:29 raspberrypi kernel: [  228.527223] [<c04eea38>] (register_netdevice) from [<c04eef08>] (register_netdev+0x24/0x34)
May  7 17:15:29 raspberrypi kernel: [  228.532724] [<c04eef08>] (register_netdev) from [<bf38b15c>] (init_module+0x64/0xa4 [lum])
May  7 17:15:29 raspberrypi kernel: [  228.538298] [<bf38b15c>] (init_module [lum]) from [<c0009a1c>] (do_one_initcall+0x4c/0x188)
May  7 17:15:29 raspberrypi kernel: [  228.543850] [<c0009a1c>] (do_one_initcall) from [<c00e3ffc>] (do_init_module+0x6c/0x1dc)
May  7 17:15:29 raspberrypi kernel: [  228.549346] [<c00e3ffc>] (do_init_module) from [<c00837d0>] (load_module+0x1a64/0x1fb8)
May  7 17:15:29 raspberrypi kernel: [  228.554907] [<c00837d0>] (load_module) from [<c0083efc>] (SyS_finit_module+0x9c/0xac)
May  7 17:15:29 raspberrypi kernel: [  228.560463] [<c0083efc>] (SyS_finit_module) from [<c000fe40>] (ret_fast_syscall+0x0/0x1c)
May  7 17:15:29 raspberrypi kernel: [  228.568861] ---[ end trace 279ccc9024b7e026 ]---

So register_netdevice method is failing, but I have no idea how to know where. Also, when I call insmod a Stack is printed in the terminal:

$ sudo insmod lum.ko
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.375707] Internal error: Oops: 5 [#1] ARM
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.411149] Process insmod (pid: 1163, stack limit = 0xda696188)
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.413044] Stack: (0xda697d48 to 0xda698000)
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.414943] 7d40:                   bf38b4c0 da69bac0 00000001 c05d16bc da697d7c da697d68
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.418939] 7d60: c05d16bc c05d023c 00000000 bf38b0f8 da6b22c0 bf38b4c0 da69bac0 00000001
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.423013] 7d80: da697da4 da697d90 c04eef08 c04eea24 bf38b6a0 bf38b4c0 da697dbc da697da8
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.427108] 7da0: bf38b15c c04eeef0 00000001 00000001 da697e3c da697dc0 c0009a1c bf38b104
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.431275] 7dc0: da69bac8 024000c0 c00e3fc0 dac01e60 0000000c 2596455c da697dfc da697de8
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.435731] 7de0: c05d0220 c05cfa70 da696000 024000c0 da697e0c da697e00 c05d0278 c05d020c
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.440472] 7e00: da697e3c da697e10 c01334a0 c05d023c 00000001 bf38b4c0 da69bac8 da6b22c0
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.445382] 7e20: bf38b4c0 da69bac0 00000001 2596455c da697e64 da697e40 c00e3ffc c00099dc
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.450472] 7e40: 00000001 bf38b4c0 da697e64 da697f3c da69bac8 00000001 da697f14 da697e68
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.455746] 7e60: c00837d0 c00e3f9c bf38b4cc 00007fff bf38b4c0 c0080f4c da697ea4 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.461149] 7e80: bf38b4cc bf38b4cc bf38b6a4 bf38b684 bf38b5b4 bf38b508 da697ee4 da697ea8
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.466589] 7ea0: c014b170 c014aaf4 dd4b2000 00000000 00000000 00000000 00000000 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.472117] 7ec0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.477650] 7ee0: 00000000 00000000 7fffffff 00000000 00000003 7f5d73b0 0000017b 7fffffff
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.483112] 7f00: 00000000 00000000 da697fa4 da697f18 c0083efc c0081d78 7fffffff 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.488641] 7f20: 00000003 c0106b70 da697f74 dd4b2000 0000158c 00000000 00000002 dd4b2000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.494167] 7f40: 0000158c dd4b31cc dd4b29ac dd4b2e70 000006a4 000008a4 00000000 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.499628] 7f60: 00000000 0000054c 00000016 00000017 0000000f 0000000d 0000000c 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.505155] 7f80: bee37758 a5d60900 7f5e9000 bee37758 c000ffc4 da696000 00000000 da697fa8
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.510672] 7fa0: c000fe40 c0083e6c a5d60900 7f5e9000 00000003 7f5d73b0 00000000 00000002
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.516137] 7fc0: a5d60900 7f5e9000 bee37758 0000017b 7f5d73b0 00000002 7f5d320c 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.521670] 7fe0: bee37590 bee37580 7f5cc0ac b6e4cc40 60000010 00000003 00000000 00000000
Message from syslogd@raspberrypi at May  7 17:15:29 ... kernel:[  228.565948] Code: e52de004 e8bd4000 e59f3460 e1a05000 (e59062e0)

I'm just wondering how could I debug this properly, since I've never worked with Kernel Modules, to get a proper understanding of what's happening.

EDIT:

I think it might be useful to resolve the IP symbol at /var/log/messages file, but I don't really know how to do it.

  • If it's a kernel module, then I assume the code is GPL licensed, so why don't you share a link to the code? – einonm May 7 '17 at 19:23
  • @einonm Well, the question was more about, how to debug code at kernel space, than fixing this particular issue. – deuseux12 May 7 '17 at 19:27
6

The simplest thing is to add a few calls to printk to the code and recompile the module. For more debugging options, see chapter 4, Debugging Techniques in Linux Device Drivers, Third Edition. The book is a bit old already, but still relevant.

  • The problem is that the function which fails is in <linux/netdev.h>, so I can't really add some printk() there. I've been following the book, but as you said, it's quite old and must of the stuff is obsolete. – deuseux12 May 7 '17 at 17:59
  • The register_netdevice function is defined in the C file net/core/dev.c. Yes, the book is old, but there are several repositories on Github that are trying to keep the sample source code from the book up to date. For example: github.com/martinezjavier/ldd3. – Johan Myréen May 7 '17 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.