• Zach Brown's avatar
    [PATCH] Fix lock inversion aio_kick_handler() · 1ebb1101
    Zach Brown authored
    lockdep found a AB BC CA lock inversion in retry-based AIO:
    
    1) The task struct's alloc_lock (A) is acquired in process context with
       interrupts enabled.  An interrupt might arrive and call wake_up() which
       grabs the wait queue's q->lock (B).
    
    2) When performing retry-based AIO the AIO core registers
       aio_wake_function() as the wake funtion for iocb->ki_wait.  It is called
       with the wait queue's q->lock (B) held and then tries to add the iocb to
       the run list after acquiring the ctx_lock (C).
    
    3) aio_kick_handler() holds the ctx_lock (C) while acquiring the
       alloc_lock (A) via lock_task() and unuse_mm().  Lockdep emits a warning
       saying that we're trying to connect the irq-safe q->lock to the
       irq-unsafe alloc_lock via ctx_lock.
    
    This fixes the inversion by calling unuse_mm() in the AIO kick handing path
    after we've released the ctx_lock.  As Ben LaHaise pointed out __put_ioctx
    could set ctx->mm to NULL, so we must only access ctx->mm while we have the
    lock.
    Signed-off-by: default avatarZach Brown <zach.brown@oracle.com>
    Signed-off-by: default avatarSuparna Bhattacharya <suparna@in.ibm.com>
    Acked-by: default avatarBenjamin LaHaise <bcrl@kvack.org>
    Cc: "Chen, Kenneth W" <kenneth.w.chen@intel.com>
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    1ebb1101
aio.c 45 KB