All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>, Ingo Molnar <mingo@elte.hu>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] tracing: move static old_tracer to trace_iterator
Date: Tue, 26 Jan 2010 15:28:13 +0800	[thread overview]
Message-ID: <4B5E998D.9070603@cn.fujitsu.com> (raw)


static old_tracer is global for all processes.

So there is a potential bug when:
current_trace and static old_tracer are changed by other processes,
current_trace and static old_tracer are match with each other.
but *iter->trace and *current_trace are not match.

This patch move old_tracer to trace_iterator, and make it not global.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index 3ca9485..925897e 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -47,6 +47,7 @@ struct trace_entry {
  */
 struct trace_iterator {
 	struct trace_array	*tr;
+	struct tracer		*old_tracer;
 	struct tracer		*trace;
 	void			*private;
 	int			cpu_file;
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 5314c90..bbb2229 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1667,7 +1667,6 @@ static void tracing_iter_reset(struct trace_iterator *iter, int cpu)
 static void *s_start(struct seq_file *m, loff_t *pos)
 {
 	struct trace_iterator *iter = m->private;
-	static struct tracer *old_tracer;
 	int cpu_file = iter->cpu_file;
 	void *p = NULL;
 	loff_t l = 0;
@@ -1675,8 +1674,8 @@ static void *s_start(struct seq_file *m, loff_t *pos)
 
 	/* copy the tracer to avoid using a global lock all around */
 	mutex_lock(&trace_types_lock);
-	if (unlikely(old_tracer != current_trace && current_trace)) {
-		old_tracer = current_trace;
+	if (unlikely(iter->old_tracer != current_trace && current_trace)) {
+		iter->old_tracer = current_trace;
 		*iter->trace = *current_trace;
 	}
 	mutex_unlock(&trace_types_lock);
@@ -3080,7 +3079,6 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
 		  size_t cnt, loff_t *ppos)
 {
 	struct trace_iterator *iter = filp->private_data;
-	static struct tracer *old_tracer;
 	ssize_t sret;
 
 	/* return any leftover data */
@@ -3092,8 +3090,8 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
 
 	/* copy the tracer to avoid using a global lock all around */
 	mutex_lock(&trace_types_lock);
-	if (unlikely(old_tracer != current_trace && current_trace)) {
-		old_tracer = current_trace;
+	if (unlikely(iter->old_tracer != current_trace && current_trace)) {
+		iter->old_tracer = current_trace;
 		*iter->trace = *current_trace;
 	}
 	mutex_unlock(&trace_types_lock);
@@ -3242,15 +3240,14 @@ static ssize_t tracing_splice_read_pipe(struct file *filp,
 		.ops		= &tracing_pipe_buf_ops,
 		.spd_release	= tracing_spd_release_pipe,
 	};
-	static struct tracer *old_tracer;
 	ssize_t ret;
 	size_t rem;
 	unsigned int i;
 
 	/* copy the tracer to avoid using a global lock all around */
 	mutex_lock(&trace_types_lock);
-	if (unlikely(old_tracer != current_trace && current_trace)) {
-		old_tracer = current_trace;
+	if (unlikely(iter->old_tracer != current_trace && current_trace)) {
+		iter->old_tracer = current_trace;
 		*iter->trace = *current_trace;
 	}
 	mutex_unlock(&trace_types_lock);


             reply	other threads:[~2010-01-26  7:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-26  7:28 Lai Jiangshan [this message]
2010-01-30 22:47 ` [PATCH] tracing: move static old_tracer to trace_iterator Frederic Weisbecker

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=4B5E998D.9070603@cn.fujitsu.com \
    --to=laijs@cn.fujitsu.com \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --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 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.