linux中的內(nèi)核死鎖調(diào)試
linux內(nèi)核死鎖調(diào)試
使用內(nèi)核的kernel hacking功能
打開以下配置
CONFIG_PROVE_LOCKING=y CONFIG_LOCK_STAT=y CONFIG_DEBUG_LOCKDEP=y
重新編譯內(nèi)核后,
proc目錄下會(huì)有l(wèi)ockdep lockdep_stats lockdep_chains說明lockdep模塊已經(jīng)生效
測試code
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
static DEFINE_SPINLOCK(hack_spinA);
static DEFINE_SPINLOCK(hack_spinB);
#ifdef MEMORY_TEST
static char* buf;
static void create_slue_err(void){
buf = kmalloc(32,GFP_KERNEL);
if(buf) {
/*memset(buf,0x00,33);*/
/* kfree(buf);
printk("%s\n","free buf" );*/
/*kfree(buf);*/
memset(buf,0x00,33);
}
return;
}
#endif
void hack_spinBA(void) {
printk("%s\n","hack_spin:B=>A\n" );
spin_lock(&hack_spinA);
spin_lock(&hack_spinB);
}
void hack_spinAB(void) {
printk("%s\n","hack_spin:A=>B\n" );
spin_lock(&hack_spinB);
}
static int __init my_test_init(void) {
printk("init %s\n", "my_test_init 1");
#ifdef MEMORY_TEST
create_slue_err();
#endif
hack_spinBA();
hack_spinAB();
printk("init %s\n", "my_test_init 2");
return 0;
}
static void __exit my_test_exit(void) {
printk("%s\n","my_test_exit" );
return ;
}
MODULE_LICENSE("GPL");
module_init(my_test_init);
module_exit(my_test_exit);
測試打?。?/p>
[ 188.596504@1] init my_test_init 1
[ 188.596548@1] hack_spin:B=>A
[ 188.596548@1]
[ 188.598679@1] hack_spin:A=>B
[ 188.598679@1]
[ 189.920389@1] BUG: spinlock lockup suspected on CPU#1, insmod/6999
[ 189.920943@1] lock: hack_spinB+0x0/0xfffffffffffffef4 [slub_test], .magic: dead4ead, .owner: insmod/6999, .owner_cpu: 1
[ 189.931758@1] CPU: 1 PID: 6999 Comm: insmod Tainted: G O 3.14.29 #6
[ 189.938784@1] Call trace:
[ 189.941406@1] [<ffffffc0010893f8>] dump_backtrace+0x0/0x144
[ 189.946896@1] [<ffffffc001089558>] show_stack+0x1c/0x28
[ 189.952120@1] [<ffffffc001b5b480>] dump_stack+0x74/0xb8
[ 189.957247@1] [<ffffffc0010fb6d4>] spin_dump+0x78/0x98
[ 189.962369@1] [<ffffffc0010fb904>] do_raw_spin_lock+0x170/0x1a8
[ 189.968199@1] [<ffffffc001b670a8>] _raw_spin_lock+0x68/0x88
[ 189.973764@1] [<ffffffbffc00507c>] hack_spinAB+0x30/0x3c [slub_test]
[ 189.980015@1] [<ffffffbffc00d028>] $x+0x28/0x4c [slub_test]
[ 189.985566@1] [<ffffffc0010816d4>] do_one_initcall+0xd4/0x13c
[ 189.991257@1] [<ffffffc00112c2f8>] load_module+0x16d8/0x1e08
[ 189.996834@1] [<ffffffc00112cba0>] SyS_finit_module+0x80/0x90[ 211.641019@1] INFO: rcu_sched detected stalls on CPUs/tasks: { 1} (detected by 2, t=2104 jiffies, g=18446744073709551337, c=18446744073709551336, q=4)
[ 211.648804@2] Task dump for CPU 1:
[ 211.652167@2] insmod R running task 0 6999 5821 0x0000000a
[ 211.659325@2] Call trace:
[ 211.661920@2] [<ffffffc001085f10>] __switch_to+0x74/0x8c
很明顯可以看出死鎖的發(fā)生路徑與調(diào)用棧
hack_spinAB在申請(qǐng)spin_lock(&hack_spinB)時(shí)死鎖了
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Centos 7.4中的遠(yuǎn)程訪問控制的實(shí)現(xiàn)方法
這篇文章主要介紹了Centos 7.4中的遠(yuǎn)程訪問控制的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-11-11
Linux系統(tǒng)?Centos7.4手動(dòng)在線升級(jí)到Centos7.7
這篇文章主要介紹了Centos7.4手動(dòng)升級(jí)到Centos7.7,需要的朋友可以參考下2022-01-01
詳解Linux下安裝php環(huán)境并且配置Nginx支持php-fpm模塊
本篇文章主要介紹了詳解Linux下安裝php環(huán)境并且配置Nginx支持php-fpm模塊,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2017-03-03
用rsync對(duì)網(wǎng)站進(jìn)行鏡像備份實(shí)現(xiàn)步驟
對(duì)系統(tǒng)管理員來說,平時(shí)的工作重心應(yīng)該集中在維護(hù)系統(tǒng)正常運(yùn)轉(zhuǎn),能夠正常提供服務(wù)上,這里往往牽涉到一個(gè)數(shù)據(jù)備份的問題2009-03-03
apache 開啟重定向 rewrite的實(shí)現(xiàn)方法
這篇文章主要介紹了apache 開啟重定向 rewrite的實(shí)現(xiàn)方法的相關(guān)資料,希望通過本文能幫助到大家,讓大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下2017-10-10

