Skip to contentSkip to conversation

tracing: move static old_tracer to trace_iterator

PATCH In review Lai Jiangshan 2 participants 2 messages Jan 26, 2010 – Jan 30, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing: move static old_tracer to trace_iterator

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.

---

include/linux/ftrace_event.h +1 -0
index 3ca9485..925897e 100644
@@ -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;
kernel/trace/trace.c +6 -9
index 5314c90..bbb2229 100644
@@ -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);
#1 lore raw
Quoted 11 lines · Lai Jiangshan

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.

We should actually get rid of old_tracer and have iter->trace to be a pointer so that the check can be summarized with

if (iter->trace != current_trace)

I don't exactly recall why we've made iter->trace a copy of the current_trace. I remember I did it this uglyness, but I don't remember exactly why. Probably for bad reasons that should be fixed another way.

Ok, having a deeper look, I think it was because some tracers implement callbacks whereas others may not, so the simple:

if (iter->trace->splice_read)

	ret = iter->trace->splice_read(...)

would be racy if we weren't copying current_trace.

To fix this, I would rather try to ensure every tracers have stub callbacks for those unimplemented. This is going to be much proper than this dance between current_tracer, old_tracer and iter->trace.

What do you think?