All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched: fair: avoid integer overflow
@ 2013-11-10 19:42 Michal Nazarewicz
  2013-11-11 19:46 ` bsegall
  2013-11-13 17:25 ` [tip:sched/urgent] sched/fair: Avoid " tip-bot for Michal Nazarewicz
  0 siblings, 2 replies; 3+ messages in thread
From: Michal Nazarewicz @ 2013-11-10 19:42 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra; +Cc: linux-kernel, Michal Nazarewicz

From: Michal Nazarewicz <mina86@mina86.com>

sa->runnable_avg_sum is of type u32 but after shifting it by NICE_0_SHIFT
bits it is promoted to u64.  This of course makes no sense, since the
result will never be more then 32-bit long.  Casting sa->runnable_avg_sum
to u64 before it is shifted, fixes this problem.

Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index df77c60..50f1e170 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2153,7 +2153,7 @@ static inline void __update_tg_runnable_avg(struct sched_avg *sa,
 	long contrib;
 
 	/* The fraction of a cpu used by this cfs_rq */
-	contrib = div_u64(sa->runnable_avg_sum << NICE_0_SHIFT,
+	contrib = div_u64((u64)sa->runnable_avg_sum << NICE_0_SHIFT,
 			  sa->runnable_avg_period + 1);
 	contrib -= cfs_rq->tg_runnable_contrib;
 
-- 
1.8.3.2


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

* Re: [PATCH] sched: fair: avoid integer overflow
  2013-11-10 19:42 [PATCH] sched: fair: avoid integer overflow Michal Nazarewicz
@ 2013-11-11 19:46 ` bsegall
  2013-11-13 17:25 ` [tip:sched/urgent] sched/fair: Avoid " tip-bot for Michal Nazarewicz
  1 sibling, 0 replies; 3+ messages in thread
From: bsegall @ 2013-11-11 19:46 UTC (permalink / raw)
  To: Michal Nazarewicz
  Cc: Ingo Molnar, Peter Zijlstra, linux-kernel, Michal Nazarewicz

Michal Nazarewicz <mpn@google.com> writes:

> From: Michal Nazarewicz <mina86@mina86.com>
>
> sa->runnable_avg_sum is of type u32 but after shifting it by NICE_0_SHIFT
> bits it is promoted to u64.  This of course makes no sense, since the
> result will never be more then 32-bit long.  Casting sa->runnable_avg_sum
> to u64 before it is shifted, fixes this problem.
>
> Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Reviewed-by: Ben Segall <bsegall@google.com>

> ---
>  kernel/sched/fair.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index df77c60..50f1e170 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -2153,7 +2153,7 @@ static inline void __update_tg_runnable_avg(struct sched_avg *sa,
>  	long contrib;
>  
>  	/* The fraction of a cpu used by this cfs_rq */
> -	contrib = div_u64(sa->runnable_avg_sum << NICE_0_SHIFT,
> +	contrib = div_u64((u64)sa->runnable_avg_sum << NICE_0_SHIFT,
>  			  sa->runnable_avg_period + 1);
>  	contrib -= cfs_rq->tg_runnable_contrib;

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

* [tip:sched/urgent] sched/fair: Avoid integer overflow
  2013-11-10 19:42 [PATCH] sched: fair: avoid integer overflow Michal Nazarewicz
  2013-11-11 19:46 ` bsegall
@ 2013-11-13 17:25 ` tip-bot for Michal Nazarewicz
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Michal Nazarewicz @ 2013-11-13 17:25 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, bsegall, hpa, mingo, peterz, tglx, mina86

Commit-ID:  85b088e934b9943322bfe37077289ae60f1b3414
Gitweb:     http://git.kernel.org/tip/85b088e934b9943322bfe37077289ae60f1b3414
Author:     Michal Nazarewicz <mina86@mina86.com>
AuthorDate: Sun, 10 Nov 2013 20:42:01 +0100
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 13 Nov 2013 13:33:55 +0100

sched/fair: Avoid integer overflow

sa->runnable_avg_sum is of type u32 but after shifting it by NICE_0_SHIFT
bits it is promoted to u64.  This of course makes no sense, since the
result will never be more then 32-bit long.  Casting sa->runnable_avg_sum
to u64 before it is shifted, fixes this problem.

Reviewed-by: Ben Segall <bsegall@google.com>
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1384112521-25177-1-git-send-email-mpn@google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/fair.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 201be78..e8b652e 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2178,7 +2178,7 @@ static inline void __update_tg_runnable_avg(struct sched_avg *sa,
 	long contrib;
 
 	/* The fraction of a cpu used by this cfs_rq */
-	contrib = div_u64(sa->runnable_avg_sum << NICE_0_SHIFT,
+	contrib = div_u64((u64)sa->runnable_avg_sum << NICE_0_SHIFT,
 			  sa->runnable_avg_period + 1);
 	contrib -= cfs_rq->tg_runnable_contrib;
 

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

end of thread, other threads:[~2013-11-13 17:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-10 19:42 [PATCH] sched: fair: avoid integer overflow Michal Nazarewicz
2013-11-11 19:46 ` bsegall
2013-11-13 17:25 ` [tip:sched/urgent] sched/fair: Avoid " tip-bot for Michal Nazarewicz

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.