[PATCH v7 0/1] target-i386: Add missing kvm bits.

2012-10-12 Thread Don Slutz
This was part of [PATCH v6 00/16] Allow changing of Hypervisor CPUIDs.

Since it is no longer in use by any of the patches in v7, I have split it off.

Don Slutz (1):
  target-i386: Add missing kvm bits.

 target-i386/cpu.c |   12 
 1 files changed, 8 insertions(+), 4 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 1/1] target-i386: Add missing kvm bits.

2012-10-12 Thread Don Slutz
Currently -cpu host,-kvmclock,-kvm_nopiodelay,-kvm_mmu does not
turn off all bits in CPUID 0x4001 EAX.

The missing ones are KVM_FEATURE_STEAL_TIME and
KVM_FEATURE_CLOCKSOURCE_STABLE_BIT.

This adds the names kvm_steal_time and kvm_clock_stable for these
bits.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   12 
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index f3708e6..e9c760d 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -87,10 +87,14 @@ static const char *ext3_feature_name[] = {
 };
 
 static const char *kvm_feature_name[] = {
-kvmclock, kvm_nopiodelay, kvm_mmu, kvmclock, kvm_asyncpf, NULL, 
kvm_pv_eoi, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+kvmclock, kvm_nopiodelay, kvm_mmu, kvmclock,
+kvm_asyncpf, kvm_steal_time, kvm_pv_eoi, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+kvm_clock_stable, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
 };
 
 static const char *svm_feature_name[] = {
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 0/1] target-i386: Add missing kvm bits.

2012-10-12 Thread Don Slutz
This was part of [PATCH v6 00/16] Allow changing of Hypervisor CPUIDs.

Since it is no longer in use by any of the patches in v7, I have split it off.

Don Slutz (1):
  target-i386: Add missing kvm bits.

 target-i386/cpu.c |   12 
 1 files changed, 8 insertions(+), 4 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 00/17] target-i386: Add way to expose VMWare CPUID

2012-10-12 Thread Don Slutz
Also known as Paravirtualization CPUIDs.

This is primarily done so that the guest will think it is running
under vmware when hypervisor-vendor=vmware is specified as a
property of a cpu.

Patches 1 to 3 define new cpu properties.
Patches 4 to 6 Add QOM access to the new properties.
Patches 7 to 9 Add setting of these when cpu features hv_spinlocks,
  hv_relaxed, or hv_vapic are specified.
Patches 10 to 12 Change kvm to use these.
Patch 13 Add VMware timing info to kvm.
Patch 14 Makes it easier to use hypervisor-vendor=vmware.
Patches 15 to 17 Change tcg to use the new properties.

This depends on:

http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg01400.html

As far as I know it is #4. It depends on (1) and (2) and (3).

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Changes from v6 to v7:
  Subject changed from Allow changing of Hypervisor CPUIDs. to target-i386: 
Add way to expose VMWare CPUID
  Split out 01/16 target-i386: Add missing kvm bits.
It is no longer related to this patch set.  Will be top posted as a 
seperate patch.
Marcelo Tosatti:
  Better commit messages.
  Reorder patches.


Changes from v5 to v6:
  Split out 01/17: target-i386: Allow tsc-frequency to be larger then 2.147G
It has been accepted as a trivial patch:
http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg03959.html
Blue Swirl:
  Fix 2 checkpatch.pl WARNING: line over 80 characters.

Changes from v4 to v5:
  Undo kvm_clock2 change.
  Add cpuid_hv_level_set; cpuid_hv_level == 0 is now valid.
  Add cpuid_hv_vendor_set; the null string is now valid.
  Handle kvm and cpuid_hv_level == 0.
  hypervisor-vendor=kvm,hypervisor-level=0 and 
hypervisor-level=0,hypervisor-vendor=kvm
now do the same thing.

Changes from v3 to v4:
  Added CPUID_HV_LEVEL_HYPERV, CPUID_HV_LEVEL_KVM.
  Added CPUID_HV_VENDOR_HYPERV.
  Added hyperv as known hypservisor-vendor.
  Allow hypervisor-level to be 0.

Changes from v2 to v3:
  Clean post to qemu-devel.

Changes from v1 to v2:

1) Added 1/4 from 
http://lists.gnu.org/archive/html/qemu-devel/2012-08/msg05153.html

   Because Fred is changing jobs and so will not be pushing to get
   this in. It needed to be rebased, And I needed it to complete the
   testing of this change.

2) Added 2/4 because of the re-work I needed a way to clear all KVM bits,

3) The rework of v1.  Make it fit into the object model re-work of cpu.c for 
x86.

4) Added 3/4 -- The split out of the code that is not needed for accel=kvm.

Changes from v2 to v3:

Marcelo Tosatti:
  Its one big patch, better split in logically correlated patches
  (with better changelog). This would help reviewers.

So split 3 and 4 into 3 to 17.  More info in change log.
No code change.

Don Slutz (17):
  target-i386: Add Hypervisor level.
  target-i386: Add Hypervisor vendor.
  target-i386: Add Hypervisor features.
  target-i386: Add cpu object access routines for Hypervisor level.
  target-i386: Add cpu object access routines for Hypervisor vendor.
  target-i386: Add cpu object access routines for Hypervisor features.
  target-i386: Add x86_set_hyperv.
  target-i386: Use x86_set_hyperv to set hypervisor vendor.
  target-i386: Use x86_set_hyperv to set hypervisor features.
  target-i386: Use Hypervisor level in -machine pc,accel=kvm.
  target-i386: Use Hypervisor vendor in -machine pc,accel=kvm.
  target-i386: Use Hypervisor features in -machine pc,accel=kvm.
  target-i386: Add VMWare CPUID Timing information in -machine
pc,accel=kvm.
  target-i386: Add vmare as a known name to Hypervisor vendor.
  target-i386: Use Hypervisor level in -machine pc,accel=tcg.
  target-i386: Use Hypervisor vendor in -machine pc,accel=tcg.
  target-i386: target-i386: Add VMWare CPUID Timing information in
-machine pc,accel=tcg

 target-i386/cpu.c |  205 +
 target-i386/cpu.h |   29 
 target-i386/kvm.c |   69 +++
 3 files changed, 290 insertions(+), 13 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 01/17] target-i386: Add Hypervisor level.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

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

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 5265c5a..1899f69 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -777,11 +777,14 @@ typedef struct CPUX86State {
 uint32_t cpuid_ext3_features;
 uint32_t cpuid_apic_id;
 bool cpuid_vendor_override;
+bool cpuid_hv_level_set;
 /* Store the results of Centaur's CPUID instructions */
 uint32_t cpuid_xlevel2;
 uint32_t cpuid_ext4_features;
 /* Flags from CPUID[EAX=7,ECX=0].EBX */
 uint32_t cpuid_7_0_ebx;
+/* Hypervisor CPUIDs */
+uint32_t cpuid_hv_level;
 
 /* MTRRs */
 uint64_t mtrr_fixed[11];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 02/17] target-i386: Add Hypervisor vendor.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

Also known as Paravirtualization vendor.
This is EBX, ECX, and EDX data for 0x4000.

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 1899f69..e76ddc0 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -778,6 +778,7 @@ typedef struct CPUX86State {
 uint32_t cpuid_apic_id;
 bool cpuid_vendor_override;
 bool cpuid_hv_level_set;
+bool cpuid_hv_vendor_set;
 /* Store the results of Centaur's CPUID instructions */
 uint32_t cpuid_xlevel2;
 uint32_t cpuid_ext4_features;
@@ -785,6 +786,9 @@ typedef struct CPUX86State {
 uint32_t cpuid_7_0_ebx;
 /* Hypervisor CPUIDs */
 uint32_t cpuid_hv_level;
+uint32_t cpuid_hv_vendor1;
+uint32_t cpuid_hv_vendor2;
+uint32_t cpuid_hv_vendor3;
 
 /* MTRRs */
 uint64_t mtrr_fixed[11];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 03/17] target-i386: Add Hypervisor features.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

Also known as kvm festures or Hypervisor vendor-neutral interface 
identification.
This is the EAX value for 0x4001.

QEMU knows this is KVM_CPUID_FEATURES (0x4001) in some builds.

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index e76ddc0..fbc8f66 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -779,6 +779,7 @@ typedef struct CPUX86State {
 bool cpuid_vendor_override;
 bool cpuid_hv_level_set;
 bool cpuid_hv_vendor_set;
+bool cpuid_hv_features_set;
 /* Store the results of Centaur's CPUID instructions */
 uint32_t cpuid_xlevel2;
 uint32_t cpuid_ext4_features;
@@ -789,6 +790,8 @@ typedef struct CPUX86State {
 uint32_t cpuid_hv_vendor1;
 uint32_t cpuid_hv_vendor2;
 uint32_t cpuid_hv_vendor3;
+/* Hypervisor features */
+uint32_t cpuid_hv_features;
 
 /* MTRRs */
 uint64_t mtrr_fixed[11];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 04/17] target-i386: Add cpu object access routines for Hypervisor level.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

These are modeled after x86_cpuid_get_xlevel and x86_cpuid_set_xlevel.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   29 +
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index b8f431a..c4bd6cf 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1162,6 +1162,32 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor 
*v, void *opaque,
 cpu-env.tsc_khz = value / 1000;
 }
 
+static void x86_cpuid_get_hv_level(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_level, name, errp);
+}
+
+static void x86_cpuid_set_hv_level(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+uint32_t value;
+
+visit_type_uint32(v, value, name, errp);
+if (error_is_set(errp)) {
+return;
+}
+
+if (value != 0  value  0x4000) {
+value += 0x4000;
+}
+cpu-env.cpuid_hv_level = value;
+cpu-env.cpuid_hv_level_set = true;
+}
+
 #if !defined(CONFIG_USER_ONLY)
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
  const char *name, Error **errp)
@@ -2053,6 +2079,9 @@ static void x86_cpu_initfn(Object *obj)
 object_property_add(obj, enforce, bool,
 x86_cpuid_get_enforce,
 x86_cpuid_set_enforce, NULL, NULL, NULL);
+object_property_add(obj, hypervisor-level, int,
+x86_cpuid_get_hv_level,
+x86_cpuid_set_hv_level, NULL, NULL, NULL);
 #if !defined(CONFIG_USER_ONLY)
 object_property_add(obj, hv_spinlocks, int,
 x86_get_hv_spinlocks,
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 05/17] target-i386: Add cpu object access routines for Hypervisor vendor.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

These are modeled after x86_cpuid_set_vendor and x86_cpuid_get_vendor.

Since kvm's vendor is shorter, the test for correct size is removed and zero 
padding is added.

See http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html for 
definition of kvm's vendor.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   44 
 1 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index c4bd6cf..a87527c 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1188,6 +1188,47 @@ static void x86_cpuid_set_hv_level(Object *obj, Visitor 
*v, void *opaque,
 cpu-env.cpuid_hv_level_set = true;
 }
 
+static char *x86_cpuid_get_hv_vendor(Object *obj, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+CPUX86State *env = cpu-env;
+char *value;
+int i;
+
+value = (char *)g_malloc(CPUID_VENDOR_SZ + 1);
+for (i = 0; i  4; i++) {
+value[i + 0] = env-cpuid_hv_vendor1  (8 * i);
+value[i + 4] = env-cpuid_hv_vendor2  (8 * i);
+value[i + 8] = env-cpuid_hv_vendor3  (8 * i);
+}
+value[CPUID_VENDOR_SZ] = '\0';
+
+return value;
+}
+
+static void x86_cpuid_set_hv_vendor(Object *obj, const char *value,
+Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+CPUX86State *env = cpu-env;
+int i;
+char adj_value[CPUID_VENDOR_SZ + 1];
+
+memset(adj_value, 0, sizeof(adj_value));
+
+pstrcpy(adj_value, sizeof(adj_value), value);
+
+env-cpuid_hv_vendor1 = 0;
+env-cpuid_hv_vendor2 = 0;
+env-cpuid_hv_vendor3 = 0;
+for (i = 0; i  4; i++) {
+env-cpuid_hv_vendor1 |= ((uint8_t)adj_value[i + 0])  (8 * i);
+env-cpuid_hv_vendor2 |= ((uint8_t)adj_value[i + 4])  (8 * i);
+env-cpuid_hv_vendor3 |= ((uint8_t)adj_value[i + 8])  (8 * i);
+}
+env-cpuid_hv_vendor_set = true;
+}
+
 #if !defined(CONFIG_USER_ONLY)
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
  const char *name, Error **errp)
@@ -2082,6 +2123,9 @@ static void x86_cpu_initfn(Object *obj)
 object_property_add(obj, hypervisor-level, int,
 x86_cpuid_get_hv_level,
 x86_cpuid_set_hv_level, NULL, NULL, NULL);
+object_property_add_str(obj, hypervisor-vendor,
+x86_cpuid_get_hv_vendor,
+x86_cpuid_set_hv_vendor, NULL);
 #if !defined(CONFIG_USER_ONLY)
 object_property_add(obj, hv_spinlocks, int,
 x86_get_hv_spinlocks,
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 06/17] target-i386: Add cpu object access routines for Hypervisor features.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

Also known as kvm festures or Hypervisor vendor-neutral interface 
identification.
This is just the EAX value for 0x4001.

QEMU knows this is KVM_CPUID_FEATURES (0x4001) in some builds.

When exposing VMWare CPUID this needs to be set to zero.

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   26 ++
 1 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index a87527c..b335a1e 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1229,6 +1229,29 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
 env-cpuid_hv_vendor_set = true;
 }
 
+static void x86_cpuid_get_hv_features(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_features, name, errp);
+}
+
+static void x86_cpuid_set_hv_features(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+uint32_t value;
+
+visit_type_uint32(v, value, name, errp);
+if (error_is_set(errp)) {
+return;
+}
+
+cpu-env.cpuid_hv_features = value;
+cpu-env.cpuid_hv_features_set = true;
+}
+
 #if !defined(CONFIG_USER_ONLY)
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
  const char *name, Error **errp)
@@ -2126,6 +2149,9 @@ static void x86_cpu_initfn(Object *obj)
 object_property_add_str(obj, hypervisor-vendor,
 x86_cpuid_get_hv_vendor,
 x86_cpuid_set_hv_vendor, NULL);
+object_property_add(obj, hypervisor-features, int,
+x86_cpuid_get_hv_features,
+x86_cpuid_set_hv_features, NULL, NULL, NULL);
 #if !defined(CONFIG_USER_ONLY)
 object_property_add(obj, hv_spinlocks, int,
 x86_get_hv_spinlocks,
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2012-10-12 Thread Don Slutz
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 0x4000.

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

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

EAX

The maximum input value for hypervisor CPUID information. For Microsoft
hypervisors, this value will be at least 0x4005. 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
live-migrating).

Signed-off-by: Don Slutz d...@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,
 return;
 }
 hyperv_set_spinlock_retries(value);
+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,
 return;
 }
 hyperv_enable_relaxed_timing(value);
+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,
 return;
 }
 hyperv_enable_vapic_recommended(value);
+x86_set_hyperv(obj, errp);
 }
 #endif
 
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  0x4005
+
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX (1  0) /* enumeration supported */
 
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 08/17] target-i386: Use x86_set_hyperv to set hypervisor vendor.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

At this stage it is used to set the cpu object's hypervisor vendor
to the default for Microsoft's Hypervisor (Microsoft Hv).

Also known as Paravirtualization vendor.
This is EBX, ECX, EDX data for 0x4000.

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |2 ++
 target-i386/cpu.h |1 +
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 283ac01..958be81 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1257,6 +1257,8 @@ static void x86_set_hyperv(Object *obj, Error **errp)
 {
 object_property_set_int(obj, CPUID_HV_LEVEL_HYPERV_CPUID_MIN,
 hypervisor-level, errp);
+object_property_set_str(obj, CPUID_HV_VENDOR_HYPERV,
+hypervisor-vendor, errp);
 }
 
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index cd4e83c..f2045d6 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -491,6 +491,7 @@
 /* The maximum input value for hypervisor CPUID information for
  * Microsoft hypervisors.  Is related to HYPERV_CPUID_MIN. */
 #define CPUID_HV_LEVEL_HYPERV_CPUID_MIN  0x4005
+#define CPUID_HV_VENDOR_HYPERV Microsoft Hv
 
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX (1  0) /* enumeration supported */
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 09/17] target-i386: Use x86_set_hyperv to set hypervisor features.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

At this stage it is used to set the cpu object's hypervisor features
to the default for Microsoft's Hypervisor (Hv#1).

Also known as kvm festures or Hypervisor vendor-neutral interface 
identification.
This is the EAX value for 0x4001.

QEMU knows this is KVM_CPUID_FEATURES (0x4001) in some builds.

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |2 ++
 target-i386/cpu.h |1 +
 2 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 958be81..f058add 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1259,6 +1259,8 @@ static void x86_set_hyperv(Object *obj, Error **errp)
 hypervisor-level, errp);
 object_property_set_str(obj, CPUID_HV_VENDOR_HYPERV,
 hypervisor-vendor, errp);
+object_property_set_int(obj, CPUID_HV_FEATURES_HYPERV,
+hypervisor-features, errp);
 }
 
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index f2045d6..9a34c7b 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -492,6 +492,7 @@
  * Microsoft hypervisors.  Is related to HYPERV_CPUID_MIN. */
 #define CPUID_HV_LEVEL_HYPERV_CPUID_MIN  0x4005
 #define CPUID_HV_VENDOR_HYPERV Microsoft Hv
+#define CPUID_HV_FEATURES_HYPERV 0x31237648 /* Hv#1 */
 
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX (1  0) /* enumeration supported */
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 10/17] target-i386: Use Hypervisor level in -machine pc,accel=kvm.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

Also known as Paravirtualization level.

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/kvm.c |8 ++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 5b18383..30963e1 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -392,10 +392,14 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c-function = KVM_CPUID_SIGNATURE;
 if (!hyperv_enabled()) {
 memcpy(signature, KVMKVMKVM\0\0\0, 12);
-c-eax = 0;
+if (!env-cpuid_hv_level_set) {
+c-eax = 0;
+} else {
+c-eax = env-cpuid_hv_level;
+}
 } else {
 memcpy(signature, Microsoft Hv, 12);
-c-eax = HYPERV_CPUID_MIN;
+c-eax = env-cpuid_hv_level;
 }
 c-ebx = signature[0];
 c-ecx = signature[1];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 11/17] target-i386: Use Hypervisor vendor in -machine pc,accel=kvm.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

Also known as Paravirtualization vendor.
This is EBX, ECX, and EDX data for 0x4000.

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

If hypervisor vendor is set then add kvm's
signature at KVM_CPUID_SIGNATURE_NEXT (0x4100).

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/kvm.c |   26 ++
 1 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 30963e1..513356d 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -390,20 +390,21 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
 c-function = KVM_CPUID_SIGNATURE;
-if (!hyperv_enabled()) {
-memcpy(signature, KVMKVMKVM\0\0\0, 12);
-if (!env-cpuid_hv_level_set) {
-c-eax = 0;
-} else {
-c-eax = env-cpuid_hv_level;
-}
+if (!env-cpuid_hv_level_set) {
+c-eax = 0;
 } else {
-memcpy(signature, Microsoft Hv, 12);
 c-eax = env-cpuid_hv_level;
 }
-c-ebx = signature[0];
-c-ecx = signature[1];
-c-edx = signature[2];
+if (!env-cpuid_hv_vendor_set) {
+memcpy(signature, KVMKVMKVM\0\0\0, 12);
+c-ebx = signature[0];
+c-ecx = signature[1];
+c-edx = signature[2];
+} else {
+c-ebx = env-cpuid_hv_vendor1;
+c-ecx = env-cpuid_hv_vendor2;
+c-edx = env-cpuid_hv_vendor3;
+}
 
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
@@ -448,7 +449,8 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c-function = HYPERV_CPUID_IMPLEMENT_LIMITS;
 c-eax = 0x40;
 c-ebx = 0x40;
-
+}
+if (env-cpuid_hv_vendor_set) {
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
 c-function = KVM_CPUID_SIGNATURE_NEXT;
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 12/17] target-i386: Use Hypervisor features in -machine pc,accel=kvm.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

QEMU knows this as KVM_CPUID_FEATURES (0x4001) in some builds.

If hypervisor features are set, then pass adjusted
cpuid_kvm_features as EAX in 0x4101.

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/kvm.c |   27 +--
 1 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 513356d..b61027f 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -409,13 +409,14 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
 c-function = KVM_CPUID_FEATURES;
-c-eax = env-cpuid_kvm_features 
-kvm_arch_get_supported_cpuid(s, KVM_CPUID_FEATURES, 0, R_EAX);
+if (!env-cpuid_hv_features_set) {
+c-eax = env-cpuid_kvm_features 
+kvm_arch_get_supported_cpuid(s, KVM_CPUID_FEATURES, 0, R_EAX);
+} else {
+c-eax = env-cpuid_hv_features;
+}
 
 if (hyperv_enabled()) {
-memcpy(signature, Hv#1\0\0\0\0\0\0\0\0, 12);
-c-eax = signature[0];
-
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
 c-function = HYPERV_CPUID_VERSION;
@@ -455,10 +456,24 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 memset(c, 0, sizeof(*c));
 c-function = KVM_CPUID_SIGNATURE_NEXT;
 memcpy(signature, KVMKVMKVM\0\0\0, 12);
-c-eax = 0;
+if (env-cpuid_hv_features_set) {
+c-eax = KVM_CPUID_SIGNATURE_NEXT -
+KVM_CPUID_SIGNATURE + KVM_CPUID_FEATURES;
+} else {
+c-eax = 0;
+}
 c-ebx = signature[0];
 c-ecx = signature[1];
 c-edx = signature[2];
+
+if (env-cpuid_hv_features_set) {
+c = cpuid_data.entries[cpuid_i++];
+memset(c, 0, sizeof(*c));
+c-function = KVM_CPUID_SIGNATURE_NEXT -
+KVM_CPUID_SIGNATURE + KVM_CPUID_FEATURES;
+c-eax = env-cpuid_kvm_features 
+kvm_arch_get_supported_cpuid(s, KVM_CPUID_FEATURES, 0, R_EAX);
+}
 }
 
 has_msr_async_pf_en = c-eax  (1  KVM_FEATURE_ASYNC_PF);
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 13/17] target-i386: Add VMWare CPUID Timing information in -machine pc,accel=kvm.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

This is EAX and EBX data for 0x4010.

Add new #define CPUID_HV_TIMING_INFO for this.

The best documentation I have found is:
   http://article.gmane.org/gmane.comp.emulators.kvm.devel/22643

And a test under ESXi 4.0 shows that VMware is setting this data.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |4 
 target-i386/kvm.c |   22 ++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 9a34c7b..6ceef05 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -488,6 +488,10 @@
 
 #define CPUID_VENDOR_VIA   CentaurHauls
 
+/* VMware hardware version 7 defines timing information as
+ * 0x4010. */
+#define CPUID_HV_TIMING_INFO 0x4010
+
 /* The maximum input value for hypervisor CPUID information for
  * Microsoft hypervisors.  Is related to HYPERV_CPUID_MIN. */
 #define CPUID_HV_LEVEL_HYPERV_CPUID_MIN  0x4005
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index b61027f..81b0014 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -451,6 +451,28 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c-eax = 0x40;
 c-ebx = 0x40;
 }
+if (env-cpuid_hv_level = CPUID_HV_TIMING_INFO) {
+const uint32_t apic_khz = 100L;
+
+/*
+ * From article.gmane.org/gmane.comp.emulators.kvm.devel/22643
+ *
+ *Leaf 0x4010, Timing Information.
+ *
+ *VMware has defined the first generic leaf to provide timing
+ *information.  This leaf returns the current TSC frequency and
+ *current Bus frequency in kHz.
+ *
+ *# EAX: (Virtual) TSC frequency in kHz.
+ *# EBX: (Virtual) Bus (local apic timer) frequency in kHz.
+ *# ECX, EDX: RESERVED (Per above, reserved fields are set to 
zero).
+ */
+c = cpuid_data.entries[cpuid_i++];
+memset(c, 0, sizeof(*c));
+c-function = CPUID_HV_TIMING_INFO;
+c-eax = (uint32_t)env-tsc_khz;
+c-ebx = apic_khz;
+}
 if (env-cpuid_hv_vendor_set) {
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 14/17] target-i386: Add vmare as a known name to Hypervisor vendor.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

Also adds some other known names (kvm, hyperv) to Hypervisor vendor.

This allows hypervisor-vendor=vmware3 instead of
hypervisor-vendor=VMwareVMware,hypervisor-level=2,hypervisor-features=0.

And hypervisor-vendor=vmware instead of
hypervisor-vendor=VMwareVMware,hypervisor-level=0x10,hypervisor-features=0.

This is based on:

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   58 -
 target-i386/cpu.h |9 
 2 files changed, 66 insertions(+), 1 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index f058add..c8466ec 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1203,6 +1203,23 @@ static char *x86_cpuid_get_hv_vendor(Object *obj, Error 
**errp)
 }
 value[CPUID_VENDOR_SZ] = '\0';
 
+/* Convert known names */
+if (!strcmp(value, CPUID_HV_VENDOR_HYPERV) 
+env-cpuid_hv_level == CPUID_HV_LEVEL_HYPERV_CPUID_MIN 
+env-cpuid_hv_features_set == CPUID_HV_FEATURES_HYPERV) {
+pstrcpy(value, sizeof(value), hyperv);
+} else if (!strcmp(value, CPUID_HV_VENDOR_VMWARE) 
+env-cpuid_hv_features_set == CPUID_HV_FEATURES_VMWARE) {
+if (env-cpuid_hv_level == CPUID_HV_LEVEL_VMWARE_4) {
+pstrcpy(value, sizeof(value), vmware4);
+} else if (env-cpuid_hv_level == CPUID_HV_LEVEL_VMWARE_3) {
+pstrcpy(value, sizeof(value), vmware3);
+}
+} else if (!strcmp(value, CPUID_HV_VENDOR_KVM) 
+   (env-cpuid_hv_level == CPUID_HV_LEVEL_KVM_0 ||
+env-cpuid_hv_level == CPUID_HV_LEVEL_KVM_1)) {
+pstrcpy(value, sizeof(value), kvm);
+}
 return value;
 }
 
@@ -1216,7 +1233,46 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
 
 memset(adj_value, 0, sizeof(adj_value));
 
-pstrcpy(adj_value, sizeof(adj_value), value);
+/* Convert known names */
+if (!strcmp(value, hyperv)) {
+if (!env-cpuid_hv_level_set) {
+object_property_set_int(obj, CPUID_HV_LEVEL_HYPERV_CPUID_MIN,
+hypervisor-level, errp);
+}
+if (!env-cpuid_hv_features_set) {
+object_property_set_int(obj, CPUID_HV_FEATURES_HYPERV,
+hypervisor-features, errp);
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_HYPERV);
+} else if (!strcmp(value, vmware) || !strcmp(value, vmware4)) {
+if (!env-cpuid_hv_level_set) {
+object_property_set_int(obj, CPUID_HV_LEVEL_VMWARE_4,
+hypervisor-level, errp);
+}
+if (!env-cpuid_hv_features_set) {
+object_property_set_int(obj, CPUID_HV_FEATURES_VMWARE,
+hypervisor-features, errp);
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_VMWARE);
+} else if (!strcmp(value, vmware3)) {
+if (!env-cpuid_hv_level_set) {
+object_property_set_int(obj, CPUID_HV_LEVEL_VMWARE_3,
+hypervisor-level, errp);
+}
+if (!env-cpuid_hv_features_set) {
+object_property_set_int(obj, CPUID_HV_FEATURES_VMWARE,
+hypervisor-features, errp);
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_VMWARE);
+} else if (!strcmp(value, kvm)) {
+if (!env-cpuid_hv_level_set) {
+object_property_set_int(obj, CPUID_HV_LEVEL_KVM_1,
+hypervisor-level, errp);
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_KVM);
+} else {
+pstrcpy(adj_value, sizeof(adj_value), value);
+}
 
 env-cpuid_hv_vendor1 = 0;
 env-cpuid_hv_vendor2 = 0;
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 6ceef05..a387d82 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -498,6 +498,15 @@
 #define CPUID_HV_VENDOR_HYPERV Microsoft Hv
 #define CPUID_HV_FEATURES_HYPERV 0x31237648 /* Hv#1 */
 
+#define CPUID_HV_LEVEL_VMWARE_3 0x4002
+#define CPUID_HV_LEVEL_VMWARE_4 0x4010
+#define CPUID_HV_VENDOR_VMWARE VMwareVMware
+#define CPUID_HV_FEATURES_VMWARE 0
+
+#define CPUID_HV_LEVEL_KVM_0  0
+#define CPUID_HV_LEVEL_KVM_1  0x4001
+#define CPUID_HV_VENDOR_KVM KVMKVMKVM
+
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX (1  0) /* enumeration supported */
 
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 15/17] target-i386: Use Hypervisor level in -machine pc,accel=tcg.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

Also known as Paravirtualization level.

QEMU knows this as KVM_CPUID_SIGNATURE (0x4000) in kvm on linux.

This does not provide vendor support in tcg yet.

From http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
kvm has this issue:

Note also that old hosts set eax value to 0x0. This should
be interpreted as if the value was 0x4001.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   30 ++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index c8466ec..5b33b95 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1767,6 +1767,24 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 index =  env-cpuid_xlevel;
 }
 }
+} else if (index  0x4000) {
+/* test if maximum index reached
+ * but only if Hypervisor level is set */
+if (env-cpuid_hv_level_set) {
+uint32_t real_level = env-cpuid_hv_level;
+
+/* Handle Hypervisor CPUIDs.
+ * kvm defines 0 to be the same as 0x4001 */
+if (real_level  0x4000) {
+real_level = 0x4001;
+}
+if (index  real_level) {
+index = real_level;
+}
+} else {
+if (index  env-cpuid_level)
+index = env-cpuid_level;
+}
 } else {
 if (index  env-cpuid_level)
 index = env-cpuid_level;
@@ -1905,6 +1923,18 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 *edx = 0;
 }
 break;
+case 0x4000:
+*eax = env-cpuid_hv_level;
+*ebx = 0;
+*ecx = 0;
+*edx = 0;
+break;
+case 0x4001:
+*eax = env-cpuid_kvm_features;
+*ebx = 0;
+*ecx = 0;
+*edx = 0;
+break;
 case 0x8000:
 *eax = env-cpuid_xlevel;
 *ebx = env-cpuid_vendor1;
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 16/17] target-i386: Use Hypervisor vendor in -machine pc,accel=tcg.

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

Also known as Paravirtualization vendor.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
This is where the 0 is the same as 0x4001 is defined.

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   11 ++-
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 5b33b95..49e5db3 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1769,8 +1769,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 }
 } else if (index  0x4000) {
 /* test if maximum index reached
- * but only if Hypervisor level is set */
-if (env-cpuid_hv_level_set) {
+ * but only if Hypervisor level is set or
+ * if Hypervisor vendor is set */
+if (env-cpuid_hv_level_set || env-cpuid_hv_vendor_set) {
 uint32_t real_level = env-cpuid_hv_level;
 
 /* Handle Hypervisor CPUIDs.
@@ -1925,9 +1926,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 break;
 case 0x4000:
 *eax = env-cpuid_hv_level;
-*ebx = 0;
-*ecx = 0;
-*edx = 0;
+*ebx = env-cpuid_hv_vendor1;
+*ecx = env-cpuid_hv_vendor2;
+*edx = env-cpuid_hv_vendor3;
 break;
 case 0x4001:
 *eax = env-cpuid_kvm_features;
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v7 17/17] target-i386: target-i386: Add VMWare CPUID Timing information in -machine pc,accel=tcg

2012-10-12 Thread Don Slutz
Part of target-i386: Add way to expose VMWare CPUID

This is EAX and EBX data for 0x4010.

Add new #define CPUID_HV_TIMING_INFO for this.

The best documentation I have found is:
   http://article.gmane.org/gmane.comp.emulators.kvm.devel/22643

And a test under ESXi 4.0 shows that VMware is setting this data.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |6 ++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 49e5db3..924db0d 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1936,6 +1936,12 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 *ecx = 0;
 *edx = 0;
 break;
+case 0x4010:
+*eax = env-tsc_khz;
+*ebx = 100; /* apic_khz */
+*ecx = 0;
+*edx = 0;
+break;
 case 0x8000:
 *eax = env-cpuid_xlevel;
 *ebx = env-cpuid_vendor1;
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 03/16] target-i386: Add cpu object access routines for Hypervisor level.

2012-10-11 Thread Don Slutz

On 10/10/12 11:40, Andreas Färber wrote:

Am 10.10.2012 17:22, schrieb Don Slutz:

On 10/09/12 15:13, Don Slutz wrote:

On 10/09/12 12:25, Marcelo Tosatti wrote:

On Mon, Sep 24, 2012 at 10:32:05AM -0400, Don Slutz wrote:

+static void x86_cpuid_set_hv_level(Object *obj, Visitor *v, void
*opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+uint32_t value;
+
+visit_type_uint32(v, value, name, errp);
+if (error_is_set(errp)) {
+return;
+}
+
+if (value != 0  value  0x4000) {
+value += 0x4000;
+}

Whats the purpose of this? Adds ambiguity.

[...]

This is direct copy with adjustment from x86_cpuid_set_xlevel():

 if (value  0x8000) {
 value += 0x8000;
 }

(Pending patch:
http://comments.gmane.org/gmane.comp.emulators.qemu/172703 adds this)

(Any pending patch can be changed ;))


The adjustment is that 0 is a legal value. See
http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

This does mean that just like xlevel=1 and xlevel=0x8001 are the
same; hypervisor-level=1 and hypervisor-level=0x401 are the same.
If this is not wanted, I have no issue with removing it.

I have no strong opinion either way, but if there's only one call site,
I'd prefer to apply these fixups to user input before setting the
property and to have the property setter error out on invalid values. I
consider that cleaner than silently fixing up values inside the setter.

Regards,
Andreas

I find more then one call site.  And one of them is converting the 
predefined x86 cpus (like 486).  So I am not planning on a change.


I have finished up the v7 changes except for this.  I will wait until 
some time tomorrow to send it in case there is more on this topic.

-Don Slutz


--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 05/16] target-i386: Use Hypervisor level in -machine pc,accel=kvm.

2012-10-10 Thread Don Slutz

On 10/09/12 15:11, Marcelo Tosatti wrote:

On Tue, Oct 09, 2012 at 03:09:17PM -0400, Don Slutz wrote:

On 10/09/12 14:47, Marcelo Tosatti wrote:

On Tue, Oct 09, 2012 at 03:27:26PM -0300, Marcelo Tosatti wrote:

On Tue, Oct 09, 2012 at 02:18:05PM -0300, Marcelo Tosatti wrote:

On Mon, Sep 24, 2012 at 10:32:07AM -0400, Don Slutz wrote:

Also known as Paravirtualization level.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
   
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
   http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
   http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
   
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

Signed-off-by: Don Slutz d...@cloudswitch.com
---
  target-i386/kvm.c |4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 895d848..8462c75 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -389,12 +389,12 @@ int kvm_arch_init_vcpu(CPUX86State *env)
  c = cpuid_data.entries[cpuid_i++];
  memset(c, 0, sizeof(*c));
  c-function = KVM_CPUID_SIGNATURE
-if (!hyperv_enabled()) {
+if (!env-cpuid_hv_level_set) {
  memcpy(signature, KVMKVMKVM\0\0\0, 12);
  c-eax = 0;
  } else {
  memcpy(signature, Microsoft Hv, 12);
-c-eax = HYPERV_CPUID_MIN;
+c-eax = env-cpuid_hv_level;

This breaks hyperv_enabled() checks.

Don, are you certain it is worthwhile to make this configurable?
Can you explain why, under your scenario, it is worthwhile?

Because these are separate problems:

- Fake VMWare hypervisor  (which seems to be your main goal).
- Make CPUID HV leafs configurable via command line.

Err, meant via properties. Point is, why have VMWare CPUID
configuration as data, if there are reasons to believe code
is a better fit (code as in current Hyper-V implementation).

Nevermind, its the right thing to do. Just separate the patchset
please:

1) Create object properties.
2) Export VMWare CPUID via properties.
3) Convert Hyper-V.

Be careful to make sure Hyper-V's current options are functional
in 3).


Did you mean 3 patch sets (or more)? Or just a different order?
-Don Slutz

Different order. Patches should be logically related (think of what
information the reviewer needs). Please write changelogs for
every patch.


Using this order causes support for Hyper-V to stop working in the 
middle of the patch set.  How about this order:

1) Create object properties.
2) Convert Hyper-V to set the new properties.
3) Change kvm.c to use the new properties.
4) Export VMWare CPUID via properties.

5) Change accel=tcg to use the new properties.

   -Don Slutz

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 06/16] target-i386: Use Hypervisor level in -machine pc,accel=tcg.

2012-10-10 Thread Don Slutz

On 10/09/12 15:01, Marcelo Tosatti wrote:

On Mon, Sep 24, 2012 at 10:32:08AM -0400, Don Slutz wrote:

Also known as Paravirtualization level.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
   
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
   http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
   http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
   
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

QEMU knows this as KVM_CPUID_SIGNATURE (0x4000) in kvm on linux.

This does not provide vendor support in tcg yet.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
  target-i386/cpu.c |   27 +++
  1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 48bdaf9..920278b 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1651,6 +1651,21 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
  index =  env-cpuid_xlevel;
  }
  }
+} else if (index  0x4000) {
+if (env-cpuid_hv_level_set) {
+uint32_t real_level = env-cpuid_hv_level;
+
+/* Handle Hypervisor CPUIDs */
+if (real_level  0x4000) {
+real_level = 0x4000;
+}
+if (index  real_level) {
+index = real_level;
+}
+} else {
+if (index  env-cpuid_level)
+index = env-cpuid_level;
+}

Whats the purpose of this checks?
They control what happens for CPUID requests outside the defined 
ranges.  Very similar to code just above this.


Please provide changelogs for each patch.

In progress.

  } else {
  if (index  env-cpuid_level)
  index = env-cpuid_level;
@@ -1789,6 +1804,18 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
  *edx = 0;
  }
  break;
+case 0x4000:
+*eax = env-cpuid_hv_level;
+*ebx = 0;
+*ecx = 0;
+*edx = 0;
+break;
+case 0x4001:
+*eax = env-cpuid_kvm_features;
+*ebx = 0;
+*ecx = 0;
+*edx = 0;
+break;
  case 0x8000:
  *eax = env-cpuid_xlevel;
  *ebx = env-cpuid_vendor1;
--
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

   -Don Slutz
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 03/16] target-i386: Add cpu object access routines for Hypervisor level.

2012-10-10 Thread Don Slutz

On 10/09/12 15:13, Don Slutz wrote:

On 10/09/12 12:25, Marcelo Tosatti wrote:

On Mon, Sep 24, 2012 at 10:32:05AM -0400, Don Slutz wrote:

These are modeled after x86_cpuid_get_xlevel and x86_cpuid_set_xlevel.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
  target-i386/cpu.c |   29 +
  1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 25ca986..451de12 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1166,6 +1166,32 @@ static void x86_cpuid_set_tsc_freq(Object 
*obj, Visitor *v, void *opaque,

  cpu-env.tsc_khz = value / 1000;
  }
  +static void x86_cpuid_get_hv_level(Object *obj, Visitor *v, void 
*opaque,

+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_level, name, errp);
+}
+
+static void x86_cpuid_set_hv_level(Object *obj, Visitor *v, void 
*opaque,

+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+uint32_t value;
+
+visit_type_uint32(v, value, name, errp);
+if (error_is_set(errp)) {
+return;
+}
+
+if (value != 0  value  0x4000) {
+value += 0x4000;
+}

Whats the purpose of this? Adds ambiguity.

Will add more info in this commit message.
   -Don
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Not clear on how to add info in the commit message.

This is direct copy with adjustment from x86_cpuid_set_xlevel():

if (value  0x8000) {
value += 0x8000;
}

(Pending patch: 
http://comments.gmane.org/gmane.comp.emulators.qemu/172703 adds this)


The adjustment is that 0 is a legal value. See 
http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html


This does mean that just like xlevel=1 and xlevel=0x8001 are the 
same; hypervisor-level=1 and hypervisor-level=0x401 are the same.  
If this is not wanted, I have no issue with removing it.


   -Don Slutz
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [QEMU PATCH] i386: cpu: add missing CPUID[EAX=7, ECX=0] flag names

2012-10-09 Thread Don Slutz

On 10/09/12 10:03, Eduardo Habkost wrote:

This makes QEMU recognize the following CPU flag names:

  Flags| Corresponding KVM kernel commit
  -+
  FSGSBASE | 176f61da82435eae09cc96f70b530d1ba0746b8b
  AVX2, BMI1, BMI2 | fb215366b3c7320ac25dca766a0152df16534932
  HLE, RTM | 83c529151ab0d4a813e3f6a3e293fff75d468519
  INVPCID  | ad756a1603c5fac207758faaac7f01c34c9d0b7b
  ERMS | a01c8f9b4e266df1d7166d23216f2060648f862d

Signed-off-by: Eduardo Habkost ehabk...@redhat.com
---
  target-i386/cpu.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index f3708e6..b012372 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -105,8 +105,8 @@ static const char *svm_feature_name[] = {
  };
  
  static const char *cpuid_7_0_ebx_feature_name[] = {

-NULL, NULL, NULL, NULL, NULL, NULL, NULL, smep,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+fsgsbase, NULL, NULL, bmi1, hle, avx2, NULL, smep,
+bmi2, erms, invpcid, rtm, NULL, NULL, NULL, NULL,
  NULL, NULL, NULL, NULL, smap, NULL, NULL, NULL,
  NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  };

Reviewed-by: Don Slutz d...@cloudswitch.com

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 05/16] target-i386: Use Hypervisor level in -machine pc,accel=kvm.

2012-10-09 Thread Don Slutz

On 10/09/12 14:47, Marcelo Tosatti wrote:

On Tue, Oct 09, 2012 at 03:27:26PM -0300, Marcelo Tosatti wrote:

On Tue, Oct 09, 2012 at 02:18:05PM -0300, Marcelo Tosatti wrote:

On Mon, Sep 24, 2012 at 10:32:07AM -0400, Don Slutz wrote:

Also known as Paravirtualization level.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
   
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
   http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
   http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
   
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

Signed-off-by: Don Slutz d...@cloudswitch.com
---
  target-i386/kvm.c |4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 895d848..8462c75 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -389,12 +389,12 @@ int kvm_arch_init_vcpu(CPUX86State *env)
  c = cpuid_data.entries[cpuid_i++];
  memset(c, 0, sizeof(*c));
  c-function = KVM_CPUID_SIGNATURE
-if (!hyperv_enabled()) {
+if (!env-cpuid_hv_level_set) {
  memcpy(signature, KVMKVMKVM\0\0\0, 12);
  c-eax = 0;
  } else {
  memcpy(signature, Microsoft Hv, 12);
-c-eax = HYPERV_CPUID_MIN;
+c-eax = env-cpuid_hv_level;

This breaks hyperv_enabled() checks.

Don, are you certain it is worthwhile to make this configurable?
Can you explain why, under your scenario, it is worthwhile?

Because these are separate problems:

- Fake VMWare hypervisor  (which seems to be your main goal).
- Make CPUID HV leafs configurable via command line.

Err, meant via properties. Point is, why have VMWare CPUID
configuration as data, if there are reasons to believe code
is a better fit (code as in current Hyper-V implementation).

Nevermind, its the right thing to do. Just separate the patchset
please:

1) Create object properties.
2) Export VMWare CPUID via properties.
3) Convert Hyper-V.

Be careful to make sure Hyper-V's current options are functional
in 3).


Did you mean 3 patch sets (or more)? Or just a different order?
   -Don Slutz

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 04/16] target-i386: Add x86_set_hyperv.

2012-10-09 Thread Don Slutz

On 10/09/12 13:17, Marcelo Tosatti wrote:

On Tue, Oct 09, 2012 at 01:34:09PM -0300, Marcelo Tosatti wrote:

On Mon, Sep 24, 2012 at 10:32:06AM -0400, Don Slutz wrote:

This is used to set the cpu object's hypervisor level to the default for 
Microsoft's Hypervisor.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
  target-i386/cpu.c |9 +
  target-i386/cpu.h |2 ++
  2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 451de12..48bdaf9 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1193,6 +1193,12 @@ static void x86_cpuid_set_hv_level(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,
+hypervisor-level, errp);
+}
+
  static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
   const char *name, Error **errp)
  {
@@ -1215,6 +1221,7 @@ static void x86_set_hv_spinlocks(Object *obj, Visitor *v, 
void *opaque,
  return;
  }
  hyperv_set_spinlock_retries(value);
+x86_set_hyperv(obj, errp);
  }
  
  static void x86_get_hv_relaxed(Object *obj, Visitor *v, void *opaque,

@@ -1235,6 +1242,7 @@ static void x86_set_hv_relaxed(Object *obj, Visitor *v, 
void *opaque,
  return;
  }
  hyperv_enable_relaxed_timing(value);
+x86_set_hyperv(obj, errp);
  }
  
  static void x86_get_hv_vapic(Object *obj, Visitor *v, void *opaque,

@@ -1255,6 +1263,7 @@ static void x86_set_hv_vapic(Object *obj, Visitor *v, 
void *opaque,
  return;
  }
  hyperv_enable_vapic_recommended(value);
+x86_set_hyperv(obj, errp);
  }
  #endif
  
diff --git a/target-i386/cpu.h b/target-i386/cpu.h

index 1899f69..3152a4e 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -488,6 +488,8 @@
  
  #define CPUID_VENDOR_VIA   CentaurHauls
  
+#define CPUID_HV_LEVEL_HYPERV  0x4005

+

Where this comes from?

http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

has under Leaf 0x4000 (at very top of table):

EAX

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

Is that the same 0x4005 as in this patch?

Yes, the #define can be reused:

#define HYPERV_CPUID_MIN0x4005


Not as simple as it seems.

http://lists.nongnu.org/archive/html/qemu-devel/2012-09/msg03359.html

I can make sure this info is part of the commit message.
-Don Slutz
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 03/16] target-i386: Add cpu object access routines for Hypervisor level.

2012-10-09 Thread Don Slutz

On 10/09/12 12:25, Marcelo Tosatti wrote:

On Mon, Sep 24, 2012 at 10:32:05AM -0400, Don Slutz wrote:

These are modeled after x86_cpuid_get_xlevel and x86_cpuid_set_xlevel.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
  target-i386/cpu.c |   29 +
  1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 25ca986..451de12 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1166,6 +1166,32 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor 
*v, void *opaque,
  cpu-env.tsc_khz = value / 1000;
  }
  
+static void x86_cpuid_get_hv_level(Object *obj, Visitor *v, void *opaque,

+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_level, name, errp);
+}
+
+static void x86_cpuid_set_hv_level(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+uint32_t value;
+
+visit_type_uint32(v, value, name, errp);
+if (error_is_set(errp)) {
+return;
+}
+
+if (value != 0  value  0x4000) {
+value += 0x4000;
+}

Whats the purpose of this? Adds ambiguity.

Will add more info in this commit message.
   -Don
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v5 00/17] Allow changing of Hypervisor CPUIDs.

2012-09-24 Thread Don Slutz

On 09/22/12 09:18, Blue Swirl wrote:

On Sat, Sep 22, 2012 at 12:13 AM, Don Slutz d...@cloudswitch.com wrote:

Also known as Paravirtualization CPUIDs.

This is primarily done so that the guest will think it is running
under vmware when hypervisor-vendor=vmware is specified as a
property of a cpu.

Please use checkpatch.pl to check for missing braces etc.
I have been.  Somehow missed the warnings on the posted patches.  v6 in 
the works.


This depends on:

http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg01400.html

As far as I know it is #4. It depends on (1) and (2) and (3).

This change is based on:

Microsoft Hypervisor CPUID Leaves:
   
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
   http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
   http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
   
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Changes from v4 to v5:
   Undo kvm_clock2 change.
   Add cpuid_hv_level_set; cpuid_hv_level == 0 is now valid.
   Add cpuid_hv_vendor_set; the null string is now valid.
   Handle kvm and cpuid_hv_level == 0.
   hypervisor-vendor=kvm,hypervisor-level=0 and 
hypervisor-level=0,hypervisor-vendor=kvm
 now do the same thing.

Changes from v3 to v4:
   Added CPUID_HV_LEVEL_HYPERV, CPUID_HV_LEVEL_KVM.
   Added CPUID_HV_VENDOR_HYPERV.
   Added hyperv as known hypservisor-vendor.
   Allow hypervisor-level to be 0.

Changes from v2 to v3:
   Clean post to qemu-devel.

Changes from v1 to v2:

1) Added 1/4 from 
http://lists.gnu.org/archive/html/qemu-devel/2012-08/msg05153.html

Because Fred is changing jobs and so will not be pushing to get
this in. It needed to be rebased, And I needed it to complete the
testing of this change.

2) Added 2/4 because of the re-work I needed a way to clear all KVM bits,

3) The rework of v1.  Make it fit into the object model re-work of cpu.c for 
x86.

4) Added 3/4 -- The split out of the code that is not needed for accel=kvm.

Changes from v2 to v3:

Marcelo Tosatti:
   Its one big patch, better split in logically correlated patches
   (with better changelog). This would help reviewers.

So split 3 and 4 into 3 to 17.  More info in change log.
No code change.

Don Slutz (17):
   target-i386: Allow tsc-frequency to be larger then 2.147G
   target-i386: Add missing kvm bits.
   target-i386: Add Hypervisor level.
   target-i386: Add cpu object access routines for Hypervisor level.
   target-i386: Add cpu object access routines for Hypervisor level.
   target-i386: Use Hypervisor level in -machine pc,accel=kvm.
   target-i386: Use Hypervisor level in -machine pc,accel=tcg.
   target-i386: Add Hypervisor vendor.
   target-i386: Add cpu object access routines for Hypervisor vendor.
   target-i386: Use Hypervisor vendor in -machine pc,accel=kvm.
   target-i386: Use Hypervisor vendor in -machine pc,accel=tcg.
   target-i386: Add some known names to Hypervisor vendor.
   target-i386: Add optional Hypervisor leaf extra.
   target-i386: Add cpu object access routines for Hypervisor leaf
 extra.
   target-i386: Add setting of Hypervisor leaf extra for known vmare4.
   target-i386: Use Hypervisor leaf extra in -machine pc,accel=kvm.
   target-i386: Use Hypervisor leaf extra in -machine pc,accel=tcg.

  target-i386/cpu.c |  285 -
  target-i386/cpu.h |   34 +++
  target-i386/kvm.c |   33 +-
  3 files changed, 341 insertions(+), 11 deletions(-)



  -Don
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 00/16] Allow changing of Hypervisor CPUIDs.

2012-09-24 Thread Don Slutz
Also known as Paravirtualization CPUIDs.

This is primarily done so that the guest will think it is running
under vmware when hypervisor-vendor=vmware is specified as a
property of a cpu.


This depends on:

http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg01400.html

As far as I know it is #4. It depends on (1) and (2) and (3).

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Changes from v5 to v6:
  Split out 01/17: target-i386: Allow tsc-frequency to be larger then 2.147G
It has been accepted as a trivial patch:
http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg03959.html
Blue Swirl:
  Fix 2 checkpatch.pl WARNING: line over 80 characters.

Changes from v4 to v5:
  Undo kvm_clock2 change.
  Add cpuid_hv_level_set; cpuid_hv_level == 0 is now valid.
  Add cpuid_hv_vendor_set; the null string is now valid.
  Handle kvm and cpuid_hv_level == 0.
  hypervisor-vendor=kvm,hypervisor-level=0 and 
hypervisor-level=0,hypervisor-vendor=kvm
now do the same thing.

Changes from v3 to v4:
  Added CPUID_HV_LEVEL_HYPERV, CPUID_HV_LEVEL_KVM.
  Added CPUID_HV_VENDOR_HYPERV.
  Added hyperv as known hypservisor-vendor.
  Allow hypervisor-level to be 0.

Changes from v2 to v3:
  Clean post to qemu-devel.

Changes from v1 to v2:

1) Added 1/4 from 
http://lists.gnu.org/archive/html/qemu-devel/2012-08/msg05153.html

   Because Fred is changing jobs and so will not be pushing to get
   this in. It needed to be rebased, And I needed it to complete the
   testing of this change.

2) Added 2/4 because of the re-work I needed a way to clear all KVM bits,

3) The rework of v1.  Make it fit into the object model re-work of cpu.c for 
x86.

4) Added 3/4 -- The split out of the code that is not needed for accel=kvm.

Changes from v2 to v3:

Marcelo Tosatti:
  Its one big patch, better split in logically correlated patches
  (with better changelog). This would help reviewers.

So split 3 and 4 into 3 to 17.  More info in change log.
No code change.

Don Slutz (16):
  target-i386: Add missing kvm bits.
  target-i386: Add Hypervisor level.
  target-i386: Add cpu object access routines for Hypervisor level.
  target-i386: Add x86_set_hyperv.
  target-i386: Use Hypervisor level in -machine pc,accel=kvm.
  target-i386: Use Hypervisor level in -machine pc,accel=tcg.
  target-i386: Add Hypervisor vendor.
  target-i386: Add cpu object access routines for Hypervisor vendor.
  target-i386: Use Hypervisor vendor in -machine pc,accel=kvm.
  target-i386: Use Hypervisor vendor in -machine pc,accel=tcg.
  target-i386: Add some known names to Hypervisor vendor.
  target-i386: Add optional Hypervisor leaf extra.
  target-i386: Add cpu object access routines for Hypervisor leaf
extra.
  target-i386: Add setting of Hypervisor leaf extra for known vmare4.
  target-i386: Use Hypervisor leaf extra in -machine pc,accel=kvm.
  target-i386: Use Hypervisor leaf extra in -machine pc,accel=tcg.

 target-i386/cpu.c |  285 -
 target-i386/cpu.h |   34 +++
 target-i386/kvm.c |   33 +-
 3 files changed, 342 insertions(+), 10 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 01/16] target-i386: Add missing kvm bits.

2012-09-24 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   12 
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 0313cf5..25ca986 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -87,10 +87,14 @@ static const char *ext3_feature_name[] = {
 };
 
 static const char *kvm_feature_name[] = {
-kvmclock, kvm_nopiodelay, kvm_mmu, kvmclock, kvm_asyncpf, NULL, 
kvm_pv_eoi, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+kvmclock, kvm_nopiodelay, kvm_mmu, kvmclock,
+kvm_asyncpf, kvm_steal_time, kvm_pv_eoi, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+kvm_clock_stable, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
 };
 
 static const char *svm_feature_name[] = {
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 02/16] target-i386: Add Hypervisor level.

2012-09-24 Thread Don Slutz
Also known as Paravirtualization level or maximim cpuid function present in 
this leaf.
This is just the EAX value for 0x4000.

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

QEMU has the value HYPERV_CPUID_MIN defined.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 5265c5a..1899f69 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -777,11 +777,14 @@ typedef struct CPUX86State {
 uint32_t cpuid_ext3_features;
 uint32_t cpuid_apic_id;
 bool cpuid_vendor_override;
+bool cpuid_hv_level_set;
 /* Store the results of Centaur's CPUID instructions */
 uint32_t cpuid_xlevel2;
 uint32_t cpuid_ext4_features;
 /* Flags from CPUID[EAX=7,ECX=0].EBX */
 uint32_t cpuid_7_0_ebx;
+/* Hypervisor CPUIDs */
+uint32_t cpuid_hv_level;
 
 /* MTRRs */
 uint64_t mtrr_fixed[11];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 03/16] target-i386: Add cpu object access routines for Hypervisor level.

2012-09-24 Thread Don Slutz
These are modeled after x86_cpuid_get_xlevel and x86_cpuid_set_xlevel.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   29 +
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 25ca986..451de12 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1166,6 +1166,32 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor 
*v, void *opaque,
 cpu-env.tsc_khz = value / 1000;
 }
 
+static void x86_cpuid_get_hv_level(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_level, name, errp);
+}
+
+static void x86_cpuid_set_hv_level(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+uint32_t value;
+
+visit_type_uint32(v, value, name, errp);
+if (error_is_set(errp)) {
+return;
+}
+
+if (value != 0  value  0x4000) {
+value += 0x4000;
+}
+cpu-env.cpuid_hv_level = value;
+cpu-env.cpuid_hv_level_set = true;
+}
+
 #if !defined(CONFIG_USER_ONLY)
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
  const char *name, Error **errp)
@@ -2061,6 +2087,9 @@ static void x86_cpu_initfn(Object *obj)
 object_property_add(obj, enforce, bool,
 x86_cpuid_get_enforce,
 x86_cpuid_set_enforce, NULL, NULL, NULL);
+object_property_add(obj, hypervisor-level, int,
+x86_cpuid_get_hv_level,
+x86_cpuid_set_hv_level, NULL, NULL, NULL);
 #if !defined(CONFIG_USER_ONLY)
 object_property_add(obj, hv_spinlocks, int,
 x86_get_hv_spinlocks,
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 04/16] target-i386: Add x86_set_hyperv.

2012-09-24 Thread Don Slutz
This is used to set the cpu object's hypervisor level to the default for 
Microsoft's Hypervisor.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |9 +
 target-i386/cpu.h |2 ++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 451de12..48bdaf9 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1193,6 +1193,12 @@ static void x86_cpuid_set_hv_level(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,
+hypervisor-level, errp);
+}
+
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
  const char *name, Error **errp)
 {
@@ -1215,6 +1221,7 @@ static void x86_set_hv_spinlocks(Object *obj, Visitor *v, 
void *opaque,
 return;
 }
 hyperv_set_spinlock_retries(value);
+x86_set_hyperv(obj, errp);
 }
 
 static void x86_get_hv_relaxed(Object *obj, Visitor *v, void *opaque,
@@ -1235,6 +1242,7 @@ static void x86_set_hv_relaxed(Object *obj, Visitor *v, 
void *opaque,
 return;
 }
 hyperv_enable_relaxed_timing(value);
+x86_set_hyperv(obj, errp);
 }
 
 static void x86_get_hv_vapic(Object *obj, Visitor *v, void *opaque,
@@ -1255,6 +1263,7 @@ static void x86_set_hv_vapic(Object *obj, Visitor *v, 
void *opaque,
 return;
 }
 hyperv_enable_vapic_recommended(value);
+x86_set_hyperv(obj, errp);
 }
 #endif
 
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 1899f69..3152a4e 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -488,6 +488,8 @@
 
 #define CPUID_VENDOR_VIA   CentaurHauls
 
+#define CPUID_HV_LEVEL_HYPERV  0x4005
+
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX (1  0) /* enumeration supported */
 
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 05/16] target-i386: Use Hypervisor level in -machine pc,accel=kvm.

2012-09-24 Thread Don Slutz
Also known as Paravirtualization level.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/kvm.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 895d848..8462c75 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -389,12 +389,12 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
 c-function = KVM_CPUID_SIGNATURE;
-if (!hyperv_enabled()) {
+if (!env-cpuid_hv_level_set) {
 memcpy(signature, KVMKVMKVM\0\0\0, 12);
 c-eax = 0;
 } else {
 memcpy(signature, Microsoft Hv, 12);
-c-eax = HYPERV_CPUID_MIN;
+c-eax = env-cpuid_hv_level;
 }
 c-ebx = signature[0];
 c-ecx = signature[1];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 06/16] target-i386: Use Hypervisor level in -machine pc,accel=tcg.

2012-09-24 Thread Don Slutz
Also known as Paravirtualization level.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

QEMU knows this as KVM_CPUID_SIGNATURE (0x4000) in kvm on linux.

This does not provide vendor support in tcg yet.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   27 +++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 48bdaf9..920278b 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1651,6 +1651,21 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 index =  env-cpuid_xlevel;
 }
 }
+} else if (index  0x4000) {
+if (env-cpuid_hv_level_set) {
+uint32_t real_level = env-cpuid_hv_level;
+
+/* Handle Hypervisor CPUIDs */
+if (real_level  0x4000) {
+real_level = 0x4000;
+}
+if (index  real_level) {
+index = real_level;
+}
+} else {
+if (index  env-cpuid_level)
+index = env-cpuid_level;
+}
 } else {
 if (index  env-cpuid_level)
 index = env-cpuid_level;
@@ -1789,6 +1804,18 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 *edx = 0;
 }
 break;
+case 0x4000:
+*eax = env-cpuid_hv_level;
+*ebx = 0;
+*ecx = 0;
+*edx = 0;
+break;
+case 0x4001:
+*eax = env-cpuid_kvm_features;
+*ebx = 0;
+*ecx = 0;
+*edx = 0;
+break;
 case 0x8000:
 *eax = env-cpuid_xlevel;
 *ebx = env-cpuid_vendor1;
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 07/16] target-i386: Add Hypervisor vendor.

2012-09-24 Thread Don Slutz
Also known as Paravirtualization vendor.
This is EBX, ECX, EDX data for 0x4000.

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 3152a4e..11730b2 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -780,6 +780,7 @@ typedef struct CPUX86State {
 uint32_t cpuid_apic_id;
 bool cpuid_vendor_override;
 bool cpuid_hv_level_set;
+bool cpuid_hv_vendor_set;
 /* Store the results of Centaur's CPUID instructions */
 uint32_t cpuid_xlevel2;
 uint32_t cpuid_ext4_features;
@@ -787,6 +788,9 @@ typedef struct CPUX86State {
 uint32_t cpuid_7_0_ebx;
 /* Hypervisor CPUIDs */
 uint32_t cpuid_hv_level;
+uint32_t cpuid_hv_vendor1;
+uint32_t cpuid_hv_vendor2;
+uint32_t cpuid_hv_vendor3;
 
 /* MTRRs */
 uint64_t mtrr_fixed[11];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 08/16] target-i386: Add cpu object access routines for Hypervisor vendor.

2012-09-24 Thread Don Slutz
These are modeled after x86_cpuid_set_vendor and x86_cpuid_get_vendor.
Since kvm's vendor is shorter, the test for correct size is removed and zero 
padding is added.

Set Microsoft's Vendor now that we can.  Value defined in:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx
And matches want is in target-i386/kvm.c

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   46 ++
 target-i386/cpu.h |2 ++
 2 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 920278b..964877f 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1192,11 +1192,54 @@ static void x86_cpuid_set_hv_level(Object *obj, Visitor 
*v, void *opaque,
 cpu-env.cpuid_hv_level_set = true;
 }
 
+static char *x86_cpuid_get_hv_vendor(Object *obj, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+CPUX86State *env = cpu-env;
+char *value;
+int i;
+
+value = (char *)g_malloc(CPUID_VENDOR_SZ + 1);
+for (i = 0; i  4; i++) {
+value[i + 0] = env-cpuid_hv_vendor1  (8 * i);
+value[i + 4] = env-cpuid_hv_vendor2  (8 * i);
+value[i + 8] = env-cpuid_hv_vendor3  (8 * i);
+}
+value[CPUID_VENDOR_SZ] = '\0';
+
+return value;
+}
+
+static void x86_cpuid_set_hv_vendor(Object *obj, const char *value,
+Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+CPUX86State *env = cpu-env;
+int i;
+char adj_value[CPUID_VENDOR_SZ + 1];
+
+memset(adj_value, 0, sizeof(adj_value));
+
+pstrcpy(adj_value, sizeof(adj_value), value);
+
+env-cpuid_hv_vendor1 = 0;
+env-cpuid_hv_vendor2 = 0;
+env-cpuid_hv_vendor3 = 0;
+for (i = 0; i  4; i++) {
+env-cpuid_hv_vendor1 |= ((uint8_t)adj_value[i + 0])  (8 * i);
+env-cpuid_hv_vendor2 |= ((uint8_t)adj_value[i + 4])  (8 * i);
+env-cpuid_hv_vendor3 |= ((uint8_t)adj_value[i + 8])  (8 * i);
+}
+env-cpuid_hv_vendor_set = true;
+}
+
 #if !defined(CONFIG_USER_ONLY)
 static void x86_set_hyperv(Object *obj, Error **errp)
 {
 object_property_set_int(obj, CPUID_HV_LEVEL_HYPERV,
 hypervisor-level, errp);
+object_property_set_str(obj, CPUID_HV_VENDOR_HYPERV,
+hypervisor-vendor, errp);
 }
 
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
@@ -2126,6 +2169,9 @@ static void x86_cpu_initfn(Object *obj)
 object_property_add(obj, hypervisor-level, int,
 x86_cpuid_get_hv_level,
 x86_cpuid_set_hv_level, NULL, NULL, NULL);
+object_property_add_str(obj, hypervisor-vendor,
+x86_cpuid_get_hv_vendor,
+x86_cpuid_set_hv_vendor, NULL);
 #if !defined(CONFIG_USER_ONLY)
 object_property_add(obj, hv_spinlocks, int,
 x86_get_hv_spinlocks,
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 11730b2..eb6aa4a 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -488,6 +488,8 @@
 
 #define CPUID_VENDOR_VIA   CentaurHauls
 
+#define CPUID_HV_VENDOR_HYPERV Microsoft Hv
+
 #define CPUID_HV_LEVEL_HYPERV  0x4005
 
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 09/16] target-i386: Use Hypervisor vendor in -machine pc,accel=kvm.

2012-09-24 Thread Don Slutz
Also known as Paravirtualization vendor.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/kvm.c |   12 +++-
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 8462c75..f8a5177 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -389,16 +389,18 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
 c-function = KVM_CPUID_SIGNATURE;
-if (!env-cpuid_hv_level_set) {
+if (!env-cpuid_hv_level_set  !env-cpuid_hv_vendor_set) {
 memcpy(signature, KVMKVMKVM\0\0\0, 12);
 c-eax = 0;
+c-ebx = signature[0];
+c-ecx = signature[1];
+c-edx = signature[2];
 } else {
-memcpy(signature, Microsoft Hv, 12);
 c-eax = env-cpuid_hv_level;
+c-ebx = env-cpuid_hv_vendor1;
+c-ecx = env-cpuid_hv_vendor2;
+c-edx = env-cpuid_hv_vendor3;
 }
-c-ebx = signature[0];
-c-ecx = signature[1];
-c-edx = signature[2];
 
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 10/16] target-i386: Use Hypervisor vendor in -machine pc,accel=tcg.

2012-09-24 Thread Don Slutz
Also known as Paravirtualization vendor.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
This is where the 0 is the same as 0x4001 is defined.

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 964877f..a929b64 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1695,7 +1695,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 }
 }
 } else if (index  0x4000) {
-if (env-cpuid_hv_level_set) {
+if (env-cpuid_hv_level_set || env-cpuid_hv_vendor_set) {
 uint32_t real_level = env-cpuid_hv_level;
 
 /* Handle Hypervisor CPUIDs */
@@ -1849,9 +1849,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 break;
 case 0x4000:
 *eax = env-cpuid_hv_level;
-*ebx = 0;
-*ecx = 0;
-*edx = 0;
+*ebx = env-cpuid_hv_vendor1;
+*ecx = env-cpuid_hv_vendor2;
+*edx = env-cpuid_hv_vendor3;
 break;
 case 0x4001:
 *eax = env-cpuid_kvm_features;
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 11/16] target-i386: Add some known names to Hypervisor vendor.

2012-09-24 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   57 +++-
 target-i386/cpu.h |   19 +
 2 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index a929b64..9ab29a7 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1207,6 +1207,24 @@ static char *x86_cpuid_get_hv_vendor(Object *obj, Error 
**errp)
 }
 value[CPUID_VENDOR_SZ] = '\0';
 
+/* Convert known names */
+if (!strcmp(value, CPUID_HV_VENDOR_HYPERV) 
+   env-cpuid_hv_level == CPUID_HV_LEVEL_HYPERV) {
+pstrcpy(value, sizeof(value), hyperv);
+} else if (!strcmp(value, CPUID_HV_VENDOR_VMWARE)) {
+if (env-cpuid_hv_level == CPUID_HV_LEVEL_VMWARE_4) {
+pstrcpy(value, sizeof(value), vmware4);
+} else if (env-cpuid_hv_level == CPUID_HV_LEVEL_VMWARE_3) {
+pstrcpy(value, sizeof(value), vmware3);
+}
+} else if (!strcmp(value, CPUID_HV_VENDOR_XEN) 
+   env-cpuid_hv_level == CPUID_HV_LEVEL_XEN) {
+pstrcpy(value, sizeof(value), xen);
+} else if (!strcmp(value, CPUID_HV_VENDOR_KVM) 
+   (env-cpuid_hv_level == 0 ||
+env-cpuid_hv_level == CPUID_HV_LEVEL_KVM)) {
+pstrcpy(value, sizeof(value), kvm);
+}
 return value;
 }
 
@@ -1220,7 +1238,35 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
 
 memset(adj_value, 0, sizeof(adj_value));
 
-pstrcpy(adj_value, sizeof(adj_value), value);
+/* Convert known names */
+if (!strcmp(value, hyperv)) {
+if (!env-cpuid_hv_level_set) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_HYPERV;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_HYPERV);
+} else if (!strcmp(value, vmware) || !strcmp(value, vmware4)) {
+if (!env-cpuid_hv_level_set) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_VMWARE_4;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_VMWARE);
+} else if (!strcmp(value, vmware3)) {
+if (!env-cpuid_hv_level_set) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_VMWARE_3;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_VMWARE);
+} else if (!strcmp(value, xen)) {
+if (!env-cpuid_hv_level_set) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_XEN;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_XEN);
+} else if (!strcmp(value, kvm)) {
+if (!env-cpuid_hv_level_set) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_KVM;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_KVM);
+} else {
+pstrcpy(adj_value, sizeof(adj_value), value);
+}
 
 env-cpuid_hv_vendor1 = 0;
 env-cpuid_hv_vendor2 = 0;
@@ -1700,7 +1746,14 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 
 /* Handle Hypervisor CPUIDs */
 if (real_level  0x4000) {
-real_level = 0x4000;
+if (env-cpuid_hv_vendor1 == CPUID_HV_VENDOR_KVM_1 
+env-cpuid_hv_vendor2 == CPUID_HV_VENDOR_KVM_2 
+env-cpuid_hv_vendor3 == CPUID_HV_VENDOR_KVM_3 
+real_level == 0) {
+real_level = CPUID_HV_LEVEL_KVM;
+} else {
+real_level = 0x4000;
+}
 }
 if (index  real_level) {
 index = real_level;
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index eb6aa4a..ebb3498 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -490,8 +490,27 @@
 
 #define CPUID_HV_VENDOR_HYPERV Microsoft Hv
 
+#define CPUID_HV_VENDOR_VMWARE_1 0x61774d56 /* VMwa */
+#define CPUID_HV_VENDOR_VMWARE_2 0x4d566572 /* reVM */
+#define CPUID_HV_VENDOR_VMWARE_3 0x65726177 /* ware */
+#define CPUID_HV_VENDOR_VMWARE VMwareVMware
+
+#define CPUID_HV_VENDOR_XEN XenVMMXenVMM
+
+#define CPUID_HV_VENDOR_KVM_1 0x4b4d564b /* KVMK */
+#define CPUID_HV_VENDOR_KVM_2 0x564b4d56 /* VMKV */
+#define CPUID_HV_VENDOR_KVM_3 0x004d /* M\0\0\0 */
+#define CPUID_HV_VENDOR_KVM KVMKVMKVM
+
 #define CPUID_HV_LEVEL_HYPERV  0x4005
 
+#define CPUID_HV_LEVEL_VMWARE_3 0x4002
+#define CPUID_HV_LEVEL_VMWARE_4 0x4010
+
+#define CPUID_HV_LEVEL_XEN  0x4002
+
+#define CPUID_HV_LEVEL_KVM  0x4001
+
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX (1  0) /* enumeration supported */
 
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 12/16] target-i386: Add optional Hypervisor leaf extra.

2012-09-24 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index ebb3498..254ddef 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -812,6 +812,10 @@ typedef struct CPUX86State {
 uint32_t cpuid_hv_vendor1;
 uint32_t cpuid_hv_vendor2;
 uint32_t cpuid_hv_vendor3;
+/* VMware extra data */
+uint32_t cpuid_hv_extra;
+uint32_t cpuid_hv_extra_a;
+uint32_t cpuid_hv_extra_b;
 
 /* MTRRs */
 uint64_t mtrr_fixed[11];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 13/16] target-i386: Add cpu object access routines for Hypervisor leaf extra.

2012-09-24 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   66 +
 1 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 9ab29a7..8bb20c7 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1279,6 +1279,63 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
 env-cpuid_hv_vendor_set = true;
 }
 
+static void x86_cpuid_get_hv_extra(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra, name, errp);
+}
+
+static void x86_cpuid_set_hv_extra(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+uint32_t value;
+
+visit_type_uint32(v, value, name, errp);
+if (error_is_set(errp)) {
+return;
+}
+
+if ((value != 0)  (value  0x4000)) {
+value += 0x4000;
+}
+cpu-env.cpuid_hv_extra = value;
+}
+
+static void x86_cpuid_get_hv_extra_a(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra_a, name, errp);
+}
+
+static void x86_cpuid_set_hv_extra_a(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra_a, name, errp);
+}
+
+static void x86_cpuid_get_hv_extra_b(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra_b, name, errp);
+}
+
+static void x86_cpuid_set_hv_extra_b(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra_b, name, errp);
+}
+
 #if !defined(CONFIG_USER_ONLY)
 static void x86_set_hyperv(Object *obj, Error **errp)
 {
@@ -2225,6 +2282,15 @@ static void x86_cpu_initfn(Object *obj)
 object_property_add_str(obj, hypervisor-vendor,
 x86_cpuid_get_hv_vendor,
 x86_cpuid_set_hv_vendor, NULL);
+object_property_add(obj, hypervisor-extra, int,
+x86_cpuid_get_hv_extra,
+x86_cpuid_set_hv_extra, NULL, NULL, NULL);
+object_property_add(obj, hypervisor-extra-a, int,
+x86_cpuid_get_hv_extra_a,
+x86_cpuid_set_hv_extra_a, NULL, NULL, NULL);
+object_property_add(obj, hypervisor-extra-b, int,
+x86_cpuid_get_hv_extra_b,
+x86_cpuid_set_hv_extra_b, NULL, NULL, NULL);
 #if !defined(CONFIG_USER_ONLY)
 object_property_add(obj, hv_spinlocks, int,
 x86_get_hv_spinlocks,
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 14/16] target-i386: Add setting of Hypervisor leaf extra for known vmare4.

2012-09-24 Thread Don Slutz
This was taken from:
  http://article.gmane.org/gmane.comp.emulators.kvm.devel/22643

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   32 
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 8bb20c7..b77dbfe 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1135,6 +1135,36 @@ static void x86_cpuid_set_model_id(Object *obj, const 
char *model_id,
 }
 }
 
+static void x86_cpuid_set_vmware_extra(Object *obj)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+if ((cpu-env.tsc_khz != 0) 
+(cpu-env.cpuid_hv_level == CPUID_HV_LEVEL_VMWARE_4) 
+(cpu-env.cpuid_hv_vendor1 == CPUID_HV_VENDOR_VMWARE_1) 
+(cpu-env.cpuid_hv_vendor2 == CPUID_HV_VENDOR_VMWARE_2) 
+(cpu-env.cpuid_hv_vendor3 == CPUID_HV_VENDOR_VMWARE_3)) {
+const uint32_t apic_khz = 100L;
+
+/*
+ * From article.gmane.org/gmane.comp.emulators.kvm.devel/22643
+ *
+ *Leaf 0x4010, Timing Information.
+ *
+ *VMware has defined the first generic leaf to provide timing
+ *information.  This leaf returns the current TSC frequency and
+ *current Bus frequency in kHz.
+ *
+ *# EAX: (Virtual) TSC frequency in kHz.
+ *# EBX: (Virtual) Bus (local apic timer) frequency in kHz.
+ *# ECX, EDX: RESERVED (Per above, reserved fields are set to 
zero).
+ */
+cpu-env.cpuid_hv_extra = 0x4010;
+cpu-env.cpuid_hv_extra_a = (uint32_t)cpu-env.tsc_khz;
+cpu-env.cpuid_hv_extra_b = apic_khz;
+}
+}
+
 static void x86_cpuid_get_tsc_freq(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
 {
@@ -1164,6 +1194,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor 
*v, void *opaque,
 }
 
 cpu-env.tsc_khz = value / 1000;
+x86_cpuid_set_vmware_extra(obj);
 }
 
 static void x86_cpuid_get_hv_level(Object *obj, Visitor *v, void *opaque,
@@ -1277,6 +1308,7 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
 env-cpuid_hv_vendor3 |= ((uint8_t)adj_value[i + 8])  (8 * i);
 }
 env-cpuid_hv_vendor_set = true;
+x86_cpuid_set_vmware_extra(obj);
 }
 
 static void x86_cpuid_get_hv_extra(Object *obj, Visitor *v, void *opaque,
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 15/16] target-i386: Use Hypervisor leaf extra in -machine pc,accel=kvm.

2012-09-24 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/kvm.c |   19 +++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index f8a5177..ff82034 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -454,6 +454,25 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c-ebx = signature[0];
 c-ecx = signature[1];
 c-edx = signature[2];
+} else if (env-cpuid_hv_extra != 0) {
+for (i = KVM_CPUID_FEATURES + 1; i = env-cpuid_hv_level; i++) {
+c = cpuid_data.entries[cpuid_i++];
+memset(c, 0, sizeof(*c));
+c-function = i;
+if (i == env-cpuid_hv_extra) {
+c-eax = env-cpuid_hv_extra_a;
+c-ebx = env-cpuid_hv_extra_b;
+}
+}
+
+c = cpuid_data.entries[cpuid_i++];
+memset(c, 0, sizeof(*c));
+c-function = KVM_CPUID_SIGNATURE_NEXT;
+memcpy(signature, KVMKVMKVM\0\0\0, 12);
+c-eax = 0;
+c-ebx = signature[0];
+c-ecx = signature[1];
+c-edx = signature[2];
 }
 
 has_msr_async_pf_en = c-eax  (1  KVM_FEATURE_ASYNC_PF);
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 16/16] target-i386: Use Hypervisor leaf extra in -machine pc,accel=tcg.

2012-09-24 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   11 +++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index b77dbfe..1d81f00 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2001,6 +2001,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 *ecx = 0;
 *edx = 0;
 break;
+case 0x4002 ... 0x40FF:
+if (index == env-cpuid_hv_extra) {
+*eax = env-cpuid_hv_extra_a;
+*ebx = env-cpuid_hv_extra_b;
+} else {
+*eax = 0;
+*ebx = 0;
+}
+*ecx = 0;
+*edx = 0;
+break;
 case 0x8000:
 *eax = env-cpuid_xlevel;
 *ebx = env-cpuid_vendor1;
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 02/17] target-i386: Add missing kvm bits.

2012-09-21 Thread Don Slutz

On 09/21/12 08:36, Eduardo Habkost wrote:

On Fri, Sep 21, 2012 at 10:39:52AM +0200, Igor Mammedov wrote:

On Thu, 20 Sep 2012 16:03:17 -0400
Don Slutz d...@cloudswitch.com wrote:


Fix duplicate name (kvmclock = kvm_clock2) also.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
  target-i386/cpu.c |   12 
  1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 0313cf5..5f9866a 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -87,10 +87,14 @@ static const char *ext3_feature_name[] = {
  };
  
  static const char *kvm_feature_name[] = {

-kvmclock, kvm_nopiodelay, kvm_mmu, kvmclock, kvm_asyncpf, NULL, 
kvm_pv_eoi, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+kvmclock, kvm_nopiodelay, kvm_mmu, kvm_clock2,

before patch if kvmclock is specified it would set 0 and 3 bits,
after patch only bit 0 is set.
Is it correct/expected behavior? if yes, please add rationale into patch
description.

This is not what I had intended.

The problem here seems to be:
- It would be interesting to make kvmclock=true enough to enable the
   optimal behavior, instead of requiring users to use kvm_clock2=true
   explicitly
- We need to allow older machine-types to be backwards compatible (not
   enabling the second bit by default), so we need a separate property
   to control the second bit.

I think this is best modelled this way:

- Having two separate properties: kvmclock and kvmclock2 (or kvm_clock2)
- Older machine-types would have kvmclock2 default to false. Newer
   machine-types would kvmclock2 default to true.
- kvmclock=false would disable both bits

Then:

  - kvmclock=false would not set any bit (it would be surprising to have
kvmclock=false but still have kvmclock enabled)
  - kvmclock=true would keep compatible behavior on older machine-types,
(only the first bit set), but would get optimal behavior on newer
machine-types (both bits set)
  - kvmclock=true,kvmclock2=true would set both bits
  - kvmclock=true,kvmclock2=false would set only the first bit

It wouldn't be a direct mapping between properties and CPUID bits, but
that's exactly the point. In this case, exposing individual CPUID bits
directly is a too low-level interface.

This does look much better.  For the sake of simple changes, this patch 
will be changed so that -kvmclock (kvmclock=false) will continue to 
clear both bits.  I will look into the right way to fit this into the 
newer cpu model.
  

+kvm_asyncpf, kvm_steal_time, kvm_pv_eoi, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+kvm_clock_stable, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
  };
  
  static const char *svm_feature_name[] = {

--
1.7.1



--
Regards,
   Igor

  -Don Slutz
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/1] target-i386: Fix default Hypervisor level for hypervisor-vendor=kvm.

2012-09-21 Thread Don Slutz

On 09/21/12 10:18, Eduardo Habkost wrote:

On Thu, Sep 20, 2012 at 04:06:27PM -0400, Don Slutz wrote:

 From http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
EAX should be KVM_CPUID_FEATURES (0x4001) not 0.

Added hypervisor-vendor=kvm0 to get the older CPUID result. kvm1 selects the 
newer one.

Why not just make hypervisor-vendor=kvm control only the hypervisor
vendor string, and support something like kvm-hypervisor-level=0 to
restore the old cpuid_hv_level=0 behavior?

  -cpu host,hypervisor-vendor=kvm,hypervisor-level=0

 Does this.


This is similar to the kvmclock case: it would allow us to make
hypervisor-vendor=kvm use saner values as default, but letting old
machine-types to override it for compatibility if required.
Right now since I am using env-cpuid_hv_level == 0 as a flag. This 
means that:


  -cpu host,hypervisor-level=0,hypervisor-vendor=kvm

  -cpu host,hypervisor-vendor=kvm,hypervisor-level=0

end up with different CPUID data (Which I do not like). I will fix this in the 
next round.

Did you want me to drop kvm0 and kvm1?
   -Don

[...]

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/1] target-i386: Fix default Hypervisor level for hypervisor-vendor=kvm.

2012-09-21 Thread Don Slutz


On 09/21/12 16:49, Eduardo Habkost wrote:

On Fri, Sep 21, 2012 at 04:26:58PM -0400, Don Slutz wrote:

On 09/21/12 10:18, Eduardo Habkost wrote:

On Thu, Sep 20, 2012 at 04:06:27PM -0400, Don Slutz wrote:

 From http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
EAX should be KVM_CPUID_FEATURES (0x4001) not 0.

Added hypervisor-vendor=kvm0 to get the older CPUID result. kvm1 selects the 
newer one.

Why not just make hypervisor-vendor=kvm control only the hypervisor
vendor string, and support something like kvm-hypervisor-level=0 to
restore the old cpuid_hv_level=0 behavior?

   -cpu host,hypervisor-vendor=kvm,hypervisor-level=0

  Does this.

Good.  :-)


This is similar to the kvmclock case: it would allow us to make
hypervisor-vendor=kvm use saner values as default, but letting old
machine-types to override it for compatibility if required.

Right now since I am using env-cpuid_hv_level == 0 as a flag. This
means that:

   -cpu host,hypervisor-level=0,hypervisor-vendor=kvm

   -cpu host,hypervisor-vendor=kvm,hypervisor-level=0

end up with different CPUID data (Which I do not like). I will fix this in the 
next round.

Right. This has to be fixed.


Did you want me to drop kvm0 and kvm1?

Yes, if level is already configurable using the hypervisor-level
property, I don't see the need for kvm0 and kvm1.

If you make kvm_arch_init_vcpu() actually use those fields, you will end
up implementing what's required to allow migration compatibility to be
kept (the only thing missing is to make the CPU class a child of
DeviceState, and add hypervisor-level=0 to the existing machine-types).
:-)


You mean like
  http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg03402.html
and
  http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg03405.html
already change kvm_arch_init_vcpu().  I did not know that I need to make 
the CPU class a child of DeviceState.
Nor that I needed to add hypervisor-vendor=kvm,hypervisor-level=0 to the 
existing machine-types.  Since without specifying hypervisor-level=0 it 
defaults to 0 and kvm_arch_init_vcpu() will default to setting 
hypervisor-vendor=kvm.

   -Don
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 00/17] Allow changing of Hypervisor CPUIDs.

2012-09-21 Thread Don Slutz
Also known as Paravirtualization CPUIDs.

This is primarily done so that the guest will think it is running
under vmware when hypervisor-vendor=vmware is specified as a
property of a cpu.


This depends on:

http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg01400.html

As far as I know it is #4. It depends on (1) and (2) and (3).

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Changes from v4 to v5:
  Undo kvm_clock2 change.
  Add cpuid_hv_level_set; cpuid_hv_level == 0 is now valid.
  Add cpuid_hv_vendor_set; the null string is now valid.
  Handle kvm and cpuid_hv_level == 0.
  hypervisor-vendor=kvm,hypervisor-level=0 and 
hypervisor-level=0,hypervisor-vendor=kvm
now do the same thing.

Changes from v3 to v4:
  Added CPUID_HV_LEVEL_HYPERV, CPUID_HV_LEVEL_KVM.
  Added CPUID_HV_VENDOR_HYPERV.
  Added hyperv as known hypservisor-vendor.
  Allow hypervisor-level to be 0.

Changes from v2 to v3:
  Clean post to qemu-devel.

Changes from v1 to v2:

1) Added 1/4 from 
http://lists.gnu.org/archive/html/qemu-devel/2012-08/msg05153.html

   Because Fred is changing jobs and so will not be pushing to get
   this in. It needed to be rebased, And I needed it to complete the
   testing of this change.

2) Added 2/4 because of the re-work I needed a way to clear all KVM bits,

3) The rework of v1.  Make it fit into the object model re-work of cpu.c for 
x86.

4) Added 3/4 -- The split out of the code that is not needed for accel=kvm.

Changes from v2 to v3:

Marcelo Tosatti:
  Its one big patch, better split in logically correlated patches
  (with better changelog). This would help reviewers.

So split 3 and 4 into 3 to 17.  More info in change log.
No code change.

Don Slutz (17):
  target-i386: Allow tsc-frequency to be larger then 2.147G
  target-i386: Add missing kvm bits.
  target-i386: Add Hypervisor level.
  target-i386: Add cpu object access routines for Hypervisor level.
  target-i386: Add cpu object access routines for Hypervisor level.
  target-i386: Use Hypervisor level in -machine pc,accel=kvm.
  target-i386: Use Hypervisor level in -machine pc,accel=tcg.
  target-i386: Add Hypervisor vendor.
  target-i386: Add cpu object access routines for Hypervisor vendor.
  target-i386: Use Hypervisor vendor in -machine pc,accel=kvm.
  target-i386: Use Hypervisor vendor in -machine pc,accel=tcg.
  target-i386: Add some known names to Hypervisor vendor.
  target-i386: Add optional Hypervisor leaf extra.
  target-i386: Add cpu object access routines for Hypervisor leaf
extra.
  target-i386: Add setting of Hypervisor leaf extra for known vmare4.
  target-i386: Use Hypervisor leaf extra in -machine pc,accel=kvm.
  target-i386: Use Hypervisor leaf extra in -machine pc,accel=tcg.

 target-i386/cpu.c |  285 -
 target-i386/cpu.h |   34 +++
 target-i386/kvm.c |   33 +-
 3 files changed, 341 insertions(+), 11 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 01/17] target-i386: Allow tsc-frequency to be larger then 2.147G

2012-09-21 Thread Don Slutz
The check using INT_MAX (2147483647) is wrong in this case.

Signed-off-by: Fred Oliveira folive...@cloudswitch.com
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index af50a8f..0313cf5 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1146,7 +1146,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor 
*v, void *opaque,
 {
 X86CPU *cpu = X86_CPU(obj);
 const int64_t min = 0;
-const int64_t max = INT_MAX;
+const int64_t max = INT64_MAX;
 int64_t value;
 
 visit_type_freq(v, value, name, errp);
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 03/17] target-i386: Add Hypervisor level.

2012-09-21 Thread Don Slutz
Also known as Paravirtualization level or maximim cpuid function present in 
this leaf.
This is just the EAX value for 0x4000.

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

QEMU has the value HYPERV_CPUID_MIN defined.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 5265c5a..1899f69 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -777,11 +777,14 @@ typedef struct CPUX86State {
 uint32_t cpuid_ext3_features;
 uint32_t cpuid_apic_id;
 bool cpuid_vendor_override;
+bool cpuid_hv_level_set;
 /* Store the results of Centaur's CPUID instructions */
 uint32_t cpuid_xlevel2;
 uint32_t cpuid_ext4_features;
 /* Flags from CPUID[EAX=7,ECX=0].EBX */
 uint32_t cpuid_7_0_ebx;
+/* Hypervisor CPUIDs */
+uint32_t cpuid_hv_level;
 
 /* MTRRs */
 uint64_t mtrr_fixed[11];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 02/17] target-i386: Add missing kvm bits.

2012-09-21 Thread Don Slutz
Fix duplicate name (kvmclock = kvm_clock2) also.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   12 
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 0313cf5..25ca986 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -87,10 +87,14 @@ static const char *ext3_feature_name[] = {
 };
 
 static const char *kvm_feature_name[] = {
-kvmclock, kvm_nopiodelay, kvm_mmu, kvmclock, kvm_asyncpf, NULL, 
kvm_pv_eoi, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+kvmclock, kvm_nopiodelay, kvm_mmu, kvmclock,
+kvm_asyncpf, kvm_steal_time, kvm_pv_eoi, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+kvm_clock_stable, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
 };
 
 static const char *svm_feature_name[] = {
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 04/17] target-i386: Add cpu object access routines for Hypervisor level.

2012-09-21 Thread Don Slutz
These are modeled after x86_cpuid_get_xlevel and x86_cpuid_set_xlevel.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   29 +
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 25ca986..7b31de9 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1166,6 +1166,32 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor 
*v, void *opaque,
 cpu-env.tsc_khz = value / 1000;
 }
 
+static void x86_cpuid_get_hv_level(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_level, name, errp);
+}
+
+static void x86_cpuid_set_hv_level(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+uint32_t value;
+
+visit_type_uint32(v, value, name, errp);
+if (error_is_set(errp)) {
+return;
+}
+
+if ((value != 0)  (value  0x4000)) {
+value += 0x4000;
+}
+cpu-env.cpuid_hv_level = value;
+cpu-env.cpuid_hv_level_set = true;
+}
+
 #if !defined(CONFIG_USER_ONLY)
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
  const char *name, Error **errp)
@@ -2061,6 +2087,9 @@ static void x86_cpu_initfn(Object *obj)
 object_property_add(obj, enforce, bool,
 x86_cpuid_get_enforce,
 x86_cpuid_set_enforce, NULL, NULL, NULL);
+object_property_add(obj, hypervisor-level, int,
+x86_cpuid_get_hv_level,
+x86_cpuid_set_hv_level, NULL, NULL, NULL);
 #if !defined(CONFIG_USER_ONLY)
 object_property_add(obj, hv_spinlocks, int,
 x86_get_hv_spinlocks,
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 05/17] target-i386: Add cpu object access routines for Hypervisor level.

2012-09-21 Thread Don Slutz
These are modeled after x86_cpuid_get_xlevel and x86_cpuid_set_xlevel.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |8 
 target-i386/cpu.h |2 ++
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 7b31de9..e5deca2 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1193,6 +1193,11 @@ static void x86_cpuid_set_hv_level(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, hypervisor-level, 
errp);
+}
+
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
  const char *name, Error **errp)
 {
@@ -1215,6 +1220,7 @@ static void x86_set_hv_spinlocks(Object *obj, Visitor *v, 
void *opaque,
 return;
 }
 hyperv_set_spinlock_retries(value);
+x86_set_hyperv(obj, errp);
 }
 
 static void x86_get_hv_relaxed(Object *obj, Visitor *v, void *opaque,
@@ -1235,6 +1241,7 @@ static void x86_set_hv_relaxed(Object *obj, Visitor *v, 
void *opaque,
 return;
 }
 hyperv_enable_relaxed_timing(value);
+x86_set_hyperv(obj, errp);
 }
 
 static void x86_get_hv_vapic(Object *obj, Visitor *v, void *opaque,
@@ -1255,6 +1262,7 @@ static void x86_set_hv_vapic(Object *obj, Visitor *v, 
void *opaque,
 return;
 }
 hyperv_enable_vapic_recommended(value);
+x86_set_hyperv(obj, errp);
 }
 #endif
 
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 1899f69..3152a4e 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -488,6 +488,8 @@
 
 #define CPUID_VENDOR_VIA   CentaurHauls
 
+#define CPUID_HV_LEVEL_HYPERV  0x4005
+
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX (1  0) /* enumeration supported */
 
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 06/17] target-i386: Use Hypervisor level in -machine pc,accel=kvm.

2012-09-21 Thread Don Slutz
Also known as Paravirtualization level.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/kvm.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 895d848..8462c75 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -389,12 +389,12 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
 c-function = KVM_CPUID_SIGNATURE;
-if (!hyperv_enabled()) {
+if (!env-cpuid_hv_level_set) {
 memcpy(signature, KVMKVMKVM\0\0\0, 12);
 c-eax = 0;
 } else {
 memcpy(signature, Microsoft Hv, 12);
-c-eax = HYPERV_CPUID_MIN;
+c-eax = env-cpuid_hv_level;
 }
 c-ebx = signature[0];
 c-ecx = signature[1];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 07/17] target-i386: Use Hypervisor level in -machine pc,accel=tcg.

2012-09-21 Thread Don Slutz
Also known as Paravirtualization level.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

QEMU knows this as KVM_CPUID_SIGNATURE (0x4000) in kvm on linux.

This does not provide vendor support in tcg yet.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   27 +++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e5deca2..bf6faed 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1650,6 +1650,21 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 index =  env-cpuid_xlevel;
 }
 }
+} else if (index  0x4000) {
+if (env-cpuid_hv_level_set) {
+uint32_t real_level = env-cpuid_hv_level;
+
+/* Handle Hypervisor CPUIDs */
+if (real_level  0x4000) {
+real_level = 0x4000;
+}
+if (index  real_level) {
+index = real_level;
+}
+} else {
+if (index  env-cpuid_level)
+index = env-cpuid_level;
+}
 } else {
 if (index  env-cpuid_level)
 index = env-cpuid_level;
@@ -1788,6 +1803,18 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 *edx = 0;
 }
 break;
+case 0x4000:
+*eax = env-cpuid_hv_level;
+*ebx = 0;
+*ecx = 0;
+*edx = 0;
+break;
+case 0x4001:
+*eax = env-cpuid_kvm_features;
+*ebx = 0;
+*ecx = 0;
+*edx = 0;
+break;
 case 0x8000:
 *eax = env-cpuid_xlevel;
 *ebx = env-cpuid_vendor1;
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 08/17] target-i386: Add Hypervisor vendor.

2012-09-21 Thread Don Slutz
Also known as Paravirtualization vendor.
This is EBX, ECX, EDX data for 0x4000.

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 3152a4e..11730b2 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -780,6 +780,7 @@ typedef struct CPUX86State {
 uint32_t cpuid_apic_id;
 bool cpuid_vendor_override;
 bool cpuid_hv_level_set;
+bool cpuid_hv_vendor_set;
 /* Store the results of Centaur's CPUID instructions */
 uint32_t cpuid_xlevel2;
 uint32_t cpuid_ext4_features;
@@ -787,6 +788,9 @@ typedef struct CPUX86State {
 uint32_t cpuid_7_0_ebx;
 /* Hypervisor CPUIDs */
 uint32_t cpuid_hv_level;
+uint32_t cpuid_hv_vendor1;
+uint32_t cpuid_hv_vendor2;
+uint32_t cpuid_hv_vendor3;
 
 /* MTRRs */
 uint64_t mtrr_fixed[11];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 09/17] target-i386: Add cpu object access routines for Hypervisor vendor.

2012-09-21 Thread Don Slutz
These are modeled after x86_cpuid_set_vendor and x86_cpuid_get_vendor.
Since kvm's vendor is shorter, the test for correct size is removed and zero 
padding is added.

Set Microsoft's Vendor now that we can.  Value defined in:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx
And matches want is in target-i386/kvm.c

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   45 +
 target-i386/cpu.h |2 ++
 2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index bf6faed..ab65594 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1192,10 +1192,52 @@ static void x86_cpuid_set_hv_level(Object *obj, Visitor 
*v, void *opaque,
 cpu-env.cpuid_hv_level_set = true;
 }
 
+static char *x86_cpuid_get_hv_vendor(Object *obj, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+CPUX86State *env = cpu-env;
+char *value;
+int i;
+
+value = (char *)g_malloc(CPUID_VENDOR_SZ + 1);
+for (i = 0; i  4; i++) {
+value[i + 0] = env-cpuid_hv_vendor1  (8 * i);
+value[i + 4] = env-cpuid_hv_vendor2  (8 * i);
+value[i + 8] = env-cpuid_hv_vendor3  (8 * i);
+}
+value[CPUID_VENDOR_SZ] = '\0';
+
+return value;
+}
+
+static void x86_cpuid_set_hv_vendor(Object *obj, const char *value,
+ Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+CPUX86State *env = cpu-env;
+int i;
+char adj_value[CPUID_VENDOR_SZ + 1];
+
+memset(adj_value, 0, sizeof(adj_value));
+
+pstrcpy(adj_value, sizeof(adj_value), value);
+
+env-cpuid_hv_vendor1 = 0;
+env-cpuid_hv_vendor2 = 0;
+env-cpuid_hv_vendor3 = 0;
+for (i = 0; i  4; i++) {
+env-cpuid_hv_vendor1 |= ((uint8_t)adj_value[i + 0])  (8 * i);
+env-cpuid_hv_vendor2 |= ((uint8_t)adj_value[i + 4])  (8 * i);
+env-cpuid_hv_vendor3 |= ((uint8_t)adj_value[i + 8])  (8 * i);
+}
+env-cpuid_hv_vendor_set = true;
+}
+
 #if !defined(CONFIG_USER_ONLY)
 static void x86_set_hyperv(Object *obj, Error **errp)
 {
 object_property_set_int(obj, CPUID_HV_LEVEL_HYPERV, hypervisor-level, 
errp);
+object_property_set_str(obj, CPUID_HV_VENDOR_HYPERV, hypervisor-vendor, 
errp);
 }
 
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
@@ -2125,6 +2167,9 @@ static void x86_cpu_initfn(Object *obj)
 object_property_add(obj, hypervisor-level, int,
 x86_cpuid_get_hv_level,
 x86_cpuid_set_hv_level, NULL, NULL, NULL);
+object_property_add_str(obj, hypervisor-vendor,
+x86_cpuid_get_hv_vendor,
+x86_cpuid_set_hv_vendor, NULL);
 #if !defined(CONFIG_USER_ONLY)
 object_property_add(obj, hv_spinlocks, int,
 x86_get_hv_spinlocks,
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 11730b2..eb6aa4a 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -488,6 +488,8 @@
 
 #define CPUID_VENDOR_VIA   CentaurHauls
 
+#define CPUID_HV_VENDOR_HYPERV Microsoft Hv
+
 #define CPUID_HV_LEVEL_HYPERV  0x4005
 
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 10/17] target-i386: Use Hypervisor vendor in -machine pc,accel=kvm.

2012-09-21 Thread Don Slutz
Also known as Paravirtualization vendor.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/kvm.c |   12 +++-
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 8462c75..f8a5177 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -389,16 +389,18 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
 c-function = KVM_CPUID_SIGNATURE;
-if (!env-cpuid_hv_level_set) {
+if (!env-cpuid_hv_level_set  !env-cpuid_hv_vendor_set) {
 memcpy(signature, KVMKVMKVM\0\0\0, 12);
 c-eax = 0;
+c-ebx = signature[0];
+c-ecx = signature[1];
+c-edx = signature[2];
 } else {
-memcpy(signature, Microsoft Hv, 12);
 c-eax = env-cpuid_hv_level;
+c-ebx = env-cpuid_hv_vendor1;
+c-ecx = env-cpuid_hv_vendor2;
+c-edx = env-cpuid_hv_vendor3;
 }
-c-ebx = signature[0];
-c-ecx = signature[1];
-c-edx = signature[2];
 
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 11/17] target-i386: Use Hypervisor vendor in -machine pc,accel=tcg.

2012-09-21 Thread Don Slutz
Also known as Paravirtualization vendor.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
This is where the 0 is the same as 0x4001 is defined.

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index ab65594..bfe7b27 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1693,7 +1693,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 }
 }
 } else if (index  0x4000) {
-if (env-cpuid_hv_level_set) {
+if (env-cpuid_hv_level_set || env-cpuid_hv_vendor_set) {
 uint32_t real_level = env-cpuid_hv_level;
 
 /* Handle Hypervisor CPUIDs */
@@ -1847,9 +1847,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 break;
 case 0x4000:
 *eax = env-cpuid_hv_level;
-*ebx = 0;
-*ecx = 0;
-*edx = 0;
+*ebx = env-cpuid_hv_vendor1;
+*ecx = env-cpuid_hv_vendor2;
+*edx = env-cpuid_hv_vendor3;
 break;
 case 0x4001:
 *eax = env-cpuid_kvm_features;
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 12/17] target-i386: Add some known names to Hypervisor vendor.

2012-09-21 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   57 +++-
 target-i386/cpu.h |   19 +
 2 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index bfe7b27..478b671 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1207,6 +1207,24 @@ static char *x86_cpuid_get_hv_vendor(Object *obj, Error 
**errp)
 }
 value[CPUID_VENDOR_SZ] = '\0';
 
+/* Convert known names */
+if (!strcmp(value, CPUID_HV_VENDOR_HYPERV) 
+   env-cpuid_hv_level == CPUID_HV_LEVEL_HYPERV) {
+pstrcpy(value, sizeof(value), hyperv);
+} else if (!strcmp(value, CPUID_HV_VENDOR_VMWARE)) {
+if (env-cpuid_hv_level == CPUID_HV_LEVEL_VMWARE_4) {
+pstrcpy(value, sizeof(value), vmware4);
+} else if (env-cpuid_hv_level == CPUID_HV_LEVEL_VMWARE_3) {
+pstrcpy(value, sizeof(value), vmware3);
+}
+} else if (!strcmp(value, CPUID_HV_VENDOR_XEN) 
+   env-cpuid_hv_level == CPUID_HV_LEVEL_XEN) {
+pstrcpy(value, sizeof(value), xen);
+} else if (!strcmp(value, CPUID_HV_VENDOR_KVM) 
+   (env-cpuid_hv_level == 0 ||
+env-cpuid_hv_level == CPUID_HV_LEVEL_KVM)) {
+pstrcpy(value, sizeof(value), kvm);
+}
 return value;
 }
 
@@ -1220,7 +1238,35 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
 
 memset(adj_value, 0, sizeof(adj_value));
 
-pstrcpy(adj_value, sizeof(adj_value), value);
+/* Convert known names */
+if (!strcmp(value, hyperv)) {
+if (!env-cpuid_hv_level_set) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_HYPERV;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_HYPERV);
+} else if (!strcmp(value, vmware) || !strcmp(value, vmware4)) {
+if (!env-cpuid_hv_level_set) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_VMWARE_4;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_VMWARE);
+} else if (!strcmp(value, vmware3)) {
+if (!env-cpuid_hv_level_set) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_VMWARE_3;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_VMWARE);
+} else if (!strcmp(value, xen)) {
+if (!env-cpuid_hv_level_set) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_XEN;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_XEN);
+} else if (!strcmp(value, kvm)) {
+if (!env-cpuid_hv_level_set) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_KVM;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_KVM);
+} else {
+pstrcpy(adj_value, sizeof(adj_value), value);
+}
 
 env-cpuid_hv_vendor1 = 0;
 env-cpuid_hv_vendor2 = 0;
@@ -1698,7 +1744,14 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 
 /* Handle Hypervisor CPUIDs */
 if (real_level  0x4000) {
-real_level = 0x4000;
+if (env-cpuid_hv_vendor1 == CPUID_HV_VENDOR_KVM_1 
+env-cpuid_hv_vendor2 == CPUID_HV_VENDOR_KVM_2 
+env-cpuid_hv_vendor3 == CPUID_HV_VENDOR_KVM_3 
+real_level == 0) {
+real_level = CPUID_HV_LEVEL_KVM;
+} else {
+real_level = 0x4000;
+}
 }
 if (index  real_level) {
 index = real_level;
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index eb6aa4a..ebb3498 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -490,8 +490,27 @@
 
 #define CPUID_HV_VENDOR_HYPERV Microsoft Hv
 
+#define CPUID_HV_VENDOR_VMWARE_1 0x61774d56 /* VMwa */
+#define CPUID_HV_VENDOR_VMWARE_2 0x4d566572 /* reVM */
+#define CPUID_HV_VENDOR_VMWARE_3 0x65726177 /* ware */
+#define CPUID_HV_VENDOR_VMWARE VMwareVMware
+
+#define CPUID_HV_VENDOR_XEN XenVMMXenVMM
+
+#define CPUID_HV_VENDOR_KVM_1 0x4b4d564b /* KVMK */
+#define CPUID_HV_VENDOR_KVM_2 0x564b4d56 /* VMKV */
+#define CPUID_HV_VENDOR_KVM_3 0x004d /* M\0\0\0 */
+#define CPUID_HV_VENDOR_KVM KVMKVMKVM
+
 #define CPUID_HV_LEVEL_HYPERV  0x4005
 
+#define CPUID_HV_LEVEL_VMWARE_3 0x4002
+#define CPUID_HV_LEVEL_VMWARE_4 0x4010
+
+#define CPUID_HV_LEVEL_XEN  0x4002
+
+#define CPUID_HV_LEVEL_KVM  0x4001
+
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX (1  0) /* enumeration supported */
 
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 13/17] target-i386: Add optional Hypervisor leaf extra.

2012-09-21 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index ebb3498..254ddef 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -812,6 +812,10 @@ typedef struct CPUX86State {
 uint32_t cpuid_hv_vendor1;
 uint32_t cpuid_hv_vendor2;
 uint32_t cpuid_hv_vendor3;
+/* VMware extra data */
+uint32_t cpuid_hv_extra;
+uint32_t cpuid_hv_extra_a;
+uint32_t cpuid_hv_extra_b;
 
 /* MTRRs */
 uint64_t mtrr_fixed[11];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 15/17] target-i386: Add setting of Hypervisor leaf extra for known vmare4.

2012-09-21 Thread Don Slutz
This was taken from:
  http://article.gmane.org/gmane.comp.emulators.kvm.devel/22643

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   32 
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 2423090..e8a21b5 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1135,6 +1135,36 @@ static void x86_cpuid_set_model_id(Object *obj, const 
char *model_id,
 }
 }
 
+static void x86_cpuid_set_vmware_extra(Object *obj)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+if ((cpu-env.tsc_khz != 0) 
+(cpu-env.cpuid_hv_level == CPUID_HV_LEVEL_VMWARE_4) 
+(cpu-env.cpuid_hv_vendor1 == CPUID_HV_VENDOR_VMWARE_1) 
+(cpu-env.cpuid_hv_vendor2 == CPUID_HV_VENDOR_VMWARE_2) 
+(cpu-env.cpuid_hv_vendor3 == CPUID_HV_VENDOR_VMWARE_3)) {
+const uint32_t apic_khz = 100L;
+
+/*
+ * From article.gmane.org/gmane.comp.emulators.kvm.devel/22643
+ *
+ *Leaf 0x4010, Timing Information.
+ *
+ *VMware has defined the first generic leaf to provide timing
+ *information.  This leaf returns the current TSC frequency and
+ *current Bus frequency in kHz.
+ *
+ *# EAX: (Virtual) TSC frequency in kHz.
+ *# EBX: (Virtual) Bus (local apic timer) frequency in kHz.
+ *# ECX, EDX: RESERVED (Per above, reserved fields are set to 
zero).
+ */
+cpu-env.cpuid_hv_extra = 0x4010;
+cpu-env.cpuid_hv_extra_a = (uint32_t)cpu-env.tsc_khz;
+cpu-env.cpuid_hv_extra_b = apic_khz;
+}
+}
+
 static void x86_cpuid_get_tsc_freq(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
 {
@@ -1164,6 +1194,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor 
*v, void *opaque,
 }
 
 cpu-env.tsc_khz = value / 1000;
+x86_cpuid_set_vmware_extra(obj);
 }
 
 static void x86_cpuid_get_hv_level(Object *obj, Visitor *v, void *opaque,
@@ -1277,6 +1308,7 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
 env-cpuid_hv_vendor3 |= ((uint8_t)adj_value[i + 8])  (8 * i);
 }
 env-cpuid_hv_vendor_set = true;
+x86_cpuid_set_vmware_extra(obj);
 }
 
 static void x86_cpuid_get_hv_extra(Object *obj, Visitor *v, void *opaque,
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 17/17] target-i386: Use Hypervisor leaf extra in -machine pc,accel=tcg.

2012-09-21 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   11 +++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e8a21b5..12bd5d4 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1999,6 +1999,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 *ecx = 0;
 *edx = 0;
 break;
+case 0x4002 ... 0x40FF:
+if (index == env-cpuid_hv_extra) {
+*eax = env-cpuid_hv_extra_a;
+*ebx = env-cpuid_hv_extra_b;
+} else {
+*eax = 0;
+*ebx = 0;
+}
+*ecx = 0;
+*edx = 0;
+break;
 case 0x8000:
 *eax = env-cpuid_xlevel;
 *ebx = env-cpuid_vendor1;
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 16/17] target-i386: Use Hypervisor leaf extra in -machine pc,accel=kvm.

2012-09-21 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/kvm.c |   19 +++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index f8a5177..ff82034 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -454,6 +454,25 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c-ebx = signature[0];
 c-ecx = signature[1];
 c-edx = signature[2];
+} else if (env-cpuid_hv_extra != 0) {
+for (i = KVM_CPUID_FEATURES + 1; i = env-cpuid_hv_level; i++) {
+c = cpuid_data.entries[cpuid_i++];
+memset(c, 0, sizeof(*c));
+c-function = i;
+if (i == env-cpuid_hv_extra) {
+c-eax = env-cpuid_hv_extra_a;
+c-ebx = env-cpuid_hv_extra_b;
+}
+}
+
+c = cpuid_data.entries[cpuid_i++];
+memset(c, 0, sizeof(*c));
+c-function = KVM_CPUID_SIGNATURE_NEXT;
+memcpy(signature, KVMKVMKVM\0\0\0, 12);
+c-eax = 0;
+c-ebx = signature[0];
+c-ecx = signature[1];
+c-edx = signature[2];
 }
 
 has_msr_async_pf_en = c-eax  (1  KVM_FEATURE_ASYNC_PF);
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 14/17] target-i386: Add cpu object access routines for Hypervisor leaf extra.

2012-09-21 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   66 +
 1 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 478b671..2423090 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1279,6 +1279,63 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
 env-cpuid_hv_vendor_set = true;
 }
 
+static void x86_cpuid_get_hv_extra(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra, name, errp);
+}
+
+static void x86_cpuid_set_hv_extra(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+uint32_t value;
+
+visit_type_uint32(v, value, name, errp);
+if (error_is_set(errp)) {
+return;
+}
+
+if ((value != 0)  (value  0x4000)) {
+value += 0x4000;
+}
+cpu-env.cpuid_hv_extra = value;
+}
+
+static void x86_cpuid_get_hv_extra_a(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra_a, name, errp);
+}
+
+static void x86_cpuid_set_hv_extra_a(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra_a, name, errp);
+}
+
+static void x86_cpuid_get_hv_extra_b(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra_b, name, errp);
+}
+
+static void x86_cpuid_set_hv_extra_b(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra_b, name, errp);
+}
+
 #if !defined(CONFIG_USER_ONLY)
 static void x86_set_hyperv(Object *obj, Error **errp)
 {
@@ -2223,6 +2280,15 @@ static void x86_cpu_initfn(Object *obj)
 object_property_add_str(obj, hypervisor-vendor,
 x86_cpuid_get_hv_vendor,
 x86_cpuid_set_hv_vendor, NULL);
+object_property_add(obj, hypervisor-extra, int,
+x86_cpuid_get_hv_extra,
+x86_cpuid_set_hv_extra, NULL, NULL, NULL);
+object_property_add(obj, hypervisor-extra-a, int,
+x86_cpuid_get_hv_extra_a,
+x86_cpuid_set_hv_extra_a, NULL, NULL, NULL);
+object_property_add(obj, hypervisor-extra-b, int,
+x86_cpuid_get_hv_extra_b,
+x86_cpuid_set_hv_extra_b, NULL, NULL, NULL);
 #if !defined(CONFIG_USER_ONLY)
 object_property_add(obj, hv_spinlocks, int,
 x86_get_hv_spinlocks,
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/1] target-i386: Fix default Hypervisor level for hypervisor-vendor=kvm.

2012-09-21 Thread Don Slutz

On 09/21/12 17:53, Eduardo Habkost wrote:

On Fri, Sep 21, 2012 at 05:28:27PM -0400, Don Slutz wrote:

On 09/21/12 16:49, Eduardo Habkost wrote:

On Fri, Sep 21, 2012 at 04:26:58PM -0400, Don Slutz wrote:

On 09/21/12 10:18, Eduardo Habkost wrote:

On Thu, Sep 20, 2012 at 04:06:27PM -0400, Don Slutz wrote:

 From http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
EAX should be KVM_CPUID_FEATURES (0x4001) not 0.

Added hypervisor-vendor=kvm0 to get the older CPUID result. kvm1 selects the 
newer one.

Why not just make hypervisor-vendor=kvm control only the hypervisor
vendor string, and support something like kvm-hypervisor-level=0 to
restore the old cpuid_hv_level=0 behavior?

   -cpu host,hypervisor-vendor=kvm,hypervisor-level=0

  Does this.

Good.  :-)


This is similar to the kvmclock case: it would allow us to make
hypervisor-vendor=kvm use saner values as default, but letting old
machine-types to override it for compatibility if required.

Right now since I am using env-cpuid_hv_level == 0 as a flag. This
means that:

   -cpu host,hypervisor-level=0,hypervisor-vendor=kvm

   -cpu host,hypervisor-vendor=kvm,hypervisor-level=0

end up with different CPUID data (Which I do not like). I will fix this in the 
next round.

Right. This has to be fixed.


Did you want me to drop kvm0 and kvm1?

Yes, if level is already configurable using the hypervisor-level
property, I don't see the need for kvm0 and kvm1.

If you make kvm_arch_init_vcpu() actually use those fields, you will end
up implementing what's required to allow migration compatibility to be
kept (the only thing missing is to make the CPU class a child of
DeviceState, and add hypervisor-level=0 to the existing machine-types).
:-)


You mean like
   http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg03402.html
and
   http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg03405.html
already change kvm_arch_init_vcpu().

Yes! Sorry, I hadn't reviewed all of your previous series yet.  :-)


I did not know that I need to
make the CPU class a child of DeviceState.

You don't. But we plan to do that, eventually, so we can put
CPU compatibility properties into machine-types.


Nor that I needed to add hypervisor-vendor=kvm,hypervisor-level=0 to
the existing machine-types.  Since without specifying
hypervisor-level=0 it defaults to 0 and kvm_arch_init_vcpu() will
default to setting hypervisor-vendor=kvm.

What I would like to do is: to change the default to 0x4001 (that's
the correct value), but make the pc-1.1 and older machine-types keep the
hypervisor-level=0 default for compatibility.

(But to be able to do that, we need to first make the CPU class a child
of DeviceState, so that's something to be done later)


Now that ([PATCH v5 00/17] Allow changing...):

http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg03810.html

is released, this contains all that is left of the patch set.  So there 
will not be a v3.  This patch set is withdrawn.


   -Don
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 00/17] Allow changing of Hypervisor CPUIDs.

2012-09-20 Thread Don Slutz
Also known as Paravirtualization CPUIDs.

This is primarily done so that the guest will think it is running
under vmware when hypervisor-vendor=vmware is specified as a
property of a cpu.


This depends on:

http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg01400.html

As far as I know it is #4. It depends on (1) and (2) and (3).

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Changes from v3 to v4:
  Added CPUID_HV_LEVEL_HYPERV, CPUID_HV_LEVEL_KVM.
  Added CPUID_HV_VENDOR_HYPERV.
  Added hyperv as known hypservisor-vendor.
  Allow hypervisor-level to be 0.

Changes from v2 to v3:
  Clean post to qemu-devel.

Changes from v1 to v2:

1) Added 1/4 from 
http://lists.gnu.org/archive/html/qemu-devel/2012-08/msg05153.html

   Because Fred is changing jobs and so will not be pushing to get
   this in. It needed to be rebased, And I needed it to complete the
   testing of this change.

2) Added 2/4 because of the re-work I needed a way to clear all KVM bits,

3) The rework of v1.  Make it fit into the object model re-work of cpu.c for 
x86.

4) Added 3/4 -- The split out of the code that is not needed for accel=kvm.

Changes from v2 to v3:

Marcelo Tosatti:
  Its one big patch, better split in logically correlated patches
  (with better changelog). This would help reviewers.

So split 3 and 4 into 3 to 17.  More info in change log.
No code change.

Don Slutz (17):
  target-i386: Allow tsc-frequency to be larger then 2.147G
  target-i386: Add missing kvm bits.
  target-i386: Add Hypervisor level.
  target-i386: Add cpu object access routines for Hypervisor level.
  target-i386: Add x86_set_hyperv.
  target-i386: Use Hypervisor level in -machine pc,accel=kvm.
  target-i386: Use Hypervisor level in -machine pc,accel=tcg.
  target-i386: Add Hypervisor vendor.
  target-i386: Add cpu object access routines for Hypervisor vendor.
  target-i386: Use Hypervisor vendor in -machine pc,accel=kvm.
  target-i386: Use Hypervisor vendor in -machine pc,accel=tcg.
  target-i386: Add some known names to Hypervisor vendor.
  target-i386: Add optional Hypervisor leaf extra.
  target-i386: Add cpu object access routines for Hypervisor leaf
extra.
  target-i386: Add setting of Hypervisor leaf extra for known vmare4.
  target-i386: Use Hypervisor leaf extra in -machine pc,accel=kvm.
  target-i386: Use Hypervisor leaf extra in -machine pc,accel=tcg.

 target-i386/cpu.c |  277 -
 target-i386/cpu.h |   29 ++
 target-i386/kvm.c |   36 ++-
 3 files changed, 331 insertions(+), 11 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 01/17] target-i386: Allow tsc-frequency to be larger then 2.147G

2012-09-20 Thread Don Slutz
The check using INT_MAX (2147483647) is wrong in this case.

Signed-off-by: Fred Oliveira folive...@cloudswitch.com
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index af50a8f..0313cf5 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1146,7 +1146,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor 
*v, void *opaque,
 {
 X86CPU *cpu = X86_CPU(obj);
 const int64_t min = 0;
-const int64_t max = INT_MAX;
+const int64_t max = INT64_MAX;
 int64_t value;
 
 visit_type_freq(v, value, name, errp);
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 02/17] target-i386: Add missing kvm bits.

2012-09-20 Thread Don Slutz
Fix duplicate name (kvmclock = kvm_clock2) also.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   12 
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 0313cf5..5f9866a 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -87,10 +87,14 @@ static const char *ext3_feature_name[] = {
 };
 
 static const char *kvm_feature_name[] = {
-kvmclock, kvm_nopiodelay, kvm_mmu, kvmclock, kvm_asyncpf, NULL, 
kvm_pv_eoi, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+kvmclock, kvm_nopiodelay, kvm_mmu, kvm_clock2,
+kvm_asyncpf, kvm_steal_time, kvm_pv_eoi, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
+kvm_clock_stable, NULL, NULL, NULL,
+NULL, NULL, NULL, NULL,
 };
 
 static const char *svm_feature_name[] = {
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 03/17] target-i386: Add Hypervisor level.

2012-09-20 Thread Don Slutz
Also known as Paravirtualization level or maximim cpuid function present in 
this leaf.
This is just the EAX value for 0x4000.

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

QEMU has the value HYPERV_CPUID_MIN defined.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 5265c5a..05c0848 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -782,6 +782,8 @@ typedef struct CPUX86State {
 uint32_t cpuid_ext4_features;
 /* Flags from CPUID[EAX=7,ECX=0].EBX */
 uint32_t cpuid_7_0_ebx;
+/* Hypervisor CPUIDs */
+uint32_t cpuid_hv_level;
 
 /* MTRRs */
 uint64_t mtrr_fixed[11];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 05/17] target-i386: Add x86_set_hyperv.

2012-09-20 Thread Don Slutz
This is used to set the cpu object's hypervisor level to the default for 
Microsoft's Hypervisor.

HYPERV_CPUID_MIN (0x4005) is defined in a linux header file.
CPUID_HV_LEVEL_HYPERV (0x4005) is used instead.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   10 ++
 target-i386/cpu.h |2 ++
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 0e4a18d..6aeb194 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1192,6 +1192,13 @@ static void x86_cpuid_set_hv_level(Object *obj, Visitor 
*v, void *opaque,
 }
 
 #if !defined(CONFIG_USER_ONLY)
+static void x86_set_hyperv(Object *obj, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+cpu-env.cpuid_hv_level = CPUID_HV_LEVEL_HYPERV;
+}
+
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
  const char *name, Error **errp)
 {
@@ -1214,6 +1221,7 @@ static void x86_set_hv_spinlocks(Object *obj, Visitor *v, 
void *opaque,
 return;
 }
 hyperv_set_spinlock_retries(value);
+x86_set_hyperv(obj, errp);
 }
 
 static void x86_get_hv_relaxed(Object *obj, Visitor *v, void *opaque,
@@ -1234,6 +1242,7 @@ static void x86_set_hv_relaxed(Object *obj, Visitor *v, 
void *opaque,
 return;
 }
 hyperv_enable_relaxed_timing(value);
+x86_set_hyperv(obj, errp);
 }
 
 static void x86_get_hv_vapic(Object *obj, Visitor *v, void *opaque,
@@ -1254,6 +1263,7 @@ static void x86_set_hv_vapic(Object *obj, Visitor *v, 
void *opaque,
 return;
 }
 hyperv_enable_vapic_recommended(value);
+x86_set_hyperv(obj, errp);
 }
 #endif
 
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 05c0848..7fc7906 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -488,6 +488,8 @@
 
 #define CPUID_VENDOR_VIA   CentaurHauls
 
+#define CPUID_HV_LEVEL_HYPERV  0x4005
+
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX (1  0) /* enumeration supported */
 
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 04/17] target-i386: Add cpu object access routines for Hypervisor level.

2012-09-20 Thread Don Slutz
These are modeled after x86_cpuid_get_xlevel and x86_cpuid_set_xlevel.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   28 
 1 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 5f9866a..0e4a18d 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1166,6 +1166,31 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor 
*v, void *opaque,
 cpu-env.tsc_khz = value / 1000;
 }
 
+static void x86_cpuid_get_hv_level(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_level, name, errp);
+}
+
+static void x86_cpuid_set_hv_level(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+uint32_t value;
+
+visit_type_uint32(v, value, name, errp);
+if (error_is_set(errp)) {
+return;
+}
+
+if ((value != 0)  (value  0x4000)) {
+value += 0x4000;
+}
+cpu-env.cpuid_hv_level = value;
+}
+
 #if !defined(CONFIG_USER_ONLY)
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
  const char *name, Error **errp)
@@ -2061,6 +2086,9 @@ static void x86_cpu_initfn(Object *obj)
 object_property_add(obj, enforce, bool,
 x86_cpuid_get_enforce,
 x86_cpuid_set_enforce, NULL, NULL, NULL);
+object_property_add(obj, hypervisor-level, int,
+x86_cpuid_get_hv_level,
+x86_cpuid_set_hv_level, NULL, NULL, NULL);
 #if !defined(CONFIG_USER_ONLY)
 object_property_add(obj, hv_spinlocks, int,
 x86_get_hv_spinlocks,
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 07/17] target-i386: Use Hypervisor level in -machine pc,accel=tcg.

2012-09-20 Thread Don Slutz
Also known as Paravirtualization level.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

QEMU knows this as KVM_CPUID_SIGNATURE (0x4000) in kvm on linux.

This does not provide vendor support in tcg yet.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   22 ++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 6aeb194..b7532b7 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1651,6 +1651,16 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 index =  env-cpuid_xlevel;
 }
 }
+} else if (index  0x4000) {
+if (env-cpuid_hv_level  0) {
+/* Handle Hypervisor CPUIDs */
+if (index  env-cpuid_hv_level) {
+index = env-cpuid_hv_level;
+}
+} else {
+if (index  env-cpuid_level)
+index = env-cpuid_level;
+}
 } else {
 if (index  env-cpuid_level)
 index = env-cpuid_level;
@@ -1789,6 +1799,18 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 *edx = 0;
 }
 break;
+case 0x4000:
+*eax = env-cpuid_hv_level;
+*ebx = 0;
+*ecx = 0;
+*edx = 0;
+break;
+case 0x4001:
+*eax = env-cpuid_kvm_features;
+*ebx = 0;
+*ecx = 0;
+*edx = 0;
+break;
 case 0x8000:
 *eax = env-cpuid_xlevel;
 *ebx = env-cpuid_vendor1;
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 06/17] target-i386: Use Hypervisor level in -machine pc,accel=kvm.

2012-09-20 Thread Don Slutz
Also known as Paravirtualization level.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/kvm.c |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 895d848..bf27793 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -389,12 +389,12 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
 c-function = KVM_CPUID_SIGNATURE;
-if (!hyperv_enabled()) {
+if (env-cpuid_hv_level == 0) {
 memcpy(signature, KVMKVMKVM\0\0\0, 12);
 c-eax = 0;
 } else {
 memcpy(signature, Microsoft Hv, 12);
-c-eax = HYPERV_CPUID_MIN;
+c-eax = env-cpuid_hv_level;
 }
 c-ebx = signature[0];
 c-ecx = signature[1];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 09/17] target-i386: Add cpu object access routines for Hypervisor vendor.

2012-09-20 Thread Don Slutz
These are modeled after x86_cpuid_set_vendor and x86_cpuid_get_vendor.
Since kvm's vendor is shorter, the test for correct size is removed and zero 
padding is added.

Set Microsoft's Vendor now that we can.  Value defined in:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx
And matches want is in target-i386/kvm.c

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   44 
 target-i386/cpu.h |2 ++
 2 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index b7532b7..d8f7e22 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1191,12 +1191,53 @@ static void x86_cpuid_set_hv_level(Object *obj, Visitor 
*v, void *opaque,
 cpu-env.cpuid_hv_level = value;
 }
 
+static char *x86_cpuid_get_hv_vendor(Object *obj, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+CPUX86State *env = cpu-env;
+char *value;
+int i;
+
+value = (char *)g_malloc(CPUID_VENDOR_SZ + 1);
+for (i = 0; i  4; i++) {
+value[i + 0] = env-cpuid_hv_vendor1  (8 * i);
+value[i + 4] = env-cpuid_hv_vendor2  (8 * i);
+value[i + 8] = env-cpuid_hv_vendor3  (8 * i);
+}
+value[CPUID_VENDOR_SZ] = '\0';
+
+return value;
+}
+
+static void x86_cpuid_set_hv_vendor(Object *obj, const char *value,
+ Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+CPUX86State *env = cpu-env;
+int i;
+char adj_value[CPUID_VENDOR_SZ + 1];
+
+memset(adj_value, 0, sizeof(adj_value));
+
+pstrcpy(adj_value, sizeof(adj_value), value);
+
+env-cpuid_hv_vendor1 = 0;
+env-cpuid_hv_vendor2 = 0;
+env-cpuid_hv_vendor3 = 0;
+for (i = 0; i  4; i++) {
+env-cpuid_hv_vendor1 |= ((uint8_t)adj_value[i + 0])  (8 * i);
+env-cpuid_hv_vendor2 |= ((uint8_t)adj_value[i + 4])  (8 * i);
+env-cpuid_hv_vendor3 |= ((uint8_t)adj_value[i + 8])  (8 * i);
+}
+}
+
 #if !defined(CONFIG_USER_ONLY)
 static void x86_set_hyperv(Object *obj, Error **errp)
 {
 X86CPU *cpu = X86_CPU(obj);
 
 cpu-env.cpuid_hv_level = CPUID_HV_LEVEL_HYPERV;
+x86_cpuid_set_hv_vendor(obj, CPUID_HV_VENDOR_HYPERV, errp);
 }
 
 static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
@@ -2121,6 +2162,9 @@ static void x86_cpu_initfn(Object *obj)
 object_property_add(obj, hypervisor-level, int,
 x86_cpuid_get_hv_level,
 x86_cpuid_set_hv_level, NULL, NULL, NULL);
+object_property_add_str(obj, hypervisor-vendor,
+x86_cpuid_get_hv_vendor,
+x86_cpuid_set_hv_vendor, NULL);
 #if !defined(CONFIG_USER_ONLY)
 object_property_add(obj, hv_spinlocks, int,
 x86_get_hv_spinlocks,
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index e13a44a..91ddf76 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -488,6 +488,8 @@
 
 #define CPUID_VENDOR_VIA   CentaurHauls
 
+#define CPUID_HV_VENDOR_HYPERV Microsoft Hv
+
 #define CPUID_HV_LEVEL_HYPERV  0x4005
 
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 10/17] target-i386: Use Hypervisor vendor in -machine pc,accel=kvm.

2012-09-20 Thread Don Slutz
Also known as Paravirtualization vendor.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/kvm.c |   15 ++-
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index bf27793..dde9214 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -389,16 +389,21 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
 c-function = KVM_CPUID_SIGNATURE;
-if (env-cpuid_hv_level == 0) {
+if (env-cpuid_hv_level == 0 
+env-cpuid_hv_vendor1 == 0 
+env-cpuid_hv_vendor2 == 0 
+env-cpuid_hv_vendor3 == 0) {
 memcpy(signature, KVMKVMKVM\0\0\0, 12);
 c-eax = 0;
+c-ebx = signature[0];
+c-ecx = signature[1];
+c-edx = signature[2];
 } else {
-memcpy(signature, Microsoft Hv, 12);
 c-eax = env-cpuid_hv_level;
+c-ebx = env-cpuid_hv_vendor1;
+c-ecx = env-cpuid_hv_vendor2;
+c-edx = env-cpuid_hv_vendor3;
 }
-c-ebx = signature[0];
-c-ecx = signature[1];
-c-edx = signature[2];
 
 c = cpuid_data.entries[cpuid_i++];
 memset(c, 0, sizeof(*c));
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 13/17] target-i386: Add optional Hypervisor leaf extra.

2012-09-20 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 6dafaeb..e158c54 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -807,6 +807,10 @@ typedef struct CPUX86State {
 uint32_t cpuid_hv_vendor1;
 uint32_t cpuid_hv_vendor2;
 uint32_t cpuid_hv_vendor3;
+/* VMware extra data */
+uint32_t cpuid_hv_extra;
+uint32_t cpuid_hv_extra_a;
+uint32_t cpuid_hv_extra_b;
 
 /* MTRRs */
 uint64_t mtrr_fixed[11];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 14/17] target-i386: Add cpu object access routines for Hypervisor leaf extra.

2012-09-20 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   66 +
 1 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 904b08f..7e9c43b 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1273,6 +1273,63 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
 }
 }
 
+static void x86_cpuid_get_hv_extra(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra, name, errp);
+}
+
+static void x86_cpuid_set_hv_extra(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+uint32_t value;
+
+visit_type_uint32(v, value, name, errp);
+if (error_is_set(errp)) {
+return;
+}
+
+if ((value != 0)  (value  0x4000)) {
+value += 0x4000;
+}
+cpu-env.cpuid_hv_extra = value;
+}
+
+static void x86_cpuid_get_hv_extra_a(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra_a, name, errp);
+}
+
+static void x86_cpuid_set_hv_extra_a(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra_a, name, errp);
+}
+
+static void x86_cpuid_get_hv_extra_b(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra_b, name, errp);
+}
+
+static void x86_cpuid_set_hv_extra_b(Object *obj, Visitor *v, void *opaque,
+const char *name, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+visit_type_uint32(v, cpu-env.cpuid_hv_extra_b, name, errp);
+}
+
 #if !defined(CONFIG_USER_ONLY)
 static void x86_set_hyperv(Object *obj, Error **errp)
 {
@@ -2215,6 +2272,15 @@ static void x86_cpu_initfn(Object *obj)
 object_property_add_str(obj, hypervisor-vendor,
 x86_cpuid_get_hv_vendor,
 x86_cpuid_set_hv_vendor, NULL);
+object_property_add(obj, hypervisor-extra, int,
+x86_cpuid_get_hv_extra,
+x86_cpuid_set_hv_extra, NULL, NULL, NULL);
+object_property_add(obj, hypervisor-extra-a, int,
+x86_cpuid_get_hv_extra_a,
+x86_cpuid_set_hv_extra_a, NULL, NULL, NULL);
+object_property_add(obj, hypervisor-extra-b, int,
+x86_cpuid_get_hv_extra_b,
+x86_cpuid_set_hv_extra_b, NULL, NULL, NULL);
 #if !defined(CONFIG_USER_ONLY)
 object_property_add(obj, hv_spinlocks, int,
 x86_get_hv_spinlocks,
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 15/17] target-i386: Add setting of Hypervisor leaf extra for known vmare4.

2012-09-20 Thread Don Slutz
This was taken from:
  http://article.gmane.org/gmane.comp.emulators.kvm.devel/22643

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   32 
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 7e9c43b..4594693 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1135,6 +1135,36 @@ static void x86_cpuid_set_model_id(Object *obj, const 
char *model_id,
 }
 }
 
+static void x86_cpuid_set_vmware_extra(Object *obj)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+if ((cpu-env.tsc_khz != 0) 
+(cpu-env.cpuid_hv_level == CPUID_HV_LEVEL_VMARE_4) 
+(cpu-env.cpuid_hv_vendor1 == CPUID_HV_VENDOR_VMWARE_1) 
+(cpu-env.cpuid_hv_vendor2 == CPUID_HV_VENDOR_VMWARE_2) 
+(cpu-env.cpuid_hv_vendor3 == CPUID_HV_VENDOR_VMWARE_3)) {
+const uint32_t apic_khz = 100L;
+
+/*
+ * From article.gmane.org/gmane.comp.emulators.kvm.devel/22643
+ *
+ *Leaf 0x4010, Timing Information.
+ *
+ *VMware has defined the first generic leaf to provide timing
+ *information.  This leaf returns the current TSC frequency and
+ *current Bus frequency in kHz.
+ *
+ *# EAX: (Virtual) TSC frequency in kHz.
+ *# EBX: (Virtual) Bus (local apic timer) frequency in kHz.
+ *# ECX, EDX: RESERVED (Per above, reserved fields are set to 
zero).
+ */
+cpu-env.cpuid_hv_extra = 0x4010;
+cpu-env.cpuid_hv_extra_a = (uint32_t)cpu-env.tsc_khz;
+cpu-env.cpuid_hv_extra_b = apic_khz;
+}
+}
+
 static void x86_cpuid_get_tsc_freq(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
 {
@@ -1164,6 +1194,7 @@ static void x86_cpuid_set_tsc_freq(Object *obj, Visitor 
*v, void *opaque,
 }
 
 cpu-env.tsc_khz = value / 1000;
+x86_cpuid_set_vmware_extra(obj);
 }
 
 static void x86_cpuid_get_hv_level(Object *obj, Visitor *v, void *opaque,
@@ -1271,6 +1302,7 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
 env-cpuid_hv_vendor2 |= ((uint8_t)adj_value[i + 4])  (8 * i);
 env-cpuid_hv_vendor3 |= ((uint8_t)adj_value[i + 8])  (8 * i);
 }
+x86_cpuid_set_vmware_extra(obj);
 }
 
 static void x86_cpuid_get_hv_extra(Object *obj, Visitor *v, void *opaque,
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 16/17] target-i386: Use Hypervisor leaf extra in -machine pc,accel=kvm.

2012-09-20 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/kvm.c |   19 +++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index dde9214..bd7753f 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -457,6 +457,25 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c-ebx = signature[0];
 c-ecx = signature[1];
 c-edx = signature[2];
+} else if (env-cpuid_hv_level  0) {
+for (i = KVM_CPUID_FEATURES + 1; i = env-cpuid_hv_level; i++) {
+c = cpuid_data.entries[cpuid_i++];
+memset(c, 0, sizeof(*c));
+c-function = i;
+if (i == env-cpuid_hv_extra) {
+c-eax = env-cpuid_hv_extra_a;
+c-ebx = env-cpuid_hv_extra_b;
+}
+}
+
+c = cpuid_data.entries[cpuid_i++];
+memset(c, 0, sizeof(*c));
+c-function = KVM_CPUID_SIGNATURE_NEXT;
+memcpy(signature, KVMKVMKVM\0\0\0, 12);
+c-eax = 0;
+c-ebx = signature[0];
+c-ecx = signature[1];
+c-edx = signature[2];
 }
 
 has_msr_async_pf_en = c-eax  (1  KVM_FEATURE_ASYNC_PF);
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 12/17] target-i386: Add some known names to Hypervisor vendor.

2012-09-20 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   44 +++-
 target-i386/cpu.h |   14 ++
 2 files changed, 57 insertions(+), 1 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 5cf7146..904b08f 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1206,6 +1206,23 @@ static char *x86_cpuid_get_hv_vendor(Object *obj, Error 
**errp)
 }
 value[CPUID_VENDOR_SZ] = '\0';
 
+/* Convert known names */
+if (!strcmp(value, CPUID_HV_VENDOR_HYPERV) 
+   env-cpuid_hv_level == CPUID_HV_LEVEL_HYPERV) {
+pstrcpy(value, sizeof(value), hyperv);
+} else if (!strcmp(value, CPUID_HV_VENDOR_VMWARE)) {
+if (env-cpuid_hv_level == CPUID_HV_LEVEL_VMARE_4) {
+pstrcpy(value, sizeof(value), vmware4);
+} else if (env-cpuid_hv_level == CPUID_HV_LEVEL_VMARE_3) {
+pstrcpy(value, sizeof(value), vmware3);
+}
+} else if (!strcmp(value, CPUID_HV_VENDOR_XEN) 
+   env-cpuid_hv_level == CPUID_HV_LEVEL_XEN) {
+pstrcpy(value, sizeof(value), xen);
+} else if (!strcmp(value, CPUID_HV_VENDOR_KVM) 
+   env-cpuid_hv_level == 0) {
+pstrcpy(value, sizeof(value), kvm);
+}
 return value;
 }
 
@@ -1219,7 +1236,32 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
 
 memset(adj_value, 0, sizeof(adj_value));
 
-pstrcpy(adj_value, sizeof(adj_value), value);
+/* Convert known names */
+if (!strcmp(value, hyperv)) {
+if (env-cpuid_hv_level == 0) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_HYPERV;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_HYPERV);
+} else if (!strcmp(value, vmware) || !strcmp(value, vmware4)) {
+if (env-cpuid_hv_level == 0) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_VMARE_4;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_VMWARE);
+} else if (!strcmp(value, vmware3)) {
+if (env-cpuid_hv_level == 0) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_VMARE_3;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_VMWARE);
+} else if (!strcmp(value, xen)) {
+if (env-cpuid_hv_level == 0) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_XEN;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_XEN);
+} else if (!strcmp(value, kvm)) {
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_KVM);
+} else {
+pstrcpy(adj_value, sizeof(adj_value), value);
+}
 
 env-cpuid_hv_vendor1 = 0;
 env-cpuid_hv_vendor2 = 0;
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index e3e176b..6dafaeb 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -490,10 +490,24 @@
 
 #define CPUID_HV_VENDOR_HYPERV Microsoft Hv
 
+#define CPUID_HV_VENDOR_VMWARE_1 0x61774d56 /* VMwa */
+#define CPUID_HV_VENDOR_VMWARE_2 0x4d566572 /* reVM */
+#define CPUID_HV_VENDOR_VMWARE_3 0x65726177 /* ware */
+#define CPUID_HV_VENDOR_VMWARE VMwareVMware
+
+#define CPUID_HV_VENDOR_XEN XenVMMXenVMM
+
+#define CPUID_HV_VENDOR_KVM KVMKVMKVM
+
 #define CPUID_HV_LEVEL_HYPERV  0x4005
 
 #define CPUID_HV_LEVEL_KVM  0x4001
 
+#define CPUID_HV_LEVEL_XEN  0x4002
+
+#define CPUID_HV_LEVEL_VMARE_3 0x4002
+#define CPUID_HV_LEVEL_VMARE_4 0x4010
+
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX (1  0) /* enumeration supported */
 
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 11/17] target-i386: Use Hypervisor vendor in -machine pc,accel=tcg.

2012-09-20 Thread Don Slutz
Also known as Paravirtualization vendor.

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
This is where the 0 is the same as 0x4001 is defined.

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   20 ++--
 target-i386/cpu.h |2 ++
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index d8f7e22..5cf7146 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1693,10 +1693,18 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 }
 }
 } else if (index  0x4000) {
-if (env-cpuid_hv_level  0) {
+if (env-cpuid_hv_level != 0 ||
+env-cpuid_hv_vendor1 != 0 ||
+env-cpuid_hv_vendor2 != 0 ||
+env-cpuid_hv_vendor3 != 0) {
+uint32_t real_level = env-cpuid_hv_level;
+
+/* Handle KVM's old level. */
+if (real_level == 0)
+real_level = CPUID_HV_LEVEL_KVM;
 /* Handle Hypervisor CPUIDs */
-if (index  env-cpuid_hv_level) {
-index = env-cpuid_hv_level;
+if (index  real_level) {
+index = real_level;
 }
 } else {
 if (index  env-cpuid_level)
@@ -1842,9 +1850,9 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 break;
 case 0x4000:
 *eax = env-cpuid_hv_level;
-*ebx = 0;
-*ecx = 0;
-*edx = 0;
+*ebx = env-cpuid_hv_vendor1;
+*ecx = env-cpuid_hv_vendor2;
+*edx = env-cpuid_hv_vendor3;
 break;
 case 0x4001:
 *eax = env-cpuid_kvm_features;
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 91ddf76..e3e176b 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -492,6 +492,8 @@
 
 #define CPUID_HV_LEVEL_HYPERV  0x4005
 
+#define CPUID_HV_LEVEL_KVM  0x4001
+
 #define CPUID_MWAIT_IBE (1  1) /* Interrupts can exit capability */
 #define CPUID_MWAIT_EMX (1  0) /* enumeration supported */
 
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 17/17] target-i386: Use Hypervisor leaf extra in -machine pc,accel=tcg.

2012-09-20 Thread Don Slutz
Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   11 +++
 1 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 4594693..72a8442 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1991,6 +1991,17 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, 
uint32_t count,
 *ecx = 0;
 *edx = 0;
 break;
+case 0x4002 ... 0x40FF:
+if (index == env-cpuid_hv_extra) {
+*eax = env-cpuid_hv_extra_a;
+*ebx = env-cpuid_hv_extra_b;
+} else {
+*eax = 0;
+*ebx = 0;
+}
+*ecx = 0;
+*edx = 0;
+break;
 case 0x8000:
 *eax = env-cpuid_xlevel;
 *ebx = env-cpuid_vendor1;
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 08/17] target-i386: Add Hypervisor vendor.

2012-09-20 Thread Don Slutz
Also known as Paravirtualization vendor.
This is EBX, ECX, EDX data for 0x4000.

QEMU knows this is KVM_CPUID_SIGNATURE (0x4000).

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 7fc7906..e13a44a 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -786,6 +786,9 @@ typedef struct CPUX86State {
 uint32_t cpuid_7_0_ebx;
 /* Hypervisor CPUIDs */
 uint32_t cpuid_hv_level;
+uint32_t cpuid_hv_vendor1;
+uint32_t cpuid_hv_vendor2;
+uint32_t cpuid_hv_vendor3;
 
 /* MTRRs */
 uint64_t mtrr_fixed[11];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 0/1] target-i386: Fix default Hypervisor level for kvm

2012-09-20 Thread Don Slutz
Looking at http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
The new value for EAX is 0x4001.

This depends on 
http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg02497.html

As far as I known it is #5.  It depends on (1), (2), (3) and (4).

Based on cpu-queue[1] branch.
(From http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg02639.html)

[1] https://github.com/ehabkost/qemu/commits/cpu-queue
My branch is now based on Andreas's qom-cpu branch from
https://github.com/afaerber/qemu-cpu/commits/qom-cpu

Changes form v1 to v2:
  Drop patch #1 -- possible live-migrating issues.

  Added kvm1 and kvm0 to handle the 2 cases.  

Don Slutz (1):
  target-i386: Fix default Hypervisor level for hypervisor-vendor=kvm.

 target-i386/cpu.c |   17 +
 1 files changed, 13 insertions(+), 4 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/1] target-i386: Fix default Hypervisor level for hypervisor-vendor=kvm.

2012-09-20 Thread Don Slutz
From http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
EAX should be KVM_CPUID_FEATURES (0x4001) not 0.

Added hypervisor-vendor=kvm0 to get the older CPUID result. kvm1 selects the 
newer one.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.c |   17 +
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 72a8442..e51b2b1 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1250,9 +1250,12 @@ static char *x86_cpuid_get_hv_vendor(Object *obj, Error 
**errp)
 } else if (!strcmp(value, CPUID_HV_VENDOR_XEN) 
env-cpuid_hv_level == CPUID_HV_LEVEL_XEN) {
 pstrcpy(value, sizeof(value), xen);
-} else if (!strcmp(value, CPUID_HV_VENDOR_KVM) 
-   env-cpuid_hv_level == 0) {
-pstrcpy(value, sizeof(value), kvm);
+} else if (!strcmp(value, CPUID_HV_VENDOR_KVM)) {
+if (env-cpuid_hv_level == CPUID_HV_LEVEL_KVM) {
+pstrcpy(value, sizeof(value), kvm1);
+} else if (env-cpuid_hv_level == 0) {
+pstrcpy(value, sizeof(value), kvm0);
+}
 }
 return value;
 }
@@ -1288,7 +1291,13 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
 env-cpuid_hv_level = CPUID_HV_LEVEL_XEN;
 }
 pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_XEN);
-} else if (!strcmp(value, kvm)) {
+} else if (!strcmp(value, kvm) || !strcmp(value, kvm1)) {
+if (env-cpuid_hv_level == 0) {
+env-cpuid_hv_level = CPUID_HV_LEVEL_KVM;
+}
+pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_KVM);
+} else if (!strcmp(value, kvm0)) {
+env-cpuid_hv_level = 0;
 pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_KVM);
 } else {
 pstrcpy(adj_value, sizeof(adj_value), value);
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] target-i386: Fix default Hypervisor level for hypervisor-vendor=kvm.

2012-09-19 Thread Don Slutz

On 09/19/12 09:20, Eduardo Habkost wrote:

On Tue, Sep 18, 2012 at 03:32:04PM -0400, Don Slutz wrote:

On 09/18/12 13:00, Eduardo Habkost wrote:

On Tue, Sep 18, 2012 at 10:49:53AM -0400, Don Slutz wrote:

 From http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
EAX should be KVM_CPUID_FEATURES (0x4001) not 0.

If kvm is not configured, the additional option of hypervisor-level=1
(or hypervisor-level=0x4001) needs to be specified to get this.
---
  target-i386/cpu.c |   12 +++-
  1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 6e43eff..d73b0a8 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1248,7 +1248,12 @@ static char *x86_cpuid_get_hv_vendor(Object *obj, Error 
**errp)
 env-cpuid_hv_level == CPUID_HV_LEVEL_XEN) {
  pstrcpy(value, sizeof(value), xen);
  } else if (!strcmp(value, CPUID_HV_VENDOR_KVM) 
-   env-cpuid_hv_level == 0) {
+#if defined(CONFIG_KVM)
+   env-cpuid_hv_level == KVM_CPUID_FEATURES
+#else
+   env-cpuid_hv_level == 0
+#endif
+   ) {
  pstrcpy(value, sizeof(value), kvm);
  }
  return value;
@@ -1281,6 +1286,11 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
  }
  pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_XEN);
  } else if (!strcmp(value, kvm)) {
+#if defined(CONFIG_KVM)
+if (env-cpuid_hv_level == 0) {
+env-cpuid_hv_level = KVM_CPUID_FEATURES;
+}
+#endif

If CPUID[0x4000].EAX set to 0 is documented as equivalent to having
it set to 0x4001 (KVM_CPUID_FEATURES), why the confusing checks for
CONFIG_KVM? Why not always set it to KVM_CPUID_FEATURES?


At line 36 of the file:

#if defined(CONFIG_KVM)
#include linux/kvm_para.h
#endif

So without the check you get compile failures (i386-linux-user).


Right. We can't include linux/kvm_para.h on a non-Linux build host, but
on the other hand I don't see any reason to not have
cpuid_hv_level=0x4001 on builds without CONFIG_KVM too.

If we want to allow fake KVM CPUID leaves on non-CONFIG_KVM builds like
the code above does, QEMU needs its own constant for
KVM_CPUID_FEATURES/0x4001, so it doesn't depend on the Linux header.


Will do a V2 with a local define.

I have no issue with removing the check(s) for 0.  Currently
hypervisor-level=0 will not force the old values; I can make a change
so that works.
  -Don Slutz

  -Don Slutz
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [Qemu-devel] [PATCH v3 05/17] target-i386: Add x86_set_hyperv.

2012-09-19 Thread Don Slutz

On 09/19/12 15:32, Eduardo Habkost wrote:

On Mon, Sep 17, 2012 at 10:00:55AM -0400, Don Slutz wrote:

This is used to set the cpu object's hypervisor level to the default for 
Microsoft's Hypervisor.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
  target-i386/cpu.c |   10 ++
  1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 0e4a18d..4120393 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1192,6 +1192,13 @@ static void x86_cpuid_set_hv_level(Object *obj, Visitor 
*v, void *opaque,
  }

  #if !defined(CONFIG_USER_ONLY)
+static void x86_set_hyperv(Object *obj, Error **errp)
+{
+X86CPU *cpu = X86_CPU(obj);
+
+cpu-env.cpuid_hv_level = HYPERV_CPUID_MIN;

HYPERV_CPUID_MIN is defined on linux-headers/asm-x86/hyperv.h, that is
included only if build host is linux-x86 and CONFIG_KVM is set.


Will fix.  I see 3 options:

1) Use the numbers like 0x4005

2) Use QEMU defines like:
 #define CPUID_HV_LEVEL_HYPERV  0x4005

3) Use condtional define:
 #ifndef HYPERV_CPUID_MIN
 #define CPUID_HV_LEVEL_HYPERV  0x4005
 #else
 #define CPUID_HV_LEVEL_HYPERV  HYPERV_CPUID_MIN
 #endif

I lean to #2 of #3 and both over #1.  This is because if in the future 
if HYPERV_CPUID_MIN ever changes then a patch to QEMU needs to be done 
and considered before that change can be seen by a guest.  Note: since 
hypervisor-level=0x4006 can be specified, this might be enough to do 
some testing.


Please advise.


+}
+
  static void x86_get_hv_spinlocks(Object *obj, Visitor *v, void *opaque,
   const char *name, Error **errp)
  {
@@ -1214,6 +1221,7 @@ static void x86_set_hv_spinlocks(Object *obj, Visitor *v, 
void *opaque,
  return;
  }
  hyperv_set_spinlock_retries(value);
+x86_set_hyperv(obj, errp);
  }

  static void x86_get_hv_relaxed(Object *obj, Visitor *v, void *opaque,
@@ -1234,6 +1242,7 @@ static void x86_set_hv_relaxed(Object *obj, Visitor *v, 
void *opaque,
  return;
  }
  hyperv_enable_relaxed_timing(value);
+x86_set_hyperv(obj, errp);
  }

  static void x86_get_hv_vapic(Object *obj, Visitor *v, void *opaque,
@@ -1254,6 +1263,7 @@ static void x86_set_hv_vapic(Object *obj, Visitor *v, 
void *opaque,
  return;
  }
  hyperv_enable_vapic_recommended(value);
+x86_set_hyperv(obj, errp);
  }
  #endif

--
1.7.1



   -Don Slutz
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/2] target-i386: Fix default Hypervisor level for kvm

2012-09-18 Thread Don Slutz
Looking at http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
The new value for EAX is 0x4001.

This depends on 
http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg02497.html

As far as I known it is #5.  It depends on (1), (2), (3) and (4).

Based on cpu-queue[1] branch.
(From http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg02639.html)

[1] https://github.com/ehabkost/qemu/commits/cpu-queue
My branch is now based on Andreas's qom-cpu branch from
https://github.com/afaerber/qemu-cpu/commits/qom-cpu


Don Slutz (2):
  target-i386: Fix default Hypervisor level for accel=kvm.
  target-i386: Fix default Hypervisor level for hypervisor-vendor=kvm.

 target-i386/cpu.c |   12 +++-
 target-i386/kvm.c |2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] target-i386: Fix default Hypervisor level for accel=kvm.

2012-09-18 Thread Don Slutz
From http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
EAX should be KVM_CPUID_FEATURES (0x4001) not 0.
---
 target-i386/kvm.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 761a9b1..0c9f5dd 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -392,7 +392,7 @@ int kvm_arch_init_vcpu(CPUX86State *env)
 c-function = KVM_CPUID_SIGNATURE;
 if (env-cpuid_hv_level == 0) {
 memcpy(signature, KVMKVMKVM\0\0\0, 12);
-c-eax = 0;
+c-eax = KVM_CPUID_FEATURES;
 c-ebx = signature[0];
 c-ecx = signature[1];
 c-edx = signature[2];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] target-i386: Fix default Hypervisor level for hypervisor-vendor=kvm.

2012-09-18 Thread Don Slutz
From http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
EAX should be KVM_CPUID_FEATURES (0x4001) not 0.

If kvm is not configured, the additional option of hypervisor-level=1
(or hypervisor-level=0x4001) needs to be specified to get this.
---
 target-i386/cpu.c |   12 +++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 6e43eff..d73b0a8 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1248,7 +1248,12 @@ static char *x86_cpuid_get_hv_vendor(Object *obj, Error 
**errp)
env-cpuid_hv_level == CPUID_HV_LEVEL_XEN) {
 pstrcpy(value, sizeof(value), xen);
 } else if (!strcmp(value, CPUID_HV_VENDOR_KVM) 
-   env-cpuid_hv_level == 0) {
+#if defined(CONFIG_KVM)
+   env-cpuid_hv_level == KVM_CPUID_FEATURES
+#else
+   env-cpuid_hv_level == 0
+#endif
+   ) {
 pstrcpy(value, sizeof(value), kvm);
 }
 return value;
@@ -1281,6 +1286,11 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
 }
 pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_XEN);
 } else if (!strcmp(value, kvm)) {
+#if defined(CONFIG_KVM)
+if (env-cpuid_hv_level == 0) {
+env-cpuid_hv_level = KVM_CPUID_FEATURES;
+}
+#endif
 pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_KVM);
 } else {
 pstrcpy(adj_value, sizeof(adj_value), value);
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] target-i386: Fix default Hypervisor level for hypervisor-vendor=kvm.

2012-09-18 Thread Don Slutz

On 09/18/12 13:00, Eduardo Habkost wrote:

On Tue, Sep 18, 2012 at 10:49:53AM -0400, Don Slutz wrote:

 From http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
EAX should be KVM_CPUID_FEATURES (0x4001) not 0.

If kvm is not configured, the additional option of hypervisor-level=1
(or hypervisor-level=0x4001) needs to be specified to get this.
---
  target-i386/cpu.c |   12 +++-
  1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 6e43eff..d73b0a8 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -1248,7 +1248,12 @@ static char *x86_cpuid_get_hv_vendor(Object *obj, Error 
**errp)
 env-cpuid_hv_level == CPUID_HV_LEVEL_XEN) {
  pstrcpy(value, sizeof(value), xen);
  } else if (!strcmp(value, CPUID_HV_VENDOR_KVM) 
-   env-cpuid_hv_level == 0) {
+#if defined(CONFIG_KVM)
+   env-cpuid_hv_level == KVM_CPUID_FEATURES
+#else
+   env-cpuid_hv_level == 0
+#endif
+   ) {
  pstrcpy(value, sizeof(value), kvm);
  }
  return value;
@@ -1281,6 +1286,11 @@ static void x86_cpuid_set_hv_vendor(Object *obj, const 
char *value,
  }
  pstrcpy(adj_value, sizeof(adj_value), CPUID_HV_VENDOR_XEN);
  } else if (!strcmp(value, kvm)) {
+#if defined(CONFIG_KVM)
+if (env-cpuid_hv_level == 0) {
+env-cpuid_hv_level = KVM_CPUID_FEATURES;
+}
+#endif

If CPUID[0x4000].EAX set to 0 is documented as equivalent to having
it set to 0x4001 (KVM_CPUID_FEATURES), why the confusing checks for
CONFIG_KVM? Why not always set it to KVM_CPUID_FEATURES?


At line 36 of the file:

#if defined(CONFIG_KVM)
#include linux/kvm_para.h
#endif

So without the check you get compile failures (i386-linux-user).

I have no issue with removing the check(s) for 0.  Currently 
hypervisor-level=0 will not force the old values; I can make a change so 
that works.

 -Don Slutz
--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/2] target-i386: Fix default Hypervisor level for accel=kvm.

2012-09-18 Thread Don Slutz

On 09/18/12 11:05, Eduardo Habkost wrote:

On Tue, Sep 18, 2012 at 10:49:52AM -0400, Don Slutz wrote:

 From http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html
EAX should be KVM_CPUID_FEATURES (0x4001) not 0.
---
  target-i386/kvm.c |2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 761a9b1..0c9f5dd 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -392,7 +392,7 @@ int kvm_arch_init_vcpu(CPUX86State *env)
  c-function = KVM_CPUID_SIGNATURE;
  if (env-cpuid_hv_level == 0) {
  memcpy(signature, KVMKVMKVM\0\0\0, 12);
-c-eax = 0;
+c-eax = KVM_CPUID_FEATURES;

This makes the CPUID bits to suddenly change, when live-migrating to a
newer QEMU version.

Strictly speaking, this is never supposed to happen, but... on both
cases the meaning of the bits are the same (0 is documented as
equivalent to KVM_CPUID_FEATURES) and probably the guest will look at
them only once on boot. Do we really want to add migration-compatibility
code for this?

My vote would be no; because this should be ok and the tests that I know 
of are all at boot time.  I will look into adding 
migration-compatibility.  I also do not have any direct need for this 
change, it just looked like the right thing to do.

  c-ebx = signature[0];
  c-ecx = signature[1];
  c-edx = signature[2];
--
1.7.1



--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 00/17] Allow changing of Hypervisor CPUIDs.

2012-09-17 Thread Don Slutz
Also known as Paravirtualization CPUIDs.

This is primarily done so that the guest will think it is running
under vmware when hypervisor-vendor=vmware is specified as a
property of a cpu.


This depends on:

http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg01400.html

As far as I know it is #4. It depends on (1) and (2) and (3).

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Changes from v1 to v2:

1) Added 1/4 from 
http://lists.gnu.org/archive/html/qemu-devel/2012-08/msg05153.html

   Because Fred is changing jobs and so will not be pushing to get
   this in. It needed to be rebased, And I needed it to complete the
   testing of this change.

2) Added 2/4 because of the re-work I needed a way to clear all KVM bits,

3) The rework of v1.  Make it fit into the object model re-work of cpu.c for 
x86.

4) Added 3/4 -- The split out of the code that is not needed for accel=kvm.

Changes from v2 to v3:

Marcelo Tosatti:
  Its one big patch, better split in logically correlated patches
  (with better changelog). This would help reviewers.

So split 3 and 4 into 3 to 17.  More info in change log.
No code change.

Don Slutz (17):
  target-i386: Allow tsc-frequency to be larger then 2.147G
  target-i386: Add missing kvm bits.
  target-i386: Add Hypervisor level.
  target-i386: Add cpu object access routines for Hypervisor level.
  target-i386: Add x86_set_hyperv.
  target-i386: Use Hypervisor level in -machine pc,accel=kvm.
  target-i386: Use Hypervisor level in -machine pc,accel=tcg.
  target-i386: Add Hypervisor vendor.
  target-i386: Add cpu object access routines for Hypervisor vendor.
  target-i386: Use Hypervisor vendor in -machine pc,accel=kvm.
  target-i386: Use Hypervisor vendor in -machine pc,accel=tcg.
  target-i386: Add some known names to Hypervisor vendor.
  target-i386: Add optional Hypervisor leaf extra.
  target-i386: Add cpu object access routines for Hypervisor leaf
extra.
  target-i386: Add setting of Hypervisor leaf extra for known vmare4.
  target-i386: Use Hypervisor leaf extra in -machine pc,accel=kvm.
  target-i386: Use Hypervisor leaf extra in -machine pc,accel=tcg.

 target-i386/cpu.c |  261 -
 target-i386/cpu.h |   21 +
 target-i386/kvm.c |   33 ++--
 3 files changed, 304 insertions(+), 11 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 00/17] *** SUBJECT HERE ***

2012-09-17 Thread Don Slutz
*** BLURB HERE ***

Don Slutz (17):
  target-i386: Allow tsc-frequency to be larger then 2.147G
  target-i386: Add missing kvm bits.
  target-i386: Add Hypervisor level.
  target-i386: Add cpu object access routines for Hypervisor level.
  target-i386: Add x86_set_hyperv.
  target-i386: Use Hypervisor level in -machine pc,accel=kvm.
  target-i386: Use Hypervisor level in -machine pc,accel=tcg.
  target-i386: Add Hypervisor vendor.
  target-i386: Add cpu object access routines for Hypervisor vendor.
  target-i386: Use Hypervisor vendor in -machine pc,accel=kvm.
  target-i386: Use Hypervisor vendor in -machine pc,accel=tcg.
  target-i386: Add some known names to Hypervisor vendor.
  target-i386: Add optional Hypervisor leaf extra.
  target-i386: Add cpu object access routines for Hypervisor leaf
extra.
  target-i386: Add setting of Hypervisor leaf extra for known vmare4.
  target-i386: Use Hypervisor leaf extra in -machine pc,accel=kvm.
  target-i386: Use Hypervisor leaf extra in -machine pc,accel=tcg.

 target-i386/cpu.c |  261 -
 target-i386/cpu.h |   21 +
 target-i386/kvm.c |   33 ++--
 3 files changed, 304 insertions(+), 11 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 00/17] Allow changing of Hypervisor CPUIDs.

2012-09-17 Thread Don Slutz
Also known as Paravirtualization CPUIDs.

This is primarily done so that the guest will think it is running
under vmware when hypervisor-vendor=vmware is specified as a
property of a cpu.


This depends on:

http://lists.gnu.org/archive/html/qemu-devel/2012-09/msg01400.html

As far as I know it is #4. It depends on (1) and (2) and (3).

This change is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html
Also:
  http://lkml.indiana.edu/hypermail/linux/kernel/1205.0/00100.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

Changes from v1 to v2:

1) Added 1/4 from 
http://lists.gnu.org/archive/html/qemu-devel/2012-08/msg05153.html

   Because Fred is changing jobs and so will not be pushing to get
   this in. It needed to be rebased, And I needed it to complete the
   testing of this change.

2) Added 2/4 because of the re-work I needed a way to clear all KVM bits,

3) The rework of v1.  Make it fit into the object model re-work of cpu.c for 
x86.

4) Added 3/4 -- The split out of the code that is not needed for accel=kvm.

Changes from v2 to v3:

Marcelo Tosatti:
  Its one big patch, better split in logically correlated patches
  (with better changelog). This would help reviewers.

So split 3 and 4 into 3 to 17.  More info in change log.
No code change.

Don Slutz (17):
  target-i386: Allow tsc-frequency to be larger then 2.147G
  target-i386: Add missing kvm bits.
  target-i386: Add Hypervisor level.
  target-i386: Add cpu object access routines for Hypervisor level.
  target-i386: Add x86_set_hyperv.
  target-i386: Use Hypervisor level in -machine pc,accel=kvm.
  target-i386: Use Hypervisor level in -machine pc,accel=tcg.
  target-i386: Add Hypervisor vendor.
  target-i386: Add cpu object access routines for Hypervisor vendor.
  target-i386: Use Hypervisor vendor in -machine pc,accel=kvm.
  target-i386: Use Hypervisor vendor in -machine pc,accel=tcg.
  target-i386: Add some known names to Hypervisor vendor.
  target-i386: Add optional Hypervisor leaf extra.
  target-i386: Add cpu object access routines for Hypervisor leaf
extra.
  target-i386: Add setting of Hypervisor leaf extra for known vmare4.
  target-i386: Use Hypervisor leaf extra in -machine pc,accel=kvm.
  target-i386: Use Hypervisor leaf extra in -machine pc,accel=tcg.

 target-i386/cpu.c |  261 -
 target-i386/cpu.h |   21 +
 target-i386/kvm.c |   33 ++--
 3 files changed, 304 insertions(+), 11 deletions(-)

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 03/17] target-i386: Add Hypervisor level.

2012-09-17 Thread Don Slutz
This is just the EAX value.

This is based on:

Microsoft Hypervisor CPUID Leaves:
  
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428%28v=vs.85%29.aspx

Linux kernel change starts with:
  http://fixunix.com/kernel/538707-use-cpuid-communicate-hypervisor.html

VMware documention on CPUIDs (Mechanisms to determine if software is
running in a VMware virtual machine):
  
http://kb.vmware.com/selfservice/microsites/search.do?language=en_UScmd=displayKCexternalId=1009458

QEMU has the value HYPERV_CPUID_MIN defined.

Signed-off-by: Don Slutz d...@cloudswitch.com
---
 target-i386/cpu.h |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 5265c5a..05c0848 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -782,6 +782,8 @@ typedef struct CPUX86State {
 uint32_t cpuid_ext4_features;
 /* Flags from CPUID[EAX=7,ECX=0].EBX */
 uint32_t cpuid_7_0_ebx;
+/* Hypervisor CPUIDs */
+uint32_t cpuid_hv_level;
 
 /* MTRRs */
 uint64_t mtrr_fixed[11];
-- 
1.7.1

--
To unsubscribe from this list: send the line unsubscribe kvm in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  1   2   >