mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tom Stellard <tstellar@redhat.com>
To: Nick Desaulniers <ndesaulniers@google.com>, hpa@zytor.com
Cc: Alistair Strachan <astrachan@google.com>,
	Manoj Gupta <manojgupta@google.com>,
	Matthias Kaehlcke <mka@google.com>,
	Greg Hackmann <ghackmann@google.com>,
	sedat.dilek@gmail.com, LKML <linux-kernel@vger.kernel.org>,
	Kees Cook <keescook@google.com>
Subject: Re: [clang] stack protector and f1f029c7bf
Date: Fri, 25 May 2018 10:35:14 -0700	[thread overview]
Message-ID: <12a870df-5f9d-94d1-8318-42cfff1bedab@redhat.com> (raw)
In-Reply-To: <CAKwvOdkpWZC4vWK8hDdgUGseTmK4Hz5uDHn_mP9yc=jbfdVPmg@mail.gmail.com>

On 05/25/2018 10:31 AM, Nick Desaulniers wrote:
> On Fri, May 25, 2018 at 9:53 AM <hpa@zytor.com> wrote:
>> On May 25, 2018 9:46:42 AM PDT, Nick Desaulniers <ndesaulniers@google.com>
> wrote:
>>> On Fri, May 25, 2018 at 9:33 AM <hpa@zytor.com> wrote:
>>>> On May 25, 2018 9:27:40 AM PDT, Nick Desaulniers
>>> <ndesaulniers@google.com> wrote:
>>> When you say
>>>
>>>> It still should be available as as inline, however, but now "extern
>>> inline".
>>>
>>> Am I understanding correctly that native_save_fl should be inlined into
>>> all
>>> call sites (modulo the problematic pv_irq_ops.save_fl case)?  Because
>>> for
>>> these two assembly implementations, it's not, but maybe there's
>>> something
>>> missing in my implementation?
> 
>> Yes, that's what "extern inline" means. Maybe it needs a must inline
> annotation, but that's really messed up.
> 

What about doing something like suggested here:
https://bugs.llvm.org/show_bug.cgi?id=37512#c17

This would keep the definition in C and make it easier for compilers
to inline.

-Tom

> I don't think it's possible to inline a function from an external
> translation unit without something like LTO.
> 
> If I move the implementation of native_save_fl() to a separate .c (with out
> of line assembly) or .S, neither clang nor gcc will inline that assembly to
> any call sites, whether the declaration of native_save_fl() looks like:
> 
> extern inline unsigned long native_save_fl(void);
> 
> or
> 
> __attribute__((always_inline))
> 
> extern inline unsigned long native_save_fl(void);
> 
> I think an external copy is the best approach for the paravirt code:
> 
> diff --git a/arch/x86/kernel/irqflags.c b/arch/x86/kernel/irqflags.c
> new file mode 100644
> index 000000000000..e173ba8bee7b
> --- /dev/null
> +++ b/arch/x86/kernel/irqflags.c
> @@ -0,0 +1,24 @@
> +#include <asm/asm.h>
> +
> +extern unsigned long native_save_fl_no_stack_protector(void);
> +extern void native_restore_fl_no_stack_protector(unsigned long flags);
> +
> +asm(
> +".pushsection .text;"
> +".global native_save_fl_no_stack_protector;"
> +".type native_save_fl_no_stack_protector, @function;"
> +"native_save_fl_no_stack_protector:"
> +"pushf;"
> +"pop %" _ASM_AX ";"
> +"ret;"
> +".popsection");
> +
> +asm(
> +".pushsection .text;"
> +".global native_restore_fl_no_stack_protector;"
> +".type native_restore_fl_no_stack_protector, @function;"
> +"native_restore_fl_no_stack_protector:"
> +"push %" _ASM_DI ";"
> +"popf;"
> +"ret;"
> +".popsection");
> diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
> index 02d6f5cf4e70..8824d01c0c35 100644
> --- a/arch/x86/kernel/Makefile
> +++ b/arch/x86/kernel/Makefile
> @@ -61,6 +61,7 @@ obj-y                 += alternative.o i8253.o
> hw_breakpoint.o
>   obj-y                  += tsc.o tsc_msr.o io_delay.o rtc.o
>   obj-y                  += pci-iommu_table.o
>   obj-y                  += resource.o
> +obj-y                  += irqflags.o
> 
>   obj-y                          += process.o
>   obj-y                          += fpu/
> --- a/arch/x86/kernel/paravirt.c
> +++ b/arch/x86/kernel/paravirt.c
> @@ -322,9 +322,12 @@ struct pv_time_ops pv_time_ops = {
>          .steal_clock = native_steal_clock,
>   };
> 
> +extern unsigned long native_save_fl_no_stack_protector(void);
> +extern void native_restore_fl_no_stack_protector(unsigned long flags);
> +
>   __visible struct pv_irq_ops pv_irq_ops = {
> -       .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
> -       .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
> +       .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl_no_stack_protector),
> +       .restore_fl =
> __PV_IS_CALLEE_SAVE(native_restore_fl_no_stack_protector),
>          .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
>          .irq_enable = __PV_IS_CALLEE_SAVE(native_irq_enable),
>          .safe_halt = native_safe_halt,
> 
> Thoughts?
> 

  reply	other threads:[~2018-05-25 17:35 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-23 22:08 Nick Desaulniers
2018-05-24 10:33 ` Sedat Dilek
2018-05-24 18:12   ` Nick Desaulniers
2018-05-24 18:19 ` hpa
2018-05-24 18:24   ` Nick Desaulniers
2018-05-24 18:48     ` Alistair Strachan
2018-05-24 19:49   ` Tom Stellard
2018-05-24 21:33     ` hpa
2018-05-24 18:59 ` hpa
2018-05-24 20:26   ` Nick Desaulniers
2018-05-24 20:52     ` Nick Desaulniers
2018-05-24 21:12       ` Nick Desaulniers
2018-05-24 21:27         ` Nick Desaulniers
2018-05-24 21:56           ` H. Peter Anvin
2018-05-24 21:49         ` H. Peter Anvin
2018-05-24 21:38       ` hpa
2018-05-24 22:05     ` H. Peter Anvin
2018-05-24 22:31       ` Nick Desaulniers
2018-05-24 22:43         ` hpa
2018-05-25 16:27           ` Nick Desaulniers
2018-05-25 16:32             ` hpa
2018-05-25 16:46               ` Nick Desaulniers
2018-05-25 16:53                 ` hpa
2018-05-25 17:31                   ` Nick Desaulniers
2018-05-25 17:35                     ` Tom Stellard [this message]
2018-05-25 17:49                       ` Nick Desaulniers
2018-05-25 17:57                         ` hpa
2018-05-25 17:59                         ` Nick Desaulniers
2018-05-25 17:56                     ` hpa
2018-05-25 20:36                       ` Nick Desaulniers
2018-05-25 21:06                         ` H. Peter Anvin
2018-05-25 22:38                           ` Nick Desaulniers
2018-05-31  6:50                             ` Nick Desaulniers
2018-06-01 17:13                               ` Nick Desaulniers
2018-05-25 16:34             ` hpa
2018-05-25  8:24     ` Sedat Dilek

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=12a870df-5f9d-94d1-8318-42cfff1bedab@redhat.com \
    --to=tstellar@redhat.com \
    --cc=astrachan@google.com \
    --cc=ghackmann@google.com \
    --cc=hpa@zytor.com \
    --cc=keescook@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=manojgupta@google.com \
    --cc=mka@google.com \
    --cc=ndesaulniers@google.com \
    --cc=sedat.dilek@gmail.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

all inboxes | Powered by JetHome®