From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=32876 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PiSue-0007Qy-HC for qemu-devel@nongnu.org; Thu, 27 Jan 2011 09:33:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PiSuc-0006Zp-8o for qemu-devel@nongnu.org; Thu, 27 Jan 2011 09:33:28 -0500 Received: from goliath.siemens.de ([192.35.17.28]:19240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PiSuc-0006Z7-0C for qemu-devel@nongnu.org; Thu, 27 Jan 2011 09:33:26 -0500 Message-ID: <4D418230.1010801@siemens.com> Date: Thu, 27 Jan 2011 15:33:20 +0100 From: Jan Kiszka MIME-Version: 1.0 References: <4D417F1F.7020302@siemens.com> In-Reply-To: <4D417F1F.7020302@siemens.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH v3 14/22] kvm: Fix race between timer signals and vcpu entry under !IOTHREAD 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, Stefan Hajnoczi Found by Stefan Hajnoczi: There is a race in kvm_cpu_exec between checking for exit_request on vcpu entry and timer signals arriving before KVM starts to catch them. Plug it by blocking both timer related signals also on !CONFIG_IOTHREAD and process those via signalfd. As this fix depends on real signalfd support (otherwise the timer signals only kick the compat helper thread, and the main thread hangs), we need to detect the invalid constellation and abort configure. Signed-off-by: Jan Kiszka CC: Stefan Hajnoczi --- I don't want to invest that much into !IOTHREAD anymore, so let's see if the proposed catch&abort is acceptable. configure | 6 ++++++ cpus.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 0 deletions(-) diff --git a/configure b/configure index 4673bf0..368ca8a 100755 --- a/configure +++ b/configure @@ -2056,6 +2056,12 @@ EOF if compile_prog "" "" ; then signalfd=yes +elif test "$kvm" = "yes" -a "$io_thread" != "yes"; then + echo + echo "ERROR: Host kernel lacks signalfd() support," + echo "but KVM depends on it when the IO thread is disabled." + echo + exit 1 fi # check if eventfd is supported diff --git a/cpus.c b/cpus.c index fc3f222..f9d9f9e 100644 --- a/cpus.c +++ b/cpus.c @@ -254,6 +254,10 @@ static void qemu_kvm_init_cpu_signals(CPUState *env) pthread_sigmask(SIG_BLOCK, NULL, &set); sigdelset(&set, SIG_IPI); sigdelset(&set, SIGBUS); +#ifndef CONFIG_IOTHREAD + sigdelset(&set, SIGIO); + sigdelset(&set, SIGALRM); +#endif r = kvm_set_signal_mask(env, &set); if (r) { fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(-r)); @@ -351,6 +355,12 @@ static void qemu_kvm_eat_signals(CPUState *env) exit(1); } } while (sigismember(&chkset, SIG_IPI) || sigismember(&chkset, SIGBUS)); + +#ifndef CONFIG_IOTHREAD + if (sigismember(&chkset, SIGIO) || sigismember(&chkset, SIGALRM)) { + qemu_notify_event(); + } +#endif } #else /* _WIN32 */ @@ -398,6 +408,14 @@ int qemu_init_main_loop(void) int ret; sigemptyset(&blocked_signals); + if (kvm_enabled()) { + /* + * We need to process timer signals synchronously to avoid a race + * between exit_request check and KVM vcpu entry. + */ + sigaddset(&blocked_signals, SIGIO); + sigaddset(&blocked_signals, SIGALRM); + } ret = qemu_signalfd_init(blocked_signals); if (ret) { @@ -535,6 +553,8 @@ static sigset_t block_io_signals(void) sigaddset(&set, SIGALRM); sigaddset(&set, SIG_IPI); sigaddset(&set, SIGBUS); + sigaddset(&set, SIGIO); + sigaddset(&set, SIGALRM); pthread_sigmask(SIG_BLOCK, &set, NULL); memset(&action, 0, sizeof(action)); -- 1.7.1