Skip to content

Commit 85434c3

Browse files
sean-jcbonzini
authored andcommitted
Revert "KVM: VMX: Move LOAD_IA32_PERF_GLOBAL_CTRL errata handling out of setup_vmcs_config()"
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]>
1 parent d96c77b commit 85434c3

File tree

1 file changed

+21
-33
lines changed

1 file changed

+21
-33
lines changed

arch/x86/kvm/vmx/vmx.c

+21-33
Original file line numberDiff line numberDiff line change
@@ -2548,28 +2548,6 @@ static bool cpu_has_sgx(void)
25482548
return cpuid_eax(0) >= 0x12 && (cpuid_eax(0x12) & BIT(0));
25492549
}
25502550

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

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

27342733
/* IA-32 SDM Vol 3B: VMCS size is never greater than 4kB. */
@@ -4432,9 +4431,6 @@ static u32 vmx_vmentry_ctrl(void)
44324431
VM_ENTRY_LOAD_IA32_EFER |
44334432
VM_ENTRY_IA32E_MODE);
44344433

4435-
if (cpu_has_perf_global_ctrl_bug())
4436-
vmentry_ctrl &= ~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL;
4437-
44384434
return vmentry_ctrl;
44394435
}
44404436

@@ -4452,10 +4448,6 @@ static u32 vmx_vmexit_ctrl(void)
44524448
if (vmx_pt_mode_is_system())
44534449
vmexit_ctrl &= ~(VM_EXIT_PT_CONCEAL_PIP |
44544450
VM_EXIT_CLEAR_IA32_RTIT_CTL);
4455-
4456-
if (cpu_has_perf_global_ctrl_bug())
4457-
vmexit_ctrl &= ~VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL;
4458-
44594451
/* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */
44604452
return vmexit_ctrl &
44614453
~(VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL | VM_EXIT_LOAD_IA32_EFER);
@@ -8415,10 +8407,6 @@ __init int vmx_hardware_setup(void)
84158407
if (setup_vmcs_config(&vmcs_config, &vmx_capability) < 0)
84168408
return -EIO;
84178409

8418-
if (cpu_has_perf_global_ctrl_bug())
8419-
pr_warn_once("VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL "
8420-
"does not work properly. Using workaround\n");
8421-
84228410
if (boot_cpu_has(X86_FEATURE_NX))
84238411
kvm_enable_efer_bits(EFER_NX);
84248412

0 commit comments

Comments
 (0)