From: Andrew Morton <akpm@linux-foundation.org>
To: Jay Vosburgh <fubar@us.ibm.com>
Cc: netdev@vger.kernel.org, jgarzik@pobox.com, davem@davemloft.net,
andy@greyhouse.net, fubar@us.ibm.com
Subject: Re: [PATCH 6/7] bonding: fix lock ordering for rtnl and bonding_rwsem
Date: Thu, 17 Jan 2008 16:38:01 -0800 [thread overview]
Message-ID: <20080117163801.77c62170.akpm@linux-foundation.org> (raw)
In-Reply-To: <12006159123054-git-send-email-fubar@us.ibm.com>
On Thu, 17 Jan 2008 16:25:02 -0800
Jay Vosburgh <fubar@us.ibm.com> wrote:
> Fix the handling of rtnl and the bonding_rwsem to always be acquired
> in a consistent order (rtnl, then bonding_rwsem).
>
> The existing code sometimes acquired them in this order, and sometimes
> in the opposite order, which opens a window for deadlock between ifenslave
> and sysfs.
>
> ...
>
> int bond_create(char *name, struct bond_params *params, struct bonding **newbond)
> {
> struct net_device *bond_dev;
> + struct bonding *bond, *nxt;
> int res;
>
> rtnl_lock();
> + down_write(&bonding_rwsem);
> +
> + /* Check to see if the bond already exists. */
> + list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list)
this could (should) use list_for_each_entry().
> + if (strnicmp(bond->dev->name, name, IFNAMSIZ) == 0) {
> + printk(KERN_ERR DRV_NAME
> + ": cannot add bond %s; it already exists\n",
> + name);
> + res = -EPERM;
> + goto out_rtnl;
> + }
> +
> bond_dev = alloc_netdev(sizeof(struct bonding), name ? name : "",
> ether_setup);
> if (!bond_dev) {
> @@ -4915,10 +4928,12 @@ int bond_create(char *name, struct bond_params *params, struct bonding **newbond
>
> netif_carrier_off(bond_dev);
>
> + up_write(&bonding_rwsem);
> rtnl_unlock(); /* allows sysfs registration of net device */
> res = bond_create_sysfs_entry(bond_dev->priv);
> if (res < 0) {
> rtnl_lock();
> + down_write(&bonding_rwsem);
> goto out_bond;
> }
>
> @@ -4929,6 +4944,7 @@ out_bond:
> out_netdev:
> free_netdev(bond_dev);
> out_rtnl:
> + up_write(&bonding_rwsem);
> rtnl_unlock();
> return res;
> }
> @@ -4949,6 +4965,9 @@ static int __init bonding_init(void)
> #ifdef CONFIG_PROC_FS
> bond_create_proc_dir();
> #endif
> +
> + init_rwsem(&bonding_rwsem);
It would be better to initialise this at compile time with DECLARE_RWSEM().
But neither of those things need to be done for 2.6.24.
next prev parent reply other threads:[~2008-01-18 0:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-18 0:24 [PATCH 0/7] bonding: 7 fixes for 2.6.24 Jay Vosburgh
2008-01-18 0:24 ` [PATCH 1/7] bonding: fix locking in sysfs primary/active selection Jay Vosburgh
2008-01-18 0:24 ` [PATCH 2/7] bonding: fix ASSERT_RTNL that produces spurious warnings Jay Vosburgh
2008-01-18 0:24 ` [PATCH 3/7] bonding: fix locking during alb failover and slave removal Jay Vosburgh
2008-01-18 0:25 ` [PATCH 4/7] bonding: release slaves when master removed via sysfs Jay Vosburgh
2008-01-18 0:25 ` [PATCH 5/7] bonding: Fix up parameter parsing Jay Vosburgh
2008-01-18 0:25 ` [PATCH 6/7] bonding: fix lock ordering for rtnl and bonding_rwsem Jay Vosburgh
2008-01-18 0:25 ` [PATCH 7/7] bonding: Don't hold lock when calling rtnl_unlock Jay Vosburgh
2008-01-18 0:38 ` Andrew Morton [this message]
2008-01-18 19:39 ` [PATCH 1/7] bonding: fix locking in sysfs primary/active selection Jeff Garzik
2008-01-21 1:15 ` [PATCH 0/7] bonding: 7 fixes for 2.6.24 David Miller
2008-01-21 1:36 ` Andrew Morton
2008-01-21 3:58 ` David Miller
2008-01-21 1:57 ` Jeff Garzik
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080117163801.77c62170.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=andy@greyhouse.net \
--cc=davem@davemloft.net \
--cc=fubar@us.ibm.com \
--cc=jgarzik@pobox.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).