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

From: David Laight
Date: Sun Mar 09 2025 - 05:46:29 EST


On Sun, 9 Mar 2025 08:50:08 +0100
Uros Bizjak <ubizjak@xxxxxxxxx> wrote:

> On Sat, Mar 8, 2025 at 8:08 PM H. Peter Anvin <hpa@xxxxxxxxx> 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?

David