From: "Paul E. McKenney" <paulmck@kernel.org>
To: Shakeel Butt <shakeel.butt@linux.dev>
Cc: "Tejun Heo" <tj@kernel.org>,
"Andrew Morton" <akpm@linux-foundation.org>,
"JP Kobryn" <inwardvessel@gmail.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Ying Huang" <huang.ying.caritas@gmail.com>,
"Vlastimil Babka" <vbabka@suse.cz>,
"Alexei Starovoitov" <ast@kernel.org>,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Michal Koutný" <mkoutny@suse.com>,
bpf@vger.kernel.org, linux-mm@kvack.org, cgroups@vger.kernel.org,
linux-kernel@vger.kernel.org,
"Meta kernel team" <kernel-team@meta.com>
Subject: Re: [PATCH 1/2] llist: avoid memory tearing for llist_node
Date: Thu, 3 Jul 2025 15:24:21 -0700 [thread overview]
Message-ID: <e33d07a0-8470-44a8-88c1-10dfcb1171ea@paulmck-laptop> (raw)
In-Reply-To: <20250703200012.3734798-1-shakeel.butt@linux.dev>
On Thu, Jul 03, 2025 at 01:00:11PM -0700, Shakeel Butt wrote:
> 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>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
> ---
> 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
>
prev parent reply other threads:[~2025-07-03 22:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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: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 ` Paul E. McKenney [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e33d07a0-8470-44a8-88c1-10dfcb1171ea@paulmck-laptop \
--to=paulmck@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=ast@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=bpf@vger.kernel.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=huang.ying.caritas@gmail.com \
--cc=inwardvessel@gmail.com \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mkoutny@suse.com \
--cc=shakeel.butt@linux.dev \
--cc=tj@kernel.org \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox