Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751931AbdFFTPM (ORCPT ); Tue, 6 Jun 2017 15:15:12 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:50491 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751561AbdFFTOv (ORCPT ); Tue, 6 Jun 2017 15:14:51 -0400 From: "Eric W. Biederman" To: linux-kernel@vger.kernel.org Cc: linux-api@vger.kernel.org, Linus Torvalds , Oleg Nesterov , Ingo Molnar , Thomas Gleixner , Kees Cook , Roland McGrath , Al Viro , David Howells , "Michael Kerrisk (man-pages)" , "Eric W. Biederman" Date: Tue, 6 Jun 2017 14:03:36 -0500 Message-Id: <20170606190338.28347-24-ebiederm@xmission.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20170606190338.28347-1-ebiederm@xmission.com> References: <877f0pym71.fsf@xmission.com> <20170606190338.28347-1-ebiederm@xmission.com> X-XM-SPF: eid=1dIJvo-0006wd-Pd;;;mid=<20170606190338.28347-24-ebiederm@xmission.com>;;;hst=in02.mta.xmission.com;;;ip=97.121.81.159;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/Za0FH9uwhKhnAflNl039iK5NSPUr2iCo= X-SA-Exim-Connect-IP: 97.121.81.159 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.0 TVD_RCVD_IP Message was received from an IP address * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;linux-kernel@vger.kernel.org X-Spam-Relay-Country: X-Spam-Timing: total 5538 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 2.4 (0.0%), b_tie_ro: 1.58 (0.0%), parse: 0.77 (0.0%), extract_message_metadata: 11 (0.2%), get_uri_detail_list: 1.44 (0.0%), tests_pri_-1000: 6 (0.1%), tests_pri_-950: 1.18 (0.0%), tests_pri_-900: 1.03 (0.0%), tests_pri_-400: 21 (0.4%), check_bayes: 20 (0.4%), b_tokenize: 7 (0.1%), b_tok_get_all: 6 (0.1%), b_comp_prob: 1.96 (0.0%), b_tok_touch_all: 2.5 (0.0%), b_finish: 0.63 (0.0%), tests_pri_0: 218 (3.9%), check_dkim_signature: 0.86 (0.0%), check_dkim_adsp: 3.7 (0.1%), tests_pri_500: 5274 (95.2%), poll_dns_idle: 5269 (95.1%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 24/26] signal: In ptrace_stop improve identical signal detection X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2440 Lines: 61 When two signals are generated make it the thread level signal that is possibly surpessed. The reasoning is that the group level signal always needs to be generated to report a group stop when that happens and it is possibly doing double duty as both the group level and the thread level signal. So if the thread level signal is identical to the group level signal it does not need to be sent (or even attempted to be sent). Signed-off-by: "Eric W. Biederman" --- kernel/signal.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index 0ec90689039a..ff41e6ee2b5e 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1813,6 +1813,7 @@ static void ptrace_stop(int exit_code, int why, int clear_code, siginfo_t *info) __acquires(¤t->sighand->siglock) { bool gstop_done = false; + bool identical = false; if (arch_ptrace_stop_needed(exit_code, info)) { /* @@ -1852,8 +1853,16 @@ static void ptrace_stop(int exit_code, int why, int clear_code, siginfo_t *info) * could be clear now. We act as if SIGCONT is received after * TASK_TRACED is entered - ignore it. */ - if (why == CLD_STOPPED && (current->jobctl & JOBCTL_STOP_PENDING)) - gstop_done = task_participate_group_stop(current); + if (why == CLD_STOPPED) { + if (current->jobctl & JOBCTL_STOP_PENDING) + gstop_done = task_participate_group_stop(current); + + /* Will the two generated signals be identical? */ + identical = gstop_done && + !(current->jobctl & JOBCTL_TRAP_NOTIFY) && + !ptrace_reparented(current) && + (task_pid(current) == task_tgid(current)); + } /* any trap clears pending STOP trap, STOP trap clears NOTIFY */ task_clear_jobctl_pending(current, JOBCTL_TRAP_STOP); @@ -1874,10 +1883,11 @@ static void ptrace_stop(int exit_code, int why, int clear_code, siginfo_t *info) * know about every stop while the real parent is only * interested in the completion of group stop. The states * for the two don't interact with each other. Notify - * separately unless they're gonna be duplicates. + * separately unless they are going to be identical. */ - do_notify_parent_cldstop(current, true, why); - if (gstop_done && ptrace_reparented(current)) + if (!identical) + do_notify_parent_cldstop(current, true, why); + if (gstop_done) do_notify_parent_cldstop(current, false, why); /* -- 2.10.1