Skip to contentSkip to conversation

posix-cpu-timers: avoid do_sys_times() races with __exit_signal()

PATCH In review Stanislaw Gruszka 2 participants 2 messages Jun 12, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 posix-cpu-timers: avoid do_sys_times() races with __exit_signal()

Protect thread_group_cputime() call by siglock, to avoid possible (but to be honest - very improbable) double times accounting of exiting task. This is revert of commit 2b5fe6de58276d0b5a7c884d5dbfc300ca47db78 "thread_group_cputime: move a couple of callsites outside of ->siglock", but implementation of thread_group_cputime() was different then.

In thread_group_cputime() we loop on all threads within the group to sum they cputimes. After finish loop, we add killed tasks times from tsk->signal. If thread (one or more) exit in gap between loop and adding killed tasks times, __exit_signal() function add already accounted times to tsk->signal.

---
 kernel/sys.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sys.c +1 -1
index e7998cf..0805d08 100644
@@ -913,8 +913,8 @@ void do_sys_times(struct tms *tms)
 	struct task_cputime cputime;
 	cputime_t cutime, cstime;
 
-	thread_group_cputime(current, &cputime);
 	spin_lock_irq(&current->sighand->siglock);
+	thread_group_cputime(current, &cputime);
 	cutime = current->signal->cutime;
 	cstime = current->signal->cstime;
 	spin_unlock_irq(&current->sighand->siglock);
Signature · 1 line
1.6.0.6
#1 lore raw
Quoted 6 lines · Stanislaw Gruszka

Protect thread_group_cputime() call by siglock, to avoid possible (but to be honest - very improbable) double times accounting of exiting task. This is revert of commit 2b5fe6de58276d0b5a7c884d5dbfc300ca47db78 "thread_group_cputime: move a couple of callsites outside of ->siglock", but implementation of thread_group_cputime() was different then.

Yes, at that time thread_group_cputime() was reading per-cpu data, and ->siglock was unneeded.

I think the patch is correct.

Oleg.