Skip to content

Commit 8d68bad

Browse files
vittyvkbonzini
authored andcommitted
KVM: nVMX: Filter out all unsupported controls when eVMCS was activated
Windows Server 2022 with Hyper-V role enabled failed to boot on KVM when enlightened VMCS is advertised. Debugging revealed there are two exposed secondary controls it is not happy with: SECONDARY_EXEC_ENABLE_VMFUNC and SECONDARY_EXEC_SHADOW_VMCS. These controls are known to be unsupported, as there are no corresponding fields in eVMCSv1 (see the comment above EVMCS1_UNSUPPORTED_2NDEXEC definition). Previously, commit 31de3d2 ("x86/kvm/hyper-v: move VMX controls sanitization out of nested_enable_evmcs()") introduced the required filtering mechanism for VMX MSRs but for some reason put only known to be problematic (and not full EVMCS1_UNSUPPORTED_* lists) controls there. Note, Windows Server 2022 seems to have gained some sanity check for VMX MSRs: it doesn't even try to launch a guest when there's something it doesn't like, nested_evmcs_check_controls() mechanism can't catch the problem. Let's be bold this time and instead of playing whack-a-mole just filter out all unsupported controls from VMX MSRs. Fixes: 31de3d2 ("x86/kvm/hyper-v: move VMX controls sanitization out of nested_enable_evmcs()") Signed-off-by: Vitaly Kuznetsov <[email protected]> Message-Id: <[email protected]> Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 0bbc2ca commit 8d68bad

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

arch/x86/kvm/vmx/evmcs.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,20 @@ void nested_evmcs_filter_control_msr(u32 msr_index, u64 *pdata)
353353
switch (msr_index) {
354354
case MSR_IA32_VMX_EXIT_CTLS:
355355
case MSR_IA32_VMX_TRUE_EXIT_CTLS:
356-
ctl_high &= ~VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL;
356+
ctl_high &= ~EVMCS1_UNSUPPORTED_VMEXIT_CTRL;
357357
break;
358358
case MSR_IA32_VMX_ENTRY_CTLS:
359359
case MSR_IA32_VMX_TRUE_ENTRY_CTLS:
360-
ctl_high &= ~VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL;
360+
ctl_high &= ~EVMCS1_UNSUPPORTED_VMENTRY_CTRL;
361361
break;
362362
case MSR_IA32_VMX_PROCBASED_CTLS2:
363-
ctl_high &= ~SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES;
363+
ctl_high &= ~EVMCS1_UNSUPPORTED_2NDEXEC;
364+
break;
365+
case MSR_IA32_VMX_PINBASED_CTLS:
366+
ctl_high &= ~EVMCS1_UNSUPPORTED_PINCTRL;
367+
break;
368+
case MSR_IA32_VMX_VMFUNC:
369+
ctl_low &= ~EVMCS1_UNSUPPORTED_VMFUNC;
364370
break;
365371
}
366372

arch/x86/kvm/vmx/vmx.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,10 +1837,11 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
18371837
&msr_info->data))
18381838
return 1;
18391839
/*
1840-
* Enlightened VMCS v1 doesn't have certain fields, but buggy
1841-
* Hyper-V versions are still trying to use corresponding
1842-
* features when they are exposed. Filter out the essential
1843-
* minimum.
1840+
* Enlightened VMCS v1 doesn't have certain VMCS fields but
1841+
* instead of just ignoring the features, different Hyper-V
1842+
* versions are either trying to use them and fail or do some
1843+
* sanity checking and refuse to boot. Filter all unsupported
1844+
* features out.
18441845
*/
18451846
if (!msr_info->host_initiated &&
18461847
vmx->nested.enlightened_vmcs_enabled)

0 commit comments

Comments
 (0)