Commit ab8bcf64 authored by Paolo Bonzini's avatar Paolo Bonzini

KVM: cpuid: do_cpuid_ent works on a whole CPUID function

Rename it as well as __do_cpuid_ent and __do_cpuid_ent_emulated to have
"func" in its name, and drop the index parameter which is always 0.
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 7be373b6
...@@ -294,14 +294,19 @@ static void do_cpuid_1_ent(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -294,14 +294,19 @@ static void do_cpuid_1_ent(struct kvm_cpuid_entry2 *entry, u32 function,
{ {
entry->function = function; entry->function = function;
entry->index = index; entry->index = index;
entry->flags = 0;
cpuid_count(entry->function, entry->index, cpuid_count(entry->function, entry->index,
&entry->eax, &entry->ebx, &entry->ecx, &entry->edx); &entry->eax, &entry->ebx, &entry->ecx, &entry->edx);
entry->flags = 0;
} }
static int __do_cpuid_ent_emulated(struct kvm_cpuid_entry2 *entry, static int __do_cpuid_func_emulated(struct kvm_cpuid_entry2 *entry,
u32 func, u32 index, int *nent, int maxnent) u32 func, int *nent, int maxnent)
{ {
entry->function = func;
entry->index = 0;
entry->flags = 0;
switch (func) { switch (func) {
case 0: case 0:
entry->eax = 7; entry->eax = 7;
...@@ -313,21 +318,18 @@ static int __do_cpuid_ent_emulated(struct kvm_cpuid_entry2 *entry, ...@@ -313,21 +318,18 @@ static int __do_cpuid_ent_emulated(struct kvm_cpuid_entry2 *entry,
break; break;
case 7: case 7:
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
if (index == 0) entry->eax = 0;
entry->ecx = F(RDPID); entry->ecx = F(RDPID);
++*nent; ++*nent;
default: default:
break; break;
} }
entry->function = func;
entry->index = index;
return 0; return 0;
} }
static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
u32 index, int *nent, int maxnent) int *nent, int maxnent)
{ {
int r; int r;
unsigned f_nx = is_efer_nx() ? F(NX) : 0; unsigned f_nx = is_efer_nx() ? F(NX) : 0;
...@@ -431,7 +433,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -431,7 +433,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
if (*nent >= maxnent) if (*nent >= maxnent)
goto out; goto out;
do_cpuid_1_ent(entry, function, index); do_cpuid_1_ent(entry, function, 0);
++*nent; ++*nent;
switch (function) { switch (function) {
...@@ -496,8 +498,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -496,8 +498,8 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
break; break;
case 7: { case 7: {
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
entry->eax = 0;
/* Mask ebx against host capability word 9 */ /* Mask ebx against host capability word 9 */
if (index == 0) {
entry->ebx &= kvm_cpuid_7_0_ebx_x86_features; entry->ebx &= kvm_cpuid_7_0_ebx_x86_features;
cpuid_mask(&entry->ebx, CPUID_7_0_EBX); cpuid_mask(&entry->ebx, CPUID_7_0_EBX);
// TSC_ADJUST is emulated // TSC_ADJUST is emulated
...@@ -518,12 +520,6 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -518,12 +520,6 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
* if the host doesn't support it. * if the host doesn't support it.
*/ */
entry->edx |= F(ARCH_CAPABILITIES); entry->edx |= F(ARCH_CAPABILITIES);
} else {
entry->ebx = 0;
entry->ecx = 0;
entry->edx = 0;
}
entry->eax = 0;
break; break;
} }
case 9: case 9:
...@@ -750,20 +746,19 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -750,20 +746,19 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
return r; return r;
} }
static int do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 func, static int do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 func,
u32 idx, int *nent, int maxnent, unsigned int type) int *nent, int maxnent, unsigned int type)
{ {
if (type == KVM_GET_EMULATED_CPUID) if (type == KVM_GET_EMULATED_CPUID)
return __do_cpuid_ent_emulated(entry, func, idx, nent, maxnent); return __do_cpuid_func_emulated(entry, func, nent, maxnent);
return __do_cpuid_ent(entry, func, idx, nent, maxnent); return __do_cpuid_func(entry, func, nent, maxnent);
} }
#undef F #undef F
struct kvm_cpuid_param { struct kvm_cpuid_param {
u32 func; u32 func;
u32 idx;
bool has_leaf_count; bool has_leaf_count;
bool (*qualifier)(const struct kvm_cpuid_param *param); bool (*qualifier)(const struct kvm_cpuid_param *param);
}; };
...@@ -836,7 +831,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid, ...@@ -836,7 +831,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
if (ent->qualifier && !ent->qualifier(ent)) if (ent->qualifier && !ent->qualifier(ent))
continue; continue;
r = do_cpuid_ent(&cpuid_entries[nent], ent->func, ent->idx, r = do_cpuid_func(&cpuid_entries[nent], ent->func,
&nent, cpuid->nent, type); &nent, cpuid->nent, type);
if (r) if (r)
...@@ -847,7 +842,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid, ...@@ -847,7 +842,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
limit = cpuid_entries[nent - 1].eax; limit = cpuid_entries[nent - 1].eax;
for (func = ent->func + 1; func <= limit && nent < cpuid->nent && r == 0; ++func) for (func = ent->func + 1; func <= limit && nent < cpuid->nent && r == 0; ++func)
r = do_cpuid_ent(&cpuid_entries[nent], func, ent->idx, r = do_cpuid_func(&cpuid_entries[nent], func,
&nent, cpuid->nent, type); &nent, cpuid->nent, type);
if (r) if (r)
......
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