All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] posix-timers: fix RLIMIT_CPU && fork()
@ 2009-03-27  0:06 Oleg Nesterov
  2009-03-27 23:59 ` Peter Zijlstra
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Oleg Nesterov @ 2009-03-27  0:06 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Peter Lojkin, Peter Zijlstra, Roland McGrath, linux-kernel, stable

See http://bugzilla.kernel.org/show_bug.cgi?id=12911

copy_signal() copies signal->rlim, but RLIMIT_CPU is "lost". Because
posix_cpu_timers_init_group() sets cputime_expires.prof_exp = 0 and thus
fastpath_timer_check() returns false unless we have other expired cpu timers.

Change copy_signal() to set cputime_expires.prof_exp if we have RLIMIT_CPU.
Also, set cputimer.running = 1 in that case. This is not strictly necessary,
but imho makes sense.

Reported-by: Peter Lojkin <ia6432@inbox.ru>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>

--- 6.29/kernel/fork.c~1_FORK	2009-03-23 18:14:34.000000000 +0100
+++ 6.29/kernel/fork.c	2009-03-27 00:25:52.000000000 +0100
@@ -808,6 +808,12 @@ static void posix_cpu_timers_init_group(
 	sig->cputime_expires.virt_exp = cputime_zero;
 	sig->cputime_expires.sched_exp = 0;
 
+	if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) {
+		sig->cputime_expires.prof_exp =
+			secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur);
+		sig->cputimer.running = 1;
+	}
+
 	/* The timer lists. */
 	INIT_LIST_HEAD(&sig->cpu_timers[0]);
 	INIT_LIST_HEAD(&sig->cpu_timers[1]);
@@ -823,11 +829,8 @@ static int copy_signal(unsigned long clo
 		atomic_inc(&current->signal->live);
 		return 0;
 	}
-	sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
-
-	if (sig)
-		posix_cpu_timers_init_group(sig);
 
+	sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
 	tsk->signal = sig;
 	if (!sig)
 		return -ENOMEM;
@@ -865,6 +868,8 @@ static int copy_signal(unsigned long clo
 	memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim);
 	task_unlock(current->group_leader);
 
+	posix_cpu_timers_init_group(sig);
+
 	acct_init_pacct(&sig->pacct);
 
 	tty_audit_fork(sig);


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

* Re: [PATCH 1/2] posix-timers: fix RLIMIT_CPU && fork()
  2009-03-27  0:06 [PATCH 1/2] posix-timers: fix RLIMIT_CPU && fork() Oleg Nesterov
@ 2009-03-27 23:59 ` Peter Zijlstra
  2009-03-31  3:01 ` [stable] " Chris Wright
  2009-04-08 16:09 ` [tip:timers/urgent] " Oleg Nesterov
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2009-03-27 23:59 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Ingo Molnar, Peter Lojkin, Roland McGrath, linux-kernel, stable

On Fri, 2009-03-27 at 01:06 +0100, Oleg Nesterov wrote:
> See http://bugzilla.kernel.org/show_bug.cgi?id=12911
> 
> copy_signal() copies signal->rlim, but RLIMIT_CPU is "lost". Because
> posix_cpu_timers_init_group() sets cputime_expires.prof_exp = 0 and thus
> fastpath_timer_check() returns false unless we have other expired cpu timers.
> 
> Change copy_signal() to set cputime_expires.prof_exp if we have RLIMIT_CPU.
> Also, set cputimer.running = 1 in that case. This is not strictly necessary,
> but imho makes sense.

The other site that enables is also syncs the timer with the clock, but
since we're doing clone_signal, I presume there isn't much of a thread
group to sync to anyway.

Looks good, thanks for looking into this.

Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>

> Reported-by: Peter Lojkin <ia6432@inbox.ru>
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> 
> --- 6.29/kernel/fork.c~1_FORK	2009-03-23 18:14:34.000000000 +0100
> +++ 6.29/kernel/fork.c	2009-03-27 00:25:52.000000000 +0100
> @@ -808,6 +808,12 @@ static void posix_cpu_timers_init_group(
>  	sig->cputime_expires.virt_exp = cputime_zero;
>  	sig->cputime_expires.sched_exp = 0;
>  
> +	if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) {
> +		sig->cputime_expires.prof_exp =
> +			secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur);
> +		sig->cputimer.running = 1;
> +	}
> +
>  	/* The timer lists. */
>  	INIT_LIST_HEAD(&sig->cpu_timers[0]);
>  	INIT_LIST_HEAD(&sig->cpu_timers[1]);
> @@ -823,11 +829,8 @@ static int copy_signal(unsigned long clo
>  		atomic_inc(&current->signal->live);
>  		return 0;
>  	}
> -	sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
> -
> -	if (sig)
> -		posix_cpu_timers_init_group(sig);
>  
> +	sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
>  	tsk->signal = sig;
>  	if (!sig)
>  		return -ENOMEM;
> @@ -865,6 +868,8 @@ static int copy_signal(unsigned long clo
>  	memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim);
>  	task_unlock(current->group_leader);
>  
> +	posix_cpu_timers_init_group(sig);
> +
>  	acct_init_pacct(&sig->pacct);
>  
>  	tty_audit_fork(sig);
> 


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

* Re: [stable] [PATCH 1/2] posix-timers: fix RLIMIT_CPU && fork()
  2009-03-27  0:06 [PATCH 1/2] posix-timers: fix RLIMIT_CPU && fork() Oleg Nesterov
  2009-03-27 23:59 ` Peter Zijlstra
@ 2009-03-31  3:01 ` Chris Wright
  2009-03-31 14:57   ` Oleg Nesterov
  2009-04-08 16:09 ` [tip:timers/urgent] " Oleg Nesterov
  2 siblings, 1 reply; 5+ messages in thread
From: Chris Wright @ 2009-03-31  3:01 UTC (permalink / raw)
  To: Oleg Nesterov
  Cc: Ingo Molnar, Peter Zijlstra, Peter Lojkin, linux-kernel,
	Roland McGrath, stable

* Oleg Nesterov (oleg@redhat.com) wrote:
> See http://bugzilla.kernel.org/show_bug.cgi?id=12911
> 
> copy_signal() copies signal->rlim, but RLIMIT_CPU is "lost". Because
> posix_cpu_timers_init_group() sets cputime_expires.prof_exp = 0 and thus
> fastpath_timer_check() returns false unless we have other expired cpu timers.
> 
> Change copy_signal() to set cputime_expires.prof_exp if we have RLIMIT_CPU.
> Also, set cputimer.running = 1 in that case. This is not strictly necessary,
> but imho makes sense.

For -stable should this be instead of 37bebc70d7ad4144c571d74500db3bb26ec0c0eb?

thanks,
-chris

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

* Re: [stable] [PATCH 1/2] posix-timers: fix RLIMIT_CPU && fork()
  2009-03-31  3:01 ` [stable] " Chris Wright
@ 2009-03-31 14:57   ` Oleg Nesterov
  0 siblings, 0 replies; 5+ messages in thread
From: Oleg Nesterov @ 2009-03-31 14:57 UTC (permalink / raw)
  To: Chris Wright
  Cc: Ingo Molnar, Peter Zijlstra, Peter Lojkin, linux-kernel,
	Roland McGrath, stable

On 03/31, Chris Wright wrote:
>
> * Oleg Nesterov (oleg@redhat.com) wrote:
> > See http://bugzilla.kernel.org/show_bug.cgi?id=12911
> >
> > copy_signal() copies signal->rlim, but RLIMIT_CPU is "lost". Because
> > posix_cpu_timers_init_group() sets cputime_expires.prof_exp = 0 and thus
> > fastpath_timer_check() returns false unless we have other expired cpu timers.
> >
> > Change copy_signal() to set cputime_expires.prof_exp if we have RLIMIT_CPU.
> > Also, set cputimer.running = 1 in that case. This is not strictly necessary,
> > but imho makes sense.
>
> For -stable should this be instead of 37bebc70d7ad4144c571d74500db3bb26ec0c0eb?

Yes, sorry for confusion.

The commit above was targeted for 2.6.29, it is not optimal. When/if
"[PATCH 1/2] posix-timers: fix RLIMIT_CPU && fork()" will be merged, I'll sent
the "revert" patch.

see http://marc.info/?t=123783777600004

Oleg.


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

* [tip:timers/urgent] posix-timers: fix RLIMIT_CPU && fork()
  2009-03-27  0:06 [PATCH 1/2] posix-timers: fix RLIMIT_CPU && fork() Oleg Nesterov
  2009-03-27 23:59 ` Peter Zijlstra
  2009-03-31  3:01 ` [stable] " Chris Wright
@ 2009-04-08 16:09 ` Oleg Nesterov
  2 siblings, 0 replies; 5+ messages in thread
From: Oleg Nesterov @ 2009-04-08 16:09 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, peterz, ia6432, roland, tglx, oleg, mingo

Commit-ID:  6279a751fe096a21dc7704e918d570d3ff06e769
Gitweb:     http://git.kernel.org/tip/6279a751fe096a21dc7704e918d570d3ff06e769
Author:     Oleg Nesterov <oleg@redhat.com>
AuthorDate: Fri, 27 Mar 2009 01:06:07 +0100
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Wed, 8 Apr 2009 17:51:38 +0200

posix-timers: fix RLIMIT_CPU && fork()

See http://bugzilla.kernel.org/show_bug.cgi?id=12911

copy_signal() copies signal->rlim, but RLIMIT_CPU is "lost". Because
posix_cpu_timers_init_group() sets cputime_expires.prof_exp = 0 and thus
fastpath_timer_check() returns false unless we have other expired cpu timers.

Change copy_signal() to set cputime_expires.prof_exp if we have RLIMIT_CPU.
Also, set cputimer.running = 1 in that case. This is not strictly necessary,
but imho makes sense.

Reported-by: Peter Lojkin <ia6432@inbox.ru>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Cc: Peter Lojkin <ia6432@inbox.ru>
Cc: Roland McGrath <roland@redhat.com>
Cc: stable@kernel.org
LKML-Reference: <20090327000607.GA10104@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>


---
 kernel/fork.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/kernel/fork.c b/kernel/fork.c
index 4854c2c..9b51a1b 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -808,6 +808,12 @@ static void posix_cpu_timers_init_group(struct signal_struct *sig)
 	sig->cputime_expires.virt_exp = cputime_zero;
 	sig->cputime_expires.sched_exp = 0;
 
+	if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) {
+		sig->cputime_expires.prof_exp =
+			secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur);
+		sig->cputimer.running = 1;
+	}
+
 	/* The timer lists. */
 	INIT_LIST_HEAD(&sig->cpu_timers[0]);
 	INIT_LIST_HEAD(&sig->cpu_timers[1]);
@@ -823,11 +829,8 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
 		atomic_inc(&current->signal->live);
 		return 0;
 	}
-	sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
-
-	if (sig)
-		posix_cpu_timers_init_group(sig);
 
+	sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
 	tsk->signal = sig;
 	if (!sig)
 		return -ENOMEM;
@@ -865,6 +868,8 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
 	memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim);
 	task_unlock(current->group_leader);
 
+	posix_cpu_timers_init_group(sig);
+
 	acct_init_pacct(&sig->pacct);
 
 	tty_audit_fork(sig);

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

end of thread, other threads:[~2009-04-08 16:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-27  0:06 [PATCH 1/2] posix-timers: fix RLIMIT_CPU && fork() Oleg Nesterov
2009-03-27 23:59 ` Peter Zijlstra
2009-03-31  3:01 ` [stable] " Chris Wright
2009-03-31 14:57   ` Oleg Nesterov
2009-04-08 16:09 ` [tip:timers/urgent] " Oleg Nesterov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.