[v7,07/17] target-i386: Add x86_set_hyperv.

Message ID 1350071782-23078-8-git-send-email-Don@CloudSwitch.com
State New
Headers show

Commit Message

Don Slutz Oct. 12, 2012, 7:56 p.m.
Part of "target-i386: Add way to expose VMWare CPUID"

At this stage it is used to set the cpu object's hypervisor level to
the default for Microsoft's Hypervisor.

Also known as Paravirtualization level or maximim cpuid function
present in this leaf.  This is the EAX value for 0x40000000.

This is based on:

Microsoft Hypervisor CPUID Leaves:

which says:
"Leaf 0x40000000" (at very top of table):


The maximum input value for hypervisor CPUID information. For Microsoft
hypervisors, this value will be at least 0x40000005. The vendor ID
signature should be used only for reporting and diagnostic purposes."

QEMU already uses HYPERV_CPUID_MIN in accel=kvm mode.  However this
HYPERV_CPUID_MIN is not used and a copy
(CPUID_HV_LEVEL_HYPERV_CPUID_MIN) is added so that the resulting
CPUID bits exposed to the guest should be a function of the
machine-type and command-line/config parameters, and nothing else
(otherwise the CPUID bits would change under the guest's feet when

Signed-off-by: Don Slutz <Don@CloudSwitch.com>
 target-i386/cpu.c |    9 +++++++++
 target-i386/cpu.h |    4 ++++
 2 files changed, 13 insertions(+), 0 deletions(-)


diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index b335a1e..283ac01 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1253,6 +1253,12 @@  static void x86_cpuid_set_hv_features(Object *obj, Visitor *v, void *opaque,
 #if !defined(CONFIG_USER_ONLY)
+static void x86_set_hyperv(Object *obj, Error **errp)
+    object_property_set_int(obj, CPUID_HV_LEVEL_HYPERV_CPUID_MIN,
+                            "hypervisor-level", errp);
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
                                  const char *name, Error **errp)
@@ -1275,6 +1281,7 @@  static void x86_set_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
+    x86_set_hyperv(obj, errp);
 static void x86_get_hv_relaxed(Object *obj, Visitor *v, void *opaque,
@@ -1295,6 +1302,7 @@  static void x86_set_hv_relaxed(Object *obj, Visitor *v, void *opaque,
+    x86_set_hyperv(obj, errp);
 static void x86_get_hv_vapic(Object *obj, Visitor *v, void *opaque,
@@ -1315,6 +1323,7 @@  static void x86_set_hv_vapic(Object *obj, Visitor *v, void *opaque,
+    x86_set_hyperv(obj, errp);
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index fbc8f66..cd4e83c 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -488,6 +488,10 @@ 
 #define CPUID_VENDOR_VIA   "CentaurHauls"
+/* The maximum input value for hypervisor CPUID information for
+ * Microsoft hypervisors.  Is related to HYPERV_CPUID_MIN. */
+#define CPUID_HV_LEVEL_HYPERV_CPUID_MIN  0x40000005
 #define CPUID_MWAIT_IBE     (1 << 1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX     (1 << 0) /* enumeration supported */