Skip to content

Commit efd04f8

Browse files
alanskindpaulmckrcu
authored andcommitted
rcu: Use WRITE_ONCE() for assignments to ->next for rculist_nulls
When the objects managed by rculist_nulls are allocated with SLAB_TYPESAFE_BY_RCU, old readers may still hold references to an object even though it is just now being added, which means the modification of ->next is visible to readers. This patch therefore uses WRITE_ONCE() for assignments to ->next. Signed-off-by: Alan Huang <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]> Reviewed-by: Joel Fernandes (Google) <[email protected]>
1 parent 3292ba0 commit efd04f8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/linux/rculist_nulls.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static inline void hlist_nulls_add_head_rcu(struct hlist_nulls_node *n,
101101
{
102102
struct hlist_nulls_node *first = h->first;
103103

104-
n->next = first;
104+
WRITE_ONCE(n->next, first);
105105
WRITE_ONCE(n->pprev, &h->first);
106106
rcu_assign_pointer(hlist_nulls_first_rcu(h), n);
107107
if (!is_a_nulls(first))
@@ -137,7 +137,7 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n,
137137
last = i;
138138

139139
if (last) {
140-
n->next = last->next;
140+
WRITE_ONCE(n->next, last->next);
141141
n->pprev = &last->next;
142142
rcu_assign_pointer(hlist_nulls_next_rcu(last), n);
143143
} else {

0 commit comments

Comments
 (0)