summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGleb Natapov <gleb@redhat.com>2009-10-14 15:52:32 +0200
committerMarcelo Tosatti <mtosatti@redhat.com>2009-10-14 15:35:06 -0300
commitb8a7857071b477b28d3055e33ff0298fc91f329a (patch)
tree138cbf2456d3637930dfea09edf53905e41aba82
parentComplete cpu initialization before signaling main thread. (diff)
downloadqemu-kvm-b8a7857071b477b28d3055e33ff0298fc91f329a.tar.gz
qemu-kvm-b8a7857071b477b28d3055e33ff0298fc91f329a.tar.bz2
qemu-kvm-b8a7857071b477b28d3055e33ff0298fc91f329a.zip
Don't sync mpstate to/from kernel when unneeded.
mp_state, unlike other cpu state, can be changed not only from vcpu context it belongs to, but by other vcpus too. That makes its loading from kernel/saving back not safe if mp_state value is changed inside kernel between load and save. For example vcpu 1 loads mp_sate into user-space and the state is RUNNING, vcpu 0 sends INIT/SIPI to vcpu 1 so in-kernel mp_sate becomes SIPI, vcpu 1 save user-space copy into kernel and calls vcpu_run(). SIPI sate is lost. The patch copies mp_sate into kernel only when it is knows that int-kernel value is outdated. This happens on reset and vmload. Signed-off-by: Gleb Natapov <gleb@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
-rw-r--r--hw/apic.c1
-rw-r--r--monitor.c2
-rw-r--r--qemu-kvm.c9
-rw-r--r--qemu-kvm.h1
-rw-r--r--target-i386/machine.c3
5 files changed, 10 insertions, 6 deletions
diff --git a/hw/apic.c b/hw/apic.c
index b8fe529e2..39105077c 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -512,6 +512,7 @@ void apic_init_reset(CPUState *env)
if (kvm_enabled() && kvm_irqchip_in_kernel()) {
env->mp_state
= env->halted ? KVM_MP_STATE_UNINITIALIZED : KVM_MP_STATE_RUNNABLE;
+ kvm_load_mpstate(env);
}
#endif
}
diff --git a/monitor.c b/monitor.c
index 7f0f5a952..dd8f2cab7 100644
--- a/monitor.c
+++ b/monitor.c
@@ -350,6 +350,7 @@ static CPUState *mon_get_cpu(void)
mon_set_cpu(0);
}
cpu_synchronize_state(cur_mon->mon_cpu);
+ kvm_save_mpstate(cur_mon->mon_cpu);
return cur_mon->mon_cpu;
}
@@ -377,6 +378,7 @@ static void do_info_cpus(Monitor *mon)
for(env = first_cpu; env != NULL; env = env->next_cpu) {
cpu_synchronize_state(env);
+ kvm_save_mpstate(env);
monitor_printf(mon, "%c CPU #%d:",
(env == mon->mon_cpu) ? '*' : ' ',
env->cpu_index);
diff --git a/qemu-kvm.c b/qemu-kvm.c
index b6c36e039..e168db2c3 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -1579,11 +1579,6 @@ static void on_vcpu(CPUState *env, void (*func)(void *data), void *data)
void kvm_arch_get_registers(CPUState *env)
{
kvm_arch_save_regs(env);
- kvm_arch_save_mpstate(env);
-#ifdef KVM_CAP_MP_STATE
- if (kvm_irqchip_in_kernel())
- env->halted = (env->mp_state == KVM_MP_STATE_HALTED);
-#endif
}
static void do_kvm_cpu_synchronize_state(void *_env)
@@ -1677,6 +1672,10 @@ static void kvm_do_save_mpstate(void *_env)
CPUState *env = _env;
kvm_arch_save_mpstate(env);
+#ifdef KVM_CAP_MP_STATE
+ if (kvm_irqchip_in_kernel())
+ env->halted = (env->mp_state == KVM_MP_STATE_HALTED);
+#endif
}
void kvm_save_mpstate(CPUState *env)
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 863911d15..6a886b1a6 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -1142,7 +1142,6 @@ void kvm_arch_get_registers(CPUState *env);
static inline void kvm_arch_put_registers(CPUState *env)
{
kvm_load_registers(env);
- kvm_load_mpstate(env);
}
void kvm_cpu_synchronize_state(CPUState *env);
diff --git a/target-i386/machine.c b/target-i386/machine.c
index e640dad4b..16d9c57ba 100644
--- a/target-i386/machine.c
+++ b/target-i386/machine.c
@@ -324,6 +324,7 @@ static void cpu_pre_save(void *opaque)
int i, bit;
cpu_synchronize_state(env);
+ kvm_save_mpstate(env);
/* FPU */
env->fpus_vmstate = (env->fpus & ~0x3800) | (env->fpstt & 0x7) << 11;
@@ -385,6 +386,8 @@ static int cpu_post_load(void *opaque, int version_id)
}
tlb_flush(env, 1);
+ kvm_load_mpstate(env);
+
return 0;
}