Debian Codegraph @

linux-kernel-patches/01-3f1f576a195aa266813cbd4ca70291deb61e0129.patch

raw
1 From 3f1f576a195aa266813cbd4ca70291deb61e0129 Mon Sep 17 00:00:00 2001
2 From: Borislav Petkov <[email protected]>
3 Date: Fri, 16 Feb 2018 12:26:38 +0100
4 Subject: x86/microcode: Propagate return value from updating functions
5
6 ... so that callers can know when microcode was updated and act
7 accordingly.
8
9 Tested-by: Ashok Raj <[email protected]>
10 Signed-off-by: Borislav Petkov <[email protected]>
11 Reviewed-by: Ashok Raj <[email protected]>
12 Cc: Andy Lutomirski <[email protected]>
13 Cc: Arjan van de Ven <[email protected]>
14 Cc: Borislav Petkov <[email protected]>
15 Cc: Dan Williams <[email protected]>
16 Cc: Dave Hansen <[email protected]>
17 Cc: David Woodhouse <[email protected]>
18 Cc: Greg Kroah-Hartman <[email protected]>
19 Cc: Josh Poimboeuf <[email protected]>
20 Cc: Linus Torvalds <[email protected]>
21 Cc: Peter Zijlstra <[email protected]>
22 Cc: Thomas Gleixner <[email protected]>
23 Link: http://lkml.kernel.org/r/[email protected]
24 Signed-off-by: Ingo Molnar <[email protected]>
25 ---
26 arch/x86/include/asm/microcode.h | 9 +++++++--
27 arch/x86/kernel/cpu/microcode/amd.c | 10 +++++-----
28 arch/x86/kernel/cpu/microcode/core.c | 33 +++++++++++++++++----------------
29 arch/x86/kernel/cpu/microcode/intel.c | 10 +++++-----
30 4 files changed, 34 insertions(+), 28 deletions(-)
31
32 diff --git a/arch/x86/include/asm/microcode.h b/arch/x86/include/asm/microcode.h
33 index 55520cec..7fb1047 100644
34 --- a/arch/x86/include/asm/microcode.h
35 +++ b/arch/x86/include/asm/microcode.h
36 @@ -37,7 +37,12 @@ struct cpu_signature {
37
38 struct device;
39
40 -enum ucode_state { UCODE_ERROR, UCODE_OK, UCODE_NFOUND };
41 +enum ucode_state {
42 + UCODE_OK = 0,
43 + UCODE_UPDATED,
44 + UCODE_NFOUND,
45 + UCODE_ERROR,
46 +};
47
48 struct microcode_ops {
49 enum ucode_state (*request_microcode_user) (int cpu,
50 @@ -54,7 +59,7 @@ struct microcode_ops {
51 * are being called.
52 * See also the "Synchronization" section in microcode_core.c.
53 */
54 - int (*apply_microcode) (int cpu);
55 + enum ucode_state (*apply_microcode) (int cpu);
56 int (*collect_cpu_info) (int cpu, struct cpu_signature *csig);
57 };
58
59 diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c
60 index 330b846..a998e1a 100644
61 --- a/arch/x86/kernel/cpu/microcode/amd.c
62 +++ b/arch/x86/kernel/cpu/microcode/amd.c
63 @@ -498,7 +498,7 @@ static unsigned int verify_patch_size(u8 family, u32 patch_size,
64 return patch_size;
65 }
66
67 -static int apply_microcode_amd(int cpu)
68 +static enum ucode_state apply_microcode_amd(int cpu)
69 {
70 struct cpuinfo_x86 *c = &cpu_data(cpu);
71 struct microcode_amd *mc_amd;
72 @@ -512,7 +512,7 @@ static int apply_microcode_amd(int cpu)
73
74 p = find_patch(cpu);
75 if (!p)
76 - return 0;
77 + return UCODE_NFOUND;
78
79 mc_amd = p->data;
80 uci->mc = p->data;
81 @@ -523,13 +523,13 @@ static int apply_microcode_amd(int cpu)
82 if (rev >= mc_amd->hdr.patch_id) {
83 c->microcode = rev;
84 uci->cpu_sig.rev = rev;
85 - return 0;
86 + return UCODE_OK;
87 }
88
89 if (__apply_microcode_amd(mc_amd)) {
90 pr_err("CPU%d: update failed for patch_level=0x%08x\n",
91 cpu, mc_amd->hdr.patch_id);
92 - return -1;
93 + return UCODE_ERROR;
94 }
95 pr_info("CPU%d: new patch_level=0x%08x\n", cpu,
96 mc_amd->hdr.patch_id);
97 @@ -537,7 +537,7 @@ static int apply_microcode_amd(int cpu)
98 uci->cpu_sig.rev = mc_amd->hdr.patch_id;
99 c->microcode = mc_amd->hdr.patch_id;
100
101 - return 0;
102 + return UCODE_UPDATED;
103 }
104
105 static int install_equiv_cpu_table(const u8 *buf)
106 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
107 index 319dd65..6fdaf7c 100644
108 --- a/arch/x86/kernel/cpu/microcode/core.c
109 +++ b/arch/x86/kernel/cpu/microcode/core.c
110 @@ -374,7 +374,7 @@ static int collect_cpu_info(int cpu)
111 }
112
113 struct apply_microcode_ctx {
114 - int err;
115 + enum ucode_state err;
116 };
117
118 static void apply_microcode_local(void *arg)
119 @@ -489,31 +489,29 @@ static void __exit microcode_dev_exit(void)
120 /* fake device for request_firmware */
121 static struct platform_device *microcode_pdev;
122
123 -static int reload_for_cpu(int cpu)
124 +static enum ucode_state reload_for_cpu(int cpu)
125 {
126 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
127 enum ucode_state ustate;
128 - int err = 0;
129
130 if (!uci->valid)
131 - return err;
132 + return UCODE_OK;
133
134 ustate = microcode_ops->request_microcode_fw(cpu, &microcode_pdev->dev, true);
135 - if (ustate == UCODE_OK)
136 - apply_microcode_on_target(cpu);
137 - else
138 - if (ustate == UCODE_ERROR)
139 - err = -EINVAL;
140 - return err;
141 + if (ustate != UCODE_OK)
142 + return ustate;
143 +
144 + return apply_microcode_on_target(cpu);
145 }
146
147 static ssize_t reload_store(struct device *dev,
148 struct device_attribute *attr,
149 const char *buf, size_t size)
150 {
151 + enum ucode_state tmp_ret = UCODE_OK;
152 unsigned long val;
153 + ssize_t ret = 0;
154 int cpu;
155 - ssize_t ret = 0, tmp_ret;
156
157 ret = kstrtoul(buf, 0, &val);
158 if (ret)
159 @@ -526,15 +524,18 @@ static ssize_t reload_store(struct device *dev,
160 mutex_lock(&microcode_mutex);
161 for_each_online_cpu(cpu) {
162 tmp_ret = reload_for_cpu(cpu);
163 - if (tmp_ret != 0)
164 + if (tmp_ret > UCODE_NFOUND) {
165 pr_warn("Error reloading microcode on CPU %d\n", cpu);
166
167 - /* save retval of the first encountered reload error */
168 - if (!ret)
169 - ret = tmp_ret;
170 + /* set retval for the first encountered reload error */
171 + if (!ret)
172 + ret = -EINVAL;
173 + }
174 }
175 - if (!ret)
176 +
177 + if (!ret && tmp_ret == UCODE_UPDATED)
178 perf_check_microcode();
179 +
180 mutex_unlock(&microcode_mutex);
181 put_online_cpus();
182
183 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
184 index a15db2b..923054a 100644
185 --- a/arch/x86/kernel/cpu/microcode/intel.c
186 +++ b/arch/x86/kernel/cpu/microcode/intel.c
187 @@ -772,7 +772,7 @@ static int collect_cpu_info(int cpu_num, struct cpu_signature *csig)
188 return 0;
189 }
190
191 -static int apply_microcode_intel(int cpu)
192 +static enum ucode_state apply_microcode_intel(int cpu)
193 {
194 struct microcode_intel *mc;
195 struct ucode_cpu_info *uci;
196 @@ -782,7 +782,7 @@ static int apply_microcode_intel(int cpu)
197
198 /* We should bind the task to the CPU */
199 if (WARN_ON(raw_smp_processor_id() != cpu))
200 - return -1;
201 + return UCODE_ERROR;
202
203 uci = ucode_cpu_info + cpu;
204 mc = uci->mc;
205 @@ -790,7 +790,7 @@ static int apply_microcode_intel(int cpu)
206 /* Look for a newer patch in our cache: */
207 mc = find_patch(uci);
208 if (!mc)
209 - return 0;
210 + return UCODE_NFOUND;
211 }
212
213 /* write microcode via MSR 0x79 */
214 @@ -801,7 +801,7 @@ static int apply_microcode_intel(int cpu)
215 if (rev != mc->hdr.rev) {
216 pr_err("CPU%d update to revision 0x%x failed\n",
217 cpu, mc->hdr.rev);
218 - return -1;
219 + return UCODE_ERROR;
220 }
221
222 if (rev != prev_rev) {
223 @@ -818,7 +818,7 @@ static int apply_microcode_intel(int cpu)
224 uci->cpu_sig.rev = rev;
225 c->microcode = rev;
226
227 - return 0;
228 + return UCODE_UPDATED;
229 }
230
231 static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
232 --
233 cgit v1.1
234