b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven.eckelmann@gmx.de>
To: greg@kroah.com
Cc: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 05/12] Staging: batman-adv: Introduce if_list_lock to protect if_list
Date: Sat, 18 Sep 2010 21:01:15 +0200	[thread overview]
Message-ID: <1284836482-23431-6-git-send-email-sven.eckelmann@gmx.de> (raw)
In-Reply-To: <1284836482-23431-1-git-send-email-sven.eckelmann@gmx.de>

The update critical sections of if_list must be protected by a locking
primitive other than RCU. The iterator must also be protected by the
chosen locking mechanism.

The rtnl_lock in hardif_remove_interfaces must also be moved outside the
iterator primitive to ensure that we don't deadlock the kernel due to
differently nested locks in hardif_remove_interfaces and hard_if_event.

Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
---
 drivers/staging/batman-adv/hard-interface.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/batman-adv/hard-interface.c b/drivers/staging/batman-adv/hard-interface.c
index a587da9..35b198c 100644
--- a/drivers/staging/batman-adv/hard-interface.c
+++ b/drivers/staging/batman-adv/hard-interface.c
@@ -33,6 +33,9 @@
 
 #define MIN(x, y) ((x) < (y) ? (x) : (y))
 
+/* protect update critical side of if_list - but not the content */
+static DEFINE_SPINLOCK(if_list_lock);
+
 struct batman_if *get_batman_if_by_netdev(struct net_device *net_dev)
 {
 	struct batman_if *batman_if;
@@ -400,7 +403,11 @@ static struct batman_if *hardif_add_interface(struct net_device *net_dev)
 	INIT_LIST_HEAD(&batman_if->list);
 
 	check_known_mac_addr(batman_if->net_dev->dev_addr);
+
+	spin_lock(&if_list_lock);
 	list_add_tail_rcu(&batman_if->list, &if_list);
+	spin_unlock(&if_list_lock);
+
 	return batman_if;
 
 free_if:
@@ -428,6 +435,8 @@ static void hardif_remove_interface(struct batman_if *batman_if)
 		return;
 
 	batman_if->if_status = IF_TO_BE_REMOVED;
+
+	/* caller must take if_list_lock */
 	list_del_rcu(&batman_if->list);
 	sysfs_del_hardif(&batman_if->hardif_obj);
 	dev_put(batman_if->net_dev);
@@ -438,11 +447,13 @@ void hardif_remove_interfaces(void)
 {
 	struct batman_if *batman_if, *batman_if_tmp;
 
+	rtnl_lock();
+	spin_lock(&if_list_lock);
 	list_for_each_entry_safe(batman_if, batman_if_tmp, &if_list, list) {
-		rtnl_lock();
 		hardif_remove_interface(batman_if);
-		rtnl_unlock();
 	}
+	spin_unlock(&if_list_lock);
+	rtnl_unlock();
 }
 
 static int hard_if_event(struct notifier_block *this,
@@ -467,7 +478,9 @@ static int hard_if_event(struct notifier_block *this,
 		hardif_deactivate_interface(batman_if);
 		break;
 	case NETDEV_UNREGISTER:
+		spin_lock(&if_list_lock);
 		hardif_remove_interface(batman_if);
+		spin_unlock(&if_list_lock);
 		break;
 	case NETDEV_CHANGEMTU:
 		if (batman_if->soft_iface)
-- 
1.7.2.3


  parent reply	other threads:[~2010-09-18 19:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-18 19:01 [B.A.T.M.A.N.] Staging: batman-adv for 2.6.37 (3) Sven Eckelmann
2010-09-18 19:01 ` [B.A.T.M.A.N.] [PATCH 01/12] Staging: batman-adv: checkpatch cleanup of comments Sven Eckelmann
2010-09-18 19:01 ` [B.A.T.M.A.N.] [PATCH 02/12] Staging: batman-adv: Move mailing list address to .org Sven Eckelmann
2010-09-18 19:01 ` [B.A.T.M.A.N.] [PATCH 03/12] Staging: batman-adv: Mark debugfs files as nonseekable Sven Eckelmann
2010-09-18 19:01 ` [B.A.T.M.A.N.] [PATCH 04/12] Staging: batman-adv: wait for call_rcu before unloading module Sven Eckelmann
2010-09-18 19:01 ` Sven Eckelmann [this message]
2010-09-18 19:01 ` [B.A.T.M.A.N.] [PATCH 06/12] Staging: batman-adv: Always protect list_for_each_entry_rcu with RCU Sven Eckelmann
2010-09-18 19:01 ` [B.A.T.M.A.N.] [PATCH 07/12] Staging: batman-adv: Remove unneeded rcu_read_lock Sven Eckelmann
2010-09-18 19:01 ` [B.A.T.M.A.N.] [PATCH 08/12] Staging: batman-adv: Use synchronize_rcu instead of call_rcu Sven Eckelmann
2010-09-18 19:01 ` [B.A.T.M.A.N.] [PATCH 09/12] Staging: batman-adv: Use refcnt to track usage count of batman_if Sven Eckelmann
2010-09-18 19:01 ` [B.A.T.M.A.N.] [PATCH 10/12] Staging: batman-adv: count batman_if list queries as reference Sven Eckelmann
2010-09-18 19:01 ` [B.A.T.M.A.N.] [PATCH 11/12] Staging: batman-adv: Track references of batman_if in set_primary_if Sven Eckelmann
2010-09-18 19:01 ` [B.A.T.M.A.N.] [PATCH 12/12] Staging: batman-adv: Introduce update_primary_addr to update mac address Sven Eckelmann

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=1284836482-23431-6-git-send-email-sven.eckelmann@gmx.de \
    --to=sven.eckelmann@gmx.de \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=greg@kroah.com \
    /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).