mirror of
https://github.com/FEX-Emu/linux.git
synced 2025-02-07 12:00:38 +00:00
exit: wait: don't use zombie->real_parent
1. wait_task_zombie() uses p->real_parent to get psig/siglock. This is correct but needs tasklist_lock, ->real_parent can exit. We can use "current" instead. This is our natural child, its parent must be our sub-thread. 2. Read psig/sig outside of ->siglock, ->signal is no longer protected by this lock. 3. Fix the outdated comments about tasklist_lock. We can not race with __exit_signal(), the whole thread group is dead, nobody but us can call it. Also clarify the usage of ->stats_lock and ->siglock. Note: thread_group_cputime_adjusted() is sub-optimal in this case, we probably want to export cputime_adjust() to avoid thread_group_cputime(). The comment says "all threads" but there are no other threads. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: Aaron Tomlin <atomlin@redhat.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Rik van Riel <riel@redhat.com> Cc: Sterling Alexander <stalexan@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
f6507f83bc
commit
f953ccd006
@ -1010,8 +1010,8 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
|
|||||||
* Check thread_group_leader() to exclude the traced sub-threads.
|
* Check thread_group_leader() to exclude the traced sub-threads.
|
||||||
*/
|
*/
|
||||||
if (state == EXIT_DEAD && thread_group_leader(p)) {
|
if (state == EXIT_DEAD && thread_group_leader(p)) {
|
||||||
struct signal_struct *psig;
|
struct signal_struct *sig = p->signal;
|
||||||
struct signal_struct *sig;
|
struct signal_struct *psig = current->signal;
|
||||||
unsigned long maxrss;
|
unsigned long maxrss;
|
||||||
cputime_t tgutime, tgstime;
|
cputime_t tgutime, tgstime;
|
||||||
|
|
||||||
@ -1023,21 +1023,20 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
|
|||||||
* accumulate in the parent's signal_struct c* fields.
|
* accumulate in the parent's signal_struct c* fields.
|
||||||
*
|
*
|
||||||
* We don't bother to take a lock here to protect these
|
* We don't bother to take a lock here to protect these
|
||||||
* p->signal fields, because they are only touched by
|
* p->signal fields because the whole thread group is dead
|
||||||
* __exit_signal, which runs with tasklist_lock
|
* and nobody can change them.
|
||||||
* write-locked anyway, and so is excluded here. We do
|
*
|
||||||
* need to protect the access to parent->signal fields,
|
* psig->stats_lock also protects us from our sub-theads
|
||||||
* as other threads in the parent group can be right
|
* which can reap other children at the same time. Until
|
||||||
* here reaping other children at the same time.
|
* we change k_getrusage()-like users to rely on this lock
|
||||||
|
* we have to take ->siglock as well.
|
||||||
*
|
*
|
||||||
* We use thread_group_cputime_adjusted() to get times for
|
* We use thread_group_cputime_adjusted() to get times for
|
||||||
* the thread group, which consolidates times for all threads
|
* the thread group, which consolidates times for all threads
|
||||||
* in the group including the group leader.
|
* in the group including the group leader.
|
||||||
*/
|
*/
|
||||||
thread_group_cputime_adjusted(p, &tgutime, &tgstime);
|
thread_group_cputime_adjusted(p, &tgutime, &tgstime);
|
||||||
spin_lock_irq(&p->real_parent->sighand->siglock);
|
spin_lock_irq(¤t->sighand->siglock);
|
||||||
psig = p->real_parent->signal;
|
|
||||||
sig = p->signal;
|
|
||||||
write_seqlock(&psig->stats_lock);
|
write_seqlock(&psig->stats_lock);
|
||||||
psig->cutime += tgutime + sig->cutime;
|
psig->cutime += tgutime + sig->cutime;
|
||||||
psig->cstime += tgstime + sig->cstime;
|
psig->cstime += tgstime + sig->cstime;
|
||||||
@ -1062,7 +1061,7 @@ static int wait_task_zombie(struct wait_opts *wo, struct task_struct *p)
|
|||||||
task_io_accounting_add(&psig->ioac, &p->ioac);
|
task_io_accounting_add(&psig->ioac, &p->ioac);
|
||||||
task_io_accounting_add(&psig->ioac, &sig->ioac);
|
task_io_accounting_add(&psig->ioac, &sig->ioac);
|
||||||
write_sequnlock(&psig->stats_lock);
|
write_sequnlock(&psig->stats_lock);
|
||||||
spin_unlock_irq(&p->real_parent->sighand->siglock);
|
spin_unlock_irq(¤t->sighand->siglock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user