Skip to content
Snippets Groups Projects
Commit ad2a90fb authored by Paolo Bonzini's avatar Paolo Bonzini Committed by Yang Yingliang
Browse files

KVM: cpuid: set struct kvm_cpuid_entry2 flags in do_cpuid_1_ent

mainline inclusion
from mainline-v5.3-rc1
commit d9aadaf6
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I3YAEG


CVE: NA

-----------------------------

do_cpuid_1_ent is typically called in two places by __do_cpuid_func
for CPUID functions that have subleafs.  Both places have to set
the KVM_CPUID_FLAG_SIGNIFCANT_INDEX.  Set that flag, and
KVM_CPUID_FLAG_STATEFUL_FUNC as well, directly in do_cpuid_1_ent.

Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: default avatarJingyi Wang <wangjingyi11@huawei.com>
Reviewed-by: default avatarKeqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
parent 18f2e790
No related branches found
No related tags found
No related merge requests found
...@@ -291,6 +291,18 @@ static void do_cpuid_1_ent(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -291,6 +291,18 @@ static void do_cpuid_1_ent(struct kvm_cpuid_entry2 *entry, u32 function,
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);
switch (function) {
case 2:
entry->flags |= KVM_CPUID_FLAG_STATEFUL_FUNC;
break;
case 4:
case 7:
case 0xb:
case 0xd:
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
break;
}
} }
static int __do_cpuid_func_emulated(struct kvm_cpuid_entry2 *entry, static int __do_cpuid_func_emulated(struct kvm_cpuid_entry2 *entry,
...@@ -493,14 +505,12 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -493,14 +505,12 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
case 2: { case 2: {
int t, times = entry->eax & 0xff; int t, times = entry->eax & 0xff;
entry->flags |= KVM_CPUID_FLAG_STATEFUL_FUNC;
entry->flags |= KVM_CPUID_FLAG_STATE_READ_NEXT; entry->flags |= KVM_CPUID_FLAG_STATE_READ_NEXT;
for (t = 1; t < times; ++t) { for (t = 1; t < times; ++t) {
if (*nent >= maxnent) if (*nent >= maxnent)
goto out; goto out;
do_cpuid_1_ent(&entry[t], function, 0); do_cpuid_1_ent(&entry[t], function, 0);
entry[t].flags |= KVM_CPUID_FLAG_STATEFUL_FUNC;
++*nent; ++*nent;
} }
break; break;
...@@ -509,7 +519,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -509,7 +519,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
case 4: { case 4: {
int i, cache_type; int i, cache_type;
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
/* read more entries until cache_type is zero */ /* read more entries until cache_type is zero */
for (i = 1; ; ++i) { for (i = 1; ; ++i) {
if (*nent >= maxnent) if (*nent >= maxnent)
...@@ -519,8 +528,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -519,8 +528,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
if (!cache_type) if (!cache_type)
break; break;
do_cpuid_1_ent(&entry[i], function, i); do_cpuid_1_ent(&entry[i], function, i);
entry[i].flags |=
KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
++*nent; ++*nent;
} }
break; break;
...@@ -535,7 +542,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -535,7 +542,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
case 7: { case 7: {
int i; int i;
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
for (i = 0; ; ) { for (i = 0; ; ) {
do_cpuid_7_mask(&entry[i], i); do_cpuid_7_mask(&entry[i], i);
if (i == entry->eax) if (i == entry->eax)
...@@ -545,8 +551,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -545,8 +551,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
++i; ++i;
do_cpuid_1_ent(&entry[i], function, i); do_cpuid_1_ent(&entry[i], function, i);
entry[i].flags |=
KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
++*nent; ++*nent;
} }
break; break;
...@@ -586,7 +590,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -586,7 +590,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
case 0xb: { case 0xb: {
int i, level_type; int i, level_type;
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
/* read more entries until level_type is zero */ /* read more entries until level_type is zero */
for (i = 1; ; ++i) { for (i = 1; ; ++i) {
if (*nent >= maxnent) if (*nent >= maxnent)
...@@ -596,8 +599,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -596,8 +599,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
if (!level_type) if (!level_type)
break; break;
do_cpuid_1_ent(&entry[i], function, i); do_cpuid_1_ent(&entry[i], function, i);
entry[i].flags |=
KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
++*nent; ++*nent;
} }
break; break;
...@@ -610,7 +611,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -610,7 +611,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
entry->ebx = xstate_required_size(supported, false); entry->ebx = xstate_required_size(supported, false);
entry->ecx = entry->ebx; entry->ecx = entry->ebx;
entry->edx &= supported >> 32; entry->edx &= supported >> 32;
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
if (!supported) if (!supported)
break; break;
...@@ -636,8 +636,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function, ...@@ -636,8 +636,6 @@ static inline int __do_cpuid_func(struct kvm_cpuid_entry2 *entry, u32 function,
} }
entry[i].ecx = 0; entry[i].ecx = 0;
entry[i].edx = 0; entry[i].edx = 0;
entry[i].flags |=
KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
++*nent; ++*nent;
++i; ++i;
} }
......
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