Skip to content

Commit

Permalink
rhashtable: Do not schedule more than one rehash if we can't grow fur…
Browse files Browse the repository at this point in the history
…ther

The current code currently only stops inserting rehashes into the
chain when no resizes are currently scheduled. As long as resizes
are scheduled and while inserting above the utilization watermark,
more and more rehashes will be scheduled.

This lead to a perfect DoS storm with thousands of rehashes
scheduled which lead to thousands of spinlocks to be taken
sequentially.

Instead, only allow either a series of resizes or a single rehash.
Drop any further rehashes and return -EBUSY.

Fixes: ccd57b1 ("rhashtable: Add immediate rehash during insertion")
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Thomas Graf authored and David S. Miller committed Apr 22, 2015
1 parent e2307ed commit a87b9eb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rhashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ int rhashtable_insert_rehash(struct rhashtable *ht)

if (rht_grow_above_75(ht, tbl))
size *= 2;
/* More than two rehashes (not resizes) detected. */
else if (WARN_ON(old_tbl != tbl && old_tbl->size == size))
/* Do not schedule more than one rehash */
else if (old_tbl != tbl)
return -EBUSY;

new_tbl = bucket_table_alloc(ht, size, GFP_ATOMIC);
Expand Down

0 comments on commit a87b9eb

Please sign in to comment.