Skip to content

Commit 2a1dada

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
x86/microcode/intel: Save the microcode only after a successful late-load
There are situations where the late microcode is loaded into memory but is not applied: 1) The rendezvous fails 2) The microcode is rejected by the CPUs If any of this happens then the pointer which was updated at firmware load time is stale and subsequent CPU hotplug operations either fail to update or create inconsistent microcode state. Save the loaded microcode in a separate pointer before the late load is attempted and when successful, update the hotplug pointer accordingly via a new microcode_ops callback. Remove the pointless fallback in the loader to a microcode pointer which is never populated. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20231002115902.505491309@linutronix.de
1 parent dd5e3e3 commit 2a1dada

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ static int microcode_reload_late(void)
397397
store_cpu_caps(&prev_info);
398398

399399
ret = stop_machine_cpuslocked(__reload_late, NULL, cpu_online_mask);
400+
401+
if (microcode_ops->finalize_late_load)
402+
microcode_ops->finalize_late_load(ret);
403+
400404
if (!ret) {
401405
pr_info("Reload succeeded, microcode revision: 0x%x -> 0x%x\n",
402406
old, boot_cpu_data.microcode);

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static const char ucode_path[] = "kernel/x86/microcode/GenuineIntel.bin";
3636

3737
/* Current microcode patch used in early patching on the APs. */
3838
static struct microcode_intel *ucode_patch_va __read_mostly;
39+
static struct microcode_intel *ucode_patch_late __read_mostly;
3940

4041
/* last level cache size per core */
4142
static unsigned int llc_size_per_core __ro_after_init;
@@ -470,12 +471,9 @@ static enum ucode_state apply_microcode_intel(int cpu)
470471
if (WARN_ON(raw_smp_processor_id() != cpu))
471472
return UCODE_ERROR;
472473

473-
mc = ucode_patch_va;
474-
if (!mc) {
475-
mc = uci->mc;
476-
if (!mc)
477-
return UCODE_NFOUND;
478-
}
474+
mc = ucode_patch_late;
475+
if (!mc)
476+
return UCODE_NFOUND;
479477

480478
/*
481479
* Save us the MSR write below - which is a particular expensive
@@ -594,15 +592,7 @@ static enum ucode_state parse_microcode_blobs(int cpu, struct iov_iter *iter)
594592
if (!new_mc)
595593
return UCODE_NFOUND;
596594

597-
/* Save for CPU hotplug */
598-
save_microcode_patch((struct microcode_intel *)new_mc);
599-
uci->mc = ucode_patch_va;
600-
601-
vfree(new_mc);
602-
603-
pr_debug("CPU%d found a matching microcode update with version 0x%x (current=0x%x)\n",
604-
cpu, cur_rev, uci->cpu_sig.rev);
605-
595+
ucode_patch_late = (struct microcode_intel *)new_mc;
606596
return UCODE_NEW;
607597
}
608598

@@ -659,10 +649,20 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
659649
return ret;
660650
}
661651

652+
static void finalize_late_load(int result)
653+
{
654+
if (!result)
655+
save_microcode_patch(ucode_patch_late);
656+
657+
vfree(ucode_patch_late);
658+
ucode_patch_late = NULL;
659+
}
660+
662661
static struct microcode_ops microcode_intel_ops = {
663662
.request_microcode_fw = request_microcode_fw,
664663
.collect_cpu_info = collect_cpu_info,
665664
.apply_microcode = apply_microcode_intel,
665+
.finalize_late_load = finalize_late_load,
666666
};
667667

668668
static __init void calc_llc_size_per_core(struct cpuinfo_x86 *c)

arch/x86/kernel/cpu/microcode/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct microcode_ops {
3131
*/
3232
enum ucode_state (*apply_microcode)(int cpu);
3333
int (*collect_cpu_info)(int cpu, struct cpu_signature *csig);
34+
void (*finalize_late_load)(int result);
3435
};
3536

3637
extern struct ucode_cpu_info ucode_cpu_info[];

0 commit comments

Comments
 (0)