Skip to content

Commit

Permalink
hash: add local variable
Browse files Browse the repository at this point in the history
The current implmentation of the hash table is not thread-safe.
This design leads to a segfault when VPP handling a lot of tunnels for
Wireguard, where one thread modify the hash table and other threads
starting to lookup at the same time.

The fix add a local variable to store how many bits are used by a user
object.

Type: fix
Signed-off-by: Gabriel Oginski <[email protected]>
Change-Id: Iecf6b3ef9f308b61015c66277cc459a6d019c9c1
  • Loading branch information
goginskx authored and Fan Zhang committed Oct 25, 2022
1 parent c9d916c commit 813c1bd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/vppinfra/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ always_inline uword
hash_is_user (void *v, uword i)
{
hash_t *h = hash_header (v);
uword i0 = i / BITS (h->is_user[0]);
uword i1 = i % BITS (h->is_user[0]);
uword bits = BITS (h->is_user[0]);
uword i0 = i / bits;
uword i1 = i % bits;
return (h->is_user[i0] & ((uword) 1 << i1)) != 0;
}

Expand Down

0 comments on commit 813c1bd

Please sign in to comment.