All of lore.kernel.org
 help / color / mirror / Atom feed
From: Antonio Quartulli <ordex@autistici.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
	Sven Eckelmann <sven@narfation.org>,
	Antonio Quartulli <ordex@autistici.org>
Subject: [PATCH 03/19] batman-adv: Initialize lockdep class keys for hashes
Date: Mon, 18 Jun 2012 22:39:07 +0200	[thread overview]
Message-ID: <1340051963-14836-4-git-send-email-ordex@autistici.org> (raw)
In-Reply-To: <1340051963-14836-1-git-send-email-ordex@autistici.org>

From: Sven Eckelmann <sven@narfation.org>

The hash for claim and backbone hash in the bridge loop avoidance code receive
the same key because they are getting initialized by hash_new with the same
key. Lockdep will create a backtrace when they are used recursively. This can
be avoided by reinitializing the key directly after the hash_new.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
 net/batman-adv/bridge_loop_avoidance.c |   13 +++++++++++++
 net/batman-adv/hash.c                  |    9 +++++++++
 net/batman-adv/hash.h                  |    4 ++++
 3 files changed, 26 insertions(+)

diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index 8bf9751..5c1ac55 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -1127,6 +1127,14 @@ out:
 	bla_start_timer(bat_priv);
 }
 
+/* The hash for claim and backbone hash receive the same key because they
+ * are getting initialized by hash_new with the same key. Reinitializing
+ * them with to different keys to allow nested locking without generating
+ * lockdep warnings
+ */
+static struct lock_class_key claim_hash_lock_class_key;
+static struct lock_class_key backbone_hash_lock_class_key;
+
 /* initialize all bla structures */
 int bla_init(struct bat_priv *bat_priv)
 {
@@ -1164,6 +1172,11 @@ int bla_init(struct bat_priv *bat_priv)
 	if (!bat_priv->claim_hash || !bat_priv->backbone_hash)
 		return -1;
 
+	batadv_hash_set_lock_class(bat_priv->claim_hash,
+				   &claim_hash_lock_class_key);
+	batadv_hash_set_lock_class(bat_priv->backbone_hash,
+				   &backbone_hash_lock_class_key);
+
 	bat_dbg(DBG_BLA, bat_priv, "bla hashes initialized\n");
 
 	bla_start_timer(bat_priv);
diff --git a/net/batman-adv/hash.c b/net/batman-adv/hash.c
index 117687b..5b2eabe 100644
--- a/net/batman-adv/hash.c
+++ b/net/batman-adv/hash.c
@@ -69,3 +69,12 @@ free_hash:
 	kfree(hash);
 	return NULL;
 }
+
+void batadv_hash_set_lock_class(struct hashtable_t *hash,
+				struct lock_class_key *key)
+{
+	uint32_t i;
+
+	for (i = 0; i < hash->size; i++)
+		lockdep_set_class(&hash->list_locks[i], key);
+}
diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h
index d4bd786..93b3c71 100644
--- a/net/batman-adv/hash.h
+++ b/net/batman-adv/hash.h
@@ -45,6 +45,10 @@ struct hashtable_t {
 /* allocates and clears the hash */
 struct hashtable_t *hash_new(uint32_t size);
 
+/* set class key for all locks */
+void batadv_hash_set_lock_class(struct hashtable_t *hash,
+				struct lock_class_key *key);
+
 /* free only the hashtable and the hash itself. */
 void hash_destroy(struct hashtable_t *hash);
 
-- 
1.7.9.4

WARNING: multiple messages have this Message-ID (diff)
From: Antonio Quartulli <ordex@autistici.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 03/19] batman-adv: Initialize lockdep class keys for hashes
Date: Mon, 18 Jun 2012 22:39:07 +0200	[thread overview]
Message-ID: <1340051963-14836-4-git-send-email-ordex@autistici.org> (raw)
In-Reply-To: <1340051963-14836-1-git-send-email-ordex@autistici.org>

From: Sven Eckelmann <sven@narfation.org>

The hash for claim and backbone hash in the bridge loop avoidance code receive
the same key because they are getting initialized by hash_new with the same
key. Lockdep will create a backtrace when they are used recursively. This can
be avoided by reinitializing the key directly after the hash_new.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
 net/batman-adv/bridge_loop_avoidance.c |   13 +++++++++++++
 net/batman-adv/hash.c                  |    9 +++++++++
 net/batman-adv/hash.h                  |    4 ++++
 3 files changed, 26 insertions(+)

diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index 8bf9751..5c1ac55 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -1127,6 +1127,14 @@ out:
 	bla_start_timer(bat_priv);
 }
 
+/* The hash for claim and backbone hash receive the same key because they
+ * are getting initialized by hash_new with the same key. Reinitializing
+ * them with to different keys to allow nested locking without generating
+ * lockdep warnings
+ */
+static struct lock_class_key claim_hash_lock_class_key;
+static struct lock_class_key backbone_hash_lock_class_key;
+
 /* initialize all bla structures */
 int bla_init(struct bat_priv *bat_priv)
 {
@@ -1164,6 +1172,11 @@ int bla_init(struct bat_priv *bat_priv)
 	if (!bat_priv->claim_hash || !bat_priv->backbone_hash)
 		return -1;
 
+	batadv_hash_set_lock_class(bat_priv->claim_hash,
+				   &claim_hash_lock_class_key);
+	batadv_hash_set_lock_class(bat_priv->backbone_hash,
+				   &backbone_hash_lock_class_key);
+
 	bat_dbg(DBG_BLA, bat_priv, "bla hashes initialized\n");
 
 	bla_start_timer(bat_priv);
diff --git a/net/batman-adv/hash.c b/net/batman-adv/hash.c
index 117687b..5b2eabe 100644
--- a/net/batman-adv/hash.c
+++ b/net/batman-adv/hash.c
@@ -69,3 +69,12 @@ free_hash:
 	kfree(hash);
 	return NULL;
 }
+
+void batadv_hash_set_lock_class(struct hashtable_t *hash,
+				struct lock_class_key *key)
+{
+	uint32_t i;
+
+	for (i = 0; i < hash->size; i++)
+		lockdep_set_class(&hash->list_locks[i], key);
+}
diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h
index d4bd786..93b3c71 100644
--- a/net/batman-adv/hash.h
+++ b/net/batman-adv/hash.h
@@ -45,6 +45,10 @@ struct hashtable_t {
 /* allocates and clears the hash */
 struct hashtable_t *hash_new(uint32_t size);
 
+/* set class key for all locks */
+void batadv_hash_set_lock_class(struct hashtable_t *hash,
+				struct lock_class_key *key);
+
 /* free only the hashtable and the hash itself. */
 void hash_destroy(struct hashtable_t *hash);
 
-- 
1.7.9.4


  parent reply	other threads:[~2012-06-18 20:39 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-18 20:39 pull request: batman-adv 2012-06-18 Antonio Quartulli
2012-06-18 20:39 ` [B.A.T.M.A.N.] " Antonio Quartulli
     [not found] ` <1340051963-14836-1-git-send-email-ordex-GaUfNO9RBHfsrOwW+9ziJQ@public.gmane.org>
2012-06-18 20:39   ` [PATCH 01/19] batman-adv: update internal version number Antonio Quartulli
2012-06-18 20:39     ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39   ` [PATCH 02/19] batman-adv: fix skb->data assignment Antonio Quartulli
2012-06-18 20:39     ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39   ` [PATCH 04/19] batman-adv: convert bat_priv->tt_crc from atomic_t to uint16_t Antonio Quartulli
2012-06-18 20:39     ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` Antonio Quartulli [this message]
2012-06-18 20:39   ` [B.A.T.M.A.N.] [PATCH 03/19] batman-adv: Initialize lockdep class keys for hashes Antonio Quartulli
2012-06-18 20:39 ` [PATCH 05/19] batman-adv: Add get_ethtool_stats() support Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 06/19] batman-adv: avoid characters requiring shell escapes in protocol names Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 07/19] batman-adv: ignore trailing CR when comparing " Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 08/19] batman-adv: return added entries instead of number of possibly added entries Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 09/19] batman-adv: get rid of pointless cast in memcpy() Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 10/19] batman-adv: trivial endianness annotations Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 11/19] batman-adv: keep batman_ogm_packet ->seqno net-endian all along Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 12/19] batman-adv: Return error codes instead of -1 on failures Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 13/19] batman-adv: don't bother flipping ->tt_data Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 14/19] batman-adv: don't bother flipping ->tt_crc Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 15/19] batman-adv: fix visualization output without neighbors on the primary interface Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 16/19] batman-adv: turn tt commit code into routing protocol agnostic API Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 17/19] batman-adv: use DBG_ALL in log_level sysfs definition Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 18/19] batman-adv: fix locking in hash_add() Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-18 20:39 ` [PATCH 19/19] batman-adv: only store changed gw_bandwidth values Antonio Quartulli
2012-06-18 20:39   ` [B.A.T.M.A.N.] " Antonio Quartulli
2012-06-19  3:28 ` pull request: batman-adv 2012-06-18 David Miller
2012-06-19  3:28   ` [B.A.T.M.A.N.] " David Miller

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=1340051963-14836-4-git-send-email-ordex@autistici.org \
    --to=ordex@autistici.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=sven@narfation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.