How to use lockdep feature in linux kernel for deadlock detection

[*]

To enable lockdep feature, edit .config file through menuconfig:

make menuconfig

And enable following in Hacking Options:

 1. [*] Detect Hard and Soft Lockups
 2. [*] Detect Hung Tasks
 3. [*] RT Mutex debugging, deadlock detection
 4. -*- Spinlock and rw-lock debugging: basic checks
 5. -*- Mutex debugging: basic checks
 6. -*- Lock debugging: detect incorrect freeing of live locks
 7. [*] Lock debugging: prove locking correctness
 8. [*] Lock usage statistics

Recompile the kernel:

make ARCH=i386 -j4 //whatever your arch is

Now, boot the new kernel image, under /proc you should see the following new folders:

/proc/lockdep
/proc/lockdep_chains
/proc/lockdep_stat
/proc/locks
/proc/lock_stats

Now, insert the module you think that is causing the error, and access it with your user application (or whatever way you use to run your driver module). If the app deadlocks(hangs), do a:

ps -aux | grep <app_name>

you should see a +D (uninterruptible sleep) state for your app, do a:

dmesg

The log it prints will include the function/file causing the deadlock.

That’s it!

Leave a Comment