public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Petr Mladek <pmladek@suse.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: Re: [PATCH] printk/tracing: Do not trace printk_nmi_enter()
Date: Thu, 6 Sep 2018 11:31:51 +0900	[thread overview]
Message-ID: <20180906023151.GA749@jagdpanzerIV> (raw)
In-Reply-To: <20180905213334.03375777@vmware.local.home>

Hello,

On (09/05/18 21:33), Steven Rostedt wrote:
>   do_idle {
> 
>     [interrupts enabled]
> 
>     <interrupt> [interrupts disabled]
> 	TRACE_IRQS_OFF [lockdep says irqs off]
> 	[...]
> 	TRACE_IRQS_IRET
> 	    test if pt_regs say return to interrupts enabled [yes]
> 	    TRACE_IRQS_ON [lockdep says irqs are on]
> 
> 	    <nmi>
> 		nmi_enter() {
> 		    printk_nmi_enter() [traced by ftrace]
> 		    [ hit ftrace breakpoint ]
> 		    <breakpoint exception>
> 			TRACE_IRQS_OFF [lockdep says irqs off]
> 			[...]
> 			TRACE_IRQS_IRET [return from breakpoint]
> 			   test if pt_regs say interrupts enabled [no]
> 			   [iret back to interrupt]
> 	   [iret back to code]
> 
>     tick_nohz_idle_enter() {
> 
> 	lockdep_assert_irqs_enabled() [lockdep say no!]
> 
> Although interrupts are indeed enabled, lockdep thinks it is not, and since
> we now do asserts via lockdep, it gives a false warning. The issue here is
> that printk_nmi_enter() is called before lockdep_off(), which disables
> lockdep (for this reason) in NMIs. By simply not allowing ftrace to see
> printk_nmi_enter() (via notrace annotation) we keep lockdep from getting
> confused.

Great catch and I like the patch!

Indeed, with printk_nmi we changed the "everything that nmi_enter does
should happen after lockdep_off" to "everything that nmi_enter does should
happen after printk_nmi_enter" // +similar change to nmi_exit.

An alternative option, thus, could be re-instating back the rule that
lockdep_off/on should be the first and the last thing we do in
nmi_enter/nmi_exit. E.g.

nmi_enter()
	lockdep_off();
	printk_nmi_enter();

nmi_exit()
	printk_nmi_exit();
	lockdep_on();

I guess that we can keep printk_nmi_enter/printk_nmi_exit at the top
and at the bottom of nmi_enter/nmi_exit correspondingly just in case
if lockdep_off/lockdep_on sometime in the future starts invoking printk(),
which would deadlock us. Hence

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


> Cc: stable@vger.kernel.org
> Fixes: 099f1c84c0052 ("printk: introduce per-cpu safe_print seq buffer")

A minor nitpick,

printk_nmi was introduced by 42a0bb3f71383b457 ("printk/nmi: generic
solution for safe printk in NMI") - in that commit we declared a new
printk_nmi_enter/exit should be the first and the last thing we do in
nmi_enter/nmi_exit rule.

	-ss

  reply	other threads:[~2018-09-06  2:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-06  1:33 [PATCH] printk/tracing: Do not trace printk_nmi_enter() Steven Rostedt
2018-09-06  2:31 ` Sergey Senozhatsky [this message]
2018-09-06  9:04   ` Petr Mladek
2018-09-06 15:22   ` Steven Rostedt
2018-09-07  7:45   ` Peter Zijlstra
2018-09-07  8:28     ` Petr Mladek
2018-09-07  8:35       ` Sergey Senozhatsky
2018-09-07 13:47         ` Steven Rostedt
2018-09-07  9:30       ` Peter Zijlstra
2018-09-07 13:53         ` Steven Rostedt
2018-09-10  5:32     ` locking/lockdep: Fix NMI handling kbuild test robot
2018-09-07  7:34 ` [PATCH] printk/tracing: Do not trace printk_nmi_enter() Peter Zijlstra
2018-09-07 13:41   ` Steven Rostedt
2018-09-07 13:45     ` Peter Zijlstra
2018-09-07 13:55       ` Steven Rostedt
2018-09-07 14:01         ` Steven Rostedt
2018-09-07 14:03           ` Peter Zijlstra
2018-09-07 14:52             ` Sergey Senozhatsky
2018-09-07 14:02         ` Peter Zijlstra

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=20180906023151.GA749@jagdpanzerIV \
    --to=sergey.senozhatsky.work@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=tglx@linutronix.de \
    /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