mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: tip-bot for Kevin Hilman <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org,
	peterz@infradead.org, john.stultz@linaro.org,
	alex.shi@linaro.org, paulmck@linux.vnet.ibm.com,
	fweisbec@gmail.com, rostedt@goodmis.org, tglx@linutronix.de,
	khilman@linaro.org
Subject: [tip:timers/urgent] sched/nohz: Fix overflow error in scheduler_tick_max_deferment()
Date: Sat, 25 Jan 2014 06:22:56 -0800	[thread overview]
Message-ID: <tip-8fe8ff09ce3b5750e1f3e45a1f4a81d59c7ff1f1@git.kernel.org> (raw)
In-Reply-To: <1387315388-31676-2-git-send-email-khilman@linaro.org>

Commit-ID:  8fe8ff09ce3b5750e1f3e45a1f4a81d59c7ff1f1
Gitweb:     http://git.kernel.org/tip/8fe8ff09ce3b5750e1f3e45a1f4a81d59c7ff1f1
Author:     Kevin Hilman <khilman@linaro.org>
AuthorDate: Wed, 15 Jan 2014 14:51:38 +0100
Committer:  Frederic Weisbecker <fweisbec@gmail.com>
CommitDate: Thu, 16 Jan 2014 00:08:12 +0100

sched/nohz: Fix overflow error in scheduler_tick_max_deferment()

While calculating the scheduler tick max deferment, the delta is
converted from microseconds to nanoseconds through a multiplication
against NSEC_PER_USEC.

But this microseconds operand is an unsigned int, thus the result may
likely overflow. The result is cast to u64 but only once the operation
is completed, which is too late to avoid overflown result.

This is currently not a problem because the scheduler tick max deferment
is 1 second. But this may become an issue as we plan to make this
value tunable.

So lets fix this by casting the usecs value to u64 before multiplying by
NSECS_PER_USEC.

Also to prevent from this kind of mistake to happen again, move this
ad-hoc jiffies -> nsecs conversion to a new helper.

Signed-off-by: Kevin Hilman <khilman@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alex Shi <alex.shi@linaro.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Kevin Hilman <khilman@linaro.org>
Link: http://lkml.kernel.org/r/1387315388-31676-2-git-send-email-khilman@linaro.org
[move ad-hoc conversion to jiffies_to_nsecs helper]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
---
 include/linux/jiffies.h | 6 ++++++
 kernel/sched/core.c     | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
index d235e88..1f44466 100644
--- a/include/linux/jiffies.h
+++ b/include/linux/jiffies.h
@@ -294,6 +294,12 @@ extern unsigned long preset_lpj;
  */
 extern unsigned int jiffies_to_msecs(const unsigned long j);
 extern unsigned int jiffies_to_usecs(const unsigned long j);
+
+static inline u64 jiffies_to_nsecs(const unsigned long j)
+{
+	return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
+}
+
 extern unsigned long msecs_to_jiffies(const unsigned int m);
 extern unsigned long usecs_to_jiffies(const unsigned int u);
 extern unsigned long timespec_to_jiffies(const struct timespec *value);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index a88f4a4..61e601f 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2325,7 +2325,7 @@ u64 scheduler_tick_max_deferment(void)
 	if (time_before_eq(next, now))
 		return 0;
 
-	return jiffies_to_usecs(next - now) * NSEC_PER_USEC;
+	return jiffies_to_nsecs(next - now);
 }
 #endif
 

  parent reply	other threads:[~2014-01-25 14:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-17 21:23 [PATCH 1/2] sched/nohz: add debugfs control over sched_tick_max_deferment Kevin Hilman
2013-12-17 21:23 ` [PATCH 2/2] sched/nohz: fix overflow error in scheduler_tick_max_deferment() Kevin Hilman
2014-01-05 13:06   ` Frederic Weisbecker
2014-01-06 18:27     ` Kevin Hilman
2014-01-25 14:22   ` tip-bot for Kevin Hilman [this message]
2014-01-05 13:21 ` [PATCH 1/2] sched/nohz: add debugfs control over sched_tick_max_deferment Frederic Weisbecker
2014-01-06 18:37   ` Kevin Hilman
2014-01-10 15:17     ` Frederic Weisbecker
2014-01-14 20:46       ` Kevin Hilman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-8fe8ff09ce3b5750e1f3e45a1f4a81d59c7ff1f1@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=alex.shi@linaro.org \
    --cc=fweisbec@gmail.com \
    --cc=hpa@zytor.com \
    --cc=john.stultz@linaro.org \
    --cc=khilman@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome