diff options
author | Peter Zijlstra <a.p.zijlstra@chello.nl> | 2010-05-21 06:31:09 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-05-31 02:46:09 -0400 |
commit | 3771f0771154675d4a0ca780be2411f3cc357208 (patch) | |
tree | 106512f307e2aa0a89f92c01598d5fa75903af47 /kernel | |
parent | 8a49542c0554af7d0073aac0ee73ee65b807ef34 (diff) |
perf_events, trace: Fix probe unregister race
tracepoint_probe_unregister() does not synchronize against the probe
callbacks, so do that explicitly. This properly serializes the callbacks
and the free of the data used therein.
Also, use this_cpu_ptr() where possible.
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <1274438476.1674.1702.camel@laptop>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/trace/trace_event_perf.c | 10 | ||||
-rw-r--r-- | kernel/trace/trace_kprobe.c | 4 | ||||
-rw-r--r-- | kernel/trace/trace_syscalls.c | 4 |
3 files changed, 12 insertions, 6 deletions
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c index cb6f365016e4..49c7abf2ba5c 100644 --- a/kernel/trace/trace_event_perf.c +++ b/kernel/trace/trace_event_perf.c | |||
@@ -116,7 +116,7 @@ int perf_trace_enable(struct perf_event *p_event) | |||
116 | if (WARN_ON_ONCE(!list)) | 116 | if (WARN_ON_ONCE(!list)) |
117 | return -EINVAL; | 117 | return -EINVAL; |
118 | 118 | ||
119 | list = per_cpu_ptr(list, smp_processor_id()); | 119 | list = this_cpu_ptr(list); |
120 | hlist_add_head_rcu(&p_event->hlist_entry, list); | 120 | hlist_add_head_rcu(&p_event->hlist_entry, list); |
121 | 121 | ||
122 | return 0; | 122 | return 0; |
@@ -142,6 +142,12 @@ void perf_trace_destroy(struct perf_event *p_event) | |||
142 | tp_event->class->perf_probe, | 142 | tp_event->class->perf_probe, |
143 | tp_event); | 143 | tp_event); |
144 | 144 | ||
145 | /* | ||
146 | * Ensure our callback won't be called anymore. See | ||
147 | * tracepoint_probe_unregister() and __DO_TRACE(). | ||
148 | */ | ||
149 | synchronize_sched(); | ||
150 | |||
145 | free_percpu(tp_event->perf_events); | 151 | free_percpu(tp_event->perf_events); |
146 | tp_event->perf_events = NULL; | 152 | tp_event->perf_events = NULL; |
147 | 153 | ||
@@ -169,7 +175,7 @@ __kprobes void *perf_trace_buf_prepare(int size, unsigned short type, | |||
169 | if (*rctxp < 0) | 175 | if (*rctxp < 0) |
170 | return NULL; | 176 | return NULL; |
171 | 177 | ||
172 | raw_data = per_cpu_ptr(perf_trace_buf[*rctxp], smp_processor_id()); | 178 | raw_data = this_cpu_ptr(perf_trace_buf[*rctxp]); |
173 | 179 | ||
174 | /* zero the dead bytes from align to not leak stack to user */ | 180 | /* zero the dead bytes from align to not leak stack to user */ |
175 | memset(&raw_data[size - sizeof(u64)], 0, sizeof(u64)); | 181 | memset(&raw_data[size - sizeof(u64)], 0, sizeof(u64)); |
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c index faf7cefd15da..f52b5f50299d 100644 --- a/kernel/trace/trace_kprobe.c +++ b/kernel/trace/trace_kprobe.c | |||
@@ -1359,7 +1359,7 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp, | |||
1359 | for (i = 0; i < tp->nr_args; i++) | 1359 | for (i = 0; i < tp->nr_args; i++) |
1360 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); | 1360 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); |
1361 | 1361 | ||
1362 | head = per_cpu_ptr(call->perf_events, smp_processor_id()); | 1362 | head = this_cpu_ptr(call->perf_events); |
1363 | perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, regs, head); | 1363 | perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, regs, head); |
1364 | } | 1364 | } |
1365 | 1365 | ||
@@ -1392,7 +1392,7 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri, | |||
1392 | for (i = 0; i < tp->nr_args; i++) | 1392 | for (i = 0; i < tp->nr_args; i++) |
1393 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); | 1393 | call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset); |
1394 | 1394 | ||
1395 | head = per_cpu_ptr(call->perf_events, smp_processor_id()); | 1395 | head = this_cpu_ptr(call->perf_events); |
1396 | perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head); | 1396 | perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1, regs, head); |
1397 | } | 1397 | } |
1398 | 1398 | ||
diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c index d2c859cec9ea..34e35804304b 100644 --- a/kernel/trace/trace_syscalls.c +++ b/kernel/trace/trace_syscalls.c | |||
@@ -519,7 +519,7 @@ static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id) | |||
519 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, | 519 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, |
520 | (unsigned long *)&rec->args); | 520 | (unsigned long *)&rec->args); |
521 | 521 | ||
522 | head = per_cpu_ptr(sys_data->enter_event->perf_events, smp_processor_id()); | 522 | head = this_cpu_ptr(sys_data->enter_event->perf_events); |
523 | perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head); | 523 | perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head); |
524 | } | 524 | } |
525 | 525 | ||
@@ -595,7 +595,7 @@ static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret) | |||
595 | rec->nr = syscall_nr; | 595 | rec->nr = syscall_nr; |
596 | rec->ret = syscall_get_return_value(current, regs); | 596 | rec->ret = syscall_get_return_value(current, regs); |
597 | 597 | ||
598 | head = per_cpu_ptr(sys_data->exit_event->perf_events, smp_processor_id()); | 598 | head = this_cpu_ptr(sys_data->exit_event->perf_events); |
599 | perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head); | 599 | perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head); |
600 | } | 600 | } |
601 | 601 | ||