]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
da7ee329e64386f62365552bf8fa7b9c8e091eb5
[thirdparty/kernel/stable-queue.git] /
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
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 From: Vitaly Kuznetsov <vkuznets@redhat.com>
10
11 commit ea1529873ab18c204688cf31746df851c098cbea upstream.
12
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).
17
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
20 longer needed.
21
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>
28
29 ---
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(-)
34
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)
40 {
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
47 };
48 int i, nent = ARRAY_SIZE(cpuid_entries);
49
50 + if (kvm_x86_ops->nested_get_evmcs_version)
51 + evmcs_ver = kvm_x86_ops->nested_get_evmcs_version(vcpu);
52 +
53 /* Skip NESTED_FEATURES if eVMCS is not supported */
54 if (!evmcs_ver)
55 --nent;
56 --- a/arch/x86/kvm/svm.c
57 +++ b/arch/x86/kvm/svm.c
58 @@ -7107,12 +7107,6 @@ failed:
59 return ret;
60 }
61
62 -static uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu)
63 -{
64 - /* Not supported */
65 - return 0;
66 -}
67 -
68 static int nested_enable_evmcs(struct kvm_vcpu *vcpu,
69 uint16_t *vmcs_version)
70 {
71 @@ -7283,7 +7277,7 @@ static struct kvm_x86_ops svm_x86_ops __
72 .mem_enc_unreg_region = svm_unregister_enc_region,
73
74 .nested_enable_evmcs = nested_enable_evmcs,
75 - .nested_get_evmcs_version = nested_get_evmcs_version,
76 + .nested_get_evmcs_version = NULL,
77
78 .need_emulation_on_page_fault = svm_need_emulation_on_page_fault,
79 };
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,
88 };
89