Re: [PATCH] Fix inconsistent lock state in inotify

From: Luca Tettamanti
Date: Wed Apr 15 2009 - 07:59:43 EST


On Wed, Apr 15, 2009 at 1:13 AM, Andrew Morton
<akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Fri, 10 Apr 2009 21:25:33 +0200
> Luca Tettamanti <kronos.it@xxxxxxxxx> wrote:
>
>> Hello,
>> in current -git lockdep generates the following warning:
>>
>> Â=================================
>> Â[ INFO: inconsistent lock state ]
>> Â2.6.30-rc1-kgdb #182
>> Â---------------------------------
>> Âinconsistent {RECLAIM_FS-ON-W} -> {IN-RECLAIM_FS-W} usage.
>> Âkswapd0/419 [HC0[0]:SC0[0]:HE1:SE1] takes:
>> Â (&inode->inotify_mutex){+.+.?.}, at: [<ffffffff802c7036>] inotify_inode_is_dead+0x30/0x94
>> Â{RECLAIM_FS-ON-W} state was registered at:
>> Â Â[<ffffffff80259621>] mark_held_locks+0x4d/0x6b
>> Â Â[<ffffffff802596e3>] lockdep_trace_alloc+0xa4/0xbd
>> Â Â[<ffffffff8029ac2e>] __kmalloc+0x51/0xe6
>> Â Â[<ffffffff802c7ea2>] kernel_event+0xa7/0x10e
>> Â Â[<ffffffff802c7fdc>] inotify_dev_queue_event+0xd3/0x14b
>> Â Â[<ffffffff802c6f56>] inotify_inode_queue_event+0xab/0xe0
>> Â Â[<ffffffff802a6d83>] vfs_create+0xb1/0xc0
>> Â Â[<ffffffff802a975a>] do_filp_open+0x240/0x842
>> Â Â[<ffffffff8029cb1e>] do_sys_open+0x53/0xda
>> Â Â[<ffffffff802d0a62>] compat_sys_open+0x15/0x17
>> Â Â[<ffffffff80228e14>] sysenter_dispatch+0x7/0x30
>> Â Â[<ffffffffffffffff>] 0xffffffffffffffff
>> Âirq event stamp: 30075
>> Âhardirqs last Âenabled at (30075): [<ffffffff802712cf>] call_rcu+0x5d/0x6a
>> Âhardirqs last disabled at (30074): [<ffffffff80271296>] call_rcu+0x24/0x6a
>> Âsoftirqs last Âenabled at (27584): [<ffffffff8023d151>] __do_softirq+0x115/0x124
>> Âsoftirqs last disabled at (27573): [<ffffffff8020c13c>] call_softirq+0x1c/0x28
>>
>> Âother info that might help us debug this:
>> Â2 locks held by kswapd0/419:
>> Â #0: Â(shrinker_rwsem){++++..}, at: [<ffffffff8027dd86>] shrink_slab+0x38/0x188
>> Â #1: Â(&type->s_umount_key#16){++++..}, at: [<ffffffff802ad8c9>] shrink_dcache_memory+0xb9/0x193
>>
>> Âstack backtrace:
>> ÂPid: 419, comm: kswapd0 Not tainted 2.6.30-rc1-kgdb #182
>> ÂCall Trace:
>> Â [<ffffffff8025906c>] print_usage_bug+0x1b6/0x1c7
>> Â [<ffffffff80259c54>] ? check_usage_forwards+0x0/0xa1
>> Â [<ffffffff8025938f>] mark_lock+0x312/0x557
>> Â [<ffffffff8025ad03>] __lock_acquire+0x7b7/0x1668
>> Â [<ffffffff802c7036>] ? inotify_inode_is_dead+0x30/0x94
>> Â [<ffffffff8025bc09>] lock_acquire+0x55/0x71
>> Â [<ffffffff802c7036>] ? inotify_inode_is_dead+0x30/0x94
>> Â [<ffffffff80442ec8>] mutex_lock_nested+0x5a/0x2fa
>> Â [<ffffffff802c7036>] ? inotify_inode_is_dead+0x30/0x94
>> Â [<ffffffff80259621>] ? mark_held_locks+0x4d/0x6b
>> Â [<ffffffff802712cf>] ? call_rcu+0x5d/0x6a
>> Â [<ffffffff802c7036>] inotify_inode_is_dead+0x30/0x94
>> Â [<ffffffff802ad3f1>] dentry_iput+0x82/0xc1
>> Â [<ffffffff802ad4f9>] d_kill+0x24/0x45
>> Â [<ffffffff802ad778>] __shrink_dcache_sb+0x25e/0x2f6
>> Â [<ffffffff802ad901>] shrink_dcache_memory+0xf1/0x193
>> Â [<ffffffff8027de2d>] shrink_slab+0xdf/0x188
>> Â [<ffffffff8027e3be>] kswapd+0x4e8/0x6a3
>> Â [<ffffffff80232d0c>] ? finish_task_switch+0x3b/0x10c
>> Â [<ffffffff8027bec4>] ? isolate_pages_global+0x0/0x26f
>> Â [<ffffffff8024becf>] ? autoremove_wake_function+0x0/0x38
>> Â [<ffffffff802598d6>] ? trace_hardirqs_on+0xd/0xf
>> Â [<ffffffff80444a41>] ? _spin_unlock_irqrestore+0x4c/0x68
>> Â [<ffffffff8027ded6>] ? kswapd+0x0/0x6a3
>> Â [<ffffffff8027ded6>] ? kswapd+0x0/0x6a3
>> Â [<ffffffff8024bb80>] kthread+0x49/0x76
>> Â [<ffffffff8020c03a>] child_rip+0xa/0x20
>> Â [<ffffffff8020ba00>] ? restore_args+0x0/0x30
>> Â [<ffffffff8024bb37>] ? kthread+0x0/0x76
>> Â [<ffffffff8020c030>] ? child_rip+0x0/0x20
>>
>> The cause is a call to kmalloc with GFP_KERNEL; the following patch
>> changes the flag to GFP_NOFS, which is also consistent with an earlier
>> call to kmem_cache_alloc in the same function.
>>
>> Signed-off-by: Luca Tettamanti <kronos.it@xxxxxxxxx>
>> ---
>>
>> Âfs/notify/inotify/inotify_user.c | Â Â2 +-
>> Â1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c
>> index bed766e..1634319 100644
>> --- a/fs/notify/inotify/inotify_user.c
>> +++ b/fs/notify/inotify/inotify_user.c
>> @@ -220,7 +220,7 @@ static struct inotify_kernel_event * kernel_event(s32 wd, u32 mask, u32 cookie,
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â rem = 0;
>> Â Â Â Â Â Â Â }
>>
>> - Â Â Â Â Â Â kevent->name = kmalloc(len + rem, GFP_KERNEL);
>> + Â Â Â Â Â Â kevent->name = kmalloc(len + rem, GFP_NOFS);
>> Â Â Â Â Â Â Â if (unlikely(!kevent->name)) {
>> Â Â Â Â Â Â Â Â Â Â Â kmem_cache_free(event_cachep, kevent);
>> Â Â Â Â Â Â Â Â Â Â Â return NULL;
>
> Thanks.
>
> This is in fact a false positive and we plan to fix it via lockdep
> annotation.

Well, I trust you on the "false positive", but a few line before there this:

kevent = kmem_cache_alloc(event_cachep, GFP_NOFS);

so can kmem_cache_alloc also use GFP_KERNEL?

Luca
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/