mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-23 15:27:29 +00:00
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>
This commit is contained in:
parent
8f0db01800
commit
149212f078
2 changed files with 43 additions and 23 deletions
|
@ -173,6 +173,7 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht,
|
|||
struct bucket_table *tbl = NULL;
|
||||
size_t size;
|
||||
int i;
|
||||
static struct lock_class_key __key;
|
||||
|
||||
size = sizeof(*tbl) + nbuckets * sizeof(tbl->buckets[0]);
|
||||
tbl = kvzalloc(size, gfp);
|
||||
|
@ -187,6 +188,8 @@ static struct bucket_table *bucket_table_alloc(struct rhashtable *ht,
|
|||
if (tbl == NULL)
|
||||
return NULL;
|
||||
|
||||
lockdep_init_map(&tbl->dep_map, "rhashtable_bucket", &__key, 0);
|
||||
|
||||
tbl->size = size;
|
||||
|
||||
rcu_head_init(&tbl->rcu);
|
||||
|
@ -244,14 +247,14 @@ static int rhashtable_rehash_one(struct rhashtable *ht,
|
|||
|
||||
new_hash = head_hashfn(ht, new_tbl, entry);
|
||||
|
||||
rht_lock(&new_tbl->buckets[new_hash]);
|
||||
rht_lock_nested(new_tbl, &new_tbl->buckets[new_hash], SINGLE_DEPTH_NESTING);
|
||||
|
||||
head = rht_ptr(rht_dereference_bucket(new_tbl->buckets[new_hash],
|
||||
new_tbl, new_hash));
|
||||
|
||||
RCU_INIT_POINTER(entry->next, head);
|
||||
|
||||
rht_assign_unlock(&new_tbl->buckets[new_hash], entry);
|
||||
rht_assign_unlock(new_tbl, &new_tbl->buckets[new_hash], entry);
|
||||
|
||||
if (pprev)
|
||||
rcu_assign_pointer(*pprev, next);
|
||||
|
@ -272,14 +275,14 @@ static int rhashtable_rehash_chain(struct rhashtable *ht,
|
|||
|
||||
if (!bkt)
|
||||
return 0;
|
||||
rht_lock(bkt);
|
||||
rht_lock(old_tbl, bkt);
|
||||
|
||||
while (!(err = rhashtable_rehash_one(ht, bkt, old_hash)))
|
||||
;
|
||||
|
||||
if (err == -ENOENT)
|
||||
err = 0;
|
||||
rht_unlock(bkt);
|
||||
rht_unlock(old_tbl, bkt);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -600,7 +603,7 @@ static void *rhashtable_try_insert(struct rhashtable *ht, const void *key,
|
|||
new_tbl = rht_dereference_rcu(tbl->future_tbl, ht);
|
||||
data = ERR_PTR(-EAGAIN);
|
||||
} else {
|
||||
rht_lock(bkt);
|
||||
rht_lock(tbl, bkt);
|
||||
data = rhashtable_lookup_one(ht, bkt, tbl,
|
||||
hash, key, obj);
|
||||
new_tbl = rhashtable_insert_one(ht, bkt, tbl,
|
||||
|
@ -608,7 +611,7 @@ static void *rhashtable_try_insert(struct rhashtable *ht, const void *key,
|
|||
if (PTR_ERR(new_tbl) != -EEXIST)
|
||||
data = ERR_CAST(new_tbl);
|
||||
|
||||
rht_unlock(bkt);
|
||||
rht_unlock(tbl, bkt);
|
||||
}
|
||||
} while (!IS_ERR_OR_NULL(new_tbl));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue