clocksource: Avoid selecting mult values that might overflow when adjusted
authorJohn Stultz <john.stultz@linaro.org>
Mon, 31 Oct 2011 21:06:35 +0000 (17:06 -0400)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 9 Dec 2011 16:54:24 +0000 (08:54 -0800)
commitbe80893d309e256fe05a1e55d440bd6188ba2748
treeb5564b37a4a723d529ebeaeb89f7438dd3564875
parenteb5f9ebf61f88796a19df09751762b9e086a5214
clocksource: Avoid selecting mult values that might overflow when adjusted

commit d65670a78cdbfae94f20a9e05ec705871d7cdf2b upstream.

For some frequencies, the clocks_calc_mult_shift() function will
unfortunately select mult values very close to 0xffffffff.  This
has the potential to overflow when NTP adjusts the clock, adding
to the mult value.

This patch adds a clocksource.maxadj value, which provides
an approximation of an 11% adjustment(NTP limits adjustments to
500ppm and the tick adjustment is limited to 10%), which could
be made to the clocksource.mult value. This is then used to both
check that the current mult value won't overflow/underflow, as
well as warning us if the timekeeping_adjust() code pushes over
that 11% boundary.

v2: Fix max_adjustment calculation, and improve WARN_ONCE
messages.

v3: Don't warn before maxadj has actually been set

CC: Yong Zhang <yong.zhang0@gmail.com>
CC: David Daney <ddaney.cavm@gmail.com>
CC: Thomas Gleixner <tglx@linutronix.de>
CC: Chen Jie <chenj@lemote.com>
CC: zhangfx <zhangfx@lemote.com>
Reported-by: Chen Jie <chenj@lemote.com>
Reported-by: zhangfx <zhangfx@lemote.com>
Tested-by: Yong Zhang <yong.zhang0@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
include/linux/clocksource.h
kernel/time/clocksource.c
kernel/time/timekeeping.c