Skip to content

Commit 8ecaf93

Browse files
sean-jcSasha Levin
authored andcommitted
Revert "KVM: VMX: Move LOAD_IA32_PERF_GLOBAL_CTRL errata handling out of setup_vmcs_config()"
commit 85434c3 upstream. Revert back to clearing VM_{ENTRY,EXIT}_LOAD_IA32_PERF_GLOBAL_CTRL in KVM's golden VMCS config, as applying the workaround during vCPU creation is pointless and broken. KVM *unconditionally* clears the controls in the values returned by vmx_vmentry_ctrl() and vmx_vmexit_ctrl(), as KVM loads PERF_GLOBAL_CTRL if and only if its necessary to do so. E.g. if KVM wants to run the guest with the same PERF_GLOBAL_CTRL as the host, then there's no need to re-load the MSR on entry and exit. Even worse, the buggy commit failed to apply the erratum where it's actually needed, add_atomic_switch_msr(). As a result, KVM completely ignores the erratum for all intents and purposes, i.e. uses the flawed VMCS controls to load PERF_GLOBAL_CTRL. To top things off, the patch was intended to be dropped, as the premise of an L1 VMM being able to pivot on FMS is flawed, and KVM can (and now does) fully emulate the controls in software. Simply revert the commit, as all upstream supported kernels that have the buggy commit should also have commit f4c93d1 ("KVM: nVMX: Always emulate PERF_GLOBAL_CTRL VM-Entry/VM-Exit controls"), i.e. the (likely theoretical) live migration concern is a complete non-issue. Opportunistically drop the manual "kvm: " scope from the warning about the erratum, as KVM now uses pr_fmt() to provide the correct scope (v6.1 kernels and earlier don't, but the erratum only applies to CPUs that are 15+ years old; it's not worth a separate patch). This reverts commit 9d78d6f. Link: https://lore.kernel.org/all/[email protected] Fixes: 9d78d6f ("KVM: VMX: Move LOAD_IA32_PERF_GLOBAL_CTRL errata handling out of setup_vmcs_config()") Cc: [email protected] Cc: Vitaly Kuznetsov <[email protected]> Cc: Maxim Levitsky <[email protected]> Signed-off-by: Sean Christopherson <[email protected]> Reviewed-by: Vitaly Kuznetsov <[email protected]> Message-ID: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6b5c131 commit 8ecaf93

File tree

1 file changed

+21
-33
lines changed

1 file changed

+21
-33
lines changed

arch/x86/kvm/vmx/vmx.c

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2551,28 +2551,6 @@ static bool cpu_has_sgx(void)
25512551
return cpuid_eax(0) >= 0x12 && (cpuid_eax(0x12) & BIT(0));
25522552
}
25532553

2554-
/*
2555-
* Some cpus support VM_{ENTRY,EXIT}_IA32_PERF_GLOBAL_CTRL but they
2556-
* can't be used due to errata where VM Exit may incorrectly clear
2557-
* IA32_PERF_GLOBAL_CTRL[34:32]. Work around the errata by using the
2558-
* MSR load mechanism to switch IA32_PERF_GLOBAL_CTRL.
2559-
*/
2560-
static bool cpu_has_perf_global_ctrl_bug(void)
2561-
{
2562-
switch (boot_cpu_data.x86_vfm) {
2563-
case INTEL_NEHALEM_EP: /* AAK155 */
2564-
case INTEL_NEHALEM: /* AAP115 */
2565-
case INTEL_WESTMERE: /* AAT100 */
2566-
case INTEL_WESTMERE_EP: /* BC86,AAY89,BD102 */
2567-
case INTEL_NEHALEM_EX: /* BA97 */
2568-
return true;
2569-
default:
2570-
break;
2571-
}
2572-
2573-
return false;
2574-
}
2575-
25762554
static int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt, u32 msr, u32 *result)
25772555
{
25782556
u32 vmx_msr_low, vmx_msr_high;
@@ -2732,6 +2710,27 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
27322710
_vmexit_control &= ~x_ctrl;
27332711
}
27342712

2713+
/*
2714+
* Some cpus support VM_{ENTRY,EXIT}_IA32_PERF_GLOBAL_CTRL but they
2715+
* can't be used due to an errata where VM Exit may incorrectly clear
2716+
* IA32_PERF_GLOBAL_CTRL[34:32]. Workaround the errata by using the
2717+
* MSR load mechanism to switch IA32_PERF_GLOBAL_CTRL.
2718+
*/
2719+
switch (boot_cpu_data.x86_vfm) {
2720+
case INTEL_NEHALEM_EP: /* AAK155 */
2721+
case INTEL_NEHALEM: /* AAP115 */
2722+
case INTEL_WESTMERE: /* AAT100 */
2723+
case INTEL_WESTMERE_EP: /* BC86,AAY89,BD102 */
2724+
case INTEL_NEHALEM_EX: /* BA97 */
2725+
_vmentry_control &= ~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL;
2726+
_vmexit_control &= ~VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL;
2727+
pr_warn_once("VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL "
2728+
"does not work properly. Using workaround\n");
2729+
break;
2730+
default:
2731+
break;
2732+
}
2733+
27352734
rdmsrl(MSR_IA32_VMX_BASIC, basic_msr);
27362735

27372736
/* IA-32 SDM Vol 3B: VMCS size is never greater than 4kB. */
@@ -4422,9 +4421,6 @@ static u32 vmx_vmentry_ctrl(void)
44224421
VM_ENTRY_LOAD_IA32_EFER |
44234422
VM_ENTRY_IA32E_MODE);
44244423

4425-
if (cpu_has_perf_global_ctrl_bug())
4426-
vmentry_ctrl &= ~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL;
4427-
44284424
return vmentry_ctrl;
44294425
}
44304426

@@ -4442,10 +4438,6 @@ static u32 vmx_vmexit_ctrl(void)
44424438
if (vmx_pt_mode_is_system())
44434439
vmexit_ctrl &= ~(VM_EXIT_PT_CONCEAL_PIP |
44444440
VM_EXIT_CLEAR_IA32_RTIT_CTL);
4445-
4446-
if (cpu_has_perf_global_ctrl_bug())
4447-
vmexit_ctrl &= ~VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL;
4448-
44494441
/* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */
44504442
return vmexit_ctrl &
44514443
~(VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL | VM_EXIT_LOAD_IA32_EFER);
@@ -8400,10 +8392,6 @@ __init int vmx_hardware_setup(void)
84008392
if (setup_vmcs_config(&vmcs_config, &vmx_capability) < 0)
84018393
return -EIO;
84028394

8403-
if (cpu_has_perf_global_ctrl_bug())
8404-
pr_warn_once("VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL "
8405-
"does not work properly. Using workaround\n");
8406-
84078395
if (boot_cpu_has(X86_FEATURE_NX))
84088396
kvm_enable_efer_bits(EFER_NX);
84098397

0 commit comments

Comments
 (0)