summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Christopherson <sean.j.christopherson@intel.com>2020-03-02 15:56:05 -0800
committerPaolo Bonzini <pbonzini@redhat.com>2020-03-16 17:57:55 +0100
commit619a17f11069ce3d338e00a621f57dd8dec164c2 (patch)
treea9be970c3a556c00466e7af7e5d83192bc98ddb9
parent68c9a46e9ee8e9f673c7e0d1bbf483a289b5a86f (diff)
downloadlinux-619a17f11069ce3d338e00a621f57dd8dec164c2.tar.bz2
KVM: x86: Refactor loop around do_cpuid_func() to separate helper
Move the guts of kvm_dev_ioctl_get_cpuid()'s CPUID func loop to a separate helper to improve code readability and pave the way for future cleanup. No functional change intended. 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.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 47ce04762c20..f49fdd06f511 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -839,6 +839,29 @@ static bool is_centaur_cpu(const struct kvm_cpuid_param *param)
return boot_cpu_data.x86_vendor == X86_VENDOR_CENTAUR;
}
+static int get_cpuid_func(struct kvm_cpuid_entry2 *entries, u32 func,
+ int *nent, int maxnent, unsigned int type)
+{
+ u32 limit;
+ int r;
+
+ r = do_cpuid_func(&entries[*nent], func, nent, maxnent, type);
+ if (r)
+ return r;
+
+ limit = entries[*nent - 1].eax;
+ for (func = func + 1; func <= limit; ++func) {
+ if (*nent >= maxnent)
+ return -E2BIG;
+
+ r = do_cpuid_func(&entries[*nent], func, nent, maxnent, type);
+ if (r)
+ break;
+ }
+
+ return r;
+}
+
static bool sanity_check_entries(struct kvm_cpuid_entry2 __user *entries,
__u32 num_entries, unsigned int ioctl_type)
{
@@ -871,8 +894,8 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
unsigned int type)
{
struct kvm_cpuid_entry2 *cpuid_entries;
- int limit, nent = 0, r = -E2BIG, i;
- u32 func;
+ int nent = 0, r = -E2BIG, i;
+
static const struct kvm_cpuid_param param[] = {
{ .func = 0 },
{ .func = 0x80000000 },
@@ -901,22 +924,8 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
if (ent->qualifier && !ent->qualifier(ent))
continue;
- r = do_cpuid_func(&cpuid_entries[nent], ent->func,
- &nent, cpuid->nent, type);
-
- if (r)
- goto out_free;
-
- limit = cpuid_entries[nent - 1].eax;
- for (func = ent->func + 1; func <= limit && r == 0; ++func) {
- if (nent >= cpuid->nent) {
- r = -E2BIG;
- goto out_free;
- }
- r = do_cpuid_func(&cpuid_entries[nent], func,
- &nent, cpuid->nent, type);
- }
-
+ r = get_cpuid_func(cpuid_entries, ent->func, &nent,
+ cpuid->nent, type);
if (r)
goto out_free;
}