]> www.infradead.org Git - users/willy/xarray.git/commitdiff
KVM: x86: Refactor CPUID 0xD.N sub-leaf entry creation
authorSean Christopherson <sean.j.christopherson@intel.com>
Mon, 2 Mar 2020 23:56:12 +0000 (15:56 -0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 16 Mar 2020 16:58:00 +0000 (17:58 +0100)
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>
arch/x86/kvm/cpuid.c

index 424dde41cb5d83634d038b08720f396ce9bf5e7b..6e1685a16cca9b15540bbe2753d009e314c0ef46 100644 (file)
@@ -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;