<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/kernel/exit.c, branch v3.19</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v3.19</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v3.19'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2015-01-08T23:10:51Z</updated>
<entry>
<title>exit: fix race between wait_consider_task() and wait_task_zombie()</title>
<updated>2015-01-08T23:10:51Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2015-01-08T22:32:12Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=3245d6acab981a2388ffb877c7ecc97e763c59d4'/>
<id>urn:sha1:3245d6acab981a2388ffb877c7ecc97e763c59d4</id>
<content type='text'>
wait_consider_task() checks EXIT_ZOMBIE after EXIT_DEAD/EXIT_TRACE and
both checks can fail if we race with EXIT_ZOMBIE -&gt; EXIT_DEAD/EXIT_TRACE
change in between, gcc needs to reload p-&gt;exit_state after
security_task_wait().  In this case -&gt;notask_error will be wrongly
cleared and do_wait() can hang forever if it was the last eligible
child.

Many thanks to Arne who carefully investigated the problem.

Note: this bug is very old but it was pure theoretical until commit
b3ab03160dfa ("wait: completely ignore the EXIT_DEAD tasks").  Before
this commit "-O2" was probably enough to guarantee that compiler won't
read -&gt;exit_state twice.

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Reported-by: Arne Goedeke &lt;el@laramies.com&gt;
Tested-by: Arne Goedeke &lt;el@laramies.com&gt;
Cc: &lt;stable@vger.kernel.org&gt;	[3.15+]
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>Merge tag 'tty-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty</title>
<updated>2014-12-14T23:23:32Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2014-12-14T23:23:32Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=37da7bbbe84fe9e8862940d3f9194fd27dce59bb'/>
<id>urn:sha1:37da7bbbe84fe9e8862940d3f9194fd27dce59bb</id>
<content type='text'>
Pull tty/serial driver updates from Greg KH:
 "Here's the big tty/serial driver update for 3.19-rc1.

  There are a number of TTY core changes/fixes in here from Peter Hurley
  that have all been teted in linux-next for a long time now.  There are
  also the normal serial driver updates as well, full details in the
  changelog below"

* tag 'tty-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: (219 commits)
  serial: pxa: hold port.lock when reporting modem line changes
  tty-hvsi_lib: Deletion of an unnecessary check before the function call "tty_kref_put"
  tty: Deletion of unnecessary checks before two function calls
  n_tty: Fix read_buf race condition, increment read_head after pushing data
  serial: of-serial: add PM suspend/resume support
  Revert "serial: of-serial: add PM suspend/resume support"
  Revert "serial: of-serial: fix up PM ops on no_console_suspend and port type"
  serial: 8250: don't attempt a trylock if in sysrq
  serial: core: Add big-endian iotype
  serial: samsung: use port-&gt;fifosize instead of hardcoded values
  serial: samsung: prefer to use fifosize from driver data
  serial: samsung: fix style problems
  serial: samsung: wait for transfer completion before clock disable
  serial: icom: fix error return code
  serial: tegra: clean up tty-flag assignments
  serial: Fix io address assign flow with Fintek PCI-to-UART Product
  serial: mxs-auart: fix tx_empty against shift register
  serial: mxs-auart: fix gpio change detection on interrupt
  serial: mxs-auart: Fix mxs_auart_set_ldisc()
  serial: 8250_dw: Use 64-bit access for OCTEON.
  ...
</content>
</entry>
<entry>
<title>exit: exit_notify: re-use "dead" list to autoreap current</title>
<updated>2014-12-11T01:41:18Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2014-12-10T23:55:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=6c66e7dba3d4419c8b973505679635efcd6b311c'/>
<id>urn:sha1:6c66e7dba3d4419c8b973505679635efcd6b311c</id>
<content type='text'>
After the previous change we can add just the exiting EXIT_DEAD task to
the "dead" list and remove another release_task(tsk).

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Aaron Tomlin &lt;atomlin@redhat.com&gt;
Cc: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
Cc: Sterling Alexander &lt;stalexan@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>exit: reparent: call forget_original_parent() under tasklist_lock</title>
<updated>2014-12-11T01:41:18Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2014-12-10T23:55:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=482a3767e5087f6e6ad2486a6655aaa5f3d59301'/>
<id>urn:sha1:482a3767e5087f6e6ad2486a6655aaa5f3d59301</id>
<content type='text'>
Shift "release dead children" loop from forget_original_parent() to its
caller, exit_notify().  It is safe to reap them even if our parent reaps
us right after we drop tasklist_lock, those children no longer have any
connection to the exiting task.

And this allows us to avoid write_lock_irq(tasklist_lock) right after it
was released by forget_original_parent(), we can simply call it with
tasklist_lock held.

While at it, move the comment about forget_original_parent() up to
this function.

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Aaron Tomlin &lt;atomlin@redhat.com&gt;
Cc: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
Cc: Sterling Alexander &lt;stalexan@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>exit: reparent: avoid find_new_reaper() if no children</title>
<updated>2014-12-11T01:41:18Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2014-12-10T23:55:17Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=ad9e206aefa56788b676ebcd6329e828f40d2238'/>
<id>urn:sha1:ad9e206aefa56788b676ebcd6329e828f40d2238</id>
<content type='text'>
Now that pid_ns logic was isolated we can change forget_original_parent()
to return right after find_child_reaper() when father-&gt;children is empty,
there is nothing to reparent in this case.

In particular this avoids find_alive_thread() and this can help if the
whole process exits and it has a lot of PF_EXITING threads at the start of
the thread list, this can easily lead to O(nr_threads ** 2) iterations.

Trivial test case (tested under KVM, 2 CPUs):

    static void *tfunc(void *arg)
    {
        pause();
        return NULL;
    }

    static int child(unsigned int nt)
    {
        pthread_t pt;

        while (nt--)
            assert(pthread_create(&amp;pt, NULL, tfunc, NULL) == 0);

        pthread_kill(pt, SIGTRAP);
        pause();
        return 0;
    }

    int main(int argc, const char *argv[])
    {
        int stat;
        unsigned int nf = atoi(argv[1]);
        unsigned int nt = atoi(argv[2]);

        while (nf--) {
            if (!fork())
                return child(nt);

            wait(&amp;stat);
            assert(stat == SIGTRAP);
        }

        return 0;
    }

$ time ./test 16 16536 shows:

              real        user         sys
    -    5m37.628s    0m4.437s    8m5.560s
    +    0m50.032s    0m7.130s    1m4.927s

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Aaron Tomlin &lt;atomlin@redhat.com&gt;
Cc: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
Cc: Sterling Alexander &lt;stalexan@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>exit: reparent: introduce find_alive_thread()</title>
<updated>2014-12-11T01:41:17Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2014-12-10T23:55:14Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=c9dc05bfdb3f7fd7c00f3cbd33816c99d2cb9029'/>
<id>urn:sha1:c9dc05bfdb3f7fd7c00f3cbd33816c99d2cb9029</id>
<content type='text'>
Add the new simple helper to factor out the for_each_thread() code in
find_child_reaper() and find_new_reaper().  It can also simplify the
potential PF_EXITING -&gt; exit_state change, plus perhaps we can change this
code to take SIGNAL_GROUP_EXIT into account.

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Aaron Tomlin &lt;atomlin@redhat.com&gt;
Cc: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
Cc: Kay Sievers &lt;kay@vrfy.org&gt;
Cc: Lennart Poettering &lt;lennart@poettering.net&gt;
Cc: Sterling Alexander &lt;stalexan@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>exit: reparent: introduce find_child_reaper()</title>
<updated>2014-12-11T01:41:17Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2014-12-10T23:55:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=1109909c7df08f55ff9104276bb9db1ee2e6e53d'/>
<id>urn:sha1:1109909c7df08f55ff9104276bb9db1ee2e6e53d</id>
<content type='text'>
find_new_reaper() does 2 completely different things.  Not only it finds a
reaper, it also updates pid_ns-&gt;child_reaper or kills the whole namespace
if the caller is -&gt;child_reaper.

Now that has_child_subreaper logic doesn't depend on child_reaper check we
can move that pid_ns code into a separate helper.  IMHO this makes the
code more clean, and this allows the next changes.

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Aaron Tomlin &lt;atomlin@redhat.com&gt;
Cc: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
Cc: Kay Sievers &lt;kay@vrfy.org&gt;
Cc: Lennart Poettering &lt;lennart@poettering.net&gt;
Cc: Sterling Alexander &lt;stalexan@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>exit: reparent: document the -&gt;has_child_subreaper checks</title>
<updated>2014-12-11T01:41:17Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2014-12-10T23:55:08Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=175aed3f8d38b87d3287bb765c794205f2b511de'/>
<id>urn:sha1:175aed3f8d38b87d3287bb765c794205f2b511de</id>
<content type='text'>
Swap the "init_task" and same_thread_group() checks.  This way it is more
simple to document these checks and we can remove the link to the previous
discussion on lkml.

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Aaron Tomlin &lt;atomlin@redhat.com&gt;
Cc: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
Cc: Kay Sievers &lt;kay@vrfy.org&gt;
Cc: Lennart Poettering &lt;lennart@poettering.net&gt;
Cc: Sterling Alexander &lt;stalexan@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>exit: reparent: s/while_each_thread/for_each_thread/ in find_new_reaper()</title>
<updated>2014-12-11T01:41:17Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2014-12-10T23:55:05Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=3750ef979cfa1296630aa9f23e265c1bd721498a'/>
<id>urn:sha1:3750ef979cfa1296630aa9f23e265c1bd721498a</id>
<content type='text'>
Change find_new_reaper() to use for_each_thread() instead of deprecated
while_each_thread().  We do not bother to check "thread != father" in the
1st loop, we can rely on PF_EXITING check.

Note: this means the minor behavioural change: for_each_thread() starts
from the group leader.  But this should be fine, nobody should make any
assumption about do_wait(__WNOTHREAD) when it comes to reparented tasks.
And this can avoid the pointless reparenting to a short-living thread
While zombie leaders are not that common.

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Aaron Tomlin &lt;atomlin@redhat.com&gt;
Cc: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
Cc: Kay Sievers &lt;kay@vrfy.org&gt;
Cc: Lennart Poettering &lt;lennart@poettering.net&gt;
Cc: Sterling Alexander &lt;stalexan@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>exit: reparent: fix the cross-namespace PR_SET_CHILD_SUBREAPER reparenting</title>
<updated>2014-12-11T01:41:17Z</updated>
<author>
<name>Oleg Nesterov</name>
<email>oleg@redhat.com</email>
</author>
<published>2014-12-10T23:55:02Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=7d24e2df52f596a1ea922e4f84a61f2fb24fbb70'/>
<id>urn:sha1:7d24e2df52f596a1ea922e4f84a61f2fb24fbb70</id>
<content type='text'>
find_new_reaper() assumes that "has_child_subreaper" logic is safe as
long as we are not the exiting -&gt;child_reaper and this is doubly wrong:

1. In fact it is safe if "pid_ns-&gt;child_reaper == father"; there must
   be no children after zap_pid_ns_processes() returns, so it doesn't
   matter what we return in this case and even pid_ns-&gt;child_reaper is
   wrong otherwise: we can't reparent to -&gt;child_reaper == current.

   This is not a bug, but this is confusing.

2. It is not safe if we are not pid_ns-&gt;child_reaper but from the same
   thread group. We drop tasklist_lock before zap_pid_ns_processes(),
   so another thread can lock it and choose the new reaper from the
   upper namespace if has_child_subreaper == T, and this is obviously
   wrong.

   This is not that bad, zap_pid_ns_processes() won't return until the
   the new reaper reaps all zombies, but this should be fixed anyway.

We could change for_each_thread() loop to use -&gt;exit_state instead of
PF_EXITING which we had to use until 8aac62706ada, or we could change
copy_signal() to check CLONE_NEWPID before setting has_child_subreaper,
but lets change this code so that it is clear we can't look outside of
our namespace, otherwise same_thread_group(reaper, child_reaper) check
will look wrong and confusing anyway.

We can simply start from "father" and fix the problem. We can't wrongly
return a thread from the same thread group if -&gt;is_child_subreaper == T,
we know that all threads have PF_EXITING set.

Signed-off-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Aaron Tomlin &lt;atomlin@redhat.com&gt;
Cc: "Eric W. Biederman" &lt;ebiederm@xmission.com&gt;
Cc: Kay Sievers &lt;kay@vrfy.org&gt;
Cc: Lennart Poettering &lt;lennart@poettering.net&gt;
Cc: Sterling Alexander &lt;stalexan@redhat.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
</feed>
