From patchwork Thu Jan 27 14:20:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 80700 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6742CB7129 for ; Fri, 28 Jan 2011 01:21:14 +1100 (EST) Received: from localhost ([127.0.0.1]:47445 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PiSik-0008UL-8l for incoming@patchwork.ozlabs.org; Thu, 27 Jan 2011 09:21:10 -0500 Received: from [140.186.70.92] (port=41758 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PiSi0-0008U5-Al for qemu-devel@nongnu.org; Thu, 27 Jan 2011 09:20:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PiShz-0003Rt-3H for qemu-devel@nongnu.org; Thu, 27 Jan 2011 09:20:24 -0500 Received: from thoth.sbs.de ([192.35.17.2]:24348) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PiShy-0003RN-Qw for qemu-devel@nongnu.org; Thu, 27 Jan 2011 09:20:23 -0500 Received: from mail1.siemens.de (localhost [127.0.0.1]) by thoth.sbs.de (8.12.11.20060308/8.12.11) with ESMTP id p0REKIha010620; Thu, 27 Jan 2011 15:20:18 +0100 Received: from mchn199C.mchp.siemens.de ([139.25.109.49]) by mail1.siemens.de (8.13.6/8.13.6) with ESMTP id p0REKFOx024237; Thu, 27 Jan 2011 15:20:15 +0100 Message-ID: <4D417F1F.7020302@siemens.com> Date: Thu, 27 Jan 2011 15:20:15 +0100 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Avi Kivity , Marcelo Tosatti References: In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2 14/22] kvm: Fix race between timer signals and vcpu entry under !IOTHREAD X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. Signed-off-by: Jan Kiszka CC: Stefan Hajnoczi --- Added blocking of SIGIO/SIGALRM which was missing in previous version. Stefan just provided a test case, and that now passes. However, I realized (and checked) that this fix does not work with signalfd_compat: The signals will be swallowed by the helper thread. That affects all host kernels < 2.6.22. Given that we require 2.6.29 as baseline (unless kvm-kmod is used) and that !CONFIG_IOTHREAD is not that important for KVM mode, I tend to catch and reject CONFIG_KVM+!CONFIG_IOTHREAD+!CONFIG_SIGNALFD as unsupported during configure. Comments? cpus.c | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) 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));