All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] timers: Fix overflow in get_next_timer_interrupt
@ 2017-08-01  7:11 Matija Glavinic Pecotic
  2017-08-01  8:16 ` Alexander Sverdlin
  2017-08-01 12:25 ` [tip:timers/urgent] " tip-bot for Matija Glavinic Pecotic
  0 siblings, 2 replies; 3+ messages in thread
From: Matija Glavinic Pecotic @ 2017-08-01  7:11 UTC (permalink / raw)
  To: khilman, tglx, mingo, akpm, hpa, linux-kernel
  Cc: Sverdlin, Alexander (Nokia - DE/Ulm)

For e.g. HZ=100, timer being 430 jiffies in the future, and 32 bit
unsigned int, there is an overflow on unsigned int right-hand side
of the expression which results with wrong values being returned.

Problem was observed on tickless core and with following applied:

	sched/nohz: add debugfs control over sched_tick_max_deferment
	https://lkml.org/lkml/2013/9/16/499

Signed-off-by: Matija Glavinic Pecotic <matija.glavinic-pecotic.ext@nokia.com>
---
 kernel/time/timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 71ce3f4..8f5d1bf 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1495,7 +1495,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
 		base->is_idle = false;
 	} else {
 		if (!is_max_delta)
-			expires = basem + (nextevt - basej) * TICK_NSEC;
+			expires = basem + (u64)(nextevt - basej) * TICK_NSEC;
 		/*
 		 * If we expect to sleep more than a tick, mark the base idle:
 		 */
-- 
2.1.4

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

* Re: [PATCH] timers: Fix overflow in get_next_timer_interrupt
  2017-08-01  7:11 [PATCH] timers: Fix overflow in get_next_timer_interrupt Matija Glavinic Pecotic
@ 2017-08-01  8:16 ` Alexander Sverdlin
  2017-08-01 12:25 ` [tip:timers/urgent] " tip-bot for Matija Glavinic Pecotic
  1 sibling, 0 replies; 3+ messages in thread
From: Alexander Sverdlin @ 2017-08-01  8:16 UTC (permalink / raw)
  To: Matija Glavinic Pecotic, khilman, tglx, mingo, akpm, hpa, linux-kernel

On 01/08/17 09:11, Matija Glavinic Pecotic wrote:
> For e.g. HZ=100, timer being 430 jiffies in the future, and 32 bit
> unsigned int, there is an overflow on unsigned int right-hand side
> of the expression which results with wrong values being returned.
> 
> Problem was observed on tickless core and with following applied:
> 
> 	sched/nohz: add debugfs control over sched_tick_max_deferment
> 	https://lkml.org/lkml/2013/9/16/499
> 
> Signed-off-by: Matija Glavinic Pecotic <matija.glavinic-pecotic.ext@nokia.com>

Reviewed-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>

> ---
>  kernel/time/timer.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/time/timer.c b/kernel/time/timer.c
> index 71ce3f4..8f5d1bf 100644
> --- a/kernel/time/timer.c
> +++ b/kernel/time/timer.c
> @@ -1495,7 +1495,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
>  		base->is_idle = false;
>  	} else {
>  		if (!is_max_delta)
> -			expires = basem + (nextevt - basej) * TICK_NSEC;
> +			expires = basem + (u64)(nextevt - basej) * TICK_NSEC;
>  		/*
>  		 * If we expect to sleep more than a tick, mark the base idle:
>  		 */

-- 
Best regards,
Alexander Sverdlin.

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

* [tip:timers/urgent] timers: Fix overflow in get_next_timer_interrupt
  2017-08-01  7:11 [PATCH] timers: Fix overflow in get_next_timer_interrupt Matija Glavinic Pecotic
  2017-08-01  8:16 ` Alexander Sverdlin
@ 2017-08-01 12:25 ` tip-bot for Matija Glavinic Pecotic
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Matija Glavinic Pecotic @ 2017-08-01 12:25 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, hpa, matija.glavinic-pecotic.ext, alexander.sverdlin,
	mingo, linux-kernel

Commit-ID:  34f41c0316ed52b0b44542491d89278efdaa70e4
Gitweb:     http://git.kernel.org/tip/34f41c0316ed52b0b44542491d89278efdaa70e4
Author:     Matija Glavinic Pecotic <matija.glavinic-pecotic.ext@nokia.com>
AuthorDate: Tue, 1 Aug 2017 09:11:52 +0200
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Tue, 1 Aug 2017 14:20:53 +0200

timers: Fix overflow in get_next_timer_interrupt

For e.g. HZ=100, timer being 430 jiffies in the future, and 32 bit
unsigned int, there is an overflow on unsigned int right-hand side
of the expression which results with wrong values being returned.

Type cast the multiplier to 64bit to avoid that issue.

Fixes: 46c8f0b077a8 ("timers: Fix get_next_timer_interrupt() computation")
Signed-off-by: Matija Glavinic Pecotic <matija.glavinic-pecotic.ext@nokia.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
Cc: khilman@baylibre.com
Cc: akpm@linux-foundation.org
Cc: stable@vger.kernel.org
Link: http://lkml.kernel.org/r/a7900f04-2a21-c9fd-67be-ab334d459ee5@nokia.com
---
 kernel/time/timer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 71ce3f4..8f5d1bf 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1495,7 +1495,7 @@ u64 get_next_timer_interrupt(unsigned long basej, u64 basem)
 		base->is_idle = false;
 	} else {
 		if (!is_max_delta)
-			expires = basem + (nextevt - basej) * TICK_NSEC;
+			expires = basem + (u64)(nextevt - basej) * TICK_NSEC;
 		/*
 		 * If we expect to sleep more than a tick, mark the base idle:
 		 */

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

end of thread, other threads:[~2017-08-01 12:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-01  7:11 [PATCH] timers: Fix overflow in get_next_timer_interrupt Matija Glavinic Pecotic
2017-08-01  8:16 ` Alexander Sverdlin
2017-08-01 12:25 ` [tip:timers/urgent] " tip-bot for Matija Glavinic Pecotic

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.