bonding: fix potential deadlock in bond_uninit()
Subsystems (3)
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().
---
drivers/net/bonding/bond_main.c +4 -1
@@ -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);
Quoted 5 lines · Amerigo Wang
bond_uninit()is invoked withrtnl_lockheld, when it doesdestroy_workqueue()which will potentially flush all works in this workqueue, if we holdrtnl_lockagain in the work function, it will deadlock.So unlock
rtnl_lockbefore callingdestroy_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
Signed-off-by WANG Cong <[email protected]>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@@ -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);
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 withrtnl_lockheld, when it doesdestroy_workqueue()which will potentially flush all works in this workqueue, if we holdrtnl_lockagain in the work function, it will deadlock.So unlock
rtnl_lockbefore callingdestroy_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_workqueueinto 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.
Quoted 10 lines · Eric W. Biederman
Quoted 5 lines · Amerigo Wang
bond_uninit()is invoked withrtnl_lockheld, when it doesdestroy_workqueue()which will potentially flush all works in this workqueue, if we holdrtnl_lockagain in the work function, it will deadlock.So unlock
rtnl_lockbefore callingdestroy_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_workqueueinto the network device destructor.
Oh, this seems a better idea, as long as the destructor are not called with any locks holding.
Thanks!