Debian Codegraph @

linux-kernel-patches/07-30ec26da9967d0d785abc24073129a34c3211777.patch

raw
1 From 30ec26da9967d0d785abc24073129a34c3211777 Mon Sep 17 00:00:00 2001
2 From: Ashok Raj <[email protected]>
3 Date: Wed, 28 Feb 2018 11:28:43 +0100
4 Subject: x86/microcode: Do not upload microcode if CPUs are offline
5
6 Avoid loading microcode if any of the CPUs are offline, and issue a
7 warning. Having different microcode revisions on the system at any time
8 is outright dangerous.
9
10 [ Borislav: Massage changelog. ]
11
12 Signed-off-by: Ashok Raj <[email protected]>
13 Signed-off-by: Borislav Petkov <[email protected]>
14 Signed-off-by: Thomas Gleixner <[email protected]>
15 Tested-by: Tom Lendacky <[email protected]>
16 Tested-by: Ashok Raj <[email protected]>
17 Reviewed-by: Tom Lendacky <[email protected]>
18 Cc: Arjan Van De Ven <[email protected]>
19 Link: http://lkml.kernel.org/r/[email protected]
20 Link: https://lkml.kernel.org/r/[email protected]
21 ---
22 arch/x86/kernel/cpu/microcode/core.c | 18 ++++++++++++++++++
23 1 file changed, 18 insertions(+)
24
25 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
26 index 6337065..fa32cb3 100644
27 --- a/arch/x86/kernel/cpu/microcode/core.c
28 +++ b/arch/x86/kernel/cpu/microcode/core.c
29 @@ -486,6 +486,16 @@ static void __exit microcode_dev_exit(void)
30 /* fake device for request_firmware */
31 static struct platform_device *microcode_pdev;
32
33 +static int check_online_cpus(void)
34 +{
35 + if (num_online_cpus() == num_present_cpus())
36 + return 0;
37 +
38 + pr_err("Not all CPUs online, aborting microcode update.\n");
39 +
40 + return -EINVAL;
41 +}
42 +
43 static enum ucode_state reload_for_cpu(int cpu)
44 {
45 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
46 @@ -519,7 +529,13 @@ static ssize_t reload_store(struct device *dev,
47 return size;
48
49 get_online_cpus();
50 +
51 + ret = check_online_cpus();
52 + if (ret)
53 + goto put;
54 +
55 mutex_lock(&microcode_mutex);
56 +
57 for_each_online_cpu(cpu) {
58 tmp_ret = reload_for_cpu(cpu);
59 if (tmp_ret > UCODE_NFOUND) {
60 @@ -538,6 +554,8 @@ static ssize_t reload_store(struct device *dev,
61 microcode_check();
62
63 mutex_unlock(&microcode_mutex);
64 +
65 +put:
66 put_online_cpus();
67
68 if (!ret)
69 --
70 cgit v1.1
71