欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

linux中的內(nèi)核死鎖調(diào)試

 更新時間:2024年02月12日 18:19:59   作者:來自深淵的凝視  
這篇文章主要介紹了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目錄下會有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);

測試打印:

[  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在申請spin_lock(&hack_spinB)時死鎖了

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論