Commit 5dee1707 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

move the related code from exit_notify() to exit_signals()

The previous bugfix was not optimal, we shouldn't care about group stop
when we are the only thread or the group stop is in progress.  In that case
nothing special is needed, just set PF_EXITING and return.

Also, take the related "TIF_SIGPENDING re-targeting" code from exit_notify().

So, from the performance POV the only difference is that we don't trust
!signal_pending() until we take ->siglock.  But this in fact fixes another
___pure___ theoretical minor race.  __group_complete_signal() finds the
task without PF_EXITING and chooses it as the target for signal_wake_up().
But nothing prevents this task from exiting in between without noticing the
pending signal and thus unpredictably delaying the actual delivery.
Signed-off-by: default avatarOleg Nesterov <oleg@tv-sign.ru>
Cc: Davide Libenzi <davidel@xmailserver.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Roland McGrath <roland@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 6806aac6
...@@ -745,24 +745,6 @@ static void exit_notify(struct task_struct *tsk) ...@@ -745,24 +745,6 @@ static void exit_notify(struct task_struct *tsk)
struct task_struct *t; struct task_struct *t;
struct pid *pgrp; struct pid *pgrp;
if (signal_pending(tsk) && !(tsk->signal->flags & SIGNAL_GROUP_EXIT)
&& !thread_group_empty(tsk)) {
/*
* This occurs when there was a race between our exit
* syscall and a group signal choosing us as the one to
* wake up. It could be that we are the only thread
* alerted to check for pending signals, but another thread
* should be woken now to take the signal since we will not.
* Now we'll wake all the threads in the group just to make
* sure someone gets all the pending signals.
*/
spin_lock_irq(&tsk->sighand->siglock);
for (t = next_thread(tsk); t != tsk; t = next_thread(t))
if (!signal_pending(t) && !(t->flags & PF_EXITING))
recalc_sigpending_and_wake(t);
spin_unlock_irq(&tsk->sighand->siglock);
}
/* /*
* This does two things: * This does two things:
* *
......
...@@ -1903,19 +1903,36 @@ int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, ...@@ -1903,19 +1903,36 @@ int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka,
void exit_signals(struct task_struct *tsk) void exit_signals(struct task_struct *tsk)
{ {
int group_stop = 0; int group_stop = 0;
struct task_struct *t;
spin_lock_irq(&tsk->sighand->siglock); if (thread_group_empty(tsk) || signal_group_exit(tsk->signal)) {
if (unlikely(tsk->signal->group_stop_count) && tsk->flags |= PF_EXITING;
!--tsk->signal->group_stop_count) { return;
tsk->signal->flags = SIGNAL_STOP_STOPPED;
group_stop = 1;
} }
spin_lock_irq(&tsk->sighand->siglock);
/* /*
* From now this task is not visible for group-wide signals, * From now this task is not visible for group-wide signals,
* see wants_signal(), do_signal_stop(). * see wants_signal(), do_signal_stop().
*/ */
tsk->flags |= PF_EXITING; tsk->flags |= PF_EXITING;
if (!signal_pending(tsk))
goto out;
/* It could be that __group_complete_signal() choose us to
* notify about group-wide signal. Another thread should be
* woken now to take the signal since we will not.
*/
for (t = tsk; (t = next_thread(t)) != tsk; )
if (!signal_pending(t) && !(t->flags & PF_EXITING))
recalc_sigpending_and_wake(t);
if (unlikely(tsk->signal->group_stop_count) &&
!--tsk->signal->group_stop_count) {
tsk->signal->flags = SIGNAL_STOP_STOPPED;
group_stop = 1;
}
out:
spin_unlock_irq(&tsk->sighand->siglock); spin_unlock_irq(&tsk->sighand->siglock);
if (unlikely(group_stop)) { if (unlikely(group_stop)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment