public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jan Kara <jack@suse.cz>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] printk/nmi: avoid direct printk()-s from __printk_nmi_flush()
Date: Tue, 30 Aug 2016 18:39:18 +0900	[thread overview]
Message-ID: <20160830093918.GA23693@swordfish> (raw)
In-Reply-To: <20160830090436.GO4866@pathway.suse.cz>

On (08/30/16 11:04), Petr Mladek wrote:
> On Tue 2016-08-30 16:58:34, Sergey Senozhatsky wrote:
> > Petr,
> > one more question. Not related to the patch, but still related to NMI.
> > 
> > can NMI nest?
> 
> AFAIK, they cannot. NMIs should be disabled until iret is called.
> Therefore we should be on the safe side if iret is not called
> inside the NMI handler. But this should not happen because
> it would cause other problems, like using wrong return address.
> 
> Well, x86 nmi code has some hacks to handle exceptions inside
> NMI handlers that use iret. But printk_nmi_enter()/printk_nmi_exit()
> are never nested there. It is prevented by the nmi_state per-CPU
> variable. See do_nmi() in arch/x86/kernel/nmi.c.

yes, x86 has a per-cpu nmi_state to handle the case when NMI is
loosing its NMI context. But other arch-s, as far as I can see,
don't do that. Does it mean that we are safe only on x86?

this printk_func_saved thing is still will be needed, I think,
for alt_printk.

Example:

process abc
	printk()
		alt_printk_enter()
			this_cpu_write(printk_func, vprintk_alt);
->	NMI
	:	printk_nmi_enter()
	:		this_cpu_write(printk_func, vprintk_nmi);
	:	printk_nmi_exit()
	:		this_cpu_write(printk_func, vprintk_default);
	return NMI

		printk()  <<<<  nested printk -> vprintk_default(), set by nmi_exit()
		alt_printk_exit()
	...

	-ss

  reply	other threads:[~2016-08-30  9:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-29 12:32 [PATCH] printk/nmi: avoid direct printk()-s from __printk_nmi_flush() Sergey Senozhatsky
2016-08-29 15:16 ` Petr Mladek
2016-08-30  1:07   ` Sergey Senozhatsky
2016-08-30  7:58   ` Sergey Senozhatsky
2016-08-30  9:04     ` Petr Mladek
2016-08-30  9:39       ` Sergey Senozhatsky [this message]
2016-08-30 11:19         ` Petr Mladek
2016-08-31  4:00           ` Sergey Senozhatsky
2016-09-01  7:55           ` Sergey Senozhatsky
2016-09-01  8:17             ` 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=20160830093918.GA23693@swordfish \
    --to=sergey.senozhatsky.work@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.com \
    --cc=sergey.senozhatsky@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