diff mbox

[6/6] qemu-kvm: use reset handler for vcpus

Message ID 20100323165347.689886209@amt.cnet (mailing list archive)
State New, archived
Headers show

Commit Message

Marcelo Tosatti March 23, 2010, 4:53 p.m. UTC
None
diff mbox

Patch

Index: qemu-kvm-cleanups/qemu-kvm.c
===================================================================
--- qemu-kvm-cleanups.orig/qemu-kvm.c
+++ qemu-kvm-cleanups/qemu-kvm.c
@@ -439,6 +439,13 @@  void kvm_disable_pit_creation(kvm_contex
     kvm->no_pit_creation = 1;
 }
 
+static void kvm_reset_vcpu(void *opaque)
+{
+    CPUState *env = opaque;
+
+    kvm_arch_cpu_reset(env);
+}
+
 static void kvm_create_vcpu(CPUState *env, int id)
 {
     long mmap_size;
@@ -473,6 +480,11 @@  static void kvm_create_vcpu(CPUState *en
                s->coalesced_mmio * PAGE_SIZE;
 #endif
 
+    r = kvm_arch_init_vcpu(env);
+    if (r == 0) {
+        qemu_register_reset(kvm_reset_vcpu, env);
+    }
+
     return;
   err_fd:
     close(env->kvm_fd);
@@ -1777,17 +1789,10 @@  static void setup_kernel_sigmask(CPUStat
 
 static void qemu_kvm_system_reset(void)
 {
-    CPUState *penv = first_cpu;
-
     pause_all_threads();
 
     qemu_system_reset();
 
-    while (penv) {
-        kvm_arch_cpu_reset(penv);
-        penv = (CPUState *) penv->next_cpu;
-    }
-
     resume_all_threads();
 }
 
@@ -1829,7 +1834,6 @@  static void *ap_main_loop(void *_env)
     env->thread_id = kvm_get_thread_id();
     sigfillset(&signals);
     sigprocmask(SIG_BLOCK, &signals, NULL);
-    kvm_create_vcpu(env, env->cpu_index);
 
 #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
     /* do ioperm for io ports of assigned devices */
@@ -1837,12 +1841,11 @@  static void *ap_main_loop(void *_env)
         on_vcpu(env, kvm_arch_do_ioperm, data);
 #endif
 
-    setup_kernel_sigmask(env);
-
     pthread_mutex_lock(&qemu_mutex);
     cpu_single_env = env;
 
-    kvm_arch_init_vcpu(env);
+    kvm_create_vcpu(env, env->cpu_index);
+    setup_kernel_sigmask(env);
 
     /* signal VCPU creation */
     current_env->created = 1;