Re: [PATCH] tracing: Protect the buffer from recursion in perf

From: Masami Hiramatsu
Date: Wed Nov 04 2009 - 22:07:56 EST


Frederic Weisbecker wrote:
> While tracing using events with perf, if one enables the
> lockdep:lock_acquire event, it will infect every other perf trace
> events.
>
> Basically, you can enable whatever set of trace events through perf
> but if this event is part of the set, the only result we can get is a
> long list of lock_acquire events of rcu read lock, and only that.
>
> This is because of a recursion inside perf.
>
> 1) When a trace event is triggered, it will fill a per cpu buffer and
> submit it to perf.
> 2) Perf will commit this event but will also protect some data using
> rcu_read_lock
> 3) A recursion appears: rcu_read_lock triggers a lock_acquire event that
> will fill the per cpu event and then submit the buffer to perf.
> 4) Perf detects a recursion and ignore it
> 5) Perf continue its work on the previous event, but its buffer has been
> overwritten by the lock_acquire event, it has then been turned into
> a lock_acquire event of rcu read lock
>
> Such scenario also happens with lock_release with rcu_read_unlock().
>
> We could turn the rcu_read_lock() into __rcu_read_lock() to drop the
> lock debugging from perf fast path, but that would make us lose
> the rcu debugging and that doesn't prevent from other possible kind of
> recursion from perf in the future.
>
> This patch adds a recursion protection on the perf trace per cpu
> buffers to solve the problem.

OK, so you added a counter to find recursion.
I found a style issue, see below.

> diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
> index a7f9460..d80928d 100644
> --- a/include/trace/ftrace.h
> +++ b/include/trace/ftrace.h
> @@ -649,6 +649,7 @@ __attribute__((section("_ftrace_events"))) event_##call = { \
> * struct ftrace_event_call *event_call =&event_<call>;
> * extern void perf_tp_event(int, u64, u64, void *, int);
> * struct ftrace_raw_##call *entry;
> +* struct perf_trace_buf *trace_buf;
^^ Here, we need a space :-)

Others looks good to me, Thanks!

Reviewed-by: Masami Hiramatsu <mhiramat@xxxxxxxxxx>


--
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@xxxxxxxxxx

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/