From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: fix qemu-kvm sigsegv at exit Date: Mon, 26 Oct 2009 16:46:02 -0200 Message-ID: <20091026184602.GB6016@amt.cnet> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm To: Avi Kivity Return-path: Received: from mx1.redhat.com ([209.132.183.28]:15560 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753640AbZJZSvd (ORCPT ); Mon, 26 Oct 2009 14:51:33 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9QIpcks028810 for ; Mon, 26 Oct 2009 14:51:38 -0400 Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: Michael reported a qemu-kvm SIGSEGV at shutdown: Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x411d0940 (LWP 14446)] 0x000000000040afb4 in qemu_mod_timer (ts=0x19f0fd0, expire_time=62275467335) at /home/mst/scm/qemu-kvm/vl.c:1009 1009 if ((alarm_timer->flags & ALARM_FLAG_EXPIRED) == 0) { (gdb) l 1004 ts->next = *pt; 1005 *pt = ts; 1006 1007 /* Rearm if necessary */ 1008 if (pt == &active_timers[ts->clock->type]) { 1009 if ((alarm_timer->flags & ALARM_FLAG_EXPIRED) == 0) { 1010 qemu_rearm_alarm_timer(alarm_timer); 1011 } 1012 /* Interrupt execution to force deadline recalculation. */ 1013 if (use_icount) (gdb) p alarm_timer $1 = (struct qemu_alarm_timer *) 0x0 Problem is kvm_main_loop_wait(env, 0) can process the stop request (signalling iothread that vcpu is stopped, so its OK to exit) and continue to kvm_cpu_exec. Make sure cpu is not stopped before proceeding to kvm_cpu_exec. Signed-off-by: Marcelo Tosatti Reported-by: "Michael S. Tsirkin" diff --git a/qemu-kvm.c b/qemu-kvm.c index 4c13628..ab8f0e4 100644 --- a/qemu-kvm.c +++ b/qemu-kvm.c @@ -1868,7 +1868,8 @@ static int kvm_main_loop_cpu(CPUState *env) } if (run_cpu) { kvm_main_loop_wait(env, 0); - kvm_cpu_exec(env); + if (!is_cpu_stopped(env)) + kvm_cpu_exec(env); } else { kvm_main_loop_wait(env, 1000); }