timekeeping: Add checks to cap clocksource reads to the 'max_cycles' value
timekeeping: Add checks to cap clocksource reads to the 'max_cycles' value

When calculating the current delta since the last tick, we
currently have no hard protections to prevent a multiplication
overflow from occuring.

This patch introduces infrastructure to allow a cap that
limits the clocksource read delta value to the 'max_cycles' value,
which is where an overflow would occur.

Since this is in the hotpath, it adds the extra checking under
CONFIG_DEBUG_TIMEKEEPING=y.

There was some concern that capping time like this could cause
problems as we may stop expiring timers, which could go circular
if the timer that triggers time accumulation were mis-scheduled
too far in the future, which would cause time to stop.

However, since the mult overflow would result in a smaller time
value, we would effectively have the same problem there.

Signed-off-by: John Stultz <33837adfb53316eae44aad04041e1240088d76fd@linaro.org>
Cc: Dave Jones <d5ec0d24602845f6f4b6a35ef729998d1fba5507@codemonkey.org.uk>
Cc: Linus Torvalds <69652caca27c8b940640ad396ab71f93cacec34f@linux-foundation.org>
Cc: Peter Zijlstra <3fddac958924aef220f202ca567388ddab3f14a8@infradead.org>
Cc: Prarit Bhargava <fe4655370dc87a32329d591d6e8472329333dfad@redhat.com>
Cc: Richard Cochran <e27030aebe9cad8817d34b8c31dbaf301fb798b9@gmail.com>
Cc: Stephen Boyd <010521127f513270fe503d86ab8316ac5147f4b7@codeaurora.org>
Cc: Thomas Gleixner <00e4cf8f46a57000a44449bf9dd8cbbcc209fd2a@linutronix.de>
Link: http://lkml.kernel.org/r/1426133800-29329-6-git-send-email-33837adfb53316eae44aad04041e1240088d76fd@linaro.org
Signed-off-by: Ingo Molnar <9dbbbf0688fedc85ad4da37637f1a64b8c718ee2@kernel.org>

KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs,KristFoundation/Programs