[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 15/37] Set up signalfd under !CONFIG_IOTHREAD
From: |
Marcelo Tosatti |
Subject: |
[Qemu-devel] [PATCH 15/37] Set up signalfd under !CONFIG_IOTHREAD |
Date: |
Mon, 14 Feb 2011 13:22:44 -0200 |
From: Jan Kiszka <address@hidden>
Will be required for SIGBUS handling. For obvious reasons, this will
remain a nop on Windows hosts.
Signed-off-by: Jan Kiszka <address@hidden>
Reviewed-by: Paolo Bonzini <address@hidden>
Signed-off-by: Marcelo Tosatti <address@hidden>
---
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
- [Qemu-devel] [PATCH 19/37] kvm: Unconditionally reenter kernel after IO exits, (continued)
- [Qemu-devel] [PATCH 19/37] kvm: Unconditionally reenter kernel after IO exits, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 09/37] kvm: Handle kvm_init_vcpu errors, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 12/37] kvm: Set up signal mask also for !CONFIG_IOTHREAD, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 20/37] kvm: Remove static return code of kvm_handle_io, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 35/37] cirrus: Remove obsolete kvm.h include, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 28/37] Move debug exception handling out of cpu_exec, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 07/37] kvm: Report proper error on GET_VCPU_MMAP_SIZE failures, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 11/37] Refactor signal setup functions in cpus.c, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 23/37] Refactor kvm&tcg function names in cpus.c, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 14/37] kvm: Call qemu_kvm_eat_signals also under !CONFIG_IOTHREAD, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 15/37] Set up signalfd under !CONFIG_IOTHREAD,
Marcelo Tosatti <=
- [Qemu-devel] [PATCH 02/37] Stop current VCPU on synchronous reset requests, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 22/37] kvm: make tsc stable over migration and machine start, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 04/37] Trigger exit from cpu_exec_all on pending IO events, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 34/37] Introduce log_start/log_stop in CPUPhysMemoryClient, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 16/37] kvm: Fix race between timer signals and vcpu entry under !IOTHREAD, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 17/37] kvm: Add MCE signal support for !CONFIG_IOTHREAD, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 37/37] kvm: x86: Introduce kvmclock device to save/restore its state, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 30/37] kvm: x86: Prepare VCPU loop for in-kernel irqchip, Marcelo Tosatti, 2011/02/14
- [Qemu-devel] [PATCH 31/37] kvm: Drop return values from kvm_arch_pre/post_run, Marcelo Tosatti, 2011/02/14
- Re: [Qemu-devel] [PATCH 00/37] [PULL] qemu-kvm.git uq/master queue, Anthony Liguori, 2011/02/14