clocksource: Avoid selecting mult values that might overflow when adjusted
PATCH 1/1 clocksource: Avoid selecting mult values that might overflow when adjusted
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
--- include/linux/clocksource.h | 3 +- kernel/time/clocksource.c | 58 +++++++++++++++++++++++++++++++++++------- kernel/time/timekeeping.c | 7 +++++ 3 files changed, 57 insertions(+), 11 deletions(-)
include/linux/clocksource.h +2 -1
@@ -156,6 +156,7 @@ extern u64 timecounter_cyc2time(struct timecounter *tc,* @mult: cycle to nanosecond multiplier * @shift: cycle to nanosecond divisor (power of two) * @max_idle_ns: max idle time permitted by the clocksource (nsecs) +* @maxadj maximum adjustment value to mult (~11%) * @flags: flags describing special properties * @archdata: arch-specific data * @suspend: suspend function for the clocksource, if necessary
@@ -172,7 +173,7 @@ struct clocksource {u32 mult;u32 shift;u64 max_idle_ns; - +u32 maxadj;#ifdef CONFIG_ARCH_CLOCKSOURCE_DATA struct arch_clocksource_data archdata;#endif
kernel/time/clocksource.c +48 -10
98 lines not on this page · raw message
kernel/time/timekeeping.c +7 -0
@@ -820,6 +820,13 @@ static void timekeeping_adjust(s64 offset) }else return ; +WARN_ONCE (timekeeper.clock->maxadj && + (timekeeper.mult + adj > timekeeper.clock->mult + + timekeeper.clock->maxadj), +"Adjusting %s more then 11%% (%ld vs %ld)\n" , + timekeeper.clock->name, (long )timekeeper.mult + adj, + (long )timekeeper.clock->mult + + timekeeper.clock->maxadj); timekeeper.mult += adj; timekeeper.xtime_interval += interval; timekeeper.xtime_nsec -= offset;
Signature · 1 line
1.7.3.2.146.gca209