From: Kunwu Chan <kunwu.chan@gmail.com>
To: arnd@arndb.de, anna-maria@linutronix.de, frederic@kernel.org,
mingo@kernel.org, tglx@kernel.org
Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
Kunwu Chan <kunwu.chan@gmail.com>,
"Paul E . McKenney" <paulmck@kernel.org>
Subject: [PATCH v2 1/2] rwonce: Add READ_ONCE_THIS_CPU() and WRITE_ONCE_THIS_CPU()
Date: Fri, 2 Oct 2026 23:17:55 +0800 [thread overview]
Message-ID: <20261002151757.3605081-2-kunwu.chan@gmail.com> (raw)
In-Reply-To: <20261002151757.3605081-1-kunwu.chan@gmail.com>
Per-CPU variables are sometimes accessed from different execution
contexts on the same CPU, typically task context and an interrupt or
NMI handler.
A plain READ_ONCE() or WRITE_ONCE() marks such an access as an
intentional race but does not express where the racing accesses are
expected to come from. This distinction allows concurrency tools such
as KCSAN to tell an intentional same-CPU context race apart from an
access that may race across CPUs.
Add READ_ONCE_THIS_CPU() and WRITE_ONCE_THIS_CPU() to identify accesses
to a per-CPU variable which are intended to race only with accesses
from other execution contexts on the same CPU. For now, they are
simple wrappers around READ_ONCE() and WRITE_ONCE(), so generated code
and tool behaviour are unchanged.
Suggested-by: Thomas Gleixner <tglx@kernel.org>
Suggested-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Kunwu Chan <kunwu.chan@gmail.com>
---
include/asm-generic/rwonce.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/include/asm-generic/rwonce.h b/include/asm-generic/rwonce.h
index 52b969c7cef9..4d4e009a4489 100644
--- a/include/asm-generic/rwonce.h
+++ b/include/asm-generic/rwonce.h
@@ -61,6 +61,17 @@ do { \
__WRITE_ONCE(x, val); \
} while (0)
+/*
+ * {READ,WRITE}_ONCE_THIS_CPU() identify accesses to a per-CPU variable
+ * which are intended to race only with accesses from other execution
+ * contexts on the same CPU, e.g. task and interrupt context.
+ *
+ * For now, these are simple wrappers around READ_ONCE() and
+ * WRITE_ONCE().
+ */
+#define READ_ONCE_THIS_CPU(x) READ_ONCE(x)
+#define WRITE_ONCE_THIS_CPU(x, val) WRITE_ONCE(x, val)
+
static __no_sanitize_or_inline
unsigned long __read_once_word_nocheck(const void *addr)
{
--
2.43.0
next prev parent reply other threads:[~2026-10-02 15:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 15:17 [PATCH v2 0/2] rwonce: Introduce {READ,WRITE}_ONCE_THIS_CPU() Kunwu Chan
2026-10-02 15:17 ` Kunwu Chan [this message]
2026-10-02 15:44 ` [PATCH v2 1/2] rwonce: Add READ_ONCE_THIS_CPU() and WRITE_ONCE_THIS_CPU() Paul E. McKenney
2026-10-02 15:17 ` [PATCH v2 2/2] timers/nohz: Mark got_idle_tick accesses as same-CPU races Kunwu Chan
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=20261002151757.3605081-2-kunwu.chan@gmail.com \
--to=kunwu.chan@gmail.com \
--cc=anna-maria@linutronix.de \
--cc=arnd@arndb.de \
--cc=frederic@kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@kernel.org \
--cc=tglx@kernel.org \
/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
all inboxes | Powered by JetHome®