fix potential jiffies overflow
PATCH 1/1 fix potential jiffies overflow
I found i386 timer_resume is updating jiffies, not jiffies_64. It looks there is a potential overflow problem. Is this a correct fix?
arch/i386/kernel/time.c +1 -1
@@ -413,7 +413,7 @@ static int timer_resume(struct sys_devic xtime.tv_sec = sec; xtime.tv_nsec =0 ;write_sequnlock_irqrestore (&xtime_lock, flags); - jiffies += sleep_length; + jiffies_64 += sleep_length; wall_jiffies += sleep_length;if (last_timer->resume) last_timer->resume ();
Quoted 10 lines · Atsushi Nemoto
I found i386
timer_resumeis updating jiffies, notjiffies_64. It looks there is a potential overflow problem. Is this a correct fix?Signed-off-by Atsushi Nemoto <[email protected]>arch/i386/kernel/time.c +0
-0
arch/i386/kernel/time.c static int timer_resume(struct sys_devic · line 419
Quoted 8 lines
arch/i386/kernel/time.c +1
-1@@ -413,7 +413,7 @@ static int timer_resume(struct sys_devic xtime.tv_sec = sec; xtime.tv_nsec =0 ;write_sequnlock_irqrestore (&xtime_lock, flags); - jiffies += sleep_length; + jiffies_64 += sleep_length; wall_jiffies += sleep_length;if (last_timer->resume) last_timer->resume ();
The 64-bit jiffies value is not atomic. You need to hold xtime_lock to read it.
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Ram Gupta
I found i386
timer_resumeis updating jiffies, notjiffies_64. It looks there is a potential overflow problem. Is this a correct fix?
ram> The 64-bit jiffies value is not atomic. You need to hold ram> xtime_lock to read it.
OK, and I guess wall_jiffies also needs xtime_lock.
I found i386 timer_resume is updating jiffies, not jiffies_64. It looks there is a potential overflow problem. And jiffies_64 and wall_jiffies should be protected by xtime_lock.
arch/i386/kernel/time.c +2 -2
@@ -412,9 +412,9 @@ static int timer_resume(struct sys_devicwrite_seqlock_irqsave (&xtime_lock, flags); xtime.tv_sec = sec; xtime.tv_nsec =0 ; -write_sequnlock_irqrestore (&xtime_lock, flags); - jiffies += sleep_length; + jiffies_64 += sleep_length; wall_jiffies += sleep_length; +write_sequnlock_irqrestore (&xtime_lock, flags);if (last_timer->resume) last_timer->resume (); cur_timer = last_timer;
Quoted 24 lines · Atsushi Nemoto
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Ram Gupta
I found i386
timer_resumeis updating jiffies, notjiffies_64. It looks there is a potential overflow problem. Is this a correct fix?ram> The 64-bit jiffies value is not atomic. You need to hold ram>
xtime_lockto read it.OK, and I guess
wall_jiffiesalso needsxtime_lock.I found i386
timer_resumeis updating jiffies, notjiffies_64. It looks there is a potential overflow problem. Andjiffies_64andwall_jiffiesshould be protected byxtime_lock.Signed-off-by Atsushi Nemoto <[email protected]>arch/i386/kernel/time.c +0
-0@@ -412,9 +412,9 @@ static int timer_resume(struct sys_devicwrite_seqlock_irqsave (&xtime_lock, flags);
arch/i386/kernel/time.c static int timer_resume(struct sys_devic · line 420
Quoted 10 lines
arch/i386/kernel/time.c +2
-2xtime.tv_sec = sec; xtime.tv_nsec =0 ; -write_sequnlock_irqrestore (&xtime_lock, flags); - jiffies += sleep_length; + jiffies_64 += sleep_length; wall_jiffies += sleep_length; +write_sequnlock_irqrestore (&xtime_lock, flags);if (last_timer->resume) last_timer->resume (); cur_timer = last_timer;
Thanks, that looks like 2.6.16 material.
What happens if the machine slept for more than 49.7 days?
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Andrew Morton
akpm> Thanks, that looks like 2.6.16 material.
akpm> What happens if the machine slept for more than 49.7 days?
Well, jiffies will lose 49.7 days... Then, how about this? We can sleep 136 years.
arch/i386/kernel/time.c +2 -2
@@ -400,7 +400,7 @@ static int timer_resume(struct sys_devic {unsigned long flags;unsigned long sec; -unsigned long sleep_length; +u64 sleep_length;#ifdef CONFIG_HPET_TIMER if (is_hpet_enabled ())
@@ -408,7 +408,7 @@ static int timer_resume(struct sys_devic#endif setup_pit_timer (); sec =get_cmos_time () + clock_cmos_diff; - sleep_length = (get_cmos_time () - sleep_start) *HZ ; + sleep_length = (u64)(get_cmos_time () - sleep_start) *HZ ;write_seqlock_irqsave (&xtime_lock, flags); xtime.tv_sec = sec; xtime.tv_nsec =0 ;
Quoted 25 lines · Atsushi Nemoto
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines · Andrew Morton
akpm> Thanks, that looks like 2.6.16 material.
akpm> What happens if the machine slept for more than 49.7 days?
Well, jiffies will lose 49.7 days... Then, how about this? We can sleep 136 years.
Signed-off-by Atsushi Nemoto <[email protected]>arch/i386/kernel/time.c +1
-1@@ -400,7 +400,7 @@ static int timer_resume(struct sys_devic {unsigned long flags;unsigned long sec; -unsigned long sleep_length; +u64 sleep_length;#ifdef CONFIG_HPET_TIMER if (is_hpet_enabled ())
arch/i386/kernel/time.c static int timer_resume(struct sys_devic · line 414
Quoted 8 lines
arch/i386/kernel/time.c +1
-1@@ -408,7 +408,7 @@ static int timer_resume(struct sys_devic#endif setup_pit_timer (); sec =get_cmos_time () + clock_cmos_diff; - sleep_length = (get_cmos_time () - sleep_start) *HZ ; + sleep_length = (u64)(get_cmos_time () - sleep_start) *HZ ;write_seqlock_irqsave (&xtime_lock, flags); xtime.tv_sec = sec; xtime.tv_nsec =0 ;
but...
wall_jiffies += sleep_length;
wall_jiffies is 32-bit.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Andrew Morton
Well, jiffies will lose 49.7 days... Then, how about this? We can sleep 136 years.
akpm> but...
akpm> wall_jiffies += sleep_length;
akpm> wall_jiffies is 32-bit.
Yes ... and I think wall_jiffies can be removed completely (with update_times() cleanup). Of course it should not be 2.6.16 material.
---
Atsushi Nemoto
arch/i386/kernel/time.c static int timer_resume(struct sys_devic · line 411
Quoted 4 lines · Atsushi Nemoto
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Andrew Morton
arch/i386/kernel/time.c +1
-1sec =get_cmos_time () + clock_cmos_diff; - sleep_length = (get_cmos_time () - sleep_start) *HZ ; + sleep_length = (u64)(get_cmos_time () - sleep_start) *HZ ;
Calls to get_cmos_time() currently take an average of .5 seconds as it waits for a clock edge to go by. I've got some patches queueing up to eliminate this but it's probably worth caching the result here anyway.
Signature · 1 line
Mathematics is the supreme nostalgia of our time.