Subject: [PATCH net 0/2] net: fix lockdep false positive splat
Subsystems (4)
cover Subject: [PATCH net 0/2] net: fix lockdep false positive splat
This patchset is to fix lockdep false positive splat in multicast part of the bridge.
When mdb or multicast config is changed, it acquires multicast_lock, which is a per-interface(bridge) lock.
So, spin_lock_nested() should be used instead of spin_lock() because interfaces can be recursive.
The spin_lock_nested() needs 'subclass' parameter.
The first patch adds a new helper function, which returns the nest_level variable under RCU. The nest_level variable can be used as 'subclass' parameter of spin_lock_nested().
The second patch fix lockdep false positive splat in the bridge multicast part by using netdev_get_nest_level_rcu().
Taehee Yoo (2):
net: core: make bond_get_lowest_level_rcu() generic
net: bridge: fix lockdep multicast_lock false positive splat
drivers/net/bonding/bond_main.c | 45 +--------- include/linux/netdevice.h | 1 + net/bridge/br_mdb.c | 12 +-- net/bridge/br_multicast.c | 146 ++++++++++++++++++++------------ net/bridge/br_multicast_eht.c | 18 ++-- net/bridge/br_private.h | 48 +++++++++++ net/core/dev.c | 44 ++++++++++ 7 files changed, 204 insertions(+), 110 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/2 net: core: make bond_get_lowest_level_rcu() generic
The purpose of bond_get_lowest_level_rcu() is to get nested_level under RCU. Because dev->nested_level is protected by RTNL, so it shouldn't be used without RTNL. But bonding module needs this value under RCU without RTNL.
So, this function was added.
But, there is another module, which needs this function. So, make this function generic.
the new name is netdev_get_nest_level_rcu().
--- drivers/net/bonding/bond_main.c | 45 +-------------------------------- include/linux/netdevice.h | 1 + net/core/dev.c | 44 ++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 44 deletions(-)
drivers/net/bonding/bond_main.c +1 -44
@@ -3754,47 +3754,6 @@ static void bond_fold_stats(struct rtnl_link_stats64 *_res, } } -#ifdef CONFIG_LOCKDEP -static int bond_get_lowest_level_rcu (struct net_device *dev) -{ -struct net_device *ldev, *next, *now, *dev_stack[MAX_NEST_DEV +1 ]; -struct list_head *niter, *iter, *iter_stack[MAX_NEST_DEV +1 ]; -int cur =0 , max =0 ; - - now = dev; - iter = &dev->adj_list.lower; - -while (1 ) { - next =NULL ; -while (1 ) { - ldev =netdev_next_lower_dev_rcu (now, &iter); -if (!ldev) -break ; - - next = ldev; - niter = &ldev->adj_list.lower; - dev_stack[cur] = now; - iter_stack[cur++] = iter; -if (max <= cur) - max = cur; -break ; - } - -if (!next) { -if (!cur) -return max; - next = dev_stack[--cur]; - niter = iter_stack[cur]; - } - - now = next; - iter = niter; - } - -return max; -} -#endif -static void bond_get_stats (struct net_device *bond_dev,struct rtnl_link_stats64 *stats) {
@@ -3806,9 +3765,7 @@ static void bond_get_stats(struct net_device *bond_dev,rcu_read_lock (); -#ifdef CONFIG_LOCKDEP - nest_level =bond_get_lowest_level_rcu (bond_dev); -#endif + nest_level =netdev_get_nest_level_rcu (bond_dev);spin_lock_nested (&bond->stats_lock, nest_level);memcpy (stats, &bond->bond_stats,sizeof (*stats));
include/linux/netdevice.h +1 -0
@@ -4699,6 +4699,7 @@ int netdev_walk_all_lower_dev(struct net_device *dev,int (*fn)(struct net_device *lower_dev,struct netdev_nested_priv *priv), struct netdev_nested_priv *priv); +int netdev_get_nest_level_rcu (struct net_device *dev); int netdev_walk_all_lower_dev_rcu(struct net_device *dev, int (*fn)(struct net_device *lower_dev, struct netdev_nested_priv *priv),
net/core/dev.c +44 -0
50 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 2/2 net: bridge: fix lockdep multicast_lock false positive splat
In reply to Taehee Yoomulticast_lock is a per-interface(bridge) lock.
This lock can be used recursively because interfaces can be used recursively. So, it should use spin_lock_nested() but it doesn't. So lockdep false positive splat occurred.
Some inline helper functions are added.
These functions internally get 'subclass' variable, which is used as parameter of spin_lock_nested() and use spin_lock_nested() with a subclass parameter.
Test commands:
ip link add br0 type bridge
ip link add bond0 type bond
ip link add br1 type bridge
ip link set br0 master bond0
ip link set bond0 up
ip link set bond0 master br1
ip link set br0 up
ip link set br1 up
ip link set br0 type bridge mcast_router 1 mcast_querier 1 ip link set br1 type bridge mcast_querier 1 mcast_router 1
Splat looks like:
============================================
WARNING: possible recursive locking detected 5.12.0-rc7+ #855 Not tainted
--------------------------------------------
kworker/5:1/56 is trying to acquire lock:ffff88810f833000 (&br->multicast_lock){+.-.}-{2:2}, at:br_multicast_rcv+0x1484/0x5280 [bridge]
but task is already holding lock:ffff888116e63000 (&br->multicast_lock){+.-.}-{2:2}, at:br_multicast_port_query_expired+0x40/0x140 [bridge]
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
---- lock(&br->multicast_lock);
lock(&br->multicast_lock);
*** DEADLOCK ***
May be due to missing lock nesting notation
9 locks held by kworker/5:1/56:
#0: ffff888100079b48 ((wq_completion)events){+.+.}-{0:0}, at:
process_one_work+0x761/0x1440
#1: ffff888100c6fe00 ((linkwatch_work).work){+.+.}-{0:0}, at:
process_one_work+0x795/0x1440
#2: ffffffffa1278f30 (rtnl_mutex){+.+.}-{3:3}, at:
linkwatch_event+0xa/0x50
#3: ffff88811a009dc8 ((&port->ip4_own_query.timer)){+.-.}-{0:0}, at:
call_timer_fn+0xc8/0x460
#4: ffff888116e63000 (&br->multicast_lock){+.-.}-{2:2}, at:
br_multicast_port_query_expired+0x40/0x140 [bridge]
#5: ffffffffa0e308a0 (rcu_read_lock_bh){....}-{1:2}, at:
__dev_queue_xmit+0x1fd/0x2990
#6: ffffffffa0e30900 (rcu_read_lock){....}-{1:2}, at:
bond_start_xmit+0x7b/0x1160 [bonding]
#7: ffffffffa0e308a0 (rcu_read_lock_bh){....}-{1:2}, at:
__dev_queue_xmit+0x1fd/0x2990
#8: ffffffffa0e30900 (rcu_read_lock){....}-{1:2}, at:
br_dev_xmit+0x5/0x1350 [bridge]
stack backtrace:
CPU: 5 PID: 56 Comm: kworker/5:1 Not tainted 5.12.0-rc7+ #855
Workqueue: events linkwatch_event
Call Trace:
<IRQ>
dump_stack+0xa4/0xe5
__lock_acquire.cold.76+0x1f2/0x3d7
? register_lock_class+0x1750/0x1750
? module_assert_mutex_or_preempt+0x41/0x70
? rcu_read_lock_sched_held+0x91/0xc0
? rcu_read_lock_bh_held+0xa0/0xa0
lock_acquire+0x191/0x720
? br_multicast_rcv+0x1484/0x5280 [bridge]
? lockdep_hardirqs_on_prepare+0x3e0/0x3e0
? skb_checksum_trimmed+0x247/0x360
? ip_mc_check_igmp+0x423/0xf70
_raw_spin_lock+0x30/0x70
? br_multicast_rcv+0x1484/0x5280 [bridge]
br_multicast_rcv+0x1484/0x5280 [bridge]
? print_usage_bug+0x80/0x80
? register_lock_class+0x1750/0x1750
? br_ip6_multicast_leave_group.part.62+0x1b0/0x1b0 [bridge]
? br_handle_vlan+0xa50/0xa50 [bridge]
? lockdep_hardirqs_on_prepare+0x3e0/0x3e0
? rcu_read_lock_held+0x91/0xa0
? rcu_read_lock_sched_held+0xc0/0xc0
br_dev_xmit+0x5fe/0x1350 [bridge]
? br_dev_open+0xd0/0xd0 [bridge]
? rcu_read_lock_sched_held+0x91/0xc0
? skb_csum_hwoffload_help+0x100/0x100
? rcu_read_lock_sched_held+0x91/0xc0
? rcu_read_lock_bh_held+0xa0/0xa0
dev_hard_start_xmit+0x1ae/0x6e0
__dev_queue_xmit+0x1ef8/0x2990
? netdev_core_pick_tx+0x290/0x290
? check_chain_key+0x244/0x5f0
? rcu_read_lock_sched_held+0x91/0xc0
? rcu_read_lock_bh_held+0xa0/0xa0
? rcu_read_lock_held+0x91/0xa0
? rcu_read_lock_sched_held+0xc0/0xc0
? register_lock_class+0x1750/0x1750
? bond_start_xmit+0x274/0x1160 [bonding]
bond_start_xmit+0x274/0x1160 [bonding]
? skb_csum_hwoffload_help+0x100/0x100
? bond_xmit_get_slave+0x2c0/0x2c0 [bonding]
? rcu_read_lock_sched_held+0x91/0xc0
? rcu_read_lock_bh_held+0xa0/0xa0
? netif_skb_features+0x296/0x9c0
dev_hard_start_xmit+0x1ae/0x6e0
__dev_queue_xmit+0x1ef8/0x2990
? check_object+0xb3/0x290
? init_object+0x4e/0x80
? netdev_core_pick_tx+0x290/0x290
? mark_held_locks+0xb7/0x120
? rcu_read_lock_sched_held+0x91/0xc0
? rcu_read_lock_bh_held+0xa0/0xa0
? slab_post_alloc_hook+0x43/0x430
? trace_kmalloc_node+0xb0/0xe0
? __kmalloc_node_track_caller+0x11c/0x2b0
? __alloc_skb+0xc5/0x290
? memset+0x1f/0x40
? br_dev_queue_push_xmit+0x1ad/0x610 [bridge]
br_dev_queue_push_xmit+0x1ad/0x610 [bridge]
[...]--- net/bridge/br_mdb.c | 12 +-- net/bridge/br_multicast.c | 146 +++++++++++++++++++++------------- net/bridge/br_multicast_eht.c | 18 +++-- net/bridge/br_private.h | 48 +++++++++++ 4 files changed, 158 insertions(+), 66 deletions(-)
net/bridge/br_mdb.c +6 -6
@@ -490,7 +490,7 @@ static void br_mdb_complete(struct net_device *dev, int err, void *priv)if (err) goto err; -spin_lock_bh (&br->multicast_lock); +br_multicast_lock_rtnl_bh (br); mp =br_mdb_ip_get (br, &data->ip);if (!mp) goto out;
@@ -501,7 +501,7 @@ static void br_mdb_complete(struct net_device *dev, int err, void *priv) p->flags |=MDB_PG_FLAGS_OFFLOAD ; } out: -spin_unlock_bh (&br->multicast_lock); +br_multicast_unlock_bh (br); err:kfree (priv); }
@@ -949,9 +949,9 @@ static int __br_mdb_add(struct net *net, struct net_bridge *br, {int ret; -spin_lock_bh (&br->multicast_lock); +br_multicast_lock_rtnl_bh (br); ret =br_mdb_add_group (br, p, entry, mdb_attrs, extack); -spin_unlock_bh (&br->multicast_lock); +br_multicast_unlock_bh (br);return ret; }
@@ -1042,7 +1042,7 @@ static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry,__mdb_entry_to_br_ip (entry, &ip, mdb_attrs); -spin_lock_bh (&br->multicast_lock); +br_multicast_lock_rtnl_bh (br); mp =br_mdb_ip_get (br, &ip);if (!mp) goto unlock;
@@ -1072,7 +1072,7 @@ static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry, } unlock: -spin_unlock_bh (&br->multicast_lock); +br_multicast_unlock_bh (br);return err; }
net/bridge/br_multicast.c +92 -54
435 lines not on this page · raw message
net/bridge/br_multicast_eht.c +12 -6
@@ -209,7 +209,8 @@ static void br_multicast_eht_set_entry_expired(struct timer_list *t)struct net_bridge_group_eht_set_entry *set_h =from_timer (set_h, t, timer);struct net_bridge *br = set_h->br; -spin_lock (&br->multicast_lock); +rcu_read_lock (); +br_multicast_lock_rcu (br);if (RB_EMPTY_NODE (&set_h->rb_node) ||timer_pending (&set_h->timer)) goto out;
@@ -217,7 +218,8 @@ static void br_multicast_eht_set_entry_expired(struct timer_list *t) &set_h->eht_set->src_addr, &set_h->h_addr); out: -spin_unlock (&br->multicast_lock); +br_multicast_unlock (br); +rcu_read_unlock (); }static void br_multicast_eht_set_expired (struct timer_list *t)
@@ -226,13 +228,15 @@ static void br_multicast_eht_set_expired(struct timer_list *t) timer);struct net_bridge *br = eht_set->br; -spin_lock (&br->multicast_lock); +rcu_read_lock (); +br_multicast_lock_rcu (br);if (RB_EMPTY_NODE (&eht_set->rb_node) ||timer_pending (&eht_set->timer)) goto out;br_multicast_del_eht_set (eht_set); out: -spin_unlock (&br->multicast_lock); +br_multicast_unlock (br); +rcu_read_unlock (); } static struct net_bridge_group_eht_host *
@@ -870,9 +874,11 @@ int br_multicast_eht_set_hosts_limit(struct net_bridge_port *p,if (!eht_hosts_limit)return -EINVAL ; -spin_lock_bh (&br->multicast_lock); +rcu_read_lock (); +br_multicast_lock_rcu_bh (br); p->multicast_eht_hosts_limit = eht_hosts_limit; -spin_unlock_bh (&br->multicast_lock); +br_multicast_unlock_bh (br); +rcu_read_unlock ();return 0 ; }
net/bridge/br_private.h +48 -0
54 lines not on this page · raw message
Signature · 1 line
2.17.1