lkml.org 
[lkml]   [2023]   [Mar]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH printk v1 02/18] printk: Add NMI check to down_trylock_console_sem()
    Date
    The printk path is NMI safe because it only adds content to the
    buffer and then triggers the delayed output via irq_work. If the
    console is flushed or unblanked (on panic) from NMI then it can
    deadlock in down_trylock_console_sem() because the semaphore is not
    NMI safe.

    Avoid try-locking the console from NMI and assume it failed.

    Signed-off-by: John Ogness <john.ogness@linutronix.de>
    ---
    kernel/printk/printk.c | 4 ++++
    1 file changed, 4 insertions(+)

    diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
    index 40c5f4170ac7..84af038292d9 100644
    --- a/kernel/printk/printk.c
    +++ b/kernel/printk/printk.c
    @@ -318,6 +318,10 @@ static int __down_trylock_console_sem(unsigned long ip)
    int lock_failed;
    unsigned long flags;

    + /* Semaphores are not NMI-safe. */
    + if (in_nmi())
    + return 1;
    +
    /*
    * Here and in __up_console_sem() we need to be in safe mode,
    * because spindump/WARN/etc from under console ->lock will
    --
    2.30.2
    \
     
     \ /
      Last update: 2023-03-27 00:42    [W:4.437 / U:0.116 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site