hrtimers: avoid overflow for large relative timeouts

Relative hrtimers with a large timeout value might end up as negative
timer values, when the current time is added in hrtimer_start().

This in turn is causing the clockevents_set_next() function to set an
huge timeout and sleep for quite a long time when we have a clock
source which is capable of long sleeps like HPET. With PIT this almost
goes unnoticed as the maximum delta is ~27ms. The non-hrt/nohz code
sorts this out in the next timer interrupt, so we never noticed that
problem which has been there since the first day of hrtimers.

This bug became more apparent in 2.6.24 which activates HPET on more
hardware.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>

authored by Thomas Gleixner and committed by Ingo Molnar 62f0f61e f194d132

+8
+8
kernel/hrtimer.c
··· 850 #ifdef CONFIG_TIME_LOW_RES 851 tim = ktime_add(tim, base->resolution); 852 #endif 853 } 854 timer->expires = tim; 855
··· 850 #ifdef CONFIG_TIME_LOW_RES 851 tim = ktime_add(tim, base->resolution); 852 #endif 853 + /* 854 + * Careful here: User space might have asked for a 855 + * very long sleep, so the add above might result in a 856 + * negative number, which enqueues the timer in front 857 + * of the queue. 858 + */ 859 + if (tim.tv64 < 0) 860 + tim.tv64 = KTIME_MAX; 861 } 862 timer->expires = tim; 863