aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace.c
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-03-12 19:56:00 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2010-04-01 19:01:17 -0400
commit8c3492dc6b9ee58b025ffddc83431c5a5d466282 (patch)
tree352e42e3a7e064423b3abc0e1c2279e0cef063bd /kernel/trace/trace.c
parent70e27dedd11fdbb3a9dec79af59d8ba61a19365b (diff)
tracing: Disable buffer switching when starting or stopping trace
commit a2f8071428ed9a0f06865f417c962421c9a6b488 upstream. When the trace iterator is read, tracing_start() and tracing_stop() is called to stop tracing while the iterator is processing the trace output. These functions disable both the standard buffer and the max latency buffer. But if the wakeup tracer is running, it can switch these buffers between the two disables: buffer = global_trace.buffer; if (buffer) ring_buffer_record_disable(buffer); <<<--------- swap happens here buffer = max_tr.buffer; if (buffer) ring_buffer_record_disable(buffer); What happens is that we disabled the same buffer twice. On tracing_start() we can enable the same buffer twice. All ring_buffer_record_disable() must be matched with a ring_buffer_record_enable() or the buffer can be disable permanently, or enable prematurely, and cause a bug where a reset happens while a trace is commiting. This patch protects these two by taking the ftrace_max_lock to prevent a switch from occurring. Found with Li Zefan's ftrace_stress_test. Reported-by: Lai Jiangshan <laijs@cn.fujitsu.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r--kernel/trace/trace.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 95c944a0b1e1..f65708136a28 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -857,6 +857,8 @@ void tracing_start(void)
857 goto out; 857 goto out;
858 } 858 }
859 859
860 /* Prevent the buffers from switching */
861 arch_spin_lock(&ftrace_max_lock);
860 862
861 buffer = global_trace.buffer; 863 buffer = global_trace.buffer;
862 if (buffer) 864 if (buffer)
@@ -866,6 +868,8 @@ void tracing_start(void)
866 if (buffer) 868 if (buffer)
867 ring_buffer_record_enable(buffer); 869 ring_buffer_record_enable(buffer);
868 870
871 arch_spin_unlock(&ftrace_max_lock);
872
869 ftrace_start(); 873 ftrace_start();
870 out: 874 out:
871 spin_unlock_irqrestore(&tracing_start_lock, flags); 875 spin_unlock_irqrestore(&tracing_start_lock, flags);
@@ -887,6 +891,9 @@ void tracing_stop(void)
887 if (trace_stop_count++) 891 if (trace_stop_count++)
888 goto out; 892 goto out;
889 893
894 /* Prevent the buffers from switching */
895 arch_spin_lock(&ftrace_max_lock);
896
890 buffer = global_trace.buffer; 897 buffer = global_trace.buffer;
891 if (buffer) 898 if (buffer)
892 ring_buffer_record_disable(buffer); 899 ring_buffer_record_disable(buffer);
@@ -895,6 +902,8 @@ void tracing_stop(void)
895 if (buffer) 902 if (buffer)
896 ring_buffer_record_disable(buffer); 903 ring_buffer_record_disable(buffer);
897 904
905 arch_spin_unlock(&ftrace_max_lock);
906
898 out: 907 out:
899 spin_unlock_irqrestore(&tracing_start_lock, flags); 908 spin_unlock_irqrestore(&tracing_start_lock, flags);
900} 909}