* [PATCH 1/4] rhashtable: RCU annotations for next pointers
2014-08-13 14:38 [PATCH 0/4] rhashtable annotation fixes Thomas Graf
@ 2014-08-13 14:38 ` Thomas Graf
2014-08-13 14:38 ` [PATCH 2/4] rhashtable: unexport and make rht_obj() static Thomas Graf
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Thomas Graf @ 2014-08-13 14:38 UTC (permalink / raw)
To: netdev
Properly annotate next pointers as access is RCU protected in
the lookup path.
Signed-off-by: Thomas Graf <tgraf@suug.ch>
---
include/linux/rhashtable.h | 4 ++--
lib/rhashtable.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index 9cda293..8c6048e 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -21,7 +21,7 @@
#include <linux/rculist.h>
struct rhash_head {
- struct rhash_head *next;
+ struct rhash_head __rcu *next;
};
#define INIT_HASH_HEAD(ptr) ((ptr)->next = NULL)
@@ -97,7 +97,7 @@ u32 rhashtable_obj_hashfn(const struct rhashtable *ht, void *ptr);
void rhashtable_insert(struct rhashtable *ht, struct rhash_head *node, gfp_t);
bool rhashtable_remove(struct rhashtable *ht, struct rhash_head *node, gfp_t);
void rhashtable_remove_pprev(struct rhashtable *ht, struct rhash_head *obj,
- struct rhash_head **pprev, gfp_t flags);
+ struct rhash_head __rcu **pprev, gfp_t flags);
bool rht_grow_above_75(const struct rhashtable *ht, size_t new_size);
bool rht_shrink_below_30(const struct rhashtable *ht, size_t new_size);
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index e6940cf..338dd7a 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -386,7 +386,7 @@ EXPORT_SYMBOL_GPL(rhashtable_insert);
* deletion when combined with walking or lookup.
*/
void rhashtable_remove_pprev(struct rhashtable *ht, struct rhash_head *obj,
- struct rhash_head **pprev, gfp_t flags)
+ struct rhash_head __rcu **pprev, gfp_t flags)
{
struct bucket_table *tbl = rht_dereference(ht->tbl, ht);
--
1.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/4] rhashtable: unexport and make rht_obj() static
2014-08-13 14:38 [PATCH 0/4] rhashtable annotation fixes Thomas Graf
2014-08-13 14:38 ` [PATCH 1/4] rhashtable: RCU annotations for next pointers Thomas Graf
@ 2014-08-13 14:38 ` Thomas Graf
2014-08-13 14:38 ` [PATCH 3/4] rhashtable: fix annotations for rht_for_each_entry_rcu() Thomas Graf
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Thomas Graf @ 2014-08-13 14:38 UTC (permalink / raw)
To: netdev
No need to export rht_obj(), all inner to outer object translations
occur internally. It was intended to be used with rht_for_each() which
now primarily serves as the iterator for rhashtable_remove_pprev() to
effectively flush and free the full table.
Signed-off-by: Thomas Graf <tgraf@suug.ch>
---
include/linux/rhashtable.h | 1 -
lib/rhashtable.c | 8 +-------
2 files changed, 1 insertion(+), 8 deletions(-)
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index 8c6048e..af967c4 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -117,7 +117,6 @@ void rhashtable_destroy(const struct rhashtable *ht);
#define rht_dereference_rcu(p, ht) \
rcu_dereference_check(p, lockdep_rht_mutex_is_held(ht))
-/* Internal, use rht_obj() instead */
#define rht_entry(ptr, type, member) container_of(ptr, type, member)
#define rht_entry_safe(ptr, type, member) \
({ \
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 338dd7a..a2c7881 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -38,16 +38,10 @@ int lockdep_rht_mutex_is_held(const struct rhashtable *ht)
EXPORT_SYMBOL_GPL(lockdep_rht_mutex_is_held);
#endif
-/**
- * rht_obj - cast hash head to outer object
- * @ht: hash table
- * @he: hashed node
- */
-void *rht_obj(const struct rhashtable *ht, const struct rhash_head *he)
+static void *rht_obj(const struct rhashtable *ht, const struct rhash_head *he)
{
return (void *) he - ht->p.head_offset;
}
-EXPORT_SYMBOL_GPL(rht_obj);
static u32 __hashfn(const struct rhashtable *ht, const void *key,
u32 len, u32 hsize)
--
1.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 3/4] rhashtable: fix annotations for rht_for_each_entry_rcu()
2014-08-13 14:38 [PATCH 0/4] rhashtable annotation fixes Thomas Graf
2014-08-13 14:38 ` [PATCH 1/4] rhashtable: RCU annotations for next pointers Thomas Graf
2014-08-13 14:38 ` [PATCH 2/4] rhashtable: unexport and make rht_obj() static Thomas Graf
@ 2014-08-13 14:38 ` Thomas Graf
2014-08-13 14:38 ` [PATCH 4/4] netlink: Annotate RCU locking for seq_file walker Thomas Graf
2014-08-14 22:14 ` [PATCH 0/4] rhashtable annotation fixes David Miller
4 siblings, 0 replies; 6+ messages in thread
From: Thomas Graf @ 2014-08-13 14:38 UTC (permalink / raw)
To: netdev
Call rcu_deference_raw() directly from within rht_for_each_entry_rcu()
as list_for_each_entry_rcu() does.
Fixes the following sparse warnings:
net/netlink/af_netlink.c:2906:25: expected struct rhash_head const *__mptr
net/netlink/af_netlink.c:2906:25: got struct rhash_head [noderef] <asn:4>*<noident>
Fixes: e341694e3eb57fc ("netlink: Convert netlink_lookup() to use RCU protected hash table")
Signed-off-by: Thomas Graf <tgraf@suug.ch>
---
include/linux/rhashtable.h | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index af967c4..36826c0 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -123,11 +123,6 @@ void rhashtable_destroy(const struct rhashtable *ht);
typeof(ptr) __ptr = (ptr); \
__ptr ? rht_entry(__ptr, type, member) : NULL; \
})
-#define rht_entry_safe_rcu(ptr, type, member) \
-({ \
- typeof(*ptr) __rcu *__ptr = (typeof(*ptr) __rcu __force *)ptr; \
- __ptr ? container_of((typeof(ptr))rcu_dereference_raw(__ptr), type, member) : NULL; \
-})
#define rht_next_entry_safe(pos, ht, member) \
({ \
@@ -204,9 +199,10 @@ void rhashtable_destroy(const struct rhashtable *ht);
* traversal is guarded by rcu_read_lock().
*/
#define rht_for_each_entry_rcu(pos, head, member) \
- for (pos = rht_entry_safe_rcu(head, typeof(*(pos)), member); \
+ for (pos = rht_entry_safe(rcu_dereference_raw(head), \
+ typeof(*(pos)), member); \
pos; \
- pos = rht_entry_safe_rcu((pos)->member.next, \
- typeof(*(pos)), member))
+ pos = rht_entry_safe(rcu_dereference_raw((pos)->member.next), \
+ typeof(*(pos)), member))
#endif /* _LINUX_RHASHTABLE_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 4/4] netlink: Annotate RCU locking for seq_file walker
2014-08-13 14:38 [PATCH 0/4] rhashtable annotation fixes Thomas Graf
` (2 preceding siblings ...)
2014-08-13 14:38 ` [PATCH 3/4] rhashtable: fix annotations for rht_for_each_entry_rcu() Thomas Graf
@ 2014-08-13 14:38 ` Thomas Graf
2014-08-14 22:14 ` [PATCH 0/4] rhashtable annotation fixes David Miller
4 siblings, 0 replies; 6+ messages in thread
From: Thomas Graf @ 2014-08-13 14:38 UTC (permalink / raw)
To: netdev
Silences the following sparse warnings:
net/netlink/af_netlink.c:2926:21: warning: context imbalance in 'netlink_seq_start' - wrong count at exit
net/netlink/af_netlink.c:2972:13: warning: context imbalance in 'netlink_seq_stop' - unexpected unlock
Signed-off-by: Thomas Graf <tgraf@suug.ch>
---
net/netlink/af_netlink.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 2e152e5..c416725 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -2921,6 +2921,7 @@ static struct sock *netlink_seq_socket_idx(struct seq_file *seq, loff_t pos)
}
static void *netlink_seq_start(struct seq_file *seq, loff_t *pos)
+ __acquires(RCU)
{
rcu_read_lock();
return *pos ? netlink_seq_socket_idx(seq, *pos - 1) : SEQ_START_TOKEN;
@@ -2970,6 +2971,7 @@ static void *netlink_seq_next(struct seq_file *seq, void *v, loff_t *pos)
}
static void netlink_seq_stop(struct seq_file *seq, void *v)
+ __releases(RCU)
{
rcu_read_unlock();
}
--
1.9.3
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 0/4] rhashtable annotation fixes
2014-08-13 14:38 [PATCH 0/4] rhashtable annotation fixes Thomas Graf
` (3 preceding siblings ...)
2014-08-13 14:38 ` [PATCH 4/4] netlink: Annotate RCU locking for seq_file walker Thomas Graf
@ 2014-08-14 22:14 ` David Miller
4 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2014-08-14 22:14 UTC (permalink / raw)
To: tgraf; +Cc: netdev
From: Thomas Graf <tgraf@suug.ch>
Date: Wed, 13 Aug 2014 16:38:28 +0200
> Thomas Graf (4):
> rhashtable: RCU annotations for next pointers
> rhashtable: unexport and make rht_obj() static
> rhashtable: fix annotations for rht_for_each_entry_rcu()
> netlink: Annotate RCU locking for seq_file walker
Series applied, thanks Thomas.
^ permalink raw reply [flat|nested] 6+ messages in thread