linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: tglx@linutronix.de, x86@kernel.org, elver@google.com,
	kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org,
	will@kernel.org, dvyukov@google.com, glider@google.com,
	andreyknvl@google.com
Subject: Re: [PATCH 2/9] rcu: Fixup noinstr warnings
Date: Mon, 15 Jun 2020 10:14:04 -0700	[thread overview]
Message-ID: <20200615171404.GI2723@paulmck-ThinkPad-P72> (raw)
In-Reply-To: <20200615162427.GI2554@hirez.programming.kicks-ass.net>

On Mon, Jun 15, 2020 at 06:24:27PM +0200, Peter Zijlstra wrote:
> On Mon, Jun 15, 2020 at 05:55:13PM +0200, Peter Zijlstra wrote:
> > On Mon, Jun 15, 2020 at 05:49:05PM +0200, Peter Zijlstra wrote:
> > > @@ -983,13 +993,17 @@ noinstr void rcu_nmi_enter(void)
> > >  		if (!in_nmi())
> > >  			rcu_cleanup_after_idle();
> > >  
> > > +		instrumentation_begin();
> > > +		// instrumentation for the noinstr rcu_dynticks_curr_cpu_in_eqs()
> > > +		instrument_atomic_read(&rdp->dynticks, sizeof(rdp->dynticks));
> > > +		// instrumentation for the noinstr rcu_dynticks_eqs_exit()
> > > +		instrument_atomic_write(&rdp->dynticks, sizeof(rdp->dynticks));
> > > +
> > >  		incby = 1;
> > >  	} else if (!in_nmi()) {
> > >  		instrumentation_begin();
> > >  		rcu_irq_enter_check_tick();
> > > -		instrumentation_end();
> > >  	}
> > > -	instrumentation_begin();
> > >  	trace_rcu_dyntick(incby == 1 ? TPS("Endirq") : TPS("++="),
> > >  			  rdp->dynticks_nmi_nesting,
> > >  			  rdp->dynticks_nmi_nesting + incby, atomic_read(&rdp->dynticks));
> > 
> > Oh, that's lost a possible instrumentation_begin() :/ But weirdly
> > objtool didn't complain about that... Let me poke at that.

This merge window has been quite the trainwreck, hasn't it?  :-/

> Like so then...

Looks plausible, firing up some tests.

							Thanx, Paul

> ---
> Subject: rcu: Fixup noinstr warnings
> 
> A KCSAN build revealed we have explicit annoations through atomic_*()
> usage, switch to arch_atomic_*() for the respective functions.
> 
> vmlinux.o: warning: objtool: rcu_nmi_exit()+0x4d: call to __kcsan_check_access() leaves .noinstr.text section
> vmlinux.o: warning: objtool: rcu_dynticks_eqs_enter()+0x25: call to __kcsan_check_access() leaves .noinstr.text section
> vmlinux.o: warning: objtool: rcu_nmi_enter()+0x4f: call to __kcsan_check_access() leaves .noinstr.text section
> vmlinux.o: warning: objtool: rcu_dynticks_eqs_exit()+0x2a: call to __kcsan_check_access() leaves .noinstr.text section
> vmlinux.o: warning: objtool: __rcu_is_watching()+0x25: call to __kcsan_check_access() leaves .noinstr.text section
> 
> Additionally, without the NOP in instrumentation_begin(), objtool would
> not detect the lack of the 'else instrumentation_begin();' branch in
> rcu_nmi_enter().
> 
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
>  include/linux/compiler.h |    2 +-
>  kernel/rcu/tree.c        |   33 +++++++++++++++++++++++++--------
>  2 files changed, 26 insertions(+), 9 deletions(-)
> 
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -123,7 +123,7 @@ void ftrace_likely_update(struct ftrace_
>  #ifdef CONFIG_DEBUG_ENTRY
>  /* Begin/end of an instrumentation safe region */
>  #define instrumentation_begin() ({					\
> -	asm volatile("%c0:\n\t"						\
> +	asm volatile("%c0: nop\n\t"						\
>  		     ".pushsection .discard.instr_begin\n\t"		\
>  		     ".long %c0b - .\n\t"				\
>  		     ".popsection\n\t" : : "i" (__COUNTER__));		\
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -250,7 +250,7 @@ static noinstr void rcu_dynticks_eqs_ent
>  	 * next idle sojourn.
>  	 */
>  	rcu_dynticks_task_trace_enter();  // Before ->dynticks update!
> -	seq = atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdp->dynticks);
> +	seq = arch_atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdp->dynticks);
>  	// RCU is no longer watching.  Better be in extended quiescent state!
>  	WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
>  		     (seq & RCU_DYNTICK_CTRL_CTR));
> @@ -274,13 +274,13 @@ static noinstr void rcu_dynticks_eqs_exi
>  	 * and we also must force ordering with the next RCU read-side
>  	 * critical section.
>  	 */
> -	seq = atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdp->dynticks);
> +	seq = arch_atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdp->dynticks);
>  	// RCU is now watching.  Better not be in an extended quiescent state!
>  	rcu_dynticks_task_trace_exit();  // After ->dynticks update!
>  	WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
>  		     !(seq & RCU_DYNTICK_CTRL_CTR));
>  	if (seq & RCU_DYNTICK_CTRL_MASK) {
> -		atomic_andnot(RCU_DYNTICK_CTRL_MASK, &rdp->dynticks);
> +		arch_atomic_andnot(RCU_DYNTICK_CTRL_MASK, &rdp->dynticks);
>  		smp_mb__after_atomic(); /* _exit after clearing mask. */
>  	}
>  }
> @@ -313,7 +313,7 @@ static __always_inline bool rcu_dynticks
>  {
>  	struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
>  
> -	return !(atomic_read(&rdp->dynticks) & RCU_DYNTICK_CTRL_CTR);
> +	return !(arch_atomic_read(&rdp->dynticks) & RCU_DYNTICK_CTRL_CTR);
>  }
>  
>  /*
> @@ -633,6 +633,10 @@ static noinstr void rcu_eqs_enter(bool u
>  	do_nocb_deferred_wakeup(rdp);
>  	rcu_prepare_for_idle();
>  	rcu_preempt_deferred_qs(current);
> +
> +	// instrumentation for the noinstr rcu_dynticks_eqs_enter()
> +	instrument_atomic_write(&rdp->dynticks, sizeof(rdp->dynticks));
> +
>  	instrumentation_end();
>  	WRITE_ONCE(rdp->dynticks_nesting, 0); /* Avoid irq-access tearing. */
>  	// RCU is watching here ...
> @@ -692,6 +696,7 @@ noinstr void rcu_nmi_exit(void)
>  {
>  	struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
>  
> +	instrumentation_begin();
>  	/*
>  	 * Check for ->dynticks_nmi_nesting underflow and bad ->dynticks.
>  	 * (We are exiting an NMI handler, so RCU better be paying attention
> @@ -705,7 +710,6 @@ noinstr void rcu_nmi_exit(void)
>  	 * leave it in non-RCU-idle state.
>  	 */
>  	if (rdp->dynticks_nmi_nesting != 1) {
> -		instrumentation_begin();
>  		trace_rcu_dyntick(TPS("--="), rdp->dynticks_nmi_nesting, rdp->dynticks_nmi_nesting - 2,
>  				  atomic_read(&rdp->dynticks));
>  		WRITE_ONCE(rdp->dynticks_nmi_nesting, /* No store tearing. */
> @@ -714,13 +718,15 @@ noinstr void rcu_nmi_exit(void)
>  		return;
>  	}
>  
> -	instrumentation_begin();
>  	/* This NMI interrupted an RCU-idle CPU, restore RCU-idleness. */
>  	trace_rcu_dyntick(TPS("Startirq"), rdp->dynticks_nmi_nesting, 0, atomic_read(&rdp->dynticks));
>  	WRITE_ONCE(rdp->dynticks_nmi_nesting, 0); /* Avoid store tearing. */
>  
>  	if (!in_nmi())
>  		rcu_prepare_for_idle();
> +
> +	// instrumentation for the noinstr rcu_dynticks_eqs_enter()
> +	instrument_atomic_write(&rdp->dynticks, sizeof(rdp->dynticks));
>  	instrumentation_end();
>  
>  	// RCU is watching here ...
> @@ -838,6 +844,10 @@ static void noinstr rcu_eqs_exit(bool us
>  	rcu_dynticks_eqs_exit();
>  	// ... but is watching here.
>  	instrumentation_begin();
> +
> +	// instrumentation for the noinstr rcu_dynticks_eqs_exit()
> +	instrument_atomic_write(&rdp->dynticks, sizeof(rdp->dynticks));
> +
>  	rcu_cleanup_after_idle();
>  	trace_rcu_dyntick(TPS("End"), rdp->dynticks_nesting, 1, atomic_read(&rdp->dynticks));
>  	WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current));
> @@ -983,13 +993,20 @@ noinstr void rcu_nmi_enter(void)
>  		if (!in_nmi())
>  			rcu_cleanup_after_idle();
>  
> +		instrumentation_begin();
> +		// instrumentation for the noinstr rcu_dynticks_curr_cpu_in_eqs()
> +		instrument_atomic_read(&rdp->dynticks, sizeof(rdp->dynticks));
> +		// instrumentation for the noinstr rcu_dynticks_eqs_exit()
> +		instrument_atomic_write(&rdp->dynticks, sizeof(rdp->dynticks));
> +
>  		incby = 1;
>  	} else if (!in_nmi()) {
>  		instrumentation_begin();
>  		rcu_irq_enter_check_tick();
> -		instrumentation_end();
> +	} else {
> +		instrumentation_begin();
>  	}
> -	instrumentation_begin();
> +
>  	trace_rcu_dyntick(incby == 1 ? TPS("Endirq") : TPS("++="),
>  			  rdp->dynticks_nmi_nesting,
>  			  rdp->dynticks_nmi_nesting + incby, atomic_read(&rdp->dynticks));

  reply	other threads:[~2020-06-15 17:14 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03 11:40 [PATCH 0/9] x86/entry fixes Peter Zijlstra
2020-06-03 11:40 ` [PATCH 1/9] x86/entry: Fix irq_exit() Peter Zijlstra
2020-06-03 11:40 ` [PATCH 2/9] rcu: Fixup noinstr warnings Peter Zijlstra
2020-06-03 16:46   ` Paul E. McKenney
2020-06-03 17:13     ` Peter Zijlstra
2020-06-04  3:34       ` Paul E. McKenney
2020-06-04  6:02         ` Marco Elver
2020-06-04 14:14           ` Paul E. McKenney
2020-06-04  8:05         ` Peter Zijlstra
2020-06-04 14:17           ` Paul E. McKenney
2020-06-15 15:30     ` Peter Zijlstra
2020-06-15 15:52       ` Paul E. McKenney
2020-06-15 16:06         ` Peter Zijlstra
2020-06-15 15:49   ` Peter Zijlstra
2020-06-15 15:55     ` Peter Zijlstra
2020-06-15 16:24       ` Peter Zijlstra
2020-06-15 17:14         ` Paul E. McKenney [this message]
2020-06-15 18:33           ` Peter Zijlstra
2020-06-15 18:59             ` Paul E. McKenney
2020-06-15 20:00           ` Paul E. McKenney
2020-06-19 22:15           ` Paul E. McKenney
2020-06-23 20:46             ` Peter Zijlstra
2020-06-23 21:44               ` Paul E. McKenney
2020-06-24  7:52                 ` Peter Zijlstra
2020-06-24 13:03                   ` Paul E. McKenney
2020-06-03 11:40 ` [PATCH 3/9] x86/entry: __always_inline debugreg for noinstr Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 11:40 ` [PATCH 4/9] x86/entry: __always_inline irqflags " Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 11:40 ` [PATCH 5/9] x86/entry: __always_inline arch_atomic_* " Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 11:40 ` [PATCH 6/9] x86/entry: Re-order #DB handler to avoid *SAN instrumentation Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 11:40 ` [PATCH 7/9] lockdep: __always_inline more for noinstr Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 11:40 ` [PATCH 8/9] x86/entry: __always_inline CR2 " Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 11:40 ` [PATCH 9/9] x86/entry, cpumask: Provide non-instrumented variant of cpu_is_offline() Peter Zijlstra
2020-06-03 17:50   ` [tip: x86/entry] " tip-bot2 for Peter Zijlstra
2020-06-03 12:00 ` [PATCH 0/9] x86/entry fixes Peter Zijlstra
2020-06-03 12:08   ` Peter Zijlstra
2020-06-03 12:08     ` Marco Elver
2020-06-03 12:18       ` Peter Zijlstra
2020-06-03 13:32         ` Marco Elver
2020-06-03 14:47           ` Marco Elver
2020-06-03 16:07             ` Peter Zijlstra
2020-06-03 17:26               ` Marco Elver
2020-06-03 18:16               ` Peter Zijlstra
2020-06-03 19:10                 ` Marco Elver
2020-06-04  6:00                   ` Marco Elver
2020-06-04  9:52                     ` Marco Elver

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=20200615171404.GI2723@paulmck-ThinkPad-P72 \
    --to=paulmck@kernel.org \
    --cc=andreyknvl@google.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.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;
as well as URLs for NNTP newsgroup(s).