mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 00:16:45 +0200	[thread overview]
Message-ID: <87ld8igzaq.ffs@fw13> (raw)
In-Reply-To: <43ac14e7-8d9a-4ff5-87ee-55ec3c7cdeb8@paulmck-laptop>

On Wed, Sep 30 2026 at 13:00, Paul E. McKenney wrote:
> On Tue, Sep 29, 2026 at 02:21:32PM +0200, Thomas Gleixner wrote:
>> On Sun, Sep 20 2026 at 16:54, Kunwu Chan wrote:
>> > tick_sched_do_timer(), called from the tick interrupt handler, sets
>> > ts->got_idle_tick when a tick fires while the CPU is idle.  The idle
>> > path reads and clears it via tick_nohz_idle_got_tick() to detect
>> > whether the tick handler has run.
>> >
>> > The flag is accessed locklessly from hardirq and task context.  A
>> > concurrent set can be overwritten by the clear.
>> >
>> > Use READ_ONCE() and WRITE_ONCE() to annotate the lockless accesses.
>> 
>> The following scenarios still happen:
>> 
>> A)
>> 
>>               if (READ_ONCE(got_tick))      // reads true
>> -> interrupt       
>>        WRITE_ONCE(got_tick, true);   
>> 
>>                    WRITE_ONCE(got_tick, false);
>> 
>> B)
>> 
>>               if (READ_ONCE(got_tick))      // reads false
>> -> interrupt       
>>        WRITE_ONCE(got_tick, true);   
>> 
>> #A is harmless because got_tick is already true and #B is harmless as
>>  well because the got_tick read result is only a hint for the next idle
>>  invocation.
>> 
>> As this is stricly per CPU the READ/WRITE_ONCE() does not change
>> anything in terms of ordering. So what exactly is solved by the
>> READ/WRITE_ONCE()?
>
> This is a step towards allowing more-strict KCSAN checks to be enabled,
> namely data races between base code and interrupt handlers.  KCSAN has
> found a few bugs of this type in RCU over the past year or so, which
> suggests that similar bugs might be lurking elsewhere.
>
> Yes, in this particular case, current compilers don't have a huge amount
> of freedom to mess things up, but the standard really does permit the
> compiler to use a to-be-stored-to location as a temporary just prior to
> that store.
>
> This is like the situation with lockdep, where we tell it about
> deadlock-free situations that it does not see as being deadlock-free.
>
> Seem reasonable?

Yes, but then the change log should clearly state exactly that along
with a corresponding comment in the code. These boilerplate copy&pasta
changes are annoying as hell because they fail to provide any reasonable
rationale for the proposed change. See Documentation/process/...

I'm refusing to accept this slop whether it's generated by humans or any
form of tools.

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.

Thanks,

        tglx

  reply	other threads:[~2026-09-30 22:16 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 [this message]
2026-09-30 22:30       ` Paul E. McKenney
2026-10-01 14:06         ` Thomas Gleixner

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=87ld8igzaq.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®