From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg0-f65.google.com ([74.125.83.65]:42103 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752429AbeF1CZL (ORCPT ); Wed, 27 Jun 2018 22:25:11 -0400 Date: Thu, 28 Jun 2018 11:25:07 +0900 From: Sergey Senozhatsky To: Petr Mladek Cc: Sergey Senozhatsky , Steven Rostedt , Peter Zijlstra , Tetsuo Handa , Sergey Senozhatsky , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2 3/3] printk/nmi: Prevent deadlock when accessing the main log buffer in NMI Message-ID: <20180628022507.GD481@jagdpanzerIV> References: <20180627140817.27764-1-pmladek@suse.com> <20180627142028.11259-1-pmladek@suse.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180627142028.11259-1-pmladek@suse.com> Sender: stable-owner@vger.kernel.org List-ID: On (06/27/18 16:20), Petr Mladek wrote: > +/* > + * Marks a code that might produce many messages in NMI context > + * and the risk of losing them is more critical than eventual > + * reordering. > + * > + * It has effect only when called in NMI context. Then printk() > + * will try to store the messages into the main logbuf directly > + * and use the per-CPU buffers only as a fallback when the lock > + * is not available. > + */ > +void printk_nmi_direct_enter(void) > +{ > + if (this_cpu_read(printk_context) & PRINTK_NMI_CONTEXT_MASK) > + this_cpu_or(printk_context, PRINTK_NMI_DIRECT_CONTEXT_MASK); > +} A side note: This nesting also handles recursive printk-s for us. NMI: printk_nmi_enter ftrace_dump printk_nmi_direct_enter vprintk_func spin_lock(logbuf_lock) vprintk_store vsprintf WARN_ON vprintk_func vprintk_nmi > __printf(1, 0) int vprintk_func(const char *fmt, va_list args) > { > + /* > + * Try to use the main logbuf even in NMI. But avoid calling console > + * drivers that might have their own locks. > + */ > + if ((this_cpu_read(printk_context) & PRINTK_NMI_DIRECT_CONTEXT_MASK) && > + raw_spin_trylock(&logbuf_lock)) { > + int len; > + > + len = vprintk_store(0, LOGLEVEL_DEFAULT, NULL, 0, fmt, args); > + raw_spin_unlock(&logbuf_lock); > + defer_console(); > + return len; > + } So, maybe, something a bit better than defer_console(). Otherwise, Acked-by: Sergey Senozhatsky -ss