]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/5.0.11/x86-retpolines-disable-switch-jump-tables-when-retpolines-are-enabled.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 5.0.11 / x86-retpolines-disable-switch-jump-tables-when-retpolines-are-enabled.patch
CommitLineData
088b31d9
GKH
1From a9d57ef15cbe327fe54416dd194ee0ea66ae53a4 Mon Sep 17 00:00:00 2001
2From: Daniel Borkmann <daniel@iogearbox.net>
3Date: Mon, 25 Mar 2019 14:56:20 +0100
4Subject: x86/retpolines: Disable switch jump tables when retpolines are enabled
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9From: Daniel Borkmann <daniel@iogearbox.net>
10
11commit a9d57ef15cbe327fe54416dd194ee0ea66ae53a4 upstream.
12
13Commit ce02ef06fcf7 ("x86, retpolines: Raise limit for generating indirect
14calls from switch-case") raised the limit under retpolines to 20 switch
15cases where gcc would only then start to emit jump tables, and therefore
16effectively disabling the emission of slow indirect calls in this area.
17
18After this has been brought to attention to gcc folks [0], Martin Liska
19has then fixed gcc to align with clang by avoiding to generate switch jump
20tables entirely under retpolines. This is taking effect in gcc starting
21from stable version 8.4.0. Given kernel supports compilation with older
22versions of gcc where the fix is not being available or backported anymore,
23we need to keep the extra KBUILD_CFLAGS around for some time and generally
24set the -fno-jump-tables to align with what more recent gcc is doing
25automatically today.
26
27More than 20 switch cases are not expected to be fast-path critical, but
28it would still be good to align with gcc behavior for versions < 8.4.0 in
29order to have consistency across supported gcc versions. vmlinux size is
30slightly growing by 0.27% for older gcc. This flag is only set to work
31around affected gcc, no change for clang.
32
33 [0] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86952
34
35Suggested-by: Martin Liska <mliska@suse.cz>
36Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
37Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
38Cc: David Woodhouse <dwmw2@infradead.org>
39Cc: Linus Torvalds <torvalds@linux-foundation.org>
40Cc: Jesper Dangaard Brouer <brouer@redhat.com>
41Cc: Björn Töpel<bjorn.topel@intel.com>
42Cc: Magnus Karlsson <magnus.karlsson@intel.com>
43Cc: Alexei Starovoitov <ast@kernel.org>
44Cc: H.J. Lu <hjl.tools@gmail.com>
45Cc: Alexei Starovoitov <ast@kernel.org>
46Cc: David S. Miller <davem@davemloft.net>
47Link: https://lkml.kernel.org/r/20190325135620.14882-1-daniel@iogearbox.net
48Signed-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