Skip to content

Commit

Permalink
kernel: smp: CPU start may result in null pointer access
Browse files Browse the repository at this point in the history
It is observed that starting up CPU may result in other CPUs
crashing due to de-referencing NULL pointers. Note that this
happened on the up_squared board, but there was no way to
attach debugger to verify. It started working again after
moving z_dummy_thread_init() before smp_timer_init(), which
was the old behavior before commit
eefaeee where the issue
first appeared. So mimic the old behavior to workaround
the issue.

Fixes zephyrproject-rtos#68115

Signed-off-by: Daniel Leung <[email protected]>
  • Loading branch information
dcpleung authored and dleach02 committed Feb 5, 2024
1 parent 065253c commit caacc27
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions kernel/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ static inline void smp_init_top(void *arg)
*/
wait_for_start_signal(&cpu_start_flag);

if ((csc == NULL) || csc->invoke_sched) {
/* Initialize the dummy thread struct so that
* the scheduler can schedule actual threads to run.
*/
z_dummy_thread_init(&dummy_thread);
}

#ifdef CONFIG_SYS_CLOCK_EXISTS
if ((csc == NULL) || csc->reinit_timer) {
smp_timer_init();
Expand All @@ -135,11 +142,6 @@ static inline void smp_init_top(void *arg)
return;
}

/* Initialize the dummy thread struct so that
* the scheduler can schedule actual threads to run.
*/
z_dummy_thread_init(&dummy_thread);

/* Let scheduler decide what thread to run next. */
z_swap_unlocked();

Expand Down

0 comments on commit caacc27

Please sign in to comment.