Skip to content

Commit 4ce0ff5

Browse files
RuibinChangkartben
authored andcommitted
drivers/timer/it8xxx2: fix busy wait timer race condition
Command "waitms 50" on ChromeBook EC console, then it will crash EC. Because arch_busy_wait() is re-entried by two different tasks, the second calling will reset the timer and may cause the first calling to fail to reach the waiting destination (if the first calling's wait time is longer enough). Verified by follow test pattern: west build -p auto -b it8xxx2_evb tests/kernel/timer/timer_api west build -p auto -b it8xxx2_evb tests/kernel/timer/timer_error_case west build -p auto -b it8xxx2_evb tests/kernel/timer/timer_monotonic west build -p auto -b it8xxx2_evb tests/kernel/timer/starve west build -p auto -b it8xxx2_evb tests/kernel/context Signed-off-by: Ruibin Chang <[email protected]>
1 parent d740201 commit 4ce0ff5

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

drivers/timer/ite_it8xxx2_timer.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,23 +150,17 @@ void timer_5ms_one_shot(void)
150150
#ifdef CONFIG_ARCH_HAS_CUSTOM_BUSY_WAIT
151151
void arch_busy_wait(uint32_t usec_to_wait)
152152
{
153+
uint32_t start = IT8XXX2_EXT_CNTOX(BUSY_WAIT_H_TIMER);
154+
153155
if (!usec_to_wait) {
154156
return;
155157
}
156158

157159
/* Decrease 1us here to calibrate our access registers latency */
158160
usec_to_wait--;
159161

160-
/*
161-
* We want to set the bit(1) re-start busy wait timer as soon
162-
* as possible, so we directly write 0xb instead of | bit(1).
163-
*/
164-
IT8XXX2_EXT_CTRLX(BUSY_WAIT_L_TIMER) = IT8XXX2_EXT_ETX_COMB_RST_EN;
165-
166162
for (;;) {
167-
uint32_t curr = IT8XXX2_EXT_CNTOX(BUSY_WAIT_H_TIMER);
168-
169-
if (curr >= usec_to_wait) {
163+
if ((IT8XXX2_EXT_CNTOX(BUSY_WAIT_H_TIMER) - start) >= usec_to_wait) {
170164
break;
171165
}
172166
}

0 commit comments

Comments
 (0)