public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tracing: fix invalid function_graph entry
@ 2009-07-28 12:11 Lai Jiangshan
  2009-07-28 15:33 ` Frederic Weisbecker
  2009-08-04 12:12 ` [tip:tracing/urgent] tracing: Fix " tip-bot for Lai Jiangshan
  0 siblings, 2 replies; 3+ messages in thread
From: Lai Jiangshan @ 2009-07-28 12:11 UTC (permalink / raw)
  To: Frederic Weisbecker, Steven Rostedt, Ingo Molnar, LKML


print_graph_entry() consumes current event, if this event
is the last event in the page, the ring_buffer may reuse
the page. It will become invalid.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
index abf7c4a..02102a3 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -835,9 +835,16 @@ print_graph_function(struct trace_iterator *iter)
 
 	switch (entry->type) {
 	case TRACE_GRAPH_ENT: {
-		struct ftrace_graph_ent_entry *field;
+		/*
+		 * print_graph_entry() may consume the current event,
+		 * thus @field may become invalid, so we need to save it.
+		 * sizeof(struct ftrace_graph_ent_entry) is very small,
+		 * it is safely saved at the stack.
+		 */
+		struct ftrace_graph_ent_entry *field, saved;
 		trace_assign_type(field, entry);
-		return print_graph_entry(field, s, iter);
+		saved = *field;
+		return print_graph_entry(&saved, s, iter);
 	}
 	case TRACE_GRAPH_RET: {
 		struct ftrace_graph_ret_entry *field;


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tracing: fix invalid function_graph entry
  2009-07-28 12:11 [PATCH] tracing: fix invalid function_graph entry Lai Jiangshan
@ 2009-07-28 15:33 ` Frederic Weisbecker
  2009-08-04 12:12 ` [tip:tracing/urgent] tracing: Fix " tip-bot for Lai Jiangshan
  1 sibling, 0 replies; 3+ messages in thread
From: Frederic Weisbecker @ 2009-07-28 15:33 UTC (permalink / raw)
  To: Lai Jiangshan; +Cc: Steven Rostedt, Ingo Molnar, LKML

On Tue, Jul 28, 2009 at 08:11:24PM +0800, Lai Jiangshan wrote:
> 
> print_graph_entry() consumes current event, if this event
> is the last event in the page, the ring_buffer may reuse
> the page. It will become invalid.
> 
> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
> ---


Queued for .31, thanks Lai!


> diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
> index abf7c4a..02102a3 100644
> --- a/kernel/trace/trace_functions_graph.c
> +++ b/kernel/trace/trace_functions_graph.c
> @@ -835,9 +835,16 @@ print_graph_function(struct trace_iterator *iter)
>  
>  	switch (entry->type) {
>  	case TRACE_GRAPH_ENT: {
> -		struct ftrace_graph_ent_entry *field;
> +		/*
> +		 * print_graph_entry() may consume the current event,
> +		 * thus @field may become invalid, so we need to save it.
> +		 * sizeof(struct ftrace_graph_ent_entry) is very small,
> +		 * it is safely saved at the stack.
> +		 */
> +		struct ftrace_graph_ent_entry *field, saved;
>  		trace_assign_type(field, entry);
> -		return print_graph_entry(field, s, iter);
> +		saved = *field;
> +		return print_graph_entry(&saved, s, iter);
>  	}
>  	case TRACE_GRAPH_RET: {
>  		struct ftrace_graph_ret_entry *field;
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:tracing/urgent] tracing: Fix invalid function_graph entry
  2009-07-28 12:11 [PATCH] tracing: fix invalid function_graph entry Lai Jiangshan
  2009-07-28 15:33 ` Frederic Weisbecker
@ 2009-08-04 12:12 ` tip-bot for Lai Jiangshan
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Lai Jiangshan @ 2009-08-04 12:12 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, fweisbec, rostedt, tglx, laijs

Commit-ID:  38ceb592fcac9110c6b3c87ea0a27bff68c43486
Gitweb:     http://git.kernel.org/tip/38ceb592fcac9110c6b3c87ea0a27bff68c43486
Author:     Lai Jiangshan <laijs@cn.fujitsu.com>
AuthorDate: Tue, 28 Jul 2009 20:11:24 +0800
Committer:  Frederic Weisbecker <fweisbec@gmail.com>
CommitDate: Tue, 28 Jul 2009 23:17:23 +0200

tracing: Fix invalid function_graph entry

When print_graph_entry() computes a function call entry event, it needs
to also check the next entry to guess if it matches the return event of
the current function entry.
In order to look at this next event, it needs to consume the current
entry before going ahead in the ring buffer.

However, if the current event that gets consumed is the last one in the
ring buffer head page, the ring_buffer may reuse the page for writers.
The consumed entry will then become invalid because of possible
racy overwriting.

Me must then handle this entry by making a copy of it.

The fix also applies on 2.6.30

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: stable@kernel.org
LKML-Reference: <4A6EEAEC.3050508@cn.fujitsu.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>


---
 kernel/trace/trace_functions_graph.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
index d2249ab..420ec34 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -843,9 +843,16 @@ print_graph_function(struct trace_iterator *iter)
 
 	switch (entry->type) {
 	case TRACE_GRAPH_ENT: {
-		struct ftrace_graph_ent_entry *field;
+		/*
+		 * print_graph_entry() may consume the current event,
+		 * thus @field may become invalid, so we need to save it.
+		 * sizeof(struct ftrace_graph_ent_entry) is very small,
+		 * it can be safely saved at the stack.
+		 */
+		struct ftrace_graph_ent_entry *field, saved;
 		trace_assign_type(field, entry);
-		return print_graph_entry(field, s, iter);
+		saved = *field;
+		return print_graph_entry(&saved, s, iter);
 	}
 	case TRACE_GRAPH_RET: {
 		struct ftrace_graph_ret_entry *field;

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-08-04 12:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-28 12:11 [PATCH] tracing: fix invalid function_graph entry Lai Jiangshan
2009-07-28 15:33 ` Frederic Weisbecker
2009-08-04 12:12 ` [tip:tracing/urgent] tracing: Fix " tip-bot for Lai Jiangshan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox