printk/nmi: Prevent deadlock when accessing the main log buffer in NMI
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...
Showing
- include/linux/printk.h 4 additions, 0 deletionsinclude/linux/printk.h
- kernel/printk/internal.h 8 additions, 1 deletionkernel/printk/internal.h
- kernel/printk/printk_safe.c 37 additions, 21 deletionskernel/printk/printk_safe.c
- kernel/trace/trace.c 3 additions, 1 deletionkernel/trace/trace.c
- lib/nmi_backtrace.c 0 additions, 3 deletionslib/nmi_backtrace.c
Please register or sign in to comment