Skip to content

Commit 4cd24de

Browse files
Zhenzhong DuanKAGA-KOKO
authored andcommitted
x86/retpoline: Make CONFIG_RETPOLINE depend on compiler support
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: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@oracle.com> Signed-off-by: Thomas 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@default
1 parent 2e6e902 commit 4cd24de

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

arch/x86/Kconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,6 @@ config RETPOLINE
444444
branches. Requires a compiler with -mindirect-branch=thunk-extern
445445
support for full protection. The kernel may run slower.
446446

447-
Without compiler support, at least indirect branches in assembler
448-
code are eliminated. Since this includes the syscall entry path,
449-
it is not entirely pointless.
450-
451447
config INTEL_RDT
452448
bool "Intel Resource Director Technology support"
453449
depends on X86 && CPU_SUP_INTEL

arch/x86/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,10 @@ KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
220220

221221
# Avoid indirect branches in kernel to deal with Spectre
222222
ifdef CONFIG_RETPOLINE
223-
ifneq ($(RETPOLINE_CFLAGS),)
224-
KBUILD_CFLAGS += $(RETPOLINE_CFLAGS) -DRETPOLINE
223+
ifeq ($(RETPOLINE_CFLAGS),)
224+
$(error You are building kernel with non-retpoline compiler, please update your compiler.)
225225
endif
226+
KBUILD_CFLAGS += $(RETPOLINE_CFLAGS)
226227
endif
227228

228229
archscripts: scripts_basic

arch/x86/include/asm/nospec-branch.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,12 @@
162162
_ASM_PTR " 999b\n\t" \
163163
".popsection\n\t"
164164

165-
#if defined(CONFIG_X86_64) && defined(RETPOLINE)
165+
#ifdef CONFIG_RETPOLINE
166+
#ifdef CONFIG_X86_64
166167

167168
/*
168-
* Since the inline asm uses the %V modifier which is only in newer GCC,
169-
* the 64-bit one is dependent on RETPOLINE not CONFIG_RETPOLINE.
169+
* Inline asm uses the %V modifier which is only in newer GCC
170+
* which is ensured when CONFIG_RETPOLINE is defined.
170171
*/
171172
# define CALL_NOSPEC \
172173
ANNOTATE_NOSPEC_ALTERNATIVE \
@@ -181,7 +182,7 @@
181182
X86_FEATURE_RETPOLINE_AMD)
182183
# define THUNK_TARGET(addr) [thunk_target] "r" (addr)
183184

184-
#elif defined(CONFIG_X86_32) && defined(CONFIG_RETPOLINE)
185+
#else /* CONFIG_X86_32 */
185186
/*
186187
* For i386 we use the original ret-equivalent retpoline, because
187188
* otherwise we'll run out of registers. We don't care about CET
@@ -211,6 +212,7 @@
211212
X86_FEATURE_RETPOLINE_AMD)
212213

213214
# define THUNK_TARGET(addr) [thunk_target] "rm" (addr)
215+
#endif
214216
#else /* No retpoline for C / inline asm */
215217
# define CALL_NOSPEC "call *%[thunk_target]\n"
216218
# define THUNK_TARGET(addr) [thunk_target] "rm" (addr)

arch/x86/kernel/cpu/bugs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static void __init spec2_print_if_secure(const char *reason)
252252

253253
static inline bool retp_compiler(void)
254254
{
255-
return __is_defined(RETPOLINE);
255+
return __is_defined(CONFIG_RETPOLINE);
256256
}
257257

258258
static inline bool match_option(const char *arg, int arglen, const char *opt)

scripts/Makefile.build

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,8 @@ ifdef CONFIG_GCOV_KERNEL
236236
objtool_args += --no-unreachable
237237
endif
238238
ifdef CONFIG_RETPOLINE
239-
ifneq ($(RETPOLINE_CFLAGS),)
240239
objtool_args += --retpoline
241240
endif
242-
endif
243241

244242

245243
ifdef CONFIG_MODVERSIONS

0 commit comments

Comments
 (0)