public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Peter Zijlstra <peterz@infradead.org>,
	Paul McKenney <paulmck@kernel.org>,
	eupm90@gmail.com
Cc: linux-kernel@vger.kernel.org, x86@kernel.org,
	Andy Lutomirski <luto@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: #PF from NMI
Date: Sat, 14 Nov 2020 00:13:58 +0100	[thread overview]
Message-ID: <87ima8luix.fsf@nanos.tec.linutronix.de> (raw)
In-Reply-To: <20201113125332.GA2611@hirez.programming.kicks-ass.net>

On Fri, Nov 13 2020 at 13:53, Peter Zijlstra wrote:
> [  139.226724] WARNING: CPU: 9 PID: 2290 at kernel/rcu/tree.c:932 __rcu_irq_enter_check_tick+0x84/0xd0
> [  139.226753]  irqentry_enter+0x25/0x40
> [  139.226753]  exc_page_fault+0x38/0x4c0
> [  139.226753]  asm_exc_page_fault+0x1e/0x30

...

> [  139.226757]  perf_callchain_user+0xf4/0x280
>
> Which is a #PF from NMI context, which is perfectly fine. However
> __rcu_irq_enter_check_tick() is triggering WARN.
>
> AFAICT the right thing is to simply remove the warn like so.
>
> ---
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index 430ba58d8bfe..9bda92d8b914 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -928,8 +928,8 @@ void __rcu_irq_enter_check_tick(void)
>  {
>  	struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
>  
> -	 // Enabling the tick is unsafe in NMI handlers.
> -	if (WARN_ON_ONCE(in_nmi()))
> +	// if we're here from NMI, there's nothing to do.
> +	if (in_nmi())
>  		return;
>  
>  	RCU_LOCKDEP_WARN(rcu_dynticks_curr_cpu_in_eqs(),

Yes. That's right.

To answer Pauls question:

> But is a corresponding change required on return-from-NMI side?
> Looks OK to me at first glance, but I could be missing something.

No. The corresponding issue is not return from NMI. The corresponding
problem is the return from the page fault handler, but there is nothing
to worry about. That part is NMI safe already.

And Luto's as well:

> with the following caveat that has nothing to do with NMI: the rest of
> irqentry_enter() has tracing calls in it. Does anything prevent
> infinite recursion if one of those tracing calls causes a page fault?

nmi:
  ...
  trace_hardirqs_off_finish() {
    if (!this_cpu_read(tracing_irq_cpu)) {
           this_cpu_write(tracing_irq_cpu, 1);
           ...
  }
  ...
  perf()

#PF
  save_cr2()
  
  irqentry_enter()
     trace_hardirqs_off_finish()
        if (!this_cpu_read(tracing_irq_cpu)) {

So yes, it is recursion protected unless I'm missing something.

Thanks,

        tglx

  parent reply	other threads:[~2020-11-13 23:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13 12:53 #PF from NMI Peter Zijlstra
2020-11-13 17:16 ` Paul E. McKenney
2020-11-13 17:23 ` Andy Lutomirski
2020-11-13 23:13 ` Thomas Gleixner [this message]
2020-11-14  1:05   ` Paul E. McKenney
2020-11-16 12:10     ` [PATCH] rcu: Allow rcu_irq_enter_check_tick() " Peter Zijlstra
2020-11-16 17:24       ` Thomas Gleixner
2020-11-16 20:00         ` Paul E. McKenney
2020-11-16 16:46   ` #PF " Steven Rostedt

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=87ima8luix.fsf@nanos.tec.linutronix.de \
    --to=tglx@linutronix.de \
    --cc=eupm90@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=x86@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