From patchwork Mon Feb 14 15:22:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 83112 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 90313B71A3 for ; Tue, 15 Feb 2011 03:16:45 +1100 (EST) Received: from localhost ([127.0.0.1]:56126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pp16Q-0006a2-KX for incoming@patchwork.ozlabs.org; Mon, 14 Feb 2011 11:16:42 -0500 Received: from [140.186.70.92] (port=57830 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pp0IN-0000C6-N5 for qemu-devel@nongnu.org; Mon, 14 Feb 2011 10:25:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pp0IK-0003yY-1w for qemu-devel@nongnu.org; Mon, 14 Feb 2011 10:24:59 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44572) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pp0IJ-0003xM-Mu for qemu-devel@nongnu.org; Mon, 14 Feb 2011 10:24:55 -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 p1EFOrY1029358 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 14 Feb 2011 10:24:54 -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 p1EFOrhI018451; Mon, 14 Feb 2011 10:24:53 -0500 Received: from amt.cnet (vpn-11-144.rdu.redhat.com [10.11.11.144]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p1EFOpkt006225; Mon, 14 Feb 2011 10:24:51 -0500 Received: from amt.cnet (localhost.localdomain [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 78D396520C1; Mon, 14 Feb 2011 13:23:52 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.4/8.14.4/Submit) id p1EFNoj1031977; Mon, 14 Feb 2011 13:23:50 -0200 From: Marcelo Tosatti To: Anthony Liguori Date: Mon, 14 Feb 2011 13:22:44 -0200 Message-Id: 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 Subject: [Qemu-devel] [PATCH 15/37] Set up signalfd under !CONFIG_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 Will be required for SIGBUS handling. For obvious reasons, this will remain a nop on Windows hosts. Signed-off-by: Jan Kiszka Reviewed-by: Paolo Bonzini Signed-off-by: Marcelo Tosatti --- Makefile.objs | 2 +- cpus.c | 117 +++++++++++++++++++++++++++++++-------------------------- 2 files changed, 65 insertions(+), 54 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index adb5842..b21f9d3 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -141,7 +141,7 @@ common-obj-y += $(addprefix ui/, $(ui-obj-y)) common-obj-y += iov.o acl.o common-obj-$(CONFIG_THREAD) += qemu-thread.o -common-obj-$(CONFIG_IOTHREAD) += compatfd.o +common-obj-$(CONFIG_POSIX) += compatfd.o common-obj-y += notify.o event_notifier.o common-obj-y += qemu-timer.o qemu-timer-common.o diff --git a/cpus.c b/cpus.c index f2ec74c..84792f0 100644 --- a/cpus.c +++ b/cpus.c @@ -227,6 +227,59 @@ static void dummy_signal(int sig) { } +/* If we have signalfd, we mask out the signals we want to handle and then + * use signalfd to listen for them. We rely on whatever the current signal + * handler is to dispatch the signals when we receive them. + */ +static void sigfd_handler(void *opaque) +{ + int fd = (unsigned long) opaque; + struct qemu_signalfd_siginfo info; + struct sigaction action; + ssize_t len; + + while (1) { + do { + len = read(fd, &info, sizeof(info)); + } while (len == -1 && errno == EINTR); + + if (len == -1 && errno == EAGAIN) { + break; + } + + if (len != sizeof(info)) { + printf("read from sigfd returned %zd: %m\n", len); + return; + } + + sigaction(info.ssi_signo, NULL, &action); + if ((action.sa_flags & SA_SIGINFO) && action.sa_sigaction) { + action.sa_sigaction(info.ssi_signo, + (siginfo_t *)&info, NULL); + } else if (action.sa_handler) { + action.sa_handler(info.ssi_signo); + } + } +} + +static int qemu_signalfd_init(sigset_t mask) +{ + int sigfd; + + sigfd = qemu_signalfd(&mask); + if (sigfd == -1) { + fprintf(stderr, "failed to create signalfd\n"); + return -errno; + } + + fcntl_setfl(sigfd, O_NONBLOCK); + + qemu_set_fd_handler2(sigfd, NULL, sigfd_handler, NULL, + (void *)(unsigned long) sigfd); + + return 0; +} + static void sigbus_reraise(void); static void qemu_kvm_eat_signals(CPUState *env) @@ -330,6 +383,17 @@ static void qemu_kvm_init_cpu_signals(CPUState *env) int qemu_init_main_loop(void) { +#ifndef _WIN32 + sigset_t blocked_signals; + int ret; + + sigemptyset(&blocked_signals); + + ret = qemu_signalfd_init(blocked_signals); + if (ret) { + return ret; + } +#endif cpu_set_debug_excp_handler(cpu_debug_handler); return qemu_event_init(); @@ -426,41 +490,6 @@ static QemuCond qemu_system_cond; static QemuCond qemu_pause_cond; static QemuCond qemu_work_cond; -/* If we have signalfd, we mask out the signals we want to handle and then - * use signalfd to listen for them. We rely on whatever the current signal - * handler is to dispatch the signals when we receive them. - */ -static void sigfd_handler(void *opaque) -{ - int fd = (unsigned long) opaque; - struct qemu_signalfd_siginfo info; - struct sigaction action; - ssize_t len; - - while (1) { - do { - len = read(fd, &info, sizeof(info)); - } while (len == -1 && errno == EINTR); - - if (len == -1 && errno == EAGAIN) { - break; - } - - if (len != sizeof(info)) { - printf("read from sigfd returned %zd: %m\n", len); - return; - } - - sigaction(info.ssi_signo, NULL, &action); - if ((action.sa_flags & SA_SIGINFO) && action.sa_sigaction) { - action.sa_sigaction(info.ssi_signo, - (siginfo_t *)&info, NULL); - } else if (action.sa_handler) { - action.sa_handler(info.ssi_signo); - } - } -} - static void cpu_signal(int sig) { if (cpu_single_env) { @@ -532,24 +561,6 @@ static sigset_t block_io_signals(void) return set; } -static int qemu_signalfd_init(sigset_t mask) -{ - int sigfd; - - sigfd = qemu_signalfd(&mask); - if (sigfd == -1) { - fprintf(stderr, "failed to create signalfd\n"); - return -errno; - } - - fcntl_setfl(sigfd, O_NONBLOCK); - - qemu_set_fd_handler2(sigfd, NULL, sigfd_handler, NULL, - (void *)(unsigned long) sigfd); - - return 0; -} - int qemu_init_main_loop(void) { int ret;