Patchwork [uq/master,5/9] kvm: synchronize state from cpu context

login
register
mail settings
Submitter Marcelo Tosatti
Date May 4, 2010, 12:45 p.m.
Message ID <20100504124634.399797233@redhat.com>
Download mbox | patch
Permalink /patch/51602/
State New
Headers show

Comments

Marcelo Tosatti - May 4, 2010, 12:45 p.m.
From: Jan Kiszka <jan.kiszka@siemens.com>

It is not safe to retrieve the KVM internal state of a given cpu
while its potentially modifying it.

Queue the request to run on cpu context, similarly to qemu-kvm.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Avi Kivity - May 6, 2010, 11:31 a.m.
On 05/04/2010 03:45 PM, Marcelo Tosatti wrote:
> From: Jan Kiszka<jan.kiszka@siemens.com>
>
> It is not safe to retrieve the KVM internal state of a given cpu
> while its potentially modifying it.
>
> Queue the request to run on cpu context, similarly to qemu-kvm.
>    

Even better is to query the state in the cpu thread; but that can come 
later.

Patch

Index: qemu/kvm-all.c
===================================================================
--- qemu.orig/kvm-all.c
+++ qemu/kvm-all.c
@@ -796,14 +796,22 @@  void kvm_flush_coalesced_mmio_buffer(voi
 #endif
 }
 
-void kvm_cpu_synchronize_state(CPUState *env)
+static void do_kvm_cpu_synchronize_state(void *_env)
 {
+    CPUState *env = _env;
+
     if (!env->kvm_vcpu_dirty) {
         kvm_arch_get_registers(env);
         env->kvm_vcpu_dirty = 1;
     }
 }
 
+void kvm_cpu_synchronize_state(CPUState *env)
+{
+    if (!env->kvm_vcpu_dirty)
+        run_on_cpu(env, do_kvm_cpu_synchronize_state, env);
+}
+
 void kvm_cpu_synchronize_post_reset(CPUState *env)
 {
     kvm_arch_put_registers(env, KVM_PUT_RESET_STATE);