Commit 5d52dad27a08d2c8851acb12b041088ec07881dd

Authored by Sven Eckelmann
Committed by Antonio Quartulli
1 parent d2b6cc8e46

batman-adv: Initialize lockdep class keys for hashes

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>

Showing 3 changed files with 26 additions and 0 deletions Side-by-side Diff

net/batman-adv/bridge_loop_avoidance.c
... ... @@ -1127,6 +1127,14 @@
1127 1127 bla_start_timer(bat_priv);
1128 1128 }
1129 1129  
  1130 +/* The hash for claim and backbone hash receive the same key because they
  1131 + * are getting initialized by hash_new with the same key. Reinitializing
  1132 + * them with to different keys to allow nested locking without generating
  1133 + * lockdep warnings
  1134 + */
  1135 +static struct lock_class_key claim_hash_lock_class_key;
  1136 +static struct lock_class_key backbone_hash_lock_class_key;
  1137 +
1130 1138 /* initialize all bla structures */
1131 1139 int bla_init(struct bat_priv *bat_priv)
1132 1140 {
... ... @@ -1163,6 +1171,11 @@
1163 1171  
1164 1172 if (!bat_priv->claim_hash || !bat_priv->backbone_hash)
1165 1173 return -1;
  1174 +
  1175 + batadv_hash_set_lock_class(bat_priv->claim_hash,
  1176 + &claim_hash_lock_class_key);
  1177 + batadv_hash_set_lock_class(bat_priv->backbone_hash,
  1178 + &backbone_hash_lock_class_key);
1166 1179  
1167 1180 bat_dbg(DBG_BLA, bat_priv, "bla hashes initialized\n");
1168 1181  
net/batman-adv/hash.c
... ... @@ -69,4 +69,13 @@
69 69 kfree(hash);
70 70 return NULL;
71 71 }
  72 +
  73 +void batadv_hash_set_lock_class(struct hashtable_t *hash,
  74 + struct lock_class_key *key)
  75 +{
  76 + uint32_t i;
  77 +
  78 + for (i = 0; i < hash->size; i++)
  79 + lockdep_set_class(&hash->list_locks[i], key);
  80 +}
net/batman-adv/hash.h
... ... @@ -45,6 +45,10 @@
45 45 /* allocates and clears the hash */
46 46 struct hashtable_t *hash_new(uint32_t size);
47 47  
  48 +/* set class key for all locks */
  49 +void batadv_hash_set_lock_class(struct hashtable_t *hash,
  50 + struct lock_class_key *key);
  51 +
48 52 /* free only the hashtable and the hash itself. */
49 53 void hash_destroy(struct hashtable_t *hash);
50 54