[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20260206182650.6c21b0ff@pumpkin>
Date: Fri, 6 Feb 2026 18:26:50 +0000
From: David Laight <david.laight.linux@...il.com>
To: Marco Elver <elver@...gle.com>
Cc: Will Deacon <will@...nel.org>, Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>, Thomas Gleixner <tglx@...utronix.de>, Boqun
Feng <boqun.feng@...il.com>, Waiman Long <longman@...hat.com>, Bart Van
Assche <bvanassche@....org>, llvm@...ts.linux.dev, Catalin Marinas
<catalin.marinas@....com>, Arnd Bergmann <arnd@...db.de>,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org, kernel
test robot <lkp@...el.com>, Boqun Feng <boqun@...nel.org>, Linus Torvalds
<torvalds@...ux-foundation.org>, Al Viro <viro@...iv.linux.org.uk>
Subject: Re: [PATCH v3 3/3] arm64, compiler-context-analysis: Permit alias
analysis through __READ_ONCE() with CONFIG_LTO=y
On Fri, 6 Feb 2026 16:09:35 +0100
Marco Elver <elver@...gle.com> wrote:
> On Wed, 4 Feb 2026 at 15:15, Will Deacon <will@...nel.org> wrote:
> >
> > On Wed, Feb 04, 2026 at 02:14:00PM +0100, Peter Zijlstra wrote:
> > > On Wed, Feb 04, 2026 at 11:46:02AM +0100, Marco Elver wrote:
> > > > On Tue, 3 Feb 2026 at 12:47, Will Deacon <will@...nel.org> wrote:
> > > > [...]
> > > > > > > What does GCC do with this? :/
> > > > > >
> > > > > > GCC currently doesn't see it, LTO is clang only.
> > > > >
> > > > > LTO is just one way that a compiler could end up breaking dependency
> > > > > chains, so I really want to maintain the option to enable this path for
> > > > > GCC in case we run into problems caused by other optimisations in future.
> > > >
> > > > It will work for GCC, but only from GCC 11. Before that __auto_type
> > > > does not drop qualifiers:
> > > > https://godbolt.org/z/sc5bcnzKd (switch to GCC 11 to see it compile)
> > > >
> > > > So to summarize, all supported Clang versions deal with __auto_type
> > > > correctly for the fallback; GCC from version 11 does (kernel currently
> > > > supports GCC 8 and above). From GCC 14 and Clang 19 we have
> > > > __typeof_unqual__.
> > > >
> > > > I really don't see another way forward; there's no other good way to
> > > > solve this issue. I would advise against pessimizing new compilers and
> > > > features because maybe one day we might still want to enable this
> > > > version of READ_ONCE() for GCC 8-10.
> > > >
> > > > Should we one day choose to enable this READ_ONCE() version for GCC,
> > > > we will (a) either have bumped the minimum GCC version to 11+, or (b)
> > > > we can only do so from GCC 11. At this point GCC 11 was released 5
> > > > years ago!
> > >
> > > There is, from this thread:
> > >
> > > https://lkml.kernel.org/r/20260111182010.GH3634291@ZenIV
> > >
> > > another trick to strip qualifiers:
> > >
> > > #define unqual_non_array(T) __typeof__(((T(*)(void))0)())
> > >
> > > which will work from GCC-8.4 onwards. Arguably, it should be possible to
> > > raise the minimum from 8 to 8.4 (IMO).
>
> That looks like an interesting option.
>
> > That sounds reasonable to me but I'm not usually the one to push back
> > on raising the minimum compiler version!
> >
> > > But yes; in general I think it is fine to have 'old' compilers generate
> > > suboptimal code.
> >
> > I'm absolutely fine with the codegen being terrible for ancient
> > toolchains as long as it's correct.
>
> From that discussion a month ago and this one, it seems we need
> something to fix __unqual_scalar_typeof().
>
> What's the way forward?
>
> 1. Bump minimum GCC version to 8.4. Replace __unqual_scalar_typeof()
> for old compilers with the better unqual_non_array hack?
>
> 2. Leave __unqual_scalar_typeof() as-is. The patch "compiler: Use
> __typeof_unqual__() for __unqual_scalar_typeof()" will fix the codegen
> issues for new compilers. Doesn't fix not dropping 'const' for old
> compilers for non-scalar types, and requires localized workarounds
> (like this patch here).
>
> Either way we need a fix for this arm64 LTO version to fix the
> context-analysis "see through" the inline asm (how this patch series
> started).
>
> Option #1 needs a lot more due-diligence and testing that it all works
> for all compilers and configs (opening Pandora's Box :-)). For option
> #2 we just need these patches here to at least fix the acute issue
> with this arm64 LTO version.
Option 3.
Look are where/why they are used and change the code to do it differently.
Don't forget the similar __unsigned_scalar_typeof() in bitfield.h.
(I posted a patch that nuked that one not long ago - used sizeof instead.)
The one in minmax_array (in minmax.h) is particularly pointless.
The value 'suffers' integer promotion as soon as it is used, nothing
wrong with 'auto _x = x + 0' there.
That will work elsewhere.
David
Powered by blists - more mailing lists