From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Jiri Olsa <jolsa@redhat.com>
Subject: Re: [RFC][PATCH 01/18 v2] ftrace: Add hash list to save RCU unsafe functions
Date: Tue, 3 Sep 2013 18:24:04 -0700 [thread overview]
Message-ID: <20130904012404.GI3871@linux.vnet.ibm.com> (raw)
In-Reply-To: <20130903195705.3ba3442f@gandalf.local.home>
On Tue, Sep 03, 2013 at 07:57:05PM -0400, Steven Rostedt wrote:
> On Tue, 3 Sep 2013 15:18:08 -0700
> "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> wrote:
>
>
> > > Just found this bug. Strange that gcc never gave me a warning :-/
> >
> > I can't give gcc too much trouble, as I also didn't give you an
> > uninitialized-variable warning.
>
> I was also chasing down a nasty bug that looked to be a pointer
> corruption somewhere. Still never found exactly where it happened, but
> it always happened with the following conditions:
>
> synchronize_sched() was in progress
>
> The ftrace_unsafe_callback() was preempted by an interrupt
>
> lockdep was processing a lock
>
>
> A crash would happen which had memory corruption involved. But the
> above seemed always to be in play.
>
> Now, I changed the logic from disabling context level recursion to
> disabling recursion at all. That is, the original code had used a
> series of bits to test for recursion (via helper functions) that would
> allow for the callback to be preempted by an interrupt, and then be
> called again.
>
> The new code sets a per_cpu flag, and will not allow the callback to
> recurse if it were preempted by an interrupt. No real need to allow for
> that anyway.
>
> I can go and debug this further, because I'm nervous that lockdep may
> have some kind of bug that the function tracer can trigger. But I'm not
> too concerned about it.
>
> Here's the diff of the new code against the previous code.
>
> Paul, can I still keep all your acks and reviewed-bys on this?
Yep, but some questions below.
Thanx, Paul
> -- Steve
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 310b727..899c8c1 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -1373,7 +1373,7 @@ ftrace_hash_rec_enable(struct ftrace_ops *ops, int filter_hash);
>
> static int ftrace_convert_size_to_bits(int size)
> {
> - int bits;
> + int bits = 0;
>
> /*
> * Make the hash size about 1/2 the # found
> diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
> index f5a9031..0883069 100644
> --- a/kernel/trace/trace_functions.c
> +++ b/kernel/trace/trace_functions.c
> @@ -561,16 +561,21 @@ static inline int init_func_cmd_traceon(void)
>
> #ifdef CONFIG_FTRACE_UNSAFE_RCU_CHECKER
>
> +static DEFINE_PER_CPU(int, ftrace_rcu_running);
> static atomic_t ftrace_unsafe_rcu_disabled;
>
> void ftrace_unsafe_rcu_checker_disable(void)
> {
> atomic_inc(&ftrace_unsafe_rcu_disabled);
> + /* Make sure the update is seen immediately */
> + smp_wmb();
smp_mb__after_atomic_inc()?
> }
>
> void ftrace_unsafe_rcu_checker_enable(void)
> {
> atomic_dec(&ftrace_unsafe_rcu_disabled);
> + /* Make sure the update is seen immediately */
> + smp_wmb();
smp_mb__after_atomic_dec()?
> }
>
> static DEFINE_PER_CPU(unsigned long, ftrace_rcu_func);
> @@ -588,15 +593,14 @@ static void
> ftrace_unsafe_callback(unsigned long ip, unsigned long parent_ip,
> struct ftrace_ops *op, struct pt_regs *pt_regs)
> {
> - int bit;
> -
> + /* Make sure we see disabled or not first */
> + smp_rmb();
smp_mb__before_atomic_inc()?
> if (atomic_read(&ftrace_unsafe_rcu_disabled))
> return;
>
> preempt_disable_notrace();
>
> - bit = trace_test_and_set_recursion(TRACE_FTRACE_START, TRACE_FTRACE_MAX);
> - if (bit < 0)
> + if (this_cpu_read(ftrace_rcu_running))
> goto out;
>
> if (WARN_ONCE(ftrace_rcu_unsafe(ip),
> @@ -604,13 +608,15 @@ ftrace_unsafe_callback(unsigned long ip, unsigned long parent_ip,
> (void *)ip))
> goto out;
>
> + this_cpu_write(ftrace_rcu_running, 1);
> this_cpu_write(ftrace_rcu_func, ip);
> +
> /* Should trigger a RCU splat if called from unsafe RCU function */
> rcu_read_lock();
> rcu_read_unlock();
> this_cpu_write(ftrace_rcu_func, 0);
>
> - trace_clear_recursion(bit);
> + this_cpu_write(ftrace_rcu_running, 0);
> out:
> preempt_enable_notrace();
> }
>
next prev parent reply other threads:[~2013-09-04 1:24 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-31 5:11 [RFC][PATCH 00/18 v2] ftrace/rcu: Handle unsafe RCU functions and ftrace callbacks Steven Rostedt
2013-08-31 5:11 ` [RFC][PATCH 01/18 v2] ftrace: Add hash list to save RCU unsafe functions Steven Rostedt
2013-08-31 19:28 ` Paul E. McKenney
2013-09-03 21:15 ` Steven Rostedt
2013-09-03 22:18 ` Paul E. McKenney
2013-09-03 23:57 ` Steven Rostedt
2013-09-04 0:18 ` Steven Rostedt
2013-09-04 1:11 ` [RFC][PATCH 19/18] ftrace: Print a message when the rcu checker is disabled Steven Rostedt
2013-09-04 1:25 ` Paul E. McKenney
2013-09-04 1:24 ` Paul E. McKenney [this message]
2013-09-04 1:51 ` [RFC][PATCH 01/18 v2] ftrace: Add hash list to save RCU unsafe functions Steven Rostedt
2013-09-04 1:56 ` Steven Rostedt
2013-09-04 2:01 ` Steven Rostedt
2013-09-04 2:03 ` Steven Rostedt
2013-09-04 4:18 ` Paul E. McKenney
2013-09-04 11:50 ` Steven Rostedt
2013-09-04 4:12 ` Paul E. McKenney
2013-08-31 5:11 ` [RFC][PATCH 02/18 v2] ftrace: Do not set ftrace records for unsafe RCU when not allowed Steven Rostedt
2013-08-31 19:29 ` Paul E. McKenney
2013-08-31 5:11 ` [RFC][PATCH 03/18 v2] ftrace: Set ftrace internal function tracing RCU safe Steven Rostedt
2013-08-31 19:30 ` Paul E. McKenney
2013-08-31 19:44 ` Paul E. McKenney
2013-09-03 13:22 ` Steven Rostedt
2013-09-03 13:54 ` Paul E. McKenney
2013-08-31 5:11 ` [RFC][PATCH 04/18 v2] ftrace: Add test for ops against unsafe RCU functions in callback Steven Rostedt
2013-08-31 19:45 ` Paul E. McKenney
2013-08-31 5:11 ` [RFC][PATCH 05/18 v2] ftrace: Do not display non safe RCU functions in available_filter_functions Steven Rostedt
2013-08-31 19:46 ` Paul E. McKenney
2013-08-31 20:35 ` Steven Rostedt
2013-08-31 20:54 ` Paul E. McKenney
2013-09-03 13:26 ` Steven Rostedt
2013-09-03 13:54 ` Paul E. McKenney
2013-08-31 5:11 ` [RFC][PATCH 06/18 v2] ftrace: Add rcu_unsafe_filter_functions file Steven Rostedt
2013-08-31 19:46 ` Paul E. McKenney
2013-08-31 5:11 ` [RFC][PATCH 07/18 v2] ftrace: Add selftest to check if RCU unsafe functions are filtered properly Steven Rostedt
2013-08-31 19:47 ` Paul E. McKenney
2013-08-31 5:11 ` [RFC][PATCH 08/18 v2] ftrace/rcu: Do not trace debug_lockdep_rcu_enabled() Steven Rostedt
2013-08-31 19:21 ` Paul E. McKenney
2013-08-31 20:31 ` Steven Rostedt
2013-08-31 5:11 ` [RFC][PATCH 09/18 v2] ftrace: Fix a slight race in modifying what function callback gets traced Steven Rostedt
2013-08-31 5:11 ` [RFC][PATCH 10/18 v2] ftrace: Create a RCU unsafe checker Steven Rostedt
2013-08-31 19:49 ` Paul E. McKenney
2013-08-31 5:11 ` [RFC][PATCH 11/18 v2] ftrace: Adde infrastructure to stop RCU unsafe checker from checking Steven Rostedt
2013-08-31 19:52 ` Paul E. McKenney
2013-08-31 20:40 ` Steven Rostedt
2013-09-03 13:43 ` Steven Rostedt
2013-09-03 15:22 ` Paul E. McKenney
2013-08-31 5:11 ` [RFC][PATCH 12/18 v2] ftrace: Disable RCU unsafe checker when function graph is enabled Steven Rostedt
2013-08-31 19:55 ` Paul E. McKenney
2013-08-31 20:42 ` Steven Rostedt
2013-08-31 20:58 ` Paul E. McKenney
2013-08-31 5:11 ` [RFC][PATCH 13/18 v2] ftrace: Disable the RCU unsafe checker when irqsoff " Steven Rostedt
2013-08-31 19:58 ` Paul E. McKenney
2013-08-31 5:11 ` [RFC][PATCH 14/18 v2] ftrace/lockdep: Have the RCU lockdep splat show what function triggered Steven Rostedt
2013-08-31 19:59 ` Paul E. McKenney
2013-09-05 19:18 ` Peter Zijlstra
2013-09-05 19:52 ` Steven Rostedt
2013-09-06 12:57 ` Ingo Molnar
2013-09-06 13:16 ` Steven Rostedt
2013-09-05 19:35 ` Peter Zijlstra
2013-09-05 20:27 ` Steven Rostedt
2013-08-31 5:11 ` [RFC][PATCH 15/18 v2] ftrace/rcu: Mark functions that are RCU unsafe Steven Rostedt
2013-08-31 20:00 ` Paul E. McKenney
2013-08-31 20:43 ` Steven Rostedt
2013-08-31 20:54 ` Paul E. McKenney
2013-08-31 5:11 ` [RFC][PATCH 16/18 v2] rcu/irq/x86: " Steven Rostedt
2013-08-31 20:01 ` Paul E. McKenney
2013-08-31 5:11 ` [RFC][PATCH 17/18 v2] ftrace/cpuidle/x86: " Steven Rostedt
2013-08-31 11:07 ` Wysocki, Rafael J
2013-08-31 20:02 ` Paul E. McKenney
2013-09-04 0:16 ` H. Peter Anvin
2013-08-31 5:11 ` [RFC][PATCH 18/18 v2] ftrace/sched: " Steven Rostedt
2013-08-31 20:01 ` Paul E. McKenney
2013-08-31 15:50 ` [RFC][PATCH 00/18 v2] ftrace/rcu: Handle unsafe RCU functions and ftrace callbacks 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=20130904012404.GI3871@linux.vnet.ibm.com \
--to=paulmck@linux.vnet.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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