aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace_events.c
diff options
context:
space:
mode:
authorLi Zefan <lizf@cn.fujitsu.com>2009-05-05 22:33:45 -0400
committerIngo Molnar <mingo@elte.hu>2009-05-06 04:38:19 -0400
commit20c8928abe70e204bd077ab6cfe23002d7788983 (patch)
treee161656f99c814ebdd69df8b5a79dab58f80065e /kernel/trace/trace_events.c
parent2df75e415709ad12862028916c772c1f377f6a7c (diff)
tracing/events: fix concurrent access to ftrace_events list
A module will add/remove its trace events when it gets loaded/unloaded, so the ftrace_events list is not "const", and concurrent access needs to be protected. This patch thus fixes races between loading/unloding modules and read 'available_events' or read/write 'set_event', etc. Below shows how to reproduce the race: # for ((; ;)) { cat /mnt/tracing/available_events; } > /dev/null & # for ((; ;)) { insmod trace-events-sample.ko; rmmod sample; } & After a while: BUG: unable to handle kernel paging request at 0010011c IP: [<c1080f27>] t_next+0x1b/0x2d ... Call Trace: [<c10c90e6>] ? seq_read+0x217/0x30d [<c10c8ecf>] ? seq_read+0x0/0x30d [<c10b4c19>] ? vfs_read+0x8f/0x136 [<c10b4fc3>] ? sys_read+0x40/0x65 [<c1002a68>] ? sysenter_do_call+0x12/0x36 [ Impact: fix races when concurrent accessing ftrace_events list ] Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Acked-by: Steven Rostedt <rostedt@goodmis.org> Acked-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Tom Zanussi <tzanussi@gmail.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> LKML-Reference: <4A00F709.3080800@cn.fujitsu.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/trace/trace_events.c')
-rw-r--r--kernel/trace/trace_events.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index f251a150e75e..8d579ff23610 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -21,7 +21,7 @@
21 21
22#define TRACE_SYSTEM "TRACE_SYSTEM" 22#define TRACE_SYSTEM "TRACE_SYSTEM"
23 23
24static DEFINE_MUTEX(event_mutex); 24DEFINE_MUTEX(event_mutex);
25 25
26LIST_HEAD(ftrace_events); 26LIST_HEAD(ftrace_events);
27 27
@@ -80,6 +80,7 @@ static void ftrace_clear_events(void)
80{ 80{
81 struct ftrace_event_call *call; 81 struct ftrace_event_call *call;
82 82
83 mutex_lock(&event_mutex);
83 list_for_each_entry(call, &ftrace_events, list) { 84 list_for_each_entry(call, &ftrace_events, list) {
84 85
85 if (call->enabled) { 86 if (call->enabled) {
@@ -87,6 +88,7 @@ static void ftrace_clear_events(void)
87 call->unregfunc(); 88 call->unregfunc();
88 } 89 }
89 } 90 }
91 mutex_unlock(&event_mutex);
90} 92}
91 93
92static void ftrace_event_enable_disable(struct ftrace_event_call *call, 94static void ftrace_event_enable_disable(struct ftrace_event_call *call,
@@ -274,6 +276,9 @@ t_next(struct seq_file *m, void *v, loff_t *pos)
274 276
275static void *t_start(struct seq_file *m, loff_t *pos) 277static void *t_start(struct seq_file *m, loff_t *pos)
276{ 278{
279 mutex_lock(&event_mutex);
280 if (*pos == 0)
281 m->private = ftrace_events.next;
277 return t_next(m, NULL, pos); 282 return t_next(m, NULL, pos);
278} 283}
279 284
@@ -303,6 +308,9 @@ s_next(struct seq_file *m, void *v, loff_t *pos)
303 308
304static void *s_start(struct seq_file *m, loff_t *pos) 309static void *s_start(struct seq_file *m, loff_t *pos)
305{ 310{
311 mutex_lock(&event_mutex);
312 if (*pos == 0)
313 m->private = ftrace_events.next;
306 return s_next(m, NULL, pos); 314 return s_next(m, NULL, pos);
307} 315}
308 316
@@ -319,12 +327,12 @@ static int t_show(struct seq_file *m, void *v)
319 327
320static void t_stop(struct seq_file *m, void *p) 328static void t_stop(struct seq_file *m, void *p)
321{ 329{
330 mutex_unlock(&event_mutex);
322} 331}
323 332
324static int 333static int
325ftrace_event_seq_open(struct inode *inode, struct file *file) 334ftrace_event_seq_open(struct inode *inode, struct file *file)
326{ 335{
327 int ret;
328 const struct seq_operations *seq_ops; 336 const struct seq_operations *seq_ops;
329 337
330 if ((file->f_mode & FMODE_WRITE) && 338 if ((file->f_mode & FMODE_WRITE) &&
@@ -332,13 +340,7 @@ ftrace_event_seq_open(struct inode *inode, struct file *file)
332 ftrace_clear_events(); 340 ftrace_clear_events();
333 341
334 seq_ops = inode->i_private; 342 seq_ops = inode->i_private;
335 ret = seq_open(file, seq_ops); 343 return seq_open(file, seq_ops);
336 if (!ret) {
337 struct seq_file *m = file->private_data;
338
339 m->private = ftrace_events.next;
340 }
341 return ret;
342} 344}
343 345
344static ssize_t 346static ssize_t