Skip to content

Commit ad474ca

Browse files
oleg-nesterovIngo Molnar
authored andcommitted
fix for account_group_exec_runtime(), make sure ->signal can't be freed under rq->lock
Impact: fix hang/crash on ia64 under high load This is ugly, but the simplest patch by far. Unlike other similar routines, account_group_exec_runtime() could be called "implicitly" from within scheduler after exit_notify(). This means we can race with the parent doing release_task(), we can't just check ->signal != NULL. Change __exit_signal() to do spin_unlock_wait(&task_rq(tsk)->lock) before __cleanup_signal() to make sure ->signal can't be freed under task_rq(tsk)->lock. Note that task_rq_unlock_wait() doesn't care about the case when tsk changes cpu/rq under us, this should be OK. Thanks to Ingo who nacked my previous buggy patch. Signed-off-by: Oleg Nesterov <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reported-by: Doug Chapman <[email protected]>
1 parent 5ac5c4d commit ad474ca

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

include/linux/sched.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ extern void init_idle(struct task_struct *idle, int cpu);
247247
extern void init_idle_bootup_task(struct task_struct *idle);
248248

249249
extern int runqueue_is_locked(void);
250+
extern void task_rq_unlock_wait(struct task_struct *p);
250251

251252
extern cpumask_t nohz_cpu_mask;
252253
#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)

kernel/exit.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ static void __exit_signal(struct task_struct *tsk)
141141
if (sig) {
142142
flush_sigqueue(&sig->shared_pending);
143143
taskstats_tgid_free(sig);
144+
/*
145+
* Make sure ->signal can't go away under rq->lock,
146+
* see account_group_exec_runtime().
147+
*/
148+
task_rq_unlock_wait(tsk);
144149
__cleanup_signal(sig);
145150
}
146151
}

kernel/sched.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,14 @@ static struct rq *task_rq_lock(struct task_struct *p, unsigned long *flags)
969969
}
970970
}
971971

972+
void task_rq_unlock_wait(struct task_struct *p)
973+
{
974+
struct rq *rq = task_rq(p);
975+
976+
smp_mb(); /* spin-unlock-wait is not a full memory barrier */
977+
spin_unlock_wait(&rq->lock);
978+
}
979+
972980
static void __task_rq_unlock(struct rq *rq)
973981
__releases(rq->lock)
974982
{

0 commit comments

Comments
 (0)