From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: [PATCH 01/22] Prevent abortion on multiple VCPU kicks Date: Thu, 27 Jan 2011 14:09:45 +0100 Message-ID: References: Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org To: Avi Kivity , Marcelo Tosatti Return-path: Received: from thoth.sbs.de ([192.35.17.2]:19913 "EHLO thoth.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753045Ab1A0NK1 (ORCPT ); Thu, 27 Jan 2011 08:10:27 -0500 In-Reply-To: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org List-ID: If we call qemu_cpu_kick more than once before the target was able to process the signal, pthread_kill will fail, and qemu will abort. Prevent this by avoiding the redundant signal. This logic can be found in qemu-kvm as well. Signed-off-by: Jan Kiszka --- cpu-defs.h | 1 + cpus.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/cpu-defs.h b/cpu-defs.h index 8d4bf86..db809ed 100644 --- a/cpu-defs.h +++ b/cpu-defs.h @@ -205,6 +205,7 @@ typedef struct CPUWatchpoint { uint32_t stopped; /* Artificially stopped */ \ struct QemuThread *thread; \ struct QemuCond *halt_cond; \ + int thread_kicked; \ struct qemu_work_item *queued_work_first, *queued_work_last; \ const char *cpu_model_str; \ struct KVMState *kvm_state; \ diff --git a/cpus.c b/cpus.c index 4c9928e..ab6e40e 100644 --- a/cpus.c +++ b/cpus.c @@ -481,6 +481,7 @@ static void qemu_wait_io_event_common(CPUState *env) qemu_cond_signal(&qemu_pause_cond); } flush_queued_work(env); + env->thread_kicked = false; } static void qemu_tcg_wait_io_event(void) @@ -648,7 +649,10 @@ void qemu_cpu_kick(void *_env) { CPUState *env = _env; qemu_cond_broadcast(env->halt_cond); - qemu_thread_signal(env->thread, SIG_IPI); + if (!env->thread_kicked) { + qemu_thread_signal(env->thread, SIG_IPI); + env->thread_kicked = true; + } } int qemu_cpu_self(void *_env) -- 1.7.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=49465 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PiRcF-0001YC-D8 for qemu-devel@nongnu.org; Thu, 27 Jan 2011 08:10:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PiRc7-0000lT-3F for qemu-devel@nongnu.org; Thu, 27 Jan 2011 08:10:23 -0500 Received: from thoth.sbs.de ([192.35.17.2]:19819) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PiRc6-0000il-8K for qemu-devel@nongnu.org; Thu, 27 Jan 2011 08:10:14 -0500 From: Jan Kiszka Date: Thu, 27 Jan 2011 14:09:45 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: Subject: [Qemu-devel] [PATCH 01/22] Prevent abortion on multiple VCPU kicks List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity , Marcelo Tosatti Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org If we call qemu_cpu_kick more than once before the target was able to process the signal, pthread_kill will fail, and qemu will abort. Prevent this by avoiding the redundant signal. This logic can be found in qemu-kvm as well. Signed-off-by: Jan Kiszka --- cpu-defs.h | 1 + cpus.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/cpu-defs.h b/cpu-defs.h index 8d4bf86..db809ed 100644 --- a/cpu-defs.h +++ b/cpu-defs.h @@ -205,6 +205,7 @@ typedef struct CPUWatchpoint { uint32_t stopped; /* Artificially stopped */ \ struct QemuThread *thread; \ struct QemuCond *halt_cond; \ + int thread_kicked; \ struct qemu_work_item *queued_work_first, *queued_work_last; \ const char *cpu_model_str; \ struct KVMState *kvm_state; \ diff --git a/cpus.c b/cpus.c index 4c9928e..ab6e40e 100644 --- a/cpus.c +++ b/cpus.c @@ -481,6 +481,7 @@ static void qemu_wait_io_event_common(CPUState *env) qemu_cond_signal(&qemu_pause_cond); } flush_queued_work(env); + env->thread_kicked = false; } static void qemu_tcg_wait_io_event(void) @@ -648,7 +649,10 @@ void qemu_cpu_kick(void *_env) { CPUState *env = _env; qemu_cond_broadcast(env->halt_cond); - qemu_thread_signal(env->thread, SIG_IPI); + if (!env->thread_kicked) { + qemu_thread_signal(env->thread, SIG_IPI); + env->thread_kicked = true; + } } int qemu_cpu_self(void *_env) -- 1.7.1