From 59c9666e3986442e0997c97ffac0dfbdcf5d8323 Mon Sep 17 00:00:00 2001 From: Yaniv Kamay Date: Tue, 24 Mar 2009 14:16:52 -0300 Subject: [PATCH] Stop/start cpus before/after devices Stop cpus before devices when stopping the VM, start cpus after devices when starting VM. Otherwise a vcpu could access a stopped device. Acked-by: Dor Laor Signed-off-by: Marcelo Tosatti Signed-off-by: Avi Kivity --- qemu-kvm.c | 19 +++++-------------- qemu-kvm.h | 3 +++ vl.c | 4 ++++ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/qemu-kvm.c b/qemu-kvm.c index 93af6eab19..4164368b2d 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -285,7 +285,7 @@ static int all_threads_paused(void) return 1; } -static void pause_all_threads(void) +void qemu_kvm_pause_all_threads(void) { CPUState *penv = first_cpu; @@ -305,7 +305,7 @@ static void pause_all_threads(void) qemu_cond_wait(&qemu_pause_cond); } -static void resume_all_threads(void) +void qemu_kvm_resume_all_threads(void) { CPUState *penv = first_cpu; @@ -319,14 +319,6 @@ static void resume_all_threads(void) } } -static void kvm_vm_state_change_handler(void *context, int running, int reason) -{ - if (running) - resume_all_threads(); - else - pause_all_threads(); -} - static void update_regs_for_sipi(CPUState *env) { kvm_arch_update_regs_for_sipi(env); @@ -371,7 +363,7 @@ static void qemu_kvm_system_reset(void) { CPUState *penv = first_cpu; - pause_all_threads(); + qemu_kvm_pause_all_threads(); qemu_system_reset(); @@ -380,7 +372,7 @@ static void qemu_kvm_system_reset(void) penv = (CPUState *)penv->next_cpu; } - resume_all_threads(); + qemu_kvm_resume_all_threads(); } static int kvm_main_loop_cpu(CPUState *env) @@ -466,7 +458,6 @@ int kvm_init_ap(void) #ifdef TARGET_I386 kvm_tpr_opt_setup(); #endif - qemu_add_vm_change_state_handler(kvm_vm_state_change_handler, NULL); signal(SIG_IPI, sig_ipi_handler); return 0; @@ -610,7 +601,7 @@ int kvm_main_loop(void) #endif } - pause_all_threads(); + qemu_kvm_pause_all_threads(); pthread_mutex_unlock(&qemu_mutex); return 0; diff --git a/qemu-kvm.h b/qemu-kvm.h index c0549dfc23..ca59af8d9e 100644 --- a/qemu-kvm.h +++ b/qemu-kvm.h @@ -119,6 +119,9 @@ int qemu_kvm_register_coalesced_mmio(target_phys_addr_t addr, int qemu_kvm_unregister_coalesced_mmio(target_phys_addr_t addr, unsigned int size); +void qemu_kvm_pause_all_threads(void); +void qemu_kvm_resume_all_threads(void); + int kvm_coalesce_mmio_region(target_phys_addr_t start, ram_addr_t size); int kvm_uncoalesce_mmio_region(target_phys_addr_t start, ram_addr_t size); diff --git a/vl.c b/vl.c index 7ae266e714..c52d2d73de 100644 --- a/vl.c +++ b/vl.c @@ -3596,6 +3596,8 @@ void vm_start(void) cpu_enable_ticks(); vm_running = 1; vm_state_notify(1, 0); + if (kvm_enabled()) + qemu_kvm_resume_all_threads(); qemu_rearm_alarm_timer(alarm_timer); } } @@ -3605,6 +3607,8 @@ void vm_stop(int reason) if (vm_running) { cpu_disable_ticks(); vm_running = 0; + if (kvm_enabled()) + qemu_kvm_pause_all_threads(); vm_state_notify(0, reason); } } -- 2.11.4.GIT