genetlink: fix netns vs. netlink table locking
Subsystems (2)
PATCH 1/1 genetlink: fix netns vs. netlink table locking
Since my commits introducing netns awareness into
genetlink we can get this problem:
BUG: scheduling while atomic: modprobe/1178/0x00000002
2 locks held by modprobe/1178:
#0: (genl_mutex){+.+.+.}, at: [<ffffffff8135ee1a>] genl_register_mc_grou
#1: (rcu_read_lock){.+.+..}, at: [<ffffffff8135eeb5>] genl_register_mc_g
Pid: 1178, comm: modprobe Not tainted 2.6.31-rc8-wl-34789-g95cb731-dirty #
Call Trace:
[<ffffffff8103e285>] __schedule_bug+0x85/0x90
[<ffffffff81403138>] schedule+0x108/0x588
[<ffffffff8135b131>] netlink_table_grab+0xa1/0xf0
[<ffffffff8135c3a7>] netlink_change_ngroups+0x47/0x100
[<ffffffff8135ef0f>] genl_register_mc_group+0x12f/0x290because I overlooked that netlink_table_grab() will schedule, thinking it was just the rwlock. However, in the contention case, that isn't actually true.
Fix this by letting the code grab the netlink table lock first and then the RCU for netns protection.
--- include/linux/netlink.h | 4 +++ net/netlink/af_netlink.c | 51 ++++++++++++++++++++++++++--------------------- net/netlink/genetlink.c | 5 +++- 3 files changed, 37 insertions(+), 23 deletions(-)
include/linux/netlink.h +4 -0
@@ -176,12 +176,16 @@ struct netlink_skb_parms#define NETLINK_CREDS (skb) (&NETLINK_CB((skb)).creds) +extern void netlink_table_grab (void ); +extern void netlink_table_ungrab (void ); +extern struct sock *netlink_kernel_create (struct net *net,int unit,unsigned int groups,void (*input)(struct sk_buff *skb),struct mutex *cb_mutex,struct module *module);extern void netlink_kernel_release (struct sock *sk); +extern int __netlink_change_ngroups (struct sock *sk,unsigned int groups);extern int netlink_change_ngroups (struct sock *sk,unsigned int groups);extern void netlink_clear_multicast_users (struct sock *sk,unsigned int group);extern void netlink_ack (struct sk_buff *in_skb,struct nlmsghdr *nlh,int err);
net/netlink/af_netlink.c +29 -22
90 lines not on this page · raw message
net/netlink/genetlink.c +4 -1
@@ -176,9 +176,10 @@ int genl_register_mc_group(struct genl_fif (family->netnsok) {struct net *net; +netlink_table_grab ();rcu_read_lock ();for_each_net_rcu (net) { - err =netlink_change_ngroups (net->genl_sock, + err =__netlink_change_ngroups (net->genl_sock, mc_groups_longs *BITS_PER_LONG );if (err) {/*
@@ -188,10 +189,12 @@ int genl_register_mc_group(struct genl_f* increased on some sockets which is ok. */ rcu_read_unlock (); +netlink_table_ungrab (); goto out; } }rcu_read_unlock (); +netlink_table_ungrab (); }else { err =netlink_change_ngroups (init_net.genl_sock, mc_groups_longs *BITS_PER_LONG );
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 1/1 genetlink: fix netns vs. netlink table locking
Since my commits introducing netns awareness into genetlink we can get this problem:
BUG: scheduling while atomic: modprobe/1178/0x00000002
2 locks held by modprobe/1178:
#0: (genl_mutex){+.+.+.}, at: [<ffffffff8135ee1a>] genl_register_mc_grou
#1: (rcu_read_lock){.+.+..}, at: [<ffffffff8135eeb5>] genl_register_mc_g
Pid: 1178, comm: modprobe Not tainted 2.6.31-rc8-wl-34789-g95cb731-dirty #
Call Trace:
[<ffffffff8103e285>] __schedule_bug+0x85/0x90
[<ffffffff81403138>] schedule+0x108/0x588
[<ffffffff8135b131>] netlink_table_grab+0xa1/0xf0
[<ffffffff8135c3a7>] netlink_change_ngroups+0x47/0x100
[<ffffffff8135ef0f>] genl_register_mc_group+0x12f/0x290because I overlooked that netlink_table_grab() will schedule, thinking it was just the rwlock. However, in the contention case, that isn't actually true.
Fix this by letting the code grab the netlink table lock first and then the RCU for netns protection.
---
v2: rebase over removal of netlink_change_ngroups EXPORT_SYMBOL
include/linux/netlink.h | 4 +++ net/netlink/af_netlink.c | 51 ++++++++++++++++++++++++++--------------------- net/netlink/genetlink.c | 5 +++- 3 files changed, 37 insertions(+), 23 deletions(-)
include/linux/netlink.h +4 -0
@@ -176,12 +176,16 @@ struct netlink_skb_parms#define NETLINK_CREDS (skb) (&NETLINK_CB((skb)).creds) +extern void netlink_table_grab (void ); +extern void netlink_table_ungrab (void ); +extern struct sock *netlink_kernel_create (struct net *net,int unit,unsigned int groups,void (*input)(struct sk_buff *skb),struct mutex *cb_mutex,struct module *module);extern void netlink_kernel_release (struct sock *sk); +extern int __netlink_change_ngroups (struct sock *sk,unsigned int groups);extern int netlink_change_ngroups (struct sock *sk,unsigned int groups);extern void netlink_clear_multicast_users (struct sock *sk,unsigned int group);extern void netlink_ack (struct sk_buff *in_skb,struct nlmsghdr *nlh,int err);
net/netlink/af_netlink.c +29 -22
90 lines not on this page · raw message
net/netlink/genetlink.c +4 -1
@@ -176,9 +176,10 @@ int genl_register_mc_group(struct genl_fif (family->netnsok) {struct net *net; +netlink_table_grab ();rcu_read_lock ();for_each_net_rcu (net) { - err =netlink_change_ngroups (net->genl_sock, + err =__netlink_change_ngroups (net->genl_sock, mc_groups_longs *BITS_PER_LONG );if (err) {/*
@@ -188,10 +189,12 @@ int genl_register_mc_group(struct genl_f* increased on some sockets which is ok. */ rcu_read_unlock (); +netlink_table_ungrab (); goto out; } }rcu_read_unlock (); +netlink_table_ungrab (); }else { err =netlink_change_ngroups (init_net.genl_sock, mc_groups_longs *BITS_PER_LONG );
From: Johannes Berg <[email protected]>
Date: Sat, 12 Sep 2009 07:03:15 -0600
Quoted 15 lines
Since my commits introducing netns awareness into genetlink we can get this problem:
BUG: scheduling while atomic: modprobe/1178/0x00000002 2 locks held by modprobe/1178: #0: (genl_mutex){+.+.+.}, at: [<ffffffff8135ee1a>] genl_register_mc_grou #1: (rcu_read_lock){.+.+..}, at: [<ffffffff8135eeb5>] genl_register_mc_g Pid: 1178, comm: modprobe Not tainted 2.6.31-rc8-wl-34789-g95cb731-dirty # Call Trace: [<ffffffff8103e285>] __schedule_bug+0x85/0x90 [<ffffffff81403138>] schedule+0x108/0x588 [<ffffffff8135b131>] netlink_table_grab+0xa1/0xf0 [<ffffffff8135c3a7>] netlink_change_ngroups+0x47/0x100 [<ffffffff8135ef0f>] genl_register_mc_group+0x12f/0x290
Quoted 8 lines
because I overlooked that
netlink_table_grab()will schedule, thinking it was just the rwlock. However, in the contention case, that isn't actually true.Fix this by letting the code grab the netlink table lock first and then the RCU for netns protection.
Signed-off-by Johannes Berg <[email protected]>
Applied, thanks.