Skip to content
  • Petr Mladek's avatar
    printk/nmi: Prevent deadlock when accessing the main log buffer in NMI · 03fc7f9c
    Petr Mladek authored
    The commit 719f6a70 ("printk: Use the main logbuf in NMI
    when logbuf_lock is available") brought back the possible deadlocks
    in printk() and NMI.
    
    The check of logbuf_lock is done only in printk_nmi_enter() to prevent
    mixed output. But another CPU might take the lock later, enter NMI, and:
    
          + Both NMIs might be serialized by yet another lock, for example,
    	the one in nmi_cpu_backtrace().
    
          + The other CPU might get stopped in NMI, see smp_send_stop()
    	in panic().
    
    The only safe solution is to use trylock when storing the message
    into the main log-buffer. It might cause reordering when some lines
    go to the main lock buffer directly and others are delayed via
    the per-CPU buffer. It means that it is not useful in general.
    
    This patch replaces the problematic NMI deferred context with NMI
    direct context. It can be used to mark a code that might produce
    many messages in NMI and the risk of losing them is more critical
    t...
    03fc7f9c