Skip to content

Commit a9d57ef

Browse files
borkmannKAGA-KOKO
authored andcommitted
x86/retpolines: Disable switch jump tables when retpolines are enabled
Commit ce02ef0 ("x86, retpolines: Raise limit for generating indirect calls from switch-case") raised the limit under retpolines to 20 switch cases where gcc would only then start to emit jump tables, and therefore effectively disabling the emission of slow indirect calls in this area. After this has been brought to attention to gcc folks [0], Martin Liska has then fixed gcc to align with clang by avoiding to generate switch jump tables entirely under retpolines. This is taking effect in gcc starting from stable version 8.4.0. Given kernel supports compilation with older versions of gcc where the fix is not being available or backported anymore, we need to keep the extra KBUILD_CFLAGS around for some time and generally set the -fno-jump-tables to align with what more recent gcc is doing automatically today. More than 20 switch cases are not expected to be fast-path critical, but it would still be good to align with gcc behavior for versions < 8.4.0 in order to have consistency across supported gcc versions. vmlinux size is slightly growing by 0.27% for older gcc. This flag is only set to work around affected gcc, no change for clang. [0] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86952 Suggested-by: Martin Liska <mliska@suse.cz> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Jesper Dangaard Brouer <brouer@redhat.com> Cc: Björn Töpel<bjorn.topel@intel.com> Cc: Magnus Karlsson <magnus.karlsson@intel.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: H.J. Lu <hjl.tools@gmail.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: David S. Miller <davem@davemloft.net> Link: https://lkml.kernel.org/r/20190325135620.14882-1-daniel@iogearbox.net
1 parent b929a50 commit a9d57ef

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/x86/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,12 @@ ifdef CONFIG_RETPOLINE
219219
# Additionally, avoid generating expensive indirect jumps which
220220
# are subject to retpolines for small number of switch cases.
221221
# clang turns off jump table generation by default when under
222-
# retpoline builds, however, gcc does not for x86.
223-
KBUILD_CFLAGS += $(call cc-option,--param=case-values-threshold=20)
222+
# retpoline builds, however, gcc does not for x86. This has
223+
# only been fixed starting from gcc stable version 8.4.0 and
224+
# onwards, but not for older ones. See gcc bug #86952.
225+
ifndef CONFIG_CC_IS_CLANG
226+
KBUILD_CFLAGS += $(call cc-option,-fno-jump-tables)
227+
endif
224228
endif
225229

226230
archscripts: scripts_basic

0 commit comments

Comments
 (0)