summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Christopherson <sean.j.christopherson@intel.com>2020-03-02 15:56:12 -0800
committerPaolo Bonzini <pbonzini@redhat.com>2020-03-16 17:58:00 +0100
commit8b2fc445a7619fec55740d0a5785aae4bd1058f3 (patch)
tree71f120538f6901ee759364ab5ee05506e34503cd
parent91001d403ad39b9c800a3b805bf48c5b027ecac5 (diff)
downloadlinux-8b2fc445a7619fec55740d0a5785aae4bd1058f3.tar.gz
linux-8b2fc445a7619fec55740d0a5785aae4bd1058f3.zip
KVM: x86: Refactor CPUID 0xD.N sub-leaf entry creation
Increment the number of CPUID entries immediately after do_host_cpuid() in preparation for moving the logic into do_host_cpuid(). Handle the rare/impossible case of encountering a bogus sub-leaf by decrementing the number entries on failure. Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--arch/x86/kvm/cpuid.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 424dde41cb5d..6e1685a16cca 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -677,6 +677,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
goto out;
do_host_cpuid(&entry[i], function, idx);
+ ++*nent;
/*
* The @supported check above should have filtered out
@@ -685,12 +686,13 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
* reach this point, and they should have a non-zero
* save state size.
*/
- if (WARN_ON_ONCE(!entry[i].eax || (entry[i].ecx & 1)))
+ if (WARN_ON_ONCE(!entry[i].eax || (entry[i].ecx & 1))) {
+ --*nent;
continue;
+ }
entry[i].ecx = 0;
entry[i].edx = 0;
- ++*nent;
++i;
}
break;