From patchwork Wed Jul 20 05:01:30 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Raymond X-Patchwork-Id: 105580 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DDA3EB6F74 for ; Wed, 20 Jul 2011 15:05:38 +1000 (EST) Received: from localhost ([::1]:56863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjOyV-0007PW-9T for incoming@patchwork.ozlabs.org; Wed, 20 Jul 2011 01:05:35 -0400 Received: from eggs.gnu.org ([140.186.70.92]:46310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjOvO-0007Oc-3y for qemu-devel@nongnu.org; Wed, 20 Jul 2011 01:02:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QjOvL-0005Cp-Do for qemu-devel@nongnu.org; Wed, 20 Jul 2011 01:02:21 -0400 Received: from mail-vx0-f173.google.com ([209.85.220.173]:49605) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjOvL-0005Bj-0T for qemu-devel@nongnu.org; Wed, 20 Jul 2011 01:02:19 -0400 Received: by mail-vx0-f173.google.com with SMTP id 29so3304581vxi.4 for ; Tue, 19 Jul 2011 22:02:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=419SYlosTGaIrtalxbHOVpacSeY2S9QEKW+vrPIkIBo=; b=D8cM4MpPndhIMoSL0JCIs/Vj6Kwc2bKBL5qsSSWoH7XU4PczmFp+eM4iRSd+fKbKPI kLThFi0R0Uz+3b/WKdP/qXc41JdX1eyU6tKPhTgGZ6qXj9dheXD45t7nBsLfObpzvyph n9Ly/48TtwuhyQNlOv/RslCMrG6Xcwn33Unjg= Received: by 10.220.84.193 with SMTP id k1mr2323197vcl.17.1311138138669; Tue, 19 Jul 2011 22:02:18 -0700 (PDT) Received: from localhost.localdomain (modemcable055.201-23-96.mc.videotron.ca [96.23.201.55]) by mx.google.com with ESMTPS id m9sm2554792vcv.40.2011.07.19.22.02.17 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 19 Jul 2011 22:02:18 -0700 (PDT) From: Alexandre Raymond To: qemu-devel@nongnu.org Date: Wed, 20 Jul 2011 01:01:30 -0400 Message-Id: <1311138090-2909-3-git-send-email-cerbere@gmail.com> X-Mailer: git-send-email 1.7.5 In-Reply-To: <1311138090-2909-1-git-send-email-cerbere@gmail.com> References: <1311138090-2909-1-git-send-email-cerbere@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.220.173 Cc: Alexandre Raymond , pbonzini@redhat.com, andreas.faerber@web.de, agraf@suse.de, jan.kiszka@siemens.com Subject: [Qemu-devel] [RFC PATCH 2/2] Signals: rework initial signal setup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org -Restructure the signal setup by creating two groups: * blocked_set, which contains signals that are ignored by QEMU or caught directly by a specific thread (e.g.: SIG_IPI). * handled_set, which contains signals handled synchronously via signalfd. Signed-off-by: Alexandre Raymond --- cpus.c | 41 +++++++++++++++++++++++------------------ 1 files changed, 23 insertions(+), 18 deletions(-) diff --git a/cpus.c b/cpus.c index f466d95..565676a 100644 --- a/cpus.c +++ b/cpus.c @@ -388,40 +388,45 @@ static void sigfd_handler(void *opaque) static int qemu_signal_init(void) { int sigfd; - sigset_t set; + /* + * - blocked_set contains signals that are handled directly by a specific + * thread such as SIG_IPI, which is caught directly by the cpu thread. + * - handled_set contains signals that are handled synchronously via the + * signal thread. + */ + sigset_t blocked_set; + sigset_t handled_set; -#ifdef CONFIG_IOTHREAD + sigemptyset(&blocked_set); + sigemptyset(&handled_set); + /* SIGUSR2 used by posix-aio-compat.c */ + sigaddset(&handled_set, SIGUSR2); + sigaddset(&handled_set, SIGBUS); +#ifdef CONFIG_IOTHREAD /* * SIG_IPI must be blocked in the main thread and must not be caught * by sigwait() in the signal thread. Otherwise, the cpu thread will * not catch it reliably. */ - sigemptyset(&set); - sigaddset(&set, SIG_IPI); - pthread_sigmask(SIG_BLOCK, &set, NULL); + sigaddset(&blocked_set, SIG_IPI); - sigemptyset(&set); - sigaddset(&set, SIGUSR2); - sigaddset(&set, SIGIO); - sigaddset(&set, SIGALRM); - sigaddset(&set, SIGBUS); + sigaddset(&handled_set, SIGIO); + sigaddset(&handled_set, SIGALRM); #else - sigemptyset(&set); - sigaddset(&set, SIGUSR2); - sigaddset(&set, SIGBUS); if (kvm_enabled()) { /* * We need to process timer signals synchronously to avoid a race * between exit_request check and KVM vcpu entry. */ - sigaddset(&set, SIGIO); - sigaddset(&set, SIGALRM); + sigaddset(&handled_set, SIGIO); + sigaddset(&handled_set, SIGALRM); } #endif - pthread_sigmask(SIG_BLOCK, &set, NULL); + pthread_sigmask(SIG_BLOCK, &blocked_set, NULL); + pthread_sigmask(SIG_BLOCK, &handled_set, NULL); - sigfd = qemu_signalfd(&set); + sigfd = qemu_signalfd(&handled_set); if (sigfd == -1) { fprintf(stderr, "failed to create signalfd\n"); return -errno;