public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] posix-cpu-timers: avoid do_sys_times() races with __exit_signal()
@ 2009-06-12  6:49 Stanislaw Gruszka
  2009-06-12  7:09 ` Peter Zijlstra
  0 siblings, 1 reply; 6+ messages in thread
From: Stanislaw Gruszka @ 2009-06-12  6:49 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-kernel@vger.kernel.org, Oleg Nesterov, Peter Zijlstra,
	Ingo Molnar, Andrew Morton

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.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
 kernel/sys.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index e7998cf..0805d08 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -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);
-- 
1.6.0.6


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

* Re: [PATCH 1/2] posix-cpu-timers: avoid do_sys_times() races with __exit_signal()
  2009-06-12  6:49 Stanislaw Gruszka
@ 2009-06-12  7:09 ` Peter Zijlstra
  2009-06-12  7:56   ` Stanislaw Gruszka
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Zijlstra @ 2009-06-12  7:09 UTC (permalink / raw)
  To: Stanislaw Gruszka
  Cc: Thomas Gleixner, linux-kernel@vger.kernel.org, Oleg Nesterov,
	Ingo Molnar, Andrew Morton

On Fri, 2009-06-12 at 08:49 +0200, Stanislaw Gruszka wrote:
> 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.

Would be nice to have a description of exactly how you'd end up
accounting twice (and thus how this patch fixes it).

> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> ---
>  kernel/sys.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/kernel/sys.c b/kernel/sys.c
> index e7998cf..0805d08 100644
> --- a/kernel/sys.c
> +++ b/kernel/sys.c
> @@ -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);


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

* Re: [PATCH 1/2] posix-cpu-timers: avoid do_sys_times() races with __exit_signal()
  2009-06-12  7:09 ` Peter Zijlstra
@ 2009-06-12  7:56   ` Stanislaw Gruszka
  0 siblings, 0 replies; 6+ messages in thread
From: Stanislaw Gruszka @ 2009-06-12  7:56 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: Thomas Gleixner, linux-kernel@vger.kernel.org, Oleg Nesterov,
	Ingo Molnar, Andrew Morton

On Fri, 12 Jun 2009 09:09:58 +0200
Peter Zijlstra <a.p.zijlstra@chello.nl> wrote:

> On Fri, 2009-06-12 at 08:49 +0200, Stanislaw Gruszka wrote:
> > 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.
> 
> Would be nice to have a description of exactly how you'd end up
> accounting twice (and thus how this patch fixes it).

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.
So some exiting threads times could be accounted twice.

Stanislaw

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

* [PATCH 1/2] posix-cpu-timers: avoid do_sys_times() races with __exit_signal()
@ 2009-06-12  8:34 Stanislaw Gruszka
  2009-06-12 13:46 ` Oleg Nesterov
  0 siblings, 1 reply; 6+ messages in thread
From: Stanislaw Gruszka @ 2009-06-12  8:34 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-kernel@vger.kernel.org, Oleg Nesterov, Peter Zijlstra,
	Ingo Molnar, Andrew Morton

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.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
 kernel/sys.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index e7998cf..0805d08 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -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);
-- 
1.6.0.6


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

* Re: [PATCH 1/2] posix-cpu-timers: avoid do_sys_times() races with __exit_signal()
  2009-06-12  8:34 [PATCH 1/2] posix-cpu-timers: avoid do_sys_times() races with __exit_signal() Stanislaw Gruszka
@ 2009-06-12 13:46 ` Oleg Nesterov
  0 siblings, 0 replies; 6+ messages in thread
From: Oleg Nesterov @ 2009-06-12 13:46 UTC (permalink / raw)
  To: Stanislaw Gruszka
  Cc: Thomas Gleixner, linux-kernel@vger.kernel.org, Peter Zijlstra,
	Ingo Molnar, Andrew Morton

On 06/12, Stanislaw Gruszka wrote:
>
> 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.


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

* [PATCH 1/2] posix-cpu-timers: avoid do_sys_times() races with __exit_signal()
@ 2009-06-15  8:36 Stanislaw Gruszka
  0 siblings, 0 replies; 6+ messages in thread
From: Stanislaw Gruszka @ 2009-06-15  8:36 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: linux-kernel@vger.kernel.org, Oleg Nesterov, Peter Zijlstra,
	Ingo Molnar

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.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
 kernel/sys.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index 438d99a..aef73e1 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -914,8 +914,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);
-- 
1.5.5.6

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

end of thread, other threads:[~2009-06-15  8:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-12  8:34 [PATCH 1/2] posix-cpu-timers: avoid do_sys_times() races with __exit_signal() Stanislaw Gruszka
2009-06-12 13:46 ` Oleg Nesterov
  -- strict thread matches above, loose matches on Subject: below --
2009-06-15  8:36 Stanislaw Gruszka
2009-06-12  6:49 Stanislaw Gruszka
2009-06-12  7:09 ` Peter Zijlstra
2009-06-12  7:56   ` Stanislaw Gruszka

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