render / rpms / qemu

Forked from rpms/qemu 5 months ago
Clone

Blame qemu-properly-save-kvm-system-time-registers.patch

Mark McLoughlin 86104d
From 20a3c3095744ea65b4dfb5365efea8cdb802f7f5 Mon Sep 17 00:00:00 2001
Mark McLoughlin 86104d
From: Glauber Costa <glommer@redhat.com>
Mark McLoughlin 86104d
Date: Wed, 21 Oct 2009 10:52:46 -0400
Mark McLoughlin 86104d
Subject: [PATCH] properly save kvm system time msr registers
Mark McLoughlin 86104d
Mark McLoughlin 86104d
Currently, the msrs involved in setting up pvclock are not saved over
Mark McLoughlin 86104d
migration and/or save/restore. This patch puts their value in special
Mark McLoughlin 86104d
fields in our CPUState, and deal with them using vmstate.
Mark McLoughlin 86104d
Mark McLoughlin 86104d
kvm also has to account for it, by including them in the msr list
Mark McLoughlin 86104d
for the ioctls.
Mark McLoughlin 86104d
Mark McLoughlin 86104d
Fedora-patch: qemu-properly-save-kvm-system-time-registers.patch
Mark McLoughlin 86104d
Signed-off-by: Glauber Costa <glommer@redhat.com>
Mark McLoughlin 86104d
---
Mark McLoughlin 86104d
 qemu-kvm-x86.c        |   15 +++++++++++++--
Mark McLoughlin 86104d
 target-i386/cpu.h     |    5 ++++-
Mark McLoughlin 86104d
 target-i386/machine.c |    8 ++++++++
Mark McLoughlin 86104d
 3 files changed, 25 insertions(+), 3 deletions(-)
Mark McLoughlin 86104d
Mark McLoughlin 86104d
diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
Mark McLoughlin 86104d
index d5436b6..300e6c2 100644
Mark McLoughlin 86104d
--- a/qemu-kvm-x86.c
Mark McLoughlin 86104d
+++ b/qemu-kvm-x86.c
Mark McLoughlin 86104d
@@ -839,6 +839,12 @@ static int get_msr_entry(struct kvm_msr_entry *entry, CPUState *env)
Mark McLoughlin 86104d
         case MSR_VM_HSAVE_PA:
Mark McLoughlin 86104d
             env->vm_hsave     = entry->data;
Mark McLoughlin 86104d
             break;
Mark McLoughlin 86104d
+        case MSR_KVM_SYSTEM_TIME:
Mark McLoughlin 86104d
+            env->system_time_msr = entry->data;
Mark McLoughlin 86104d
+            break;
Mark McLoughlin 86104d
+        case MSR_KVM_WALL_CLOCK:
Mark McLoughlin 86104d
+            env->wall_clock_msr = entry->data;
Mark McLoughlin 86104d
+            break;
Mark McLoughlin 86104d
         default:
Mark McLoughlin 86104d
             printf("Warning unknown msr index 0x%x\n", entry->index);
Mark McLoughlin 86104d
             return 1;
Mark McLoughlin 86104d
@@ -847,9 +853,9 @@ static int get_msr_entry(struct kvm_msr_entry *entry, CPUState *env)
Mark McLoughlin 86104d
 }
Mark McLoughlin 86104d
 
Mark McLoughlin 86104d
 #ifdef TARGET_X86_64
Mark McLoughlin 86104d
-#define MSR_COUNT 10
Mark McLoughlin 86104d
+#define MSR_COUNT 12
Mark McLoughlin 86104d
 #else
Mark McLoughlin 86104d
-#define MSR_COUNT 6
Mark McLoughlin 86104d
+#define MSR_COUNT 8
Mark McLoughlin 86104d
 #endif
Mark McLoughlin 86104d
 
Mark McLoughlin 86104d
 static void set_v8086_seg(struct kvm_segment *lhs, const SegmentCache *rhs)
Mark McLoughlin 86104d
@@ -1007,6 +1013,8 @@ void kvm_arch_load_regs(CPUState *env)
Mark McLoughlin 86104d
         set_msr_entry(&msrs[n++], MSR_LSTAR  ,           env->lstar);
Mark McLoughlin 86104d
     }
Mark McLoughlin 86104d
 #endif
Mark McLoughlin 86104d
+    set_msr_entry(&msrs[n++], MSR_KVM_SYSTEM_TIME,  env->system_time_msr);
Mark McLoughlin 86104d
+    set_msr_entry(&msrs[n++], MSR_KVM_WALL_CLOCK,  env->wall_clock_msr);
Mark McLoughlin 86104d
 
Mark McLoughlin 86104d
     rc = kvm_set_msrs(env->kvm_cpu_state.vcpu_ctx, msrs, n);
Mark McLoughlin 86104d
     if (rc == -1)
Mark McLoughlin 86104d
@@ -1184,6 +1192,9 @@ void kvm_arch_save_regs(CPUState *env)
Mark McLoughlin 86104d
         msrs[n++].index = MSR_LSTAR;
Mark McLoughlin 86104d
     }
Mark McLoughlin 86104d
 #endif
Mark McLoughlin 86104d
+    msrs[n++].index = MSR_KVM_SYSTEM_TIME;
Mark McLoughlin 86104d
+    msrs[n++].index = MSR_KVM_WALL_CLOCK;
Mark McLoughlin 86104d
+
Mark McLoughlin 86104d
     rc = kvm_get_msrs(env->kvm_cpu_state.vcpu_ctx, msrs, n);
Mark McLoughlin 86104d
     if (rc == -1) {
Mark McLoughlin 86104d
         perror("kvm_get_msrs FAILED");
Mark McLoughlin 86104d
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
Mark McLoughlin 86104d
index 08200ed..22e76ec 100644
Mark McLoughlin 86104d
--- a/target-i386/cpu.h
Mark McLoughlin 86104d
+++ b/target-i386/cpu.h
Mark McLoughlin 86104d
@@ -640,6 +640,9 @@ typedef struct CPUX86State {
Mark McLoughlin 86104d
     target_ulong fmask;
Mark McLoughlin 86104d
     target_ulong kernelgsbase;
Mark McLoughlin 86104d
 #endif
Mark McLoughlin 86104d
+    uint64_t system_time_msr;
Mark McLoughlin 86104d
+    uint64_t wall_clock_msr;
Mark McLoughlin 86104d
+
Mark McLoughlin 86104d
 
Mark McLoughlin 86104d
     uint64_t tsc;
Mark McLoughlin 86104d
 
Mark McLoughlin 86104d
@@ -867,7 +870,7 @@ static inline int cpu_get_time_fast(void)
Mark McLoughlin 86104d
 #define cpu_signal_handler cpu_x86_signal_handler
Mark McLoughlin 86104d
 #define cpu_list x86_cpu_list
Mark McLoughlin 86104d
 
Mark McLoughlin 86104d
-#define CPU_SAVE_VERSION 10
Mark McLoughlin 86104d
+#define CPU_SAVE_VERSION 11
Mark McLoughlin 86104d
 
Mark McLoughlin 86104d
 /* MMU modes definitions */
Mark McLoughlin 86104d
 #define MMU_MODE0_SUFFIX _kernel
Mark McLoughlin 86104d
diff --git a/target-i386/machine.c b/target-i386/machine.c
Mark McLoughlin 86104d
index ca32a92..4654508 100644
Mark McLoughlin 86104d
--- a/target-i386/machine.c
Mark McLoughlin 86104d
+++ b/target-i386/machine.c
Mark McLoughlin 86104d
@@ -174,6 +174,9 @@ void cpu_save(QEMUFile *f, void *opaque)
Mark McLoughlin 86104d
             qemu_put_be64s(f, &env->mce_banks[4*i + 3]);
Mark McLoughlin 86104d
         }
Mark McLoughlin 86104d
     }
Mark McLoughlin 86104d
+
Mark McLoughlin 86104d
+    qemu_put_be64s(f, &env->system_time_msr);
Mark McLoughlin 86104d
+    qemu_put_be64s(f, &env->wall_clock_msr);
Mark McLoughlin 86104d
  }
Mark McLoughlin 86104d
 
Mark McLoughlin 86104d
 #ifdef USE_X86LDOUBLE
Mark McLoughlin 86104d
@@ -405,5 +408,10 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
Mark McLoughlin 86104d
             kvm_arch_load_mpstate(env);
Mark McLoughlin 86104d
         }
Mark McLoughlin 86104d
     }
Mark McLoughlin 86104d
+
Mark McLoughlin 86104d
+    if (version_id >= 11) {
Mark McLoughlin 86104d
+        qemu_get_be64s(f, &env->system_time_msr);
Mark McLoughlin 86104d
+        qemu_get_be64s(f, &env->wall_clock_msr);
Mark McLoughlin 86104d
+    }
Mark McLoughlin 86104d
     return 0;
Mark McLoughlin 86104d
 }
Mark McLoughlin 86104d
-- 
Mark McLoughlin 86104d
1.6.2.2
Mark McLoughlin 86104d