linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	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
Date: Thu, 28 Jun 2018 11:41:25 +0200	[thread overview]
Message-ID: <20180628094125.cq5qunckjyxhbovb@pathway.suse.cz> (raw)
In-Reply-To: <20180628022507.GD481@jagdpanzerIV>

On Thu 2018-06-28 11:25:07, Sergey Senozhatsky wrote:
> 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

Uff, it seems that the current design is "good" at lest from some
points of view.

> >  __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().

I am not super happy with the name either. But wakeup_console(),
schedule_console(), or queue_console() looked confusing.

Also I thought about poke_console() but I guess that I already suggested
this name in the past and people did not like it.

Feel free to suggest anything.


> Otherwise,
> Acked-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>

Anyway, thanks a lot for review.

Best Regards,
Petr

  reply	other threads:[~2018-06-28 19:04 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-27 14:08 [PATCH v2 0/3] printk: Deadlock in NMI regression Petr Mladek
2018-06-27 14:08 ` [PATCH v2 1/3] printk: Split the code for storing a message into the log buffer Petr Mladek
2018-06-28  2:10   ` Sergey Senozhatsky
2018-06-27 14:08 ` [PATCH v2 2/3] printk: Create helper function to queue deferred console handling Petr Mladek
2018-06-28  2:16   ` Sergey Senozhatsky
2018-06-28  2:19     ` Sergey Senozhatsky
2018-06-27 14:16 ` [PATCH v2 0/3] printk: Deadlock in NMI regression Sergey Senozhatsky
2018-06-27 14:23   ` Sergey Senozhatsky
2018-06-27 14:34   ` Petr Mladek
2018-06-28  9:08     ` Sergey Senozhatsky
2018-06-27 14:20 ` [PATCH v2 3/3] printk/nmi: Prevent deadlock when accessing the main log buffer in NMI Petr Mladek
2018-06-28  2:25   ` Sergey Senozhatsky
2018-06-28  9:41     ` Petr Mladek [this message]
2018-06-29  1:47       ` Sergey Senozhatsky
2018-06-29  7:25         ` Petr Mladek
2018-06-29 10:01           ` Sergey Senozhatsky
2018-06-28  2:39 ` [PATCH v2 0/3] printk: Deadlock in NMI regression Sergey Senozhatsky
2018-06-28 10:54   ` Petr Mladek
2018-06-29  1:52     ` Sergey Senozhatsky
2018-07-09 13:27 ` Petr Mladek

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=20180628094125.cq5qunckjyxhbovb@pathway.suse.cz \
    --to=pmladek@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=stable@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).