linux-toolchains.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH 02/24] x86/traps: Move arch/x86/kernel/traps.c to arch/x86/entry/
       [not found]             ` <YTDS/p/bnsTFzNES@hirez.programming.kicks-ass.net>
@ 2021-09-02 17:05               ` Nick Desaulniers
  2021-09-02 17:19                 ` Miguel Ojeda
  2021-09-03  7:36                 ` Martin Liška
  0 siblings, 2 replies; 6+ messages in thread
From: Nick Desaulniers @ 2021-09-02 17:05 UTC (permalink / raw)
  To: Peter Zijlstra, Miguel Ojeda, Martin Liška
  Cc: Lai Jiangshan, Joerg Roedel, Lai Jiangshan, linux-kernel,
	Andy Lutomirski, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	x86, H. Peter Anvin, Daniel Bristot de Oliveira, Brijesh Singh,
	Andy Shevchenko, Arvind Sankar, Chester Lin, Juergen Gross,
	andrew.cooper3, linux-toolchains

On Thu, Sep 2, 2021 at 6:36 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Thu, Sep 02, 2021 at 02:05:41PM +0200, Peter Zijlstra wrote:
> > On Thu, Sep 02, 2021 at 07:54:25PM +0800, Lai Jiangshan wrote:
> > > For example, stack-protector is instrumenting many noninstr functions now
> > > if the CONFIG is yes.  It is normally Ok and gcc is adding per-function control
> > > on it.
> >
> > IIRC the latest compiler have an attribute for this too, that really
> > should be added to noinstr. Lemme go find.
>
> Something like so... Nick ?
>
> diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h
> index 49b0ac8b6fd3..6a15c3d8df5c 100644
> --- a/include/linux/compiler-clang.h
> +++ b/include/linux/compiler-clang.h
> @@ -62,6 +62,12 @@
>  #define __no_sanitize_coverage
>  #endif
>
> +#if defined(CONFIG_STACKPROTECTOR)
> +#define __no_stack_protector __attribute__((no_stack_protector))
> +#else
> +#define __no_stack_protector
> +#endif
> +
>  /*
>   * Not all versions of clang implement the type-generic versions
>   * of the builtin overflow checkers. Fortunately, clang implements
> diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
> index cb9217fc60af..7ac0a3f11ba9 100644
> --- a/include/linux/compiler-gcc.h
> +++ b/include/linux/compiler-gcc.h
> @@ -128,6 +128,12 @@
>  #define __no_sanitize_coverage
>  #endif
>
> +#if defined(CONFIG_STACKPROTECTOR) && __has_attribute__(__no_stack_protector__)
> +#define __no_stack_protector __attribute__((no_stack_protector))
> +#else
> +#define __no_stack_protector
> +#endif
> +

The above 2 hunks should go in include/linux/compiler_attributes.h,
but yes.  I'd been meaning to send such a patch; it's nice to have
finer grain function-level control over -fno-stack-protector which
significantly hurts ergonomics for things like LTO.  IIRC GCC only
added the attribute recently in the 10.X release, so it might be too
new to rely on quite yet.

>  #if GCC_VERSION >= 50100
>  #define COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW 1
>  #endif
> diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
> index e4ea86fc584d..5ae1c08dba8d 100644
> --- a/include/linux/compiler_types.h
> +++ b/include/linux/compiler_types.h
> @@ -210,7 +210,8 @@ struct ftrace_likely_data {
>  /* Section for code which can't be instrumented at all */
>  #define noinstr                                                                \
>         noinline notrace __attribute((__section__(".noinstr.text")))    \
> -       __no_kcsan __no_sanitize_address __no_profile __no_sanitize_coverage
> +       __no_kcsan __no_sanitize_address __no_profile __no_sanitize_coverage \
> +       __no_stack_protector
>
>  #endif /* __KERNEL__ */
>


-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 02/24] x86/traps: Move arch/x86/kernel/traps.c to arch/x86/entry/
  2021-09-02 17:05               ` [PATCH 02/24] x86/traps: Move arch/x86/kernel/traps.c to arch/x86/entry/ Nick Desaulniers
@ 2021-09-02 17:19                 ` Miguel Ojeda
  2021-09-02 17:23                   ` Nick Desaulniers
  2021-09-03  7:36                 ` Martin Liška
  1 sibling, 1 reply; 6+ messages in thread
From: Miguel Ojeda @ 2021-09-02 17:19 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Peter Zijlstra, Miguel Ojeda, Martin Liška, Lai Jiangshan,
	Joerg Roedel, Lai Jiangshan, linux-kernel, Andy Lutomirski,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, Daniel Bristot de Oliveira, Brijesh Singh,
	Andy Shevchenko, Arvind Sankar, Chester Lin, Juergen Gross,
	Andrew Cooper, linux-toolchains

On Thu, Sep 2, 2021 at 7:05 PM Nick Desaulniers <ndesaulniers@google.com> wrote:
>
> The above 2 hunks should go in include/linux/compiler_attributes.h,
> but yes.  I'd been meaning to send such a patch; it's nice to have

Note that `compiler_attributes.h` does not keep attributes that depend
on config options.

On one hand, I feel we should put them there. On the other hand, I
want to avoid making a mess again since the purpose of the file is to
keep things clean for the majority of attributes.

Perhaps we should do a middle-ground, and only allow those that depend
on a single config option, i.e. no nesting `#if`s or complex
conditions.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 02/24] x86/traps: Move arch/x86/kernel/traps.c to arch/x86/entry/
  2021-09-02 17:19                 ` Miguel Ojeda
@ 2021-09-02 17:23                   ` Nick Desaulniers
  0 siblings, 0 replies; 6+ messages in thread
From: Nick Desaulniers @ 2021-09-02 17:23 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Peter Zijlstra, Miguel Ojeda, Martin Liška, Lai Jiangshan,
	Joerg Roedel, Lai Jiangshan, linux-kernel, Andy Lutomirski,
	Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	H. Peter Anvin, Daniel Bristot de Oliveira, Brijesh Singh,
	Andy Shevchenko, Arvind Sankar, Chester Lin, Juergen Gross,
	Andrew Cooper, linux-toolchains

On Thu, Sep 2, 2021 at 10:19 AM Miguel Ojeda
<miguel.ojeda.sandonis@gmail.com> wrote:
>
> On Thu, Sep 2, 2021 at 7:05 PM Nick Desaulniers <ndesaulniers@google.com> wrote:
> >
> > The above 2 hunks should go in include/linux/compiler_attributes.h,
> > but yes.  I'd been meaning to send such a patch; it's nice to have
>
> Note that `compiler_attributes.h` does not keep attributes that depend
> on config options.

Sure, I'd drop the config check and define it conditionally on the
__has_attribute check alone. Does it hurt to mark functions as
__attribute__((no_stack_protector)) when we're not building with
-fstack-protector*? Nope!

> On one hand, I feel we should put them there. On the other hand, I
> want to avoid making a mess again since the purpose of the file is to
> keep things clean for the majority of attributes.
>
> Perhaps we should do a middle-ground, and only allow those that depend
> on a single config option, i.e. no nesting `#if`s or complex
> conditions.
-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 02/24] x86/traps: Move arch/x86/kernel/traps.c to arch/x86/entry/
  2021-09-02 17:05               ` [PATCH 02/24] x86/traps: Move arch/x86/kernel/traps.c to arch/x86/entry/ Nick Desaulniers
  2021-09-02 17:19                 ` Miguel Ojeda
@ 2021-09-03  7:36                 ` Martin Liška
  2021-09-07 21:12                   ` Nick Desaulniers
  1 sibling, 1 reply; 6+ messages in thread
From: Martin Liška @ 2021-09-03  7:36 UTC (permalink / raw)
  To: Nick Desaulniers, Peter Zijlstra, Miguel Ojeda
  Cc: Lai Jiangshan, Joerg Roedel, Lai Jiangshan, linux-kernel,
	Andy Lutomirski, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	x86, H. Peter Anvin, Daniel Bristot de Oliveira, Brijesh Singh,
	Andy Shevchenko, Arvind Sankar, Chester Lin, Juergen Gross,
	andrew.cooper3, linux-toolchains

On 9/2/21 19:05, Nick Desaulniers wrote:
> IIRC GCC only
> added the attribute recently in the 10.X release, so it might be too
> new to rely on quite yet.

The no_stack_protector attribute was actually added in the GCC 11.x release:
https://gcc.gnu.org/gcc-11/changes.html

Note the compiler is definitely used by Fedora, openSUSE Tumbleweed
and other cutting edge distributions.

Cheers,
Martin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 02/24] x86/traps: Move arch/x86/kernel/traps.c to arch/x86/entry/
  2021-09-03  7:36                 ` Martin Liška
@ 2021-09-07 21:12                   ` Nick Desaulniers
  2021-09-08  7:33                     ` Martin Liška
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Desaulniers @ 2021-09-07 21:12 UTC (permalink / raw)
  To: Martin Liška
  Cc: Peter Zijlstra, Miguel Ojeda, Lai Jiangshan, Joerg Roedel,
	Lai Jiangshan, linux-kernel, Andy Lutomirski, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, x86, H. Peter Anvin,
	Daniel Bristot de Oliveira, Brijesh Singh, Andy Shevchenko,
	Arvind Sankar, Chester Lin, Juergen Gross, andrew.cooper3,
	linux-toolchains

On Fri, Sep 3, 2021 at 12:36 AM Martin Liška <mliska@suse.cz> wrote:
>
> On 9/2/21 19:05, Nick Desaulniers wrote:
> > IIRC GCC only
> > added the attribute recently in the 10.X release, so it might be too
> > new to rely on quite yet.
>
> The no_stack_protector attribute was actually added in the GCC 11.x release:
> https://gcc.gnu.org/gcc-11/changes.html

Ah right, that lays more weight though that this feature is still too
new to rely on quite yet.  Martin, do you know if what happens with
regards to inlining when the callee and caller mismatch on this
function attribute in GCC?  This is very much a problem for the
kernel.

> Note the compiler is definitely used by Fedora, openSUSE Tumbleweed
> and other cutting edge distributions.

Kernel supports GCC 4.9+ currently. This feature can only be emulated
with the coarse grain -fno-stack-protector (or gnu_inline with out of
line assembler definition...:( ).
-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 02/24] x86/traps: Move arch/x86/kernel/traps.c to arch/x86/entry/
  2021-09-07 21:12                   ` Nick Desaulniers
@ 2021-09-08  7:33                     ` Martin Liška
  0 siblings, 0 replies; 6+ messages in thread
From: Martin Liška @ 2021-09-08  7:33 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Peter Zijlstra, Miguel Ojeda, Lai Jiangshan, Joerg Roedel,
	Lai Jiangshan, linux-kernel, Andy Lutomirski, Thomas Gleixner,
	Ingo Molnar, Borislav Petkov, x86, H. Peter Anvin,
	Daniel Bristot de Oliveira, Brijesh Singh, Andy Shevchenko,
	Arvind Sankar, Chester Lin, Juergen Gross, andrew.cooper3,
	linux-toolchains

On 9/7/21 23:12, Nick Desaulniers wrote:
> On Fri, Sep 3, 2021 at 12:36 AM Martin Liška <mliska@suse.cz> wrote:
>>
>> On 9/2/21 19:05, Nick Desaulniers wrote:
>>> IIRC GCC only
>>> added the attribute recently in the 10.X release, so it might be too
>>> new to rely on quite yet.
>>
>> The no_stack_protector attribute was actually added in the GCC 11.x release:
>> https://gcc.gnu.org/gcc-11/changes.html
> 
> Ah right, that lays more weight though that this feature is still too
> new to rely on quite yet.

Sure.

> Martin, do you know if what happens with
> regards to inlining when the callee and caller mismatch on this
> function attribute in GCC?  This is very much a problem for the
> kernel.

That's a know issue that was already discusses both in a Kernel mailing and
GCC bugzilla:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94722#c9

Martin

> 
>> Note the compiler is definitely used by Fedora, openSUSE Tumbleweed
>> and other cutting edge distributions.
> 
> Kernel supports GCC 4.9+ currently. This feature can only be emulated
> with the coarse grain -fno-stack-protector (or gnu_inline with out of
> line assembler definition...:( ).
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-09-08  7:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20210831175025.27570-1-jiangshanlai@gmail.com>
     [not found] ` <20210831175025.27570-3-jiangshanlai@gmail.com>
     [not found]   ` <YTCGov+vvAMvso7q@suse.de>
     [not found]     ` <1f327579-e62a-df65-0763-e88243829db3@linux.alibaba.com>
     [not found]       ` <YTCsWpSmPYvXa1xz@hirez.programming.kicks-ass.net>
     [not found]         ` <4c589fef-8c98-a6fc-693f-b205a7710e42@linux.alibaba.com>
     [not found]           ` <YTC+FTo4uLLdyBxA@hirez.programming.kicks-ass.net>
     [not found]             ` <YTDS/p/bnsTFzNES@hirez.programming.kicks-ass.net>
2021-09-02 17:05               ` [PATCH 02/24] x86/traps: Move arch/x86/kernel/traps.c to arch/x86/entry/ Nick Desaulniers
2021-09-02 17:19                 ` Miguel Ojeda
2021-09-02 17:23                   ` Nick Desaulniers
2021-09-03  7:36                 ` Martin Liška
2021-09-07 21:12                   ` Nick Desaulniers
2021-09-08  7:33                     ` Martin Liška

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).