mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 04:33:26 +02:00
rhashtable: Allow rhashtable to be used from irq-safe contexts
rhashtable currently only does bh-safe synchronization making it impossible to use from irq-safe contexts. Switch it to use irq-safe synchronization to remove the restriction. v2: Update the lock functions to return the ulong flags value and unlock functions to take the value directly instead of passing around the pointer. Suggested by Linus. Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: David Vernet <dvernet@meta.com> Acked-by: Josh Don <joshdon@google.com> Acked-by: Hao Luo <haoluo@google.com> Acked-by: Barret Rhoden <brho@google.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
b602d00384
commit
e47877c7aa
@@ -231,6 +231,7 @@ static int rhashtable_rehash_one(struct rhashtable *ht,
|
||||
struct rhash_head *head, *next, *entry;
|
||||
struct rhash_head __rcu **pprev = NULL;
|
||||
unsigned int new_hash;
|
||||
unsigned long flags;
|
||||
|
||||
if (new_tbl->nest)
|
||||
goto out;
|
||||
@@ -253,13 +254,14 @@ static int rhashtable_rehash_one(struct rhashtable *ht,
|
||||
|
||||
new_hash = head_hashfn(ht, new_tbl, entry);
|
||||
|
||||
rht_lock_nested(new_tbl, &new_tbl->buckets[new_hash], SINGLE_DEPTH_NESTING);
|
||||
flags = rht_lock_nested(new_tbl, &new_tbl->buckets[new_hash],
|
||||
SINGLE_DEPTH_NESTING);
|
||||
|
||||
head = rht_ptr(new_tbl->buckets + new_hash, new_tbl, new_hash);
|
||||
|
||||
RCU_INIT_POINTER(entry->next, head);
|
||||
|
||||
rht_assign_unlock(new_tbl, &new_tbl->buckets[new_hash], entry);
|
||||
rht_assign_unlock(new_tbl, &new_tbl->buckets[new_hash], entry, flags);
|
||||
|
||||
if (pprev)
|
||||
rcu_assign_pointer(*pprev, next);
|
||||
@@ -276,18 +278,19 @@ static int rhashtable_rehash_chain(struct rhashtable *ht,
|
||||
{
|
||||
struct bucket_table *old_tbl = rht_dereference(ht->tbl, ht);
|
||||
struct rhash_lock_head __rcu **bkt = rht_bucket_var(old_tbl, old_hash);
|
||||
unsigned long flags;
|
||||
int err;
|
||||
|
||||
if (!bkt)
|
||||
return 0;
|
||||
rht_lock(old_tbl, bkt);
|
||||
flags = rht_lock(old_tbl, bkt);
|
||||
|
||||
while (!(err = rhashtable_rehash_one(ht, bkt, old_hash)))
|
||||
;
|
||||
|
||||
if (err == -ENOENT)
|
||||
err = 0;
|
||||
rht_unlock(old_tbl, bkt);
|
||||
rht_unlock(old_tbl, bkt, flags);
|
||||
|
||||
return err;
|
||||
}
|
||||
@@ -590,6 +593,7 @@ static void *rhashtable_try_insert(struct rhashtable *ht, const void *key,
|
||||
struct bucket_table *new_tbl;
|
||||
struct bucket_table *tbl;
|
||||
struct rhash_lock_head __rcu **bkt;
|
||||
unsigned long flags;
|
||||
unsigned int hash;
|
||||
void *data;
|
||||
|
||||
@@ -607,7 +611,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(tbl, bkt);
|
||||
flags = rht_lock(tbl, bkt);
|
||||
data = rhashtable_lookup_one(ht, bkt, tbl,
|
||||
hash, key, obj);
|
||||
new_tbl = rhashtable_insert_one(ht, bkt, tbl,
|
||||
@@ -615,7 +619,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(tbl, bkt);
|
||||
rht_unlock(tbl, bkt, flags);
|
||||
}
|
||||
} while (!IS_ERR_OR_NULL(new_tbl));
|
||||
|
||||
|
Reference in New Issue
Block a user