From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [PATCH 13/22] Set up signalfd under !CONFIG_IOTHREAD Date: Fri, 28 Jan 2011 09:11:32 +0100 Message-ID: References: <451506b201a2c9a84db6af26d23be751d2e65f74.1296133797.git.jan.kiszka@siemens.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: qemu-devel@nongnu.org To: kvm@vger.kernel.org Return-path: Received: from lo.gmane.org ([80.91.229.12]:32932 "EHLO lo.gmane.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755050Ab1A1IaG (ORCPT ); Fri, 28 Jan 2011 03:30:06 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PijiX-0002Co-4k for kvm@vger.kernel.org; Fri, 28 Jan 2011 09:30:05 +0100 Received: from 93-34-149-100.ip50.fastwebnet.it ([93.34.149.100]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Jan 2011 09:30:05 +0100 Received: from pbonzini by 93-34-149-100.ip50.fastwebnet.it with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Jan 2011 09:30:05 +0100 In-Reply-To: <451506b201a2c9a84db6af26d23be751d2e65f74.1296133797.git.jan.kiszka@siemens.com> Sender: kvm-owner@vger.kernel.org List-ID: On 01/27/2011 02:09 PM, Jan Kiszka wrote: > Will be required for SIGBUS handling. For obvious reasons, this will > remain a nop on Windows hosts. > > Signed-off-by: Jan Kiszka > --- > Makefile.objs | 2 +- > cpus.c | 117 +++++++++++++++++++++++++++++++-------------------------- > 2 files changed, 65 insertions(+), 54 deletions(-) > > diff --git a/Makefile.objs b/Makefile.objs > index c3e52c5..81b9a5b 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 558c0d3..fc3f222 100644 > --- a/cpus.c > +++ b/cpus.c > @@ -261,6 +261,59 @@ static void qemu_kvm_init_cpu_signals(CPUState *env) > } > } > > +/* 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 qemu_kvm_eat_signals(CPUState *env) > { > struct timespec ts = { 0, 0 }; > @@ -340,6 +393,17 @@ static void qemu_kvm_eat_signals(CPUState *env) > #ifndef CONFIG_IOTHREAD > 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(); > @@ -431,41 +495,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) { > @@ -517,24 +546,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; Reviewed-by: Paolo Bonzini Paolo From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=39618 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pijdl-0000u5-1J for qemu-devel@nongnu.org; Fri, 28 Jan 2011 03:25:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pijdi-0008Ls-RK for qemu-devel@nongnu.org; Fri, 28 Jan 2011 03:25:08 -0500 Received: from lo.gmane.org ([80.91.229.12]:50153) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pijdi-0008L8-9w for qemu-devel@nongnu.org; Fri, 28 Jan 2011 03:25:06 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Pijdg-0007Th-SN for qemu-devel@nongnu.org; Fri, 28 Jan 2011 09:25:04 +0100 Received: from 93-34-149-100.ip50.fastwebnet.it ([93.34.149.100]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Jan 2011 09:25:04 +0100 Received: from pbonzini by 93-34-149-100.ip50.fastwebnet.it with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 28 Jan 2011 09:25:04 +0100 From: Paolo Bonzini Date: Fri, 28 Jan 2011 09:11:32 +0100 Message-ID: References: <451506b201a2c9a84db6af26d23be751d2e65f74.1296133797.git.jan.kiszka@siemens.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit In-Reply-To: <451506b201a2c9a84db6af26d23be751d2e65f74.1296133797.git.jan.kiszka@siemens.com> Subject: [Qemu-devel] Re: [PATCH 13/22] Set up signalfd under !CONFIG_IOTHREAD List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org On 01/27/2011 02:09 PM, Jan Kiszka wrote: > Will be required for SIGBUS handling. For obvious reasons, this will > remain a nop on Windows hosts. > > Signed-off-by: Jan Kiszka > --- > Makefile.objs | 2 +- > cpus.c | 117 +++++++++++++++++++++++++++++++-------------------------- > 2 files changed, 65 insertions(+), 54 deletions(-) > > diff --git a/Makefile.objs b/Makefile.objs > index c3e52c5..81b9a5b 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 558c0d3..fc3f222 100644 > --- a/cpus.c > +++ b/cpus.c > @@ -261,6 +261,59 @@ static void qemu_kvm_init_cpu_signals(CPUState *env) > } > } > > +/* 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 qemu_kvm_eat_signals(CPUState *env) > { > struct timespec ts = { 0, 0 }; > @@ -340,6 +393,17 @@ static void qemu_kvm_eat_signals(CPUState *env) > #ifndef CONFIG_IOTHREAD > 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(); > @@ -431,41 +495,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) { > @@ -517,24 +546,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; Reviewed-by: Paolo Bonzini Paolo