Re: [PATCH v2 1/2] rwonce: Add READ_ONCE_THIS_CPU() and WRITE_ONCE_THIS_CPU()

From: KunWu Chan

Date: Tue Oct 06 2026 - 22:18:12 EST


On Mon, Oct 5, 2026 at 10:47 PM Frederic Weisbecker <frederic@xxxxxxxxxx> wrote:
>
> Le Fri, Oct 02, 2026 at 11:17:55PM +0800, Kunwu Chan a écrit :
> > 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.
>
> But there is a plan to handle that with KSCAN, right?
>
> If so:
>
> Acked-by: Frederic Weisbecker <frederic@xxxxxxxxxx>
>

Hi Frederic,

Yes, that's the plan. Thanks for the Ack!

Best,
Kunwu

> Thanks.
>
>
> >
> > Suggested-by: Thomas Gleixner <tglx@xxxxxxxxxx>
> > Suggested-by: Paul E. McKenney <paulmck@xxxxxxxxxx>
> > Signed-off-by: Kunwu Chan <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 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
> >
>
> --
> Frederic Weisbecker
> SUSE Labs