summaryrefslogtreecommitdiff
path: root/include/linux/rhashtable.h
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.com>2019-04-02 10:07:45 +1100
committerDavid S. Miller <davem@davemloft.net>2019-04-07 19:12:12 -0700
commit149212f07856b25a9d342bfd6d736519b2ef66dc (patch)
treeb2fc4e6c9902041bcdb4c8bfc44d2d5d3040088c /include/linux/rhashtable.h
parent8f0db018006a421956965e1149234c4e8db718ee (diff)
rhashtable: add lockdep tracking to bucket bit-spin-locks.
Native bit_spin_locks are not tracked by lockdep. The bit_spin_locks used for rhashtable buckets are local to the rhashtable implementation, so there is little opportunity for the sort of misuse that lockdep might detect. However locks are held while a hash function or compare function is called, and if one of these took a lock, a misbehaviour is possible. As it is quite easy to add lockdep support this unlikely possibility seems to be enough justification. So create a lockdep class for bucket bit_spin_lock and attach through a lockdep_map in each bucket_table. Without the 'nested' annotation in rhashtable_rehash_one(), lockdep correctly reports a possible problem as this lock is taken while another bucket lock (in another table) is held. This confirms that the added support works. With the correct nested annotation in place, lockdep reports no problems. Signed-off-by: NeilBrown <neilb@suse.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/rhashtable.h')
-rw-r--r--include/linux/rhashtable.h51
1 files changed, 34 insertions, 17 deletions
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index ccbbafdf5547..460c0eaf6b96 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -82,6 +82,8 @@ struct bucket_table {
struct bucket_table __rcu *future_tbl;
+ struct lockdep_map dep_map;
+
struct rhash_lock_head __rcu *buckets[] ____cacheline_aligned_in_smp;
};
@@ -102,23 +104,38 @@ struct bucket_table {
* this is safe.
*/
-static inline void rht_lock(struct rhash_lock_head **bkt)
+static inline void rht_lock(struct bucket_table *tbl,
+ struct rhash_lock_head **bkt)
{
local_bh_disable();
bit_spin_lock(1, (unsigned long *)bkt);
+ lock_map_acquire(&tbl->dep_map);
+}
+
+static inline void rht_lock_nested(struct bucket_table *tbl,
+ struct rhash_lock_head **bucket,
+ unsigned int subclass)
+{
+ local_bh_disable();
+ bit_spin_lock(1, (unsigned long *)bucket);
+ lock_acquire_exclusive(&tbl->dep_map, subclass, 0, NULL, _THIS_IP_);
}
-static inline void rht_unlock(struct rhash_lock_head **bkt)
+static inline void rht_unlock(struct bucket_table *tbl,
+ struct rhash_lock_head **bkt)
{
+ lock_map_release(&tbl->dep_map);
bit_spin_unlock(1, (unsigned long *)bkt);
local_bh_enable();
}
-static inline void rht_assign_unlock(struct rhash_lock_head **bkt,
+static inline void rht_assign_unlock(struct bucket_table *tbl,
+ struct rhash_lock_head **bkt,
struct rhash_head *obj)
{
struct rhash_head **p = (struct rhash_head **)bkt;
+ lock_map_release(&tbl->dep_map);
rcu_assign_pointer(*p, obj);
preempt_enable();
__release(bitlock);
@@ -672,11 +689,11 @@ static inline void *__rhashtable_insert_fast(
if (!bkt)
goto out;
pprev = NULL;
- rht_lock(bkt);
+ rht_lock(tbl, bkt);
if (unlikely(rcu_access_pointer(tbl->future_tbl))) {
slow_path:
- rht_unlock(bkt);
+ rht_unlock(tbl, bkt);
rcu_read_unlock();
return rhashtable_insert_slow(ht, key, obj);
}
@@ -708,9 +725,9 @@ slow_path:
RCU_INIT_POINTER(list->rhead.next, head);
if (pprev) {
rcu_assign_pointer(*pprev, obj);
- rht_unlock(bkt);
+ rht_unlock(tbl, bkt);
} else
- rht_assign_unlock(bkt, obj);
+ rht_assign_unlock(tbl, bkt, obj);
data = NULL;
goto out;
}
@@ -737,7 +754,7 @@ slow_path:
}
atomic_inc(&ht->nelems);
- rht_assign_unlock(bkt, obj);
+ rht_assign_unlock(tbl, bkt, obj);
if (rht_grow_above_75(ht, tbl))
schedule_work(&ht->run_work);
@@ -749,7 +766,7 @@ out:
return data;
out_unlock:
- rht_unlock(bkt);
+ rht_unlock(tbl, bkt);
goto out;
}
@@ -951,7 +968,7 @@ static inline int __rhashtable_remove_fast_one(
if (!bkt)
return -ENOENT;
pprev = NULL;
- rht_lock(bkt);
+ rht_lock(tbl, bkt);
rht_for_each_from(he, rht_ptr(*bkt), tbl, hash) {
struct rhlist_head *list;
@@ -995,14 +1012,14 @@ static inline int __rhashtable_remove_fast_one(
if (pprev) {
rcu_assign_pointer(*pprev, obj);
- rht_unlock(bkt);
+ rht_unlock(tbl, bkt);
} else {
- rht_assign_unlock(bkt, obj);
+ rht_assign_unlock(tbl, bkt, obj);
}
goto unlocked;
}
- rht_unlock(bkt);
+ rht_unlock(tbl, bkt);
unlocked:
if (err > 0) {
atomic_dec(&ht->nelems);
@@ -1110,7 +1127,7 @@ static inline int __rhashtable_replace_fast(
return -ENOENT;
pprev = NULL;
- rht_lock(bkt);
+ rht_lock(tbl, bkt);
rht_for_each_from(he, rht_ptr(*bkt), tbl, hash) {
if (he != obj_old) {
@@ -1121,15 +1138,15 @@ static inline int __rhashtable_replace_fast(
rcu_assign_pointer(obj_new->next, obj_old->next);
if (pprev) {
rcu_assign_pointer(*pprev, obj_new);
- rht_unlock(bkt);
+ rht_unlock(tbl, bkt);
} else {
- rht_assign_unlock(bkt, obj_new);
+ rht_assign_unlock(tbl, bkt, obj_new);
}
err = 0;
goto unlocked;
}
- rht_unlock(bkt);
+ rht_unlock(tbl, bkt);
unlocked:
return err;