aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2009-06-09 17:29:07 -0400
committerSteven Rostedt <rostedt@goodmis.org>2009-06-09 17:29:07 -0400
commit110bf2b764eb6026b868d84499263cb24b1bcc8d (patch)
tree66c869f6f96497051c4bda0797e234b3f7b39e8f /kernel/trace
parent725c624a58a10ef90a2ff889e122158fabf36147 (diff)
tracing: add protection around module events unload
When reading the trace buffer, there is a race that when a module is unloaded it removes events that is stilled referenced in the buffers. This patch adds the protection around the unloading of the events from modules and the reading of the trace buffers. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace')
-rw-r--r--kernel/trace/trace_events.c4
-rw-r--r--kernel/trace/trace_output.c15
-rw-r--r--kernel/trace/trace_output.h4
3 files changed, 19 insertions, 4 deletions
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 6c81f9c21426..aa08be69a1b6 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1050,12 +1050,13 @@ static void trace_module_remove_events(struct module *mod)
1050 struct ftrace_event_call *call, *p; 1050 struct ftrace_event_call *call, *p;
1051 bool found = false; 1051 bool found = false;
1052 1052
1053 down_write(&trace_event_mutex);
1053 list_for_each_entry_safe(call, p, &ftrace_events, list) { 1054 list_for_each_entry_safe(call, p, &ftrace_events, list) {
1054 if (call->mod == mod) { 1055 if (call->mod == mod) {
1055 found = true; 1056 found = true;
1056 ftrace_event_enable_disable(call, 0); 1057 ftrace_event_enable_disable(call, 0);
1057 if (call->event) 1058 if (call->event)
1058 unregister_ftrace_event(call->event); 1059 __unregister_ftrace_event(call->event);
1059 debugfs_remove_recursive(call->dir); 1060 debugfs_remove_recursive(call->dir);
1060 list_del(&call->list); 1061 list_del(&call->list);
1061 trace_destroy_fields(call); 1062 trace_destroy_fields(call);
@@ -1079,6 +1080,7 @@ static void trace_module_remove_events(struct module *mod)
1079 */ 1080 */
1080 if (found) 1081 if (found)
1081 tracing_reset_current_online_cpus(); 1082 tracing_reset_current_online_cpus();
1083 up_write(&trace_event_mutex);
1082} 1084}
1083 1085
1084static int trace_module_notify(struct notifier_block *self, 1086static int trace_module_notify(struct notifier_block *self,
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index c05aff465dc9..7938f3ae93e3 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -14,7 +14,7 @@
14/* must be a power of 2 */ 14/* must be a power of 2 */
15#define EVENT_HASHSIZE 128 15#define EVENT_HASHSIZE 128
16 16
17static DECLARE_RWSEM(trace_event_mutex); 17DECLARE_RWSEM(trace_event_mutex);
18 18
19DEFINE_PER_CPU(struct trace_seq, ftrace_event_seq); 19DEFINE_PER_CPU(struct trace_seq, ftrace_event_seq);
20EXPORT_PER_CPU_SYMBOL(ftrace_event_seq); 20EXPORT_PER_CPU_SYMBOL(ftrace_event_seq);
@@ -702,6 +702,16 @@ int register_ftrace_event(struct trace_event *event)
702} 702}
703EXPORT_SYMBOL_GPL(register_ftrace_event); 703EXPORT_SYMBOL_GPL(register_ftrace_event);
704 704
705/*
706 * Used by module code with the trace_event_mutex held for write.
707 */
708int __unregister_ftrace_event(struct trace_event *event)
709{
710 hlist_del(&event->node);
711 list_del(&event->list);
712 return 0;
713}
714
705/** 715/**
706 * unregister_ftrace_event - remove a no longer used event 716 * unregister_ftrace_event - remove a no longer used event
707 * @event: the event to remove 717 * @event: the event to remove
@@ -709,8 +719,7 @@ EXPORT_SYMBOL_GPL(register_ftrace_event);
709int unregister_ftrace_event(struct trace_event *event) 719int unregister_ftrace_event(struct trace_event *event)
710{ 720{
711 down_write(&trace_event_mutex); 721 down_write(&trace_event_mutex);
712 hlist_del(&event->node); 722 __unregister_ftrace_event(event);
713 list_del(&event->list);
714 up_write(&trace_event_mutex); 723 up_write(&trace_event_mutex);
715 724
716 return 0; 725 return 0;
diff --git a/kernel/trace/trace_output.h b/kernel/trace/trace_output.h
index ac240e76eb01..d38bec4a9c30 100644
--- a/kernel/trace/trace_output.h
+++ b/kernel/trace/trace_output.h
@@ -27,6 +27,10 @@ extern struct trace_event *ftrace_find_event(int type);
27extern enum print_line_t trace_nop_print(struct trace_iterator *iter, 27extern enum print_line_t trace_nop_print(struct trace_iterator *iter,
28 int flags); 28 int flags);
29 29
30/* used by module unregistering */
31extern int __unregister_ftrace_event(struct trace_event *event);
32extern struct rw_semaphore trace_event_mutex;
33
30#define MAX_MEMHEX_BYTES 8 34#define MAX_MEMHEX_BYTES 8
31#define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1) 35#define HEX_CHARS (MAX_MEMHEX_BYTES*2 + 1)
32 36