]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
c84253f90fc263bca84164cdd69d1f5a76aa337a
[thirdparty/kernel/stable-queue.git] /
1 From 85434c3c73fcad58870016ddfe5eaa5036672675 Mon Sep 17 00:00:00 2001
2 From: Sean Christopherson <seanjc@google.com>
3 Date: Mon, 18 Nov 2024 17:14:33 -0800
4 Subject: Revert "KVM: VMX: Move LOAD_IA32_PERF_GLOBAL_CTRL errata handling out of setup_vmcs_config()"
5
6 From: Sean Christopherson <seanjc@google.com>
7
8 commit 85434c3c73fcad58870016ddfe5eaa5036672675 upstream.
9
10 Revert back to clearing VM_{ENTRY,EXIT}_LOAD_IA32_PERF_GLOBAL_CTRL in KVM's
11 golden VMCS config, as applying the workaround during vCPU creation is
12 pointless and broken. KVM *unconditionally* clears the controls in the
13 values returned by vmx_vmentry_ctrl() and vmx_vmexit_ctrl(), as KVM loads
14 PERF_GLOBAL_CTRL if and only if its necessary to do so. E.g. if KVM wants
15 to run the guest with the same PERF_GLOBAL_CTRL as the host, then there's
16 no need to re-load the MSR on entry and exit.
17
18 Even worse, the buggy commit failed to apply the erratum where it's
19 actually needed, add_atomic_switch_msr(). As a result, KVM completely
20 ignores the erratum for all intents and purposes, i.e. uses the flawed
21 VMCS controls to load PERF_GLOBAL_CTRL.
22
23 To top things off, the patch was intended to be dropped, as the premise
24 of an L1 VMM being able to pivot on FMS is flawed, and KVM can (and now
25 does) fully emulate the controls in software. Simply revert the commit,
26 as all upstream supported kernels that have the buggy commit should also
27 have commit f4c93d1a0e71 ("KVM: nVMX: Always emulate PERF_GLOBAL_CTRL
28 VM-Entry/VM-Exit controls"), i.e. the (likely theoretical) live migration
29 concern is a complete non-issue.
30
31 Opportunistically drop the manual "kvm: " scope from the warning about
32 the erratum, as KVM now uses pr_fmt() to provide the correct scope (v6.1
33 kernels and earlier don't, but the erratum only applies to CPUs that are
34 15+ years old; it's not worth a separate patch).
35
36 This reverts commit 9d78d6fb186bc4aff41b5d6c4726b76649d3cb53.
37
38 Link: https://lore.kernel.org/all/YtnZmCutdd5tpUmz@google.com
39 Fixes: 9d78d6fb186b ("KVM: VMX: Move LOAD_IA32_PERF_GLOBAL_CTRL errata handling out of setup_vmcs_config()")
40 Cc: stable@vger.kernel.org
41 Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
42 Cc: Maxim Levitsky <mlevitsk@redhat.com>
43 Signed-off-by: Sean Christopherson <seanjc@google.com>
44 Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
45 Message-ID: <20241119011433.1797921-1-seanjc@google.com>
46 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
47 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
48 ---
49 arch/x86/kvm/vmx/vmx.c | 54 +++++++++++++++++++------------------------------
50 1 file changed, 21 insertions(+), 33 deletions(-)
51
52 --- a/arch/x86/kvm/vmx/vmx.c
53 +++ b/arch/x86/kvm/vmx/vmx.c
54 @@ -2551,28 +2551,6 @@ static bool cpu_has_sgx(void)
55 return cpuid_eax(0) >= 0x12 && (cpuid_eax(0x12) & BIT(0));
56 }
57
58 -/*
59 - * Some cpus support VM_{ENTRY,EXIT}_IA32_PERF_GLOBAL_CTRL but they
60 - * can't be used due to errata where VM Exit may incorrectly clear
61 - * IA32_PERF_GLOBAL_CTRL[34:32]. Work around the errata by using the
62 - * MSR load mechanism to switch IA32_PERF_GLOBAL_CTRL.
63 - */
64 -static bool cpu_has_perf_global_ctrl_bug(void)
65 -{
66 - switch (boot_cpu_data.x86_vfm) {
67 - case INTEL_NEHALEM_EP: /* AAK155 */
68 - case INTEL_NEHALEM: /* AAP115 */
69 - case INTEL_WESTMERE: /* AAT100 */
70 - case INTEL_WESTMERE_EP: /* BC86,AAY89,BD102 */
71 - case INTEL_NEHALEM_EX: /* BA97 */
72 - return true;
73 - default:
74 - break;
75 - }
76 -
77 - return false;
78 -}
79 -
80 static int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt, u32 msr, u32 *result)
81 {
82 u32 vmx_msr_low, vmx_msr_high;
83 @@ -2732,6 +2710,27 @@ static int setup_vmcs_config(struct vmcs
84 _vmexit_control &= ~x_ctrl;
85 }
86
87 + /*
88 + * Some cpus support VM_{ENTRY,EXIT}_IA32_PERF_GLOBAL_CTRL but they
89 + * can't be used due to an errata where VM Exit may incorrectly clear
90 + * IA32_PERF_GLOBAL_CTRL[34:32]. Workaround the errata by using the
91 + * MSR load mechanism to switch IA32_PERF_GLOBAL_CTRL.
92 + */
93 + switch (boot_cpu_data.x86_vfm) {
94 + case INTEL_NEHALEM_EP: /* AAK155 */
95 + case INTEL_NEHALEM: /* AAP115 */
96 + case INTEL_WESTMERE: /* AAT100 */
97 + case INTEL_WESTMERE_EP: /* BC86,AAY89,BD102 */
98 + case INTEL_NEHALEM_EX: /* BA97 */
99 + _vmentry_control &= ~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL;
100 + _vmexit_control &= ~VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL;
101 + pr_warn_once("VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL "
102 + "does not work properly. Using workaround\n");
103 + break;
104 + default:
105 + break;
106 + }
107 +
108 rdmsrl(MSR_IA32_VMX_BASIC, basic_msr);
109
110 /* IA-32 SDM Vol 3B: VMCS size is never greater than 4kB. */
111 @@ -4422,9 +4421,6 @@ static u32 vmx_vmentry_ctrl(void)
112 VM_ENTRY_LOAD_IA32_EFER |
113 VM_ENTRY_IA32E_MODE);
114
115 - if (cpu_has_perf_global_ctrl_bug())
116 - vmentry_ctrl &= ~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL;
117 -
118 return vmentry_ctrl;
119 }
120
121 @@ -4442,10 +4438,6 @@ static u32 vmx_vmexit_ctrl(void)
122 if (vmx_pt_mode_is_system())
123 vmexit_ctrl &= ~(VM_EXIT_PT_CONCEAL_PIP |
124 VM_EXIT_CLEAR_IA32_RTIT_CTL);
125 -
126 - if (cpu_has_perf_global_ctrl_bug())
127 - vmexit_ctrl &= ~VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL;
128 -
129 /* Loading of EFER and PERF_GLOBAL_CTRL are toggled dynamically */
130 return vmexit_ctrl &
131 ~(VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL | VM_EXIT_LOAD_IA32_EFER);
132 @@ -8400,10 +8392,6 @@ __init int vmx_hardware_setup(void)
133 if (setup_vmcs_config(&vmcs_config, &vmx_capability) < 0)
134 return -EIO;
135
136 - if (cpu_has_perf_global_ctrl_bug())
137 - pr_warn_once("VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL "
138 - "does not work properly. Using workaround\n");
139 -
140 if (boot_cpu_has(X86_FEATURE_NX))
141 kvm_enable_efer_bits(EFER_NX);
142