* [Qemu-devel] [PATCH] expose paravirt feature list to cpuid
@ 2009-01-28 12:22 Glauber Costa
2009-01-28 13:50 ` Paul Brook
0 siblings, 1 reply; 2+ messages in thread
From: Glauber Costa @ 2009-01-28 12:22 UTC (permalink / raw)
To: qemu-devel; +Cc: aliguori
Expose the paravirt features provided by the host to the guest.
The features exposed uses qemu just as a medium, since they only
depend on a negotiation between the host and guest directly.
As a direct result, we're now able to run the kvm pvclock in qemu
based kvm guests.
Signed-off-by: Glauber Costa <glommer@redhat.com>
---
kvm.h | 1 +
target-i386/kvm.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/kvm.h b/kvm.h
index efce145..db58baa 100644
--- a/kvm.h
+++ b/kvm.h
@@ -17,6 +17,7 @@
#include "config.h"
#ifdef CONFIG_KVM
+#include <linux/kvm_para.h>
extern int kvm_allowed;
#define kvm_enabled() (kvm_allowed)
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 2412ae4..3c62df5 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -33,6 +33,35 @@
do { } while (0)
#endif
+struct kvm_para_features {
+ int cap;
+ int feature;
+} para_features[] = {
+#ifdef KVM_CAP_CLOCKSOURCE
+ { KVM_CAP_CLOCKSOURCE, KVM_FEATURE_CLOCKSOURCE },
+#endif
+#ifdef KVM_CAP_NOP_IO_DELAY
+ { KVM_CAP_NOP_IO_DELAY, KVM_FEATURE_NOP_IO_DELAY },
+#endif
+#ifdef KVM_CAP_PV_MMU
+ { KVM_CAP_PV_MMU, KVM_FEATURE_MMU_OP },
+#endif
+#ifdef KVM_CAP_CR3_CACHE
+ { KVM_CAP_CR3_CACHE, KVM_FEATURE_CR3_CACHE },
+#endif
+};
+
+static int get_para_features(CPUState *env)
+{
+ int i, features = 0;
+
+ for (i = 0; i < ARRAY_SIZE(para_features); i++) {
+ if (kvm_ioctl(env->kvm_state, KVM_CHECK_EXTENSION, para_features[i].cap))
+ features |= (1 << para_features[i].feature);
+ }
+
+ return features;
+}
int kvm_arch_init_vcpu(CPUState *env)
{
struct {
@@ -41,8 +70,29 @@ int kvm_arch_init_vcpu(CPUState *env)
} __attribute__((packed)) cpuid_data;
uint32_t limit, i, cpuid_i;
uint32_t eax, ebx, ecx, edx;
+#ifdef KVM_CPUID_SIGNATURE
+ struct kvm_cpuid_entry *pv_ent;
+ uint32_t signature[3];
+#endif
cpuid_i = 0;
+#ifdef KVM_CPUID_SIGNATURE
+ /* Paravirtualization CPUIDs */
+ memcpy(signature, "KVMKVMKVM\0\0\0", 12);
+ pv_ent = &cpuid_data.entries[cpuid_i++];
+ memset(pv_ent, 0, sizeof(*pv_ent));
+ pv_ent->function = KVM_CPUID_SIGNATURE;
+ pv_ent->eax = 0;
+ pv_ent->ebx = signature[0];
+ pv_ent->ecx = signature[1];
+ pv_ent->edx = signature[2];
+
+ pv_ent = &cpuid_data.entries[cpuid_i++];
+ memset(pv_ent, 0, sizeof(*pv_ent));
+ pv_ent->function = KVM_CPUID_FEATURES;
+ pv_ent->eax = get_para_features(env);
+#endif
+
cpu_x86_cpuid(env, 0, &eax, &ebx, &ecx, &edx);
limit = eax;
--
1.5.6.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] expose paravirt feature list to cpuid
2009-01-28 12:22 [Qemu-devel] [PATCH] expose paravirt feature list to cpuid Glauber Costa
@ 2009-01-28 13:50 ` Paul Brook
0 siblings, 0 replies; 2+ messages in thread
From: Paul Brook @ 2009-01-28 13:50 UTC (permalink / raw)
To: qemu-devel; +Cc: Glauber Costa, aliguori
> +#ifdef KVM_CPUID_SIGNATURE
> + /* Paravirtualization CPUIDs */
> + memcpy(signature, "KVMKVMKVM\0\0\0", 12);
> + pv_ent->ebx = signature[0];
> + pv_ent->ecx = signature[1];
> + pv_ent->edx = signature[2];
This is broken on big-endian hosts.
I realise this code is currently only enabled for x86 hosts, however there's a
good chance we'll want to implement something similar for normal qemu. At
minimum it needs a comment saying that it's potentially broken.
Paul
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-01-28 13:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-28 12:22 [Qemu-devel] [PATCH] expose paravirt feature list to cpuid Glauber Costa
2009-01-28 13:50 ` Paul Brook
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).