Skip to content

Commit a8b3238

Browse files
schouleur-sckartben
authored andcommitted
arm64: core: force data synchronization between context switch
This patch fixes memory corruption that can happen when running in multi-thread and multi-core environment with heavy scheduling stress. In SMP configuration, we must ensure that all thread's context is stored before writing the switch_handle flag. Otherwise some of the thread context writes could be delayed after another CPU begins to schedule this thread which could lead to memory corruptions. Signed-off-by: Sylvain Chouleur <[email protected]>
1 parent 71ef6c6 commit a8b3238

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/arm64/core/switch.S

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ SECTION_FUNC(TEXT, z_arm64_context_switch)
7474
ldp x0, x1, [sp], #16
7575
#endif
7676

77+
#ifdef CONFIG_SMP
78+
/* Write barrier: ensure all preceding writes are executed
79+
* before writing the switch handle
80+
*/
81+
dmb sy
82+
#endif
83+
7784
/* save old thread into switch handle which is required by
7885
* z_sched_switch_spin()
7986
*/

0 commit comments

Comments
 (0)