+ signal-on-exit-skip-waiting-for-an-ack-from-the-tracer-if-it-is-frozen.patch added to mm-nonmm-unstable branch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     Subject: signal: on exit skip waiting for an ack from the tracer if it is frozen
has been added to the -mm mm-nonmm-unstable branch.  Its filename is
     signal-on-exit-skip-waiting-for-an-ack-from-the-tracer-if-it-is-frozen.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/signal-on-exit-skip-waiting-for-an-ack-from-the-tracer-if-it-is-frozen.patch

This patch will later appear in the mm-nonmm-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days

------------------------------------------------------
From: Suren Baghdasaryan <surenb@xxxxxxxxxx>
Subject: signal: on exit skip waiting for an ack from the tracer if it is frozen
Date: Fri, 28 Jun 2024 10:32:47 -0700

When a process is being killed or exiting and it has a tracer, it will
notify the tracer and wait for an ack from the tracer to proceed.  However
if the tracer is frozen, this ack will not arrive until the tracer gets
thawed.  This poses a problem especially during memory pressure because
resources of the process are not released.

Things become even more interesting if OOM killer picks such tracee and
adds it into oom_victims.  oom_victims counter will get incremented and
stay that way until tracee exits.  In the meantime, if the system tries to
go into suspend, it will call oom_killer_disable() after freezing all
processes.  That call will fail due to positive oom_victims, but not until
freeze_timeout_msecs passes.  For the whole duration of the
freeze_timeout_msecs (20sec by default) the system will appear
unresponsive.

To fix this problem, skip the ack waiting step in the tracee when it's
exiting and the tracer is frozen.  Per ptrace(2) manual, the tracer cannot
assume that the ptrace-stopped tracee exists.  Therefore this change does
not break any valid assumptions.

Link: https://lkml.kernel.org/r/20240628173247.3507846-1-surenb@xxxxxxxxxx
Signed-off-by: Suren Baghdasaryan <surenb@xxxxxxxxxx>
Debugged-by: Martin Liu <liumartin@xxxxxxxxxx>
Debugged-by: Minchan Kim <minchan@xxxxxxxxxx>
Cc: Ard Biesheuvel <ardb@xxxxxxxxxx>
Cc: Christian Brauner <brauner@xxxxxxxxxx>
Cc: Michal Hocko <mhocko@xxxxxxxx>
Cc: Oleg Nesterov <oleg@xxxxxxxxxx>
Cc: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>
Cc: Tycho Andersen <tandersen@xxxxxxxxxxx>
Cc: Vincent Whitchurch <vincent.whitchurch@xxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 kernel/signal.c |   14 ++++++++++++++
 1 file changed, 14 insertions(+)

--- a/kernel/signal.c~signal-on-exit-skip-waiting-for-an-ack-from-the-tracer-if-it-is-frozen
+++ a/kernel/signal.c
@@ -2321,6 +2321,19 @@ static int ptrace_stop(int exit_code, in
 		do_notify_parent_cldstop(current, false, why);
 
 	/*
+	 * If tracer is frozen, it won't ack until it gets unfrozen and if the
+	 * tracee is exiting this means its resources do not get freed until
+	 * the tracer is thawed. Skip waiting for the tracer. Per ptrace(2)
+	 * manual, the tracer cannot assume that the ptrace-stopped tracee
+	 * exists, so exiting now should not be an issue.
+	 */
+	if (current->ptrace && (exit_code >> 8) == PTRACE_EVENT_EXIT &&
+	    cgroup_task_frozen(current->parent)) {
+		read_unlock(&tasklist_lock);
+		goto skip_wait;
+	}
+
+	/*
 	 * The previous do_notify_parent_cldstop() invocation woke ptracer.
 	 * One a PREEMPTION kernel this can result in preemption requirement
 	 * which will be fulfilled after read_unlock() and the ptracer will be
@@ -2356,6 +2369,7 @@ static int ptrace_stop(int exit_code, in
 	schedule();
 	cgroup_leave_frozen(true);
 
+skip_wait:
 	/*
 	 * We are back.  Now reacquire the siglock before touching
 	 * last_siginfo, so that we are sure to have synchronized with
_

Patches currently in -mm which might be from surenb@xxxxxxxxxx are

signal-on-exit-skip-waiting-for-an-ack-from-the-tracer-if-it-is-frozen.patch





[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux