Skip to content

Commit

Permalink
rhashtable: Lower/upper bucket may map to same lock while shrinking
Browse files Browse the repository at this point in the history
Each per bucket lock covers a configurable number of buckets. While
shrinking, two buckets in the old table contain entries for a single
bucket in the new table. We need to lock down both while linking.
Check if they are protected by different locks to avoid a recursive
lock.

Fixes: 97defe1 ("rhashtable: Per bucket locks & deferred expansion/shrinking")
Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Thomas Graf authored and David S. Miller committed Jan 14, 2015
1 parent df8a39d commit 80ca8c3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/rhashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,16 +443,25 @@ int rhashtable_shrink(struct rhashtable *ht)
new_bucket_lock = bucket_lock(new_tbl, new_hash);

spin_lock_bh(old_bucket_lock1);
spin_lock_bh_nested(old_bucket_lock2, RHT_LOCK_NESTED);
spin_lock_bh_nested(new_bucket_lock, RHT_LOCK_NESTED2);

/* Depending on the lock per buckets mapping, the bucket in
* the lower and upper region may map to the same lock.
*/
if (old_bucket_lock1 != old_bucket_lock2) {
spin_lock_bh_nested(old_bucket_lock2, RHT_LOCK_NESTED);
spin_lock_bh_nested(new_bucket_lock, RHT_LOCK_NESTED2);
} else {
spin_lock_bh_nested(new_bucket_lock, RHT_LOCK_NESTED);
}

rcu_assign_pointer(*bucket_tail(new_tbl, new_hash),
tbl->buckets[new_hash]);
rcu_assign_pointer(*bucket_tail(new_tbl, new_hash),
tbl->buckets[new_hash + new_tbl->size]);

spin_unlock_bh(new_bucket_lock);
spin_unlock_bh(old_bucket_lock2);
if (old_bucket_lock1 != old_bucket_lock2)
spin_unlock_bh(old_bucket_lock2);
spin_unlock_bh(old_bucket_lock1);
}

Expand Down

0 comments on commit 80ca8c3

Please sign in to comment.