From nobody Wed Feb 11 22:55:47 2026 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A9941E878 for ; Wed, 19 Jun 2024 04:05:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718769928; cv=none; b=n8CvBZ6lf3uPddZYNuZi1/9ypdHH3b+FZyQLwePO73rABazQ3MNM0Vde/YZWV+kx8TcipOoGSSyIfyfx1MoyVAiOTw/rE86nyVafLXawSu7u71Ztr/tDbirGZQ5qNKRYZXPizMlbbdyOKAfpFFTwhak7vBa28WRcJ+5SaFSIz0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718769928; c=relaxed/simple; bh=q2wQbY2M6W+WWZICaH3LyquyTOM9BGzcmpoj/Zh08H8=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=COZ2zf4RzsFpNETuT83tN8rhabvm3lNi8wD6dXy3XJh7YvhW0Q1iBnKWGuXBKe2MvMgI9lIz10wnY44NrcQHzbLOH1uaDQvj3SCaoqhH14PnXzU52wQa6dVv0zuULaE2LY6ZGdkCh9SRcgWImD/KIUThd8hkA2EubHNkwwT9p0g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:52086) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmZZ-00E6La-N7; Tue, 18 Jun 2024 22:05:25 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:55888 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmZY-009RKH-BN; Tue, 18 Jun 2024 22:05:25 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:05:16 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <87iky5inlv.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmZY-009RKH-BN;;;mid=<87iky5inlv.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX19qO6ww9qXWAM8xKGdWMh3T3kotA0Uo1eQ= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa04 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Spam-DCC: XMission; sa04 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 482 ms - load_scoreonly_sql: 0.06 (0.0%), signal_user_changed: 14 (2.9%), b_tie_ro: 12 (2.4%), parse: 1.54 (0.3%), extract_message_metadata: 19 (3.9%), get_uri_detail_list: 3.7 (0.8%), tests_pri_-2000: 19 (3.9%), tests_pri_-1000: 3.3 (0.7%), tests_pri_-950: 1.63 (0.3%), tests_pri_-900: 1.24 (0.3%), tests_pri_-90: 85 (17.6%), check_bayes: 83 (17.2%), b_tokenize: 10 (2.1%), b_tok_get_all: 9 (1.9%), b_comp_prob: 3.2 (0.7%), b_tok_touch_all: 56 (11.6%), b_finish: 1.16 (0.2%), tests_pri_0: 317 (65.8%), check_dkim_signature: 0.72 (0.2%), check_dkim_adsp: 3.2 (0.7%), poll_dns_idle: 0.92 (0.2%), tests_pri_10: 4.1 (0.9%), tests_pri_500: 12 (2.5%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 01/17] signal: Make SIGKILL during coredumps an explicit special case X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Simplify the code that allows SIGKILL during coredumps to terminate the coredump. As far as I can tell I have avoided breaking this case by dumb luck. Historically with all of the other threads stopping in exit_mm the wants_signal loop in complete_signal would find the dumper task and then complete_signal would wake the dumper task with signal_wake_up. After moving the coredump_task_exit above the setting of PF_EXITING in commit 92307383082d ("coredump: Don't perform any cleanups before dumping core") wants_signal will consider all of the threads in a multi-threaded process for waking up, not just the core dumping task. Luckily complete_signal short circuits SIGKILL during a coredump marks every thread with SIGKILL and signal_wake_up. This code is arguably buggy however as it tries to skip creating a group exit when is already present, and it fails that a coredump is in progress. Ever since commit 06af8679449d ("coredump: Limit what can interrupt coredumps") was added, dump_interrupted needs not just TIF_SIGPENDING set on the dumper task but also SIGKILL set in it's pending bitmap. This means that if the code is ever fixed not to short-circuit and kill a process after it has already been killed the special case for SIGKILL during a coredump will be broken. Sort all of this out by making the coredump special case more special. Perform all of the work in prepare_signal and leave the rest of the signal delivery path out of it. In prepare_signal when the process coredumping is sent SIGKILL find the task performing the coredump and use sigaddset and signal_wake_up to ensure that task reports fatal_signal_pending. Return false from prepare_signal to tell the rest of the signal delivery path to ignore the signal. Remove the "signal->core_state || !(signal->flags && SIGNAL_GROUP_EXIT)" test from complete_signal as signal delivery after process exit does not reach complete_signal. I have tested this and verified I did not break SIGKILL during coredumps by accident (before or after this change). I actually thought I had and I had to figure out what I had misread that kept SIGKILL during coredumps working. v1: https://lkml.kernel.org/r/20211213225350.27481-1-ebiederm@xmission.com Signed-off-by: "Eric W. Biederman" --- kernel/signal.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index 1f9dd41c04be..e3662fff919a 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -907,8 +907,12 @@ static bool prepare_signal(int sig, struct task_struct= *p, bool force) sigset_t flush; =20 if (signal->flags & SIGNAL_GROUP_EXIT) { - if (signal->core_state) - return sig =3D=3D SIGKILL; + if (signal->core_state && (sig =3D=3D SIGKILL)) { + struct task_struct *dumper =3D + signal->core_state->dumper.task; + sigaddset(&dumper->pending.signal, SIGKILL); + signal_wake_up(dumper, 1); + } /* * The process is in the middle of dying, drop the signal. */ @@ -1033,7 +1037,6 @@ static void complete_signal(int sig, struct task_stru= ct *p, enum pid_type type) * then start taking the whole group down immediately. */ if (sig_fatal(p, sig) && - (signal->core_state || !(signal->flags & SIGNAL_GROUP_EXIT)) && !sigismember(&t->real_blocked, sig) && (sig =3D=3D SIGKILL || !p->ptrace)) { /* --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0880E21A04 for ; Wed, 19 Jun 2024 04:05:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718769953; cv=none; b=eem9OKfpxuFf9wVJXERE0H3ClGICeUqWlGAxF1ee4V/77+IOSaJ3Zdm04kqVr8cveKTsnsGObrdcikK6jIeqQKqvdEqdDFUiWtk4dh3Ux8kN3++mAEXwDG+CSxB97klKQwU9hU0JB46pmH4U/JCENH7qY36pdoN7XGCEdnN4vTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718769953; c=relaxed/simple; bh=0LXz04i9dTCWrESR46TDgV9Iu1PXvNJ+7B87yCnsHm4=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=WbiSUDGMKQErgTUC9HtHMb25yUiFpKZjvoA8Z/wV+q3rIyza1KBg0d4MzE4ZhP6d7ONirZmH3jO4ZPELSiAVFtSR4rdbptgtuQiOSsrrP3FPktTiIH4PBivyiuQWCLSc4v1EVyVf+DBv3tLfCK8ZG2hLhUre1iffRZZuPJ5lUVU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in02.mta.xmission.com ([166.70.13.52]:38232) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmZy-00E6MB-UA; Tue, 18 Jun 2024 22:05:50 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:48484 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmZx-002rYB-W8; Tue, 18 Jun 2024 22:05:50 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:05:42 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <87cyodinl5.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmZx-002rYB-W8;;;mid=<87cyodinl5.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1+Ab7xcdTCkx2xFp2VcowCNlPj2wJXhpwk= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Virus: No X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4990] * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa01 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa01 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 374 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 4.6 (1.2%), b_tie_ro: 3.2 (0.9%), parse: 1.14 (0.3%), extract_message_metadata: 11 (2.9%), get_uri_detail_list: 1.31 (0.4%), tests_pri_-2000: 10 (2.8%), tests_pri_-1000: 1.79 (0.5%), tests_pri_-950: 1.01 (0.3%), tests_pri_-900: 0.76 (0.2%), tests_pri_-90: 120 (31.9%), check_bayes: 118 (31.5%), b_tokenize: 4.8 (1.3%), b_tok_get_all: 5 (1.5%), b_comp_prob: 1.48 (0.4%), b_tok_touch_all: 103 (27.6%), b_finish: 0.74 (0.2%), tests_pri_0: 211 (56.4%), check_dkim_signature: 0.38 (0.1%), check_dkim_adsp: 3.2 (0.8%), poll_dns_idle: 1.83 (0.5%), tests_pri_10: 2.6 (0.7%), tests_pri_500: 7 (1.9%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 02/17] signal: Compute the process exit_code in get_signal X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In prepartion for moving the work of sys_exit and sys_group_exit into get_signal compute exit_code in get_signal, make PF_SIGNALED depend on the exit_code and pass the exit_code to do_group_exit. Anytime there is a group exit the exit_code may differ from the signal number. To match the historical precedent as best I can make the exit_code 0 during exec. (The exit_code field would not have been set but probably would have been left at a value of 0). Signed-off-by: "Eric W. Biederman" --- kernel/signal.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index e3662fff919a..392d802dbf61 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2738,6 +2738,7 @@ bool get_signal(struct ksignal *ksig) for (;;) { struct k_sigaction *ka; enum pid_type type; + int exit_code; =20 /* Has this task already been marked for death? */ if ((signal->flags & SIGNAL_GROUP_EXIT) || @@ -2751,6 +2752,10 @@ bool get_signal(struct ksignal *ksig) * implies do_group_exit() or return to PF_USER_WORKER, * no need to initialize ksig->info/etc. */ + if (signal->flags & SIGNAL_GROUP_EXIT) + exit_code =3D signal->group_exit_code; + else + exit_code =3D 0; goto fatal; } =20 @@ -2872,15 +2877,17 @@ bool get_signal(struct ksignal *ksig) continue; } =20 + /* + * Anything else is fatal, maybe with a core dump. + */ + exit_code =3D signr; fatal: spin_unlock_irq(&sighand->siglock); if (unlikely(cgroup_task_frozen(current))) cgroup_leave_frozen(true); =20 - /* - * Anything else is fatal, maybe with a core dump. - */ - current->flags |=3D PF_SIGNALED; + if (exit_code & 0x7f) + current->flags |=3D PF_SIGNALED; =20 if (sig_kernel_coredump(signr)) { if (print_fatal_signals) @@ -2909,7 +2916,7 @@ bool get_signal(struct ksignal *ksig) /* * Death signals, no core dump. */ - do_group_exit(signr); + do_group_exit(exit_code); /* NOTREACHED */ } spin_unlock_irq(&sighand->siglock); --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F09FE2A8D3 for ; Wed, 19 Jun 2024 04:12:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.231 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770380; cv=none; b=rfhif6l9ew3/20WhYEuappVplefSDzobEBm/Uoy/uGEbO1DhsdOGI/h2F7rY0qQF9YmCK3kh2HYRGgWyyUG5wN0y3M5G6KBBuTtxy3Yz6Bx2ftk5odAF5Vy19JW0pvXm6U+BJtTMHSLK1ZVaxDqHJZA5KcsdLZspTQ9ESh2roHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770380; c=relaxed/simple; bh=hcUFQAxueVB1U7SwcYYc/DV9YG48AAloDLiW68bjzsI=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=NuryD2mLB3b604aDyp1D2I7kb6GNbZgFsCZ3UmM7p/tSel9H5BF7kbJrGnI+r2o0ro+aGi7pv8csVL67S92QypM51Khc3mU7nEx+HM5i4kMoJvD4MeiIT1ghwSqlIv2rL61VPwerlQfOLuVmMLixBl1cMFnV+tlbo6I8gs07Fxw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:34508) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmaP-004PJ4-LG; Tue, 18 Jun 2024 22:06:18 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:56746 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmaO-009RUo-Nc; Tue, 18 Jun 2024 22:06:17 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:06:08 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <877celinkf.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmaO-009RUo-Nc;;;mid=<877celinkf.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1+Szj+jOI9RXNy+Sb3fEgssCDHScSg1/yA= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. * 1.0 XMMoneyMeta_00 Subject Contains Money Spam X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 350 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 11 (3.2%), b_tie_ro: 10 (2.8%), parse: 0.98 (0.3%), extract_message_metadata: 12 (3.5%), get_uri_detail_list: 1.55 (0.4%), tests_pri_-2000: 13 (3.7%), tests_pri_-1000: 2.4 (0.7%), tests_pri_-950: 1.25 (0.4%), tests_pri_-900: 1.03 (0.3%), tests_pri_-90: 52 (15.0%), check_bayes: 51 (14.6%), b_tokenize: 7 (2.0%), b_tok_get_all: 6 (1.7%), b_comp_prob: 2.1 (0.6%), b_tok_touch_all: 33 (9.3%), b_finish: 0.89 (0.3%), tests_pri_0: 243 (69.4%), check_dkim_signature: 0.61 (0.2%), check_dkim_adsp: 3.0 (0.9%), poll_dns_idle: 1.12 (0.3%), tests_pri_10: 2.1 (0.6%), tests_pri_500: 8 (2.3%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 03/17] coredump: Consolidate the work to allow SIGKILL during coredumps X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Consolidate all of the work to allow SIGKILL during coredumps in zap_threads. Move the comment explaning what is happening from zap_process. Clear the per task pending SIGKILL to ensure that __fatal_signal_pending returns false, and that interruptible waits continue to wait during coredump generation. Move the atomic_set before the comment as setting nr_threads has nothing to do with allowing SIGKILL. With the work of allowing SIGKILL consolidated in zap_threads make the process tear-down in zap_process as much like the other places that set SIGKILL as possible. Include current in the set of processes being asked to exit. With the per task SIGKILL cleared in zap_threads the current process remains killable as it performs the coredump. Removing the only reason I know of for not current to exit. Separately count the tasks that will stop in coredump_task_exit that coredump_wait needs to wait for. Which tasks to count is different from which tasks to signal, and the logic need to remain even when task exiting is unified. Signed-off-by: "Eric W. Biederman" --- fs/coredump.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index a57a06b80f57..be0405346882 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -366,18 +366,17 @@ static int zap_process(struct task_struct *start, int= exit_code) struct task_struct *t; int nr =3D 0; =20 - /* Allow SIGKILL, see prepare_signal() */ start->signal->flags =3D SIGNAL_GROUP_EXIT; start->signal->group_exit_code =3D exit_code; start->signal->group_stop_count =3D 0; =20 for_each_thread(start, t) { task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); - if (t !=3D current && !(t->flags & PF_POSTCOREDUMP)) { + if (!(t->flags & PF_POSTCOREDUMP)) { sigaddset(&t->pending.signal, SIGKILL); signal_wake_up(t, 1); - nr++; } + nr +=3D (t !=3D current) && !(t->flags & PF_POSTCOREDUMP); } =20 return nr; @@ -393,9 +392,12 @@ static int zap_threads(struct task_struct *tsk, if (!(signal->flags & SIGNAL_GROUP_EXIT) && !signal->group_exec_task) { signal->core_state =3D core_state; nr =3D zap_process(tsk, exit_code); + atomic_set(&core_state->nr_threads, nr); + + /* Allow SIGKILL, see prepare_signal() */ clear_tsk_thread_flag(tsk, TIF_SIGPENDING); + sigdelset(&tsk->pending.signal, SIGKILL); tsk->flags |=3D PF_DUMPCORE; - atomic_set(&core_state->nr_threads, nr); } spin_unlock_irq(&tsk->sighand->siglock); return nr; --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 865BF1E878 for ; Wed, 19 Jun 2024 04:06:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770006; cv=none; b=eNHqPiGOcZy8Gh79wtjn0261ZqMpucDjhOlBxAvndcsnlXhuKD6rSArAUUl4XaLmrlAv7OIOq0omIzBc6yF6NJrYyEwckvkwvUdqjtMZ9bJMFMEngo/j136g7EL5u5XLiMjsqjIcxRWncrgzuloFxfAGXFHUwsTQnvPB68iT5R8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770006; c=relaxed/simple; bh=fjQaafk/Rm+2nL3ouvn0B9Us3sRSiAV4htBW8U3yqz8=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=DBxMPHFcoRQRyP1FVr8hJeQeGkWsoEUI3F98wCCsdtU901VlBKtshMhoLoqOfyjehk3QVzqmf+vTZ1f8l+FyGCIrmWCzdUTEOQ4MuraEyx5BzouJKMrmZgEfPszE0VRilQhGBrgLttFCWhdVHzfbZxlr0I77oYhUXX1NkpnYdy8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in02.mta.xmission.com ([166.70.13.52]:54142) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmap-00E6Vx-DW; Tue, 18 Jun 2024 22:06:43 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:36228 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmao-002rij-HO; Tue, 18 Jun 2024 22:06:43 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:06:33 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <871q4tinjq.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmao-002rij-HO;;;mid=<871q4tinjq.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX18nk/aH0Ch9VSe+bG0PF1Bvf/4AwkcIeCM= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4976] * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 357 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 9 (2.5%), b_tie_ro: 8 (2.2%), parse: 1.22 (0.3%), extract_message_metadata: 13 (3.7%), get_uri_detail_list: 1.66 (0.5%), tests_pri_-2000: 13 (3.5%), tests_pri_-1000: 2.3 (0.6%), tests_pri_-950: 1.21 (0.3%), tests_pri_-900: 0.97 (0.3%), tests_pri_-90: 68 (19.1%), check_bayes: 67 (18.8%), b_tokenize: 7 (1.9%), b_tok_get_all: 6 (1.7%), b_comp_prob: 2.0 (0.6%), b_tok_touch_all: 49 (13.7%), b_finish: 0.85 (0.2%), tests_pri_0: 233 (65.4%), check_dkim_signature: 0.57 (0.2%), check_dkim_adsp: 3.2 (0.9%), poll_dns_idle: 1.29 (0.4%), tests_pri_10: 3.0 (0.8%), tests_pri_500: 9 (2.5%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 04/17] signal: In get_signal call do_exit when it is unnecessary to shoot down threads X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In get_signal if other threads of the current process do not need to be shoot down calling do_group_exit is equivalent to calling do_exit. The code in get_signal is only responsible for shooting down threads when it dequeues a signal and decides the signal is fatal. To remove special cases and make the code easier to read, call do_exit instead of do_group_exit when no other threads need to be shoot down. With do_group_exit no longer being called when exec is terminating threads in de_thread remove the special case in do_group_exit for handling exec. Signed-off-by: "Eric W. Biederman" --- kernel/exit.c | 4 ---- kernel/signal.c | 7 ++++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index f95a2c1338a8..08de33740b9c 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -1001,8 +1001,6 @@ do_group_exit(int exit_code) =20 if (sig->flags & SIGNAL_GROUP_EXIT) exit_code =3D sig->group_exit_code; - else if (sig->group_exec_task) - exit_code =3D 0; else { struct sighand_struct *const sighand =3D current->sighand; =20 @@ -1010,8 +1008,6 @@ do_group_exit(int exit_code) if (sig->flags & SIGNAL_GROUP_EXIT) /* Another thread got here before we took the lock. */ exit_code =3D sig->group_exit_code; - else if (sig->group_exec_task) - exit_code =3D 0; else { sig->group_exit_code =3D exit_code; sig->flags =3D SIGNAL_GROUP_EXIT; diff --git a/kernel/signal.c b/kernel/signal.c index 392d802dbf61..caeaff81a197 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2736,6 +2736,7 @@ bool get_signal(struct ksignal *ksig) } =20 for (;;) { + bool group_exit_needed =3D false; struct k_sigaction *ka; enum pid_type type; int exit_code; @@ -2881,6 +2882,7 @@ bool get_signal(struct ksignal *ksig) * Anything else is fatal, maybe with a core dump. */ exit_code =3D signr; + group_exit_needed =3D true; fatal: spin_unlock_irq(&sighand->siglock); if (unlikely(cgroup_task_frozen(current))) @@ -2916,7 +2918,10 @@ bool get_signal(struct ksignal *ksig) /* * Death signals, no core dump. */ - do_group_exit(exit_code); + if (group_exit_needed) + do_group_exit(exit_code); + else + do_exit(exit_code); /* NOTREACHED */ } spin_unlock_irq(&sighand->siglock); --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E69A1E878 for ; Wed, 19 Jun 2024 04:07:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770032; cv=none; b=QLGJrG1rONzJxxHRnJ3b9nOvqR+VfiW+HQkNUtIFDeOKO75St06owQ15o9F2GxiAOVJPelo+tBDKx13oJHTlaPb/4nrshSGk5x5KYxyyiUcLrXF8IPOumwXgQzDWjm6sgAab1AGBb0LUa6UALVxaqHfYWcZvGXlVqVTnzL/qSgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770032; c=relaxed/simple; bh=i+m7kUTGynqCmryG7YxhUOK/9KsV3QYutaznmVWfxmg=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=f0NRcZJmtxt0uX98Zve41C7arvenMjbEjnsE4ctArfqPpZj9G0gP68VwT+RExJN4TNE5gBS+EqwTRUy334YZ7AgQBmE/4wbT4fXGLYfdH6PMNLw010qmaUjHGGHn/L3nihd9QsP8b24FNV6uKlJZvpYj3J2XuULvVVtoBRwH38M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in02.mta.xmission.com ([166.70.13.52]:42174) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmbG-005ubB-57; Tue, 18 Jun 2024 22:07:10 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:55932 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmbF-002rlL-6O; Tue, 18 Jun 2024 22:07:09 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:07:01 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <87v825h8yi.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmbF-002rlL-6O;;;mid=<87v825h8yi.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1/y2ryawxIpgt1oI8YJofl+KVxOOknMOMc= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.7 XMSubLong Long Subject * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa08 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Spam-DCC: XMission; sa08 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 383 ms - load_scoreonly_sql: 0.08 (0.0%), signal_user_changed: 15 (3.9%), b_tie_ro: 12 (3.2%), parse: 1.13 (0.3%), extract_message_metadata: 14 (3.5%), get_uri_detail_list: 1.09 (0.3%), tests_pri_-2000: 13 (3.3%), tests_pri_-1000: 2.3 (0.6%), tests_pri_-950: 1.46 (0.4%), tests_pri_-900: 1.13 (0.3%), tests_pri_-90: 183 (47.6%), check_bayes: 180 (47.0%), b_tokenize: 4.3 (1.1%), b_tok_get_all: 7 (1.8%), b_comp_prob: 2.00 (0.5%), b_tok_touch_all: 162 (42.2%), b_finish: 1.44 (0.4%), tests_pri_0: 138 (36.1%), check_dkim_signature: 0.50 (0.1%), check_dkim_adsp: 3.0 (0.8%), poll_dns_idle: 1.21 (0.3%), tests_pri_10: 2.3 (0.6%), tests_pri_500: 9 (2.4%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 05/17] signal: Bring down all threads when handling a non-coredump fatal signal X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" For non-coredump fatal signals instead of dropping and reacquiring siglock to shoot down the other threads from do_group_exit at the end of get_signal, shot down the other threads before siglock is dropped. This can not be done for coredump signals yet, because do_coredump needs to be in a position to catch dying threads before it kills them so it can make certain to catch them, so they can be added to the coredump. Signed-off-by: "Eric W. Biederman" --- kernel/signal.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kernel/signal.c b/kernel/signal.c index caeaff81a197..269ec88f650d 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2882,7 +2882,13 @@ bool get_signal(struct ksignal *ksig) * Anything else is fatal, maybe with a core dump. */ exit_code =3D signr; - group_exit_needed =3D true; + if (sig_kernel_coredump(signr)) + group_exit_needed =3D true; + else { + signal->group_exit_code =3D exit_code; + signal->flags =3D SIGNAL_GROUP_EXIT; + zap_other_threads(current); + } fatal: spin_unlock_irq(&sighand->siglock); if (unlikely(cgroup_task_frozen(current))) --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEF7821A04 for ; Wed, 19 Jun 2024 04:07:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770056; cv=none; b=tX2MOv1uJdMsta3uZ1Q8dAS6Xyyy2wGs1GzqcveMAV3ZfA1VzFDX/e6nv9qEoEma352VW0ahMoCEMjkSGRfHdnXcs38LhJbLPiyUqNiKFhq84YjaJHy/uUZ5uRptWQOjHFLCCeIV+O7f15fnCpBKQgQ8anxInIgI/S/6DNth+SY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770056; c=relaxed/simple; bh=K6Iay5pFDdcwxqEtxQTV2xD54wTqZzBwd5YUhYpkhPk=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=tXSOCG6pkwGUTKUj6TNAMRDHJvr2gWq7b1xi6zyixsCGJCNUJ/tDOW7HbZQ3qebWuFTxiSTa9jvqZUUoiUGHYAvIf+eyYIL5SVOVGDZeqZW39SY1imqdhzHY3LuiWUJZVlM1k96xT5gKHsXAaLNxknh8XwG8tB+O/H9624CXbp8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:42706) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmbd-00E6YB-Ni; Tue, 18 Jun 2024 22:07:33 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:35360 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmbc-009Rcs-KZ; Tue, 18 Jun 2024 22:07:33 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:07:26 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <87plsdh8xt.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmbc-009Rcs-KZ;;;mid=<87plsdh8xt.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1/PErfWajg1E24d8ogSO60aQE13VchzCaU= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. * 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: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 528 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 11 (2.1%), b_tie_ro: 10 (1.8%), parse: 1.09 (0.2%), extract_message_metadata: 13 (2.5%), get_uri_detail_list: 2.7 (0.5%), tests_pri_-2000: 13 (2.5%), tests_pri_-1000: 2.5 (0.5%), tests_pri_-950: 1.28 (0.2%), tests_pri_-900: 1.04 (0.2%), tests_pri_-90: 86 (16.4%), check_bayes: 85 (16.0%), b_tokenize: 11 (2.1%), b_tok_get_all: 9 (1.7%), b_comp_prob: 2.5 (0.5%), b_tok_touch_all: 58 (11.0%), b_finish: 1.09 (0.2%), tests_pri_0: 382 (72.4%), check_dkim_signature: 0.87 (0.2%), check_dkim_adsp: 2.9 (0.6%), poll_dns_idle: 0.81 (0.2%), tests_pri_10: 3.1 (0.6%), tests_pri_500: 10 (1.8%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 06/17] signal: Add JOBCTL_WILL_EXIT to mark exiting tasks X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Mark tasks that need to exit with JOBCTL_WILL_EXIT instead of reusing the per thread SIGKILL. A jobctl flag was choosen for this purpose because jobctl changes are protected by siglock, and updates are already careful not to change or clear other bits in jobctl. Protection by a lock when changing the value is necessary as JOBCTL_WILL_EXIT will not be limited to being set by the current task. That task->jobctl is protected by siglock is convenient as siglock is already held everywhere I want to set or reset JOBCTL_WILL_EXIT. Instead of having __fatal_signal_pending test JOBCTL_WILL_EXIT directly add a more accurately named helper task_will_exit to test JOBCTL_WILL_EXIT that __fatal_signal_pending calls. Signed-off-by: "Eric W. Biederman" --- fs/coredump.c | 4 ++-- include/linux/sched/jobctl.h | 2 ++ include/linux/sched/signal.h | 7 ++++++- kernel/signal.c | 11 ++++++----- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index be0405346882..bec9e290802a 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -373,7 +373,7 @@ static int zap_process(struct task_struct *start, int e= xit_code) for_each_thread(start, t) { task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); if (!(t->flags & PF_POSTCOREDUMP)) { - sigaddset(&t->pending.signal, SIGKILL); + t->jobctl |=3D JOBCTL_WILL_EXIT; signal_wake_up(t, 1); } nr +=3D (t !=3D current) && !(t->flags & PF_POSTCOREDUMP); @@ -396,7 +396,7 @@ static int zap_threads(struct task_struct *tsk, =20 /* Allow SIGKILL, see prepare_signal() */ clear_tsk_thread_flag(tsk, TIF_SIGPENDING); - sigdelset(&tsk->pending.signal, SIGKILL); + tsk->jobctl &=3D ~JOBCTL_WILL_EXIT; tsk->flags |=3D PF_DUMPCORE; } spin_unlock_irq(&tsk->sighand->siglock); diff --git a/include/linux/sched/jobctl.h b/include/linux/sched/jobctl.h index 68876d0a7ef9..2e840f2db746 100644 --- a/include/linux/sched/jobctl.h +++ b/include/linux/sched/jobctl.h @@ -23,6 +23,7 @@ struct task_struct; =20 #define JOBCTL_STOPPED_BIT 26 /* do_signal_stop() */ #define JOBCTL_TRACED_BIT 27 /* ptrace_stop() */ +#define JOBCTL_WILL_EXIT_BIT 31 /* task will exit */ =20 #define JOBCTL_STOP_DEQUEUED (1UL << JOBCTL_STOP_DEQUEUED_BIT) #define JOBCTL_STOP_PENDING (1UL << JOBCTL_STOP_PENDING_BIT) @@ -36,6 +37,7 @@ struct task_struct; =20 #define JOBCTL_STOPPED (1UL << JOBCTL_STOPPED_BIT) #define JOBCTL_TRACED (1UL << JOBCTL_TRACED_BIT) +#define JOBCTL_WILL_EXIT (1UL << JOBCTL_WILL_EXIT_BIT) =20 #define JOBCTL_TRAP_MASK (JOBCTL_TRAP_STOP | JOBCTL_TRAP_NOTIFY) #define JOBCTL_PENDING_MASK (JOBCTL_STOP_PENDING | JOBCTL_TRAP_MASK) diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 0a0e23c45406..33bf363a3354 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -393,9 +393,14 @@ static inline int signal_pending(struct task_struct *p) return task_sigpending(p); } =20 +static inline bool task_exit_pending(struct task_struct *p) +{ + return unlikely(READ_ONCE(p->jobctl) & JOBCTL_WILL_EXIT); +} + static inline int __fatal_signal_pending(struct task_struct *p) { - return unlikely(sigismember(&p->pending.signal, SIGKILL)); + return task_exit_pending(p); } =20 static inline int fatal_signal_pending(struct task_struct *p) diff --git a/kernel/signal.c b/kernel/signal.c index 269ec88f650d..ea7753b31be7 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -156,7 +156,8 @@ static inline bool has_pending_signals(sigset_t *signal= , sigset_t *blocked) =20 static bool recalc_sigpending_tsk(struct task_struct *t) { - if ((t->jobctl & (JOBCTL_PENDING_MASK | JOBCTL_TRAP_FREEZE)) || + if ((t->jobctl & (JOBCTL_PENDING_MASK | JOBCTL_TRAP_FREEZE | + JOBCTL_WILL_EXIT)) || PENDING(&t->pending, &t->blocked) || PENDING(&t->signal->shared_pending, &t->blocked) || cgroup_task_frozen(t)) { @@ -910,7 +911,7 @@ static bool prepare_signal(int sig, struct task_struct = *p, bool force) if (signal->core_state && (sig =3D=3D SIGKILL)) { struct task_struct *dumper =3D signal->core_state->dumper.task; - sigaddset(&dumper->pending.signal, SIGKILL); + dumper->jobctl |=3D JOBCTL_WILL_EXIT; signal_wake_up(dumper, 1); } /* @@ -1054,7 +1055,7 @@ static void complete_signal(int sig, struct task_stru= ct *p, enum pid_type type) signal->group_stop_count =3D 0; __for_each_thread(signal, t) { task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); - sigaddset(&t->pending.signal, SIGKILL); + t->jobctl |=3D JOBCTL_WILL_EXIT; signal_wake_up(t, 1); } return; @@ -1383,7 +1384,7 @@ int zap_other_threads(struct task_struct *p) /* Don't bother with already dead threads */ if (t->exit_state) continue; - sigaddset(&t->pending.signal, SIGKILL); + t->jobctl |=3D JOBCTL_WILL_EXIT; signal_wake_up(t, 1); } =20 @@ -2745,7 +2746,7 @@ bool get_signal(struct ksignal *ksig) if ((signal->flags & SIGNAL_GROUP_EXIT) || signal->group_exec_task) { signr =3D SIGKILL; - sigdelset(¤t->pending.signal, SIGKILL); + current->jobctl &=3D ~JOBCTL_WILL_EXIT; trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO, &sighand->action[SIGKILL-1]); recalc_sigpending(); --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D8A2C1E878 for ; Wed, 19 Jun 2024 04:08:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770105; cv=none; b=QmElTDg36IsQp0NXYyFxlqS4K5Vh9cYebKTKWQSQbgLjG0s54ecMETSQtl5T1HGWbDn0BLHlQaZYyNvNM2imHG+UD2dTic3OPEZkdrHcEBZAPMmPVXpwkwOqnU7sFLTM1R5KsTPsWvKzVr7knB3h8fFu7rKJWJjewYbYrwClVbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770105; c=relaxed/simple; bh=QH+DAI3nDRMv0sqQ0yqjwXEumeM6njYB9SC659wkAYA=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=WNL8lEUmF3eVemFuUlnP65EZbHK6ijz2jIB5zsVokDKahZl7TfZugfy9uciiXEKEDT9hWcSBFOv61UiVzMvAAzh6YYXrnYg+Vw9cQqejKkaeuzIKs7DAHya40tdZIcDpkUPUYCczmzVQSRSkngt/rGSAIDkjMs7ygw7krYSGwYw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:38394) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmcQ-005ucK-MC; Tue, 18 Jun 2024 22:08:22 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:40308 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmcP-009Rix-DV; Tue, 18 Jun 2024 22:08:22 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:08:14 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <87h6dph8wh.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmcP-009Rix-DV;;;mid=<87h6dph8wh.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1+ENUfgGe2dDkLUgk0AlTk9w8VqTBFhMT4= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Virus: No X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4987] * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.7 XMSubLong Long Subject * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa02 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa02 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 424 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 4.8 (1.1%), b_tie_ro: 3.4 (0.8%), parse: 1.23 (0.3%), extract_message_metadata: 12 (2.9%), get_uri_detail_list: 2.9 (0.7%), tests_pri_-2000: 11 (2.5%), tests_pri_-1000: 1.80 (0.4%), tests_pri_-950: 1.07 (0.3%), tests_pri_-900: 0.78 (0.2%), tests_pri_-90: 61 (14.4%), check_bayes: 60 (14.2%), b_tokenize: 7 (1.7%), b_tok_get_all: 8 (1.9%), b_comp_prob: 1.76 (0.4%), b_tok_touch_all: 40 (9.4%), b_finish: 0.62 (0.1%), tests_pri_0: 317 (74.9%), check_dkim_signature: 0.41 (0.1%), check_dkim_adsp: 3.2 (0.8%), poll_dns_idle: 1.98 (0.5%), tests_pri_10: 2.2 (0.5%), tests_pri_500: 7 (1.7%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 07/17] signal: Always set JOBCTL_WILL_EXIT for exiting tasks X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is a semantic change. Previously JOBCTL_WILL_EXIT replaced the use of sigaddset(&t->pending.signal, SIGKILL) to mark tasks for termination but was otherwise identical. Now JOBCTL_WILL_EXIT once set remains set (except possibly for the thread performing a coredump). Keeping JOBCTL_WILL_EXIT set makes it possible to detect and skip unnecessary work when the decision has been made for a task to exit. Getting there involves not clearing JOBCTL_WILL_EXIT when short circuited signals are being processed, and setting JOBCTL_WILL_EXIT on all tasks when SIGNAL_GROUP_EXIT is set. Never clearing JOBCTL_WILL_EXIT requires updating ptrace_stop so it will continue to stop in PTRACE_EVENT_EXIT. Set JOBCTL_WILL_EXIT in coredump_finish so that it winds up on the coredumping thread. It was initially set in zap_process when all of the tasks of the processed were asked to exit, and then cleared in zap_threads so that the coredump thread can be killed. Signed-off-by: "Eric W. Biederman" --- fs/coredump.c | 1 + kernel/exit.c | 2 ++ kernel/signal.c | 20 ++++++++++++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index bec9e290802a..c8b057724bf6 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -443,6 +443,7 @@ static void coredump_finish(bool core_dumped) current->signal->group_exit_code |=3D 0x80; next =3D current->signal->core_state->dumper.next; current->signal->core_state =3D NULL; + current->jobctl |=3D JOBCTL_WILL_EXIT; spin_unlock_irq(¤t->sighand->siglock); =20 while ((curr =3D next) !=3D NULL) { diff --git a/kernel/exit.c b/kernel/exit.c index 08de33740b9c..0059c60946a3 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -801,6 +801,7 @@ static void synchronize_group_exit(struct task_struct *= tsk, long code) struct signal_struct *signal =3D tsk->signal; =20 spin_lock_irq(&sighand->siglock); + tsk->jobctl |=3D JOBCTL_WILL_EXIT; signal->quick_threads--; if ((signal->quick_threads =3D=3D 0) && !(signal->flags & SIGNAL_GROUP_EXIT)) { @@ -1012,6 +1013,7 @@ do_group_exit(int exit_code) sig->group_exit_code =3D exit_code; sig->flags =3D SIGNAL_GROUP_EXIT; zap_other_threads(current); + current->jobctl |=3D JOBCTL_WILL_EXIT; } spin_unlock_irq(&sighand->siglock); } diff --git a/kernel/signal.c b/kernel/signal.c index ea7753b31be7..d169b47775b0 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2253,15 +2253,19 @@ static int ptrace_stop(int exit_code, int why, unsi= gned long message, spin_lock_irq(¤t->sighand->siglock); } =20 - /* - * After this point ptrace_signal_wake_up or signal_wake_up - * will clear TASK_TRACED if ptrace_unlink happens or a fatal - * signal comes in. Handle previous ptrace_unlinks and fatal - * signals here to prevent ptrace_stop sleeping in schedule. - */ - if (!current->ptrace || __fatal_signal_pending(current)) + /* Do not stop if ptrace_unlink has happened. */ + if (!current->ptrace) + return exit_code; + + /* Do not stop in a killed task except for PTRACE_EVENT_EXIT */ + if (task_exit_pending(current) && + ((exit_code >> 8) !=3D PTRACE_EVENT_EXIT)) return exit_code; =20 + /* + * After this point ptrace_unlink or a fatal signal will clear + * TASK_TRACED preventing ptrace_stop from sleeping. + */ set_special_state(TASK_TRACED); current->jobctl |=3D JOBCTL_TRACED; =20 @@ -2746,7 +2750,6 @@ bool get_signal(struct ksignal *ksig) if ((signal->flags & SIGNAL_GROUP_EXIT) || signal->group_exec_task) { signr =3D SIGKILL; - current->jobctl &=3D ~JOBCTL_WILL_EXIT; trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO, &sighand->action[SIGKILL-1]); recalc_sigpending(); @@ -2889,6 +2892,7 @@ bool get_signal(struct ksignal *ksig) signal->group_exit_code =3D exit_code; signal->flags =3D SIGNAL_GROUP_EXIT; zap_other_threads(current); + current->jobctl |=3D JOBCTL_WILL_EXIT; } fatal: spin_unlock_irq(&sighand->siglock); --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8452C1E878 for ; Wed, 19 Jun 2024 04:08:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770135; cv=none; b=s0MA8EtxIY/1y5R9z7DOp9OS/b3eJik8COACbFYFB2LFISOc0IELGkS7mJ2slz9IFdNYjZyiH4jM+XvjmWs20quTxop0TInHKkxcGt6tltaFumltPmV4V210Vooy1eIu7DknVLAU7LCFbXNrFo8E/jb9J7s2OVLSfpeamBk12z4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770135; c=relaxed/simple; bh=l+zcJ9ggR0nX8sADXoEpzsJOzpB5V9+0+3iv8sug3h8=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=bu+t1dm2yl/rJHSnJY09JWKkOVYOsgGi0LUXkmzNE244/HpjQPSTVdGQEKXwGR3MFow4NQYFEdMD3nHnd1be7/M8SN9kRjxG/H/xoqscQI9RKprRauBtVgKByAsnZ0uEPFW3ReNXbBvcOKBXIf+HHL7tIzbL2ibIus1h2aPO9UE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:40576) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmcv-005ud7-C9; Tue, 18 Jun 2024 22:08:53 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:43974 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmcu-009Rm5-D8; Tue, 18 Jun 2024 22:08:52 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:08:45 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <87bk3xh8vm.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmcu-009Rm5-D8;;;mid=<87bk3xh8vm.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1/wn0KJUa+Ve3aKlybryx15IbrIX1Ru1nE= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: * X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 1.5 XMNoVowels Alpha-numberic number with no vowels * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. * 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: *;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 284 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 11 (4.0%), b_tie_ro: 10 (3.4%), parse: 0.91 (0.3%), extract_message_metadata: 12 (4.1%), get_uri_detail_list: 1.04 (0.4%), tests_pri_-2000: 13 (4.7%), tests_pri_-1000: 2.5 (0.9%), tests_pri_-950: 1.29 (0.5%), tests_pri_-900: 1.03 (0.4%), tests_pri_-90: 54 (19.1%), check_bayes: 53 (18.6%), b_tokenize: 6 (2.1%), b_tok_get_all: 4.9 (1.7%), b_comp_prob: 1.88 (0.7%), b_tok_touch_all: 37 (12.9%), b_finish: 0.93 (0.3%), tests_pri_0: 172 (60.5%), check_dkim_signature: 0.61 (0.2%), check_dkim_adsp: 2.9 (1.0%), poll_dns_idle: 1.05 (0.4%), tests_pri_10: 3.1 (1.1%), tests_pri_500: 10 (3.5%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 08/17] signal: Don't target tasks that are exiting X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Teach wants_signal and retarget_shared_pending to use JOBCTL_TASK_EXITING to detect threads that have an exit pending and so will not be processing any more signals. Teach task_set_jobctl_pending to directly examine JOBCTL_WILL_EXIT rather than looking at PF_EXITING and fatal_signal_pending as those are redundant. Signed-off-by: "Eric W. Biederman" --- kernel/signal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/signal.c b/kernel/signal.c index d169b47775b0..5e67c00b9b30 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -281,7 +281,7 @@ bool task_set_jobctl_pending(struct task_struct *task, = unsigned long mask) JOBCTL_STOP_SIGMASK | JOBCTL_TRAPPING)); BUG_ON((mask & JOBCTL_TRAPPING) && !(mask & JOBCTL_PENDING_MASK)); =20 - if (unlikely(fatal_signal_pending(task) || (task->flags & PF_EXITING))) + if (unlikely(task->jobctl & JOBCTL_WILL_EXIT)) return false; =20 if (mask & JOBCTL_STOP_SIGMASK) @@ -985,7 +985,7 @@ static inline bool wants_signal(int sig, struct task_st= ruct *p) if (sigismember(&p->blocked, sig)) return false; =20 - if (p->flags & PF_EXITING) + if (p->jobctl & JOBCTL_WILL_EXIT) return false; =20 if (sig =3D=3D SIGKILL) @@ -2998,7 +2998,7 @@ static void retarget_shared_pending(struct task_struc= t *tsk, sigset_t *which) return; =20 for_other_threads(tsk, t) { - if (t->flags & PF_EXITING) + if (t->jobctl & JOBCTL_WILL_EXIT) continue; =20 if (!has_pending_signals(&retarget, &t->blocked)) --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2C2154662 for ; Wed, 19 Jun 2024 04:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770160; cv=none; b=S8/NcY7JIJD8FCeenMddFH1SedOSdRUVqCC6VQLldQGQH/cBqpwiQJn3OImqYXd8jM/75J8M+dYgvm5IhbTVpZXcI2/LjqVTKcEOYZptsOJ+lTPeRdPiTmWWo+0TqZgbCB8IH7NA0GIlMUt9lngKFWwpjR/yviySIpp1LEqBScA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770160; c=relaxed/simple; bh=on75TvsnuOnLH39i72mJSk2U6xcE0g8EbXgYf5NSlh0=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=jz6QEZWD+T7zOUqw3+ZYSDvfyvgFj6w4ynmf3nacIlemdxmHTIDAhw+U4FyF4hw1Fzz2nemfPxFHjoHwJNrJ7KdmLgS2x8TuzJovXb8vq49FyWA4wyD4ePo9LVGHjxAHt7IkN4ynJeX9BqtznDmLJOQXGigGd+b9Pm6I2q7+bxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:59772) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmdJ-00E6b0-Tq; Tue, 18 Jun 2024 22:09:17 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:50614 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmdJ-009Rob-0L; Tue, 18 Jun 2024 22:09:17 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:09:09 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <875xu5h8uy.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmdJ-009Rob-0L;;;mid=<875xu5h8uy.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1/qO7lFALjLBQW/RXKc2YVN6kfltibVIdk= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 333 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 11 (3.4%), b_tie_ro: 10 (3.0%), parse: 1.20 (0.4%), extract_message_metadata: 13 (4.0%), get_uri_detail_list: 1.95 (0.6%), tests_pri_-2000: 13 (3.8%), tests_pri_-1000: 2.3 (0.7%), tests_pri_-950: 1.21 (0.4%), tests_pri_-900: 0.98 (0.3%), tests_pri_-90: 58 (17.3%), check_bayes: 56 (16.8%), b_tokenize: 7 (2.1%), b_tok_get_all: 6 (1.9%), b_comp_prob: 1.88 (0.6%), b_tok_touch_all: 38 (11.4%), b_finish: 0.84 (0.3%), tests_pri_0: 216 (65.0%), check_dkim_signature: 0.51 (0.2%), check_dkim_adsp: 2.7 (0.8%), poll_dns_idle: 0.92 (0.3%), tests_pri_10: 2.9 (0.9%), tests_pri_500: 10 (2.9%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 09/17] signal: Test for process exit or de_thread using task_exit_pending X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Replace "(sig->flags & SIGNAL_GROUP_EXIT || sig->group_exec_task)" with "task_exit_pending(tsk)". THis is just a code simplification. Every case that sets SIGNAL_GROUP_EXIT also sets JOBCTL_WILL_EXIT. Similarly de_thread sets JOBCTL_WILL_EXIT except for the one task that will exist after exec. Signed-off-by: "Eric W. Biederman" --- fs/coredump.c | 2 +- fs/exec.c | 2 +- kernel/signal.c | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index c8b057724bf6..f3e363fa09a3 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -389,7 +389,7 @@ static int zap_threads(struct task_struct *tsk, int nr =3D -EAGAIN; =20 spin_lock_irq(&tsk->sighand->siglock); - if (!(signal->flags & SIGNAL_GROUP_EXIT) && !signal->group_exec_task) { + if (!task_exit_pending(tsk)) { signal->core_state =3D core_state; nr =3D zap_process(tsk, exit_code); atomic_set(&core_state->nr_threads, nr); diff --git a/fs/exec.c b/fs/exec.c index 40073142288f..0d64313716bf 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1080,7 +1080,7 @@ static int de_thread(struct task_struct *tsk) * Kill all other threads in the thread group. */ spin_lock_irq(lock); - if ((sig->flags & SIGNAL_GROUP_EXIT) || sig->group_exec_task) { + if (task_exit_pending(tsk)) { /* * Another group action in progress, just * return so that the signal is processed. diff --git a/kernel/signal.c b/kernel/signal.c index 5e67c00b9b30..12e552a35848 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2450,8 +2450,7 @@ static bool do_signal_stop(int signr) WARN_ON_ONCE(signr & ~JOBCTL_STOP_SIGMASK); =20 if (!likely(current->jobctl & JOBCTL_STOP_DEQUEUED) || - unlikely(sig->flags & SIGNAL_GROUP_EXIT) || - unlikely(sig->group_exec_task)) + unlikely(task_exit_pending(current))) return false; /* * There is no group stop already in progress. We must @@ -2747,8 +2746,7 @@ bool get_signal(struct ksignal *ksig) int exit_code; =20 /* Has this task already been marked for death? */ - if ((signal->flags & SIGNAL_GROUP_EXIT) || - signal->group_exec_task) { + if (task_exit_pending(current)) { signr =3D SIGKILL; trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO, &sighand->action[SIGKILL-1]); --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB16337700 for ; Wed, 19 Jun 2024 04:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770194; cv=none; b=uIVs4UEV3WyC3awlX4p2SGKyIwTk+oe4yvECPWpc9gPZ0NVFQi90uXHi+Oqysdviu6wzyJWbkolhPH3WjfMd0zR91ZrSn5heA30Pzs6VYaPMr06AKzhwLGBIabsMLUH5pEs5t197/O/sEFXRP6TDgLo99Ql5GyHeVMFjh3sfMU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770194; c=relaxed/simple; bh=W3pzOWYZJCJl1SnV1PqgzDFAFs70sGWEAYZOvp6wREc=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=U9bzPrNrD+NRHnA5sYRHKI/NaOq3k3FUNdJ70Y8C1mr/DcUmi/ATvQhmTe3S64vsifTyM8gT28r8JnWaVnC1tCcNrt4Y4QhWLzo7M6WalEPqQx7ftkWhEMe8THw0mulAlRQzmHoO3/XP9H03Wd9lZPkO1iZOhHXv6hyrbnpge0Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:52846) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmdr-00E6bM-Qr; Tue, 18 Jun 2024 22:09:51 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:45984 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmdq-009RsZ-Qm; Tue, 18 Jun 2024 22:09:51 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:09:44 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <87zfrhfu9j.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmdq-009RsZ-Qm;;;mid=<87zfrhfu9j.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1/PC7QFBj9tG64nO2e/p6KeXGHe8TNQDvY= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * 0.2 XM_B_SpammyWords One or more commonly used spammy words * -0.0 T_SCC_BODY_TEXT_LINE No description available. * 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: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 402 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 12 (3.0%), b_tie_ro: 10 (2.5%), parse: 1.29 (0.3%), extract_message_metadata: 15 (3.6%), get_uri_detail_list: 2.7 (0.7%), tests_pri_-2000: 13 (3.1%), tests_pri_-1000: 2.3 (0.6%), tests_pri_-950: 1.24 (0.3%), tests_pri_-900: 0.96 (0.2%), tests_pri_-90: 64 (16.0%), check_bayes: 63 (15.6%), b_tokenize: 11 (2.7%), b_tok_get_all: 7 (1.6%), b_comp_prob: 2.1 (0.5%), b_tok_touch_all: 40 (9.9%), b_finish: 0.94 (0.2%), tests_pri_0: 277 (68.8%), check_dkim_signature: 0.55 (0.1%), check_dkim_adsp: 3.0 (0.7%), poll_dns_idle: 1.20 (0.3%), tests_pri_10: 3.1 (0.8%), tests_pri_500: 10 (2.4%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 10/17] signal: Only set JOBCTL_WILL_EXIT if it is not already set X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The various code paths that set JOBCTL_WILL_EXIT optimize away setting JOBCTL_WILL_EXIT and calling signal_wake_up based on different conditions. If the task has already committed itself to exiting by setting JOBCTL_WILL_EXIT, setting JOBCTL_WILL_EXIT will accomplish nothing. So instead of using any of the original conditions only set JOBCTL_WILL_EXIT when JOBCTL_WILL_EXIT is not set. Additionally skip task_clear_jobctl_pending once JOBCTL_WILL_EXIT has been set as task_set_jobctl_pending won't set any pending bits after that. Signed-off-by: "Eric W. Biederman" --- fs/coredump.c | 4 ++-- kernel/exit.c | 5 ++++- kernel/signal.c | 21 +++++++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index f3e363fa09a3..bcef41ec69a9 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -371,8 +371,8 @@ static int zap_process(struct task_struct *start, int e= xit_code) start->signal->group_stop_count =3D 0; =20 for_each_thread(start, t) { - task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); - if (!(t->flags & PF_POSTCOREDUMP)) { + if (!(t->jobctl & JOBCTL_WILL_EXIT)) { + task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); t->jobctl |=3D JOBCTL_WILL_EXIT; signal_wake_up(t, 1); } diff --git a/kernel/exit.c b/kernel/exit.c index 0059c60946a3..73eb3afbf083 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -801,7 +801,10 @@ static void synchronize_group_exit(struct task_struct = *tsk, long code) struct signal_struct *signal =3D tsk->signal; =20 spin_lock_irq(&sighand->siglock); - tsk->jobctl |=3D JOBCTL_WILL_EXIT; + if (!(tsk->jobctl & JOBCTL_WILL_EXIT)) { + task_clear_jobctl_pending(tsk, JOBCTL_PENDING_MASK); + tsk->jobctl |=3D JOBCTL_WILL_EXIT; + } signal->quick_threads--; if ((signal->quick_threads =3D=3D 0) && !(signal->flags & SIGNAL_GROUP_EXIT)) { diff --git a/kernel/signal.c b/kernel/signal.c index 12e552a35848..341717c6cc97 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -911,8 +911,10 @@ static bool prepare_signal(int sig, struct task_struct= *p, bool force) if (signal->core_state && (sig =3D=3D SIGKILL)) { struct task_struct *dumper =3D signal->core_state->dumper.task; - dumper->jobctl |=3D JOBCTL_WILL_EXIT; - signal_wake_up(dumper, 1); + if (!(dumper->jobctl & JOBCTL_WILL_EXIT)) { + dumper->jobctl |=3D JOBCTL_WILL_EXIT; + signal_wake_up(dumper, 1); + } } /* * The process is in the middle of dying, drop the signal. @@ -1054,9 +1056,11 @@ static void complete_signal(int sig, struct task_str= uct *p, enum pid_type type) signal->group_exit_code =3D sig; signal->group_stop_count =3D 0; __for_each_thread(signal, t) { - task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); - t->jobctl |=3D JOBCTL_WILL_EXIT; - signal_wake_up(t, 1); + if (!(t->jobctl & JOBCTL_WILL_EXIT)) { + task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); + t->jobctl |=3D JOBCTL_WILL_EXIT; + signal_wake_up(t, 1); + } } return; } @@ -1378,12 +1382,13 @@ int zap_other_threads(struct task_struct *p) p->signal->group_stop_count =3D 0; =20 for_other_threads(p, t) { - task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); count++; =20 - /* Don't bother with already dead threads */ - if (t->exit_state) + /* Only bother with threads that might be alive */ + if (t->jobctl & JOBCTL_WILL_EXIT) continue; + + task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); t->jobctl |=3D JOBCTL_WILL_EXIT; signal_wake_up(t, 1); } --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70A9B1E878 for ; Wed, 19 Jun 2024 04:10:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.231 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770218; cv=none; b=JlQf0eczW/KmteYC31X/ltMGI13rdM940A2vuvanoHMgl5eabtATbq9axZYNqCrkQbACENZlAAZQg8QR6M088ZbV1tnYflQUi6UiE+iwsq5t5Z0QYFMC/P0Vrs0YWtic+gaGZm0FWqNxrBLLjG8EQjp0l2iPERge+ptGzsznlXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770218; c=relaxed/simple; bh=V0wIUt5HPjbJ6P9U7BxdMTY3xdPgMdiqjjqtH60Ki9M=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=rt3waUfogv1Fd3FJ05bgXiTxDTASC1jzLHQH5myPWMYxcbiGygnA9zjYUEKgJHGLfPvxmRL7m13a6IxFCMuP+cqBvsLbIOmr3d2GQXCloOwPZv7az7OEij5bWMGn61rphBWhV48+Kz8OxqIC0BJ3znutU3IeXQMH50eAVmljKQE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:54274) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmeG-004POC-6s; Tue, 18 Jun 2024 22:10:16 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:47492 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmeF-009RwG-4t; Tue, 18 Jun 2024 22:10:15 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:10:08 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <87tthpfu8v.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmeF-009RwG-4t;;;mid=<87tthpfu8v.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX18uezSPVsxUbrkq7vk2KmijE3ISWn2ED8w= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: * X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.7 XMSubLong Long Subject * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa08 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Spam-DCC: XMission; sa08 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 395 ms - load_scoreonly_sql: 0.07 (0.0%), signal_user_changed: 15 (3.9%), b_tie_ro: 13 (3.3%), parse: 1.30 (0.3%), extract_message_metadata: 14 (3.6%), get_uri_detail_list: 2.6 (0.7%), tests_pri_-2000: 12 (3.0%), tests_pri_-1000: 2.2 (0.6%), tests_pri_-950: 1.40 (0.4%), tests_pri_-900: 1.18 (0.3%), tests_pri_-90: 84 (21.3%), check_bayes: 82 (20.8%), b_tokenize: 8 (2.1%), b_tok_get_all: 9 (2.3%), b_comp_prob: 2.6 (0.7%), b_tok_touch_all: 57 (14.5%), b_finish: 1.36 (0.3%), tests_pri_0: 247 (62.6%), check_dkim_signature: 0.59 (0.2%), check_dkim_adsp: 3.3 (0.8%), poll_dns_idle: 1.63 (0.4%), tests_pri_10: 2.7 (0.7%), tests_pri_500: 9 (2.3%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 11/17] signal: Make individual tasks exiting a first class concept X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a helper schedule_task_exit_locked that is equivalent to asynchronously calling exit(2) except for not having an exit code. This is a generalization of what happens in do_exit, de_thread, zap_process, prepare_signal, complete_signal, and zap_other_threads when individual tasks are asked to shutdown. While schedule_task_exit_locked is a generalization of what happens in prepare_signal I do not change prepare_signal to use schedule_task_exit_locked to deliver SIGKILL to a coredumping process. This keeps all of the specialness of delivering a signal to a coredumping process limited to prepare_signal and the coredump code itself. Signed-off-by: "Eric W. Biederman" --- fs/coredump.c | 6 +----- include/linux/sched/signal.h | 2 ++ kernel/exit.c | 5 +---- kernel/signal.c | 25 +++++++++++-------------- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index bcef41ec69a9..dce91e5c121a 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -371,11 +371,7 @@ static int zap_process(struct task_struct *start, int = exit_code) start->signal->group_stop_count =3D 0; =20 for_each_thread(start, t) { - if (!(t->jobctl & JOBCTL_WILL_EXIT)) { - task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); - t->jobctl |=3D JOBCTL_WILL_EXIT; - signal_wake_up(t, 1); - } + schedule_task_exit_locked(t); nr +=3D (t !=3D current) && !(t->flags & PF_POSTCOREDUMP); } =20 diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 33bf363a3354..48b67162b38c 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -462,6 +462,8 @@ static inline void ptrace_signal_wake_up(struct task_st= ruct *t, bool resume) signal_wake_up_state(t, state); } =20 +void schedule_task_exit_locked(struct task_struct *task); + void task_join_group_stop(struct task_struct *task); =20 #ifdef TIF_RESTORE_SIGMASK diff --git a/kernel/exit.c b/kernel/exit.c index 73eb3afbf083..902af3beb7cc 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -801,10 +801,7 @@ static void synchronize_group_exit(struct task_struct = *tsk, long code) struct signal_struct *signal =3D tsk->signal; =20 spin_lock_irq(&sighand->siglock); - if (!(tsk->jobctl & JOBCTL_WILL_EXIT)) { - task_clear_jobctl_pending(tsk, JOBCTL_PENDING_MASK); - tsk->jobctl |=3D JOBCTL_WILL_EXIT; - } + schedule_task_exit_locked(tsk); signal->quick_threads--; if ((signal->quick_threads =3D=3D 0) && !(signal->flags & SIGNAL_GROUP_EXIT)) { diff --git a/kernel/signal.c b/kernel/signal.c index 341717c6cc97..ac4ac3aeda0a 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1056,11 +1056,7 @@ static void complete_signal(int sig, struct task_str= uct *p, enum pid_type type) signal->group_exit_code =3D sig; signal->group_stop_count =3D 0; __for_each_thread(signal, t) { - if (!(t->jobctl & JOBCTL_WILL_EXIT)) { - task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); - t->jobctl |=3D JOBCTL_WILL_EXIT; - signal_wake_up(t, 1); - } + schedule_task_exit_locked(t); } return; } @@ -1371,6 +1367,15 @@ int force_sig_info(struct kernel_siginfo *info) return force_sig_info_to_task(info, current, HANDLER_CURRENT); } =20 +void schedule_task_exit_locked(struct task_struct *task) +{ + if (!(task->jobctl & JOBCTL_WILL_EXIT)) { + task_clear_jobctl_pending(task, JOBCTL_PENDING_MASK); + task->jobctl |=3D JOBCTL_WILL_EXIT; + signal_wake_up(task, true); + } +} + /* * Nuke all other threads in the group. */ @@ -1383,16 +1388,8 @@ int zap_other_threads(struct task_struct *p) =20 for_other_threads(p, t) { count++; - - /* Only bother with threads that might be alive */ - if (t->jobctl & JOBCTL_WILL_EXIT) - continue; - - task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK); - t->jobctl |=3D JOBCTL_WILL_EXIT; - signal_wake_up(t, 1); + schedule_task_exit_locked(t); } - return count; } =20 --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB9AB5674D for ; Wed, 19 Jun 2024 04:10:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770245; cv=none; b=n3N4NOXuZG0b48rIsLb57q5xvnbIojnmNXcdRh0UBoOLgGuLezGfvPJuZaC+mzro5qRDwoO3gU3yAUca1NDwCcUzaguIasMZo9iZJyMq3Z+HitVYyVnI7Um3To5Pud31uRofLOAJf1WzsqJQeymr9aaT6ACy1hDOE8sHX90eyrs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770245; c=relaxed/simple; bh=45db+cBhok/OVJqOrcrMq9W2H4YzWN6x6K1kdcGkQJs=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=ZyVhCJj0LEJw471D1aRetLS5S6feGxGq0+iY1OI5IfgWsTcrst4gX4Ry3E/smdBM9VBl+qx45iY3FXOwXdFXdO3cubaI41nYYs/g90ib3efvFZXxE7c7K+G11OYaagU3Z4FEjYf18eXJc12hPHfdP9+n2mQ6fyE8nH7EjGcSjV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:59680) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmeg-005ufz-Qr; Tue, 18 Jun 2024 22:10:42 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:49564 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmef-009RzG-SJ; Tue, 18 Jun 2024 22:10:42 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:10:34 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <87o77xfu85.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmef-009RzG-SJ;;;mid=<87o77xfu85.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX18+I/REcgM7LhAWKGG9i1btRuVe5W37LQY= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4978] * 1.5 XMNoVowels Alpha-numberic number with no vowels * 1.2 LotsOfNums_01 BODY: Lots of long strings of numbers * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa08 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Spam-DCC: XMission; sa08 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 380 ms - load_scoreonly_sql: 0.11 (0.0%), signal_user_changed: 16 (4.1%), b_tie_ro: 13 (3.4%), parse: 1.52 (0.4%), extract_message_metadata: 14 (3.8%), get_uri_detail_list: 2.2 (0.6%), tests_pri_-2000: 12 (3.3%), tests_pri_-1000: 2.7 (0.7%), tests_pri_-950: 1.59 (0.4%), tests_pri_-900: 1.14 (0.3%), tests_pri_-90: 65 (17.0%), check_bayes: 63 (16.5%), b_tokenize: 9 (2.5%), b_tok_get_all: 9 (2.4%), b_comp_prob: 1.95 (0.5%), b_tok_touch_all: 37 (9.8%), b_finish: 1.35 (0.4%), tests_pri_0: 251 (66.2%), check_dkim_signature: 0.56 (0.1%), check_dkim_adsp: 3.3 (0.9%), poll_dns_idle: 1.52 (0.4%), tests_pri_10: 2.2 (0.6%), tests_pri_500: 9 (2.2%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 12/17] signal: Remove zap_other_threads X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The three callers of zap_other_threads want different things. The function do_group_exit wants to set the exit code and it does not care about the number of threads exiting. In de_thread the current thread is not exiting so there is not really an exit code. Since schedule_task_exit_locked factors out the tricky bits stop sharing the loop in zap_other_threads between de_thread, get_signal and do_group_exit. Signed-off-by: "Eric W. Biederman" --- fs/exec.c | 12 +++++++++--- include/linux/sched/signal.h | 1 - kernel/exit.c | 9 ++++++++- kernel/signal.c | 25 +++++++------------------ 4 files changed, 24 insertions(+), 23 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 0d64313716bf..57d617917b1c 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1072,6 +1072,7 @@ static int de_thread(struct task_struct *tsk) struct signal_struct *sig =3D tsk->signal; struct sighand_struct *oldsighand =3D tsk->sighand; spinlock_t *lock =3D &oldsighand->siglock; + struct task_struct *t; =20 if (thread_group_empty(tsk)) goto no_thread_group; @@ -1090,9 +1091,14 @@ static int de_thread(struct task_struct *tsk) } =20 sig->group_exec_task =3D tsk; - sig->notify_count =3D zap_other_threads(tsk); - if (!thread_group_leader(tsk)) - sig->notify_count--; + sig->group_stop_count =3D 0; + sig->notify_count =3D 0; + __for_each_thread(sig, t) { + if (t =3D=3D tsk) + continue; + sig->notify_count++; + schedule_task_exit_locked(t); + } =20 while (sig->notify_count) { __set_current_state(TASK_KILLABLE); diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 48b67162b38c..250bd537aa6a 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -338,7 +338,6 @@ extern void force_sig(int); extern void force_fatal_sig(int); extern void force_exit_sig(int); extern int send_sig(int, struct task_struct *, int); -extern int zap_other_threads(struct task_struct *p); extern struct sigqueue *sigqueue_alloc(void); extern void sigqueue_free(struct sigqueue *); extern int send_sigqueue(struct sigqueue *, struct pid *, enum pid_type); diff --git a/kernel/exit.c b/kernel/exit.c index 902af3beb7cc..564bf17f4589 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -1010,9 +1010,16 @@ do_group_exit(int exit_code) /* Another thread got here before we took the lock. */ exit_code =3D sig->group_exit_code; else { + struct task_struct *t; + sig->group_exit_code =3D exit_code; sig->flags =3D SIGNAL_GROUP_EXIT; - zap_other_threads(current); + sig->group_stop_count =3D 0; + __for_each_thread(sig, t) { + if (t =3D=3D current) + continue; + schedule_task_exit_locked(t); + } current->jobctl |=3D JOBCTL_WILL_EXIT; } spin_unlock_irq(&sighand->siglock); diff --git a/kernel/signal.c b/kernel/signal.c index ac4ac3aeda0a..2b0f6d8baebb 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1376,23 +1376,6 @@ void schedule_task_exit_locked(struct task_struct *t= ask) } } =20 -/* - * Nuke all other threads in the group. - */ -int zap_other_threads(struct task_struct *p) -{ - struct task_struct *t; - int count =3D 0; - - p->signal->group_stop_count =3D 0; - - for_other_threads(p, t) { - count++; - schedule_task_exit_locked(t); - } - return count; -} - struct sighand_struct *__lock_task_sighand(struct task_struct *tsk, unsigned long *flags) { @@ -2744,6 +2727,7 @@ bool get_signal(struct ksignal *ksig) for (;;) { bool group_exit_needed =3D false; struct k_sigaction *ka; + struct task_struct *t; enum pid_type type; int exit_code; =20 @@ -2891,7 +2875,12 @@ bool get_signal(struct ksignal *ksig) else { signal->group_exit_code =3D exit_code; signal->flags =3D SIGNAL_GROUP_EXIT; - zap_other_threads(current); + signal->group_stop_count =3D 0; + __for_each_thread(signal, t) { + if (t =3D=3D current) + continue; + schedule_task_exit_locked(t); + } current->jobctl |=3D JOBCTL_WILL_EXIT; } fatal: --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 190B74C635 for ; Wed, 19 Jun 2024 04:11:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770288; cv=none; b=d75VVOej+sbP9PjsT+YwK96G9tqVEZNU7LoXndcl4RANoV4MdQtlv3GMAxExZb4sv/Q9UJtZQc6xSjhnER6b2NUMt+CrH87am0P6AURSfB4KUlYPsoV34zRcjVwac0c3slj9s1pYoHgLM8A1KyxSWe+lTpH7+i4C+I8eHik7Wi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770288; c=relaxed/simple; bh=rI1/8Q3NCRHP7HCE6BEWfKYBhNQWkf+MwGAKNKeEfXU=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=V8fKg7XWNZb3YVtf/Y733TkP/YuwbOWMWvhSx1BnPzlnkzv+aJVyJFHMevQElj/9rYhFzjggIg5lWunGvN68+wxMUL/ber1W84mVY5m5ux7APqmrePBu2mccwKwZehHTzSAinel8pABr7UrEXTZxdOTDRURnAZmdVIDF6FJbIe0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:45972) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmfN-005ugk-Nu; Tue, 18 Jun 2024 22:11:25 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:43580 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmfM-009S3x-NM; Tue, 18 Jun 2024 22:11:25 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:11:17 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <87iky5fu6y.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmfM-009S3x-NM;;;mid=<87iky5fu6y.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1/myM0LuKtJuEsnUnXa7k2cvouZldYHIIY= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4982] * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. * 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: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 305 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 12 (3.9%), b_tie_ro: 10 (3.4%), parse: 1.09 (0.4%), extract_message_metadata: 13 (4.1%), get_uri_detail_list: 1.32 (0.4%), tests_pri_-2000: 13 (4.3%), tests_pri_-1000: 2.3 (0.8%), tests_pri_-950: 1.22 (0.4%), tests_pri_-900: 0.96 (0.3%), tests_pri_-90: 74 (24.2%), check_bayes: 72 (23.6%), b_tokenize: 6 (1.9%), b_tok_get_all: 4.7 (1.5%), b_comp_prob: 1.67 (0.5%), b_tok_touch_all: 57 (18.6%), b_finish: 1.01 (0.3%), tests_pri_0: 173 (56.6%), check_dkim_signature: 0.50 (0.2%), check_dkim_adsp: 2.9 (0.9%), poll_dns_idle: 1.08 (0.4%), tests_pri_10: 3.1 (1.0%), tests_pri_500: 9 (3.0%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 13/17] signal: Stop skipping current in do_group_exit & get_signal X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that schedule_task_exit_locked uses JOBCTL_WILL_EXIT instead of setting the per task SIGKILL pending bit, and JOBCTL_WILL_EXIT is expected to be present on all tasks that are exiting, it makes no sense to skip the current task. So call schedule_task_exit_locked on all threads. Signed-off-by: "Eric W. Biederman" --- kernel/exit.c | 6 +----- kernel/signal.c | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index 564bf17f4589..471af82376e5 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -1015,12 +1015,8 @@ do_group_exit(int exit_code) sig->group_exit_code =3D exit_code; sig->flags =3D SIGNAL_GROUP_EXIT; sig->group_stop_count =3D 0; - __for_each_thread(sig, t) { - if (t =3D=3D current) - continue; + __for_each_thread(sig, t) schedule_task_exit_locked(t); - } - current->jobctl |=3D JOBCTL_WILL_EXIT; } spin_unlock_irq(&sighand->siglock); } diff --git a/kernel/signal.c b/kernel/signal.c index 2b0f6d8baebb..8ae6d6550e82 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2876,12 +2876,8 @@ bool get_signal(struct ksignal *ksig) signal->group_exit_code =3D exit_code; signal->flags =3D SIGNAL_GROUP_EXIT; signal->group_stop_count =3D 0; - __for_each_thread(signal, t) { - if (t =3D=3D current) - continue; + __for_each_thread(signal, t) schedule_task_exit_locked(t); - } - current->jobctl |=3D JOBCTL_WILL_EXIT; } fatal: spin_unlock_irq(&sighand->siglock); --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 052451E878 for ; Wed, 19 Jun 2024 04:12:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.231 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770322; cv=none; b=HRC6UZWE7rwjlbNYA3zjUpCl1URL3+CttF5y3P6YlWr8mXVA64UEWfzETcPIuxI/EMgMDuqn/PtQ/72Y1jw26tDdeQgTk+uVHg2Bq8mBLNc0ChXWrI0Q/Yo37e5Z4PI3+DsH5YtXVcVcaXUjX7uofD+W6n5MwZk2An5HwYe6vyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770322; c=relaxed/simple; bh=vtmrOF5N4KhitX4HDnMLKIVY1v8F5yZrqYrbuDCbe5o=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=n1Azhd9dz4W6QsZH9Iy22cXuwFF5llVjEAMsOHaYdbgA91u+glIOuKHzDZxlGW65+/Dk6yaJ39JDMQpQU7eHmjPAF0nGKYDZW25jd+VwEmGYQDMX50C+S0l0YSgvs5NZj8DiuMhH4GrNxKl/40gRb6VdhI7vStCOjGqT1JGn0Q0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:35746) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmfu-004PQd-8P; Tue, 18 Jun 2024 22:11:58 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:57468 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmfs-009S7c-Mh; Tue, 18 Jun 2024 22:11:57 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:11:49 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <87cyodfu62.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmfs-009S7c-Mh;;;mid=<87cyodfu62.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1+l132/YIhjPoZqdGCn7BV7GUBu/unn59Y= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: * X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4995] * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.5 XMGappySubj_01 Very gappy subject * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa05 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * -0.0 T_SCC_BODY_TEXT_LINE No description available. X-Spam-DCC: XMission; sa05 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 982 ms - load_scoreonly_sql: 0.07 (0.0%), signal_user_changed: 14 (1.4%), b_tie_ro: 12 (1.2%), parse: 1.82 (0.2%), extract_message_metadata: 20 (2.0%), get_uri_detail_list: 3.9 (0.4%), tests_pri_-2000: 19 (2.0%), tests_pri_-1000: 3.3 (0.3%), tests_pri_-950: 1.71 (0.2%), tests_pri_-900: 1.30 (0.1%), tests_pri_-90: 537 (54.7%), check_bayes: 535 (54.5%), b_tokenize: 12 (1.2%), b_tok_get_all: 476 (48.4%), b_comp_prob: 3.9 (0.4%), b_tok_touch_all: 39 (4.0%), b_finish: 1.26 (0.1%), tests_pri_0: 364 (37.1%), check_dkim_signature: 0.83 (0.1%), check_dkim_adsp: 3.7 (0.4%), poll_dns_idle: 1.22 (0.1%), tests_pri_10: 3.9 (0.4%), tests_pri_500: 11 (1.1%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 14/17] signal: Factor out schedule_group_exit_locked X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Essentially the same code is present in zap_process, complete_signal, do_group_exit and get_signal. Place that code in a function and call it signal_group_exit_locked. Call signal_group_exit_locked instead of repeat the sequence inline 4 different times. Signed-off-by: "Eric W. Biederman" --- fs/coredump.c | 8 ++------ include/linux/sched/signal.h | 1 + kernel/exit.c | 11 ++-------- kernel/signal.c | 40 ++++++++++++++++++------------------ 4 files changed, 25 insertions(+), 35 deletions(-) diff --git a/fs/coredump.c b/fs/coredump.c index dce91e5c121a..aba72f1d170a 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -366,14 +366,10 @@ static int zap_process(struct task_struct *start, int= exit_code) struct task_struct *t; int nr =3D 0; =20 - start->signal->flags =3D SIGNAL_GROUP_EXIT; - start->signal->group_exit_code =3D exit_code; - start->signal->group_stop_count =3D 0; + schedule_group_exit_locked(start->signal, exit_code); =20 - for_each_thread(start, t) { - schedule_task_exit_locked(t); + for_each_thread(start, t) nr +=3D (t !=3D current) && !(t->flags & PF_POSTCOREDUMP); - } =20 return nr; } diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 250bd537aa6a..54b2b924aaea 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -462,6 +462,7 @@ static inline void ptrace_signal_wake_up(struct task_st= ruct *t, bool resume) } =20 void schedule_task_exit_locked(struct task_struct *task); +void schedule_group_exit_locked(struct signal_struct *signal, int exit_cod= e); =20 void task_join_group_stop(struct task_struct *task); =20 diff --git a/kernel/exit.c b/kernel/exit.c index 471af82376e5..35452e822cc9 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -1009,15 +1009,8 @@ do_group_exit(int exit_code) if (sig->flags & SIGNAL_GROUP_EXIT) /* Another thread got here before we took the lock. */ exit_code =3D sig->group_exit_code; - else { - struct task_struct *t; - - sig->group_exit_code =3D exit_code; - sig->flags =3D SIGNAL_GROUP_EXIT; - sig->group_stop_count =3D 0; - __for_each_thread(sig, t) - schedule_task_exit_locked(t); - } + else + schedule_group_exit_locked(sig, exit_code); spin_unlock_irq(&sighand->siglock); } =20 diff --git a/kernel/signal.c b/kernel/signal.c index 8ae6d6550e82..fe1d46b00e9f 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -999,6 +999,23 @@ static inline bool wants_signal(int sig, struct task_s= truct *p) return task_curr(p) || !task_sigpending(p); } =20 +void schedule_group_exit_locked(struct signal_struct *signal, int exit_cod= e) +{ + /* + * Start a group exit and wake everybody up. + * This way we don't have other threads + * running and doing things after a slower + * thread has the fatal signal pending. + */ + struct task_struct *t; + + signal->flags =3D SIGNAL_GROUP_EXIT; + signal->group_exit_code =3D exit_code; + signal->group_stop_count =3D 0; + __for_each_thread(signal, t) + schedule_task_exit_locked(t); +} + static void complete_signal(int sig, struct task_struct *p, enum pid_type = type) { struct signal_struct *signal =3D p->signal; @@ -1046,18 +1063,7 @@ static void complete_signal(int sig, struct task_str= uct *p, enum pid_type type) * This signal will be fatal to the whole group. */ if (!sig_kernel_coredump(sig)) { - /* - * Start a group exit and wake everybody up. - * This way we don't have other threads - * running and doing things after a slower - * thread has the fatal signal pending. - */ - signal->flags =3D SIGNAL_GROUP_EXIT; - signal->group_exit_code =3D sig; - signal->group_stop_count =3D 0; - __for_each_thread(signal, t) { - schedule_task_exit_locked(t); - } + schedule_group_exit_locked(signal, sig); return; } } @@ -2727,7 +2733,6 @@ bool get_signal(struct ksignal *ksig) for (;;) { bool group_exit_needed =3D false; struct k_sigaction *ka; - struct task_struct *t; enum pid_type type; int exit_code; =20 @@ -2872,13 +2877,8 @@ bool get_signal(struct ksignal *ksig) exit_code =3D signr; if (sig_kernel_coredump(signr)) group_exit_needed =3D true; - else { - signal->group_exit_code =3D exit_code; - signal->flags =3D SIGNAL_GROUP_EXIT; - signal->group_stop_count =3D 0; - __for_each_thread(signal, t) - schedule_task_exit_locked(t); - } + else + schedule_group_exit_locked(signal, exit_code); fatal: spin_unlock_irq(&sighand->siglock); if (unlikely(cgroup_task_frozen(current))) --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A97A03C099 for ; Wed, 19 Jun 2024 04:12:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770345; cv=none; b=Tjr/NrBDgH5Msoe+m6ph+Y4KRUSfFin65JdpOrMQvpT3qSGMGjOBGAFoaQEAAfIiuy99/prjceFWAJVWJK7uyxG0+cyLP2nPJ9xcXhHtqafGPpGtBLbcTXQr0GKU/EKRgN9+ha64aj+qPtm9dU+GWfrC2UsgFXBfXGPyNeV7GNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770345; c=relaxed/simple; bh=sUrNmkLXmK66eGoLP0Q3kuFYnsriY9zdRjT2aEhy/pY=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=aYBu7C4j8M4aot96sn2MWeIyg0jpEErSdhSCDX/Fh/fluG/msEWIHKsDPI/JtZAYqCdxjB22ZouJgllwq+j4NtFW6a5iXtxzVTq6YWmtIOFwu1ZIQjvfxO48Rt7xrGxgssqnDVt98ZwqeZgMOacv5ar0SLBjtwSKqOXYDxacuUE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:39140) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmgI-005up4-G8; Tue, 18 Jun 2024 22:12:22 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:59068 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmgH-009SG7-1S; Tue, 18 Jun 2024 22:12:22 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:12:12 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <877celfu5f.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmgH-009SG7-1S;;;mid=<877celfu5f.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX18H0Aorairo9gNKQotFHiRTRk8CwDTc7a0= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. * 0.0 T_TooManySym_02 5+ unique symbols in subject * 0.4 XMBrknScrpt_02 Possible Broken Spam Script * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_03 6+ unique symbols in subject X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 874 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 12 (1.4%), b_tie_ro: 11 (1.2%), parse: 1.30 (0.1%), extract_message_metadata: 15 (1.8%), get_uri_detail_list: 4.5 (0.5%), tests_pri_-2000: 13 (1.5%), tests_pri_-1000: 2.3 (0.3%), tests_pri_-950: 1.26 (0.1%), tests_pri_-900: 0.97 (0.1%), tests_pri_-90: 323 (37.0%), check_bayes: 321 (36.8%), b_tokenize: 14 (1.5%), b_tok_get_all: 11 (1.3%), b_comp_prob: 3.2 (0.4%), b_tok_touch_all: 289 (33.1%), b_finish: 1.17 (0.1%), tests_pri_0: 489 (56.0%), check_dkim_signature: 0.61 (0.1%), check_dkim_adsp: 3.0 (0.3%), poll_dns_idle: 1.27 (0.1%), tests_pri_10: 3.0 (0.3%), tests_pri_500: 8 (1.0%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 15/17] ptrace: Separate task->ptrace_code out from task->exit_code X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A process can be marked for death by setting SIGNAL_GROUP_EXIT and group_exit_code, long before do_exit is called. Unfortunately because of PTRACE_EVENT_EXIT residing in do_exit this same tactic can not be used for task death. Correct this by adding a new task field task->ptrace_code that holds the code for ptrace stops. This allows task->exit_code to be set to the exit code long before the PTRACE_EVENT_EXIT ptrace stop. Signed-off-by: "Eric W. Biederman" --- fs/proc/array.c | 3 +++ include/linux/sched.h | 1 + kernel/exit.c | 2 +- kernel/ptrace.c | 12 ++++++------ kernel/signal.c | 22 +++++++++++----------- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/fs/proc/array.c b/fs/proc/array.c index 34a47fb0c57f..b1c1d1f2bda8 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -525,6 +525,9 @@ static int do_task_stat(struct seq_file *m, struct pid_= namespace *ns, =20 rsslim =3D READ_ONCE(sig->rlim[RLIMIT_RSS].rlim_cur); =20 + if (task_is_traced(task) && !(task->jobctl & JOBCTL_LISTENING)) + exit_code =3D task->ptrace_code; + if (whole) { if (sig->flags & (SIGNAL_GROUP_EXIT | SIGNAL_STOP_STOPPED)) exit_code =3D sig->group_exit_code; diff --git a/include/linux/sched.h b/include/linux/sched.h index 61591ac6eab6..0995775cd065 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1213,6 +1213,7 @@ struct task_struct { /* Ptrace state: */ unsigned long ptrace_message; kernel_siginfo_t *last_siginfo; + int ptrace_code; =20 struct task_io_accounting ioac; #ifdef CONFIG_PSI diff --git a/kernel/exit.c b/kernel/exit.c index 35452e822cc9..dc944e3c1493 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -1199,7 +1199,7 @@ static int *task_stopped_code(struct task_struct *p, = bool ptrace) { if (ptrace) { if (task_is_traced(p) && !(p->jobctl & JOBCTL_LISTENING)) - return &p->exit_code; + return &p->ptrace_code; } else { if (p->signal->flags & SIGNAL_STOP_STOPPED) return &p->signal->group_exit_code; diff --git a/kernel/ptrace.c b/kernel/ptrace.c index d5f89f9ef29f..9f8022e55eb7 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -162,7 +162,7 @@ void __ptrace_unlink(struct task_struct *child) =20 static bool looks_like_a_spurious_pid(struct task_struct *task) { - if (task->exit_code !=3D ((PTRACE_EVENT_EXEC << 8) | SIGTRAP)) + if (task->ptrace_code !=3D ((PTRACE_EVENT_EXEC << 8) | SIGTRAP)) return false; =20 if (task_pid_vnr(task) =3D=3D task->ptrace_message) @@ -578,7 +578,7 @@ static int ptrace_detach(struct task_struct *child, uns= igned int data) * tasklist_lock avoids the race with wait_task_stopped(), see * the comment in ptrace_resume(). */ - child->exit_code =3D data; + child->ptrace_code =3D data; __ptrace_detach(current, child); write_unlock_irq(&tasklist_lock); =20 @@ -851,16 +851,16 @@ static int ptrace_resume(struct task_struct *child, l= ong request, } =20 /* - * Change ->exit_code and ->state under siglock to avoid the race - * with wait_task_stopped() in between; a non-zero ->exit_code will + * Change ->ptrace_code and ->state under siglock to avoid the race + * with wait_task_stopped() in between; a non-zero ->ptrace_code will * wrongly look like another report from tracee. * - * Note that we need siglock even if ->exit_code =3D=3D data and/or this + * Note that we need siglock even if ->ptrace_code =3D=3D data and/or this * status was not reported yet, the new status must not be cleared by * wait_task_stopped() after resume. */ spin_lock_irq(&child->sighand->siglock); - child->exit_code =3D data; + child->ptrace_code =3D data; child->jobctl &=3D ~JOBCTL_TRACED; wake_up_state(child, __TASK_TRACED); spin_unlock_irq(&child->sighand->siglock); diff --git a/kernel/signal.c b/kernel/signal.c index fe1d46b00e9f..dc9ab998fa15 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2193,7 +2193,7 @@ static void do_notify_parent_cldstop(struct task_stru= ct *tsk, info.si_status =3D tsk->signal->group_exit_code & 0x7f; break; case CLD_TRAPPED: - info.si_status =3D tsk->exit_code & 0x7f; + info.si_status =3D tsk->ptrace_code & 0x7f; break; default: BUG(); @@ -2223,7 +2223,7 @@ static void do_notify_parent_cldstop(struct task_stru= ct *tsk, * with. If the code did not stop because the tracer is gone, * the stop signal remains unchanged unless clear_code. */ -static int ptrace_stop(int exit_code, int why, unsigned long message, +static int ptrace_stop(int code, int why, unsigned long message, kernel_siginfo_t *info) __releases(¤t->sighand->siglock) __acquires(¤t->sighand->siglock) @@ -2246,12 +2246,12 @@ static int ptrace_stop(int exit_code, int why, unsi= gned long message, =20 /* Do not stop if ptrace_unlink has happened. */ if (!current->ptrace) - return exit_code; + return code; =20 /* Do not stop in a killed task except for PTRACE_EVENT_EXIT */ if (task_exit_pending(current) && - ((exit_code >> 8) !=3D PTRACE_EVENT_EXIT)) - return exit_code; + ((code >> 8) !=3D PTRACE_EVENT_EXIT)) + return code; =20 /* * After this point ptrace_unlink or a fatal signal will clear @@ -2282,7 +2282,7 @@ static int ptrace_stop(int exit_code, int why, unsign= ed long message, =20 current->ptrace_message =3D message; current->last_siginfo =3D info; - current->exit_code =3D exit_code; + current->ptrace_code =3D code; =20 /* * If @why is CLD_STOPPED, we're trapping to participate in a group @@ -2361,10 +2361,10 @@ static int ptrace_stop(int exit_code, int why, unsi= gned long message, * any signal-sending on another CPU that wants to examine it. */ spin_lock_irq(¤t->sighand->siglock); - exit_code =3D current->exit_code; + code =3D current->ptrace_code; current->last_siginfo =3D NULL; current->ptrace_message =3D 0; - current->exit_code =3D 0; + current->ptrace_code =3D 0; =20 /* LISTENING can be set only during STOP traps, clear it */ current->jobctl &=3D ~(JOBCTL_LISTENING | JOBCTL_PTRACE_FROZEN); @@ -2375,7 +2375,7 @@ static int ptrace_stop(int exit_code, int why, unsign= ed long message, * This sets TIF_SIGPENDING, but never clears it. */ recalc_sigpending_tsk(current); - return exit_code; + return code; } =20 static int ptrace_do_notify(int signr, int exit_code, int why, unsigned lo= ng message) @@ -2535,11 +2535,11 @@ static bool do_signal_stop(int signr) * * When PT_SEIZED, it's used for both group stop and explicit * SEIZE/INTERRUPT traps. Both generate PTRACE_EVENT_STOP trap with - * accompanying siginfo. If stopped, lower eight bits of exit_code contain + * accompanying siginfo. If stopped, lower eight bits of ptrace_code cont= ain * the stop signal; otherwise, %SIGTRAP. * * When !PT_SEIZED, it's used only for group stop trap with stop signal - * number as exit_code and no siginfo. + * number as ptrace_code and no siginfo. * * CONTEXT: * Must be called with @current->sighand->siglock held, which may be --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0E935588E for ; Wed, 19 Jun 2024 04:13:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.231 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770387; cv=none; b=Gg61vlImK5gl5FzB3GgZWO5barehTn47NM4ubtG1M4xLWshzMI1mBj2oWNw+bEI58r3h96Nf2GyNuohJ2yamrS9EZ3Ve2z9FxzPUf+KvBXN+3ABcz5TzM1HklGB77PX+l7Tsss8YgYjgCGFAaTHtx4LYu5HpuK+Be6XjHMXHGq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770387; c=relaxed/simple; bh=N5xqzhHiMn5sjodiwTiMky0jNsveAIIw19AeHh9JrSw=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=dzAhpnXUxnOzN58mHCShZpeUTQ0frseEEKbH4wVfqjCpNEuImdS2KJpT5Y8ETvM2BE2oF7O6BXQ3IaVaVLSalihSXK3uFAkY42wGLa3eeaR5uORP8SZpg1ea+8CTPlIKI5834K/lGyHpo5NKt5xo79Sxdye+dWnNzjig7y7C4o4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.231 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:42776) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmgy-004PYQ-G3; Tue, 18 Jun 2024 22:13:04 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:56222 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmgx-009SKN-DK; Tue, 18 Jun 2024 22:13:04 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:12:56 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <87y171efjr.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmgx-009SKN-DK;;;mid=<87y171efjr.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1/Jyv22mqBP7c5a8A8XIKv6TJOQkl6JrFY= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Virus: No X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4894] * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.7 XMSubLong Long Subject * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa03 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa03 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 443 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 4.5 (1.0%), b_tie_ro: 3.1 (0.7%), parse: 1.30 (0.3%), extract_message_metadata: 11 (2.5%), get_uri_detail_list: 2.8 (0.6%), tests_pri_-2000: 11 (2.4%), tests_pri_-1000: 1.80 (0.4%), tests_pri_-950: 1.06 (0.2%), tests_pri_-900: 0.78 (0.2%), tests_pri_-90: 55 (12.5%), check_bayes: 54 (12.3%), b_tokenize: 7 (1.6%), b_tok_get_all: 7 (1.6%), b_comp_prob: 1.60 (0.4%), b_tok_touch_all: 36 (8.0%), b_finish: 0.75 (0.2%), tests_pri_0: 342 (77.4%), check_dkim_signature: 0.43 (0.1%), check_dkim_adsp: 3.8 (0.9%), poll_dns_idle: 1.49 (0.3%), tests_pri_10: 2.8 (0.6%), tests_pri_500: 8 (1.8%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 16/17] signal: Record the exit_code when an exit is scheduled X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With ptrace_stop no longer using task->exit_code it is safe to set task->exit_code when an exit is scheduled. Use the bit JOBCTL_WILL_EXIT to detect when a exit is first scheduled and only set exit_code the first time. Only use the code provided to do_exit if the task has not yet been schedled to exit. In get_signal and do_grup_exit when JOBCTL_WILL_EXIT is set read the recored exit_code from current->exit_code, instead of assuming exit_code will always be 0. Signed-off-by: "Eric W. Biederman" --- fs/exec.c | 2 +- include/linux/sched/signal.h | 2 +- kernel/exit.c | 9 +++++---- kernel/signal.c | 7 ++++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 57d617917b1c..99ee1a850c37 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1097,7 +1097,7 @@ static int de_thread(struct task_struct *tsk) if (t =3D=3D tsk) continue; sig->notify_count++; - schedule_task_exit_locked(t); + schedule_task_exit_locked(t, 0); } =20 while (sig->notify_count) { diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index 54b2b924aaea..bc702fd94a1f 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -461,7 +461,7 @@ static inline void ptrace_signal_wake_up(struct task_st= ruct *t, bool resume) signal_wake_up_state(t, state); } =20 -void schedule_task_exit_locked(struct task_struct *task); +void schedule_task_exit_locked(struct task_struct *task, int exit_code); void schedule_group_exit_locked(struct signal_struct *signal, int exit_cod= e); =20 void task_join_group_stop(struct task_struct *task); diff --git a/kernel/exit.c b/kernel/exit.c index dc944e3c1493..2b4e57ff02a1 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -795,13 +795,14 @@ static void check_stack_usage(void) static inline void check_stack_usage(void) {} #endif =20 -static void synchronize_group_exit(struct task_struct *tsk, long code) +static int synchronize_group_exit(struct task_struct *tsk, long code) { struct sighand_struct *sighand =3D tsk->sighand; struct signal_struct *signal =3D tsk->signal; =20 spin_lock_irq(&sighand->siglock); - schedule_task_exit_locked(tsk); + schedule_task_exit_locked(tsk, code); + code =3D tsk->exit_code; signal->quick_threads--; if ((signal->quick_threads =3D=3D 0) && !(signal->flags & SIGNAL_GROUP_EXIT)) { @@ -810,6 +811,7 @@ static void synchronize_group_exit(struct task_struct *= tsk, long code) signal->group_stop_count =3D 0; } spin_unlock_irq(&sighand->siglock); + return code; } =20 void __noreturn do_exit(long code) @@ -819,7 +821,7 @@ void __noreturn do_exit(long code) =20 WARN_ON(irqs_disabled()); =20 - synchronize_group_exit(tsk, code); + code =3D synchronize_group_exit(tsk, code); =20 WARN_ON(tsk->plug); =20 @@ -856,7 +858,6 @@ void __noreturn do_exit(long code) tty_audit_exit(); audit_free(tsk); =20 - tsk->exit_code =3D code; taskstats_exit(tsk, group_dead); =20 exit_mm(); diff --git a/kernel/signal.c b/kernel/signal.c index dc9ab998fa15..c8b896bc84bb 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1013,7 +1013,7 @@ void schedule_group_exit_locked(struct signal_struct = *signal, int exit_code) signal->group_exit_code =3D exit_code; signal->group_stop_count =3D 0; __for_each_thread(signal, t) - schedule_task_exit_locked(t); + schedule_task_exit_locked(t, exit_code); } =20 static void complete_signal(int sig, struct task_struct *p, enum pid_type = type) @@ -1373,11 +1373,12 @@ int force_sig_info(struct kernel_siginfo *info) return force_sig_info_to_task(info, current, HANDLER_CURRENT); } =20 -void schedule_task_exit_locked(struct task_struct *task) +void schedule_task_exit_locked(struct task_struct *task, int exit_code) { if (!(task->jobctl & JOBCTL_WILL_EXIT)) { task_clear_jobctl_pending(task, JOBCTL_PENDING_MASK); task->jobctl |=3D JOBCTL_WILL_EXIT; + task->exit_code =3D exit_code; signal_wake_up(task, true); } } @@ -2749,7 +2750,7 @@ bool get_signal(struct ksignal *ksig) if (signal->flags & SIGNAL_GROUP_EXIT) exit_code =3D signal->group_exit_code; else - exit_code =3D 0; + exit_code =3D current->exit_code; goto fatal; } =20 --=20 2.41.0 From nobody Wed Feb 11 22:55:47 2026 Received: from out03.mta.xmission.com (out03.mta.xmission.com [166.70.13.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 311F42A8D3 for ; Wed, 19 Jun 2024 04:13:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=166.70.13.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770414; cv=none; b=IErIPrvHMIvCc6zcVl9dur7xrM5l78r/Y8DPNafJkqEbv6M87mutfHPeyaYf5aGOekxLCHNsV1WgsBJAdZwxdETUt+JFLkgG7C2YwWiTV2LFvn0UB3yxvIXfhGs/Mxy6+CA8H4maednz05j3oz6gK8iv+91eHB7PnZAzWJ/0owc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718770414; c=relaxed/simple; bh=uI2aHM4hUVaJa/MTUb83cPxMZqUtYAayeTzix/5VaDQ=; h=From:To:Cc:References:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type:Subject; b=DZYidfIBR+ApL4uC5RboiaHgRyELee6caHXG5LvRdjnWwpcOB6I2JMSlVWxzSxvoy1v8o4IQ6hhf6w7l4QmX2PQ3S13mIhXIdK9J9NmjGKYl5oAbJNQyVfkZY3eaZOoC/R5R6i21Qkc7oomGi96XijxY0Hgt/B1M9Wrqi/W+KYU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com; spf=pass smtp.mailfrom=xmission.com; arc=none smtp.client-ip=166.70.13.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xmission.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xmission.com Received: from in01.mta.xmission.com ([166.70.13.51]:42400) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmhQ-005uro-4N; Tue, 18 Jun 2024 22:13:32 -0600 Received: from ip68-227-168-167.om.om.cox.net ([68.227.168.167]:51064 helo=email.froward.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1sJmhO-009SNH-E2; Tue, 18 Jun 2024 22:13:31 -0600 From: "Eric W. Biederman" To: Oleg Nesterov Cc: Andrew Morton , Tejun Heo , linux-kernel@vger.kernel.org References: <20240609142342.GA11165@redhat.com> <87r0d5t2nt.fsf@email.froward.int.ebiederm.org> <20240610152902.GC20640@redhat.com> <20240613154541.GD18218@redhat.com> <87ikyamf4u.fsf@email.froward.int.ebiederm.org> <20240617183758.GB10753@redhat.com> <87iky5k2yi.fsf@email.froward.int.ebiederm.org> <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> Date: Tue, 18 Jun 2024 23:13:22 -0500 In-Reply-To: <87o77xinmt.fsf_-_@email.froward.int.ebiederm.org> (Eric W. Biederman's message of "Tue, 18 Jun 2024 23:04:42 -0500") Message-ID: <87sex9efj1.fsf_-_@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-XM-SPF: eid=1sJmhO-009SNH-E2;;;mid=<87sex9efj1.fsf_-_@email.froward.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.168.167;;;frm=ebiederm@xmission.com;;;spf=pass X-XM-AID: U2FsdGVkX1+0SSFViOftj1kkcdetOJH4HiMXICFn8N8= X-SA-Exim-Connect-IP: 68.227.168.167 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Level: ** X-Spam-Virus: No X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.5000] * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa01 1397; Body=1 Fuz1=1 Fuz2=1] * -0.0 T_SCC_BODY_TEXT_LINE No description available. * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa01 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Oleg Nesterov X-Spam-Relay-Country: X-Spam-Timing: total 324 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 4.5 (1.4%), b_tie_ro: 3.1 (0.9%), parse: 1.15 (0.4%), extract_message_metadata: 12 (3.7%), get_uri_detail_list: 1.89 (0.6%), tests_pri_-2000: 10 (3.2%), tests_pri_-1000: 1.79 (0.6%), tests_pri_-950: 1.03 (0.3%), tests_pri_-900: 0.77 (0.2%), tests_pri_-90: 55 (17.1%), check_bayes: 54 (16.7%), b_tokenize: 5 (1.6%), b_tok_get_all: 5 (1.6%), b_comp_prob: 1.28 (0.4%), b_tok_touch_all: 39 (12.2%), b_finish: 0.71 (0.2%), tests_pri_0: 226 (69.8%), check_dkim_signature: 0.39 (0.1%), check_dkim_adsp: 3.6 (1.1%), poll_dns_idle: 1.71 (0.5%), tests_pri_10: 1.74 (0.5%), tests_pri_500: 7 (2.0%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 17/17] signal: Set SIGNAL_GROUP_EXIT when all tasks have decided to exit X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the quick_threads decrement from synchronize_group_exit into schedule_task_exit_locked allowing quick_threads to be decremented when the decision is made for a task to exit. Set SIGNAL_GROUP_EXIT, group_exit_code, and group_stop_code when the decision is made that the last thread will exit. This makes the information available earlier and so the kernel needs to do less work when a process is exiting. Signed-off-by: "Eric W. Biederman" --- kernel/exit.c | 8 -------- kernel/signal.c | 10 +++++++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/kernel/exit.c b/kernel/exit.c index 2b4e57ff02a1..ba48124f9bc9 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -798,18 +798,10 @@ static inline void check_stack_usage(void) {} static int synchronize_group_exit(struct task_struct *tsk, long code) { struct sighand_struct *sighand =3D tsk->sighand; - struct signal_struct *signal =3D tsk->signal; =20 spin_lock_irq(&sighand->siglock); schedule_task_exit_locked(tsk, code); code =3D tsk->exit_code; - signal->quick_threads--; - if ((signal->quick_threads =3D=3D 0) && - !(signal->flags & SIGNAL_GROUP_EXIT)) { - signal->flags =3D SIGNAL_GROUP_EXIT; - signal->group_exit_code =3D code; - signal->group_stop_count =3D 0; - } spin_unlock_irq(&sighand->siglock); return code; } diff --git a/kernel/signal.c b/kernel/signal.c index c8b896bc84bb..59e0c5505d76 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -1009,9 +1009,6 @@ void schedule_group_exit_locked(struct signal_struct = *signal, int exit_code) */ struct task_struct *t; =20 - signal->flags =3D SIGNAL_GROUP_EXIT; - signal->group_exit_code =3D exit_code; - signal->group_stop_count =3D 0; __for_each_thread(signal, t) schedule_task_exit_locked(t, exit_code); } @@ -1376,10 +1373,17 @@ int force_sig_info(struct kernel_siginfo *info) void schedule_task_exit_locked(struct task_struct *task, int exit_code) { if (!(task->jobctl & JOBCTL_WILL_EXIT)) { + struct signal_struct *signal =3D task->signal; task_clear_jobctl_pending(task, JOBCTL_PENDING_MASK); task->jobctl |=3D JOBCTL_WILL_EXIT; task->exit_code =3D exit_code; signal_wake_up(task, true); + signal->quick_threads--; + if (signal->quick_threads =3D=3D 0) { + signal->flags =3D SIGNAL_GROUP_EXIT; + signal->group_exit_code =3D exit_code; + signal->group_stop_count =3D 0; + } } } =20 --=20 2.41.0