Commit a9c90037 authored by Zhenzhong Duan's avatar Zhenzhong Duan Committed by Greg Kroah-Hartman

x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support

commit 4cd24de3 upstream

Since retpoline capable compilers are widely available, make
CONFIG_RETPOLINE hard depend on the compiler capability.

Break the build when CONFIG_RETPOLINE is enabled and the compiler does not
support it. Emit an error message in that case:

 "arch/x86/Makefile:226: *** You are building kernel with non-retpoline
  compiler, please update your compiler..  Stop."

[dwmw: Fail the build with non-retpoline compiler]
Suggested-by: default avatarPeter Zijlstra <peterz@infradead.org>
Signed-off-by: default avatarZhenzhong Duan <zhenzhong.duan@oracle.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: David Woodhouse <dwmw@amazon.co.uk>
Cc: Borislav Petkov <bp@suse.de>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Michal Marek <michal.lkml@markovi.net>
Cc: <srinivas.eeda@oracle.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/cca0cb20-f9e2-4094-840b-fb0f8810cd34@defaultSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 46dfe55f
...@@ -440,10 +440,6 @@ config RETPOLINE ...@@ -440,10 +440,6 @@ config RETPOLINE
branches. Requires a compiler with -mindirect-branch=thunk-extern branches. Requires a compiler with -mindirect-branch=thunk-extern
support for full protection. The kernel may run slower. support for full protection. The kernel may run slower.
Without compiler support, at least indirect branches in assembler
code are eliminated. Since this includes the syscall entry path,
it is not entirely pointless.
config INTEL_RDT config INTEL_RDT
bool "Intel Resource Director Technology support" bool "Intel Resource Director Technology support"
default n default n
......
...@@ -241,9 +241,10 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables ...@@ -241,9 +241,10 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
# Avoid indirect branches in kernel to deal with Spectre # Avoid indirect branches in kernel to deal with Spectre
ifdef CONFIG_RETPOLINE ifdef CONFIG_RETPOLINE
ifneq ($(RETPOLINE_CFLAGS),) ifeq ($(RETPOLINE_CFLAGS),)
KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) -DRETPOLINE $(error You are building kernel with non-retpoline compiler, please update your compiler.)
endif endif
KBUILD_CFLAGS += $(RETPOLINE_CFLAGS)
endif endif
archscripts: scripts_basic archscripts: scripts_basic
......
...@@ -162,11 +162,12 @@ ...@@ -162,11 +162,12 @@
_ASM_PTR " 999b\n\t" \ _ASM_PTR " 999b\n\t" \
".popsection\n\t" ".popsection\n\t"
#if defined(CONFIG_X86_64) && defined(RETPOLINE) #ifdef CONFIG_RETPOLINE
#ifdef CONFIG_X86_64
/* /*
* Since the inline asm uses the %V modifier which is only in newer GCC, * Inline asm uses the %V modifier which is only in newer GCC
* the 64-bit one is dependent on RETPOLINE not CONFIG_RETPOLINE. * which is ensured when CONFIG_RETPOLINE is defined.
*/ */
# define CALL_NOSPEC \ # define CALL_NOSPEC \
ANNOTATE_NOSPEC_ALTERNATIVE \ ANNOTATE_NOSPEC_ALTERNATIVE \
...@@ -181,7 +182,7 @@ ...@@ -181,7 +182,7 @@
X86_FEATURE_RETPOLINE_AMD) X86_FEATURE_RETPOLINE_AMD)
# define THUNK_TARGET(addr) [thunk_target] "r" (addr) # define THUNK_TARGET(addr) [thunk_target] "r" (addr)
#elif defined(CONFIG_X86_32) && defined(CONFIG_RETPOLINE) #else /* CONFIG_X86_32 */
/* /*
* For i386 we use the original ret-equivalent retpoline, because * For i386 we use the original ret-equivalent retpoline, because
* otherwise we'll run out of registers. We don't care about CET * otherwise we'll run out of registers. We don't care about CET
...@@ -211,6 +212,7 @@ ...@@ -211,6 +212,7 @@
X86_FEATURE_RETPOLINE_AMD) X86_FEATURE_RETPOLINE_AMD)
# define THUNK_TARGET(addr) [thunk_target] "rm" (addr) # define THUNK_TARGET(addr) [thunk_target] "rm" (addr)
#endif
#else /* No retpoline for C / inline asm */ #else /* No retpoline for C / inline asm */
# define CALL_NOSPEC "call *%[thunk_target]\n" # define CALL_NOSPEC "call *%[thunk_target]\n"
# define THUNK_TARGET(addr) [thunk_target] "rm" (addr) # define THUNK_TARGET(addr) [thunk_target] "rm" (addr)
......
...@@ -251,7 +251,7 @@ static void __init spec2_print_if_secure(const char *reason) ...@@ -251,7 +251,7 @@ static void __init spec2_print_if_secure(const char *reason)
static inline bool retp_compiler(void) static inline bool retp_compiler(void)
{ {
return __is_defined(RETPOLINE); return __is_defined(CONFIG_RETPOLINE);
} }
static inline bool match_option(const char *arg, int arglen, const char *opt) static inline bool match_option(const char *arg, int arglen, const char *opt)
......
...@@ -272,10 +272,8 @@ else ...@@ -272,10 +272,8 @@ else
objtool_args += $(call cc-ifversion, -lt, 0405, --no-unreachable) objtool_args += $(call cc-ifversion, -lt, 0405, --no-unreachable)
endif endif
ifdef CONFIG_RETPOLINE ifdef CONFIG_RETPOLINE
ifneq ($(RETPOLINE_CFLAGS),)
objtool_args += --retpoline objtool_args += --retpoline
endif endif
endif
ifdef CONFIG_MODVERSIONS ifdef CONFIG_MODVERSIONS
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment