[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 15/23] Set up signalfd under !CONFIG_IOTHREAD
From: |
Marcelo Tosatti |
Subject: |
[Qemu-devel] [PATCH 15/23] Set up signalfd under !CONFIG_IOTHREAD |
Date: |
Fri, 4 Feb 2011 13:47:18 -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 f1c7bfe..05014e9 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 861e270..359361f 100644
--- a/cpus.c
+++ b/cpus.c
@@ -235,6 +235,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)
@@ -338,6 +391,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();
@@ -430,41 +494,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) {
@@ -536,24 +565,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.2.3
- [Qemu-devel] [PATCH 21/23] kvm: Leave kvm_cpu_exec directly after KVM_EXIT_SHUTDOWN, (continued)
- [Qemu-devel] [PATCH 21/23] kvm: Leave kvm_cpu_exec directly after KVM_EXIT_SHUTDOWN, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 22/23] x86: Fix MCA broadcast parameters for TCG case, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 08/23] kvm: Drop redundant kvm_enabled from kvm_cpu_thread_fn, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 16/23] kvm: Fix race between timer signals and vcpu entry under !IOTHREAD, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 02/23] Stop current VCPU on synchronous reset requests, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 05/23] Leave inner main_loop faster on pending requests, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 20/23] kvm: Remove static return code of kvm_handle_io, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 10/23] kvm: Provide sigbus services arch-independently, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 15/23] Set up signalfd under !CONFIG_IOTHREAD,
Marcelo Tosatti <=
- [Qemu-devel] [PATCH 12/23] kvm: Set up signal mask also for !CONFIG_IOTHREAD, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 06/23] Flatten the main loop, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 01/23] Prevent abortion on multiple VCPU kicks, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 04/23] Trigger exit from cpu_exec_all on pending IO events, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 14/23] kvm: Call qemu_kvm_eat_signals also under !CONFIG_IOTHREAD, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 09/23] kvm: Handle kvm_init_vcpu errors, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 03/23] Process vmstop requests in IO thread, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 11/23] Refactor signal setup functions in cpus.c, Marcelo Tosatti, 2011/02/04
- [Qemu-devel] [PATCH 17/23] kvm: Add MCE signal support for !CONFIG_IOTHREAD, Marcelo Tosatti, 2011/02/04
- Re: [Qemu-devel] [PATCH 00/23] [PULL] qemu-kvm.git uq/master queue, Anthony Liguori, 2011/02/04