]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.180/x86-speculation-move-stipb-ibpb-string-conditionals-out-of-cpu_show_common.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.180 / x86-speculation-move-stipb-ibpb-string-conditionals-out-of-cpu_show_common.patch
1 From foo@baz Tue 14 May 2019 08:29:35 PM CEST
2 From: Tim Chen <tim.c.chen@linux.intel.com>
3 Date: Sun, 25 Nov 2018 19:33:32 +0100
4 Subject: x86/speculation: Move STIPB/IBPB string conditionals out of cpu_show_common()
5
6 From: Tim Chen <tim.c.chen@linux.intel.com>
7
8 commit a8f76ae41cd633ac00be1b3019b1eb4741be3828 upstream.
9
10 The Spectre V2 printout in cpu_show_common() handles conditionals for the
11 various mitigation methods directly in the sprintf() argument list. That's
12 hard to read and will become unreadable if more complex decisions need to
13 be made for a particular method.
14
15 Move the conditionals for STIBP and IBPB string selection into helper
16 functions, so they can be extended later on.
17
18 Signed-off-by: Tim Chen <tim.c.chen@linux.intel.com>
19 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
20 Reviewed-by: Ingo Molnar <mingo@kernel.org>
21 Cc: Peter Zijlstra <peterz@infradead.org>
22 Cc: Andy Lutomirski <luto@kernel.org>
23 Cc: Linus Torvalds <torvalds@linux-foundation.org>
24 Cc: Jiri Kosina <jkosina@suse.cz>
25 Cc: Tom Lendacky <thomas.lendacky@amd.com>
26 Cc: Josh Poimboeuf <jpoimboe@redhat.com>
27 Cc: Andrea Arcangeli <aarcange@redhat.com>
28 Cc: David Woodhouse <dwmw@amazon.co.uk>
29 Cc: Andi Kleen <ak@linux.intel.com>
30 Cc: Dave Hansen <dave.hansen@intel.com>
31 Cc: Casey Schaufler <casey.schaufler@intel.com>
32 Cc: Asit Mallick <asit.k.mallick@intel.com>
33 Cc: Arjan van de Ven <arjan@linux.intel.com>
34 Cc: Jon Masters <jcm@redhat.com>
35 Cc: Waiman Long <longman9394@gmail.com>
36 Cc: Greg KH <gregkh@linuxfoundation.org>
37 Cc: Dave Stewart <david.c.stewart@intel.com>
38 Cc: Kees Cook <keescook@chromium.org>
39 Link: https://lkml.kernel.org/r/20181125185003.874479208@linutronix.de
40 Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
41 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
42 ---
43 arch/x86/kernel/cpu/bugs.c | 20 ++++++++++++++++++--
44 1 file changed, 18 insertions(+), 2 deletions(-)
45
46 --- a/arch/x86/kernel/cpu/bugs.c
47 +++ b/arch/x86/kernel/cpu/bugs.c
48 @@ -759,6 +759,22 @@ static void __init l1tf_select_mitigatio
49
50 #ifdef CONFIG_SYSFS
51
52 +static char *stibp_state(void)
53 +{
54 + if (x86_spec_ctrl_base & SPEC_CTRL_STIBP)
55 + return ", STIBP";
56 + else
57 + return "";
58 +}
59 +
60 +static char *ibpb_state(void)
61 +{
62 + if (boot_cpu_has(X86_FEATURE_USE_IBPB))
63 + return ", IBPB";
64 + else
65 + return "";
66 +}
67 +
68 static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr,
69 char *buf, unsigned int bug)
70 {
71 @@ -777,9 +793,9 @@ static ssize_t cpu_show_common(struct de
72
73 case X86_BUG_SPECTRE_V2:
74 return sprintf(buf, "%s%s%s%s%s%s\n", spectre_v2_strings[spectre_v2_enabled],
75 - boot_cpu_has(X86_FEATURE_USE_IBPB) ? ", IBPB" : "",
76 + ibpb_state(),
77 boot_cpu_has(X86_FEATURE_USE_IBRS_FW) ? ", IBRS_FW" : "",
78 - (x86_spec_ctrl_base & SPEC_CTRL_STIBP) ? ", STIBP" : "",
79 + stibp_state(),
80 boot_cpu_has(X86_FEATURE_RSB_CTXSW) ? ", RSB filling" : "",
81 spectre_v2_module_string());
82