[PATCH] Add support for kvm pvtimer to qemu

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ben Luo <bn0418@xxxxxxxxx>

Add save/restore of MSR for migration and cpuid bit.

Signed-off-by: Yang Zhang <yang.zhang.wz@xxxxxxxxx>
Signed-off-by: Quan Xu <quan.xu0@xxxxxxxxx>
Signed-off-by: Ben Luo <bn0418@xxxxxxxxx>
---
 linux-headers/asm-x86/kvm_para.h |    2 ++
 target/i386/cpu.c                |    4 +++-
 target/i386/cpu.h                |    1 +
 target/i386/kvm.c                |    9 +++++++++
 target/i386/machine.c            |   19 +++++++++++++++++++
 5 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/linux-headers/asm-x86/kvm_para.h b/linux-headers/asm-x86/kvm_para.h
index cefa127..2ef62e5 100644
--- a/linux-headers/asm-x86/kvm_para.h
+++ b/linux-headers/asm-x86/kvm_para.h
@@ -24,6 +24,7 @@
 #define KVM_FEATURE_STEAL_TIME		5
 #define KVM_FEATURE_PV_EOI		6
 #define KVM_FEATURE_PV_UNHALT		7
+#define KVM_FEATURE_PV_TIMER		8
 
 /* The last 8 bits are used to indicate how to interpret the flags field
  * in pvclock structure. If no bits are set, all flags are ignored.
@@ -40,6 +41,7 @@
 #define MSR_KVM_ASYNC_PF_EN 0x4b564d02
 #define MSR_KVM_STEAL_TIME  0x4b564d03
 #define MSR_KVM_PV_EOI_EN      0x4b564d04
+#define MSR_KVM_PV_TIMER_EN    0x4b564d05
 
 struct kvm_steal_time {
 	__u64 steal;
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 045d661..d6e5ada 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -347,7 +347,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
         .feat_names = {
             "kvmclock", "kvm-nopiodelay", "kvm-mmu", "kvmclock",
             "kvm-asyncpf", "kvm-steal-time", "kvm-pv-eoi", "kvm-pv-unhalt",
-            NULL, "kvm-pv-tlb-flush", NULL, NULL,
+            "kvm-pv-timer", "kvm-pv-tlb-flush", NULL, NULL,
             NULL, NULL, NULL, NULL,
             NULL, NULL, NULL, NULL,
             NULL, NULL, NULL, NULL,
@@ -1580,6 +1580,7 @@ static PropValue kvm_default_props[] = {
     { "kvm-asyncpf", "on" },
     { "kvm-steal-time", "on" },
     { "kvm-pv-eoi", "on" },
+    { "kvm-pv-timer", "on" },
     { "kvmclock-stable-bit", "on" },
     { "x2apic", "on" },
     { "acpi", "off" },
@@ -4038,6 +4039,7 @@ static void x86_cpu_initfn(Object *obj)
     object_property_add_alias(obj, "kvm_steal_time", obj, "kvm-steal-time", &error_abort);
     object_property_add_alias(obj, "kvm_pv_eoi", obj, "kvm-pv-eoi", &error_abort);
     object_property_add_alias(obj, "kvm_pv_unhalt", obj, "kvm-pv-unhalt", &error_abort);
+    object_property_add_alias(obj, "kvm_pv_timer", obj, "kvm-pv-timer", &error_abort);
     object_property_add_alias(obj, "svm_lock", obj, "svm-lock", &error_abort);
     object_property_add_alias(obj, "nrip_save", obj, "nrip-save", &error_abort);
     object_property_add_alias(obj, "tsc_scale", obj, "tsc-scale", &error_abort);
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index b086b15..e4f1df5 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -1090,6 +1090,7 @@ typedef struct CPUX86State {
     uint64_t steal_time_msr;
     uint64_t async_pf_en_msr;
     uint64_t pv_eoi_en_msr;
+    uint64_t pv_timer_en_msr;
 
     uint64_t msr_hv_hypercall;
     uint64_t msr_hv_guest_os_id;
diff --git a/target/i386/kvm.c b/target/i386/kvm.c
index b1e32e9..f399084 100644
--- a/target/i386/kvm.c
+++ b/target/i386/kvm.c
@@ -1648,6 +1648,9 @@ static int kvm_put_msrs(X86CPU *cpu, int level)
         if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_PV_EOI)) {
             kvm_msr_entry_add(cpu, MSR_KVM_PV_EOI_EN, env->pv_eoi_en_msr);
         }
+        if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_PV_TIMER)) {
+            kvm_msr_entry_add(cpu, MSR_KVM_PV_TIMER_EN, env->pv_timer_en_msr);
+        }
         if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_STEAL_TIME)) {
             kvm_msr_entry_add(cpu, MSR_KVM_STEAL_TIME, env->steal_time_msr);
         }
@@ -2021,6 +2024,9 @@ static int kvm_get_msrs(X86CPU *cpu)
     if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_PV_EOI)) {
         kvm_msr_entry_add(cpu, MSR_KVM_PV_EOI_EN, 0);
     }
+    if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_PV_TIMER)) {
+        kvm_msr_entry_add(cpu, MSR_KVM_PV_TIMER_EN, 0);
+    }
     if (env->features[FEAT_KVM] & (1 << KVM_FEATURE_STEAL_TIME)) {
         kvm_msr_entry_add(cpu, MSR_KVM_STEAL_TIME, 0);
     }
@@ -2232,6 +2238,9 @@ static int kvm_get_msrs(X86CPU *cpu)
         case MSR_KVM_PV_EOI_EN:
             env->pv_eoi_en_msr = msrs[i].data;
             break;
+        case MSR_KVM_PV_TIMER_EN:
+            env->pv_timer_en_msr = msrs[i].data;
+            break;
         case MSR_KVM_STEAL_TIME:
             env->steal_time_msr = msrs[i].data;
             break;
diff --git a/target/i386/machine.c b/target/i386/machine.c
index df5ec35..64b7a12 100644
--- a/target/i386/machine.c
+++ b/target/i386/machine.c
@@ -315,6 +315,13 @@ static bool pv_eoi_msr_needed(void *opaque)
     return cpu->env.pv_eoi_en_msr != 0;
 }
 
+static bool pv_timer_msr_needed(void *opaque)
+{
+    X86CPU *cpu = opaque;
+
+    return cpu->env.pv_timer_en_msr != 0;
+}
+
 static bool steal_time_msr_needed(void *opaque)
 {
     X86CPU *cpu = opaque;
@@ -355,6 +362,17 @@ static const VMStateDescription vmstate_pv_eoi_msr = {
     }
 };
 
+static const VMStateDescription vmstate_pv_timer_msr = {
+    .name = "cpu/async_pv_timer_msr",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .needed = pv_timer_msr_needed,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT64(env.pv_timer_en_msr, X86CPU),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static bool fpop_ip_dp_needed(void *opaque)
 {
     X86CPU *cpu = opaque;
@@ -915,6 +933,7 @@ VMStateDescription vmstate_x86_cpu = {
     .subsections = (const VMStateDescription*[]) {
         &vmstate_async_pf_msr,
         &vmstate_pv_eoi_msr,
+        &vmstate_pv_timer_msr,
         &vmstate_steal_time_msr,
         &vmstate_fpop_ip_dp,
         &vmstate_msr_tsc_adjust,
-- 
1.7.1




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux