From: Cong Wang Subject: [Patch net] netns: correct gfp flags for alloc_netid() Date: Thu, 26 Feb 2015 16:54:50 -0800 Message-ID: <1424998490-9565-1-git-send-email-xiyou.wangcong@gmail.com> Cc: Nicolas Dichtel , Cong Wang To: netdev@vger.kernel.org Return-path: Received: from mail-pd0-f169.google.com ([209.85.192.169]:45765 "EHLO mail-pd0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753862AbbB0Ay5 (ORCPT ); Thu, 26 Feb 2015 19:54:57 -0500 Received: by pdjz10 with SMTP id z10so16919665pdj.12 for ; Thu, 26 Feb 2015 16:54:57 -0800 (PST) Sender: netdev-owner@vger.kernel.org List-ID: This fixes the following kernel warning: =============================== [ INFO: suspicious RCU usage. ] 3.19.0+ #805 Tainted: G W ------------------------------- include/linux/rcupdate.h:538 Illegal context switch in RCU read-side critical section! other info that might help us debug this: rcu_scheduler_active = 1, debug_locks = 0 2 locks held by ip/771: #0: (rtnl_mutex){+.+.+.}, at: [] netlink_dump+0x21/0x26c #1: (rcu_read_lock){......}, at: [] rcu_read_lock+0x0/0x6e stack backtrace: CPU: 3 PID: 771 Comm: ip Tainted: G W 3.19.0+ #805 Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011 0000000000000001 ffff8800d51e7718 ffffffff81a27457 0000000029e729e6 ffff8800d6108000 ffff8800d51e7748 ffffffff810b539b ffffffff820013dd 00000000000001c8 0000000000000000 ffff8800d7448088 ffff8800d51e7758 Call Trace: [] dump_stack+0x4c/0x65 [] lockdep_rcu_suspicious+0x107/0x110 [] rcu_preempt_sleep_check+0x45/0x47 [] ___might_sleep+0x1d/0x1cb [] __might_sleep+0x78/0x80 [] idr_alloc+0x45/0xd1 [] ? rcu_read_lock_held+0x3b/0x3d [] ? idr_for_each+0x53/0x101 [] alloc_netid+0x61/0x69 [] __peernet2id+0x79/0x8d [] peernet2id+0x13/0x1f [] rtnl_fill_ifinfo+0xa8d/0xc20 [] ? __lock_is_held+0x39/0x52 [] rtnl_dump_ifinfo+0x149/0x213 [] netlink_dump+0xef/0x26c [] netlink_recvmsg+0x17b/0x2c5 [] __sock_recvmsg+0x4e/0x59 [] sock_recvmsg+0x3f/0x51 [] ___sys_recvmsg+0xf6/0x1d9 [] ? handle_pte_fault+0x6e1/0xd3d [] ? native_sched_clock+0x35/0x37 [] ? sched_clock_local+0x12/0x72 [] ? sched_clock_cpu+0x9e/0xb7 [] ? rcu_read_lock_held+0x3b/0x3d [] ? __fcheck_files+0x4c/0x58 [] ? __fget_light+0x2d/0x52 [] __sys_recvmsg+0x42/0x60 [] SyS_recvmsg+0x12/0x1c Fixes: commit 0c7aecd4bde4b7302 ("netns: add rtnl cmd to add and get peer netns ids") Cc: Nicolas Dichtel Signed-off-by: Cong Wang --- diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index cb5290b..ecf8e70 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -148,7 +148,8 @@ static void ops_free_list(const struct pernet_operations *ops, } } -static int alloc_netid(struct net *net, struct net *peer, int reqid) +static int alloc_netid(struct net *net, struct net *peer, int reqid, + gfp_t flags) { int min = 0, max = 0; @@ -159,7 +160,7 @@ static int alloc_netid(struct net *net, struct net *peer, int reqid) max = reqid + 1; } - return idr_alloc(&net->netns_ids, peer, min, max, GFP_KERNEL); + return idr_alloc(&net->netns_ids, peer, min, max, flags); } /* This function is used by idr_for_each(). If net is equal to peer, the @@ -188,7 +189,7 @@ static int __peernet2id(struct net *net, struct net *peer, bool alloc) return id; if (alloc) - return alloc_netid(net, peer, -1); + return alloc_netid(net, peer, -1, GFP_ATOMIC); return -ENOENT; } @@ -524,7 +525,7 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh) goto out; } - err = alloc_netid(net, peer, nsid); + err = alloc_netid(net, peer, nsid, GFP_KERNEL); if (err > 0) err = 0; out: