]>
Commit | Line | Data |
---|---|---|
088b31d9 GKH |
1 | From a9d57ef15cbe327fe54416dd194ee0ea66ae53a4 Mon Sep 17 00:00:00 2001 |
2 | From: Daniel Borkmann <daniel@iogearbox.net> | |
3 | Date: Mon, 25 Mar 2019 14:56:20 +0100 | |
4 | Subject: x86/retpolines: Disable switch jump tables when retpolines are enabled | |
5 | MIME-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ||
9 | From: Daniel Borkmann <daniel@iogearbox.net> | |
10 | ||
11 | commit a9d57ef15cbe327fe54416dd194ee0ea66ae53a4 upstream. | |
12 | ||
13 | Commit ce02ef06fcf7 ("x86, retpolines: Raise limit for generating indirect | |
14 | calls from switch-case") raised the limit under retpolines to 20 switch | |
15 | cases where gcc would only then start to emit jump tables, and therefore | |
16 | effectively disabling the emission of slow indirect calls in this area. | |
17 | ||
18 | After this has been brought to attention to gcc folks [0], Martin Liska | |
19 | has then fixed gcc to align with clang by avoiding to generate switch jump | |
20 | tables entirely under retpolines. This is taking effect in gcc starting | |
21 | from stable version 8.4.0. Given kernel supports compilation with older | |
22 | versions of gcc where the fix is not being available or backported anymore, | |
23 | we need to keep the extra KBUILD_CFLAGS around for some time and generally | |
24 | set the -fno-jump-tables to align with what more recent gcc is doing | |
25 | automatically today. | |
26 | ||
27 | More than 20 switch cases are not expected to be fast-path critical, but | |
28 | it would still be good to align with gcc behavior for versions < 8.4.0 in | |
29 | order to have consistency across supported gcc versions. vmlinux size is | |
30 | slightly growing by 0.27% for older gcc. This flag is only set to work | |
31 | around affected gcc, no change for clang. | |
32 | ||
33 | [0] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86952 | |
34 | ||
35 | Suggested-by: Martin Liska <mliska@suse.cz> | |
36 | Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> | |
37 | Signed-off-by: Thomas Gleixner <tglx@linutronix.de> | |
38 | Cc: David Woodhouse <dwmw2@infradead.org> | |
39 | Cc: Linus Torvalds <torvalds@linux-foundation.org> | |
40 | Cc: Jesper Dangaard Brouer <brouer@redhat.com> | |
41 | Cc: Björn Töpel<bjorn.topel@intel.com> | |
42 | Cc: Magnus Karlsson <magnus.karlsson@intel.com> | |
43 | Cc: Alexei Starovoitov <ast@kernel.org> | |
44 | Cc: H.J. Lu <hjl.tools@gmail.com> | |
45 | Cc: Alexei Starovoitov <ast@kernel.org> | |
46 | Cc: David S. Miller <davem@davemloft.net> | |
47 | Link: https://lkml.kernel.org/r/20190325135620.14882-1-daniel@iogearbox.net | |
48 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
49 | ||
50 | --- | |
51 | arch/x86/Makefile | 8 ++++++-- | |
52 | 1 file changed, 6 insertions(+), 2 deletions(-) | |
53 | ||
54 | --- a/arch/x86/Makefile | |
55 | +++ b/arch/x86/Makefile | |
56 | @@ -220,8 +220,12 @@ ifdef CONFIG_RETPOLINE | |
57 | # Additionally, avoid generating expensive indirect jumps which | |
58 | # are subject to retpolines for small number of switch cases. | |
59 | # clang turns off jump table generation by default when under | |
60 | - # retpoline builds, however, gcc does not for x86. | |
61 | - KBUILD_CFLAGS += $(call cc-option,--param=case-values-threshold=20) | |
62 | + # retpoline builds, however, gcc does not for x86. This has | |
63 | + # only been fixed starting from gcc stable version 8.4.0 and | |
64 | + # onwards, but not for older ones. See gcc bug #86952. | |
65 | + ifndef CONFIG_CC_IS_CLANG | |
66 | + KBUILD_CFLAGS += $(call cc-option,-fno-jump-tables) | |
67 | + endif | |
68 | endif | |
69 | ||
70 | archscripts: scripts_basic |