Re: [PATCH] x86/asm: Use asm_inline() instead of asm() in __untagged_addr()

From: Ingo Molnar
Date: Mon Mar 17 2025 - 05:28:52 EST



* Ingo Molnar <mingo@xxxxxxxxxx> wrote:

> But GCC cannot always do proper inlining decisions due to our
> complicated ALTERNATIVE macro constructs confusing the GCC inliner:
>
> > > ALTERNATIVE macro that expands to several pseudo directives causes
> > > instruction length estimate to count more than 20 instructions.
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> Note how the asm_inline() compiler feature was added by GCC at the
> kernel community's request to address such issues. (!)
>
> So for those reasons, in my book, eliminating a function call for
> really simple single instruction inlines is an unconditional
> improvement that doesn't require futile performance measurements - it
> 'only' requires assembly level code generation analysis in the
> changelog.

Note that at least in part this is a weakness of GCC: the compiler
isn't looking at the asm() closely enough and the 20 instructions count
vastly overestimates the true footprint of these statements.

Yet GCC is also giving us a tool: "asm __inline", which tells the
compiler that this piece of asm() statement is small. A tool that was
created at the request of the kernel community's complaints about this
issue. :-/

asm_inline() is functionally similar to __force_inline - which we
regularly apply if it has code generation benefits.

So I really don't see the harm in these patches - they have benefits in
terms of GCC code generation quality, documentation and performance:

- It documents small asm() statements by annotating them asm_inline().

- It sometimes avoids function call overhead, improving performance.

And because single-function inlining changes are next to impossible to
measure in practice in most cases, I'd suggest we skip the performance
measurement requirement if the code generation advantages on a recent
GCC version are unambiguous.

Thanks,

Ingo