From patchwork Fri Feb 4 15:47:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 81907 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 DD644B7135 for ; Sat, 5 Feb 2011 03:00:33 +1100 (EST) Received: from localhost ([127.0.0.1]:36828 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PlO5H-0002cG-0U for incoming@patchwork.ozlabs.org; Fri, 04 Feb 2011 11:00:31 -0500 Received: from [140.186.70.92] (port=51720 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PlNuv-00062E-JS for qemu-devel@nongnu.org; Fri, 04 Feb 2011 10:49:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PlNut-0007zQ-R8 for qemu-devel@nongnu.org; Fri, 04 Feb 2011 10:49:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:64325) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PlNut-0007yt-J9 for qemu-devel@nongnu.org; Fri, 04 Feb 2011 10:49:47 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p14FnjPq029039 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 4 Feb 2011 10:49:46 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p14Fnj89001038; Fri, 4 Feb 2011 10:49:45 -0500 Received: from amt.cnet (vpn2-8-97.ams2.redhat.com [10.36.8.97]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p14FnhuE002227; Fri, 4 Feb 2011 10:49:44 -0500 Received: from amt.cnet (localhost.localdomain [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 49A66652149; Fri, 4 Feb 2011 13:48:34 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.4/8.14.4/Submit) id p14FmTeA017686; Fri, 4 Feb 2011 13:48:29 -0200 From: Marcelo Tosatti To: Anthony Liguori Date: Fri, 4 Feb 2011 13:47:19 -0200 Message-Id: <4a3cf4661e663df87b315d7556b047b0d8b2aa58.1296834446.git.mtosatti@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Jan Kiszka , Marcelo Tosatti , qemu-devel@nongnu.org, kvm@vger.kernel.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 16/23] 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 From: Jan Kiszka 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 Signed-off-by: Marcelo Tosatti --- configure | 6 ++++++ cpus.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletions(-) diff --git a/configure b/configure index 598e8e1..a3f5345 100755 --- a/configure +++ b/configure @@ -2057,6 +2057,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 359361f..18caf47 100644 --- a/cpus.c +++ b/cpus.c @@ -327,6 +327,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 */ @@ -376,11 +382,15 @@ static void qemu_kvm_init_cpu_signals(CPUState *env) sigemptyset(&set); sigaddset(&set, SIG_IPI); + sigaddset(&set, SIGIO); + sigaddset(&set, SIGALRM); pthread_sigmask(SIG_BLOCK, &set, NULL); pthread_sigmask(SIG_BLOCK, NULL, &set); sigdelset(&set, SIG_IPI); sigdelset(&set, SIGBUS); + sigdelset(&set, SIGIO); + sigdelset(&set, SIGALRM); r = kvm_set_signal_mask(env, &set); if (r) { fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(-r)); @@ -389,13 +399,32 @@ static void qemu_kvm_init_cpu_signals(CPUState *env) #endif } +#ifndef _WIN32 +static sigset_t block_synchronous_signals(void) +{ + sigset_t set; + + sigemptyset(&set); + if (kvm_enabled()) { + /* + * We need to process timer signals synchronously to avoid a race + * between exit_request check and KVM vcpu entry. + */ + sigaddset(&set, SIGIO); + sigaddset(&set, SIGALRM); + } + + return set; +} +#endif + int qemu_init_main_loop(void) { #ifndef _WIN32 sigset_t blocked_signals; int ret; - sigemptyset(&blocked_signals); + blocked_signals = block_synchronous_signals(); ret = qemu_signalfd_init(blocked_signals); if (ret) {