Skip to contentSkip to conversation

hlist_add_tail_rcu disable sparse warning

PATCH In review Michael S. Tsirkin 2 participants 2 messages Feb 27, 2017 – Mar 3, 2017 RCU

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hlist_add_tail_rcu disable sparse warning

sparse is unhappy about this code in hlist_add_tail_rcu:

        struct hlist_node *i, *last = NULL;

        for (i = hlist_first_rcu(h); i; i = hlist_next_rcu(i))
                last = i;

This is because hlist_next_rcu and hlist_next_rcu return __rcu pointers.

It's a false positive - it's a write side primitive and so does not need to be called in a read side critical section.

The following trivial patch disables the warning
without changing the behaviour in any way.

Note: __hlist_for_each_rcu would also remove the warning but it would be confusing since it calls rcu_derefence and is designed to run in the rcu read side critical section.

---

Comments from v2:
add a comment as requested by Steven Rostedt

 include/linux/rculist.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/rculist.h +2 -1
index 4f7a956..b1fd8bf 100644
@@ -509,7 +509,8 @@ static inline void hlist_add_tail_rcu(struct hlist_node *n,
 {
 	struct hlist_node *i, *last = NULL;
 
-	for (i = hlist_first_rcu(h); i; i = hlist_next_rcu(i))
+	/* Note: write side code, so rcu accessors are not needed. */
+	for (i = h->first; i; i = i->next)
 		last = i;
 
 	if (last) {
Signature · 1 line
MST
#1 lore raw
Quoted 16 lines · Michael S. Tsirkin

sparse is unhappy about this code in hlist_add_tail_rcu:

        struct hlist_node *i, *last = NULL;

        for (i = hlist_first_rcu(h); i; i = hlist_next_rcu(i))
                last = i;

This is because hlist_next_rcu and hlist_next_rcu return __rcu pointers.

It's a false positive - it's a write side primitive and so does not need to be called in a read side critical section.

The following trivial patch disables the warning
without changing the behaviour in any way.

Quoted 6 lines

Note: __hlist_for_each_rcu would also remove the warning but it would be confusing since it calls rcu_derefence and is designed to run in the rcu read side critical section.

Queud for further review and testing, thank you both!

Thanx, Paul

Quoted 25 lines

---

Comments from v2:
add a comment as requested by Steven Rostedt

 include/linux/rculist.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/rculist.h +2 -1
index 4f7a956..b1fd8bf 100644
@@ -509,7 +509,8 @@ static inline void hlist_add_tail_rcu(struct hlist_node *n,
 {
 	struct hlist_node *i, *last = NULL;
 
-	for (i = hlist_first_rcu(h); i; i = hlist_next_rcu(i))
+	/* Note: write side code, so rcu accessors are not needed. */
+	for (i = h->first; i; i = i->next)
 		last = i;
 
 	if (last) {
Signature · 1 line
MST