Skip to content

Commit 933a8f9

Browse files
povergoingstephanosio
authored andcommitted
arch: arm64: Fix coherence issue of SMP boot code
The current SMP boot code doesn't consider that the cores can boot at the same time. Possibly, more than one core can boot into primary core boot sequence. Fix it by using the atomic operation to make sure only one core act as the primary core. Correspondingly, sgi_raise_ipi should transfer CPU id to mpidr. Signed-off-by: Jaxson Han <[email protected]>
1 parent 2f6087b commit 933a8f9

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

arch/arm64/core/reset.S

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,18 @@ SECTION_SUBSEC_FUNC(TEXT,_reset_section,__start)
109109

110110
ldr x0, =arm64_cpu_boot_params
111111
get_cpu_id x1
112-
ldr x2, [x0, #BOOT_PARAM_MPID_OFFSET]
112+
113+
/*
114+
* If the cores start up at the same time, we should atomically load and
115+
* store the mpid into arm64_cpu_boot_params.
116+
*/
117+
ldaxr x2, [x0, #BOOT_PARAM_MPID_OFFSET]
113118
cmp x2, #-1
114-
beq primary_core
119+
bne 1f
120+
/* try to store x1 (mpid) */
121+
stlxr w3, x1, [x0]
122+
/* If succeed, go to primary_core */
123+
cbz w3, primary_core
115124

116125
/* loop until our turn comes */
117126
1: dmb ld
@@ -125,8 +134,6 @@ SECTION_SUBSEC_FUNC(TEXT,_reset_section,__start)
125134
b 2f
126135

127136
primary_core:
128-
/* advertise ourself */
129-
str x1, [x0, #BOOT_PARAM_MPID_OFFSET]
130137
#endif
131138
/* load primary stack and entry point */
132139
ldr x24, =(z_interrupt_stacks + CONFIG_ISR_STACK_SIZE)

arch/arm64/core/smp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ void flush_fpu_ipi_handler(const void *unused)
213213

214214
void z_arm64_flush_fpu_ipi(unsigned int cpu)
215215
{
216-
const uint64_t mpidr = GET_MPIDR();
216+
const uint64_t mpidr = cpu_node_list[cpu];
217217

218-
gic_raise_sgi(SGI_FPU_IPI, mpidr, (1 << cpu));
218+
gic_raise_sgi(SGI_FPU_IPI, mpidr, 1 << MPIDR_TO_CORE(mpidr));
219219
}
220220
#endif
221221

0 commit comments

Comments
 (0)