netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch V2] bonding: fix potential deadlock in bond_uninit()
@ 2010-04-01  6:06 Amerigo Wang
  2010-04-01  6:12 ` Eric W. Biederman
  0 siblings, 1 reply; 5+ messages in thread
From: Amerigo Wang @ 2010-04-01  6:06 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jiri Pirko, Stephen Hemminger, netdev, David S. Miller,
	Eric W. Biederman, Amerigo Wang, bonding-devel, Jay Vosburgh


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 move destroy_workqueue() to destructor where rtnl_lock is not held any more,
suggested by Eric.

Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Jay Vosburgh <fubar@us.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Stephen Hemminger <shemminger@vyatta.com>
Cc: Jiri Pirko <jpirko@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>

---

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 5b92fbf..9f0aaa2 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -4450,6 +4450,14 @@ static const struct net_device_ops bond_netdev_ops = {
 	.ndo_vlan_rx_kill_vid	= bond_vlan_rx_kill_vid,
 };
 
+static void bond_destructor(struct net_device *bond_dev)
+{
+	struct bonding *bond = netdev_priv(bond_dev);
+	if (bond->wq)
+		destroy_workqueue(bond->wq);
+	free_netdev(bond_dev);
+}
+
 static void bond_setup(struct net_device *bond_dev)
 {
 	struct bonding *bond = netdev_priv(bond_dev);
@@ -4470,7 +4478,7 @@ static void bond_setup(struct net_device *bond_dev)
 	bond_dev->ethtool_ops = &bond_ethtool_ops;
 	bond_set_mode_ops(bond, bond->params.mode);
 
-	bond_dev->destructor = free_netdev;
+	bond_dev->destructor = bond_destructor;
 
 	/* Initialize the device options */
 	bond_dev->tx_queue_len = 0;
@@ -4542,9 +4550,6 @@ static void bond_uninit(struct net_device *bond_dev)
 
 	bond_remove_proc_entry(bond);
 
-	if (bond->wq)
-		destroy_workqueue(bond->wq);
-
 	netif_addr_lock_bh(bond_dev);
 	bond_mc_list_destroy(bond);
 	netif_addr_unlock_bh(bond_dev);

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch V2] bonding: fix potential deadlock in bond_uninit()
  2010-04-01  6:06 [Patch V2] bonding: fix potential deadlock in bond_uninit() Amerigo Wang
@ 2010-04-01  6:12 ` Eric W. Biederman
  2010-04-01  6:54   ` Cong Wang
  2010-04-01  7:30   ` [Patch V3] " Cong Wang
  0 siblings, 2 replies; 5+ messages in thread
From: Eric W. Biederman @ 2010-04-01  6:12 UTC (permalink / raw)
  To: Amerigo Wang
  Cc: linux-kernel, Jiri Pirko, Stephen Hemminger, netdev,
	David S. Miller, bonding-devel, Jay Vosburgh

Amerigo Wang <amwang@redhat.com> writes:

> 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 move destroy_workqueue() to destructor where rtnl_lock is not held any more,
> suggested by Eric.

The error handling on creating a bond device needs to be updated as well.

Eric


> Signed-off-by: WANG Cong <amwang@redhat.com>
> Cc: Jay Vosburgh <fubar@us.ibm.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Stephen Hemminger <shemminger@vyatta.com>
> Cc: Jiri Pirko <jpirko@redhat.com>
> Cc: "Eric W. Biederman" <ebiederm@xmission.com>
>
> ---
>
> diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
> index 5b92fbf..9f0aaa2 100644
> --- a/drivers/net/bonding/bond_main.c
> +++ b/drivers/net/bonding/bond_main.c
> @@ -4450,6 +4450,14 @@ static const struct net_device_ops bond_netdev_ops = {
>  	.ndo_vlan_rx_kill_vid	= bond_vlan_rx_kill_vid,
>  };
>  
> +static void bond_destructor(struct net_device *bond_dev)
> +{
> +	struct bonding *bond = netdev_priv(bond_dev);
> +	if (bond->wq)
> +		destroy_workqueue(bond->wq);
> +	free_netdev(bond_dev);
> +}
> +
>  static void bond_setup(struct net_device *bond_dev)
>  {
>  	struct bonding *bond = netdev_priv(bond_dev);
> @@ -4470,7 +4478,7 @@ static void bond_setup(struct net_device *bond_dev)
>  	bond_dev->ethtool_ops = &bond_ethtool_ops;
>  	bond_set_mode_ops(bond, bond->params.mode);
>  
> -	bond_dev->destructor = free_netdev;
> +	bond_dev->destructor = bond_destructor;
>  
>  	/* Initialize the device options */
>  	bond_dev->tx_queue_len = 0;
> @@ -4542,9 +4550,6 @@ static void bond_uninit(struct net_device *bond_dev)
>  
>  	bond_remove_proc_entry(bond);
>  
> -	if (bond->wq)
> -		destroy_workqueue(bond->wq);
> -
>  	netif_addr_lock_bh(bond_dev);
>  	bond_mc_list_destroy(bond);
>  	netif_addr_unlock_bh(bond_dev);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch V2] bonding: fix potential deadlock in bond_uninit()
  2010-04-01  6:12 ` Eric W. Biederman
@ 2010-04-01  6:54   ` Cong Wang
  2010-04-01  7:30   ` [Patch V3] " Cong Wang
  1 sibling, 0 replies; 5+ messages in thread
From: Cong Wang @ 2010-04-01  6:54 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: linux-kernel, Jiri Pirko, Stephen Hemminger, netdev,
	David S. Miller, bonding-devel, Jay Vosburgh

Eric W. Biederman wrote:
> Amerigo Wang <amwang@redhat.com> writes:
> 
>> 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 move destroy_workqueue() to destructor where rtnl_lock is not held any more,
>> suggested by Eric.
> 
> The error handling on creating a bond device needs to be updated as well.
> 

You're right, I missed that part. Will update it soon.

Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Patch V3] bonding: fix potential deadlock in bond_uninit()
  2010-04-01  6:12 ` Eric W. Biederman
  2010-04-01  6:54   ` Cong Wang
@ 2010-04-01  7:30   ` Cong Wang
  2010-04-02  0:26     ` David Miller
  1 sibling, 1 reply; 5+ messages in thread
From: Cong Wang @ 2010-04-01  7:30 UTC (permalink / raw)
  To: Eric W. Biederman
  Cc: linux-kernel, Jiri Pirko, Stephen Hemminger, netdev,
	David S. Miller, bonding-devel, Jay Vosburgh

[-- Attachment #1: Type: text/plain, Size: 482 bytes --]

Eric W. Biederman wrote:
> Amerigo Wang <amwang@redhat.com> writes:
> 
>> 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 move destroy_workqueue() to destructor where rtnl_lock is not held any more,
>> suggested by Eric.
> 
> The error handling on creating a bond device needs to be updated as well.
> 

Done.


[-- Attachment #2: drivers-net-bonding-bond_main_c-fix-destroy_workqueue-deadlock.diff --]
[-- Type: text/x-patch, Size: 2517 bytes --]

V3: fix error handling path of bond_create()

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 move destroy_workqueue() to destructor where rtnl_lock is not held any more,
suggested by Eric.

Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Jay Vosburgh <fubar@us.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Stephen Hemminger <shemminger@vyatta.com>
Cc: Jiri Pirko <jpirko@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>

---

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 5b92fbf..61f8c63 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -4450,6 +4450,14 @@ static const struct net_device_ops bond_netdev_ops = {
 	.ndo_vlan_rx_kill_vid	= bond_vlan_rx_kill_vid,
 };
 
+static void bond_destructor(struct net_device *bond_dev)
+{
+	struct bonding *bond = netdev_priv(bond_dev);
+	if (bond->wq)
+		destroy_workqueue(bond->wq);
+	free_netdev(bond_dev);
+}
+
 static void bond_setup(struct net_device *bond_dev)
 {
 	struct bonding *bond = netdev_priv(bond_dev);
@@ -4470,7 +4478,7 @@ static void bond_setup(struct net_device *bond_dev)
 	bond_dev->ethtool_ops = &bond_ethtool_ops;
 	bond_set_mode_ops(bond, bond->params.mode);
 
-	bond_dev->destructor = free_netdev;
+	bond_dev->destructor = bond_destructor;
 
 	/* Initialize the device options */
 	bond_dev->tx_queue_len = 0;
@@ -4542,9 +4550,6 @@ static void bond_uninit(struct net_device *bond_dev)
 
 	bond_remove_proc_entry(bond);
 
-	if (bond->wq)
-		destroy_workqueue(bond->wq);
-
 	netif_addr_lock_bh(bond_dev);
 	bond_mc_list_destroy(bond);
 	netif_addr_unlock_bh(bond_dev);
@@ -4956,8 +4961,8 @@ int bond_create(struct net *net, const char *name)
 				bond_setup);
 	if (!bond_dev) {
 		pr_err("%s: eek! can't alloc netdev!\n", name);
-		res = -ENOMEM;
-		goto out;
+		rtnl_unlock();
+		return -ENOMEM;
 	}
 
 	dev_net_set(bond_dev, net);
@@ -4966,19 +4971,16 @@ int bond_create(struct net *net, const char *name)
 	if (!name) {
 		res = dev_alloc_name(bond_dev, "bond%d");
 		if (res < 0)
-			goto out_netdev;
+			goto out;
 	}
 
 	res = register_netdevice(bond_dev);
-	if (res < 0)
-		goto out_netdev;
 
 out:
 	rtnl_unlock();
+	if (res < 0)
+		bond_destructor(bond_dev);
 	return res;
-out_netdev:
-	free_netdev(bond_dev);
-	goto out;
 }
 
 static int __net_init bond_net_init(struct net *net)

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch V3] bonding: fix potential deadlock in bond_uninit()
  2010-04-01  7:30   ` [Patch V3] " Cong Wang
@ 2010-04-02  0:26     ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2010-04-02  0:26 UTC (permalink / raw)
  To: amwang
  Cc: ebiederm, linux-kernel, jpirko, shemminger, netdev, bonding-devel,
	fubar

From: Cong Wang <amwang@redhat.com>
Date: Thu, 01 Apr 2010 15:30:52 +0800

> Eric W. Biederman wrote:
>> Amerigo Wang <amwang@redhat.com> writes:
>> 
>>> 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 move destroy_workqueue() to destructor where rtnl_lock is not held
>>> any more,
>>> suggested by Eric.
>> The error handling on creating a bond device needs to be updated as
>> well.
>> 
> 
> Done.

Applied, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-04-02  0:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-01  6:06 [Patch V2] bonding: fix potential deadlock in bond_uninit() Amerigo Wang
2010-04-01  6:12 ` Eric W. Biederman
2010-04-01  6:54   ` Cong Wang
2010-04-01  7:30   ` [Patch V3] " Cong Wang
2010-04-02  0:26     ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).