All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Jiri Olsa <olsajiri@gmail.com>,
	Frederic Weisbecker <frederic@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	netdev@vger.kernel.org, bpf@vger.kernel.org,
	lkml <linux-kernel@vger.kernel.org>,
	Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
	Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@chromium.org>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH bpf-next 1/2] cpuidle/rcu: Making arch_cpu_idle and rcu_idle_exit noinstr
Date: Thu, 19 May 2022 13:33:16 +0200	[thread overview]
Message-ID: <YoYq/M6ZSQ+U2sar@krava> (raw)
In-Reply-To: <20220518162118.GA2661055@paulmck-ThinkPad-P17-Gen-1>

On Wed, May 18, 2022 at 09:21:18AM -0700, Paul E. McKenney wrote:
> On Tue, May 17, 2022 at 12:13:45PM +0200, Jiri Olsa wrote:
> > On Mon, May 16, 2022 at 01:49:22PM +0200, Frederic Weisbecker wrote:
> > > On Sun, May 15, 2022 at 09:25:35PM -0700, Paul E. McKenney wrote:
> > > > On Sun, May 15, 2022 at 10:36:52PM +0200, Jiri Olsa wrote:
> > > > > Making arch_cpu_idle and rcu_idle_exit noinstr. Both functions run
> > > > > in rcu 'not watching' context and if there's tracer attached to
> > > > > them, which uses rcu (e.g. kprobe multi interface) it will hit RCU
> > > > > warning like:
> > > > > 
> > > > >   [    3.017540] WARNING: suspicious RCU usage
> > > > >   ...
> > > > >   [    3.018363]  kprobe_multi_link_handler+0x68/0x1c0
> > > > >   [    3.018364]  ? kprobe_multi_link_handler+0x3e/0x1c0
> > > > >   [    3.018366]  ? arch_cpu_idle_dead+0x10/0x10
> > > > >   [    3.018367]  ? arch_cpu_idle_dead+0x10/0x10
> > > > >   [    3.018371]  fprobe_handler.part.0+0xab/0x150
> > > > >   [    3.018374]  0xffffffffa00080c8
> > > > >   [    3.018393]  ? arch_cpu_idle+0x5/0x10
> > > > >   [    3.018398]  arch_cpu_idle+0x5/0x10
> > > > >   [    3.018399]  default_idle_call+0x59/0x90
> > > > >   [    3.018401]  do_idle+0x1c3/0x1d0
> > > > > 
> > > > > The call path is following:
> > > > > 
> > > > > default_idle_call
> > > > >   rcu_idle_enter
> > > > >   arch_cpu_idle
> > > > >   rcu_idle_exit
> > > > > 
> > > > > The arch_cpu_idle and rcu_idle_exit are the only ones from above
> > > > > path that are traceble and cause this problem on my setup.
> > > > > 
> > > > > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > > > 
> > > > From an RCU viewpoint:
> > > > 
> > > > Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
> > > > 
> > > > [ I considered asking for an instrumentation_on() in rcu_idle_exit(),
> > > > but there is no point given that local_irq_restore() isn't something
> > > > you instrument anyway. ]
> > > 
> > > So local_irq_save() in the beginning of rcu_idle_exit() is unsafe because
> > > it is instrumentable by the function (graph)  tracers and the irqsoff tracer.
> > > 
> > > Also it calls into lockdep that might make use of RCU.
> > > 
> > > That's why rcu_idle_exit() is not noinstr yet. See this patch:
> > > 
> > > https://lore.kernel.org/lkml/20220503100051.2799723-4-frederic@kernel.org/
> > 
> > I see, could we mark it at least with notrace meanwhile?
> 
> For the RCU part, how about as follows?
> 
> If this approach is reasonable, my guess would be that Frederic will pull
> it into his context-tracking series, perhaps using a revert of this patch
> to maintain sanity in the near term.
> 
> If this approach is unreasonable, well, that is Murphy for you!

I checked and it works in my test ;-)

> 
> For the x86 idle part, my feeling is still that the rcu_idle_enter()
> and rcu_idle_exit() need to be pushed deeper into the code.  Perhaps
> an ongoing process as the idle loop continues to be dug deeper?

for arch_cpu_idle with noinstr I'm getting this W=1 warning:

vmlinux.o: warning: objtool: arch_cpu_idle()+0xb: call to {dynamic}() leaves .noinstr.text section

we could have it with notrace if that's a problem

thanks,
jirka

> 
> 							Thanx, Paul
> 
> ------------------------------------------------------------------------
> 
> commit cd338be719a0a692e0d50e1a8438e1f6c7165d9c
> Author: Paul E. McKenney <paulmck@kernel.org>
> Date:   Tue May 17 21:00:04 2022 -0700
> 
>     rcu: Apply noinstr to rcu_idle_enter() and rcu_idle_exit()
>     
>     This commit applies the "noinstr" tag to the rcu_idle_enter() and
>     rcu_idle_exit() functions, which are invoked from portions of the idle
>     loop that cannot be instrumented.  These tags require reworking the
>     rcu_eqs_enter() and rcu_eqs_exit() functions that these two functions
>     invoke in order to cause them to use normal assertions rather than
>     lockdep.  In addition, within rcu_idle_exit(), the raw versions of
>     local_irq_save() and local_irq_restore() are used, again to avoid issues
>     with lockdep in uninstrumented code.
>     
>     This patch is based in part on an earlier patch by Jiri Olsa, discussions
>     with Peter Zijlstra and Frederic Weisbecker, earlier changes by Thomas
>     Gleixner, and off-list discussions with Yonghong Song.
>     
>     Link: https://lore.kernel.org/lkml/20220515203653.4039075-1-jolsa@kernel.org/
>     Reported-by: Jiri Olsa <jolsa@kernel.org>
>     Reported-by: Alexei Starovoitov <ast@kernel.org>
>     Reported-by: Andrii Nakryiko <andrii@kernel.org>
>     Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
>     Reviewed-by: Yonghong Song <yhs@fb.com>
> 
> diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
> index 222d59299a2af..02233b17cce0e 100644
> --- a/kernel/rcu/tree.c
> +++ b/kernel/rcu/tree.c
> @@ -635,8 +635,8 @@ static noinstr void rcu_eqs_enter(bool user)
>  		return;
>  	}
>  
> -	lockdep_assert_irqs_disabled();
>  	instrumentation_begin();
> +	lockdep_assert_irqs_disabled();
>  	trace_rcu_dyntick(TPS("Start"), rdp->dynticks_nesting, 0, atomic_read(&rdp->dynticks));
>  	WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current));
>  	rcu_preempt_deferred_qs(current);
> @@ -663,9 +663,9 @@ static noinstr void rcu_eqs_enter(bool user)
>   * If you add or remove a call to rcu_idle_enter(), be sure to test with
>   * CONFIG_RCU_EQS_DEBUG=y.
>   */
> -void rcu_idle_enter(void)
> +void noinstr rcu_idle_enter(void)
>  {
> -	lockdep_assert_irqs_disabled();
> +	WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !raw_irqs_disabled());
>  	rcu_eqs_enter(false);
>  }
>  EXPORT_SYMBOL_GPL(rcu_idle_enter);
> @@ -865,7 +865,7 @@ static void noinstr rcu_eqs_exit(bool user)
>  	struct rcu_data *rdp;
>  	long oldval;
>  
> -	lockdep_assert_irqs_disabled();
> +	WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !raw_irqs_disabled());
>  	rdp = this_cpu_ptr(&rcu_data);
>  	oldval = rdp->dynticks_nesting;
>  	WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && oldval < 0);
> @@ -900,13 +900,13 @@ static void noinstr rcu_eqs_exit(bool user)
>   * If you add or remove a call to rcu_idle_exit(), be sure to test with
>   * CONFIG_RCU_EQS_DEBUG=y.
>   */
> -void rcu_idle_exit(void)
> +void noinstr rcu_idle_exit(void)
>  {
>  	unsigned long flags;
>  
> -	local_irq_save(flags);
> +	raw_local_irq_save(flags);
>  	rcu_eqs_exit(false);
> -	local_irq_restore(flags);
> +	raw_local_irq_restore(flags);
>  }
>  EXPORT_SYMBOL_GPL(rcu_idle_exit);
>  

  reply	other threads:[~2022-05-19 11:33 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-15 20:36 [PATCH bpf-next 1/2] cpuidle/rcu: Making arch_cpu_idle and rcu_idle_exit noinstr Jiri Olsa
2022-05-15 20:36 ` [PATCH bpf-next 2/2] selftests/bpf: Remove filter for unsafe functions in kprobe_multi test Jiri Olsa
2022-05-16  4:25 ` [PATCH bpf-next 1/2] cpuidle/rcu: Making arch_cpu_idle and rcu_idle_exit noinstr Paul E. McKenney
2022-05-16 11:49   ` Frederic Weisbecker
2022-05-16 13:39     ` Paul E. McKenney
2022-05-17 10:13     ` Jiri Olsa
2022-05-18 16:21       ` Paul E. McKenney
2022-05-19 11:33         ` Jiri Olsa [this message]
2022-05-19 13:54           ` Paul E. McKenney
2022-05-23 13:12             ` Jiri Olsa
2022-05-24 17:33               ` Paul E. McKenney
2022-05-17  2:39 ` kernel test robot
2022-05-17  2:54 ` Yonghong Song
2022-05-17  7:49   ` Jiri Olsa
2022-05-19  0:00     ` Masami Hiramatsu
2022-05-17  9:19 ` kernel test robot
2023-05-20  9:47 ` Ze Gao
2023-05-21  3:58   ` Yonghong Song
2023-05-21 15:10     ` Re: Ze Gao
2023-05-21 20:26       ` Re: Jiri Olsa
2023-05-22  1:36         ` Re: Masami Hiramatsu
2023-05-22  2:07         ` Re: Ze Gao
2023-05-23  4:38           ` Re: Yonghong Song
2023-05-23  5:30           ` Re: Masami Hiramatsu
2023-05-23  6:59             ` Re: Paul E. McKenney
2023-05-25  0:13               ` Re: Masami Hiramatsu
2023-05-23 14:10           ` kprobes and rcu_is_watching() Steven Rostedt
2023-05-24  3:51             ` Ze Gao
2023-05-21  8:08   ` Jiri Olsa
2023-05-21 10:09     ` Re: Masami Hiramatsu
2023-05-21 14:19       ` Re: Ze Gao

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=YoYq/M6ZSQ+U2sar@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=frederic@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.