Skip to content
  • Oleg Nesterov's avatar
    sched/api: Introduce task_rcu_dereference() and try_get_task_struct() · 150593bf
    Oleg Nesterov authored
    
    
    Generally task_struct is only protected by RCU if it was found on a
    RCU protected list (say, for_each_process() or find_task_by_vpid()).
    
    As Kirill pointed out rq->curr isn't protected by RCU, the scheduler
    drops the (potentially) last reference without RCU gp, this means
    that we need to fix the code which uses foreign_rq->curr under
    rcu_read_lock().
    
    Add a new helper which can be used to dereference rq->curr or any
    other pointer to task_struct assuming that it should be cleared or
    updated before the final put_task_struct(). It returns non-NULL
    only if this task can't go away before rcu_read_unlock().
    
    ( Also add try_get_task_struct() to make it easier to use this API
      correctly. )
    
    Suggested-by: default avatarKirill Tkhai <ktkhai@parallels.com>
    Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
    [ Updated comments; added try_get_task_struct()]
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Cc: Chris Metcalf <cmetcalf@ezchip.com>
    Cc: Christoph Lameter <cl@linux.com>
    Cc: Kirill Tkhai <tkhai@yandex.ru>
    Cc: Linus Torvalds <torvalds@linux-foundation.org>
    Cc: Mike Galbraith <efault@gmx.de>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Vladimir Davydov <vdavydov@parallels.com>
    Link: http://lkml.kernel.org/r/20160518170218.GY3192@twins.programming.kicks-ass.net
    
    
    Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
    150593bf