aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/kernel.h
diff options
context:
space:
mode:
authorSalman Qazi <sqazi@google.com>2012-03-09 16:41:01 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-13 08:14:08 -0700
commitee9c2e08d37dae695a4f4cfb4dc003c5c2576f79 (patch)
tree82c0d322544c9a6ef56c1100a07a80e5d48b6f17 /include/linux/kernel.h
parent1802657ecb10d7ca620c3cf642920009d1aa2ec3 (diff)
downloadkernel_samsung_smdk4412-ee9c2e08d37dae695a4f4cfb4dc003c5c2576f79.zip
kernel_samsung_smdk4412-ee9c2e08d37dae695a4f4cfb4dc003c5c2576f79.tar.gz
kernel_samsung_smdk4412-ee9c2e08d37dae695a4f4cfb4dc003c5c2576f79.tar.bz2
sched/x86: Fix overflow in cyc2ns_offset
commit 9993bc635d01a6ee7f6b833b4ee65ce7c06350b1 upstream. When a machine boots up, the TSC generally gets reset. However, when kexec is used to boot into a kernel, the TSC value would be carried over from the previous kernel. The computation of cycns_offset in set_cyc2ns_scale is prone to an overflow, if the machine has been up more than 208 days prior to the kexec. The overflow happens when we multiply *scale, even though there is enough room to store the final answer. We fix this issue by decomposing tsc_now into the quotient and remainder of division by CYC2NS_SCALE_FACTOR and then performing the multiplication separately on the two components. Refactor code to share the calculation with the previous fix in __cycles_2_ns(). Signed-off-by: Salman Qazi <sqazi@google.com> Acked-by: John Stultz <john.stultz@linaro.org> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Paul Turner <pjt@google.com> Cc: john stultz <johnstul@us.ibm.com> Link: http://lkml.kernel.org/r/20120310004027.19291.88460.stgit@dungbeetle.mtv.corp.google.com Signed-off-by: Ingo Molnar <mingo@elte.hu> Cc: Mike Galbraith <efault@gmx.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r--include/linux/kernel.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 953352a..3a3925d 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -77,6 +77,19 @@
} \
)
+/*
+ * Multiplies an integer by a fraction, while avoiding unnecessary
+ * overflow or loss of precision.
+ */
+#define mult_frac(x, numer, denom)( \
+{ \
+ typeof(x) quot = (x) / (denom); \
+ typeof(x) rem = (x) % (denom); \
+ (quot * (numer)) + ((rem * (numer)) / (denom)); \
+} \
+)
+
+
#define _RET_IP_ (unsigned long)__builtin_return_address(0)
#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })