Skip to content

Commit 30ec26d

Browse files
ashok-rajKAGA-KOKO
authored andcommitted
x86/microcode: Do not upload microcode if CPUs are offline
Avoid loading microcode if any of the CPUs are offline, and issue a warning. Having different microcode revisions on the system at any time is outright dangerous. [ Borislav: Massage changelog. ] Signed-off-by: Ashok Raj <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Tested-by: Tom Lendacky <[email protected]> Tested-by: Ashok Raj <[email protected]> Reviewed-by: Tom Lendacky <[email protected]> Cc: Arjan Van De Ven <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected]
1 parent 91df9fd commit 30ec26d

File tree

1 file changed

+18
-0
lines changed
  • arch/x86/kernel/cpu/microcode

1 file changed

+18
-0
lines changed

arch/x86/kernel/cpu/microcode/core.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,16 @@ static void __exit microcode_dev_exit(void)
486486
/* fake device for request_firmware */
487487
static struct platform_device *microcode_pdev;
488488

489+
static int check_online_cpus(void)
490+
{
491+
if (num_online_cpus() == num_present_cpus())
492+
return 0;
493+
494+
pr_err("Not all CPUs online, aborting microcode update.\n");
495+
496+
return -EINVAL;
497+
}
498+
489499
static enum ucode_state reload_for_cpu(int cpu)
490500
{
491501
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
@@ -519,7 +529,13 @@ static ssize_t reload_store(struct device *dev,
519529
return size;
520530

521531
get_online_cpus();
532+
533+
ret = check_online_cpus();
534+
if (ret)
535+
goto put;
536+
522537
mutex_lock(&microcode_mutex);
538+
523539
for_each_online_cpu(cpu) {
524540
tmp_ret = reload_for_cpu(cpu);
525541
if (tmp_ret > UCODE_NFOUND) {
@@ -538,6 +554,8 @@ static ssize_t reload_store(struct device *dev,
538554
microcode_check();
539555

540556
mutex_unlock(&microcode_mutex);
557+
558+
put:
541559
put_online_cpus();
542560

543561
if (!ret)

0 commit comments

Comments
 (0)