Re: [PATCH v3 1/2] rwonce: Add READ_ONCE_THIS_CPU() and WRITE_ONCE_THIS_CPU()
From: KunWu Chan
Date: Thu Oct 08 2026 - 01:58:39 EST
On Wed, Oct 7, 2026 at 6:50 PM Arnd Bergmann <arnd@xxxxxxxx> wrote:
>
> On Wed, Oct 7, 2026, at 04:28, Kunwu Chan wrote:
> > 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>
> > Reviewed-by: Paul E. McKenney <paulmck@xxxxxxxxxx>
> > Acked-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
> > Signed-off-by: Kunwu Chan <kunwu.chan@xxxxxxxxx>
>
> No objections here, but since I missed the background, I don't
> see what a future implementation of the new macros might do
> that is different from the existing macros, maybe you can still
> clarify that.
>
Hi Arnd,
Thanks for the Ack!
The background was discussed in the v1 thread:
https://lore.kernel.org/all/87qzici6yb.ffs@fw13/
The idea is that the *_THIS_CPU() variants make the intended
access scope explicit: a race between different execution contexts
on the same CPU, rather than a race that may occur across CPUs.
For now, they are just wrappers around READ_ONCE() and
WRITE_ONCE(), as Thomas suggested. A future KCSAN implementation
could use the annotation to distinguish these same-CPU races from
cross-CPU races.
Thanks,
Kunwu
> For taking this through something other than my asm-generic tree:
>
> Acked-by: Arnd Bergmann <arnd@xxxxxxxx>