Check that the VM-function controls are actually enabled before performing eVMCS-specific consistency checks, as the VMFUNC controls are supposed to be completely ignored if they're not enabled. Per the SDM: If the "enable VM functions" processor-based VM-execution control is 0, no checks are performed on the VM-function controls. Fixes: 3ff8a13d41b2 ("KVM: nVMX: WARN once and fail VM-Enter if eVMCS sees VMFUNC[63:32] != 0") Fixes: a83502314ce3 ("x86/kvm/hyper-v: don't allow to turn on unsupported VMX controls for nested guests") Cc: stable@vger.kernel.org Reported-by: Manuel Andreas Closes: https://lore.kernel.org/all/f1f39118-2e1b-476b-9a84-ef7d56412bdc@tum.de Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/hyperv.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/hyperv.c b/arch/x86/kvm/vmx/hyperv.c index 2b40ac32ff06..a1daf8f2ec5a 100644 --- a/arch/x86/kvm/vmx/hyperv.c +++ b/arch/x86/kvm/vmx/hyperv.c @@ -187,11 +187,10 @@ int nested_evmcs_check_controls(struct vmcs12 *vmcs12) * controls in bits 63:32, i.e. dropping those bits on the consistency * check is intentional. */ - if (WARN_ON_ONCE(vmcs12->vm_function_control >> 32)) - return -EINVAL; - - if (CC(!nested_evmcs_is_valid_controls(EVMCS_VMFUNC, - vmcs12->vm_function_control))) + if (nested_cpu_has_vmfunc(vmcs12) && + (WARN_ON_ONCE(vmcs12->vm_function_control >> 32) || + CC(!nested_evmcs_is_valid_controls(EVMCS_VMFUNC, + vmcs12->vm_function_control)))) return -EINVAL; return 0; -- 2.56.0.567.gdb80ae8cd5-goog