Patchwork [06/12] kvm: synchronize state from cpu context

login
register
mail settings
Submitter Marcelo Tosatti
Date May 12, 2010, 9:25 p.m.
Message ID <2705d56a6a7e9c7833e04d33aedbc01d2280a280.1273699506.git.mtosatti@redhat.com>
Download mbox | patch
Permalink /patch/52435/
State New
Headers show

Comments

Marcelo Tosatti - May 12, 2010, 9:25 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>
Signed-off-by: Avi Kivity <avi@redhat.com>
---
 kvm-all.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

Patch

diff --git a/kvm-all.c b/kvm-all.c
index fbd084c..e766202 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -796,14 +796,22 @@  void kvm_flush_coalesced_mmio_buffer(void)
 #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);