[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201216211931.GL2657@paulmck-ThinkPad-P72>
Date: Wed, 16 Dec 2020 13:19:31 -0800
From: "Paul E. McKenney" <paulmck@...nel.org>
To: Thomas Gleixner <tglx@...utronix.de>
Cc: Peter Zijlstra <peterz@...radead.org>,
Marco Elver <elver@...gle.com>,
LKML <linux-kernel@...r.kernel.org>,
kasan-dev <kasan-dev@...glegroups.com>,
Ingo Molnar <mingo@...nel.org>,
Frederic Weisbecker <frederic@...nel.org>,
Will Deacon <will@...nel.org>,
Naresh Kamboju <naresh.kamboju@...aro.org>,
syzbot+23a256029191772c2f02@...kaller.appspotmail.com,
syzbot+56078ac0b9071335a745@...kaller.appspotmail.com,
syzbot+867130cb240c41f15164@...kaller.appspotmail.com
Subject: Re: [patch 3/3] tick: Annotate tick_do_timer_cpu data races
On Wed, Dec 16, 2020 at 01:27:43AM +0100, Thomas Gleixner wrote:
> On Tue, Dec 08 2020 at 07:03, Paul E. McKenney wrote:
>
> > On Tue, Dec 08, 2020 at 09:11:29AM +0100, Peter Zijlstra wrote:
> >> On Mon, Dec 07, 2020 at 11:44:06AM -0800, Paul E. McKenney wrote:
> >>
> >> > Also, in this particular case, why data_race() rather than READ_ONCE()?
> >> > Do we really expect the compiler to be able to optimize this case
> >> > significantly without READ_ONCE()?
>
> There is probably not much optimization potential for the compiler if
> data_race() is used vs. READ/WRITE_ONCE() in this code.
OK, got it.
> >> It's about intent and how the code reads. READ_ONCE() is something
> >> completely different from data_race(). data_race() is correct here.
> >
> > Why?
>
> Lemme answer that to the extent why _I_ chose data_race() - aside of my
> likely confusion over our IRC conversation.
>
> The code does not really care about the compiler trying to be clever or
> not as it is designed to be tolerant of all sorts of concurrency
> including competing writes. It does not care about multiple reloads
> either. It neither cares about invented stores as long as these
> invented stores are not storing phantasy values.
>
> The only thing it cares about is store/load tearing, but there is no
> 'clever' way to use that because of the only valid transitions of
> 'cpunr' which comes from smp_processor_id() to TICK_DO_TIMER_NONE which
> is the only constant involved or the other way round (which is
> intentionally subject to competing stores).
>
> If the compiler is free to store the 32bit value as 4 seperate bytes or
> does invented stores with phantasy values, then there is surely a reason
> to switch to READ/WRITE_ONCE(), but that'd be a really daft reason.
>
> So my intent was to document that this code does not care about anything
> else than what I'd consider to be plain compiler bugs.
>
> My conclusion might be wrong as usual :)
Given that there is no optimization potential, then the main reason to use
data_race() instead of *_ONCE() is to prevent KCSAN from considering the
accesses when looking for data races. But that is mostly for debugging
accesses, in cases when these accesses are not really part of the
concurrent algorithm.
So if I understand the situation correctly, I would be using *ONCE().
Thanx, Paul
Powered by blists - more mailing lists