cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] llist: avoid memory tearing for llist_node
@ 2025-07-03 20:00 Shakeel Butt
  2025-07-03 20:00 ` [PATCH 2/2] cgroup: explain the race between updater and flusher Shakeel Butt
  2025-07-03 22:24 ` [PATCH 1/2] llist: avoid memory tearing for llist_node Paul E. McKenney
  0 siblings, 2 replies; 10+ messages in thread
From: Shakeel Butt @ 2025-07-03 20:00 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Paul E . McKenney, Andrew Morton, JP Kobryn, Johannes Weiner,
	Ying Huang, Vlastimil Babka, Alexei Starovoitov,
	Sebastian Andrzej Siewior, Michal Koutný, bpf, linux-mm,
	cgroups, linux-kernel, Meta kernel team

Before the commit 36df6e3dbd7e ("cgroup: make css_rstat_updated nmi
safe"), the struct llist_node is expected to be private to the one
inserting the node to the lockless list or the one removing the node
from the lockless list. After the mentioned commit, the llist_node in
the rstat code is per-cpu shared between the stacked contexts i.e.
process, softirq, hardirq & nmi. It is possible the compiler may tear
the loads or stores of llist_node. Let's avoid that.

Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
---
 include/linux/llist.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/include/linux/llist.h b/include/linux/llist.h
index 27b17f64bcee..607b2360c938 100644
--- a/include/linux/llist.h
+++ b/include/linux/llist.h
@@ -83,7 +83,7 @@ static inline void init_llist_head(struct llist_head *list)
  */
 static inline void init_llist_node(struct llist_node *node)
 {
-	node->next = node;
+	WRITE_ONCE(node->next, node);
 }
 
 /**
@@ -97,7 +97,7 @@ static inline void init_llist_node(struct llist_node *node)
  */
 static inline bool llist_on_list(const struct llist_node *node)
 {
-	return node->next != node;
+	return READ_ONCE(node->next) != node;
 }
 
 /**
@@ -220,7 +220,7 @@ static inline bool llist_empty(const struct llist_head *head)
 
 static inline struct llist_node *llist_next(struct llist_node *node)
 {
-	return node->next;
+	return READ_ONCE(node->next);
 }
 
 /**
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-07-04 17:58 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-03 20:00 [PATCH 1/2] llist: avoid memory tearing for llist_node Shakeel Butt
2025-07-03 20:00 ` [PATCH 2/2] cgroup: explain the race between updater and flusher Shakeel Butt
2025-07-03 22:29   ` Paul E. McKenney
2025-07-03 22:46     ` Shakeel Butt
2025-07-03 23:53       ` Paul E. McKenney
2025-07-04  1:54         ` Shakeel Butt
2025-07-04  4:44           ` Paul E. McKenney
2025-07-04 17:45             ` Shakeel Butt
2025-07-04 17:58               ` Paul E. McKenney
2025-07-03 22:24 ` [PATCH 1/2] llist: avoid memory tearing for llist_node Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).