From: Nadav Amit <namit@vmware.com>
To: Kees Cook <keescook@chromium.org>
Cc: LKML <linux-kernel@vger.kernel.org>, X86 ML <x86@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Jan Beulich <JBeulich@suse.com>,
Josh Poimboeuf <jpoimboe@redhat.com>
Subject: Re: [PATCH v2 3/9] x86: refcount: prevent gcc distortions
Date: Mon, 4 Jun 2018 22:20:50 +0000 [thread overview]
Message-ID: <BB35D478-3BB6-4C95-9BB0-D49E3C501D37@vmware.com> (raw)
In-Reply-To: <CAGXu5jJFUMsQFhxeZivbQZwQRPwdJr6gD8EkKfzasWr2SBoggQ@mail.gmail.com>
Kees Cook <keescook@chromium.org> wrote:
> On Mon, Jun 4, 2018 at 4:21 AM, Nadav Amit <namit@vmware.com> wrote:
>> GCC considers the number of statements in inlined assembly blocks,
>> according to new-lines and semicolons, as an indication to the cost of
>> the block in time and space. This data is distorted by the kernel code,
>> which puts information in alternative sections. As a result, the
>> compiler may perform incorrect inlining and branch optimizations.
>>
>> The solution is to set an assembly macro and call it from the inlined
>> assembly block. As a result GCC considers the inline assembly block as
>> a single instruction.
>>
>> This patch allows to inline functions such as __get_seccomp_filter().
>> Interestingly, this allows more aggressive inlining while reducing the
>> kernel size.
>>
>> text data bss dec hex filename
>> 18140970 10225412 2957312 31323694 1ddf62e ./vmlinux before
>> 18140140 10225284 2957312 31322736 1ddf270 ./vmlinux after (-958)
>>
>> Static text symbols:
>> Before: 40302
>> After: 40286 (-16)
>>
>> Functions such as kref_get(), free_user(), fuse_file_get() now get
>> inlined.
>>
>> Cc: Thomas Gleixner <tglx@linutronix.de>
>> Cc: Ingo Molnar <mingo@redhat.com>
>> Cc: "H. Peter Anvin" <hpa@zytor.com>
>> Cc: x86@kernel.org
>> Cc: Kees Cook <keescook@chromium.org>
>> Cc: Jan Beulich <JBeulich@suse.com>
>> Cc: Josh Poimboeuf <jpoimboe@redhat.com>
>>
>> Signed-off-by: Nadav Amit <namit@vmware.com>
>> ---
>> arch/x86/include/asm/refcount.h | 73 ++++++++++++++++++++-------------
>> arch/x86/kernel/macros.S | 1 +
>> 2 files changed, 45 insertions(+), 29 deletions(-)
>>
>> diff --git a/arch/x86/include/asm/refcount.h b/arch/x86/include/asm/refcount.h
>> index 4cf11d88d3b3..53462f32b58e 100644
>> --- a/arch/x86/include/asm/refcount.h
>> +++ b/arch/x86/include/asm/refcount.h
>> @@ -4,6 +4,9 @@
>> * x86-specific implementation of refcount_t. Based on PAX_REFCOUNT from
>> * PaX/grsecurity.
>> */
>> +
>> +#ifndef __ASSEMBLY__
>
> Can you swap the order here, so that the asm macros are visible first
> in the file?
>
> #ifdef __ASSEMBLY__
> ...macros
> #else
> ....C
> #endif
Done. I also noticed that I forgot in one instance (REFCOUNT_CHECK_LT_ZERO)
to explicitly mark the parameter name (“counter=\counter”), so I’ll fix it
as well in the next version.
next prev parent reply other threads:[~2018-06-04 22:20 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-04 11:21 [PATCH v2 0/9] x86: macrofying inline asm for better compilation Nadav Amit
2018-06-04 11:21 ` [PATCH v2 1/9] Makefile: Prepare for using macros for inline asm Nadav Amit
2018-06-04 11:21 ` [PATCH v2 2/9] x86: objtool: use asm macro for better compiler decisions Nadav Amit
2018-06-04 19:04 ` Josh Poimboeuf
2018-06-05 5:41 ` kbuild test robot
2018-06-04 11:21 ` [PATCH v2 3/9] x86: refcount: prevent gcc distortions Nadav Amit
2018-06-04 22:06 ` Kees Cook
2018-06-04 22:20 ` Nadav Amit [this message]
2018-06-05 8:26 ` kbuild test robot
2018-06-04 11:21 ` [PATCH v2 4/9] x86: alternatives: macrofy locks for better inlining Nadav Amit
2018-06-05 5:36 ` kbuild test robot
2018-06-05 14:07 ` kbuild test robot
2018-06-07 3:05 ` [lkp-robot] [x86] 1a39381d70: WARNING:at_kernel/locking/mutex.c:#__mutex_unlock_slowpath kernel test robot
2018-06-04 11:21 ` [PATCH v2 5/9] x86: bug: prevent gcc distortions Nadav Amit
2018-06-05 7:34 ` kbuild test robot
2018-06-04 11:21 ` [PATCH v2 6/9] x86: prevent inline distortion by paravirt ops Nadav Amit
2018-06-04 11:21 ` [PATCH v2 7/9] x86: extable: use macros instead of inline assembly Nadav Amit
2018-06-04 11:21 ` [PATCH v2 8/9] x86: cpufeature: " Nadav Amit
2018-06-04 11:21 ` [PATCH v2 9/9] x86: jump-labels: " Nadav Amit
2018-06-04 19:05 ` [PATCH v2 0/9] x86: macrofying inline asm for better compilation Josh Poimboeuf
2018-06-04 19:56 ` Nadav Amit
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=BB35D478-3BB6-4C95-9BB0-D49E3C501D37@vmware.com \
--to=namit@vmware.com \
--cc=JBeulich@suse.com \
--cc=hpa@zytor.com \
--cc=jpoimboe@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--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 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).