Skip to content

Commit f9e14db

Browse files
committed
x86/cpu: Load microcode during restore_processor_state()
When resuming from system sleep state, restore_processor_state() restores the boot CPU MSRs. These MSRs could be emulated by microcode. If microcode is not loaded yet, writing to emulated MSRs leads to unchecked MSR access error: ... PM: Calling lapic_suspend+0x0/0x210 unchecked MSR access error: WRMSR to 0x10f (tried to write 0x0...0) at rIP: ... (native_write_msr) Call Trace: <TASK> ? restore_processor_state x86_acpi_suspend_lowlevel acpi_suspend_enter suspend_devices_and_enter pm_suspend.cold state_store kobj_attr_store sysfs_kf_write kernfs_fop_write_iter new_sync_write vfs_write ksys_write __x64_sys_write do_syscall_64 entry_SYSCALL_64_after_hwframe RIP: 0033:0x7fda13c260a7 To ensure microcode emulated MSRs are available for restoration, load the microcode on the boot CPU before restoring these MSRs. [ Pawan: write commit message and productize it. ] Fixes: e2a1256 ("x86/speculation: Restore speculation related MSRs during S3 resume") Reported-by: Kyle D. Pelton <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Signed-off-by: Pawan Gupta <[email protected]> Tested-by: Kyle D. Pelton <[email protected]> Cc: [email protected] Link: https://bugzilla.kernel.org/show_bug.cgi?id=215841 Link: https://lore.kernel.org/r/4350dfbf785cd482d3fafa72b2b49c83102df3ce.1650386317.git.pawan.kumar.gupta@linux.intel.com
1 parent 3ccce93 commit f9e14db

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

arch/x86/include/asm/microcode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,12 @@ extern void __init load_ucode_bsp(void);
131131
extern void load_ucode_ap(void);
132132
void reload_early_microcode(void);
133133
extern bool initrd_gone;
134+
void microcode_bsp_resume(void);
134135
#else
135136
static inline void __init load_ucode_bsp(void) { }
136137
static inline void load_ucode_ap(void) { }
137138
static inline void reload_early_microcode(void) { }
139+
static inline void microcode_bsp_resume(void) { }
138140
#endif
139141

140142
#endif /* _ASM_X86_MICROCODE_H */

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,9 @@ static struct subsys_interface mc_cpu_interface = {
758758
};
759759

760760
/**
761-
* mc_bp_resume - Update boot CPU microcode during resume.
761+
* microcode_bsp_resume - Update boot CPU microcode during resume.
762762
*/
763-
static void mc_bp_resume(void)
763+
void microcode_bsp_resume(void)
764764
{
765765
int cpu = smp_processor_id();
766766
struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
@@ -772,7 +772,7 @@ static void mc_bp_resume(void)
772772
}
773773

774774
static struct syscore_ops mc_syscore_ops = {
775-
.resume = mc_bp_resume,
775+
.resume = microcode_bsp_resume,
776776
};
777777

778778
static int mc_cpu_starting(unsigned int cpu)

arch/x86/power/cpu.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <asm/cpu.h>
2626
#include <asm/mmu_context.h>
2727
#include <asm/cpu_device_id.h>
28+
#include <asm/microcode.h>
2829

2930
#ifdef CONFIG_X86_32
3031
__visible unsigned long saved_context_ebx;
@@ -262,11 +263,18 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)
262263
x86_platform.restore_sched_clock_state();
263264
mtrr_bp_restore();
264265
perf_restore_debug_store();
265-
msr_restore_context(ctxt);
266266

267267
c = &cpu_data(smp_processor_id());
268268
if (cpu_has(c, X86_FEATURE_MSR_IA32_FEAT_CTL))
269269
init_ia32_feat_ctl(c);
270+
271+
microcode_bsp_resume();
272+
273+
/*
274+
* This needs to happen after the microcode has been updated upon resume
275+
* because some of the MSRs are "emulated" in microcode.
276+
*/
277+
msr_restore_context(ctxt);
270278
}
271279

272280
/* Needed by apm.c */

0 commit comments

Comments
 (0)