From: NeilBrown <neilb@suse.com>
To: Thomas Graf <tgraf@suug.ch>,
Herbert Xu <herbert@gondor.apana.org.au>,
David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 4/5] rhashtable: replace rht_ptr_locked() with rht_assign_locked()
Date: Fri, 12 Apr 2019 11:52:08 +1000 [thread overview]
Message-ID: <155503392804.17793.16261235110097755380.stgit@noble.brown> (raw)
In-Reply-To: <155503371949.17793.8266195008003399968.stgit@noble.brown>
The only times rht_ptr_locked() is used, it is to store a new
value in a bucket-head. This is the only time it makes sense
to use it too. So replace it by a function which does the
whole task: Sets the lock bit and assigns to a bucket head.
Signed-off-by: NeilBrown <neilb@suse.com>
---
include/linux/rhashtable.h | 9 ++++++---
lib/rhashtable.c | 6 +++---
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index b54e6436547e..882bc0fcea4b 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -316,6 +316,7 @@ static inline struct rhash_lock_head __rcu **rht_bucket_insert(
* local_bh. For that we have rht_assign_unlock(). As rcu_assign_pointer()
* provides the same release semantics that bit_spin_unlock() provides,
* this is safe.
+ * When we write to a bucket without unlocking, we use rht_assign_locked().
*/
static inline void rht_lock(struct bucket_table *tbl,
@@ -369,10 +370,12 @@ static inline struct rhash_head *rht_ptr_exclusive(
return (void *)(((unsigned long)p) & ~BIT(1));
}
-static inline struct rhash_lock_head __rcu *rht_ptr_locked(const
- struct rhash_head *p)
+static inline void rht_assign_locked(struct rhash_lock_head __rcu **bkt,
+ struct rhash_head *obj)
{
- return (void *)(((unsigned long)p) | BIT(1));
+ struct rhash_head __rcu **p = (struct rhash_head __rcu **)bkt;
+
+ rcu_assign_pointer(*p, (void *)((unsigned long)obj | BIT(1)));
}
static inline void rht_assign_unlock(struct bucket_table *tbl,
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 1f38f550ba76..3bae6b05b4ba 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -260,7 +260,7 @@ static int rhashtable_rehash_one(struct rhashtable *ht,
rcu_assign_pointer(*pprev, next);
else
/* Need to preserved the bit lock. */
- rcu_assign_pointer(*bkt, rht_ptr_locked(next));
+ rht_assign_locked(bkt, next);
out:
return err;
@@ -518,7 +518,7 @@ static void *rhashtable_lookup_one(struct rhashtable *ht,
rcu_assign_pointer(*pprev, obj);
else
/* Need to preserve the bit lock */
- rcu_assign_pointer(*bkt, rht_ptr_locked(obj));
+ rht_assign_locked(bkt, obj);
return NULL;
}
@@ -571,7 +571,7 @@ static struct bucket_table *rhashtable_insert_one(struct rhashtable *ht,
/* bkt is always the head of the list, so it holds
* the lock, which we need to preserve
*/
- rcu_assign_pointer(*bkt, rht_ptr_locked(obj));
+ rht_assign_locked(bkt, obj);
atomic_inc(&ht->nelems);
if (rht_grow_above_75(ht, tbl))
next prev parent reply other threads:[~2019-04-12 1:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-12 1:52 [PATCH 0/5] Fix rhashtable bit-locking for m68k NeilBrown
2019-04-12 1:52 ` [PATCH 1/5] rhashtable: fix some __rcu annotation errors NeilBrown
2019-04-12 1:52 ` [PATCH 5/5] rhashtable: use BIT(0) for locking NeilBrown
2019-04-12 1:52 ` [PATCH 2/5] rhashtable: reorder some inline functions and macros NeilBrown
2019-05-14 19:25 ` Jakub Kicinski
2019-04-12 1:52 ` NeilBrown [this message]
2019-04-12 1:52 ` [PATCH 3/5] rhashtable: move dereference inside rht_ptr() NeilBrown
2019-04-12 18:08 ` [PATCH 0/5] Fix rhashtable bit-locking for m68k Guenter Roeck
2019-04-13 0:34 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=155503392804.17793.16261235110097755380.stgit@noble.brown \
--to=neilb@suse.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=netdev@vger.kernel.org \
--cc=tgraf@suug.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).