• Tejun Heo's avatar
    percpu: finer grained locking to break deadlock and allow atomic free · ccea34b5
    Tejun Heo authored
    Impact: fix deadlock and allow atomic free
    
    Percpu allocation always uses GFP_KERNEL and whole alloc/free paths
    were protected by single mutex.  All percpu allocations have been from
    GFP_KERNEL-safe context and the original allocator had this assumption
    too.  However, by protecting both alloc and free paths with the same
    mutex, the new allocator creates free -> alloc -> GFP_KERNEL
    dependency which the original allocator didn't have.  This can lead to
    deadlock if free is called from FS or IO paths.  Also, in general,
    allocators are expected to allow free to be called from atomic
    context.
    
    This patch implements finer grained locking to break the deadlock and
    allow atomic free.  For details, please read the "Synchronization
    rules" comment.
    
    While at it, also add CONTEXT: to function comments to describe which
    context they expect to be called from and what they do to it.
    
    This problem was reported by Thomas Gleixner and Peter Zijlstra.
    
      http://thread.gmane.org/gmane.linux.kernel/802384Signed-off-by: default avatarTejun Heo <tj@kernel.org>
    Reported-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Reported-by: default avatarPeter Zijlstra <peterz@infradead.org>
    ccea34b5
percpu.c 33.7 KB