From: Kees Cook <keescook@chromium.org>
To: Nadav Amit <namit@vmware.com>
Cc: Ingo Molnar <mingo@redhat.com>,
LKML <linux-kernel@vger.kernel.org>, X86 ML <x86@kernel.org>,
Masahiro Yamada <yamada.masahiro@socionext.com>,
Sam Ravnborg <sam@ravnborg.org>,
Alok Kataria <akataria@vmware.com>,
Christopher Li <sparse@chrisli.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"H. Peter Anvin" <hpa@zytor.com>, Jan Beulich <JBeulich@suse.com>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Juergen Gross <jgross@suse.com>,
Kate Stewart <kstewart@linuxfoundation.org>,
Sparse Mailing-list <linux-sparse@vger.kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Philippe Ombredanne <pombredanne@nexb.com>,
Thomas Gleixner <tglx@linutronix.de>,
virtualization@lists.linux-foundation.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Chris Zankel <chris@zankel.net>,
Max Filippov <jcmvbkbc@gmail.com>,
linux-xtensa@linux-xtensa.org
Subject: Re: [PATCH v8 00/10] x86: macrofying inline asm for better compilation
Date: Fri, 21 Sep 2018 11:26:38 -0700 [thread overview]
Message-ID: <CAGXu5jK307b+bs6h-1f6dhRCj3HfoQQmbACuurOE9RbhzijHAQ@mail.gmail.com> (raw)
In-Reply-To: <20180918212847.199085-1-namit@vmware.com>
On Tue, Sep 18, 2018 at 2:28 PM, Nadav Amit <namit@vmware.com> wrote:
> This patch-set deals with an interesting yet stupid problem: kernel code
> that does not get inlined despite its simplicity. There are several
> causes for this behavior: "cold" attribute on __init, different function
> optimization levels; conditional constant computations based on
> __builtin_constant_p(); and finally large inline assembly blocks.
>
> This patch-set deals with the inline assembly problem. I separated these
> patches from the others (that were sent in the RFC) for easier
> inclusion. I also separated the removal of unnecessary new-lines which
> would be sent separately.
>
> The problem with inline assembly is that inline assembly is often used
> by the kernel for things that are other than code - for example,
> assembly directives and data. GCC however is oblivious to the content of
> the blocks and assumes their cost in space and time is proportional to
> the number of the perceived assembly "instruction", according to the
> number of newlines and semicolons. Alternatives, paravirt and other
> mechanisms are affected, causing code not to be inlined, and degrading
> compilation quality in general.
>
> The solution that this patch-set carries for this problem is to create
> an assembly macro, and then call it from the inline assembly block. As
> a result, the compiler sees a single "instruction" and assigns the more
> appropriate cost to the code.
>
> To avoid uglification of the code, as many noted, the macros are first
> precompiled into an assembly file, which is later assembled together
> with the C files. This also enables to avoid duplicate implementation
> that was set before for the asm and C code. This can be seen in the
> exception table changes.
>
> Overall this patch-set slightly increases the kernel size (my build was
> done using my Ubuntu 18.04 config + localyesconfig for the record):
>
> text data bss dec hex filename
> 18140829 10224724 2957312 31322865 1ddf2f1 ./vmlinux before
> 18163608 10227348 2957312 31348268 1de562c ./vmlinux after (+0.1%)
>
> The number of static functions in the image is reduced by 379, but
> actually inlining is even better, which does not always shows in these
> numbers: a function may be inlined causing the calling function not to
> be inlined.
>
> I ran some limited number of benchmarks, and in general the performance
> impact is not very notable. You can still see >10 cycles shaved off some
> syscalls that manipulate page-tables (e.g., mprotect()), in which
> paravirt caused many functions not to be inlined. In addition this
> patch-set can prevent issues such as [1], and improves code readability
> and maintainability.
>
> [1] https://patchwork.kernel.org/patch/10450037/
>
> v7->v8: * Add acks (Masahiro, Max)
> * Rebase on 4.19 (Ingo)
I've tested the series for booting and with the refcount lkdtm tests.
Looks good, thanks!
Tested-by: Kees Cook <keescook@chromium.org>
-Kees
--
Kees Cook
Pixel Security
prev parent reply other threads:[~2018-09-21 18:35 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-18 21:28 [PATCH v8 00/10] x86: macrofying inline asm for better compilation Nadav Amit
2018-09-18 21:28 ` [PATCH v8 01/10] xtensa: defining LINKER_SCRIPT for the linker script Nadav Amit
2018-09-18 21:28 ` [PATCH v8 02/10] Makefile: Prepare for using macros for inline asm Nadav Amit
2018-09-26 8:58 ` Rasmus Villemoes
2018-09-26 17:56 ` Nadav Amit
2018-09-27 7:52 ` Rasmus Villemoes
2018-10-01 22:01 ` Masahiro Yamada
2018-10-03 19:41 ` Nadav Amit
2018-10-02 10:59 ` Ingo Molnar
2018-10-03 19:43 ` hpa
2018-10-03 20:29 ` Nadav Amit
2018-09-18 21:28 ` [PATCH v8 03/10] x86: objtool: use asm macro for better compiler decisions Nadav Amit
2018-09-18 21:28 ` [PATCH v8 04/10] x86: refcount: prevent gcc distortions Nadav Amit
2018-09-18 21:28 ` [PATCH v8 05/10] x86: alternatives: macrofy locks for better inlining Nadav Amit
2018-09-18 21:28 ` [PATCH v8 06/10] x86: bug: prevent gcc distortions Nadav Amit
2018-09-18 21:28 ` [PATCH v8 07/10] x86: prevent inline distortion by paravirt ops Nadav Amit
2018-09-18 21:28 ` [PATCH v8 08/10] x86: extable: use macros instead of inline assembly Nadav Amit
2018-09-18 21:28 ` [PATCH v8 09/10] x86: cpufeature: " Nadav Amit
2018-09-18 21:28 ` [PATCH v8 10/10] x86: jump-labels: " Nadav Amit
2018-09-21 18:26 ` Kees Cook [this message]
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=CAGXu5jK307b+bs6h-1f6dhRCj3HfoQQmbACuurOE9RbhzijHAQ@mail.gmail.com \
--to=keescook@chromium.org \
--cc=JBeulich@suse.com \
--cc=akataria@vmware.com \
--cc=chris@zankel.net \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=jcmvbkbc@gmail.com \
--cc=jgross@suse.com \
--cc=jpoimboe@redhat.com \
--cc=kstewart@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sparse@vger.kernel.org \
--cc=linux-xtensa@linux-xtensa.org \
--cc=mingo@redhat.com \
--cc=namit@vmware.com \
--cc=peterz@infradead.org \
--cc=pombredanne@nexb.com \
--cc=sam@ravnborg.org \
--cc=sparse@chrisli.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=virtualization@lists.linux-foundation.org \
--cc=x86@kernel.org \
--cc=yamada.masahiro@socionext.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).