Skip to content

Commit e899e7e

Browse files
mhiramathitachigregkh
authored andcommitted
tracing/kprobe: Wait for disabling all running kprobe handlers
commit a232e27 upstream. Wait for disabling all running kprobe handlers when a kprobe event is disabled, since the caller, trace_remove_event_call() supposes that a removing event is disabled completely by disabling the event. With this change, ftrace can ensure that there is no running event handlers after disabling it. Link: http://lkml.kernel.org/r/20130709093526.20138.93100.stgit@mhiramat-M0-7522 Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b0cfaff commit e899e7e

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

‎kernel/trace/trace_kprobe.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ trace_probe_file_index(struct trace_probe *tp, struct ftrace_event_file *file)
281281
static int
282282
disable_trace_probe(struct trace_probe *tp, struct ftrace_event_file *file)
283283
{
284+
struct ftrace_event_file **old = NULL;
285+
int wait = 0;
284286
int ret = 0;
285287

286288
mutex_lock(&probe_enable_lock);
@@ -314,10 +316,7 @@ disable_trace_probe(struct trace_probe *tp, struct ftrace_event_file *file)
314316
}
315317

316318
rcu_assign_pointer(tp->files, new);
317-
318-
/* Make sure the probe is done with old files */
319-
synchronize_sched();
320-
kfree(old);
319+
wait = 1;
321320
} else
322321
tp->flags &= ~TP_FLAG_PROFILE;
323322

@@ -326,11 +325,25 @@ disable_trace_probe(struct trace_probe *tp, struct ftrace_event_file *file)
326325
disable_kretprobe(&tp->rp);
327326
else
328327
disable_kprobe(&tp->rp.kp);
328+
wait = 1;
329329
}
330330

331331
out_unlock:
332332
mutex_unlock(&probe_enable_lock);
333333

334+
if (wait) {
335+
/*
336+
* Synchronize with kprobe_trace_func/kretprobe_trace_func
337+
* to ensure disabled (all running handlers are finished).
338+
* This is not only for kfree(), but also the caller,
339+
* trace_remove_event_call() supposes it for releasing
340+
* event_call related objects, which will be accessed in
341+
* the kprobe_trace_func/kretprobe_trace_func.
342+
*/
343+
synchronize_sched();
344+
kfree(old); /* Ignored if link == NULL */
345+
}
346+
334347
return ret;
335348
}
336349

0 commit comments

Comments
 (0)