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