Re: [PATCH] kernel/printk: prevent deadlock at calling kmsg_dump from NMI context

From: Konstantin Khlebnikov
Date: Sat Jul 13 2019 - 02:51:38 EST


On Sat, Jul 13, 2019 at 9:10 AM Sergey Senozhatsky
<sergey.senozhatsky@xxxxxxxxx> wrote:
>
> On (07/12/19 17:54), Konstantin Khlebnikov wrote:
> > Function kmsg_dump could be invoked from NMI context intentionally or
> > accidentally because it is called at various oops/panic paths.
> > Kernel message dumpers are not ready to work in NMI context right now.
> > They could deadlock on lockbuf_lock or break internal structures.
>
> Hmm.
> printk()-s from NMI go through per-CPU printk_safe/nmi - a bunch of
> lockless buffers which is supposed to deal with printk() deadlocks,
> including NMI printk()-s.
>
> include/linux/hardirq.h
>
> #define nmi_enter()
> ...
> printk_nmi_enter();
> ...
>
> #define nmi_exit()
> ...
> printk_nmi_exit();
> ...
>
> So we are not really supposed to deadlock.

Yep printk() can deal with NMI, but kmsg_dump() is a different beast.
It reads printk buffer and saves content into persistent storage like ACPI ERST.

>
> -ss