Re: [PATCH -tip] x86/locking/atomic: Use asm_inline for atomic locking insns

Uros Bizjak
2025-03-09T09:57:33Z

On Sun, Mar 9, 2025 at 10:46 AM David Laight
<david.laight.linux@gmail.com> wrote:
>
> On Sun, 9 Mar 2025 08:50:08 +0100
> Uros Bizjak <ubizjak@gmail.com> wrote:
>
> > On Sat, Mar 8, 2025 at 8:08 PM H. Peter Anvin <hpa@zytor.com> wrote:
> ...
> > > In fact, I would wonder if we shouldn't simply do:
> > >
> > > #define asm __asm__ __inline__
> > > #define asm_noinline __asm__
> > >
> > > ... in other words, to make asm inline an opt-out instead of an opt-in.
>
> The asm statements themselves get inlined (typically they are in an
> always_inline wrapper), the size affects whether the calling code is inlined.
> You are now in the 'games' of I$ fetches, overall code size and TLB lookups
> (not helped by the speculative execution mitigations for 'ret').
>
> > > It is comparatively unusual that we do complex things in inline assembly
> > > that we would want gcc to treat as something that should be avoided.
> >
> > I don't think we need such radical changes. There are only a few
> > groups of instructions, nicely hidden behind macros, that need asm
> > noinline. Alternatives (gcc counted them as 20 - 23 instructions) are
> > already using asm inline (please see
> > arch/x86/include/asm/alternative.h) in their high-level macros, and my
> > proposed patch converts all asm using LOCK_PREFIX by amending macros
> > in 7 header files.
>
> The other ones that are likely to get mis-sized are the ones that change
> the section to add annotations.
> The size overestimate may be better in order to reduce the number of
> annotations?

Yes, this is why I think it is better to use asm inline on a per-case
basis. While ALTERNATIVE and LOCK_HERE instructions result in one insn
(and can be trivially amended with asm inline to instruct the compiler
about this fact), this may not always be the case.

Uros.