* [PATCH] KVM: userspace: Fetch sub-leaf cpuid values for functions 4, 0xb, 0xd.
@ 2009-01-12 11:59 Amit Shah
0 siblings, 0 replies; 2+ messages in thread
From: Amit Shah @ 2009-01-12 11:59 UTC (permalink / raw)
To: avi; +Cc: kvm, Amit Shah
CPUID functions 4, 0xb and 0xd have sub-leaf values which depend on the
input value of ECX. Fetch these cpuid values and pass them on to the kernel.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
qemu/qemu-kvm-x86.c | 24 +++++++++++++++++++-----
1 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/qemu/qemu-kvm-x86.c b/qemu/qemu-kvm-x86.c
index 4fad2af..fbcd2bd 100644
--- a/qemu/qemu-kvm-x86.c
+++ b/qemu/qemu-kvm-x86.c
@@ -463,9 +463,10 @@ void kvm_arch_save_regs(CPUState *env)
}
static void do_cpuid_ent(struct kvm_cpuid_entry *e, uint32_t function,
- CPUState *env)
+ uint32_t count, CPUState *env)
{
env->regs[R_EAX] = function;
+ env->regs[R_ECX] = count;
qemu_kvm_cpuid_on_env(env);
e->function = function;
e->eax = env->regs[R_EAX];
@@ -514,7 +515,7 @@ int kvm_arch_qemu_init_env(CPUState *cenv)
#endif
int cpuid_nent = 0;
CPUState copy;
- uint32_t i, limit;
+ uint32_t i, j, limit;
copy = *cenv;
@@ -539,15 +540,28 @@ int kvm_arch_qemu_init_env(CPUState *cenv)
qemu_kvm_cpuid_on_env(©);
limit = copy.regs[R_EAX];
- for (i = 0; i <= limit; ++i)
- do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, ©);
+ for (i = 0; i <= limit; ++i) {
+ if (i == 4 || i == 0xb || i == 0xd) {
+ for (j = 0; ; ++j) {
+ do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, j, ©);
+
+ if (i == 4 && copy.regs[R_EAX] == 0)
+ break;
+ if (i == 0xb && !(copy.regs[R_ECX] & 0xff00))
+ break;
+ if (i == 0xd && copy.regs[R_EAX] == 0)
+ break;
+ }
+ } else
+ do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, 0, ©);
+ }
copy.regs[R_EAX] = 0x80000000;
qemu_kvm_cpuid_on_env(©);
limit = copy.regs[R_EAX];
for (i = 0x80000000; i <= limit; ++i)
- do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, ©);
+ do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, 0, ©);
kvm_setup_cpuid(kvm_context, cenv->cpu_index, cpuid_nent, cpuid_ent);
return 0;
--
1.6.0.6
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH] kvm: userspace: Fetch sub-leaf cpuid values for functions 4, 0xb, 0xd.
2009-01-14 16:51 ` [PATCH] kvm: libkvm: Add a wrapper for an ioctl for the KVM_SET_CPUID2 interface Amit Shah
@ 2009-01-14 16:51 ` Amit Shah
0 siblings, 0 replies; 2+ messages in thread
From: Amit Shah @ 2009-01-14 16:51 UTC (permalink / raw)
To: avi; +Cc: kvm, Amit Shah
CPUID functions 4, 0xb and 0xd have sub-leaf values which depend on the
input value of ECX. Fetch these cpuid values and pass them on to the kernel.
We also switch to the kvm_set_cpuid2() ioctl for this; kvm_set_cpuid() can't
handle the extra parameters we need to support sub-leaves.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
qemu/qemu-kvm-x86.c | 37 ++++++++++++++++++++++++++++---------
1 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/qemu/qemu-kvm-x86.c b/qemu/qemu-kvm-x86.c
index 4fad2af..52ddd33 100644
--- a/qemu/qemu-kvm-x86.c
+++ b/qemu/qemu-kvm-x86.c
@@ -462,10 +462,11 @@ void kvm_arch_save_regs(CPUState *env)
}
}
-static void do_cpuid_ent(struct kvm_cpuid_entry *e, uint32_t function,
- CPUState *env)
+static void do_cpuid_ent(struct kvm_cpuid_entry2 *e, uint32_t function,
+ uint32_t count, CPUState *env)
{
env->regs[R_EAX] = function;
+ env->regs[R_ECX] = count;
qemu_kvm_cpuid_on_env(env);
e->function = function;
e->eax = env->regs[R_EAX];
@@ -507,14 +508,14 @@ static int get_para_features(kvm_context_t kvm_context)
int kvm_arch_qemu_init_env(CPUState *cenv)
{
- struct kvm_cpuid_entry cpuid_ent[100];
+ struct kvm_cpuid_entry2 cpuid_ent[100];
#ifdef KVM_CPUID_SIGNATURE
- struct kvm_cpuid_entry *pv_ent;
+ struct kvm_cpuid_entry2 *pv_ent;
uint32_t signature[3];
#endif
int cpuid_nent = 0;
CPUState copy;
- uint32_t i, limit;
+ uint32_t i, j, limit;
copy = *cenv;
@@ -539,17 +540,35 @@ int kvm_arch_qemu_init_env(CPUState *cenv)
qemu_kvm_cpuid_on_env(©);
limit = copy.regs[R_EAX];
- for (i = 0; i <= limit; ++i)
- do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, ©);
+ for (i = 0; i <= limit; ++i) {
+ if (i == 4 || i == 0xb || i == 0xd) {
+ for (j = 0; ; ++j) {
+ do_cpuid_ent(&cpuid_ent[cpuid_nent], i, j, ©);
+
+ cpuid_ent[cpuid_nent].flags = KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
+ cpuid_ent[cpuid_nent].index = j;
+
+ cpuid_nent++;
+
+ if (i == 4 && copy.regs[R_EAX] == 0)
+ break;
+ if (i == 0xb && !(copy.regs[R_ECX] & 0xff00))
+ break;
+ if (i == 0xd && copy.regs[R_EAX] == 0)
+ break;
+ }
+ } else
+ do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, 0, ©);
+ }
copy.regs[R_EAX] = 0x80000000;
qemu_kvm_cpuid_on_env(©);
limit = copy.regs[R_EAX];
for (i = 0x80000000; i <= limit; ++i)
- do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, ©);
+ do_cpuid_ent(&cpuid_ent[cpuid_nent++], i, 0, ©);
- kvm_setup_cpuid(kvm_context, cenv->cpu_index, cpuid_nent, cpuid_ent);
+ kvm_setup_cpuid2(kvm_context, cenv->cpu_index, cpuid_nent, cpuid_ent);
return 0;
}
--
1.6.0.6
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-01-14 16:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-12 11:59 [PATCH] KVM: userspace: Fetch sub-leaf cpuid values for functions 4, 0xb, 0xd Amit Shah
2009-01-14 16:51 Support for cpuid functions with subleaves Amit Shah
2009-01-14 16:51 ` [PATCH] kvm: libkvm: Add a wrapper for an ioctl for the KVM_SET_CPUID2 interface Amit Shah
2009-01-14 16:51 ` [PATCH] kvm: userspace: Fetch sub-leaf cpuid values for functions 4, 0xb, 0xd Amit Shah
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).