From patchwork Tue May 30 16:14:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 768707 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wcdww4RBMz9s7t for ; Wed, 31 May 2017 02:14:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="oQvfXTQL"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version:content-type; q=dns; s=default; b=gzNq4 LmF72pItqw3pP2pVXov5QviOzMKvWzSwbBJH4MgrRncVkiA8IKyxBpLPO10M4J4E +1fT11+Fz3C2kLo6WepST09RVYnD8R2960fxLYDbNLMEyaEeRLTJFsTK1IIJ1L8n 4dWdMiKPKiBHX3FAs+CCw6MTJOi1gQ+oLMsEfk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version:content-type; s=default; bh=UUJGIVPp7zh jrL+FX7DI5zasfCQ=; b=oQvfXTQLUlR3CnTGwnUCL8HSPqZP/C8allwSFleUZZ/ X0zAZihxi6EIqvpgclWy+96exA9mBJCmMbalq8x/f9zVKQ6CpeMbTsa3k4hwMsbS VlH2W4h3GuFNu1CGdC6pKYq+sRA2Hf4Y6rRR+1A7GJD/k3TO72eRhc9cpCsZ8nb4 = Received: (qmail 48519 invoked by alias); 30 May 2017 16:14:42 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 48399 invoked by uid 89); 30 May 2017 16:14:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-9.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=H*Ad:U*mingo, studying X-HELO: Galois.linutronix.de Date: Tue, 30 May 2017 18:14:26 +0200 (CEST) From: Thomas Gleixner To: LKML cc: Oleg Nesterov , Linus Torvalds , Peter Zijlstra , Ingo Molnar , Michael Kerrisk , linux-man@vger.kernel.org, libc-alpha@sourceware.org Subject: Re: signals: Bug or manpage inconsistency? In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 On Tue, 30 May 2017, Thomas Gleixner wrote: > The commit which added the queuing of blocked and ignored signals is in the > history tree with a pretty useless changelog. > > https://git.kernel.org/pub/scm/linux/kernel/git/tglx/history.git > > commit 98fc8ab9e74389e0c7001052597f61336dc62833 > Author: Linus Torvalds > Date: Tue Feb 11 20:49:03 2003 -0800 > > Don't wake up processes unnecessarily for ignored signals > > It rewrites sig_ignored() and adds the following to it: > > + /* > + * Blocked signals are never ignored, since the > + * signal handler may change by the time it is > + * unblocked. > + */ > + if (sigismember(&t->blocked, sig)) > + return 0; > > I have no idea how that is related to $subject of the commit and why this > decision was made. > > Linus, any recollection? So I found at least some explanation by studying the spec some more. There are two variants of ignored signals: 1) handler is SIG_IGN 2) handler is SIG_DFL and default action is 'ignore' These are the signals in SIG_KERNEL_IGNORE_MASK #define SIG_KERNEL_IGNORE_MASK (\ rt_sigmask(SIGCONT) | rt_sigmask(SIGCHLD) | \ rt_sigmask(SIGWINCH) | rt_sigmask(SIGURG) ) These signals are not allowed to be discarded when the signal is blocked. So my understanding of the spec is: #1 Can discard the signals as long as SIG_IGN is set whether the signal is blocked or not #2 Must queue them if the signal is blocked, otherwise discard I changed the logic according to this with the patch below and a quick test run of lpt and glibc test cases produces no failures. Thoughts? Thanks, tglx 8<-------------------- Subject: signals: Reduce scope of blocked signals in sig_handler_ignored() From: Thomas Gleixner Date: Tue, 30 May 2017 18:01:33 +0200 Add proper changelog and a big fat comment in the code. Not-yet-signed-off-by: Thomas Gleixner --- kernel/signal.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) Index: b/kernel/signal.c =================================================================== --- a/kernel/signal.c +++ b/kernel/signal.c @@ -70,6 +70,13 @@ static int sig_handler_ignored(void __us (handler == SIG_DFL && sig_kernel_ignore(sig)); } +static int sig_handler_is_sigign(struct task_struct *t, int sig) +{ + void __user *handler = sig_handler(t, sig); + + return handler == SIG_IGN; +} + static int sig_task_ignored(struct task_struct *t, int sig, bool force) { void __user *handler; @@ -91,7 +98,7 @@ static int sig_ignored(struct task_struc * unblocked. */ if (sigismember(&t->blocked, sig) || sigismember(&t->real_blocked, sig)) - return 0; + return sig_handler_is_sigign(t, sig); if (!sig_task_ignored(t, sig, force)) return 0;