2018-03-19 22:34:43

by Peter Zijlstra

[permalink] [raw]
Subject: [PATCH 1/2] x86: Force asm-goto

We want to start using asm-goto to guarantee the absence of dynamic
branches (and thus speculation).

A primary prerequisite for this is of course that the compiler
supports asm-goto. This effecively lifts the minimum GCC version to
build an x86 kernel to gcc-4.5.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
---
Makefile | 13 +++++++------
arch/x86/Makefile | 4 ++++
2 files changed, 11 insertions(+), 6 deletions(-)

--- a/Makefile
+++ b/Makefile
@@ -494,6 +494,13 @@ RETPOLINE_CFLAGS_CLANG := -mretpoline-ex
RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
export RETPOLINE_CFLAGS

+# check for 'asm goto'
+ifeq ($(shell $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
+ CC_HAVE_ASM_GOTO := 1
+ KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
+ KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
+endif
+
ifeq ($(config-targets),1)
# ===========================================================================
# *config targets only - make sure prerequisites are updated, and descend
@@ -658,12 +665,6 @@ KBUILD_CFLAGS += $(call cc-ifversion, -l
# Tell gcc to never replace conditional load with a non-conditional one
KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)

-# check for 'asm goto'
-ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
- KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
- KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
-endif
-
include scripts/Makefile.kcov
include scripts/Makefile.gcc-plugins

--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -181,6 +181,10 @@ ifdef CONFIG_FUNCTION_GRAPH_TRACER
endif
endif

+ifndef CC_HAVE_ASM_GOTO
+ $(error Compiler lacks asm-goto support.)
+endif
+
#
# Jump labels need '-maccumulate-outgoing-args' for gcc < 4.5.2 to prevent a
# GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46226). There's no way




2018-03-19 20:00:49

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86: Force asm-goto

On Mon, 19 Mar 2018, Peter Zijlstra wrote:

> We want to start using asm-goto to guarantee the absence of dynamic
> branches (and thus speculation).
>
> A primary prerequisite for this is of course that the compiler
> supports asm-goto. This effecively lifts the minimum GCC version to
> build an x86 kernel to gcc-4.5.
>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> ---
> Makefile | 13 +++++++------
> arch/x86/Makefile | 4 ++++
> 2 files changed, 11 insertions(+), 6 deletions(-)
>
> --- a/Makefile
> +++ b/Makefile
> @@ -494,6 +494,13 @@ RETPOLINE_CFLAGS_CLANG := -mretpoline-ex
> RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
> export RETPOLINE_CFLAGS
>
> +# check for 'asm goto'
> +ifeq ($(shell $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)

Why are you not using the shell-cached version which you remove further
down?

Thanks,

tglx


2018-03-20 01:49:57

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86: Force asm-goto

On Mon, Mar 19, 2018 at 08:57:48PM +0100, Thomas Gleixner wrote:
> On Mon, 19 Mar 2018, Peter Zijlstra wrote:
>
> > We want to start using asm-goto to guarantee the absence of dynamic
> > branches (and thus speculation).
> >
> > A primary prerequisite for this is of course that the compiler
> > supports asm-goto. This effecively lifts the minimum GCC version to
> > build an x86 kernel to gcc-4.5.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> > ---
> > Makefile | 13 +++++++------
> > arch/x86/Makefile | 4 ++++
> > 2 files changed, 11 insertions(+), 6 deletions(-)
> >
> > --- a/Makefile
> > +++ b/Makefile
> > @@ -494,6 +494,13 @@ RETPOLINE_CFLAGS_CLANG := -mretpoline-ex
> > RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
> > export RETPOLINE_CFLAGS
> >
> > +# check for 'asm goto'
> > +ifeq ($(shell $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
>
> Why are you not using the shell-cached version which you remove further
> down?

Bah, I'm an idiot. I fixed that up at least two times, but clearly I
forgot to check that again before sending.

---
Subject: x86: Force asm-goto
From: Peter Zijlstra <[email protected]>
Date: Wed Jan 17 11:42:07 CET 2018

We want to start using asm-goto to guarantee the absence of dynamic
branches (and thus speculation).

A primary prerequisite for this is of course that the compiler
supports asm-goto. This effecively lifts the minimum GCC version to
build an x86 kernel to gcc-4.5.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
---
Makefile | 13 +++++++------
arch/x86/Makefile | 4 ++++
2 files changed, 11 insertions(+), 6 deletions(-)

--- a/Makefile
+++ b/Makefile
@@ -494,6 +494,13 @@ RETPOLINE_CFLAGS_CLANG := -mretpoline-ex
RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
export RETPOLINE_CFLAGS

+# check for 'asm goto'
+ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
+ CC_HAVE_ASM_GOTO := 1
+ KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
+ KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
+endif
+
ifeq ($(config-targets),1)
# ===========================================================================
# *config targets only - make sure prerequisites are updated, and descend
@@ -658,12 +665,6 @@ KBUILD_CFLAGS += $(call cc-ifversion, -l
# Tell gcc to never replace conditional load with a non-conditional one
KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)

-# check for 'asm goto'
-ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
- KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
- KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
-endif
-
include scripts/Makefile.kcov
include scripts/Makefile.gcc-plugins

--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -181,6 +181,10 @@ ifdef CONFIG_FUNCTION_GRAPH_TRACER
endif
endif

+ifndef CC_HAVE_ASM_GOTO
+ $(error Compiler lacks asm-goto support.)
+endif
+
#
# Jump labels need '-maccumulate-outgoing-args' for gcc < 4.5.2 to prevent a
# GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46226). There's no way

Subject: [tip:x86/build] x86: Force asm-goto

Commit-ID: e501ce957a786ecd076ea0cfb10b114e6e4d0f40
Gitweb: https://git.kernel.org/tip/e501ce957a786ecd076ea0cfb10b114e6e4d0f40
Author: Peter Zijlstra <[email protected]>
AuthorDate: Wed, 17 Jan 2018 11:42:07 +0100
Committer: Thomas Gleixner <[email protected]>
CommitDate: Tue, 20 Mar 2018 10:58:02 +0100

x86: Force asm-goto

We want to start using asm-goto to guarantee the absence of dynamic
branches (and thus speculation).

A primary prerequisite for this is of course that the compiler
supports asm-goto. This effecively lifts the minimum GCC version to
build an x86 kernel to gcc-4.5.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Cc: [email protected]
Link: https://lkml.kernel.org/r/[email protected]
---
Makefile | 13 +++++++------
arch/x86/Makefile | 4 ++++
2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index d65e2e229017..6fb6fd28a124 100644
--- a/Makefile
+++ b/Makefile
@@ -494,6 +494,13 @@ RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
export RETPOLINE_CFLAGS

+# check for 'asm goto'
+ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
+ CC_HAVE_ASM_GOTO := 1
+ KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
+ KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
+endif
+
ifeq ($(config-targets),1)
# ===========================================================================
# *config targets only - make sure prerequisites are updated, and descend
@@ -658,12 +665,6 @@ KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0409, \
# Tell gcc to never replace conditional load with a non-conditional one
KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)

-# check for 'asm goto'
-ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
- KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
- KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
-endif
-
include scripts/Makefile.kcov
include scripts/Makefile.gcc-plugins

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 498c1b812300..d798e36d103c 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -181,6 +181,10 @@ ifdef CONFIG_FUNCTION_GRAPH_TRACER
endif
endif

+ifndef CC_HAVE_ASM_GOTO
+ $(error Compiler lacks asm-goto support.)
+endif
+
#
# Jump labels need '-maccumulate-outgoing-args' for gcc < 4.5.2 to prevent a
# GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46226). There's no way

2018-03-20 15:47:07

by Jonathan Corbet

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86: Force asm-goto

On Mon, 19 Mar 2018 16:41:25 +0100
Peter Zijlstra <[email protected]> wrote:

> A primary prerequisite for this is of course that the compiler
> supports asm-goto. This effecively lifts the minimum GCC version to
> build an x86 kernel to gcc-4.5.

Given that, how about a patch to Documentation/Changes to reflect the new
reality? It's not in RST yet, so you should be able to go there without
ill effect :)

Thanks,

jon

2018-03-20 15:52:43

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86: Force asm-goto

On Tue, Mar 20, 2018 at 09:45:54AM -0600, Jonathan Corbet wrote:
> On Mon, 19 Mar 2018 16:41:25 +0100
> Peter Zijlstra <[email protected]> wrote:
>
> > A primary prerequisite for this is of course that the compiler
> > supports asm-goto. This effecively lifts the minimum GCC version to
> > build an x86 kernel to gcc-4.5.
>
> Given that, how about a patch to Documentation/Changes to reflect the new
> reality? It's not in RST yet, so you should be able to go there without
> ill effect :)


That thing says:

GCC
---

The gcc version requirements may vary depending on the type of CPU in your
computer. jon

Which is still entirely accurate. And afaik the 3.2 minimum listed there
still works for !x86.

2018-03-20 18:46:06

by Jonathan Corbet

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86: Force asm-goto

On Tue, 20 Mar 2018 16:50:36 +0100
Peter Zijlstra <[email protected]> wrote:

> > Given that, how about a patch to Documentation/Changes to reflect the new
> > reality? It's not in RST yet, so you should be able to go there without
> > ill effect :)
>
>
> That thing says:
>
> GCC
> ---
>
> The gcc version requirements may vary depending on the type of CPU in your
> computer. jon
>
> Which is still entirely accurate. And afaik the 3.2 minimum listed there
> still works for !x86.

Well, other recent discussions established that nothing earlier than 4.1
has been observed to work anywhere for some time.

I guess what we really need is a little table of architecture-specific
minimum GCC versions so that our users actually know what's required.
I'll see if I can find a moment to pull that together at some point.

jon

2018-03-22 12:12:09

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86: Force asm-goto

On Tue 2018-03-20 16:50:36, Peter Zijlstra wrote:
> On Tue, Mar 20, 2018 at 09:45:54AM -0600, Jonathan Corbet wrote:
> > On Mon, 19 Mar 2018 16:41:25 +0100
> > Peter Zijlstra <[email protected]> wrote:
> >
> > > A primary prerequisite for this is of course that the compiler
> > > supports asm-goto. This effecively lifts the minimum GCC version to
> > > build an x86 kernel to gcc-4.5.
> >
> > Given that, how about a patch to Documentation/Changes to reflect the new
> > reality? It's not in RST yet, so you should be able to go there without
> > ill effect :)
>
>
> That thing says:
>
> GCC
> ---
>
> The gcc version requirements may vary depending on the type of CPU in your
> computer. jon
>
> Which is still entirely accurate. And afaik the 3.2 minimum listed there
> still works for !x86.

Maybe accurate, but pretty user hostile :-(.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (1.02 kB)
signature.asc (188.00 B)
Digital signature
Download all attachments

2018-03-27 17:14:41

by Anders Roxell

[permalink] [raw]
Subject: Re: [PATCH 1/2] x86: Force asm-goto

On 2018-03-19 21:13, Peter Zijlstra wrote:
> On Mon, Mar 19, 2018 at 08:57:48PM +0100, Thomas Gleixner wrote:
> > On Mon, 19 Mar 2018, Peter Zijlstra wrote:
> >
> > > We want to start using asm-goto to guarantee the absence of dynamic
> > > branches (and thus speculation).
> > >
> > > A primary prerequisite for this is of course that the compiler
> > > supports asm-goto. This effecively lifts the minimum GCC version to
> > > build an x86 kernel to gcc-4.5.
> > >
> > > Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> > > ---
> > > Makefile | 13 +++++++------
> > > arch/x86/Makefile | 4 ++++
> > > 2 files changed, 11 insertions(+), 6 deletions(-)
> > >
> > > --- a/Makefile
> > > +++ b/Makefile
> > > @@ -494,6 +494,13 @@ RETPOLINE_CFLAGS_CLANG := -mretpoline-ex
> > > RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
> > > export RETPOLINE_CFLAGS
> > >
> > > +# check for 'asm goto'
> > > +ifeq ($(shell $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
> >
> > Why are you not using the shell-cached version which you remove further
> > down?
>
> Bah, I'm an idiot. I fixed that up at least two times, but clearly I
> forgot to check that again before sending.
>
> ---
> Subject: x86: Force asm-goto
> From: Peter Zijlstra <[email protected]>
> Date: Wed Jan 17 11:42:07 CET 2018
>
> We want to start using asm-goto to guarantee the absence of dynamic
> branches (and thus speculation).
>
> A primary prerequisite for this is of course that the compiler
> supports asm-goto. This effecively lifts the minimum GCC version to
> build an x86 kernel to gcc-4.5.

With this patch applied I'm not able to do "make kernelversion" without
any toolchain to get the kernel version, I was able to do that before.

Cheers,
Anders

>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
> ---
> Makefile | 13 +++++++------
> arch/x86/Makefile | 4 ++++
> 2 files changed, 11 insertions(+), 6 deletions(-)
>
> --- a/Makefile
> +++ b/Makefile
> @@ -494,6 +494,13 @@ RETPOLINE_CFLAGS_CLANG := -mretpoline-ex
> RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
> export RETPOLINE_CFLAGS
>
> +# check for 'asm goto'
> +ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
> + CC_HAVE_ASM_GOTO := 1
> + KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
> + KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
> +endif
> +
> ifeq ($(config-targets),1)
> # ===========================================================================
> # *config targets only - make sure prerequisites are updated, and descend
> @@ -658,12 +665,6 @@ KBUILD_CFLAGS += $(call cc-ifversion, -l
> # Tell gcc to never replace conditional load with a non-conditional one
> KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
>
> -# check for 'asm goto'
> -ifeq ($(call shell-cached,$(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
> - KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
> - KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
> -endif
> -
> include scripts/Makefile.kcov
> include scripts/Makefile.gcc-plugins
>
> --- a/arch/x86/Makefile
> +++ b/arch/x86/Makefile
> @@ -181,6 +181,10 @@ ifdef CONFIG_FUNCTION_GRAPH_TRACER
> endif
> endif
>
> +ifndef CC_HAVE_ASM_GOTO
> + $(error Compiler lacks asm-goto support.)
> +endif
> +
> #
> # Jump labels need '-maccumulate-outgoing-args' for gcc < 4.5.2 to prevent a
> # GCC bug (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46226). There's no way