[Top] [All Lists]

Re: [PATCH V2 02/02] MIPS: Init new mmu_context for each possible CPU to

To: Huacai Chen <>
Subject: Re: [PATCH V2 02/02] MIPS: Init new mmu_context for each possible CPU to avoid memory corruption
From: David Daney <>
Date: Wed, 20 Mar 2013 16:16:07 -0700
Cc: Ralf Baechle <>,,, Fuxin Zhang <>, Zhangjin Wu <>
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed;; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=uH5Dh9DzSMsaz/Df9/TX5pKNST6IEVVJ3/t8djdiuYI=; b=meQPlFXEU1WcgruSFnPujKtX9/GdKMDbvAI+sK1Fct75syngZ6lvKz8YYfUDf0Xr5M FUPYEOC3j3PUxxbvEwWV7gSvbfiUpnbdDX4y+7m+JkuudHUoqCOjRN4nEYlwkbMK62Ux 3XaPPSLnId1x6IjIfidndz0tBlrLDBL+6S4kEel5EkRjrLVirgMy19HJlKSlg2wkFWv9 I3fjZ1E3XzgggSbeHoEPFUMo9E6qJEwbdUnp4X36cHLHo89w1aRexfAle837b3py4U0u 6EFdofEPxsfuSDJRR1icUQly4neu1WaPmg3NA6wZW/cIjT4tOgHFAmFlrL3O1X2gq3Ym 2csQ==
In-reply-to: <>
List-archive: <>
List-help: <>
List-id: linux-mips <>
List-owner: <>
List-post: <>
List-software: Ecartis version 1.0.0
List-subscribe: <>
List-unsubscribe: <>
References: <>
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2
On 03/17/2013 05:50 AM, Huacai Chen wrote:
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.

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 <>

We were seeing the same crashes, this patch set seems to fix the problem.

Acked-by: David Daney <>

  arch/mips/include/asm/mmu_context.h |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/mips/include/asm/mmu_context.h 
index e81d719..49d220c 100644
--- a/arch/mips/include/asm/mmu_context.h
+++ b/arch/mips/include/asm/mmu_context.h
@@ -133,7 +133,7 @@ init_new_context(struct task_struct *tsk, struct mm_struct 
        int i;

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

        return 0;

<Prev in Thread] Current Thread [Next in Thread>