Re: [PATCH] READ_ONCE, WRITE_ONCE, kcsan: Perform checks in __*_ONCE variants

From: Qian Cai
Date: Tue May 19 2020 - 17:45:42 EST


On Tue, May 19, 2020 at 5:26 PM Marco Elver <elver@xxxxxxxxxx> wrote:
>
> On Tue, 19 May 2020 at 23:10, Qian Cai <cai@xxxxxx> wrote:
> >
> > On Tue, May 12, 2020 at 3:09 PM Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> > >
> > > On Tue, May 12, 2020 at 08:38:39PM +0200, Marco Elver wrote:
> > > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> > > > index 741c93c62ecf..e902ca5de811 100644
> > > > --- a/include/linux/compiler.h
> > > > +++ b/include/linux/compiler.h
> > > > @@ -224,13 +224,16 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
> > > > * atomicity or dependency ordering guarantees. Note that this may result
> > > > * in tears!
> > > > */
> > > > -#define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x))
> > > > +#define __READ_ONCE(x) \
> > > > +({ \
> > > > + kcsan_check_atomic_read(&(x), sizeof(x)); \
> > > > + data_race((*(const volatile __unqual_scalar_typeof(x) *)&(x))); \
> > > > +})
> > >
> > > NAK
> > >
> > > This will actively insert instrumentation into __READ_ONCE() and I need
> > > it to not have any.
> >
> > Any way to move this forward? Due to linux-next commit 6bcc8f459fe7
> > (locking/atomics: Flip fallbacks and instrumentation), it triggers a
> > lots of KCSAN warnings due to atomic ops are no longer marked.
>
> This is no longer the right solution we believe due to the various
> requirements that Peter also mentioned. See the discussion here:
> https://lkml.kernel.org/r/CANpmjNOGFqhtDa9wWpXs2kztQsSozbwsuMO5BqqW0c0g0zGfSA@xxxxxxxxxxxxxx
>
> The new solution is here:
> https://lkml.kernel.org/r/20200515150338.190344-1-elver@xxxxxxxxxx
> While it's a little inconvenient that we'll require Clang 11
> (currently available by building yourself from LLVM repo), but until
> we get GCC fixed (my patch there still pending :-/), this is probably
> the right solution going forward. If possible, please do test!

That would be quite unfortunate. The version here is still gcc-8.3.1
and clang-9.0.1 on RHEL 8.2 here. It will probably need many years to
be able to get the fixed compilers having versions that high. Sigh...
Also, I want to avoid compiling compilers on my own.