public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] sched: fix broken SCHED_RESET_ON_FORK handling
@ 2011-07-27 15:14 Mike Galbraith
  2011-07-27 16:10 ` Mike Galbraith
  2011-08-14 15:58 ` [tip:sched/core] " tip-bot for Mike Galbraith
  0 siblings, 2 replies; 3+ messages in thread
From: Mike Galbraith @ 2011-07-27 15:14 UTC (permalink / raw)
  To: LKML; +Cc: Peter Zijlstra, Ingo Molnar


sched: fix broken SCHED_RESET_ON_FORK handling

Setting child->prio = current->normal_prio _after_ SCHED_RESET_ON_FORK has
been handled for an RT parent gives birth to a deranged mutant child with
non-RT policy, but RT prio and sched_class.

Move PI leakage protection up, always set priorities and weight, and if the
child is leaving RT class, reset rt_priority to the proper value.

Signed-off-by: Mike Galbraith <efault@gmx.de>
Cc: <stable@kernel.org>

diff --git a/kernel/sched.c b/kernel/sched.c
index 0281f84..a3e65a0 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -2804,19 +2804,23 @@ void sched_fork(struct task_struct *p)
 	p->state = TASK_RUNNING;
 
 	/*
+	 * Make sure we do not leak PI boosting priority to the child.
+	 */
+	p->prio = current->normal_prio;
+
+	/*
 	 * Revert to default priority/policy on fork if requested.
 	 */
 	if (unlikely(p->sched_reset_on_fork)) {
-		if (p->policy == SCHED_FIFO || p->policy == SCHED_RR) {
+		if (task_has_rt_policy(p)) {
 			p->policy = SCHED_NORMAL;
-			p->normal_prio = p->static_prio;
-		}
-
-		if (PRIO_TO_NICE(p->static_prio) < 0) {
 			p->static_prio = NICE_TO_PRIO(0);
-			p->normal_prio = p->static_prio;
-			set_load_weight(p);
-		}
+			p->rt_priority = 0;
+		} else if (PRIO_TO_NICE(p->static_prio) < 0)
+			p->static_prio = NICE_TO_PRIO(0);
+
+		p->prio = p->normal_prio = __normal_prio(p);
+		set_load_weight(p);
 
 		/*
 		 * We don't need the reset flag anymore after the fork. It has
@@ -2825,11 +2829,6 @@ void sched_fork(struct task_struct *p)
 		p->sched_reset_on_fork = 0;
 	}
 
-	/*
-	 * Make sure we do not leak PI boosting priority to the child.
-	 */
-	p->prio = current->normal_prio;
-
 	if (!rt_prio(p->prio))
 		p->sched_class = &fair_sched_class;
 



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

* Re: [patch] sched: fix broken SCHED_RESET_ON_FORK handling
  2011-07-27 15:14 [patch] sched: fix broken SCHED_RESET_ON_FORK handling Mike Galbraith
@ 2011-07-27 16:10 ` Mike Galbraith
  2011-08-14 15:58 ` [tip:sched/core] " tip-bot for Mike Galbraith
  1 sibling, 0 replies; 3+ messages in thread
From: Mike Galbraith @ 2011-07-27 16:10 UTC (permalink / raw)
  To: LKML; +Cc: Peter Zijlstra, Ingo Molnar

I knew that thing had been moved before.. see f83f9ac2.

On Wed, 2011-07-27 at 17:14 +0200, Mike Galbraith wrote:
> sched: fix broken SCHED_RESET_ON_FORK handling
> 
> Setting child->prio = current->normal_prio _after_ SCHED_RESET_ON_FORK has
> been handled for an RT parent gives birth to a deranged mutant child with
> non-RT policy, but RT prio and sched_class.
> 
> Move PI leakage protection up, always set priorities and weight, and if the
> child is leaving RT class, reset rt_priority to the proper value.
> 
> Signed-off-by: Mike Galbraith <efault@gmx.de>
> Cc: <stable@kernel.org>
> 
> diff --git a/kernel/sched.c b/kernel/sched.c
> index 0281f84..a3e65a0 100644
> --- a/kernel/sched.c
> +++ b/kernel/sched.c
> @@ -2804,19 +2804,23 @@ void sched_fork(struct task_struct *p)
>  	p->state = TASK_RUNNING;
>  
>  	/*
> +	 * Make sure we do not leak PI boosting priority to the child.
> +	 */
> +	p->prio = current->normal_prio;
> +
> +	/*
>  	 * Revert to default priority/policy on fork if requested.
>  	 */
>  	if (unlikely(p->sched_reset_on_fork)) {
> -		if (p->policy == SCHED_FIFO || p->policy == SCHED_RR) {
> +		if (task_has_rt_policy(p)) {
>  			p->policy = SCHED_NORMAL;
> -			p->normal_prio = p->static_prio;
> -		}
> -
> -		if (PRIO_TO_NICE(p->static_prio) < 0) {
>  			p->static_prio = NICE_TO_PRIO(0);
> -			p->normal_prio = p->static_prio;
> -			set_load_weight(p);
> -		}
> +			p->rt_priority = 0;
> +		} else if (PRIO_TO_NICE(p->static_prio) < 0)
> +			p->static_prio = NICE_TO_PRIO(0);
> +
> +		p->prio = p->normal_prio = __normal_prio(p);
> +		set_load_weight(p);
>  
>  		/*
>  		 * We don't need the reset flag anymore after the fork. It has
> @@ -2825,11 +2829,6 @@ void sched_fork(struct task_struct *p)
>  		p->sched_reset_on_fork = 0;
>  	}
>  
> -	/*
> -	 * Make sure we do not leak PI boosting priority to the child.
> -	 */
> -	p->prio = current->normal_prio;
> -
>  	if (!rt_prio(p->prio))
>  		p->sched_class = &fair_sched_class;
>  
> 
> 



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

* [tip:sched/core] sched: fix broken SCHED_RESET_ON_FORK handling
  2011-07-27 15:14 [patch] sched: fix broken SCHED_RESET_ON_FORK handling Mike Galbraith
  2011-07-27 16:10 ` Mike Galbraith
@ 2011-08-14 15:58 ` tip-bot for Mike Galbraith
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Mike Galbraith @ 2011-08-14 15:58 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, a.p.zijlstra, efault, tglx, mingo

Commit-ID:  c350a04efd1c89cd256b2abc8f07a21d0d53ff24
Gitweb:     http://git.kernel.org/tip/c350a04efd1c89cd256b2abc8f07a21d0d53ff24
Author:     Mike Galbraith <efault@gmx.de>
AuthorDate: Wed, 27 Jul 2011 17:14:55 +0200
Committer:  Ingo Molnar <mingo@elte.hu>
CommitDate: Sun, 14 Aug 2011 12:00:43 +0200

sched: fix broken SCHED_RESET_ON_FORK handling

Setting child->prio = current->normal_prio _after_ SCHED_RESET_ON_FORK has
been handled for an RT parent gives birth to a deranged mutant child with
non-RT policy, but RT prio and sched_class.

Move PI leakage protection up, always set priorities and weight, and if the
child is leaving RT class, reset rt_priority to the proper value.

Signed-off-by: Mike Galbraith <efault@gmx.de>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1311779695.8691.2.camel@marge.simson.net
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
 kernel/sched.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index b1e8f0e..cf427bb 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -2844,19 +2844,23 @@ void sched_fork(struct task_struct *p)
 	p->state = TASK_RUNNING;
 
 	/*
+	 * Make sure we do not leak PI boosting priority to the child.
+	 */
+	p->prio = current->normal_prio;
+
+	/*
 	 * Revert to default priority/policy on fork if requested.
 	 */
 	if (unlikely(p->sched_reset_on_fork)) {
-		if (p->policy == SCHED_FIFO || p->policy == SCHED_RR) {
+		if (task_has_rt_policy(p)) {
 			p->policy = SCHED_NORMAL;
-			p->normal_prio = p->static_prio;
-		}
-
-		if (PRIO_TO_NICE(p->static_prio) < 0) {
 			p->static_prio = NICE_TO_PRIO(0);
-			p->normal_prio = p->static_prio;
-			set_load_weight(p);
-		}
+			p->rt_priority = 0;
+		} else if (PRIO_TO_NICE(p->static_prio) < 0)
+			p->static_prio = NICE_TO_PRIO(0);
+
+		p->prio = p->normal_prio = __normal_prio(p);
+		set_load_weight(p);
 
 		/*
 		 * We don't need the reset flag anymore after the fork. It has
@@ -2865,11 +2869,6 @@ void sched_fork(struct task_struct *p)
 		p->sched_reset_on_fork = 0;
 	}
 
-	/*
-	 * Make sure we do not leak PI boosting priority to the child.
-	 */
-	p->prio = current->normal_prio;
-
 	if (!rt_prio(p->prio))
 		p->sched_class = &fair_sched_class;
 

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

end of thread, other threads:[~2011-08-14 15:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-27 15:14 [patch] sched: fix broken SCHED_RESET_ON_FORK handling Mike Galbraith
2011-07-27 16:10 ` Mike Galbraith
2011-08-14 15:58 ` [tip:sched/core] " tip-bot for Mike Galbraith

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