# Kernel Panic



## viswesh (Sep 23, 2011)

Hi,

I got a kernel panic, trying to do some operations on my pcie device and these are the messages.
What I am doing is from user space, through ioctls ,execute certain commands on my device.


```
Fatal trap 12: page fault while in user mode
cpuid = 0; apic id = 00
fault virtual address   = 0x28197664
fault code              = user write, page not present
instruction pointer     = 0x33:0x281012e8
stack pointer           = 0x3b:0xbfbfecd0
frame pointer           = 0x3b:0xbfbfecd8
code segment            = base 0x0, limit 0xfffff, type 0x1b
                        = DPL 3, pres 1, def32 1, gran 1
processor eflags        = interrupt enabled, resume, IOPL = 0
current process         = 1358 (opsched)
trap number             = 12
panic: page fault
cpuid = 0
```
How do I continue debugging.

The address which is present in IP, doesn't look like a kernel space address.
Doesn't look like a user space address also.

Any clues?


----------



## vwe@ (Sep 23, 2011)

viswesh,

First, it might be a good idea to communicate the OS version you're working on.

The next thing to definitely look at is the kernel stack backtrace. While being dropped to the debugger, please get the output of the 'bt' command. If a core dump has been written, you may (after a reboot) later do the same when opening the core dump with the kgdb debugger and get the backtrace. While working with the core dump in kgdb, you also have the chance to check for conditions and other stuff.

I find the kgdb use much better than doing it online using ddb(4) but YMMV.

Please be aware, nobody can help you without knowing your OS release level and the backtrace.


----------



## viswesh (Sep 25, 2011)

I am sorry for missing out the kernel version. I am using 8.2-RELEASE FreeBSD 8.2-RELEASE. This is the kgdb stack trace. Looks like stack has corrupted.

Unread portion of the kernel message buffer:


```
instruction pointer     = 0x33:0x280ff2e8
stack pointer           = 0x3b:0xbfbfec30
frame pointer           = 0x3b:0xbfbfec38
code segment            = base 0x0, limit 0xfffff, type 0x1b
                        = DPL 3, pres 1, def32 1, gran 1
processor eflags        = interrupt enabled, resume, IOPL = 0
current process         = 1096 (a.out)
trap number             = 12
panic: page fault
cpuid = 2
KDB: stack backtrace:
#0 0xc08e0d07 at kdb_backtrace+0x47
#1 0xc08b1dc7 at panic+0x117
#2 0xc0be4b43 at trap_fatal+0x323
#3 0xc0be5020 at trap+0x180
#4 0xc0bcbebc at calltrap+0x6
Uptime: 4m19s
Physical memory: 3443 MB
Dumping 107 MB: 92 76 60 44 28 12

Reading symbols from ./cdev.ko...done.
Loaded symbols for ./cdev.ko
#0  doadump () at pcpu.h:231
231             __asm("movl %%fs:0,%0" : "=r" (td));
(kgdb) bt
#0  doadump () at pcpu.h:231
#1  0xc08b1b63 in boot (howto=260) at /usr/src/sys/kern/kern_shutdown.c:419
#2  0xc08b1e00 in panic (fmt=Variable "fmt" is not available.
) at /usr/src/sys/kern/kern_shutdown.c:592
#3  0xc0be4b43 in trap_fatal (frame=0xe95cbd28, eva=672749156)
    at /usr/src/sys/i386/i386/trap.c:946
#4  0xc0be5020 in trap (frame=0xe95cbd28) at /usr/src/sys/i386/i386/trap.c:326
#5  0xc0bcbebc in calltrap () at /usr/src/sys/i386/i386/exception.s:166
#6  0x280ff2e8 in ?? ()
Previous frame inner to this frame (corrupt stack?)
(kgdb)
```


----------

