qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: Avi Kivity <avi@redhat.com>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 9/8] kvm: x86: Save/restore KVM-specific CPU states
Date: Sat, 02 May 2009 02:08:11 +0200	[thread overview]
Message-ID: <49FB8EEB.1050208@web.de> (raw)
In-Reply-To: <49FB7C81.80101@web.de>

Save and restore all so far neglected KVM-specific CPU states. Handling
the TSC stabilizes migration in KVM mode. The interrupt_bitmap and
mp_state are currently unused, but will become relevant for in-kernel
irqchip support. By including proper saving/restoring already, we avoid
having to increment CPU_SAVE_VERSION later on once again.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---

 kvm-all.c             |   20 ++++++++++++++++++++
 kvm.h                 |    3 +++
 target-i386/cpu.h     |    3 ++-
 target-i386/kvm.c     |   10 ++++++++++
 target-i386/machine.c |   16 ++++++++++++++--
 5 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/kvm-all.c b/kvm-all.c
index 2ac5129..f17055f 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -181,6 +181,26 @@ err:
     return ret;
 }
 
+int kvm_put_mp_state(CPUState *env)
+{
+    struct kvm_mp_state mp_state = { .mp_state = env->mp_state };
+
+    return kvm_vcpu_ioctl(env, KVM_SET_MP_STATE, &mp_state);
+}
+
+int kvm_get_mp_state(CPUState *env)
+{
+    struct kvm_mp_state mp_state;
+    int ret;
+
+    ret = kvm_vcpu_ioctl(env, KVM_GET_MP_STATE, &mp_state);
+    if (ret < 0) {
+        return ret;
+    }
+    env->mp_state = mp_state.mp_state;
+    return 0;
+}
+
 int kvm_sync_vcpus(void)
 {
     CPUState *env;
diff --git a/kvm.h b/kvm.h
index 6e0589a..8256eb6 100644
--- a/kvm.h
+++ b/kvm.h
@@ -72,6 +72,9 @@ int kvm_vm_ioctl(KVMState *s, int type, ...);
 
 int kvm_vcpu_ioctl(CPUState *env, int type, ...);
 
+int kvm_get_mp_state(CPUState *env);
+int kvm_put_mp_state(CPUState *env);
+
 /* Arch specific hooks */
 
 int kvm_arch_post_run(CPUState *env, struct kvm_run *run);
diff --git a/target-i386/cpu.h b/target-i386/cpu.h
index c6bca94..eaa623c 100644
--- a/target-i386/cpu.h
+++ b/target-i386/cpu.h
@@ -669,6 +669,7 @@ typedef struct CPUX86State {
 
     /* For KVM */
     uint64_t interrupt_bitmap[256 / 64];
+    uint32_t mp_state;
 
     /* in order to simplify APIC support, we leave this pointer to the
        user */
@@ -837,7 +838,7 @@ static inline int cpu_get_time_fast(void)
 #define cpu_signal_handler cpu_x86_signal_handler
 #define cpu_list x86_cpu_list
 
-#define CPU_SAVE_VERSION 8
+#define CPU_SAVE_VERSION 9
 
 /* MMU modes definitions */
 #define MMU_MODE0_SUFFIX _kernel
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index 2de8b81..f65ae00 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -43,6 +43,8 @@ int kvm_arch_init_vcpu(CPUState *env)
     uint32_t limit, i, j, cpuid_i;
     uint32_t unused;
 
+    env->mp_state = KVM_MP_STATE_UNINITIALIZED;
+
     cpuid_i = 0;
 
     cpu_x86_cpuid(env, 0, 0, &limit, &unused, &unused, &unused);
@@ -565,6 +567,10 @@ int kvm_arch_put_registers(CPUState *env)
     if (ret < 0)
         return ret;
 
+    ret = kvm_put_mp_state(env);
+    if (ret < 0)
+        return ret;
+
     return 0;
 }
 
@@ -588,6 +594,10 @@ int kvm_arch_get_registers(CPUState *env)
     if (ret < 0)
         return ret;
 
+    ret = kvm_get_mp_state(env);
+    if (ret < 0)
+        return ret;
+
     return 0;
 }
 
diff --git a/target-i386/machine.c b/target-i386/machine.c
index 4fc7335..e1ba0d5 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -149,6 +149,12 @@ void cpu_save(QEMUFile *f, void *opaque)
         qemu_put_be64s(f, &env->mtrr_var[i].base);
         qemu_put_be64s(f, &env->mtrr_var[i].mask);
     }
+
+    for (i = 0; i < sizeof(env->interrupt_bitmap)/8; i++) {
+        qemu_put_be64s(f, &env->interrupt_bitmap[i]);
+    }
+    qemu_put_be64s(f, &env->tsc);
+    qemu_put_be32s(f, &env->mp_state);
 }
 
 #ifdef USE_X86LDOUBLE
@@ -183,8 +189,7 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
     uint16_t fpus, fpuc, fptag, fpregs_format;
     int32_t a20_mask;
 
-    if (version_id != 3 && version_id != 4 && version_id != 5
-        && version_id != 6 && version_id != 7 && version_id != 8)
+    if (version_id < 3 || version_id > CPU_SAVE_VERSION)
         return -EINVAL;
     for(i = 0; i < CPU_NB_REGS; i++)
         qemu_get_betls(f, &env->regs[i]);
@@ -328,6 +333,13 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id)
             qemu_get_be64s(f, &env->mtrr_var[i].mask);
         }
     }
+    if (version_id >= 9) {
+        for (i = 0; i < sizeof(env->interrupt_bitmap)/8; i++) {
+            qemu_get_be64s(f, &env->interrupt_bitmap[i]);
+        }
+        qemu_get_be64s(f, &env->tsc);
+        qemu_get_be32s(f, &env->mp_state);
+    }
 
     /* XXX: ensure compatiblity for halted bit ? */
     /* XXX: compute redundant hflags bits */

  parent reply	other threads:[~2009-05-02  0:08 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-01 21:17 [Qemu-devel] [PATCH 0/8] kvm: Fixes, cleanups and live migration Jan Kiszka
2009-05-01 21:17 ` [Qemu-devel] [PATCH 1/8] kvm: Conditionally apply workaround for KVM slot handling bug Jan Kiszka
2009-05-01 21:17 ` [Qemu-devel] [PATCH 6/8] kvm: Fix framebuffer dirty log sync Jan Kiszka
2009-05-01 21:17 ` [Qemu-devel] [PATCH 5/8] kvm: Add missing bits to support live migration Jan Kiszka
2009-05-01 21:17 ` [Qemu-devel] [PATCH 3/8] kvm: Fix dirty log temporary buffer size Jan Kiszka
2009-05-01 21:17 ` [Qemu-devel] [PATCH 2/8] kvm: Introduce kvm_set_migration_log Jan Kiszka
2009-05-01 21:17 ` [Qemu-devel] [PATCH 4/8] kvm: Rework dirty bitmap synchronization Jan Kiszka
2009-05-03 10:05   ` [Qemu-devel] " Avi Kivity
2009-05-04  8:52     ` Jan Kiszka
2009-05-01 21:17 ` [Qemu-devel] [PATCH 7/8] Introduce reset notifier order Jan Kiszka
2009-05-01 23:52   ` Paul Brook
2009-05-02  0:05     ` [Qemu-devel] " Jan Kiszka
2009-05-02  0:34       ` Paul Brook
2009-05-04  7:45         ` Jan Kiszka
2009-05-01 21:17 ` [Qemu-devel] [PATCH 8/8] kvm: Rework VCPU reset Jan Kiszka
2009-05-03 15:58   ` [Qemu-devel] " Avi Kivity
2009-05-04  8:54     ` Jan Kiszka
2009-05-04  9:12       ` Avi Kivity
2009-05-04  9:29         ` Jan Kiszka
2009-05-04 10:01           ` Avi Kivity
2009-05-01 22:30 ` [Qemu-devel] Re: [PATCH 0/8] kvm: Fixes, cleanups and live migration Anthony Liguori
2009-05-01 22:49   ` Anthony Liguori
2009-05-01 22:49   ` Jan Kiszka
2009-05-01 22:40 ` Anthony Liguori
2009-05-01 22:56   ` Jan Kiszka
2009-05-02  8:07     ` Avi Kivity
2009-05-02  7:40   ` Gleb Natapov
2009-05-02 13:50     ` Anthony Liguori
2009-05-02 17:23       ` Gleb Natapov
2009-05-02 19:12         ` Avi Kivity
2009-05-02 20:07           ` Gleb Natapov
2009-05-02 20:09             ` [Qemu-devel] Re: [PATCH 0/8] kvm: Fixes, cleanups and livemigration Anthony Liguori
2009-05-03  5:25               ` Gleb Natapov
2009-05-03  5:57             ` [Qemu-devel] Re: [PATCH 0/8] kvm: Fixes, cleanups and live migration Avi Kivity
2009-05-03  6:05               ` Gleb Natapov
2009-05-03  7:36                 ` Avi Kivity
2009-05-03  7:46                   ` Gleb Natapov
2009-05-03  7:50                     ` Avi Kivity
2009-05-03  7:56                       ` Gleb Natapov
2009-05-03  8:01                         ` Avi Kivity
2009-05-03  8:35                           ` Gleb Natapov
2009-05-01 22:49 ` [Qemu-devel] [PATCH 9/8] kvm: Save/restore TSC counter Jan Kiszka
2009-05-01 22:51   ` [Qemu-devel] " Anthony Liguori
2009-05-01 22:58     ` Jan Kiszka
2009-05-01 23:09       ` Jan Kiszka
2009-05-01 23:18         ` Anthony Liguori
2009-05-02  0:08   ` Jan Kiszka [this message]
2009-05-02  0:20     ` [Qemu-devel] [PATCH 9/8 v2] kvm: x86: Save/restore KVM-specific CPU states Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49FB8EEB.1050208@web.de \
    --to=jan.kiszka@web.de \
    --cc=aliguori@us.ibm.com \
    --cc=avi@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).