···11+Table of contents22+=================33+44+Last updated: 20 December 200555+66+Contents77+========88+99+- Introduction1010+- Devices not appearing1111+- Finding patch that caused a bug1212+-- Finding using git-bisect1313+-- Finding it the old way1414+- Fixing the bug1515+1616+Introduction1717+============1818+1919+Always try the latest kernel from kernel.org and build from source. If you are2020+not confident in doing that please report the bug to your distribution vendor2121+instead of to a kernel developer.2222+2323+Finding bugs is not always easy. Have a go though. If you can't find it don't2424+give up. Report as much as you have found to the relevant maintainer. See2525+MAINTAINERS for who that is for the subsystem you have worked on.2626+2727+Before you submit a bug report read REPORTING-BUGS.2828+2929+Devices not appearing3030+=====================3131+3232+Often this is caused by udev. Check that first before blaming it on the3333+kernel.3434+3535+Finding patch that caused a bug3636+===============================3737+3838+3939+4040+Finding using git-bisect4141+------------------------4242+4343+Using the provided tools with git makes finding bugs easy provided the bug is4444+reproducible.4545+4646+Steps to do it:4747+- start using git for the kernel source4848+- read the man page for git-bisect4949+- have fun5050+5151+Finding it the old way5252+----------------------5353+154[Sat Mar 2 10:32:33 PST 1996 KERNEL_BUG-HOWTO lm@sgi.com (Larry McVoy)]255356This is how to track down a bug if you know nothing about kernel hacking. ···14390because Linux snapshots will let you do this - something that you can't14491do with vendor supplied releases.145929393+Fixing the bug9494+==============9595+9696+Nobody is going to tell you how to fix bugs. Seriously. You need to work it9797+out. But below are some hints on how to use the tools.9898+9999+To debug a kernel, use objdump and look for the hex offset from the crash100100+output to find the valid line of code/assembler. Without debug symbols, you101101+will see the assembler code for the routine shown, but if your kernel has102102+debug symbols the C code will also be available. (Debug symbols can be enabled103103+in the kernel hacking menu of the menu configuration.) For example:104104+105105+ objdump -r -S -l --disassemble net/dccp/ipv4.o106106+107107+NB.: you need to be at the top level of the kernel tree for this to pick up108108+your C files.109109+110110+If you don't have access to the code you can also debug on some crash dumps111111+e.g. crash dump output as shown by Dave Miller.112112+113113+> EIP is at ip_queue_xmit+0x14/0x4c0114114+> ...115115+> Code: 44 24 04 e8 6f 05 00 00 e9 e8 fe ff ff 8d 76 00 8d bc 27 00 00116116+> 00 00 55 57 56 53 81 ec bc 00 00 00 8b ac 24 d0 00 00 00 8b 5d 08117117+> <8b> 83 3c 01 00 00 89 44 24 14 8b 45 28 85 c0 89 44 24 18 0f 85118118+>119119+> Put the bytes into a "foo.s" file like this:120120+>121121+> .text122122+> .globl foo123123+> foo:124124+> .byte .... /* bytes from Code: part of OOPS dump */125125+>126126+> Compile it with "gcc -c -o foo.o foo.s" then look at the output of127127+> "objdump --disassemble foo.o".128128+>129129+> Output:130130+>131131+> ip_queue_xmit:132132+> push %ebp133133+> push %edi134134+> push %esi135135+> push %ebx136136+> sub $0xbc, %esp137137+> mov 0xd0(%esp), %ebp ! %ebp = arg0 (skb)138138+> mov 0x8(%ebp), %ebx ! %ebx = skb->sk139139+> mov 0x13c(%ebx), %eax ! %eax = inet_sk(sk)->opt140140+141141+Another very useful option of the Kernel Hacking section in menuconfig is142142+Debug memory allocations. This will help you see whether data has been143143+initialised and not set before use etc. To see the values that get assigned144144+with this look at mm/slab.c and search for POISON_INUSE. When using this an145145+Oops will often show the poisoned data instead of zero which is the default.146146+147147+Once you have worked out a fix please submit it upstream. After all open148148+source is about sharing what you do and don't you want to be recognised for149149+your genius?150150+151151+Please do read Documentation/SubmittingPatches though to help your code get152152+accepted.