Skip to contentSkip to conversation

x86: fix hpet timer reinit for x86_64

PATCH Applied Pavel Emelyanov 4 participants 7 messages Feb 4, 2009 – Feb 5, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: fix hpet timer reinit for x86_64

There's a small problem with hpet_rtc_reinit function - it checks for the
hpet_readl(HPET_COUNTER) - hpet_t1_cmp > 0
to continue increasing both the HPET_T1_CMP (register) and the hpet_t1_cmp (variable).

But since the HPET_COUNTER is always 32-bit, if the hpet_t1_cmp is 64-bit this condition will always be FALSE once the latter hits the 32-bit boundary, and we can have a situation, when we don't increase the HPET_T1_CMP register high enough.

The result - timer stops ticking, since HPET_T1_CMP becomes less, than the COUNTER and never increased again.

The solution is to cut the upper 32-bit from the hpet_t1_cmp variable to make the comparison to HPET_COUNTER correct.

---

arch/x86/kernel/hpet.c +1 -1
index 64d5ad0..ec319d1 100644
@@ -1075,7 +1075,7 @@ static void hpet_rtc_timer_reinit(void)
 		hpet_t1_cmp += delta;
 		hpet_writel(hpet_t1_cmp, HPET_T1_CMP);
 		lost_ints++;
-	} while ((long)(hpet_readl(HPET_COUNTER) - hpet_t1_cmp) > 0);
+	} while ((long)(hpet_readl(HPET_COUNTER) - (u32)hpet_t1_cmp) > 0);
 
 	if (lost_ints) {
 		if (hpet_rtc_flags & RTC_PIE)
#1 lore raw
Quoted 12 lines · Pavel Emelyanov

There's a small problem with hpet_rtc_reinit function - it checks for the
hpet_readl(HPET_COUNTER) - hpet_t1_cmp > 0
to continue increasing both the HPET_T1_CMP (register) and the hpet_t1_cmp (variable).

But since the HPET_COUNTER is always 32-bit, if the hpet_t1_cmp is 64-bit this condition will always be FALSE once the latter hits the 32-bit boundary, and we can have a situation, when we don't increase the HPET_T1_CMP register high enough.

Quoted 5 lines

The result - timer stops ticking, since HPET_T1_CMP becomes less, than the COUNTER and never increased again.

The solution is to cut the upper 32-bit from the hpet_t1_cmp variable to make the comparison to HPET_COUNTER correct.

Why not to use u32 as a type for hpet_t1_cmp then? --
wbr, Vitaly

#2 lore raw
Quoted 12 lines · Vitaly Mayatskikh
Quoted 11 lines · Pavel Emelyanov

There's a small problem with hpet_rtc_reinit function - it checks for the
hpet_readl(HPET_COUNTER) - hpet_t1_cmp > 0
to continue increasing both the HPET_T1_CMP (register) and the hpet_t1_cmp (variable).

But since the HPET_COUNTER is always 32-bit, if the hpet_t1_cmp is 64-bit this condition will always be FALSE once the latter hits the 32-bit boundary, and we can have a situation, when we don't increase the HPET_T1_CMP register high enough.

Quoted 7 lines
Quoted 5 lines

The result - timer stops ticking, since HPET_T1_CMP becomes less, than the COUNTER and never increased again.

The solution is to cut the upper 32-bit from the hpet_t1_cmp variable to make the comparison to HPET_COUNTER correct.

Why not to use u32 as a type for hpet_t1_cmp then?

That's the matter of taste from my POV, so I can re-send the patch if x86 maintainers agree with your version.

Quoted 3 lines

--
wbr, Vitaly

#3 lore raw
In reply to Vitaly Mayatskikh
Quoted 16 lines · Vitaly Mayatskikh
Quoted 15 lines · Pavel Emelyanov

There's a small problem with hpet_rtc_reinit function - it checks for the
hpet_readl(HPET_COUNTER) - hpet_t1_cmp > 0
to continue increasing both the HPET_T1_CMP (register) and the hpet_t1_cmp (variable).

But since the HPET_COUNTER is always 32-bit, if the hpet_t1_cmp is 64-bit this condition will always be FALSE once the latter hits the 32-bit boundary, and we can have a situation, when we don't increase the HPET_T1_CMP register high enough.

The result - timer stops ticking, since HPET_T1_CMP becomes less, than the COUNTER and never increased again.

Quoted 6 lines
Quoted 2 lines

The solution is to cut the upper 32-bit from the hpet_t1_cmp variable to make the comparison to HPET_COUNTER correct.

Why not to use u32 as a type for hpet_t1_cmp then? --
wbr, Vitaly

Pavel, I agree, better please submit original fix replacing unsigned long to unsigned int (or u32) in definition of hpet_t1_cmp.

Thanks,
Kirill

Applied
#4 lore raw
In reply to Pavel Emelyanov
Quoted 11 lines · Pavel Emelyanov

There's a small problem with hpet_rtc_reinit function - it checks for the
hpet_readl(HPET_COUNTER) - hpet_t1_cmp > 0
to continue increasing both the HPET_T1_CMP (register) and the hpet_t1_cmp (variable).

But since the HPET_COUNTER is always 32-bit, if the hpet_t1_cmp is 64-bit this condition will always be FALSE once the latter hits the 32-bit boundary, and we can have a situation, when we don't increase the HPET_T1_CMP register high enough.

Quoted 8 lines

The result - timer stops ticking, since HPET_T1_CMP becomes less, than the COUNTER and never increased again.

The solution is to cut the upper 32-bit from the hpet_t1_cmp variable to make the comparison to HPET_COUNTER correct.

applied to tip/timers/urgent, thanks Pavel!

I'm wondering, what symptoms were seen due to the bug? Did system time stop, or did it become erratic, or were there outright lockups?

Ingo

#5 lore raw
Quoted 21 lines · Ingo Molnar
Quoted 17 lines · Pavel Emelyanov

There's a small problem with hpet_rtc_reinit function - it checks for the
hpet_readl(HPET_COUNTER) - hpet_t1_cmp > 0
to continue increasing both the HPET_T1_CMP (register) and the hpet_t1_cmp (variable).

But since the HPET_COUNTER is always 32-bit, if the hpet_t1_cmp is 64-bit this condition will always be FALSE once the latter hits the 32-bit boundary, and we can have a situation, when we don't increase the HPET_T1_CMP register high enough.

The result - timer stops ticking, since HPET_T1_CMP becomes less, than the COUNTER and never increased again.

The solution is to cut the upper 32-bit from the hpet_t1_cmp variable to make the comparison to HPET_COUNTER correct.

Quoted 7 lines
Quoted 2 lines

applied to tip/timers/urgent, thanks Pavel!

I'm wondering, what symptoms were seen due to the bug? Did system time stop, or did it become erratic, or were there outright lockups?

Symptoms were observed in user space. An application doing read() on /dev/rtc blocked sometimes for a long periods of time (as turned out - until counter gets wrap around).

Regards,
Kirill

#6 lore raw
Quoted 26 lines · Kirill Korotaev
Quoted 24 lines · Ingo Molnar
Quoted 19 lines · Pavel Emelyanov

There's a small problem with hpet_rtc_reinit function - it checks for the
hpet_readl(HPET_COUNTER) - hpet_t1_cmp > 0
to continue increasing both the HPET_T1_CMP (register) and the hpet_t1_cmp (variable).

But since the HPET_COUNTER is always 32-bit, if the hpet_t1_cmp is 64-bit this condition will always be FALSE once the latter hits the 32-bit boundary, and we can have a situation, when we don't increase the HPET_T1_CMP register high enough.

The result - timer stops ticking, since HPET_T1_CMP becomes less, than the COUNTER and never increased again.

The solution is to cut the upper 32-bit from the hpet_t1_cmp variable to make the comparison to HPET_COUNTER correct.

Quoted 8 lines
Quoted 4 lines

applied to tip/timers/urgent, thanks Pavel!

I'm wondering, what symptoms were seen due to the bug? Did system time stop, or did it become erratic, or were there outright lockups?

Symptoms were observed in user space. An application doing read() on /dev/rtc blocked sometimes for a long periods of time (as turned out - until counter gets wrap around).

okay. Could you guys please put this info in the commit log on the resubmitted patch? Thanks,

Ingo