Skip to content

Commit ab31c74

Browse files
ashok-rajbp3tk0v
authored andcommitted
x86/microcode: Add a parameter to microcode_check() to store CPU capabilities
Add a parameter to store CPU capabilities before performing a microcode update so that CPU capabilities can be compared before and after update. [ bp: Massage. ] Signed-off-by: Ashok Raj <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 59047d9 commit ab31c74

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

arch/x86/include/asm/processor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ bool xen_set_default_idle(void);
697697
#endif
698698

699699
void __noreturn stop_this_cpu(void *dummy);
700-
void microcode_check(void);
700+
void microcode_check(struct cpuinfo_x86 *prev_info);
701701

702702
enum l1tf_mitigations {
703703
L1TF_MITIGATION_OFF,

arch/x86/kernel/cpu/common.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,30 +2297,35 @@ void cpu_init_secondary(void)
22972297
#endif
22982298

22992299
#ifdef CONFIG_MICROCODE_LATE_LOADING
2300-
/*
2300+
/**
2301+
* microcode_check() - Check if any CPU capabilities changed after an update.
2302+
* @prev_info: CPU capabilities stored before an update.
2303+
*
23012304
* The microcode loader calls this upon late microcode load to recheck features,
23022305
* only when microcode has been updated. Caller holds microcode_mutex and CPU
23032306
* hotplug lock.
2307+
*
2308+
* Return: None
23042309
*/
2305-
void microcode_check(void)
2310+
void microcode_check(struct cpuinfo_x86 *prev_info)
23062311
{
2307-
struct cpuinfo_x86 info;
2308-
23092312
perf_check_microcode();
23102313

23112314
/* Reload CPUID max function as it might've changed. */
2312-
info.cpuid_level = cpuid_eax(0);
2315+
prev_info->cpuid_level = cpuid_eax(0);
23132316

23142317
/*
23152318
* Copy all capability leafs to pick up the synthetic ones so that
23162319
* memcmp() below doesn't fail on that. The ones coming from CPUID will
23172320
* get overwritten in get_cpu_cap().
23182321
*/
2319-
memcpy(&info.x86_capability, &boot_cpu_data.x86_capability, sizeof(info.x86_capability));
2322+
memcpy(&prev_info->x86_capability, &boot_cpu_data.x86_capability,
2323+
sizeof(prev_info->x86_capability));
23202324

2321-
get_cpu_cap(&info);
2325+
get_cpu_cap(prev_info);
23222326

2323-
if (!memcmp(&info.x86_capability, &boot_cpu_data.x86_capability, sizeof(info.x86_capability)))
2327+
if (!memcmp(&prev_info->x86_capability, &boot_cpu_data.x86_capability,
2328+
sizeof(prev_info->x86_capability)))
23242329
return;
23252330

23262331
pr_warn("x86/CPU: CPU features have changed after loading microcode, but might not take effect.\n");

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ static int __reload_late(void *info)
438438
static int microcode_reload_late(void)
439439
{
440440
int old = boot_cpu_data.microcode, ret;
441+
struct cpuinfo_x86 prev_info;
441442

442443
pr_err("Attempting late microcode loading - it is dangerous and taints the kernel.\n");
443444
pr_err("You should switch to early loading, if possible.\n");
@@ -447,7 +448,7 @@ static int microcode_reload_late(void)
447448

448449
ret = stop_machine_cpuslocked(__reload_late, NULL, cpu_online_mask);
449450
if (ret == 0)
450-
microcode_check();
451+
microcode_check(&prev_info);
451452

452453
pr_info("Reload completed, microcode revision: 0x%x -> 0x%x\n",
453454
old, boot_cpu_data.microcode);

0 commit comments

Comments
 (0)