problem with switch GFP_ATOMIC => GFP_KERNEL

Frantisek Hrbata <[email protected]> Mon, 21 Jul 2008 16:49:12 -0500
Newsgroups gmane.linux.dazuko.devel
Organization AVG Technologies
Message-ID <[email protected]>
Hi,

I am playing with redirfs + dazuko + avg and I found one problem in the dazuko.
Problem is with the switch you made from GFP_ATOMIC to GFP_KERNEL. 

dazuko_core.c: dazuko_is_selected(...)
        call_xp_read_lock(&(slist->lock_lists));
                        |
                        v
        kfs->aliases = (struct dazuko_file_listnode *)xp_malloc(sizeof(struct dazuko_file_listnode));

Here you are holding spinlock(slist->lock_lists == xp_rwlock ==  rwlock_t) and
you are calling kmalloc with the GFP_KERNEL. Allocation with GFP_KERNEL can
block and you can not block while you are holding a spinlock(possible dead
lock).

Jul 21 15:08:35 humpdell kernel: BUG: sleeping function called from invalid context at mm/slab.c:3054
Jul 21 15:08:35 humpdell kernel: in_atomic():1, irqs_disabled():0
Jul 21 15:08:35 humpdell kernel: INFO: lockdep is turned off.
Jul 21 15:08:35 humpdell kernel: Pid: 5219, comm: avgscan Tainted: GF 2.6.25.4 #26
Jul 21 15:08:35 humpdell kernel:
Jul 21 15:08:35 humpdell kernel: Call Trace:
Jul 21 15:08:35 humpdell kernel:  [<ffffffff8024d631>] ? __debug_show_held_locks+0x1b/0x24
Jul 21 15:08:35 humpdell kernel:  [<ffffffff8022bccd>] __might_sleep+0xd9/0xdb
Jul 21 15:08:35 humpdell kernel:  [<ffffffff80286a72>] __kmalloc+0x60/0xe1
Jul 21 15:08:35 humpdell kernel:  [<ffffffff88039ebb>] :dazuko:xp_malloc+0xe/0x10
Jul 21 15:08:35 humpdell kernel:  [<ffffffff88037d37>] :dazuko:dazuko_handle_request_get_an_access+0x1ce/0x657
Jul 21 15:08:35 humpdell kernel:  [<ffffffff803c13ca>] ? __up_read+0x1a/0x83
Jul 21 15:08:35 humpdell kernel:  [<ffffffff880384eb>] :dazuko:dazuko_handle_request+0x32b/0xe8e
Jul 21 15:08:35 humpdell kernel:  [<ffffffff8061fb7b>] ? _spin_unlock_irqrestore+0x4c/0x68
Jul 21 15:08:35 humpdell kernel:  [<ffffffff8803940d>] :dazuko:dazuko_handle_user_request+0x3bf/0x4f2
Jul 21 15:08:35 humpdell kernel:  [<ffffffff88039c24>] :dazuko:linux_dazuko_device_write+0x77/0x92
Jul 21 15:08:35 humpdell kernel:  [<ffffffff8061fbc7>] ? _spin_unlock+0x30/0x4b
Jul 21 15:08:35 humpdell kernel:  [<ffffffff80289c02>] vfs_write+0xae/0x137
Jul 21 15:08:35 humpdell kernel:  [<ffffffff80289d4f>] sys_write+0x47/0x6f
Jul 21 15:08:35 humpdell kernel:  [<ffffffff80223c92>] ia32_sysret+0x0/0xa

I quickly changed the allocation for the kfs->aliases to the GFP_ATOMIC and it
works fine. 

kfs->aliases = (struct dazuko_file_listnode *)kmalloc(sizeof(struct dazuko_file_listnode), GFP_ATOMIC);

I didn't check other parts of dazuko code, so it is possible that this is not the only one allocation
with locked spinlock.
 
-FH