Skip to contentSkip to conversation

Cannot delete a bridge using 'ip' netlink interface

PATCH Applied Sridhar Samudrala 4 participants 6 messages Oct 6, 2011 – Oct 19, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

On a linux 3.1.0-rc9 system using the latest iproute2, i tried creating a bridge and deleting it with an attached interface.

Here is the sequence of steps i tried
ip link add br0 type bridge
ip link set dev eth1 master br0
ip link set br0 up
ip link del br0

The last command hangs with the following kernel messages kernel:unregister_netdevice: waiting for br0 to become free. Usage count = 1

I see the same behavior even if the bridge is brought down before trying to delete the bridge.

brctl delbr fails with an error message if the bridge is up. But it succeeds if the bridge is brought down before doing a delbr even if it has interfaces attached.

Thanks
Sridhar

#1 lore raw

PATCH 1/1 bridge: fix hang on removal of bridge via netlink

Need to cleanup bridge device timers and ports when being bridge device is being removed via netlink.

This fixes the problem of observed when doing:
ip link add br0 type bridge
ip link set dev eth1 master br0
ip link set br0 up
ip link del br0

which would cause br0 to hang in unregister_netdev because of leftover reference count.

---
Patch is against net-next but should go to net and stable trees since it is an observable hang on 3.0 and later kernels.

net/bridge/br_if.c +5 -4
@@ -160,9 +160,10 @@ static void del_nbp(struct net_bridge_po
 	call_rcu(&p->rcu, destroy_nbp_rcu);
 }
 
-/* called with RTNL */
-static void del_br(struct net_bridge *br, struct list_head *head)
+/* Delete bridge device */
+void br_dev_delete(struct net_device *dev, struct list_head *head)
 {
+	struct net_bridge *br = netdev_priv(dev);
 	struct net_bridge_port *p, *n;
 
 	list_for_each_entry_safe(p, n, &br->port_list, list) {
@@ -267,7 +268,7 @@ int br_del_bridge(struct net *net, const
 	}
 
 	else
-		del_br(netdev_priv(dev), NULL);
+		br_dev_delete(dev, NULL);
 
 	rtnl_unlock();
 	return ret;
@@ -446,7 +447,7 @@ void __net_exit br_net_exit(struct net *
 	rtnl_lock();
 	for_each_netdev(net, dev)
 		if (dev->priv_flags & IFF_EBRIDGE)
-			del_br(netdev_priv(dev), &list);
+			br_dev_delete(dev, &list);
 
 	unregister_netdevice_many(&list);
 	rtnl_unlock();
net/bridge/br_netlink.c +1 -0
@@ -210,6 +210,7 @@ static struct rtnl_link_ops br_link_ops
 	.priv_size	= sizeof(struct net_bridge),
 	.setup		= br_dev_setup,
 	.validate	= br_validate,
+	.dellink	= br_dev_delete,
 };
 
 int __init br_netlink_init(void)
net/bridge/br_private.h +1 -0
@@ -301,6 +301,7 @@ static inline int br_is_root_bridge(cons
 
 /* br_device.c */
 extern void br_dev_setup(struct net_device *dev);
+extern void br_dev_delete(struct net_device *dev, struct list_head *list);
 extern netdev_tx_t br_dev_xmit(struct sk_buff *skb,
 			       struct net_device *dev);
 #ifdef CONFIG_NET_POLL_CONTROLLER
author Acked-by on v1 1/1
#2 lore raw

Re: [PATCH] bridge: fix hang on removal of bridge via netlink

Quoted 9 lines · Stephen Hemminger

Need to cleanup bridge device timers and ports when being bridge device is being removed via netlink.

This fixes the problem of observed when doing:
ip link add br0 type bridge
ip link set dev eth1 master br0
ip link set br0 up
ip link del br0

Quoted 5 lines

which would cause br0 to hang in unregister_netdev because of leftover reference count.

Quoted 58 lines

---
Patch is against net-next but should go to net and stable trees since it is an observable hang on 3.0 and later kernels.

net/bridge/br_if.c +5 -4
@@ -160,9 +160,10 @@ static void del_nbp(struct net_bridge_po
 	call_rcu(&p->rcu, destroy_nbp_rcu);
 }
 
-/* called with RTNL */
-static void del_br(struct net_bridge *br, struct list_head *head)
+/* Delete bridge device */
+void br_dev_delete(struct net_device *dev, struct list_head *head)
 {
+	struct net_bridge *br = netdev_priv(dev);
 	struct net_bridge_port *p, *n;
 
 	list_for_each_entry_safe(p, n, &br->port_list, list) {
@@ -267,7 +268,7 @@ int br_del_bridge(struct net *net, const
 	}
 
 	else
-		del_br(netdev_priv(dev), NULL);
+		br_dev_delete(dev, NULL);
 
 	rtnl_unlock();
 	return ret;
@@ -446,7 +447,7 @@ void __net_exit br_net_exit(struct net *
 	rtnl_lock();
 	for_each_netdev(net, dev)
 		if (dev->priv_flags & IFF_EBRIDGE)
-			del_br(netdev_priv(dev), &list);
+			br_dev_delete(dev, &list);
 
 	unregister_netdevice_many(&list);
 	rtnl_unlock();
net/bridge/br_netlink.c +1 -0
@@ -210,6 +210,7 @@ static struct rtnl_link_ops br_link_ops
 	.priv_size	= sizeof(struct net_bridge),
 	.setup		= br_dev_setup,
 	.validate	= br_validate,
+	.dellink	= br_dev_delete,
 };
 
 int __init br_netlink_init(void)
net/bridge/br_private.h +1 -0
@@ -301,6 +301,7 @@ static inline int br_is_root_bridge(cons
 
 /* br_device.c */
 extern void br_dev_setup(struct net_device *dev);
+extern void br_dev_delete(struct net_device *dev, struct list_head *list);
 extern netdev_tx_t br_dev_xmit(struct sk_buff *skb,
 			       struct net_device *dev);
 #ifdef CONFIG_NET_POLL_CONTROLLER
maintainer Applied
#3 lore raw

Re: [PATCH] bridge: fix hang on removal of bridge via netlink

From: Sridhar Samudrala <[email protected]>
Date: Thu, 06 Oct 2011 16:02:49 -0700

Quoted 10 lines · Stephen Hemminger
Quoted 9 lines

Need to cleanup bridge device timers and ports when being bridge device is being removed via netlink.

This fixes the problem of observed when doing:
ip link add br0 type bridge
ip link set dev eth1 master br0
ip link set br0 up
ip link del br0

Quoted 7 lines
Quoted 5 lines

which would cause br0 to hang in unregister_netdev because of leftover reference count.

Applied to 'net' and queued up for -stable, thanks.

#4 lore raw
In reply to Sridhar Samudrala
Quoted 11 lines · Sridhar Samudrala

On a linux 3.1.0-rc9 system using the latest iproute2, i tried creating a bridge and deleting it with an attached interface.

Here is the sequence of steps i tried
ip link add br0 type bridge
ip link set dev eth1 master br0
ip link set br0 up
ip link del br0

The last command hangs with the following kernel messages kernel:unregister_netdevice: waiting for br0 to become free. Usage count = 1

Note that the same thing happens when one tries to rmmod bridge while it is in use. I'm trying your patch to see if that helps... ;)

/mjt

#5 lore raw
Quoted 10 lines · Michael Tokarev
Quoted 9 lines · Sridhar Samudrala

On a linux 3.1.0-rc9 system using the latest iproute2, i tried creating a bridge and deleting it with an attached interface.

Here is the sequence of steps i tried
ip link add br0 type bridge
ip link set dev eth1 master br0
ip link set br0 up
ip link del br0

Quoted 5 lines
Quoted 2 lines

The last command hangs with the following kernel messages kernel:unregister_netdevice: waiting for br0 to become free. Usage count = 1

Note that the same thing happens when one tries to rmmod bridge while it is in use. I'm trying your patch to see if that helps... ;)

..And with the patch sent in this thread, bridge module can be removed and inserted again with proper cleanup.

So you can add my

too, if necessary :)

Thanks,

/mjt