From: Thomas Gleixner <tglx@kernel.org>
To: paulmck@kernel.org
Cc: Kunwu Chan <kunwu.chan@gmail.com>,
anna-maria@linutronix.de, frederic@kernel.org, mingo@kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] timers/nohz: Annotate lockless accesses to got_idle_tick
Date: Thu, 01 Oct 2026 16:06:04 +0200 [thread overview]
Message-ID: <87cxtth5wz.ffs@fw13> (raw)
In-Reply-To: <0d74e178-274e-4555-b904-23bd1910020d@paulmck-laptop>
On Wed, Sep 30 2026 at 15:30, Paul E. McKenney wrote:
> On Thu, Oct 01, 2026 at 12:16:45AM +0200, Thomas Gleixner wrote:
>> That said, I further have to say that just reusing READ/WRITE_ONCE() for
>> this is completely wrong.
>>
>> A strict and harmless per CPU modification/race is very much different
>> from cross CPU races. So avoiding any potential confusion and thereby
>> allowing tools like KCSAN to treat them differently is useful.
>>
>> Using the same annotation for something which is strictly a per CPU
>> situation prevents to detect the accidential cross CPU access which
>> might not be safe at all.
>>
>> Even if the momentary implementation falls back to the same mechanism
>> for the tools the value of implied code documentation is valuable. It
>> avoids extensive comments and it also allows tools to differentiate the
>> meaning in the future.
>>
>> READ/WRITE_ONCE() are just non-distinguishable "paper over all race
>> problems which tools might complain about" hammers.
>>
>> But we all should know by now that "Birmingham screwdrivers" are more
>> than suboptimal.
>
> Yeah, if you hit something with a Birmingham screwdriver, it might not
> quite realize that it has been hit. On the other hand, if you instead use
> a 16-pound (7 1/4 kg) sledgehammer, at least the fool thing will *know*
> that it has been hit. ;-)
>
> Back to the topic at hand...
>
> So your thought is to have a KCSAN annotation that says "should be accessed
> only from the corresponding CPU". Or maybe "from no more than one CPU".
>
> That would certainly be useful, easy though it is for me to say.
>
> Marco, is something like this practical for KCSAN?
>
> There are quite a few variations, including "written from one CPU but
> read from everywhere" and vice versa. But maybe start with the things
> actually proven useful. ;-)
Well, written from one CPU and read from everywhere is what
READ/WRITE_ONCE() is for just with the extra twist that the WRITE is
bound to a single specific CPU. But that's not the problem at hand.
What I meant is to have something like this:
WRITE_ONCE_THIS_CPU(...)
READ_ONCE_THIS_CPU(...)
where both operate on the same per CPU variable and the race is between
different contexts, e.g. task and interrupt.
That's first of all useful as documentation for the reader and also for
static analysis tools.
As long as KCSAN cannot make use of it the macros simply fall back to
the existing WRITE/READ_ONCE() so the problem which the patch under
discussion is trying to solve is addressed. When some future KCSAN
implementation can make this a special case with actual per CPU checks
then we get even more benefit.
Thanks,
tglx
prev parent reply other threads:[~2026-10-01 14:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-20 8:54 Kunwu Chan
2026-09-29 12:21 ` Thomas Gleixner
2026-09-30 20:00 ` Paul E. McKenney
2026-09-30 22:16 ` Thomas Gleixner
2026-09-30 22:30 ` Paul E. McKenney
2026-10-01 14:06 ` Thomas Gleixner [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=87cxtth5wz.ffs@fw13 \
--to=tglx@kernel.org \
--cc=anna-maria@linutronix.de \
--cc=frederic@kernel.org \
--cc=kunwu.chan@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@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®