Skip to content

Commit

Permalink
esp_system: Fix a race-condition in esp_ipc_isr (in QEMU env)
Browse files Browse the repository at this point in the history
The race condition is very unlikely on real hardware but can be observed with
qemu under heavy load.
Also add missing `memw` instructions which are generated by the C compiler but
absent in the assembly code.

Signed-off-by: Paul Guyot <[email protected]>
Signed-off-by: KonstantinKondrashov <[email protected]>

Merges #11447
Closes #11433
  • Loading branch information
pguyot authored and KonstantinKondrashov committed May 24, 2023
1 parent a8a2b08 commit ceb121f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/esp_system/port/arch/xtensa/esp_ipc_isr.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ void IRAM_ATTR esp_ipc_isr_release_other_cpu(void)
const uint32_t cpu_id = xPortGetCoreID();
if (--s_count_of_nested_calls[cpu_id] == 0) {
esp_ipc_isr_finish_cmd = 1;
// Make sure end flag is cleared and esp_ipc_isr_waiting_for_finish_cmd is done.
while (!esp_ipc_isr_end_fl) {};
IPC_ISR_EXIT_CRITICAL();
#if CONFIG_FREERTOS_SMP
portRESTORE_INTERRUPTS(s_stored_interrupt_level);
Expand Down
2 changes: 2 additions & 0 deletions components/esp_system/port/arch/xtensa/esp_ipc_isr_handler.S
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ esp_ipc_isr_handler:

/* set the start flag */
movi a0, esp_ipc_isr_start_fl
memw
s32i a0, a0, 0

/* Call the esp_ipc_function(void* arg) */
Expand All @@ -113,6 +114,7 @@ esp_ipc_isr_handler:

/* set the end flag */
movi a0, esp_ipc_isr_end_fl
memw
s32i a0, a0, 0

/* restore a0 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
esp_ipc_isr_waiting_for_finish_cmd:
/* waiting for the finish command */
.check_finish_cmd:
memw
l32i a3, a2, 0
beqz a3, .check_finish_cmd
ret

0 comments on commit ceb121f

Please sign in to comment.