Linux kernel 错误:从arch/x86/mm/fault.c的无效上下文调用休眠函数

Linux kernel 错误:从arch/x86/mm/fault.c的无效上下文调用休眠函数,linux-kernel,Linux Kernel,我是内核编码新手。我在内核模块中定义了一个工作队列,如下所示: struct sk_buff_head *g_temp =NULL; struct workqueue_struct *myqueue; // pointer to your workqueue void dowork( struct work_struct *data ); // your function.s prototype DECLARE_DELAYED_WORK( mywork, dowork );

我是内核编码新手。我在内核模块中定义了一个工作队列,如下所示:

struct sk_buff_head *g_temp =NULL;
struct workqueue_struct *myqueue;       // pointer to your workqueue
void dowork( struct work_struct *data );    // your function.s prototype
DECLARE_DELAYED_WORK( mywork, dowork );

void dowork( struct work_struct *data )
{

printk("\nInside dowork \n");
if(g_temp !=NULL)
{
    printk("\n g_temp not NULL\n");
    skb_queue_purge(g_temp);
    kfree(g_temp);
    g_temp = NULL;
}
printk("\n\n I am doing the delayed work right now  \n");

queue_delayed_work( myqueue, &mywork, 5000);
}

static int __init my_init(void)
{
    myqueue = create_workqueue("mywork");
    if ( !queue_delayed_work( myqueue, &mywork, 5000 ) )
        return 0;
}

static void __exit my_exit(void)
{
    cancel_delayed_work(&mywork);     /* no "new ones" */
    flush_workqueue(myqueue);  /* wait till all "old ones" finished */

    destroy_workqueue(myqueue);
}
内存在另一个函数中分配,如:

static unsigned int
packet(struct sk_buff *in_skb)
{
   g_temp = kzalloc(sizeof(struct sk_buff_head), GFP_ATOMIC);             


   if( NULL == g_temp)
   {         
      kfree_skb(new_skb);
   }
   skb_queue_head_init(g_temp);
   skb_queue_tail(g_temp, new_skb);
}
我的主要想法是在sk_buff_head中对传入的数据包进行排队,并在5次sce后刷新数据包。但结果如下:

BUG: sleeping function called from invalid context at arch/x86/mm/fault.c
in_atomic(): 0, irqs_disabled(): 1, pid: 4632, name: sh
 Pid: 4632, comm: sh Not tainted 2.6.33.3-85.fc13.i686.PAE #1
 Call Trace:
 [<c042f827>] __might_sleep+0xc5/0xcc
 [<c078503b>] do_page_fault+0x1b4/0x2fa
 [<c0784e87>] ? do_page_fault+0x0/0x2fa
 [<c07832df>] error_code+0x73/0x78
 [<c04c86f7>] ? kmem_cache_alloc_notrace+0x78/0xa2
 [<c04e44cf>] ? single_open+0x1f/0x90
 [<c050b8e4>] ? meminfo_proc_show+0x0/0x3b8
 [<c04e44cf>] single_open+0x1f/0x90
 [<c050b8e2>] meminfo_proc_open+0x11/0x13
 [<c05069bd>] proc_reg_open+0xae/0x111
 [<c04e407b>] ? single_release+0x0/0x1f
 [<c04cf2e6>] __dentry_open+0x155/0x245
 [<c04cf46f>] nameidata_to_filp+0x2c/0x40
 [<c050690f>] ? proc_reg_open+0x0/0x111
 [<c04d9f34>] do_filp_open+0x440/0x827
 [<c05a6680>] ? might_fault+0x19/0x1b
 [<c05a675d>] ? strncpy_from_user+0x33/0x4f
 [<c04e14f9>] ? alloc_fd+0x53/0xb9
 [<c04cf09b>] do_sys_open+0x48/0xdf
 [<c0785154>] ? do_page_fault+0x2cd/0x2fa
 [<c04cf174>] sys_open+0x1e/0x26
 [<c040885f>] sysenter_do_call+0x12/0x28
 BUG: unable to handle kernel NULL pointer dereference at 0000022a
 IP: [<c04c86f7>] kmem_cache_alloc_notrace+0x78/0xa2
 *pdpt = 000000000cad7001 *pde = 0000000000000000
BUG:从arch/x86/mm/fault.c的无效上下文调用休眠函数
in_atomic():0,irqs_disabled():1,pid:4632,name:sh
Pid:4632,通信:sh未污染2.6.33.3-85.fc13.i686.PAE#1
呼叫跟踪:
[]可能睡眠+0xc5/0xcc
[]执行页面错误+0x1b4/0x2fa
[] ? do_page_故障+0x0/0x2fa
[]错误代码+0x73/0x78
[] ? kmem_缓存_分配_notrace+0x78/0xa2
[] ? 单开门+0x1f/0x90
[] ? meminfo程序显示+0x0/0x3b8
[]单开门+0x1f/0x90
[]内存信息进程打开+0x11/0x13
[]程序注册打开+0xae/0x111
[] ? 单次释放+0x0/0x1f
[]门打开+0x155/0x245
[]将数据命名为filp+0x2c/0x40
[] ? proc_reg_open+0x0/0x111
[]do_filp_open+0x440/0x827
[] ? 可能出现故障+0x19/0x1b
[] ? strncpy_from_user+0x33/0x4f
[] ? alloc_fd+0x53/0xb9
[]执行系统打开+0x48/0xdf
[] ? do_page_故障+0x2cd/0x2fa
[]系统打开+0x1e/0x26
[]sysenter\u do\u call+0x12/0x28
错误:无法处理0000022a处的内核空指针取消引用
IP:[]kmem\u缓存\u alloc\u notrace+0x78/0xa2
*pdpt=000000000 CAD7001*pde=000000000000000