1 From ea1529873ab18c204688cf31746df851c098cbea Mon Sep 17 00:00:00 2001
2 From: Vitaly Kuznetsov <vkuznets@redhat.com>
3 Date: Tue, 27 Aug 2019 18:04:02 +0200
4 Subject: KVM: x86: hyper-v: don't crash on KVM_GET_SUPPORTED_HV_CPUID when kvm_intel.nested is disabled
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 From: Vitaly Kuznetsov <vkuznets@redhat.com>
11 commit ea1529873ab18c204688cf31746df851c098cbea upstream.
13 If kvm_intel is loaded with nested=0 parameter an attempt to perform
14 KVM_GET_SUPPORTED_HV_CPUID results in OOPS as nested_get_evmcs_version hook
15 in kvm_x86_ops is NULL (we assign it in nested_vmx_hardware_setup() and
16 this only happens in case nested is enabled).
18 Check that kvm_x86_ops->nested_get_evmcs_version is not NULL before
19 calling it. With this, we can remove the stub from svm as it is no
22 Cc: <stable@vger.kernel.org>
23 Fixes: e2e871ab2f02 ("x86/kvm/hyper-v: Introduce nested_get_evmcs_version() helper")
24 Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
25 Reviewed-by: Jim Mattson <jmattson@google.com>
26 Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
30 arch/x86/kvm/hyperv.c | 5 ++++-
31 arch/x86/kvm/svm.c | 8 +-------
32 arch/x86/kvm/vmx/vmx.c | 1 +
33 3 files changed, 6 insertions(+), 8 deletions(-)
35 --- a/arch/x86/kvm/hyperv.c
36 +++ b/arch/x86/kvm/hyperv.c
37 @@ -1783,7 +1783,7 @@ int kvm_vm_ioctl_hv_eventfd(struct kvm *
38 int kvm_vcpu_ioctl_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid,
39 struct kvm_cpuid_entry2 __user *entries)
41 - uint16_t evmcs_ver = kvm_x86_ops->nested_get_evmcs_version(vcpu);
42 + uint16_t evmcs_ver = 0;
43 struct kvm_cpuid_entry2 cpuid_entries[] = {
44 { .function = HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS },
45 { .function = HYPERV_CPUID_INTERFACE },
46 @@ -1795,6 +1795,9 @@ int kvm_vcpu_ioctl_get_hv_cpuid(struct k
48 int i, nent = ARRAY_SIZE(cpuid_entries);
50 + if (kvm_x86_ops->nested_get_evmcs_version)
51 + evmcs_ver = kvm_x86_ops->nested_get_evmcs_version(vcpu);
53 /* Skip NESTED_FEATURES if eVMCS is not supported */
56 --- a/arch/x86/kvm/svm.c
57 +++ b/arch/x86/kvm/svm.c
58 @@ -7107,12 +7107,6 @@ failed:
62 -static uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu)
68 static int nested_enable_evmcs(struct kvm_vcpu *vcpu,
69 uint16_t *vmcs_version)
71 @@ -7283,7 +7277,7 @@ static struct kvm_x86_ops svm_x86_ops __
72 .mem_enc_unreg_region = svm_unregister_enc_region,
74 .nested_enable_evmcs = nested_enable_evmcs,
75 - .nested_get_evmcs_version = nested_get_evmcs_version,
76 + .nested_get_evmcs_version = NULL,
78 .need_emulation_on_page_fault = svm_need_emulation_on_page_fault,
80 --- a/arch/x86/kvm/vmx/vmx.c
81 +++ b/arch/x86/kvm/vmx/vmx.c
82 @@ -7733,6 +7733,7 @@ static struct kvm_x86_ops vmx_x86_ops __
83 .set_nested_state = NULL,
84 .get_vmcs12_pages = NULL,
85 .nested_enable_evmcs = NULL,
86 + .nested_get_evmcs_version = NULL,
87 .need_emulation_on_page_fault = vmx_need_emulation_on_page_fault,