Skip to content
  • Waiman Long's avatar
    lib/debugobjects.c: move printk out of db lock critical sections · 7a2204c0
    Waiman Long authored
    The db->lock is a raw spinlock and so the lock hold time is supposed to be
    short.  This will not be the case when printk() is being involved in some
    of the critical sections.
    
    In order to avoid the long hold time, in case some messages need to be
    printed, all the debug_object_is_on_stack() and debug_print_object() calls
    are now moved out of those critical sections in the following functions.
    
     - __debug_object_init()
     - debug_object_activate()
     - debug_object_deactivate()
     - debug_object_destroy()
     - debug_object_free()
     - debug_object_active_state()
     - __debug_check_no_obj_freed()
     - check_results()
    
    Holding the db->lock while calling printk() may lead to deadlock if
    printk() somehow requires the allocation/freeing of debug object that
    happens to be in the same hash bucket or a circular lock dependency
    warning from lockdep as reported in
    
      https://lkml.kernel.org/r/20181211091154.GL23332@shao2-debian
    
    [   87.209665] WARNING: possible circular locking dependency detected
    [   87.210547] 4.20.0-rc4-00057-gc96cf923 #1 Tainted: G        W
    [   87.211449] ------------------------------------------------------
    [   87.212405] getty/519 is trying to acquire lock:
    [   87.213074] (____ptrval____) (&obj_hash[i].lock){-.-.}, at: debug_check_no_obj_freed+0xb4/0x302
    [   87.214343]
    [   87.214343] but task is already holding lock:
    [   87.215174] (____ptrval____) (&port_lock_key){-.-.}, at: uart_shutdown+0x3a3/0x4e2
    [   87.216260]
    [   87.216260] which lock already depends on the new lock.
    
    This patch was also found to be able to fix a boot hanging problem when
    the initramfs image was switched on after a debugobjects splat from the
    EFI code.
    
    Link: http://lkml.kernel.org/r/1544738377-3848-1-git-send-email-longman@redhat.com
    
    
    Signed-off-by: default avatarWaiman Long <longman@redhat.com>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Ingo Molnar <mingo@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Yang Shi <yang.shi@linux.alibaba.com>
    Cc: Arnd Bergmann <arnd@arndb.de>
    Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
    Cc: Dmitry Safonov <dima@arista.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
    7a2204c0