From patchwork Fri Jun 5 15:01:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Mladek X-Patchwork-Id: 481372 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 0C25C140281 for ; Sat, 6 Jun 2015 01:07:33 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z0t8u-0002BZ-7V; Fri, 05 Jun 2015 15:02:44 +0000 Received: from cantor2.suse.de ([195.135.220.15] helo=mx2.suse.de) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z0t8O-0001tH-Dh for linux-mtd@lists.infradead.org; Fri, 05 Jun 2015 15:02:14 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 5BC4FADC0; Fri, 5 Jun 2015 15:01:53 +0000 (UTC) From: Petr Mladek To: Andrew Morton , Oleg Nesterov , Tejun Heo , Ingo Molnar , Peter Zijlstra Subject: [RFC PATCH 04/18] signal: Rename kernel_sigaction() to kthread_sigaction() and clean it up Date: Fri, 5 Jun 2015 17:01:03 +0200 Message-Id: <1433516477-5153-5-git-send-email-pmladek@suse.cz> X-Mailer: git-send-email 1.8.5.6 In-Reply-To: <1433516477-5153-1-git-send-email-pmladek@suse.cz> References: <1433516477-5153-1-git-send-email-pmladek@suse.cz> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150605_080212_876242_A112EC6A X-CRM114-Status: GOOD ( 19.65 ) X-Spam-Score: -5.0 (-----) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-5.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [195.135.220.15 listed in list.dnswl.org] Cc: linux-nfs@vger.kernel.org, Borislav Petkov , Jiri Kosina , Richard Weinberger , Trond Myklebust , linux-kernel@vger.kernel.org, Steven Rostedt , Michal Hocko , Chris Mason , Petr Mladek , linux-mtd@lists.infradead.org, linux-api@vger.kernel.org, Linus Torvalds , live-patching@vger.kernel.org, Thomas Gleixner , "Paul E. McKenney" , David Woodhouse , Anna Schumaker X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch defines __kthread_sighandler_t so that we do not need to force a cast from __sighandler_t when passing an address from kernel space. At the same time, it defines constants for the ignore, default, and error sigactions that could be used within the kernel space. The __force is a bit ugly but it is needed because of the ordering of includes. Finally, the patch renames kernel_sigaction() to kthread_sigaction(). We are going to add proper signal handling to kthreads and this will help to distinguish the related functions from the user-space orientated ones. Note that we will just improve the existing basic support for signals in kthreads. The patch does not have any runtime effects. It is just a cleanup. Note that it does not break the compilation with sparse. It warns when a wrong part or the union is used in a wrong context. Signed-off-by: Petr Mladek --- include/linux/signal.h | 23 ++++++++++++++++++----- kernel/kmod.c | 2 +- kernel/signal.c | 8 ++++---- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/linux/signal.h b/include/linux/signal.h index ab1e0392b5ac..06e54762c281 100644 --- a/include/linux/signal.h +++ b/include/linux/signal.h @@ -241,13 +241,26 @@ extern void __set_current_blocked(const sigset_t *); extern int show_unhandled_signals; extern int sigsuspend(sigset_t *); +typedef __signalfn_t *__kthread_sighandler_t; + +/* use the default signal handler for the kthread */ +#define KTHREAD_SIG_DFL ((__force __kthread_sighandler_t)SIG_DFL) +/* ignore the signal in the kthread */ +#define KTHREAD_SIG_IGN ((__force __kthread_sighandler_t)SIG_IGN) + struct sigaction { #ifndef __ARCH_HAS_IRIX_SIGACTION - __sighandler_t sa_handler; + union { + __sighandler_t sa_handler; + __kthread_sighandler_t kthread_sa_handler; + }; unsigned long sa_flags; #else unsigned int sa_flags; - __sighandler_t sa_handler; + union { + __sighandler_t sa_handler; + __kthread_sighandler_t kthread_sa_handler; + }; #endif #ifdef __ARCH_HAS_SA_RESTORER __sigrestore_t sa_restorer; @@ -280,7 +293,7 @@ struct ksignal { extern int get_signal(struct ksignal *ksig); extern void signal_setup_done(int failed, struct ksignal *ksig, int stepping); extern void exit_signals(struct task_struct *tsk); -extern void kernel_sigaction(int, __sighandler_t); +extern void kthread_sigaction(int, __kthread_sighandler_t); static inline void allow_signal(int sig) { @@ -289,12 +302,12 @@ static inline void allow_signal(int sig) * know it'll be handled, so that they don't get converted to * SIGKILL or just silently dropped. */ - kernel_sigaction(sig, (__force __sighandler_t)2); + kthread_sigaction(sig, (__kthread_sighandler_t)2); } static inline void disallow_signal(int sig) { - kernel_sigaction(sig, SIG_IGN); + kthread_sigaction(sig, KTHREAD_SIG_IGN); } extern struct kmem_cache *sighand_cachep; diff --git a/kernel/kmod.c b/kernel/kmod.c index 2777f40a9c7b..d45966319bcc 100644 --- a/kernel/kmod.c +++ b/kernel/kmod.c @@ -273,7 +273,7 @@ static int wait_for_helper(void *data) pid_t pid; /* If SIGCLD is ignored sys_wait4 won't populate the status. */ - kernel_sigaction(SIGCHLD, SIG_DFL); + kthread_sigaction(SIGCHLD, KTHREAD_SIG_DFL); pid = kernel_thread(____call_usermodehelper, sub_info, SIGCHLD); if (pid < 0) { sub_info->retval = pid; diff --git a/kernel/signal.c b/kernel/signal.c index d51c5ddd855c..ca6bdb411449 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -3077,11 +3077,11 @@ COMPAT_SYSCALL_DEFINE4(rt_tgsigqueueinfo, /* * For kthreads only, must not be used if cloned with CLONE_SIGHAND */ -void kernel_sigaction(int sig, __sighandler_t action) +void kthread_sigaction(int sig, __kthread_sighandler_t action) { spin_lock_irq(¤t->sighand->siglock); - current->sighand->action[sig - 1].sa.sa_handler = action; - if (action == SIG_IGN) { + current->sighand->action[sig - 1].sa.kthread_sa_handler = action; + if (action == KTHREAD_SIG_IGN) { sigset_t mask; sigemptyset(&mask); @@ -3093,7 +3093,7 @@ void kernel_sigaction(int sig, __sighandler_t action) } spin_unlock_irq(¤t->sighand->siglock); } -EXPORT_SYMBOL(kernel_sigaction); +EXPORT_SYMBOL(kthread_sigaction); int do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact) {