Skip to contentSkip to conversation

hlist_add_tail_rcu disable sparse warning

PATCH Superseded Michael S. Tsirkin 3 participants 5 messages Feb 10, 2017 – Apr 26, 2017 RCU

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---

changes since RFC
added commit log text to explain why don't we use __hlist_for_each_rcu

 include/linux/rculist.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/rculist.h +1 -1
index 4f7a956..bf578e8 100644
@@ -509,7 +509,7 @@ 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))
+	for (i = h->first; i; i = i->next)
 		last = i;
 
 	if (last) {
Signature · 1 line
MST
reviewer Reviewed-by on v1 1/1
#1 lore raw

include/linux/rculist.h static inline void hlist_add_tail_rcu(struct hlist_node *n, · line 512

Quoted 10 lines · On Fri, 10 Feb 2017 19:39:49 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
include/linux/rculist.h +1 -1
index 4f7a956..bf578e8 100644
@@ -509,7 +509,7 @@ 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))
+	for (i = h->first; i; i = i->next)

Looks good to me, but I would probably add a comment above the loop about this being in a write side section, and rcu conversions are not needed.

-- Steve

Quoted 3 lines
include/linux/rculist.h +0 -0
 		last = i;
 
 	if (last) {
#2 lore raw
In reply to Michael S. Tsirkin
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.

---

ping

Quoted 21 lines

changes since RFC
added commit log text to explain why don't we use __hlist_for_each_rcu

 include/linux/rculist.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/rculist.h +1 -1
index 4f7a956..bf578e8 100644
@@ -509,7 +509,7 @@ 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))
+	for (i = h->first; i; i = i->next)
 		last = i;
 
 	if (last) {
Signature · 1 line
MST
#3 lore raw

Paul,

Did you see this email?

-- Steve

Quoted 47 lines · On Mon, 27 Feb 2017 20:26:01 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
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.

---

ping

Quoted 21 lines

changes since RFC
added commit log text to explain why don't we use __hlist_for_each_rcu

 include/linux/rculist.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/rculist.h +1 -1
index 4f7a956..bf578e8 100644
@@ -509,7 +509,7 @@ 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))
+	for (i = h->first; i; i = i->next)
 		last = i;
 
 	if (last) {
Signature · 1 line
MST  
#4 lore raw
Quoted 4 lines · Steven Rostedt

Paul,

Did you see this email?

Yep! Michael's patch is 48ac34666ff7 ("hlist_add_tail_rcu disable sparse warning") in -rcu and now in -tip.

But I do appreciate the reminder -- way too easy to miss stuff on LKML!

Thanx, Paul

Quoted 54 lines

-- Steve

Quoted 47 lines · On Mon, 27 Feb 2017 20:26:01 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
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.

---

ping

Quoted 21 lines

changes since RFC
added commit log text to explain why don't we use __hlist_for_each_rcu

 include/linux/rculist.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/rculist.h +1 -1
index 4f7a956..bf578e8 100644
@@ -509,7 +509,7 @@ 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))
+	for (i = h->first; i; i = i->next)
 		last = i;
 
 	if (last) {
Signature · 1 line
MST