From: Ingo Molnar <mingo@kernel.org>
To: Borislav Petkov <bp@alien8.de>
Cc: Uros Bizjak <ubizjak@gmail.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] x86/asm: Use asm_inline() instead of asm() in __untagged_addr()
Date: Mon, 17 Mar 2025 10:28:08 +0100 [thread overview]
Message-ID: <Z9frKMLYnhZI0MDD@gmail.com> (raw)
In-Reply-To: <Z9fk2NMBRHB9Eu5h@gmail.com>
* Ingo Molnar <mingo@kernel.org> 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
next prev parent reply other threads:[~2025-03-17 9:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-14 9:30 [PATCH] x86/asm: Use asm_inline() instead of asm() in __untagged_addr() Uros Bizjak
2025-03-14 11:25 ` Borislav Petkov
2025-03-14 13:22 ` Uros Bizjak
2025-03-14 13:34 ` Borislav Petkov
2025-03-17 9:01 ` Ingo Molnar
2025-03-17 9:28 ` Ingo Molnar [this message]
2025-03-17 18:34 ` H. Peter Anvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z9frKMLYnhZI0MDD@gmail.com \
--to=mingo@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=ubizjak@gmail.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.