From: Petr Mladek <pmladek@suse.com>
To: Nicholas Piggin <npiggin@gmail.com>
Cc: John Ogness <john.ogness@linutronix.de>,
linux-kernel@vger.kernel.org,
Laurent Dufour <ldufour@linux.ibm.com>
Subject: Re: Removal of printk safe buffers delays NMI context printk
Date: Fri, 5 Nov 2021 17:01:12 +0100 [thread overview]
Message-ID: <YYVVSMc3pH32twTn@alley> (raw)
In-Reply-To: <1636073838.qpmyp6q17i.astroid@bobo.none>
On Fri 2021-11-05 11:26:35, Nicholas Piggin wrote:
> printk: restore flushing of NMI buffers on remote CPUs after NMI backtraces
>
> printk from NMI context relies on irq work being raised on the local CPU
> to print to console. This can be a problem if the NMI was raised by a
> lockup detector to print lockup stack and regs, because the CPU may not
> enable irqs (because it is locked up).
>
> Introduce printk_flush() that can be called from non-NMI context on
> another CPU to try to get those messages to the console.
>
> Fixes: 93d102f094be ("printk: remove safe buffers")
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
>
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2206,6 +2206,26 @@ int vprintk_store(int facility, int level,
> return ret;
> }
>
> +void printk_flush(void)
> +{
> + /*
> + * Disable preemption to avoid being preempted while holding
> + * console_sem which would prevent anyone from printing to
> + * console
> + */
> + preempt_disable();
> + /*
> + * Try to acquire and then immediately release the console
> + * semaphore. The release will print out buffers and wake up
> + * /dev/kmsg and syslog() users.
> + */
> + if (console_trylock_spinning())
> + console_unlock();
> + preempt_enable();
> +
> + wake_up_klogd();
> +}
> +
> asmlinkage int vprintk_emit(int facility, int level,
> const struct dev_printk_info *dev_info,
> const char *fmt, va_list args)
> --- a/lib/nmi_backtrace.c
> +++ b/lib/nmi_backtrace.c
> @@ -75,6 +75,12 @@ void nmi_trigger_cpumask_backtrace(const cpumask_t *mask,
> touch_softlockup_watchdog();
> }
>
> + /*
> + * Force flush any remote buffers that might be stuck in IRQ context
> + * and therefore could not run their irq_work.
> + */
> + printk_flush();
IMHO, nmi_trigger_cpumask_backtrace() might be called also from NMI
context.
printk_flush() is not safe in NMI context because console drivers have
their own locks. Even conosle_trylock() takes a lock, see
raw_spin_lock_irqsave(&sem->lock, flags) in down_trylock().
Best Regards,
Petr
> +
> clear_bit_unlock(0, &backtrace_flag);
> put_cpu();
> }
prev parent reply other threads:[~2021-11-05 16:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-04 15:54 Nicholas Piggin
2021-11-04 16:18 ` John Ogness
2021-11-05 1:26 ` Nicholas Piggin
2021-11-05 9:55 ` John Ogness
2021-11-05 11:43 ` Nicholas Piggin
2021-11-05 13:57 ` John Ogness
2021-11-05 16:23 ` Petr Mladek
2021-11-05 16:44 ` John Ogness
2021-11-06 0:26 ` Nicholas Piggin
2021-11-06 20:05 ` John Ogness
2021-11-05 23:57 ` Nicholas Piggin
2021-11-05 23:48 ` Nicholas Piggin
2021-11-05 16:01 ` Petr Mladek [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YYVVSMc3pH32twTn@alley \
--to=pmladek@suse.com \
--cc=john.ogness@linutronix.de \
--cc=ldufour@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=npiggin@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®