Skip to contentSkip to conversation

call kvm_cpu_synchronize_state() on target vcpu

PATCH Applied Gleb Natapov 2 participants 2 messages Sep 9, 2009 KVM

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 call kvm_cpu_synchronize_state() on target vcpu

regs_modified logic doesn't work if io thread calls kvm_cpu_synchronize_state() since kvm_arch_get_registers() returns only after vcpu thread is back to kernel. Setting regs_modified to 1 at this stage causes loading of wrong vcpu state on the next vcpu_run().

--
v1->v2:
do not remove kvm_arch_get_registers(). Change it and use it.

qemu-kvm.c +15 -8
index 06efd41..e2f3b91 100644
@@ -874,14 +874,6 @@ int kvm_set_mpstate(kvm_vcpu_context_t vcpu, struct kvm_mp_state *mp_state)
 }
 #endif
 
-void kvm_cpu_synchronize_state(CPUState *env)
-{
-    if (!env->kvm_cpu_state.regs_modified) {
-        kvm_arch_get_registers(env);
-        env->kvm_cpu_state.regs_modified = 1;
-    }
-}
-
 static int handle_mmio(kvm_vcpu_context_t vcpu)
 {
     unsigned long addr = vcpu->run->mmio.phys_addr;
@@ -1539,6 +1531,21 @@ static void on_vcpu(CPUState *env, void (*func)(void *data), void *data)
         qemu_cond_wait(&qemu_work_cond);
 }
 
+static void do_kvm_cpu_synchronize_state(void *_env)
+{
+    CPUState *env = _env;
+    if (!env->kvm_cpu_state.regs_modified) {
+        kvm_arch_get_registers(env);
+        env->kvm_cpu_state.regs_modified = 1;
+    }
+}
+
+void kvm_cpu_synchronize_state(CPUState *env)
+{
+    if (!env->kvm_cpu_state.regs_modified)
+        on_vcpu(env, do_kvm_cpu_synchronize_state, env);
+}
+
 static void inject_interrupt(void *data)
 {
     cpu_interrupt(current_env, (long) data);
qemu-kvm.h +2 -2
index 2c1730b..1c42e82 100644
@@ -1155,8 +1155,8 @@ static inline int kvm_sync_vcpus(void)
 
 static inline void kvm_arch_get_registers(CPUState *env)
 {
-    kvm_save_registers(env);
-    kvm_save_mpstate(env);
+    kvm_arch_save_regs(env);
+    kvm_arch_save_mpstate(env);
 }
 
 static inline void kvm_arch_put_registers(CPUState *env)
target-i386/helper.c +1 -1
index 4a16887..57c74a2 100644
@@ -746,7 +746,7 @@ void cpu_dump_state(CPUState *env, FILE *f,
     static const char *seg_name[6] = { "ES", "CS", "SS", "DS", "FS", "GS" };
 
     if (kvm_enabled())
-        kvm_arch_get_registers(env);
+        kvm_cpu_synchronize_state(env);
 
     eflags = env->eflags;
 #ifdef TARGET_X86_64

--
Gleb.

Applied
#1 lore raw
Quoted 6 lines · Gleb Natapov

regs_modified logic doesn't work if io thread calls kvm_cpu_synchronize_state() since kvm_arch_get_registers() returns only after vcpu thread is back to kernel. Setting regs_modified to 1 at this stage causes loading of wrong vcpu state on the next vcpu_run().

Applied, thanks.

Signature · 1 line
error compiling committee.c: too many arguments to function