Skip to contentSkip to conversation

bonding: fix potential deadlock in bond_uninit()

PATCH Superseded Amerigo Wang 3 participants 4 messages Mar 31, 2010 – Apr 1, 2010

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bonding: fix potential deadlock in bond_uninit()

bond_uninit() is invoked with rtnl_lock held, when it does destroy_workqueue() which will potentially flush all works in this workqueue, if we hold rtnl_lock again in the work function, it will deadlock.

So unlock rtnl_lock before calling destroy_workqueue().

Cc Jay Vosburgh <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Stephen Hemminger <[email protected]>
Cc Jiri Pirko <[email protected]>
Cc "Eric W. Biederman" <[email protected]>

---

drivers/net/bonding/bond_main.c +4 -1
index 5b92fbf..b781728 100644
@@ -4542,8 +4542,11 @@ static void bond_uninit(struct net_device *bond_dev)
 
 	bond_remove_proc_entry(bond);
 
-	if (bond->wq)
+	if (bond->wq) {
+		rtnl_unlock();
 		destroy_workqueue(bond->wq);
+		rtnl_lock();
+	}
 
 	netif_addr_lock_bh(bond_dev);
 	bond_mc_list_destroy(bond);
#1 lore raw
Quoted 5 lines · Amerigo Wang

bond_uninit() is invoked with rtnl_lock held, when it does destroy_workqueue() which will potentially flush all works in this workqueue, if we hold rtnl_lock again in the work function, it will deadlock.

So unlock rtnl_lock before calling destroy_workqueue().

Ouch. That seems rather rude to our caller, and likely very dangerous.

Is this a deadlock you actually hit, or is this something lockdep warned about?

My gut feel says we need to move the destroy_workqueue into the network device destructor.

Eric

Quoted 25 lines
Cc Jay Vosburgh <[email protected]>
Cc "David S. Miller" <[email protected]>
Cc Stephen Hemminger <[email protected]>
Cc Jiri Pirko <[email protected]>
Cc "Eric W. Biederman" <[email protected]>

---

drivers/net/bonding/bond_main.c +4 -1
index 5b92fbf..b781728 100644
@@ -4542,8 +4542,11 @@ static void bond_uninit(struct net_device *bond_dev)
 
 	bond_remove_proc_entry(bond);
 
-	if (bond->wq)
+	if (bond->wq) {
+		rtnl_unlock();
 		destroy_workqueue(bond->wq);
+		rtnl_lock();
+	}
 
 	netif_addr_lock_bh(bond_dev);
 	bond_mc_list_destroy(bond);
#2 lore raw
Quoted 11 lines · On Wed, 31 Mar 2010 04:28:33 -0700 [email protected] (Eric W. Biederman)…
Quoted 5 lines · Amerigo Wang

bond_uninit() is invoked with rtnl_lock held, when it does destroy_workqueue() which will potentially flush all works in this workqueue, if we hold rtnl_lock again in the work function, it will deadlock.

So unlock rtnl_lock before calling destroy_workqueue().

Ouch. That seems rather rude to our caller, and likely very dangerous.

Quoted 7 lines

Is this a deadlock you actually hit, or is this something lockdep warned about?

My gut feel says we need to move the destroy_workqueue into the network device destructor.

Eric

Why is there one workqueue per bond device rather than just one workqueue for all bonding devices controlled by the module instance? It would be cleaner on removal and less space and overhead. I can't see that doing arp/mii or alb work is high parallel and load activity.

author
#3 lore raw
In reply to Eric W. Biederman
Quoted 10 lines · Eric W. Biederman
Quoted 5 lines · Amerigo Wang

bond_uninit() is invoked with rtnl_lock held, when it does destroy_workqueue() which will potentially flush all works in this workqueue, if we hold rtnl_lock again in the work function, it will deadlock.

So unlock rtnl_lock before calling destroy_workqueue().

Ouch. That seems rather rude to our caller, and likely very dangerous.

This is reasonable, because workqueue flush functions will potentially call all the work functions which could take the same lock taken before the flush call, thus deadlock.

Quoted 3 lines

Is this a deadlock you actually hit, or is this something lockdep warned about?

It's only a lockdep warning.

Quoted 4 lines

My gut feel says we need to move the destroy_workqueue into the network device destructor.

Oh, this seems a better idea, as long as the destructor are not called with any locks holding.

Thanks!