rhashtable: use cmpxchg() to protect ->future_tbl.
authorNeilBrown <neilb@suse.com>
Mon, 18 Jun 2018 02:52:50 +0000 (12:52 +1000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 22 Jun 2018 04:43:27 +0000 (13:43 +0900)
Rather than borrowing one of the bucket locks to
protect ->future_tbl updates, use cmpxchg().
This gives more freedom to change how bucket locking
is implemented.

Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: NeilBrown <neilb@suse.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
lib/rhashtable.c

index 2aa41c15df17e9dd5b9e98304bb6f16dd8e328c7..52ec832128564d8a469c1b070b75f5da273b0aa1 100644 (file)
@@ -297,21 +297,14 @@ static int rhashtable_rehash_attach(struct rhashtable *ht,
                                    struct bucket_table *old_tbl,
                                    struct bucket_table *new_tbl)
 {
-       /* Protect future_tbl using the first bucket lock. */
-       spin_lock_bh(old_tbl->locks);
-
-       /* Did somebody beat us to it? */
-       if (rcu_access_pointer(old_tbl->future_tbl)) {
-               spin_unlock_bh(old_tbl->locks);
-               return -EEXIST;
-       }
-
        /* Make insertions go into the new, empty table right away. Deletions
         * and lookups will be attempted in both tables until we synchronize.
+        * As cmpxchg() provides strong barriers, we do not need
+        * rcu_assign_pointer().
         */
-       rcu_assign_pointer(old_tbl->future_tbl, new_tbl);
 
-       spin_unlock_bh(old_tbl->locks);
+       if (cmpxchg(&old_tbl->future_tbl, NULL, new_tbl) != NULL)
+               return -EEXIST;
 
        return 0;
 }