public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] posix-timers: fix RLIMIT_CPU && setitimer(CPUCLOCK_PROF)
@ 2009-03-27  0:06 Oleg Nesterov
  2009-03-27 23:59 ` Peter Zijlstra
  2009-04-08 16:09 ` [tip:timers/urgent] " Oleg Nesterov
  0 siblings, 2 replies; 3+ 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

update_rlimit_cpu() tries to optimize out set_process_cpu_timer() in case
when we already have CPUCLOCK_PROF timer which should expire first. But it
uses cputime_lt() instead of cputime_gt().

Test case:

	int main(void)
	{
		struct itimerval it = {
			.it_value = { .tv_sec = 1000 },
		};

		assert(!setitimer(ITIMER_PROF, &it, NULL));

		struct rlimit rl = {
			.rlim_cur = 1,
			.rlim_max = 1,
		};

		assert(!setrlimit(RLIMIT_CPU, &rl));

		for (;;)
			;

		return 0;
	}

Without this patch, the task is not killed as RLIMIT_CPU demands.

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

--- 6.29/kernel/posix-cpu-timers.c~2_UPDATE_RLIM	2009-03-23 18:13:57.000000000 +0100
+++ 6.29/kernel/posix-cpu-timers.c	2009-03-27 00:45:31.000000000 +0100
@@ -18,7 +18,7 @@ void update_rlimit_cpu(unsigned long rli
 
 	cputime = secs_to_cputime(rlim_new);
 	if (cputime_eq(current->signal->it_prof_expires, cputime_zero) ||
-	    cputime_lt(current->signal->it_prof_expires, cputime)) {
+	    cputime_gt(current->signal->it_prof_expires, cputime)) {
 		spin_lock_irq(&current->sighand->siglock);
 		set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL);
 		spin_unlock_irq(&current->sighand->siglock);


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

* Re: [PATCH 2/2] posix-timers: fix RLIMIT_CPU && setitimer(CPUCLOCK_PROF)
  2009-03-27  0:06 [PATCH 2/2] posix-timers: fix RLIMIT_CPU && setitimer(CPUCLOCK_PROF) Oleg Nesterov
@ 2009-03-27 23:59 ` Peter Zijlstra
  2009-04-08 16:09 ` [tip:timers/urgent] " Oleg Nesterov
  1 sibling, 0 replies; 3+ 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:
> update_rlimit_cpu() tries to optimize out set_process_cpu_timer() in case
> when we already have CPUCLOCK_PROF timer which should expire first. But it
> uses cputime_lt() instead of cputime_gt().
> 
> Test case:
> 
> 	int main(void)
> 	{
> 		struct itimerval it = {
> 			.it_value = { .tv_sec = 1000 },
> 		};
> 
> 		assert(!setitimer(ITIMER_PROF, &it, NULL));
> 
> 		struct rlimit rl = {
> 			.rlim_cur = 1,
> 			.rlim_max = 1,
> 		};
> 
> 		assert(!setrlimit(RLIMIT_CPU, &rl));
> 
> 		for (;;)
> 			;
> 
> 		return 0;
> 	}
> 
> Without this patch, the task is not killed as RLIMIT_CPU demands.
> 
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>

Nice catch,

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

> --- 6.29/kernel/posix-cpu-timers.c~2_UPDATE_RLIM	2009-03-23 18:13:57.000000000 +0100
> +++ 6.29/kernel/posix-cpu-timers.c	2009-03-27 00:45:31.000000000 +0100
> @@ -18,7 +18,7 @@ void update_rlimit_cpu(unsigned long rli
>  
>  	cputime = secs_to_cputime(rlim_new);
>  	if (cputime_eq(current->signal->it_prof_expires, cputime_zero) ||
> -	    cputime_lt(current->signal->it_prof_expires, cputime)) {
> +	    cputime_gt(current->signal->it_prof_expires, cputime)) {
>  		spin_lock_irq(&current->sighand->siglock);
>  		set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL);
>  		spin_unlock_irq(&current->sighand->siglock);
> 


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

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

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

posix-timers: fix RLIMIT_CPU && setitimer(CPUCLOCK_PROF)

update_rlimit_cpu() tries to optimize out set_process_cpu_timer() in case
when we already have CPUCLOCK_PROF timer which should expire first. But it
uses cputime_lt() instead of cputime_gt().

Test case:

	int main(void)
	{
		struct itimerval it = {
			.it_value = { .tv_sec = 1000 },
		};

		assert(!setitimer(ITIMER_PROF, &it, NULL));

		struct rlimit rl = {
			.rlim_cur = 1,
			.rlim_max = 1,
		};

		assert(!setrlimit(RLIMIT_CPU, &rl));

		for (;;)
			;

		return 0;
	}

Without this patch, the task is not killed as RLIMIT_CPU demands.

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: <20090327000610.GA10108@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>


---
 kernel/posix-cpu-timers.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
index 8e5d9a6..bb53185 100644
--- a/kernel/posix-cpu-timers.c
+++ b/kernel/posix-cpu-timers.c
@@ -18,7 +18,7 @@ void update_rlimit_cpu(unsigned long rlim_new)
 
 	cputime = secs_to_cputime(rlim_new);
 	if (cputime_eq(current->signal->it_prof_expires, cputime_zero) ||
-	    cputime_lt(current->signal->it_prof_expires, cputime)) {
+	    cputime_gt(current->signal->it_prof_expires, cputime)) {
 		spin_lock_irq(&current->sighand->siglock);
 		set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL);
 		spin_unlock_irq(&current->sighand->siglock);

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

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

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

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