All of lore.kernel.org
 help / color / mirror / Atom feed
* rhashtable: Fix reader/rehash race
@ 2015-03-12 11:07 Herbert Xu
  2015-03-12 13:37 ` Thomas Graf
  2015-03-13  3:01 ` David Miller
  0 siblings, 2 replies; 9+ messages in thread
From: Herbert Xu @ 2015-03-12 11:07 UTC (permalink / raw)
  To: Thomas Graf, netdev

There is a potential race condition between readers and the rehasher.
In particular, the rehasher could have started a rehash while the
reader finishes a scan of the old table but fails to see the new
table pointer.

This patch closes this window by adding smp_wmb/smp_rmb.
    
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 6ffc793..68210cc 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -271,6 +271,9 @@ static void rhashtable_rehash(struct rhashtable *ht,
 	 */
 	rcu_assign_pointer(ht->future_tbl, new_tbl);
 
+	/* Ensure the new table is visible to readers. */
+	smp_wmb();
+
 	for (old_hash = 0; old_hash < old_tbl->size; old_hash++)
 		rhashtable_rehash_chain(ht, old_hash);
 
@@ -618,6 +621,9 @@ restart:
 		return rht_obj(ht, he);
 	}
 
+	/* Ensure we see any new tables. */
+	smp_rmb();
+
 	old_tbl = tbl;
 	tbl = rht_dereference_rcu(ht->future_tbl, ht);
 	if (unlikely(tbl != old_tbl))
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-03-13 10:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-12 11:07 rhashtable: Fix reader/rehash race Herbert Xu
2015-03-12 13:37 ` Thomas Graf
2015-03-12 16:33   ` [PATCH net-next] rhashtable: Fix race between rehashing and readers Thomas Graf
2015-03-12 21:50     ` Herbert Xu
2015-03-12 21:49   ` rhashtable: Fix reader/rehash race Herbert Xu
2015-03-13 10:32     ` Thomas Graf
2015-03-13 10:36       ` Herbert Xu
2015-03-13 10:54         ` Thomas Graf
2015-03-13  3:01 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.