[tip: timers/nohz] rwonce: Add READ_ONCE_THIS_CPU() and WRITE_ONCE_THIS_CPU()
From: tip-bot2 for Kunwu Chan
Date: Mon Nov 09 2026 - 12:11:27 EST
The following commit has been merged into the timers/nohz branch of tip:
Commit-ID: 3f1eb85d954ae5aa16e85e87afe982b7fed91588
Gitweb: https://git.kernel.org/tip/3f1eb85d954ae5aa16e85e87afe982b7fed91588
Author: Kunwu Chan <kunwu.chan@xxxxxxxxx>
AuthorDate: Wed, 07 Oct 2026 10:28:58 +08:00
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Mon, 09 Nov 2026 17:50:54 +01:00
rwonce: Add READ_ONCE_THIS_CPU() and WRITE_ONCE_THIS_CPU()
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@xxxxxxxxxx>
Suggested-by: Paul E. McKenney <paulmck@xxxxxxxxxx>
Signed-off-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Reviewed-by: Paul E. McKenney <paulmck@xxxxxxxxxx>
Acked-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
Acked-by: Arnd Bergmann <arnd@xxxxxxxx>
Link: https://patch.msgid.link/20261007022859.60101-2-kunwu.chan@xxxxxxxxx
---
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 52b969c..4d4e009 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)
{