Skip to contentSkip to conversation

rcu: use WRITE_ONCE() for ->next and ->pprev of hlist_nulls

PATCH In review [email protected] 3 participants 3 messages Oct 10, 2025 – Oct 20, 2025 RCU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rcu: use WRITE_ONCE() for ->next and ->pprev of hlist_nulls

From: Xuanqiang Luo <[email protected]>

In rculist_nulls.h we can still see ordinary assignments to ->pprev and ->next of hlist_nulls.

As noted in the two patches below:
commit efd04f8a8b45 ("rcu: Use WRITE_ONCE() for assignments to ->next for rculist_nulls")
commit 860c8802ace1 ("rcu: Use WRITE_ONCE() for assignments to ->pprev for hlist_nulls")

We should use WRITE_ONCE().

---
 include/linux/rculist_nulls.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/rculist_nulls.h +3 -3
index 89186c499dd4..d5a656cc4c6a 100644
@@ -138,7 +138,7 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n,
 
 	if (last) {
 		WRITE_ONCE(n->next, last->next);
-		n->pprev = &last->next;
+		WRITE_ONCE(n->pprev, &last->next);
 		rcu_assign_pointer(hlist_nulls_next_rcu(last), n);
 	} else {
 		hlist_nulls_add_head_rcu(n, h);
@@ -148,8 +148,8 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n,
 /* after that hlist_nulls_del will work */
 static inline void hlist_nulls_add_fake(struct hlist_nulls_node *n)
 {
-	n->pprev = &n->next;
-	n->next = (struct hlist_nulls_node *)NULLS_MARKER(NULL);
+	WRITE_ONCE(n->pprev, &n->next);
+	WRITE_ONCE(n->next, (struct hlist_nulls_node *)NULLS_MARKER(NULL));
 }
 
 /**
Signature · 1 line
2.25.1
#1 lore raw
Quoted 24 lines · On Thu, Oct 9, 2025 at 11:50 PM <[email protected]> wrote:

From: Xuanqiang Luo <[email protected]>

In rculist_nulls.h we can still see ordinary assignments to ->pprev and ->next of hlist_nulls.

As noted in the two patches below:
commit efd04f8a8b45 ("rcu: Use WRITE_ONCE() for assignments to ->next for rculist_nulls")
commit 860c8802ace1 ("rcu: Use WRITE_ONCE() for assignments to ->pprev for hlist_nulls")

We should use WRITE_ONCE().

---
 include/linux/rculist_nulls.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/rculist_nulls.h +0 -0
index 89186c499dd4..d5a656cc4c6a 100644

include/linux/rculist_nulls.h static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n, · line 141

Quoted 5 lines
include/linux/rculist_nulls.h +1 -1
@@ -138,7 +138,7 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n,
 
        if (last) {
                WRITE_ONCE(n->next, last->next);
-               n->pprev = &last->next;
+               WRITE_ONCE(n->pprev, &last->next);

n is private to the current thread. No other cpu/thread can see it yet.

Following rcu_assign_pointer() already has the needed barrier making sure that _when_ the object
can be seen by others, n->pprev value is fully up to date.

include/linux/rculist_nulls.h static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n, · line 152

Quoted 11 lines
include/linux/rculist_nulls.h +2 -2
                rcu_assign_pointer(hlist_nulls_next_rcu(last), n);
        } else {
                hlist_nulls_add_head_rcu(n, h);
@@ -148,8 +148,8 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n,
 /* after that hlist_nulls_del will work */
 static inline void hlist_nulls_add_fake(struct hlist_nulls_node *n)
 {
-       n->pprev = &n->next;
-       n->next = (struct hlist_nulls_node *)NULLS_MARKER(NULL);
+       WRITE_ONCE(n->pprev, &n->next);
+       WRITE_ONCE(n->next, (struct hlist_nulls_node *)NULLS_MARKER(NULL));

Same here, n is private. No need for any WRITE_ONCE().

maintainer
#2 lore raw
In reply to [email protected]
Quoted 11 lines · On Fri, Oct 10, 2025 at 02:49:10PM +0800, [email protected] wrote:

From: Xuanqiang Luo <[email protected]>

In rculist_nulls.h we can still see ordinary assignments to ->pprev and ->next of hlist_nulls.

As noted in the two patches below:
commit efd04f8a8b45 ("rcu: Use WRITE_ONCE() for assignments to ->next for rculist_nulls")
commit 860c8802ace1 ("rcu: Use WRITE_ONCE() for assignments to ->pprev for hlist_nulls")

Quoted 3 lines

We should use WRITE_ONCE().

Hearing no objections, I have pulled this in for further review and testing.

Thanx, Paul

Quoted 32 lines
---
 include/linux/rculist_nulls.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/rculist_nulls.h +3 -3
index 89186c499dd4..d5a656cc4c6a 100644
@@ -138,7 +138,7 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n,
 
 	if (last) {
 		WRITE_ONCE(n->next, last->next);
-		n->pprev = &last->next;
+		WRITE_ONCE(n->pprev, &last->next);
 		rcu_assign_pointer(hlist_nulls_next_rcu(last), n);
 	} else {
 		hlist_nulls_add_head_rcu(n, h);
@@ -148,8 +148,8 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n,
 /* after that hlist_nulls_del will work */
 static inline void hlist_nulls_add_fake(struct hlist_nulls_node *n)
 {
-	n->pprev = &n->next;
-	n->next = (struct hlist_nulls_node *)NULLS_MARKER(NULL);
+	WRITE_ONCE(n->pprev, &n->next);
+	WRITE_ONCE(n->next, (struct hlist_nulls_node *)NULLS_MARKER(NULL));
 }
 
 /**
Signature · 1 line
2.25.1