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,34 +498,28 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -496,34 +498,28 @@ 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;
/* Mask ebx against host capability word 9 */
if (index == 0) {
entry->ebx &= kvm_cpuid_7_0_ebx_x86_features;
cpuid_mask(&entry->ebx, CPUID_7_0_EBX);
// TSC_ADJUST is emulated
entry->ebx |= F(TSC_ADJUST);
entry->ecx &= kvm_cpuid_7_0_ecx_x86_features;
f_la57 = entry->ecx & F(LA57);
cpuid_mask(&entry->ecx, CPUID_7_ECX);
/* Set LA57 based on hardware capability. */
entry->ecx |= f_la57;
entry->ecx |= f_umip;
/* PKU is not yet implemented for shadow paging. */
if (!tdp_enabled || !boot_cpu_has(X86_FEATURE_OSPKE))
entry->ecx &= ~F(PKU);
entry->edx &= kvm_cpuid_7_0_edx_x86_features;
cpuid_mask(&entry->edx, CPUID_7_EDX);
/*
* We emulate ARCH_CAPABILITIES in software even
* if the host doesn't support it.
*/
entry->edx |= F(ARCH_CAPABILITIES);
} else {
entry->ebx = 0;
entry->ecx = 0;
entry->edx = 0;
}
entry->eax = 0; entry->eax = 0;
/* Mask ebx against host capability word 9 */
entry->ebx &= kvm_cpuid_7_0_ebx_x86_features;
cpuid_mask(&entry->ebx, CPUID_7_0_EBX);
// TSC_ADJUST is emulated
entry->ebx |= F(TSC_ADJUST);
entry->ecx &= kvm_cpuid_7_0_ecx_x86_features;
f_la57 = entry->ecx & F(LA57);
cpuid_mask(&entry->ecx, CPUID_7_ECX);
/* Set LA57 based on hardware capability. */
entry->ecx |= f_la57;
entry->ecx |= f_umip;
/* PKU is not yet implemented for shadow paging. */
if (!tdp_enabled || !boot_cpu_has(X86_FEATURE_OSPKE))
entry->ecx &= ~F(PKU);
entry->edx &= kvm_cpuid_7_0_edx_x86_features;
cpuid_mask(&entry->edx, CPUID_7_EDX);
/*
* We emulate ARCH_CAPABILITIES in software even
* if the host doesn't support it.
*/
entry->edx |= F(ARCH_CAPABILITIES);
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,8 +831,8 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid, ...@@ -836,8 +831,8 @@ 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)
goto out_free; goto out_free;
...@@ -847,8 +842,8 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid, ...@@ -847,8 +842,8 @@ 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)
goto out_free; goto out_free;
......
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