x86/cpu: Reinitialize IA32_FEAT_CTL MSR on BSP during wakeup
Subsystems (5)
PATCH v2 1/1 x86/cpu: Reinitialize IA32_FEAT_CTL MSR on BSP during wakeup
Reinitialize IA32_FEAT_CTL on the BSP during wakeup to handle the case where firmware doesn't initialize or save/restore across S3. This fixes a bug where IA32_FEAT_CTL is left uninitialized and results in VMXON taking a #GP due to VMX not being fully enabled, i.e. breaks KVM.
Use init_ia32_feat_ctl() to "restore" IA32_FEAT_CTL as it already deals with the case where the MSR is locked, and because APs already redo init_ia32_feat_ctl() during suspend by virtue of the SMP boot flow being used to reinitialize APs upon wakeup. Do the call in the early wakeup flow to avoid dependencies in the syscore_ops chain, e.g. simply adding a resume hook is not guaranteed to work, as KVM does VMXON in its own resume hook, kvm_resume(), when KVM has active guests.
---
v2:
- Collect Reviewed/Tested tags. [Brad, Liam, Maxim].
- Include asm/cpu.h to fix Zhaoxin and Centaur builds. [Brad, LKP]
- Add Cc to stable. [Liam]
arch/x86/include/asm/cpu.h | 5 +++++ arch/x86/kernel/cpu/centaur.c | 1 + arch/x86/kernel/cpu/cpu.h | 4 ---- arch/x86/kernel/cpu/zhaoxin.c | 1 + arch/x86/power/cpu.c | 6 ++++++ 5 files changed, 13 insertions(+), 4 deletions(-)
arch/x86/include/asm/cpu.h +5 -0
@@ -58,4 +58,9 @@ static inline bool handle_guest_split_lock(unsigned long ip)return false; }#endif +#ifdef CONFIG_IA32_FEAT_CTL +void init_ia32_feat_ctl (struct cpuinfo_x86 *c); +#else +static inline void init_ia32_feat_ctl (struct cpuinfo_x86 *c) {} +#endif #endif /* _ASM_X86_CPU_H */
arch/x86/kernel/cpu/centaur.c +1 -0
@@ -3,6 +3,7 @@#include <linux/sched.h> #include <linux/sched/clock.h> +#include <asm/cpu.h> #include <asm/cpufeature.h> #include <asm/e820/api.h> #include <asm/mtrr.h>
arch/x86/kernel/cpu/cpu.h +0 -4
@@ -80,8 +80,4 @@ extern void x86_spec_ctrl_setup_ap(void);extern u64 x86_read_arch_cap_msr (void ); -#ifdef CONFIG_IA32_FEAT_CTL -void init_ia32_feat_ctl (struct cpuinfo_x86 *c); -#endif -#endif /* ARCH_X86_CPU_H */
arch/x86/kernel/cpu/zhaoxin.c +1 -0
@@ -2,6 +2,7 @@#include <linux/sched.h> #include <linux/sched/clock.h> +#include <asm/cpu.h> #include <asm/cpufeature.h> #include "cpu.h"
arch/x86/power/cpu.c +6 -0
@@ -193,6 +193,8 @@ static void fix_processor_context(void)*/ static void notrace __restore_processor_state(struct saved_context *ctxt) { +struct cpuinfo_x86 *c; +if (ctxt->misc_enable_saved)wrmsrl (MSR_IA32_MISC_ENABLE , ctxt->misc_enable);/*
@@ -263,6 +265,10 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)mtrr_bp_restore ();perf_restore_debug_store ();msr_restore_context (ctxt); + + c = &cpu_data (smp_processor_id ()); +if (cpu_has (c,X86_FEATURE_MSR_IA32_FEAT_CTL )) +init_ia32_feat_ctl (c); }/* Needed by apm.c */
Signature · 1 line
2.26.0
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 5d5103595e9e53048bb7e70ee2673c897ab38300 Gitweb: https://git.kernel.org/tip/5d5103595e9e53048bb7e70ee2673c897ab38300 Author: Sean Christopherson <[email protected]> AuthorDate: Mon, 08 Jun 2020 10:41:34 -07:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 15 Jun 2020 14:18:37 +02:00
x86/cpu: Reinitialize IA32_FEAT_CTL MSR on BSP during wakeup
Reinitialize IA32_FEAT_CTL on the BSP during wakeup to handle the case where firmware doesn't initialize or save/restore across S3. This fixes a bug where IA32_FEAT_CTL is left uninitialized and results in VMXON taking a #GP due to VMX not being fully enabled, i.e. breaks KVM.
Use init_ia32_feat_ctl() to "restore" IA32_FEAT_CTL as it already deals with the case where the MSR is locked, and because APs already redo init_ia32_feat_ctl() during suspend by virtue of the SMP boot flow being used to reinitialize APs upon wakeup. Do the call in the early wakeup flow to avoid dependencies in the syscore_ops chain, e.g. simply adding a resume hook is not guaranteed to work, as KVM does VMXON in its own resume hook, kvm_resume(), when KVM has active guests.
--- arch/x86/include/asm/cpu.h | 5 +++++ arch/x86/kernel/cpu/centaur.c | 1 + arch/x86/kernel/cpu/cpu.h | 4 ---- arch/x86/kernel/cpu/zhaoxin.c | 1 + arch/x86/power/cpu.c | 6 ++++++ 5 files changed, 13 insertions(+), 4 deletions(-)
arch/x86/include/asm/cpu.h +5 -0
@@ -58,4 +58,9 @@ static inline bool handle_guest_split_lock(unsigned long ip)return false; }#endif +#ifdef CONFIG_IA32_FEAT_CTL +void init_ia32_feat_ctl (struct cpuinfo_x86 *c); +#else +static inline void init_ia32_feat_ctl (struct cpuinfo_x86 *c) {} +#endif #endif /* _ASM_X86_CPU_H */
arch/x86/kernel/cpu/centaur.c +1 -0
@@ -3,6 +3,7 @@#include <linux/sched.h> #include <linux/sched/clock.h> +#include <asm/cpu.h> #include <asm/cpufeature.h> #include <asm/e820/api.h> #include <asm/mtrr.h>
arch/x86/kernel/cpu/cpu.h +0 -4
@@ -81,8 +81,4 @@ extern void update_srbds_msr(void);extern u64 x86_read_arch_cap_msr (void ); -#ifdef CONFIG_IA32_FEAT_CTL -void init_ia32_feat_ctl (struct cpuinfo_x86 *c); -#endif -#endif /* ARCH_X86_CPU_H */
arch/x86/kernel/cpu/zhaoxin.c +1 -0
@@ -2,6 +2,7 @@#include <linux/sched.h> #include <linux/sched/clock.h> +#include <asm/cpu.h> #include <asm/cpufeature.h> #include "cpu.h"
arch/x86/power/cpu.c +6 -0
@@ -193,6 +193,8 @@ static void fix_processor_context(void)*/ static void notrace __restore_processor_state(struct saved_context *ctxt) { +struct cpuinfo_x86 *c; +if (ctxt->misc_enable_saved)wrmsrl (MSR_IA32_MISC_ENABLE , ctxt->misc_enable);/*
@@ -263,6 +265,10 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)mtrr_bp_restore ();perf_restore_debug_store ();msr_restore_context (ctxt); + + c = &cpu_data (smp_processor_id ()); +if (cpu_has (c,X86_FEATURE_MSR_IA32_FEAT_CTL )) +init_ia32_feat_ctl (c); }/* Needed by apm.c */
Rafael J. Wysocki
maintainerQuoted 14 lines · Sean Christopherson
Reinitialize
IA32_FEAT_CTLon the BSP during wakeup to handle the case where firmware doesn't initialize or save/restore across S3. This fixes a bug whereIA32_FEAT_CTLis left uninitialized and results in VMXON taking a #GP due to VMX not being fully enabled, i.e. breaks KVM.Use
init_ia32_feat_ctl()to "restore"IA32_FEAT_CTLas it already deals with the case where the MSR is locked, and because APs already redoinit_ia32_feat_ctl()during suspend by virtue of the SMP boot flow being used to reinitialize APs upon wakeup. Do the call in the early wakeup flow to avoid dependencies in thesyscore_opschain, e.g. simply adding a resume hook is not guaranteed to work, as KVM does VMXON in its own resume hook,kvm_resume(), when KVM has active guests.
Quoted 9 lines
Reported-by Brad Campbell <[email protected]>Tested-by Brad Campbell <[email protected]>Reviewed-by Liam Merwick <[email protected]>Reviewed-by Maxim Levitsky <[email protected]>Cc Paolo Bonzini <[email protected]>Cc [email protected] # v5.6Fixes 21bd3467a58e ("KVM: VMX: Drop initialization of IA32_FEAT_CTL MSR")Signed-off-by Sean Christopherson <[email protected]>
Given the regression fix nature of this patch, is it being taken care of by anyone (tip in particular) already?
Quoted 92 lines
---
v2:
- Collect Reviewed/Tested tags. [Brad, Liam, Maxim].
- Includeasm/cpu.hto fix Zhaoxin and Centaur builds. [Brad, LKP]
- Add Cc to stable. [Liam]arch/x86/include/asm/cpu.h | 5 +++++ arch/x86/kernel/cpu/centaur.c | 1 + arch/x86/kernel/cpu/cpu.h | 4 ---- arch/x86/kernel/cpu/zhaoxin.c | 1 + arch/x86/power/cpu.c | 6 ++++++ 5 files changed, 13 insertions(+), 4 deletions(-)arch/x86/include/asm/cpu.h +5
-0@@ -58,4 +58,9 @@ static inline bool handle_guest_split_lock(unsigned long ip)return false; }#endif +#ifdef CONFIG_IA32_FEAT_CTL +void init_ia32_feat_ctl (struct cpuinfo_x86 *c); +#else +static inline void init_ia32_feat_ctl (struct cpuinfo_x86 *c) {} +#endif #endif /* _ASM_X86_CPU_H */ arch/x86/kernel/cpu/centaur.c +1
-0@@ -3,6 +3,7 @@#include <linux/sched.h> #include <linux/sched/clock.h> +#include <asm/cpu.h> #include <asm/cpufeature.h> #include <asm/e820/api.h> #include <asm/mtrr.h> arch/x86/kernel/cpu/cpu.h +0
-4@@ -80,8 +80,4 @@ extern void x86_spec_ctrl_setup_ap(void);extern u64 x86_read_arch_cap_msr (void ); -#ifdef CONFIG_IA32_FEAT_CTL -void init_ia32_feat_ctl (struct cpuinfo_x86 *c); -#endif -#endif /* ARCH_X86_CPU_H */ arch/x86/kernel/cpu/zhaoxin.c +1
-0@@ -2,6 +2,7 @@#include <linux/sched.h> #include <linux/sched/clock.h> +#include <asm/cpu.h> #include <asm/cpufeature.h> #include "cpu.h" arch/x86/power/cpu.c +6
-1@@ -193,6 +193,8 @@ static void fix_processor_context(void)*/ static void notrace __restore_processor_state(struct saved_context *ctxt) { +struct cpuinfo_x86 *c; +if (ctxt->misc_enable_saved)wrmsrl (MSR_IA32_MISC_ENABLE , ctxt->misc_enable);/* @@ -263,6 +265,10 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)mtrr_bp_restore ();perf_restore_debug_store ();msr_restore_context (ctxt); + + c = &cpu_data (smp_processor_id ()); +if (cpu_has (c,X86_FEATURE_MSR_IA32_FEAT_CTL )) +init_ia32_feat_ctl (c); }/* Needed by apm.c */ --2.26.0
Paolo Bonzini
maintainerQuoted 26 lines · Rafael J. Wysocki
Quoted 14 lines · Sean Christopherson
Reinitialize
IA32_FEAT_CTLon the BSP during wakeup to handle the case where firmware doesn't initialize or save/restore across S3. This fixes a bug whereIA32_FEAT_CTLis left uninitialized and results in VMXON taking a #GP due to VMX not being fully enabled, i.e. breaks KVM.Use
init_ia32_feat_ctl()to "restore"IA32_FEAT_CTLas it already deals with the case where the MSR is locked, and because APs already redoinit_ia32_feat_ctl()during suspend by virtue of the SMP boot flow being used to reinitialize APs upon wakeup. Do the call in the early wakeup flow to avoid dependencies in thesyscore_opschain, e.g. simply adding a resume hook is not guaranteed to work, as KVM does VMXON in its own resume hook,kvm_resume(), when KVM has active guests.Quoted 9 lines
Reported-by Brad Campbell <[email protected]>Tested-by Brad Campbell <[email protected]>Reviewed-by Liam Merwick <[email protected]>Reviewed-by Maxim Levitsky <[email protected]>Cc Paolo Bonzini <[email protected]>Cc [email protected] # v5.6Fixes 21bd3467a58e ("KVM: VMX: Drop initialization of IA32_FEAT_CTL MSR")Signed-off-by Sean Christopherson <[email protected]>
Quoted 2 lines
Given the regression fix nature of this patch, is it being taken care of by anyone (tip in particular) already?
I was waiting for tip to pick it up, but I can as well with an Acked-by (KVM is broken by the patch but there's nothing KVM specific in it).
Paolo
Quoted 93 lines
Quoted 92 lines
---
v2:
- Collect Reviewed/Tested tags. [Brad, Liam, Maxim].
- Includeasm/cpu.hto fix Zhaoxin and Centaur builds. [Brad, LKP]
- Add Cc to stable. [Liam]arch/x86/include/asm/cpu.h | 5 +++++ arch/x86/kernel/cpu/centaur.c | 1 + arch/x86/kernel/cpu/cpu.h | 4 ---- arch/x86/kernel/cpu/zhaoxin.c | 1 + arch/x86/power/cpu.c | 6 ++++++ 5 files changed, 13 insertions(+), 4 deletions(-)arch/x86/include/asm/cpu.h +5
-0@@ -58,4 +58,9 @@ static inline bool handle_guest_split_lock(unsigned long ip)return false; }#endif +#ifdef CONFIG_IA32_FEAT_CTL +void init_ia32_feat_ctl (struct cpuinfo_x86 *c); +#else +static inline void init_ia32_feat_ctl (struct cpuinfo_x86 *c) {} +#endif #endif /* _ASM_X86_CPU_H */ arch/x86/kernel/cpu/centaur.c +1
-0@@ -3,6 +3,7 @@#include <linux/sched.h> #include <linux/sched/clock.h> +#include <asm/cpu.h> #include <asm/cpufeature.h> #include <asm/e820/api.h> #include <asm/mtrr.h> arch/x86/kernel/cpu/cpu.h +0
-4@@ -80,8 +80,4 @@ extern void x86_spec_ctrl_setup_ap(void);extern u64 x86_read_arch_cap_msr (void ); -#ifdef CONFIG_IA32_FEAT_CTL -void init_ia32_feat_ctl (struct cpuinfo_x86 *c); -#endif -#endif /* ARCH_X86_CPU_H */ arch/x86/kernel/cpu/zhaoxin.c +1
-0@@ -2,6 +2,7 @@#include <linux/sched.h> #include <linux/sched/clock.h> +#include <asm/cpu.h> #include <asm/cpufeature.h> #include "cpu.h" arch/x86/power/cpu.c +6
-1@@ -193,6 +193,8 @@ static void fix_processor_context(void)*/ static void notrace __restore_processor_state(struct saved_context *ctxt) { +struct cpuinfo_x86 *c; +if (ctxt->misc_enable_saved)wrmsrl (MSR_IA32_MISC_ENABLE , ctxt->misc_enable);/* @@ -263,6 +265,10 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)mtrr_bp_restore ();perf_restore_debug_store ();msr_restore_context (ctxt); + + c = &cpu_data (smp_processor_id ()); +if (cpu_has (c,X86_FEATURE_MSR_IA32_FEAT_CTL )) +init_ia32_feat_ctl (c); }/* Needed by apm.c */ --2.26.0
Borislav Petkov
maintainerQuoted 5 lines · Paolo Bonzini
Quoted 2 lines
Given the regression fix nature of this patch, is it being taken care of by anyone (tip in particular) already?
I was waiting for tip to pick it up, but I can as well with an Acked-by (KVM is broken by the patch but there's nothing KVM specific in it).
https://git.kernel.org/tip/5d5103595e9e53048bb7e70ee2673c897ab38300
will be in -rc3, most likely.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette