From: Marcelo Tosatti <mtosatti@redhat.com> To: Anthony Liguori <aliguori@us.ibm.com> Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org, Jan Kiszka <jan.kiszka@siemens.com>, Marcelo Tosatti <mtosatti@redhat.com> Subject: [PATCH 15/37] Set up signalfd under !CONFIG_IOTHREAD Date: Mon, 14 Feb 2011 13:22:44 -0200 [thread overview] Message-ID: <d0f294cec0ee25461a0a15b889929c5c7dc983cd.1297696986.git.mtosatti@redhat.com> (raw) In-Reply-To: <cover.1297696986.git.mtosatti@redhat.com> From: Jan Kiszka <jan.kiszka@siemens.com> Will be required for SIGBUS handling. For obvious reasons, this will remain a nop on Windows hosts. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> --- 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; -- 1.7.4
WARNING: multiple messages have this Message-ID (diff)
From: Marcelo Tosatti <mtosatti@redhat.com> To: Anthony Liguori <aliguori@us.ibm.com> Cc: Jan Kiszka <jan.kiszka@siemens.com>, Marcelo Tosatti <mtosatti@redhat.com>, qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 15/37] Set up signalfd under !CONFIG_IOTHREAD Date: Mon, 14 Feb 2011 13:22:44 -0200 [thread overview] Message-ID: <d0f294cec0ee25461a0a15b889929c5c7dc983cd.1297696986.git.mtosatti@redhat.com> (raw) In-Reply-To: <cover.1297696986.git.mtosatti@redhat.com> From: Jan Kiszka <jan.kiszka@siemens.com> Will be required for SIGBUS handling. For obvious reasons, this will remain a nop on Windows hosts. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> --- 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; -- 1.7.4
next prev parent reply other threads:[~2011-02-14 15:24 UTC|newest] Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-02-14 15:22 [PATCH 00/37] [PULL] qemu-kvm.git uq/master queue Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 01/37] Prevent abortion on multiple VCPU kicks Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 02/37] Stop current VCPU on synchronous reset requests Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 03/37] Process vmstop requests in IO thread Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 04/37] Trigger exit from cpu_exec_all on pending IO events Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 05/37] Leave inner main_loop faster on pending requests Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 06/37] Flatten the main loop Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 07/37] kvm: Report proper error on GET_VCPU_MMAP_SIZE failures Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 08/37] kvm: Drop redundant kvm_enabled from kvm_cpu_thread_fn Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 09/37] kvm: Handle kvm_init_vcpu errors Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 10/37] kvm: Provide sigbus services arch-independently Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 11/37] Refactor signal setup functions in cpus.c Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 12/37] kvm: Set up signal mask also for !CONFIG_IOTHREAD Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 13/37] kvm: Refactor qemu_kvm_eat_signals Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 14/37] kvm: Call qemu_kvm_eat_signals also under !CONFIG_IOTHREAD Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` Marcelo Tosatti [this message] 2011-02-14 15:22 ` [Qemu-devel] [PATCH 15/37] Set up signalfd " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 16/37] kvm: Fix race between timer signals and vcpu entry under !IOTHREAD Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 17/37] kvm: Add MCE signal support for !CONFIG_IOTHREAD Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 18/37] Introduce VCPU self-signaling service Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 19/37] kvm: Unconditionally reenter kernel after IO exits Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 20/37] kvm: Remove static return code of kvm_handle_io Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 21/37] kvm: Leave kvm_cpu_exec directly after KVM_EXIT_SHUTDOWN Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 22/37] kvm: make tsc stable over migration and machine start Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 23/37] Refactor kvm&tcg function names in cpus.c Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 24/37] Refactor cpu_has_work/any_cpu_has_work " Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 25/37] Fix a few coding style violations " Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 26/37] Improve vm_stop reason declarations Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 27/37] Refactor debug and vmstop request interface Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 28/37] Move debug exception handling out of cpu_exec Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-03-07 1:52 ` TeLeMan 2011-03-07 1:52 ` TeLeMan 2011-03-07 8:26 ` Jan Kiszka 2011-03-07 8:26 ` Jan Kiszka 2011-03-07 8:54 ` Jan Kiszka 2011-03-07 8:54 ` Jan Kiszka 2011-03-07 10:12 ` TeLeMan 2011-03-07 10:12 ` TeLeMan 2011-02-14 15:22 ` [PATCH 29/37] kvm: Separate TCG from KVM cpu execution Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:22 ` [PATCH 30/37] kvm: x86: Prepare VCPU loop for in-kernel irqchip Marcelo Tosatti 2011-02-14 15:22 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:23 ` [PATCH 31/37] kvm: Drop return values from kvm_arch_pre/post_run Marcelo Tosatti 2011-02-14 15:23 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:23 ` [PATCH 32/37] kvm: x86: Catch and report failing IRQ and NMI injections Marcelo Tosatti 2011-02-14 15:23 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:23 ` [PATCH 33/37] kvm: Remove unneeded memory slot reservation Marcelo Tosatti 2011-02-14 15:23 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:23 ` [PATCH 34/37] Introduce log_start/log_stop in CPUPhysMemoryClient Marcelo Tosatti 2011-02-14 15:23 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:23 ` [PATCH 35/37] cirrus: Remove obsolete kvm.h include Marcelo Tosatti 2011-02-14 15:23 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:23 ` [PATCH 36/37] kvm: Make kvm_state globally available Marcelo Tosatti 2011-02-14 15:23 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 15:23 ` [PATCH 37/37] kvm: x86: Introduce kvmclock device to save/restore its state Marcelo Tosatti 2011-02-14 15:23 ` [Qemu-devel] " Marcelo Tosatti 2011-02-14 20:17 ` [Qemu-devel] [PATCH 00/37] [PULL] qemu-kvm.git uq/master queue Anthony Liguori
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=d0f294cec0ee25461a0a15b889929c5c7dc983cd.1297696986.git.mtosatti@redhat.com \ --to=mtosatti@redhat.com \ --cc=aliguori@us.ibm.com \ --cc=jan.kiszka@siemens.com \ --cc=kvm@vger.kernel.org \ --cc=qemu-devel@nongnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.