Skip to content

Commit

Permalink
board_reset.cpp: Hartid must be read with local interrupts disabled
Browse files Browse the repository at this point in the history
We cannot allow the running task to switch to another CPU after reading
hartid, otherwise we will use a stale value. Fix this by reading hartid
after disabling local interrupts.
  • Loading branch information
pussuw committed Dec 17, 2024
1 parent b97355e commit b866075
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,16 @@ static void board_reset_enter_bootloader_and_continue_boot()

static int board_reset_enter_app(FAR void *arg)
{
uintptr_t hartid = riscv_mhartid();
uintptr_t hartid;

/* Mask local interrupts */

up_irq_save();

/* It is now safe to read and hold hartid locally (CPU cannot change) */

hartid = riscv_mhartid();

#ifdef CONFIG_SMP
/* Notify that this CPU is paused */

Expand Down

0 comments on commit b866075

Please sign in to comment.