Skip to content

Commit a74f378

Browse files
Nicolas Pitrenashif
authored andcommitted
aarch64: mmu: apply domain switching on all CPUs if SMP
It is apparently possible for one CPU to change the memory domain of a thread already being executed on another CPU. All CPUs must ensure they're using the appropriate mapping after a thread is newly added to a domain. Signed-off-by: Nicolas Pitre <[email protected]>
1 parent ec70b2b commit a74f378

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

arch/arm/core/aarch64/mmu/arm_mmu.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -989,15 +989,21 @@ void arch_mem_domain_thread_add(struct k_thread *thread)
989989
}
990990

991991
thread->arch.ptables = domain_ptables;
992+
if (thread == _current) {
993+
if (!is_ptable_active(domain_ptables)) {
994+
z_arm64_swap_ptables(thread);
995+
}
996+
} else {
997+
#ifdef CONFIG_SMP
998+
/* the thread could be running on another CPU right now */
999+
arch_sched_ipi();
1000+
#endif
1001+
}
9921002

9931003
if (is_migration) {
9941004
reset_map(old_ptables, __func__, thread->stack_info.start,
9951005
thread->stack_info.size);
9961006
}
997-
998-
if (thread == _current && !is_ptable_active(domain_ptables)) {
999-
z_arm64_swap_ptables(thread);
1000-
}
10011007
}
10021008

10031009
void arch_mem_domain_thread_remove(struct k_thread *thread)
@@ -1026,8 +1032,6 @@ void z_arm64_swap_ptables(struct k_thread *incoming)
10261032

10271033
if (!is_ptable_active(ptables)) {
10281034
z_arm64_set_ttbr0((uintptr_t)ptables->base_xlat_table);
1029-
} else {
1030-
invalidate_tlb_all();
10311035
}
10321036
}
10331037

arch/arm/core/aarch64/smp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ void sched_ipi_handler(const void *unused)
9898
{
9999
ARG_UNUSED(unused);
100100

101+
#ifdef CONFIG_USERSPACE
102+
/*
103+
* Make sure a domain switch by another CPU is effective on this CPU.
104+
* This is a no-op if the page table is already the right one.
105+
*/
106+
z_arm64_swap_ptables(_current);
107+
#endif
108+
101109
z_sched_ipi();
102110
}
103111

0 commit comments

Comments
 (0)