From patchwork Tue Feb 1 21:15:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 81391 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 4AD67B7109 for ; Wed, 2 Feb 2011 09:08:33 +1100 (EST) Received: from localhost ([127.0.0.1]:58123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkOJy-00004r-6i for incoming@patchwork.ozlabs.org; Tue, 01 Feb 2011 17:03:34 -0500 Received: from [140.186.70.92] (port=47288 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkNhM-00011g-Lk for qemu-devel@nongnu.org; Tue, 01 Feb 2011 16:27:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PkNap-0003Gc-Ki for qemu-devel@nongnu.org; Tue, 01 Feb 2011 16:16:57 -0500 Received: from fmmailgate02.web.de ([217.72.192.227]:33816) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PkNao-0003FX-VA for qemu-devel@nongnu.org; Tue, 01 Feb 2011 16:16:55 -0500 Received: from smtp05.web.de ( [172.20.4.166]) by fmmailgate02.web.de (Postfix) with ESMTP id B7EEC195B1926; Tue, 1 Feb 2011 22:16:12 +0100 (CET) Received: from [88.65.41.52] (helo=localhost.localdomain) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #2) id 1PkNa8-0006FM-00; Tue, 01 Feb 2011 22:16:12 +0100 From: Jan Kiszka To: Avi Kivity , Marcelo Tosatti Date: Tue, 1 Feb 2011 22:15:52 +0100 Message-Id: <5b30c709ccbdb88a018d31fa1e520762df65af62.1296594961.git.jan.kiszka@web.de> X-Mailer: git-send-email 1.7.1 In-Reply-To: References: In-Reply-To: References: X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX1/sxCGnGGD8ex25sLQhxhKucV89IYMR7bkFaUzB e3zdzbhrqszdEU142LFpzxlCOhbl+pTTv0ksAIzPni1vPUdDoo udEOh90s0= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 217.72.192.227 Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH v2 12/24] Refactor signal setup functions in cpus.c 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 Move {tcg,kvm}_init_ipi and block_io_signals to avoid prototypes, rename the former two to clarify that they deal with more than SIG_IPI. No functional changes - except for the tiny fixup of strerror usage. The forward declaration of sigbus_handler is just temporarily, it will be moved in a succeeding patch. dummy_signal is moved into the !_WIN32 block as we will soon need it also for !CONFIG_IOTHREAD. Signed-off-by: Jan Kiszka --- cpus.c | 162 +++++++++++++++++++++++++++++++++------------------------------- 1 files changed, 83 insertions(+), 79 deletions(-) diff --git a/cpus.c b/cpus.c index 3a32828..42717ba 100644 --- a/cpus.c +++ b/cpus.c @@ -230,7 +230,15 @@ fail: close(fds[1]); return err; } -#else + +#ifdef CONFIG_IOTHREAD +static void dummy_signal(int sig) +{ +} +#endif + +#else /* _WIN32 */ + HANDLE qemu_event_handle; static void dummy_event_handler(void *opaque) @@ -256,7 +264,7 @@ static void qemu_event_increment(void) exit (1); } } -#endif +#endif /* _WIN32 */ #ifndef CONFIG_IOTHREAD int qemu_init_main_loop(void) @@ -352,10 +360,6 @@ static QemuCond qemu_system_cond; static QemuCond qemu_pause_cond; static QemuCond qemu_work_cond; -static void tcg_init_ipi(void); -static void kvm_init_ipi(CPUState *env); -static sigset_t block_io_signals(void); - /* 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. @@ -391,6 +395,77 @@ static void sigfd_handler(void *opaque) } } +static void cpu_signal(int sig) +{ + if (cpu_single_env) { + cpu_exit(cpu_single_env); + } + exit_request = 1; +} + +static void qemu_kvm_init_cpu_signals(CPUState *env) +{ + int r; + sigset_t set; + struct sigaction sigact; + + memset(&sigact, 0, sizeof(sigact)); + sigact.sa_handler = dummy_signal; + sigaction(SIG_IPI, &sigact, NULL); + + pthread_sigmask(SIG_BLOCK, NULL, &set); + sigdelset(&set, SIG_IPI); + sigdelset(&set, SIGBUS); + r = kvm_set_signal_mask(env, &set); + if (r) { + fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(-r)); + exit(1); + } +} + +static void qemu_tcg_init_cpu_signals(void) +{ + sigset_t set; + struct sigaction sigact; + + memset(&sigact, 0, sizeof(sigact)); + sigact.sa_handler = cpu_signal; + sigaction(SIG_IPI, &sigact, NULL); + + sigemptyset(&set); + sigaddset(&set, SIG_IPI); + pthread_sigmask(SIG_UNBLOCK, &set, NULL); +} + +static void sigbus_handler(int n, struct qemu_signalfd_siginfo *siginfo, + void *ctx); + +static sigset_t block_io_signals(void) +{ + sigset_t set; + struct sigaction action; + + /* SIGUSR2 used by posix-aio-compat.c */ + sigemptyset(&set); + sigaddset(&set, SIGUSR2); + pthread_sigmask(SIG_UNBLOCK, &set, NULL); + + sigemptyset(&set); + sigaddset(&set, SIGIO); + sigaddset(&set, SIGALRM); + sigaddset(&set, SIG_IPI); + sigaddset(&set, SIGBUS); + pthread_sigmask(SIG_BLOCK, &set, NULL); + + memset(&action, 0, sizeof(action)); + action.sa_flags = SA_SIGINFO; + action.sa_sigaction = (void (*)(int, siginfo_t*, void*))sigbus_handler; + sigaction(SIGBUS, &action, NULL); + prctl(PR_MCE_KILL, 1, 1, 0, 0); + + return set; +} + static int qemu_signalfd_init(sigset_t mask) { int sigfd; @@ -619,7 +694,7 @@ static void *kvm_cpu_thread_fn(void *arg) exit(1); } - kvm_init_ipi(env); + qemu_kvm_init_cpu_signals(env); /* signal CPU creation */ env->created = 1; @@ -642,7 +717,7 @@ static void *tcg_cpu_thread_fn(void *arg) { CPUState *env = arg; - tcg_init_ipi(); + qemu_tcg_init_cpu_signals(); qemu_thread_self(env->thread); /* signal CPU creation */ @@ -683,77 +758,6 @@ int qemu_cpu_self(void *_env) return qemu_thread_equal(&this, env->thread); } -static void cpu_signal(int sig) -{ - if (cpu_single_env) - cpu_exit(cpu_single_env); - exit_request = 1; -} - -static void tcg_init_ipi(void) -{ - sigset_t set; - struct sigaction sigact; - - memset(&sigact, 0, sizeof(sigact)); - sigact.sa_handler = cpu_signal; - sigaction(SIG_IPI, &sigact, NULL); - - sigemptyset(&set); - sigaddset(&set, SIG_IPI); - pthread_sigmask(SIG_UNBLOCK, &set, NULL); -} - -static void dummy_signal(int sig) -{ -} - -static void kvm_init_ipi(CPUState *env) -{ - int r; - sigset_t set; - struct sigaction sigact; - - memset(&sigact, 0, sizeof(sigact)); - sigact.sa_handler = dummy_signal; - sigaction(SIG_IPI, &sigact, NULL); - - pthread_sigmask(SIG_BLOCK, NULL, &set); - sigdelset(&set, SIG_IPI); - sigdelset(&set, SIGBUS); - r = kvm_set_signal_mask(env, &set); - if (r) { - fprintf(stderr, "kvm_set_signal_mask: %s\n", strerror(r)); - exit(1); - } -} - -static sigset_t block_io_signals(void) -{ - sigset_t set; - struct sigaction action; - - /* SIGUSR2 used by posix-aio-compat.c */ - sigemptyset(&set); - sigaddset(&set, SIGUSR2); - pthread_sigmask(SIG_UNBLOCK, &set, NULL); - - sigemptyset(&set); - sigaddset(&set, SIGIO); - sigaddset(&set, SIGALRM); - sigaddset(&set, SIG_IPI); - sigaddset(&set, SIGBUS); - pthread_sigmask(SIG_BLOCK, &set, NULL); - - memset(&action, 0, sizeof(action)); - action.sa_flags = SA_SIGINFO; - action.sa_sigaction = (void (*)(int, siginfo_t*, void*))sigbus_handler; - sigaction(SIGBUS, &action, NULL); - prctl(PR_MCE_KILL, 1, 1, 0, 0); - - return set; -} - void qemu_mutex_lock_iothread(void) { if (kvm_enabled()) {