From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hannes Frederic Sowa Subject: Re: [PATCH] net: ipv6: fib: don't sleep inside atomic lock Date: Thu, 21 Aug 2014 14:54:40 +0200 Message-ID: <1408625680.5817.9.camel@localhost> References: <1408551366-24237-1-git-send-email-bebl@mageta.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: "David S. Miller" , Alexey Kuznetsov , James Morris , Hideaki YOSHIFUJI , Patrick McHardy , netdev@vger.kernel.org, linux-kernel@vger.kernel.org To: Benjamin Block Return-path: In-Reply-To: <1408551366-24237-1-git-send-email-bebl@mageta.org> Sender: linux-kernel-owner@vger.kernel.org List-Id: netdev.vger.kernel.org On Mi, 2014-08-20 at 18:16 +0200, Benjamin Block wrote: > The function fib6_commit_metrics() allocates a piece of memory in mode > GFP_KERNEL while holding an atomic lock from higher up in the stack, in > the function __ip6_ins_rt(). This produces the following BUG: > > > BUG: sleeping function called from invalid context at mm/slub.c:1250 > > in_atomic(): 1, irqs_disabled(): 0, pid: 2909, name: dhcpcd > > 2 locks held by dhcpcd/2909: > > #0: (rtnl_mutex){+.+.+.}, at: [] rtnl_lock+0x17/0x20 > > #1: (&tb->tb6_lock){++--+.}, at: [] ip6_route_add+0x65a/0x800 > > CPU: 1 PID: 2909 Comm: dhcpcd Not tainted 3.17.0-rc1 #1 > > Hardware name: ASUS All Series/Q87T, BIOS 0216 10/16/2013 > > 0000000000000008 ffff8800c8f13858 ffffffff81af135a 0000000000000000 > > ffff880212202430 ffff8800c8f13878 ffffffff810f8d3a ffff880212202c98 > > 0000000000000010 ffff8800c8f138c8 ffffffff8121ad0e 0000000000000001 > > Call Trace: > > [] dump_stack+0x4e/0x68 > > [] __might_sleep+0x10a/0x120 > > [] kmem_cache_alloc_trace+0x4e/0x190 > > [] ? fib6_commit_metrics+0x66/0x110 > > [] fib6_commit_metrics+0x66/0x110 > > [] fib6_add+0x883/0xa80 > > [] ? ip6_route_add+0x65a/0x800 > > [] ip6_route_add+0x675/0x800 > > [] ? ip6_route_add+0x6a/0x800 > > [] inet6_rtm_newroute+0x5c/0x80 > > [] rtnetlink_rcv_msg+0x211/0x260 > > [] ? rtnl_lock+0x17/0x20 > > [] ? lock_release_holdtime+0x28/0x180 > > [] ? rtnl_lock+0x17/0x20 > > [] ? __rtnl_unlock+0x20/0x20 > > [] netlink_rcv_skb+0x6e/0xd0 > > [] rtnetlink_rcv+0x25/0x40 > > [] netlink_unicast+0xd9/0x180 > > [] netlink_sendmsg+0x700/0x770 > > [] ? local_clock+0x25/0x30 > > [] sock_sendmsg+0x6c/0x90 > > [] ? might_fault+0xa3/0xb0 > > [] ? verify_iovec+0x7d/0xf0 > > [] ___sys_sendmsg+0x37e/0x3b0 > > [] ? trace_hardirqs_on_caller+0x185/0x220 > > [] ? mutex_unlock+0xe/0x10 > > [] ? netlink_insert+0xbc/0xe0 > > [] ? netlink_autobind.isra.30+0x125/0x150 > > [] ? netlink_autobind.isra.30+0x60/0x150 > > [] ? netlink_bind+0x159/0x230 > > [] ? might_fault+0x5a/0xb0 > > [] ? SYSC_bind+0x7e/0xd0 > > [] __sys_sendmsg+0x4d/0x80 > > [] SyS_sendmsg+0x12/0x20 > > [] system_call_fastpath+0x16/0x1b > > Fixing this by replacing the mode GFP_KERNEL with GFP_NOWAIT. > > Signed-off-by: Benjamin Block > --- > net/ipv6/ip6_fib.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c > index cb4459b..7eef9fc 100644 > --- a/net/ipv6/ip6_fib.c > +++ b/net/ipv6/ip6_fib.c > @@ -643,7 +643,7 @@ static int fib6_commit_metrics(struct dst_entry *dst, > if (dst->flags & DST_HOST) { > mp = dst_metrics_write_ptr(dst); > } else { > - mp = kzalloc(sizeof(u32) * RTAX_MAX, GFP_KERNEL); > + mp = kzalloc(sizeof(u32) * RTAX_MAX, GFP_NOWAIT); > if (!mp) > return -ENOMEM; > dst_init_metrics(dst, mp, 0); I actually think we should go with GFP_ATOMIC like the rest of the stack. The code path we are talking about here mostly uses GFP_ATOMIC, so in case this one GFP_NOWAITit bails out via error path, all those GFP_ATOMIC allocations before were useless. Bye, Hannes