sched/x86: Fix overflow in cyc2ns_offset
authorSalman Qazi <sqazi@google.com>
Sat, 10 Mar 2012 00:41:01 +0000 (16:41 -0800)
committerLuis Henriques <luis.henriques@canonical.com>
Mon, 30 Apr 2012 18:15:04 +0000 (19:15 +0100)
commit0883a88d4b18a4195b43f45ff3f2cf9f97221eea
tree62e07e5740e44e23e57eb45567247202dba1703b
parent35b4064ad2e53ddc604910ad10a0d8b54c48a802
sched/x86: Fix overflow in cyc2ns_offset

BugLink: http://bugs.launchpad.net/bugs/981162

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>
Signed-off-by: Leann Ogasawara <leann.ogasawara@canonical.com>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
arch/x86/include/asm/timer.h
arch/x86/kernel/tsc.c
include/linux/kernel.h