qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH uq/master 0/5] Hyper-V improvements and migratability
@ 2014-01-24 16:17 Paolo Bonzini
  2014-01-24 16:17 ` [Qemu-devel] [PATCH 1/5] KVM: fix coexistence of KVM and Hyper-V leaves Paolo Bonzini
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Paolo Bonzini @ 2014-01-24 16:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: mtosatti, vrozenfe, kvm

The first patch fixes the KVM leaves at 0x40000100.  Before, there
is no leaf at 0x40000101 (and the data of the highest Intel leaf
is returned, e.g. 0xd on a Sandy Bridge).  After this patch there is
one.

The second patch is extracted from Vadim's migration patches, which
are patches 3-5.

Review of the first two patches is particularly welcome.

Paolo Bonzini (2):
  KVM: fix coexistence of KVM and Hyper-V leaves
  kvm: make availability of Hyper-V enlightenments dependent on
    KVM_CAP_HYPERV

Vadim Rozenfeld (3):
  kvm: make hyperv hypercall and guest os id MSRs migratable.
  kvm: make hyperv vapic assist page migratable
  kvm: add support for hyper-v timers

 linux-headers/asm-x86/hyperv.h |   3 ++
 linux-headers/linux/kvm.h      |   1 +
 target-i386/cpu-qom.h          |   1 +
 target-i386/cpu.c              |   1 +
 target-i386/cpu.h              |   4 ++
 target-i386/kvm.c              | 109 +++++++++++++++++++++++++++++------------
 target-i386/machine.c          |  67 +++++++++++++++++++++++++
 7 files changed, 155 insertions(+), 31 deletions(-)

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 1/5] KVM: fix coexistence of KVM and Hyper-V leaves
  2014-01-24 16:17 [Qemu-devel] [PATCH uq/master 0/5] Hyper-V improvements and migratability Paolo Bonzini
@ 2014-01-24 16:17 ` Paolo Bonzini
  2014-01-24 19:08   ` Marcelo Tosatti
  2014-01-24 16:17 ` [Qemu-devel] [PATCH 2/5] kvm: make availability of Hyper-V enlightenments dependent on KVM_CAP_HYPERV Paolo Bonzini
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Paolo Bonzini @ 2014-01-24 16:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: mtosatti, vrozenfe, kvm

kvm_arch_init_vcpu's initialization of the KVM leaves at 0x40000100
is broken, because KVM_CPUID_FEATURES is left at 0x40000001.  Move
it to 0x40000101 if Hyper-V is enabled.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target-i386/kvm.c | 47 +++++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 0a21c30..5738911 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -455,6 +455,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
     uint32_t unused;
     struct kvm_cpuid_entry2 *c;
     uint32_t signature[3];
+    int kvm_base = KVM_CPUID_SIGNATURE;
     int r;
 
     memset(&cpuid_data, 0, sizeof(cpuid_data));
@@ -462,26 +463,22 @@ int kvm_arch_init_vcpu(CPUState *cs)
     cpuid_i = 0;
 
     /* Paravirtualization CPUIDs */
-    c = &cpuid_data.entries[cpuid_i++];
-    c->function = KVM_CPUID_SIGNATURE;
-    if (!hyperv_enabled(cpu)) {
-        memcpy(signature, "KVMKVMKVM\0\0\0", 12);
-        c->eax = 0;
-    } else {
+    if (hyperv_enabled(cpu)) {
+        c = &cpuid_data.entries[cpuid_i++];
+        c->function = HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
         memcpy(signature, "Microsoft Hv", 12);
         c->eax = HYPERV_CPUID_MIN;
-    }
-    c->ebx = signature[0];
-    c->ecx = signature[1];
-    c->edx = signature[2];
-
-    c = &cpuid_data.entries[cpuid_i++];
-    c->function = KVM_CPUID_FEATURES;
-    c->eax = env->features[FEAT_KVM];
+        c->ebx = signature[0];
+        c->ecx = signature[1];
+        c->edx = signature[2];
 
-    if (hyperv_enabled(cpu)) {
+        c = &cpuid_data.entries[cpuid_i++];
+        c->function = HYPERV_CPUID_INTERFACE;
         memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12);
         c->eax = signature[0];
+        c->ebx = 0;
+        c->ecx = 0;
+        c->edx = 0;
 
         c = &cpuid_data.entries[cpuid_i++];
         c->function = HYPERV_CPUID_VERSION;
@@ -513,15 +510,21 @@ int kvm_arch_init_vcpu(CPUState *cs)
         c->eax = 0x40;
         c->ebx = 0x40;
 
-        c = &cpuid_data.entries[cpuid_i++];
-        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];
+        kvm_base = KVM_CPUID_SIGNATURE_NEXT;
     }
 
+    memcpy(signature, "KVMKVMKVM\0\0\0", 12);
+    c = &cpuid_data.entries[cpuid_i++];
+    c->function = KVM_CPUID_SIGNATURE | kvm_base;
+    c->eax = 0;
+    c->ebx = signature[0];
+    c->ecx = signature[1];
+    c->edx = signature[2];
+
+    c = &cpuid_data.entries[cpuid_i++];
+    c->function = KVM_CPUID_FEATURES | kvm_base;
+    c->eax = env->features[FEAT_KVM];
+
     has_msr_async_pf_en = c->eax & (1 << KVM_FEATURE_ASYNC_PF);
 
     has_msr_pv_eoi_en = c->eax & (1 << KVM_FEATURE_PV_EOI);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 2/5] kvm: make availability of Hyper-V enlightenments dependent on KVM_CAP_HYPERV
  2014-01-24 16:17 [Qemu-devel] [PATCH uq/master 0/5] Hyper-V improvements and migratability Paolo Bonzini
  2014-01-24 16:17 ` [Qemu-devel] [PATCH 1/5] KVM: fix coexistence of KVM and Hyper-V leaves Paolo Bonzini
@ 2014-01-24 16:17 ` Paolo Bonzini
  2014-01-24 16:17 ` [Qemu-devel] [PATCH 3/5] kvm: make hyperv hypercall and guest os id MSRs migratable Paolo Bonzini
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2014-01-24 16:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: mtosatti, vrozenfe, kvm

The MS docs specify HV_X64_MSR_HYPERCALL as a mandatory interface,
thus we must provide the MSRs even if the user only specified
features that, like relaxed timing, in principle don't require them.
And the MSRs are only there if the hypervisor has KVM_CAP_HYPERV.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target-i386/kvm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 5738911..08c47bb 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -72,6 +72,7 @@ static bool has_msr_misc_enable;
 static bool has_msr_bndcfgs;
 static bool has_msr_kvm_steal_time;
 static int lm_capable_kernel;
+static bool has_msr_hv_hypercall;
 
 static bool has_msr_architectural_pmu;
 static uint32_t num_architectural_pmu_counters;
@@ -437,8 +438,10 @@ static bool hyperv_hypercall_available(X86CPU *cpu)
 
 static bool hyperv_enabled(X86CPU *cpu)
 {
-    return hyperv_hypercall_available(cpu) ||
-           cpu->hyperv_relaxed_timing;
+    CPUState *cs = CPU(cpu);
+    return kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0 &&
+           (hyperv_hypercall_available(cpu) ||
+            cpu->hyperv_relaxed_timing);
 }
 
 #define KVM_MAX_CPUID_ENTRIES  100
@@ -511,6 +514,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
         c->ebx = 0x40;
 
         kvm_base = KVM_CPUID_SIGNATURE_NEXT;
+        has_msr_hv_hypercall = true;
     }
 
     memcpy(signature, "KVMKVMKVM\0\0\0", 12);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 3/5] kvm: make hyperv hypercall and guest os id MSRs migratable.
  2014-01-24 16:17 [Qemu-devel] [PATCH uq/master 0/5] Hyper-V improvements and migratability Paolo Bonzini
  2014-01-24 16:17 ` [Qemu-devel] [PATCH 1/5] KVM: fix coexistence of KVM and Hyper-V leaves Paolo Bonzini
  2014-01-24 16:17 ` [Qemu-devel] [PATCH 2/5] kvm: make availability of Hyper-V enlightenments dependent on KVM_CAP_HYPERV Paolo Bonzini
@ 2014-01-24 16:17 ` Paolo Bonzini
  2014-01-24 16:17 ` [Qemu-devel] [PATCH 4/5] kvm: make hyperv vapic assist page migratable Paolo Bonzini
  2014-01-24 16:17 ` [Qemu-devel] [PATCH 5/5] kvm: add support for hyper-v timers Paolo Bonzini
  4 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2014-01-24 16:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: mtosatti, vrozenfe, kvm

From: Vadim Rozenfeld <vrozenfe@redhat.com>

Signed-off-by: Vadim Rozenfeld <vrozenfe@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target-i386/cpu.h     |  2 ++
 target-i386/kvm.c     | 18 +++++++++++++++---
 target-i386/machine.c | 23 +++++++++++++++++++++++
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 1fcbc82..3dba5ef 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -862,6 +862,8 @@ typedef struct CPUX86State {
     uint64_t msr_fixed_counters[MAX_FIXED_COUNTERS];
     uint64_t msr_gp_counters[MAX_GP_COUNTERS];
     uint64_t msr_gp_evtsel[MAX_GP_COUNTERS];
+    uint64_t msr_hv_hypercall;
+    uint64_t msr_hv_guest_os_id;
 
     /* exception/interrupt handling */
     int error_code;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 08c47bb..8f2854a 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1227,9 +1227,11 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
             kvm_msr_entry_set(&msrs[n++], MSR_CORE_PERF_GLOBAL_CTRL,
                               env->msr_global_ctrl);
         }
-        if (hyperv_hypercall_available(cpu)) {
-            kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_GUEST_OS_ID, 0);
-            kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_HYPERCALL, 0);
+        if (has_msr_hv_hypercall) {
+            kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_GUEST_OS_ID,
+                              env->msr_hv_guest_os_id);
+            kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_HYPERCALL,
+                              env->msr_hv_hypercall);
         }
         if (cpu->hyperv_vapic) {
             kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE, 0);
@@ -1518,6 +1520,10 @@ static int kvm_get_msrs(X86CPU *cpu)
         }
     }
 
+    if (has_msr_hv_hypercall) {
+        msrs[n++].index = HV_X64_MSR_HYPERCALL;
+        msrs[n++].index = HV_X64_MSR_GUEST_OS_ID;
+    }
     msr_data.info.nmsrs = n;
     ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, &msr_data);
     if (ret < 0) {
@@ -1625,6 +1631,12 @@ static int kvm_get_msrs(X86CPU *cpu)
         case MSR_P6_EVNTSEL0 ... MSR_P6_EVNTSEL0 + MAX_GP_COUNTERS - 1:
             env->msr_gp_evtsel[index - MSR_P6_EVNTSEL0] = msrs[i].data;
             break;
+        case HV_X64_MSR_HYPERCALL:
+            env->msr_hv_hypercall = msrs[i].data;
+            break;
+        case HV_X64_MSR_GUEST_OS_ID:
+            env->msr_hv_guest_os_id = msrs[i].data;
+            break;
         }
     }
 
diff --git a/target-i386/machine.c b/target-i386/machine.c
index 2de1964..96fd045 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -554,6 +554,26 @@ static const VMStateDescription vmstate_mpx = {
     }
 };
 
+static bool hyperv_hypercall_enable_needed(void *opaque)
+{
+    X86CPU *cpu = opaque;
+    CPUX86State *env = &cpu->env;
+
+    return env->msr_hv_hypercall != 0 || env->msr_hv_guest_os_id != 0;
+}
+
+static const VMStateDescription vmstate_msr_hypercall_hypercall = {
+    .name = "cpu/msr_hyperv_hypercall",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT64(env.msr_hv_hypercall, X86CPU),
+        VMSTATE_UINT64(env.msr_hv_guest_os_id, X86CPU),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 const VMStateDescription vmstate_x86_cpu = {
     .name = "cpu",
     .version_id = 12,
@@ -688,6 +708,9 @@ const VMStateDescription vmstate_x86_cpu = {
         } , {
             .vmsd = &vmstate_mpx,
             .needed = mpx_needed,
+        }, {
+            .vmsd = &vmstate_msr_hypercall_hypercall,
+            .needed = hyperv_hypercall_enable_needed,
         } , {
             /* empty */
         }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 4/5] kvm: make hyperv vapic assist page migratable
  2014-01-24 16:17 [Qemu-devel] [PATCH uq/master 0/5] Hyper-V improvements and migratability Paolo Bonzini
                   ` (2 preceding siblings ...)
  2014-01-24 16:17 ` [Qemu-devel] [PATCH 3/5] kvm: make hyperv hypercall and guest os id MSRs migratable Paolo Bonzini
@ 2014-01-24 16:17 ` Paolo Bonzini
  2014-01-24 16:17 ` [Qemu-devel] [PATCH 5/5] kvm: add support for hyper-v timers Paolo Bonzini
  4 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2014-01-24 16:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: mtosatti, vrozenfe, kvm

From: Vadim Rozenfeld <vrozenfe@redhat.com>

Signed-off-by: Vadim Rozenfeld <vrozenfe@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target-i386/cpu.h     |  1 +
 target-i386/kvm.c     | 16 +++++++++++++---
 target-i386/machine.c | 22 ++++++++++++++++++++++
 3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 3dba5ef..45bd554 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -864,6 +864,7 @@ typedef struct CPUX86State {
     uint64_t msr_gp_evtsel[MAX_GP_COUNTERS];
     uint64_t msr_hv_hypercall;
     uint64_t msr_hv_guest_os_id;
+    uint64_t msr_hv_vapic;
 
     /* exception/interrupt handling */
     int error_code;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 8f2854a..ddd437f 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -73,6 +73,7 @@ static bool has_msr_bndcfgs;
 static bool has_msr_kvm_steal_time;
 static int lm_capable_kernel;
 static bool has_msr_hv_hypercall;
+static bool has_msr_hv_vapic;
 
 static bool has_msr_architectural_pmu;
 static uint32_t num_architectural_pmu_counters;
@@ -496,6 +497,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
         if (cpu->hyperv_vapic) {
             c->eax |= HV_X64_MSR_HYPERCALL_AVAILABLE;
             c->eax |= HV_X64_MSR_APIC_ACCESS_AVAILABLE;
+            has_msr_hv_vapic = true;
         }
 
         c = &cpuid_data.entries[cpuid_i++];
@@ -503,7 +505,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
         if (cpu->hyperv_relaxed_timing) {
             c->eax |= HV_X64_RELAXED_TIMING_RECOMMENDED;
         }
-        if (cpu->hyperv_vapic) {
+        if (has_msr_hv_vapic) {
             c->eax |= HV_X64_APIC_ACCESS_RECOMMENDED;
         }
         c->ebx = cpu->hyperv_spinlock_attempts;
@@ -1233,8 +1235,9 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
             kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_HYPERCALL,
                               env->msr_hv_hypercall);
         }
-        if (cpu->hyperv_vapic) {
-            kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE, 0);
+        if (has_msr_hv_vapic) {
+            kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE,
+                              env->msr_hv_vapic);
         }
 
         /* Note: MSR_IA32_FEATURE_CONTROL is written separately, see
@@ -1524,6 +1527,10 @@ static int kvm_get_msrs(X86CPU *cpu)
         msrs[n++].index = HV_X64_MSR_HYPERCALL;
         msrs[n++].index = HV_X64_MSR_GUEST_OS_ID;
     }
+    if (has_msr_hv_vapic) {
+        msrs[n++].index = HV_X64_MSR_APIC_ASSIST_PAGE;
+    }
+
     msr_data.info.nmsrs = n;
     ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, &msr_data);
     if (ret < 0) {
@@ -1637,6 +1644,9 @@ static int kvm_get_msrs(X86CPU *cpu)
         case HV_X64_MSR_GUEST_OS_ID:
             env->msr_hv_guest_os_id = msrs[i].data;
             break;
+        case HV_X64_MSR_APIC_ASSIST_PAGE:
+            env->msr_hv_vapic = msrs[i].data;
+            break;
         }
     }
 
diff --git a/target-i386/machine.c b/target-i386/machine.c
index 96fd045..e72e270 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -574,6 +574,25 @@ static const VMStateDescription vmstate_msr_hypercall_hypercall = {
     }
 };
 
+static bool hyperv_vapic_enable_needed(void *opaque)
+{
+    X86CPU *cpu = opaque;
+    CPUX86State *env = &cpu->env;
+
+    return env->msr_hv_vapic != 0;
+}
+
+static const VMStateDescription vmstate_msr_hyperv_vapic = {
+    .name = "cpu/msr_hyperv_vapic",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT64(env.msr_hv_vapic, X86CPU),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 const VMStateDescription vmstate_x86_cpu = {
     .name = "cpu",
     .version_id = 12,
@@ -711,6 +730,9 @@ const VMStateDescription vmstate_x86_cpu = {
         }, {
             .vmsd = &vmstate_msr_hypercall_hypercall,
             .needed = hyperv_hypercall_enable_needed,
+        }, {
+            .vmsd = &vmstate_msr_hyperv_vapic,
+            .needed = hyperv_vapic_enable_needed,
         } , {
             /* empty */
         }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 5/5] kvm: add support for hyper-v timers
  2014-01-24 16:17 [Qemu-devel] [PATCH uq/master 0/5] Hyper-V improvements and migratability Paolo Bonzini
                   ` (3 preceding siblings ...)
  2014-01-24 16:17 ` [Qemu-devel] [PATCH 4/5] kvm: make hyperv vapic assist page migratable Paolo Bonzini
@ 2014-01-24 16:17 ` Paolo Bonzini
  4 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2014-01-24 16:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: mtosatti, vrozenfe, kvm

From: Vadim Rozenfeld <vrozenfe@redhat.com>

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

This code is generic for activating reference time counter or virtual reference time stamp counter

Signed-off-by: Vadim Rozenfeld <vrozenfe@redhat.com>
Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 linux-headers/asm-x86/hyperv.h |  3 +++
 linux-headers/linux/kvm.h      |  1 +
 target-i386/cpu-qom.h          |  1 +
 target-i386/cpu.c              |  1 +
 target-i386/cpu.h              |  1 +
 target-i386/kvm.c              | 20 +++++++++++++++++++-
 target-i386/machine.c          | 22 ++++++++++++++++++++++
 7 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/linux-headers/asm-x86/hyperv.h b/linux-headers/asm-x86/hyperv.h
index b8f1c01..3b400ee 100644
--- a/linux-headers/asm-x86/hyperv.h
+++ b/linux-headers/asm-x86/hyperv.h
@@ -149,6 +149,9 @@
 /* MSR used to read the per-partition time reference counter */
 #define HV_X64_MSR_TIME_REF_COUNT		0x40000020
 
+/* A partition's reference time stamp counter (TSC) page */
+#define HV_X64_MSR_REFERENCE_TSC		0x40000021
+
 /* MSR used to retrieve the TSC frequency */
 #define HV_X64_MSR_TSC_FREQUENCY		0x40000022
 
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index 5a49671..999fb13 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -674,6 +674,7 @@ struct kvm_ppc_smmu_info {
 #define KVM_CAP_ARM_EL1_32BIT 93
 #define KVM_CAP_SPAPR_MULTITCE 94
 #define KVM_CAP_EXT_EMUL_CPUID 95
+#define KVM_CAP_HYPERV_TIME 96
 
 #ifdef KVM_CAP_IRQ_ROUTING
 
diff --git a/target-i386/cpu-qom.h b/target-i386/cpu-qom.h
index d1751a4..722f11a 100644
--- a/target-i386/cpu-qom.h
+++ b/target-i386/cpu-qom.h
@@ -69,6 +69,7 @@ typedef struct X86CPU {
     bool hyperv_vapic;
     bool hyperv_relaxed_timing;
     int hyperv_spinlock_attempts;
+    bool hyperv_time;
     bool check_cpuid;
     bool enforce_cpuid;
 
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index 2e0be01..1f30efd 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -2702,6 +2702,7 @@ static Property x86_cpu_properties[] = {
     { .name  = "hv-spinlocks", .info  = &qdev_prop_spinlocks },
     DEFINE_PROP_BOOL("hv-relaxed", X86CPU, hyperv_relaxed_timing, false),
     DEFINE_PROP_BOOL("hv-vapic", X86CPU, hyperv_vapic, false),
+    DEFINE_PROP_BOOL("hv-time", X86CPU, hyperv_time, false),
     DEFINE_PROP_BOOL("check", X86CPU, check_cpuid, false),
     DEFINE_PROP_BOOL("enforce", X86CPU, enforce_cpuid, false),
     DEFINE_PROP_END_OF_LIST()
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index 45bd554..1b94f0f 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -865,6 +865,7 @@ typedef struct CPUX86State {
     uint64_t msr_hv_hypercall;
     uint64_t msr_hv_guest_os_id;
     uint64_t msr_hv_vapic;
+    uint64_t msr_hv_tsc;
 
     /* exception/interrupt handling */
     int error_code;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index ddd437f..e555040 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -74,6 +74,7 @@ static bool has_msr_kvm_steal_time;
 static int lm_capable_kernel;
 static bool has_msr_hv_hypercall;
 static bool has_msr_hv_vapic;
+static bool has_msr_hv_tsc;
 
 static bool has_msr_architectural_pmu;
 static uint32_t num_architectural_pmu_counters;
@@ -442,6 +443,7 @@ static bool hyperv_enabled(X86CPU *cpu)
     CPUState *cs = CPU(cpu);
     return kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV) > 0 &&
            (hyperv_hypercall_available(cpu) ||
+            cpu->hyperv_time  ||
             cpu->hyperv_relaxed_timing);
 }
 
@@ -499,7 +501,13 @@ int kvm_arch_init_vcpu(CPUState *cs)
             c->eax |= HV_X64_MSR_APIC_ACCESS_AVAILABLE;
             has_msr_hv_vapic = true;
         }
-
+        if (cpu->hyperv_time &&
+            kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_TIME) > 0) {
+            c->eax |= HV_X64_MSR_HYPERCALL_AVAILABLE;
+            c->eax |= HV_X64_MSR_TIME_REF_COUNT_AVAILABLE;
+            c->eax |= 0x200;
+            has_msr_hv_tsc = true;
+        }
         c = &cpuid_data.entries[cpuid_i++];
         c->function = HYPERV_CPUID_ENLIGHTMENT_INFO;
         if (cpu->hyperv_relaxed_timing) {
@@ -1239,6 +1247,10 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
             kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_APIC_ASSIST_PAGE,
                               env->msr_hv_vapic);
         }
+        if (has_msr_hv_tsc) {
+            kvm_msr_entry_set(&msrs[n++], HV_X64_MSR_REFERENCE_TSC,
+                              env->msr_hv_tsc);
+        }
 
         /* Note: MSR_IA32_FEATURE_CONTROL is written separately, see
          *       kvm_put_msr_feature_control. */
@@ -1530,6 +1542,9 @@ static int kvm_get_msrs(X86CPU *cpu)
     if (has_msr_hv_vapic) {
         msrs[n++].index = HV_X64_MSR_APIC_ASSIST_PAGE;
     }
+    if (has_msr_hv_tsc) {
+        msrs[n++].index = HV_X64_MSR_REFERENCE_TSC;
+    }
 
     msr_data.info.nmsrs = n;
     ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, &msr_data);
@@ -1647,6 +1662,9 @@ static int kvm_get_msrs(X86CPU *cpu)
         case HV_X64_MSR_APIC_ASSIST_PAGE:
             env->msr_hv_vapic = msrs[i].data;
             break;
+        case HV_X64_MSR_REFERENCE_TSC:
+            env->msr_hv_tsc = msrs[i].data;
+            break;
         }
     }
 
diff --git a/target-i386/machine.c b/target-i386/machine.c
index e72e270..d548c05 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -593,6 +593,25 @@ static const VMStateDescription vmstate_msr_hyperv_vapic = {
     }
 };
 
+static bool hyperv_time_enable_needed(void *opaque)
+{
+    X86CPU *cpu = opaque;
+    CPUX86State *env = &cpu->env;
+
+    return env->msr_hv_tsc != 0;
+}
+
+static const VMStateDescription vmstate_msr_hyperv_time = {
+    .name = "cpu/msr_hyperv_time",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT64(env.msr_hv_tsc, X86CPU),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 const VMStateDescription vmstate_x86_cpu = {
     .name = "cpu",
     .version_id = 12,
@@ -733,6 +752,9 @@ const VMStateDescription vmstate_x86_cpu = {
         }, {
             .vmsd = &vmstate_msr_hyperv_vapic,
             .needed = hyperv_vapic_enable_needed,
+        }, {
+            .vmsd = &vmstate_msr_hyperv_time,
+            .needed = hyperv_time_enable_needed,
         } , {
             /* empty */
         }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 1/5] KVM: fix coexistence of KVM and Hyper-V leaves
  2014-01-24 16:17 ` [Qemu-devel] [PATCH 1/5] KVM: fix coexistence of KVM and Hyper-V leaves Paolo Bonzini
@ 2014-01-24 19:08   ` Marcelo Tosatti
  2014-01-24 19:40     ` Paolo Bonzini
  0 siblings, 1 reply; 8+ messages in thread
From: Marcelo Tosatti @ 2014-01-24 19:08 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, kvm, vrozenfe

On Fri, Jan 24, 2014 at 05:17:52PM +0100, Paolo Bonzini wrote:
> kvm_arch_init_vcpu's initialization of the KVM leaves at 0x40000100
> is broken, because KVM_CPUID_FEATURES is left at 0x40000001.  Move
> it to 0x40000101 if Hyper-V is enabled.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

arch/x86/include/asm/kvm_para.h

static inline unsigned int kvm_arch_para_features(void)
{
        return cpuid_eax(KVM_CPUID_FEATURES);
}

Shouldnt it be using kvm_cpuid_base ?

> ---
>  target-i386/kvm.c | 47 +++++++++++++++++++++++++----------------------
>  1 file changed, 25 insertions(+), 22 deletions(-)
> 
> diff --git a/target-i386/kvm.c b/target-i386/kvm.c
> index 0a21c30..5738911 100644
> --- a/target-i386/kvm.c
> +++ b/target-i386/kvm.c
> @@ -455,6 +455,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
>      uint32_t unused;
>      struct kvm_cpuid_entry2 *c;
>      uint32_t signature[3];
> +    int kvm_base = KVM_CPUID_SIGNATURE;
>      int r;
>  
>      memset(&cpuid_data, 0, sizeof(cpuid_data));
> @@ -462,26 +463,22 @@ int kvm_arch_init_vcpu(CPUState *cs)
>      cpuid_i = 0;
>  
>      /* Paravirtualization CPUIDs */
> -    c = &cpuid_data.entries[cpuid_i++];
> -    c->function = KVM_CPUID_SIGNATURE;
> -    if (!hyperv_enabled(cpu)) {
> -        memcpy(signature, "KVMKVMKVM\0\0\0", 12);
> -        c->eax = 0;
> -    } else {
> +    if (hyperv_enabled(cpu)) {
> +        c = &cpuid_data.entries[cpuid_i++];
> +        c->function = HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS;
>          memcpy(signature, "Microsoft Hv", 12);
>          c->eax = HYPERV_CPUID_MIN;
> -    }
> -    c->ebx = signature[0];
> -    c->ecx = signature[1];
> -    c->edx = signature[2];
> -
> -    c = &cpuid_data.entries[cpuid_i++];
> -    c->function = KVM_CPUID_FEATURES;
> -    c->eax = env->features[FEAT_KVM];
> +        c->ebx = signature[0];
> +        c->ecx = signature[1];
> +        c->edx = signature[2];
>  
> -    if (hyperv_enabled(cpu)) {
> +        c = &cpuid_data.entries[cpuid_i++];
> +        c->function = HYPERV_CPUID_INTERFACE;
>          memcpy(signature, "Hv#1\0\0\0\0\0\0\0\0", 12);
>          c->eax = signature[0];
> +        c->ebx = 0;
> +        c->ecx = 0;
> +        c->edx = 0;
>  
>          c = &cpuid_data.entries[cpuid_i++];
>          c->function = HYPERV_CPUID_VERSION;
> @@ -513,15 +510,21 @@ int kvm_arch_init_vcpu(CPUState *cs)
>          c->eax = 0x40;
>          c->ebx = 0x40;
>  
> -        c = &cpuid_data.entries[cpuid_i++];
> -        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];
> +        kvm_base = KVM_CPUID_SIGNATURE_NEXT;
>      }
>  
> +    memcpy(signature, "KVMKVMKVM\0\0\0", 12);
> +    c = &cpuid_data.entries[cpuid_i++];
> +    c->function = KVM_CPUID_SIGNATURE | kvm_base;
> +    c->eax = 0;
> +    c->ebx = signature[0];
> +    c->ecx = signature[1];
> +    c->edx = signature[2];
> +
> +    c = &cpuid_data.entries[cpuid_i++];
> +    c->function = KVM_CPUID_FEATURES | kvm_base;
> +    c->eax = env->features[FEAT_KVM];
> +
>      has_msr_async_pf_en = c->eax & (1 << KVM_FEATURE_ASYNC_PF);
>  
>      has_msr_pv_eoi_en = c->eax & (1 << KVM_FEATURE_PV_EOI);
> -- 
> 1.8.3.1
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 1/5] KVM: fix coexistence of KVM and Hyper-V leaves
  2014-01-24 19:08   ` Marcelo Tosatti
@ 2014-01-24 19:40     ` Paolo Bonzini
  0 siblings, 0 replies; 8+ messages in thread
From: Paolo Bonzini @ 2014-01-24 19:40 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: qemu-devel, kvm, vrozenfe

Il 24/01/2014 20:08, Marcelo Tosatti ha scritto:
>> > kvm_arch_init_vcpu's initialization of the KVM leaves at 0x40000100
>> > is broken, because KVM_CPUID_FEATURES is left at 0x40000001.  Move
>> > it to 0x40000101 if Hyper-V is enabled.
>> >
>> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> arch/x86/include/asm/kvm_para.h
>
> static inline unsigned int kvm_arch_para_features(void)
> {
>         return cpuid_eax(KVM_CPUID_FEATURES);
> }
>
> Shouldnt it be using kvm_cpuid_base ?
>

Yes.

Paolo

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-01-24 19:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-24 16:17 [Qemu-devel] [PATCH uq/master 0/5] Hyper-V improvements and migratability Paolo Bonzini
2014-01-24 16:17 ` [Qemu-devel] [PATCH 1/5] KVM: fix coexistence of KVM and Hyper-V leaves Paolo Bonzini
2014-01-24 19:08   ` Marcelo Tosatti
2014-01-24 19:40     ` Paolo Bonzini
2014-01-24 16:17 ` [Qemu-devel] [PATCH 2/5] kvm: make availability of Hyper-V enlightenments dependent on KVM_CAP_HYPERV Paolo Bonzini
2014-01-24 16:17 ` [Qemu-devel] [PATCH 3/5] kvm: make hyperv hypercall and guest os id MSRs migratable Paolo Bonzini
2014-01-24 16:17 ` [Qemu-devel] [PATCH 4/5] kvm: make hyperv vapic assist page migratable Paolo Bonzini
2014-01-24 16:17 ` [Qemu-devel] [PATCH 5/5] kvm: add support for hyper-v timers Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).