From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751570AbdDBW5W (ORCPT ); Sun, 2 Apr 2017 18:57:22 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:37195 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751033AbdDBW5U (ORCPT ); Sun, 2 Apr 2017 18:57:20 -0400 From: ebiederm@xmission.com (Eric W. Biederman) To: Oleg Nesterov Cc: Andrew Morton , Aleksa Sarai , Andy Lutomirski , Attila Fazekas , Jann Horn , Kees Cook , Michal Hocko , Ulrich Obergfell , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org References: <20170213141452.GA30203@redhat.com> <20170224160354.GA845@redhat.com> <87shmv6ufl.fsf@xmission.com> <20170303173326.GA17899@redhat.com> <87tw7axlr0.fsf@xmission.com> <87d1dyw5iw.fsf@xmission.com> <87tw7aunuh.fsf@xmission.com> <87lgsmunmj.fsf_-_@xmission.com> <20170304170312.GB13131@redhat.com> <8760ir192p.fsf@xmission.com> <878tnkpv8h.fsf_-_@xmission.com> <874ly6a0h1.fsf_-_@xmission.com> Date: Sun, 02 Apr 2017 17:51:59 -0500 In-Reply-To: <874ly6a0h1.fsf_-_@xmission.com> (Eric W. Biederman's message of "Sun, 02 Apr 2017 17:50:02 -0500") Message-ID: <87pogu8ltc.fsf_-_@xmission.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1cuoQr-0001OJ-NZ;;;mid=<87pogu8ltc.fsf_-_@xmission.com>;;;hst=in01.mta.xmission.com;;;ip=67.3.234.240;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1+GSfbOcZSONewQ/bqNw6aew4aejBFI/uU= X-SA-Exim-Connect-IP: 67.3.234.240 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 TR_Symld_Words too many words that have symbols inside * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa05 1397; Body=1 Fuz1=1 Fuz2=26] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa05 1397; Body=1 Fuz1=1 Fuz2=26 X-Spam-Combo: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 5537 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 2.5 (0.0%), b_tie_ro: 1.78 (0.0%), parse: 0.66 (0.0%), extract_message_metadata: 8 (0.1%), get_uri_detail_list: 0.94 (0.0%), tests_pri_-1000: 4.7 (0.1%), tests_pri_-950: 0.89 (0.0%), tests_pri_-900: 0.74 (0.0%), tests_pri_-400: 17 (0.3%), check_bayes: 16 (0.3%), b_tokenize: 5 (0.1%), b_tok_get_all: 5 (0.1%), b_comp_prob: 1.37 (0.0%), b_tok_touch_all: 2.5 (0.0%), b_finish: 0.47 (0.0%), tests_pri_0: 167 (3.0%), check_dkim_signature: 0.42 (0.0%), check_dkim_adsp: 2.3 (0.0%), tests_pri_500: 5334 (96.3%), poll_dns_idle: 5327 (96.2%), rewrite_mail: 0.00 (0.0%) Subject: [RFC][PATCH v2 2/5] sighand: Count each thread group once in sighand_struct 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 in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In practice either a thread group is either using a sighand_struct or it isn't. Therefore simplify things a bit and only increment the count in sighand_struct when a new thread group is created that uses the existing sighand_struct, and only decrement the count in sighand_struct when a thread group exits. As well as standing on it's own merits this has the potential to simply de_thread. Signed-off-by: "Eric W. Biederman" --- kernel/exit.c | 2 +- kernel/fork.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index e126ebf2400c..8c5b3e106298 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -163,9 +163,9 @@ static void __exit_signal(struct task_struct *tsk) tsk->sighand = NULL; spin_unlock(&sighand->siglock); - __cleanup_sighand(sighand); clear_tsk_thread_flag(tsk, TIF_SIGPENDING); if (group_dead) { + __cleanup_sighand(sighand); flush_sigqueue(&sig->shared_pending); tty_kref_put(tty); } diff --git a/kernel/fork.c b/kernel/fork.c index 6c463c80e93d..fe6f1bf32bb9 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1295,7 +1295,8 @@ static int copy_sighand(unsigned long clone_flags, struct task_struct *tsk) struct sighand_struct *sig; if (clone_flags & CLONE_SIGHAND) { - atomic_inc(¤t->sighand->count); + if (!(clone_flags & CLONE_THREAD)) + atomic_inc(¤t->sighand->count); return 0; } sig = kmem_cache_alloc(sighand_cachep, GFP_KERNEL); @@ -1896,7 +1897,8 @@ static __latent_entropy struct task_struct *copy_process( if (!(clone_flags & CLONE_THREAD)) free_signal_struct(p->signal); bad_fork_cleanup_sighand: - __cleanup_sighand(p->sighand); + if (!(clone_flags & CLONE_THREAD)) + __cleanup_sighand(p->sighand); bad_fork_cleanup_fs: exit_fs(p); /* blocking */ bad_fork_cleanup_files: -- 2.10.1 From mboxrd@z Thu Jan 1 00:00:00 1970 From: ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org (Eric W. Biederman) Subject: [RFC][PATCH v2 2/5] sighand: Count each thread group once in sighand_struct Date: Sun, 02 Apr 2017 17:51:59 -0500 Message-ID: <87pogu8ltc.fsf_-_@xmission.com> References: <20170213141452.GA30203@redhat.com> <20170224160354.GA845@redhat.com> <87shmv6ufl.fsf@xmission.com> <20170303173326.GA17899@redhat.com> <87tw7axlr0.fsf@xmission.com> <87d1dyw5iw.fsf@xmission.com> <87tw7aunuh.fsf@xmission.com> <87lgsmunmj.fsf_-_@xmission.com> <20170304170312.GB13131@redhat.com> <8760ir192p.fsf@xmission.com> <878tnkpv8h.fsf_-_@xmission.com> <874ly6a0h1.fsf_-_@xmission.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <874ly6a0h1.fsf_-_-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org> (Eric W. Biederman's message of "Sun, 02 Apr 2017 17:50:02 -0500") Sender: linux-api-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: Oleg Nesterov Cc: Andrew Morton , Aleksa Sarai , Andy Lutomirski , Attila Fazekas , Jann Horn , Kees Cook , Michal Hocko , Ulrich Obergfell , linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: linux-api@vger.kernel.org In practice either a thread group is either using a sighand_struct or it isn't. Therefore simplify things a bit and only increment the count in sighand_struct when a new thread group is created that uses the existing sighand_struct, and only decrement the count in sighand_struct when a thread group exits. As well as standing on it's own merits this has the potential to simply de_thread. Signed-off-by: "Eric W. Biederman" --- kernel/exit.c | 2 +- kernel/fork.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index e126ebf2400c..8c5b3e106298 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -163,9 +163,9 @@ static void __exit_signal(struct task_struct *tsk) tsk->sighand = NULL; spin_unlock(&sighand->siglock); - __cleanup_sighand(sighand); clear_tsk_thread_flag(tsk, TIF_SIGPENDING); if (group_dead) { + __cleanup_sighand(sighand); flush_sigqueue(&sig->shared_pending); tty_kref_put(tty); } diff --git a/kernel/fork.c b/kernel/fork.c index 6c463c80e93d..fe6f1bf32bb9 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1295,7 +1295,8 @@ static int copy_sighand(unsigned long clone_flags, struct task_struct *tsk) struct sighand_struct *sig; if (clone_flags & CLONE_SIGHAND) { - atomic_inc(¤t->sighand->count); + if (!(clone_flags & CLONE_THREAD)) + atomic_inc(¤t->sighand->count); return 0; } sig = kmem_cache_alloc(sighand_cachep, GFP_KERNEL); @@ -1896,7 +1897,8 @@ static __latent_entropy struct task_struct *copy_process( if (!(clone_flags & CLONE_THREAD)) free_signal_struct(p->signal); bad_fork_cleanup_sighand: - __cleanup_sighand(p->sighand); + if (!(clone_flags & CLONE_THREAD)) + __cleanup_sighand(p->sighand); bad_fork_cleanup_fs: exit_fs(p); /* blocking */ bad_fork_cleanup_files: -- 2.10.1