x86: fix hpet timer reinit for x86_64
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
@@ -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 )
Quoted 12 lines · Pavel Emelyanov
There's a small problem with
hpet_rtc_reinitfunction - it checks for the
hpet_readl(HPET_COUNTER)-hpet_t1_cmp> 0
to continue increasing both theHPET_T1_CMP(register) and thehpet_t1_cmp(variable).But since the
HPET_COUNTERis always 32-bit, if thehpet_t1_cmpis 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 theHPET_T1_CMPregister high enough.
Quoted 5 lines
The result - timer stops ticking, since
HPET_T1_CMPbecomes less, than the COUNTER and never increased again.The solution is to cut the upper 32-bit from the
hpet_t1_cmpvariable to make the comparison toHPET_COUNTERcorrect.
Why not to use u32 as a type for hpet_t1_cmp then? --
wbr, Vitaly
Quoted 12 lines · Vitaly Mayatskikh
Quoted 11 lines · Pavel Emelyanov
There's a small problem with
hpet_rtc_reinitfunction - it checks for the
hpet_readl(HPET_COUNTER)-hpet_t1_cmp> 0
to continue increasing both theHPET_T1_CMP(register) and thehpet_t1_cmp(variable).But since the
HPET_COUNTERis always 32-bit, if thehpet_t1_cmpis 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 theHPET_T1_CMPregister high enough.
Quoted 7 lines
Quoted 5 lines
The result - timer stops ticking, since
HPET_T1_CMPbecomes less, than the COUNTER and never increased again.The solution is to cut the upper 32-bit from the
hpet_t1_cmpvariable to make the comparison toHPET_COUNTERcorrect.Why not to use u32 as a type for
hpet_t1_cmpthen?
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
Quoted 16 lines · Vitaly Mayatskikh
Quoted 15 lines · Pavel Emelyanov
There's a small problem with
hpet_rtc_reinitfunction - it checks for the
hpet_readl(HPET_COUNTER)-hpet_t1_cmp> 0
to continue increasing both theHPET_T1_CMP(register) and thehpet_t1_cmp(variable).But since the
HPET_COUNTERis always 32-bit, if thehpet_t1_cmpis 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 theHPET_T1_CMPregister high enough.The result - timer stops ticking, since
HPET_T1_CMPbecomes 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_cmpvariable to make the comparison toHPET_COUNTERcorrect.Why not to use u32 as a type for
hpet_t1_cmpthen? --
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
Ingo Molnar
AppliedQuoted 11 lines · Pavel Emelyanov
There's a small problem with
hpet_rtc_reinitfunction - it checks for the
hpet_readl(HPET_COUNTER)-hpet_t1_cmp> 0
to continue increasing both theHPET_T1_CMP(register) and thehpet_t1_cmp(variable).But since the
HPET_COUNTERis always 32-bit, if thehpet_t1_cmpis 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 theHPET_T1_CMPregister high enough.
Quoted 8 lines
The result - timer stops ticking, since
HPET_T1_CMPbecomes less, than the COUNTER and never increased again.The solution is to cut the upper 32-bit from the
hpet_t1_cmpvariable to make the comparison toHPET_COUNTERcorrect.Reported-by Kirill Korotaev <[email protected]>Signed-off-by Pavel Emelyanov <[email protected]>
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
Quoted 21 lines · Ingo Molnar
Quoted 17 lines · Pavel Emelyanov
There's a small problem with
hpet_rtc_reinitfunction - it checks for the
hpet_readl(HPET_COUNTER)-hpet_t1_cmp> 0
to continue increasing both theHPET_T1_CMP(register) and thehpet_t1_cmp(variable).But since the
HPET_COUNTERis always 32-bit, if thehpet_t1_cmpis 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 theHPET_T1_CMPregister high enough.The result - timer stops ticking, since
HPET_T1_CMPbecomes less, than the COUNTER and never increased again.The solution is to cut the upper 32-bit from the
hpet_t1_cmpvariable to make the comparison toHPET_COUNTERcorrect.
Quoted 7 lines
Quoted 2 lines
Reported-by Kirill Korotaev <[email protected]>Signed-off-by Pavel Emelyanov <[email protected]>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
Quoted 26 lines · Kirill Korotaev
Quoted 24 lines · Ingo Molnar
Quoted 19 lines · Pavel Emelyanov
There's a small problem with
hpet_rtc_reinitfunction - it checks for the
hpet_readl(HPET_COUNTER)-hpet_t1_cmp> 0
to continue increasing both theHPET_T1_CMP(register) and thehpet_t1_cmp(variable).But since the
HPET_COUNTERis always 32-bit, if thehpet_t1_cmpis 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 theHPET_T1_CMPregister high enough.The result - timer stops ticking, since
HPET_T1_CMPbecomes less, than the COUNTER and never increased again.The solution is to cut the upper 32-bit from the
hpet_t1_cmpvariable to make the comparison toHPET_COUNTERcorrect.Reported-by Kirill Korotaev <[email protected]>Signed-off-by Pavel Emelyanov <[email protected]>
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/rtcblocked 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