lkml.org 
[lkml]   [2014]   [Oct]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 3.10 142/143] oom_kill: add rcu_read_lock() into find_lock_task_mm()
    Date
    3.10-stable review patch.  If anyone has any objections, please let me know.

    ------------------

    From: Oleg Nesterov <oleg@redhat.com>

    commit 4d4048be8a93769350efa31d2482a038b7de73d0 upstream.

    find_lock_task_mm() expects it is called under rcu or tasklist lock, but
    it seems that at least oom_unkillable_task()->task_in_mem_cgroup() and
    mem_cgroup_out_of_memory()->oom_badness() can call it lockless.

    Perhaps we could fix the callers, but this patch simply adds rcu lock
    into find_lock_task_mm(). This also allows to simplify a bit one of its
    callers, oom_kill_process().

    Signed-off-by: Oleg Nesterov <oleg@redhat.com>
    Cc: Sergey Dyasly <dserrg@gmail.com>
    Cc: Sameer Nanda <snanda@chromium.org>
    Cc: "Eric W. Biederman" <ebiederm@xmission.com>
    Cc: Frederic Weisbecker <fweisbec@gmail.com>
    Cc: Mandeep Singh Baines <msb@chromium.org>
    Cc: "Ma, Xindong" <xindong.ma@intel.com>
    Reviewed-by: Michal Hocko <mhocko@suse.cz>
    Cc: "Tu, Xiaobing" <xiaobing.tu@intel.com>
    Acked-by: David Rientjes <rientjes@google.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Li Zefan <lizefan@huawei.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

    ---
    mm/oom_kill.c | 12 ++++++++----
    1 file changed, 8 insertions(+), 4 deletions(-)

    --- a/mm/oom_kill.c
    +++ b/mm/oom_kill.c
    @@ -102,14 +102,19 @@ struct task_struct *find_lock_task_mm(st
    {
    struct task_struct *t;

    + rcu_read_lock();
    +
    for_each_thread(p, t) {
    task_lock(t);
    if (likely(t->mm))
    - return t;
    + goto found;
    task_unlock(t);
    }
    + t = NULL;
    +found:
    + rcu_read_unlock();

    - return NULL;
    + return t;
    }

    /* return true if the task is not adequate as candidate victim task. */
    @@ -461,10 +466,8 @@ void oom_kill_process(struct task_struct
    }
    read_unlock(&tasklist_lock);

    - rcu_read_lock();
    p = find_lock_task_mm(victim);
    if (!p) {
    - rcu_read_unlock();
    put_task_struct(victim);
    return;
    } else if (victim != p) {
    @@ -490,6 +493,7 @@ void oom_kill_process(struct task_struct
    * That thread will now get access to memory reserves since it has a
    * pending fatal signal.
    */
    + rcu_read_lock();
    for_each_process(p)
    if (p->mm == mm && !same_thread_group(p, victim) &&
    !(p->flags & PF_KTHREAD)) {



    \
     
     \ /
      Last update: 2014-10-04 01:21    [W:2.725 / U:0.296 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site