Commit 74fa0bc7 authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: x86: Hoist loop counter and terminator to top of __do_cpuid_func()

Declare "i" and "max_idx" at the top of __do_cpuid_func() to consolidate
a handful of declarations in various case statements.

More importantly, establish the pattern of using max_idx instead of e.g.
entry->eax as the loop terminator in preparation for refactoring how
entry is handled in __do_cpuid_func().

No functional change intended.
Reviewed-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: default avatarSean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent aa10a7dc
...@@ -439,7 +439,7 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry) ...@@ -439,7 +439,7 @@ static inline void do_cpuid_7_mask(struct kvm_cpuid_entry2 *entry)
static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
int *nent, int maxnent) int *nent, int maxnent)
{ {
int r; int r, i, max_idx;
unsigned f_nx = is_efer_nx() ? F(NX) : 0; unsigned f_nx = is_efer_nx() ? F(NX) : 0;
#ifdef CONFIG_X86_64 #ifdef CONFIG_X86_64
unsigned f_gbpages = (kvm_x86_ops->get_lpage_level() == PT_PDPE_LEVEL) unsigned f_gbpages = (kvm_x86_ops->get_lpage_level() == PT_PDPE_LEVEL)
...@@ -535,20 +535,18 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -535,20 +535,18 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
* may return different values. This forces us to get_cpu() before * may return different values. This forces us to get_cpu() before
* issuing the first command, and also to emulate this annoying behavior * issuing the first command, and also to emulate this annoying behavior
* in kvm_emulate_cpuid() using KVM_CPUID_FLAG_STATE_READ_NEXT */ * in kvm_emulate_cpuid() using KVM_CPUID_FLAG_STATE_READ_NEXT */
case 2: { case 2:
int t, times = entry->eax & 0xff;
entry->flags |= KVM_CPUID_FLAG_STATE_READ_NEXT; entry->flags |= KVM_CPUID_FLAG_STATE_READ_NEXT;
for (t = 1; t < times; ++t) {
if (!do_host_cpuid(&entry[t], nent, maxnent, function, 0)) for (i = 1, max_idx = entry->eax & 0xff; i < max_idx; ++i) {
if (!do_host_cpuid(&entry[i], nent, maxnent, function, 0))
goto out; goto out;
} }
break; break;
}
/* functions 4 and 0x8000001d have additional index. */ /* functions 4 and 0x8000001d have additional index. */
case 4: case 4:
case 0x8000001d: { case 0x8000001d: {
int i, cache_type; int cache_type;
/* read more entries until cache_type is zero */ /* read more entries until cache_type is zero */
for (i = 1; ; ++i) { for (i = 1; ; ++i) {
...@@ -568,19 +566,16 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -568,19 +566,16 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
entry->edx = 0; entry->edx = 0;
break; break;
/* function 7 has additional index. */ /* function 7 has additional index. */
case 7: { case 7:
int i;
do_cpuid_7_mask(entry); do_cpuid_7_mask(entry);
for (i = 1; i <= entry->eax; i++) { for (i = 1, max_idx = entry->eax; i <= max_idx; i++) {
if (!do_host_cpuid(&entry[i], nent, maxnent, function, i)) if (!do_host_cpuid(&entry[i], nent, maxnent, function, i))
goto out; goto out;
do_cpuid_7_mask(&entry[i]); do_cpuid_7_mask(&entry[i]);
} }
break; break;
}
case 9: case 9:
break; break;
case 0xa: { /* Architectural Performance Monitoring */ case 0xa: { /* Architectural Performance Monitoring */
...@@ -617,9 +612,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -617,9 +612,7 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
* thus they can be handled by common code. * thus they can be handled by common code.
*/ */
case 0x1f: case 0x1f:
case 0xb: { case 0xb:
int i;
/* /*
* We filled in entry[0] for CPUID(EAX=<function>, * We filled in entry[0] for CPUID(EAX=<function>,
* ECX=00H) above. If its level type (ECX[15:8]) is * ECX=00H) above. If its level type (ECX[15:8]) is
...@@ -633,9 +626,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -633,9 +626,8 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
goto out; goto out;
} }
break; break;
}
case 0xd: { case 0xd: {
int idx, i; int idx;
u64 supported = kvm_supported_xcr0(); u64 supported = kvm_supported_xcr0();
entry->eax &= supported; entry->eax &= supported;
...@@ -684,18 +676,15 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -684,18 +676,15 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
break; break;
} }
/* Intel PT */ /* Intel PT */
case 0x14: { case 0x14:
int t, times = entry->eax;
if (!f_intel_pt) if (!f_intel_pt)
break; break;
for (t = 1; t <= times; ++t) { for (i = 1, max_idx = entry->eax; i <= max_idx; ++i) {
if (!do_host_cpuid(&entry[t], nent, maxnent, function, t)) if (!do_host_cpuid(&entry[i], nent, maxnent, function, i))
goto out; goto out;
} }
break; break;
}
case KVM_CPUID_SIGNATURE: { case KVM_CPUID_SIGNATURE: {
static const char signature[12] = "KVMKVMKVM\0\0"; static const char signature[12] = "KVMKVMKVM\0\0";
const u32 *sigptr = (const u32 *)signature; const u32 *sigptr = (const u32 *)signature;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment