public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] account_group_exec_runtime: fix the racy usage of ->signal
@ 2008-11-07 16:52 Oleg Nesterov
  2008-11-07 16:21 ` Ingo Molnar
  0 siblings, 1 reply; 8+ messages in thread
From: Oleg Nesterov @ 2008-11-07 16:52 UTC (permalink / raw)
  To: Andrew Morton, Ingo Molnar
  Cc: adobriyan, Doug Chapman, Peter Zijlstra, Roland McGrath,
	linux-kernel

Compile tested.

Unlike other similar routines, account_group_exec_runtime() could be
called "implicitly" after exit_notify(). This means we can race with
the parent doing release_task(), we can't just check ->signal != NULL.

Take ->siglock to make sure ->signal can't go away.

This is the minimal fix, with this patch we don't need need get/put cpu,
and I think we should uninline this function.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>

--- K-28/kernel/sched_stats.h~A_G_E_R_FIX	2008-11-07 17:32:02.000000000 +0100
+++ K-28/kernel/sched_stats.h	2008-11-07 17:44:39.000000000 +0100
@@ -351,10 +351,12 @@ static inline void account_group_exec_ru
 					      unsigned long long ns)
 {
 	struct signal_struct *sig;
+	unsigned long flags;
 
-	sig = tsk->signal;
-	if (unlikely(!sig))
+	if (unlikely(!lock_task_sighand(tsk, &flags)))
 		return;
+
+	sig = tsk->signal;
 	if (sig->cputime.totals) {
 		struct task_cputime *times;
 
@@ -362,4 +364,6 @@ static inline void account_group_exec_ru
 		times->sum_exec_runtime += ns;
 		put_cpu_no_resched();
 	}
+
+	unlock_task_sighand(tsk, &flags);
 }


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-11-10 12:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-07 16:52 [PATCH] account_group_exec_runtime: fix the racy usage of ->signal Oleg Nesterov
2008-11-07 16:21 ` Ingo Molnar
2008-11-07 16:58   ` Doug Chapman
2008-11-07 18:42     ` Oleg Nesterov
2008-11-07 17:40   ` Oleg Nesterov
2008-11-08  9:28     ` Ingo Molnar
2008-11-10 13:04       ` Oleg Nesterov
2008-11-10 12:13         ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox