aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2008-11-10 09:39:30 -0500
committerIngo Molnar <mingo@elte.hu>2008-11-11 02:01:43 -0500
commitad474caca3e2a0550b7ce0706527ad5ab389a4d4 (patch)
tree6d4e5cbcee3a85230317a33d66655ece0c873f5c
parent5ac5c4d604bf894ef672a7971d03fefdc7ea7e49 (diff)
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 <oleg@redhat.com> Acked-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@elte.hu> Reported-by: Doug Chapman <doug.chapman@hp.com>
-rw-r--r--include/linux/sched.h1
-rw-r--r--kernel/exit.c5
-rw-r--r--kernel/sched.c8
3 files changed, 14 insertions, 0 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 295b7c756ca6..644ffbda17ca 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -247,6 +247,7 @@ extern void init_idle(struct task_struct *idle, int cpu);
247extern void init_idle_bootup_task(struct task_struct *idle); 247extern void init_idle_bootup_task(struct task_struct *idle);
248 248
249extern int runqueue_is_locked(void); 249extern int runqueue_is_locked(void);
250extern void task_rq_unlock_wait(struct task_struct *p);
250 251
251extern cpumask_t nohz_cpu_mask; 252extern cpumask_t nohz_cpu_mask;
252#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ) 253#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
diff --git a/kernel/exit.c b/kernel/exit.c
index 80137a5d9467..ae2b92be5fae 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -141,6 +141,11 @@ static void __exit_signal(struct task_struct *tsk)
141 if (sig) { 141 if (sig) {
142 flush_sigqueue(&sig->shared_pending); 142 flush_sigqueue(&sig->shared_pending);
143 taskstats_tgid_free(sig); 143 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);
144 __cleanup_signal(sig); 149 __cleanup_signal(sig);
145 } 150 }
146} 151}
diff --git a/kernel/sched.c b/kernel/sched.c
index f3149244e324..50a21f964679 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -969,6 +969,14 @@ static struct rq *task_rq_lock(struct task_struct *p, unsigned long *flags)
969 } 969 }
970} 970}
971 971
972void 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
972static void __task_rq_unlock(struct rq *rq) 980static void __task_rq_unlock(struct rq *rq)
973 __releases(rq->lock) 981 __releases(rq->lock)
974{ 982{