Skip to content

Commit

Permalink
MIPS: Init new mmu_context for each possible CPU to avoid memory corr…
Browse files Browse the repository at this point in the history
…uption

Currently, init_new_context() only for each online CPU, this may cause
memory corruption when CPU hotplug and fork() happens at the same time.
To avoid this, we make init_new_context() cover each possible CPU.

Scenario:
1, CPU#1 is being offline;
2, On CPU#0, do_fork() call dup_mm() and copy a mm_struct to the child;
3, On CPU#0, dup_mm() call init_new_context(), since CPU#1 is offline
   and init_new_context() only covers the online CPUs, child has the
   same asid as its parent on CPU#1 (however, child's asid should be 0);
4, CPU#1 is being online;
5, Now, if both parent and child run on CPU#1, memory corruption (e.g.
   segfault, bus error, etc.) will occur.

Signed-off-by: Huacai Chen <chenhc@lemote.com>
Acked-by: David Daney <david.daney@cavium.com>
Patchwork: http://patchwork.linux-mips.org/patch/4995/
Acked-by: John Crispin <blogic@openwrt.org>
  • Loading branch information
Huacai Chen authored and Ralf Baechle committed May 7, 2013
1 parent 8759934 commit 2247867
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion arch/mips/include/asm/mmu_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ init_new_context(struct task_struct *tsk, struct mm_struct *mm)
{
int i;

for_each_online_cpu(i)
for_each_possible_cpu(i)
cpu_context(i, mm) = 0;

return 0;
Expand Down

0 comments on commit 2247867

Please sign in to comment.