Commit ca89bc07 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Steven Rostedt (VMware)

tracing/kprobe: Add multi-probe per event support

Add multi-probe per one event support to kprobe events.
User can define several different probes on one trace event
if those events have same "event signature",
e.g.

  # echo p:testevent _do_fork > kprobe_events
  # echo p:testevent fork_idle >> kprobe_events
  # kprobe_events
  p:kprobes/testevent _do_fork
  p:kprobes/testevent fork_idle

The event signature is defined by kprobe type (retprobe or not),
the number of args, argument names, and argument types.

Note that this only support appending method. Delete event
operation will delete all probes on the event.

Link: http://lkml.kernel.org/r/156095686913.28024.9357292202316540742.stgit@devnote2Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 30199137
...@@ -4815,11 +4815,11 @@ static const char readme_msg[] = ...@@ -4815,11 +4815,11 @@ static const char readme_msg[] =
#endif #endif
#endif /* CONFIG_STACK_TRACER */ #endif /* CONFIG_STACK_TRACER */
#ifdef CONFIG_DYNAMIC_EVENTS #ifdef CONFIG_DYNAMIC_EVENTS
" dynamic_events\t\t- Add/remove/show the generic dynamic events\n" " dynamic_events\t\t- Create/append/remove/show the generic dynamic events\n"
"\t\t\t Write into this file to define/undefine new trace events.\n" "\t\t\t Write into this file to define/undefine new trace events.\n"
#endif #endif
#ifdef CONFIG_KPROBE_EVENTS #ifdef CONFIG_KPROBE_EVENTS
" kprobe_events\t\t- Add/remove/show the kernel dynamic events\n" " kprobe_events\t\t- Create/append/remove/show the kernel dynamic events\n"
"\t\t\t Write into this file to define/undefine new trace events.\n" "\t\t\t Write into this file to define/undefine new trace events.\n"
#endif #endif
#ifdef CONFIG_UPROBE_EVENTS #ifdef CONFIG_UPROBE_EVENTS
......
...@@ -492,6 +492,10 @@ static void __unregister_trace_kprobe(struct trace_kprobe *tk) ...@@ -492,6 +492,10 @@ static void __unregister_trace_kprobe(struct trace_kprobe *tk)
/* Unregister a trace_probe and probe_event */ /* Unregister a trace_probe and probe_event */
static int unregister_trace_kprobe(struct trace_kprobe *tk) static int unregister_trace_kprobe(struct trace_kprobe *tk)
{ {
/* If other probes are on the event, just unregister kprobe */
if (trace_probe_has_sibling(&tk->tp))
goto unreg;
/* Enabled event can not be unregistered */ /* Enabled event can not be unregistered */
if (trace_probe_is_enabled(&tk->tp)) if (trace_probe_is_enabled(&tk->tp))
return -EBUSY; return -EBUSY;
...@@ -500,12 +504,38 @@ static int unregister_trace_kprobe(struct trace_kprobe *tk) ...@@ -500,12 +504,38 @@ static int unregister_trace_kprobe(struct trace_kprobe *tk)
if (unregister_kprobe_event(tk)) if (unregister_kprobe_event(tk))
return -EBUSY; return -EBUSY;
unreg:
__unregister_trace_kprobe(tk); __unregister_trace_kprobe(tk);
dyn_event_remove(&tk->devent); dyn_event_remove(&tk->devent);
trace_probe_unlink(&tk->tp);
return 0; return 0;
} }
static int append_trace_kprobe(struct trace_kprobe *tk, struct trace_kprobe *to)
{
int ret;
/* Append to existing event */
ret = trace_probe_append(&tk->tp, &to->tp);
if (ret)
return ret;
/* Register k*probe */
ret = __register_trace_kprobe(tk);
if (ret == -ENOENT && !trace_kprobe_module_exist(tk)) {
pr_warn("This probe might be able to register after target module is loaded. Continue.\n");
ret = 0;
}
if (ret)
trace_probe_unlink(&tk->tp);
else
dyn_event_add(&tk->devent);
return ret;
}
/* Register a trace_probe and probe_event */ /* Register a trace_probe and probe_event */
static int register_trace_kprobe(struct trace_kprobe *tk) static int register_trace_kprobe(struct trace_kprobe *tk)
{ {
...@@ -514,14 +544,24 @@ static int register_trace_kprobe(struct trace_kprobe *tk) ...@@ -514,14 +544,24 @@ static int register_trace_kprobe(struct trace_kprobe *tk)
mutex_lock(&event_mutex); mutex_lock(&event_mutex);
/* Delete old (same name) event if exist */
old_tk = find_trace_kprobe(trace_probe_name(&tk->tp), old_tk = find_trace_kprobe(trace_probe_name(&tk->tp),
trace_probe_group_name(&tk->tp)); trace_probe_group_name(&tk->tp));
if (old_tk) { if (old_tk) {
ret = unregister_trace_kprobe(old_tk); if (trace_kprobe_is_return(tk) != trace_kprobe_is_return(old_tk)) {
if (ret < 0) trace_probe_log_set_index(0);
goto end; trace_probe_log_err(0, DIFF_PROBE_TYPE);
free_trace_kprobe(old_tk); ret = -EEXIST;
} else {
ret = trace_probe_compare_arg_type(&tk->tp, &old_tk->tp);
if (ret) {
/* Note that argument starts index = 2 */
trace_probe_log_set_index(ret + 1);
trace_probe_log_err(0, DIFF_ARG_TYPE);
ret = -EEXIST;
} else
ret = append_trace_kprobe(tk, old_tk);
}
goto end;
} }
/* Register new event */ /* Register new event */
...@@ -755,7 +795,7 @@ static int trace_kprobe_create(int argc, const char *argv[]) ...@@ -755,7 +795,7 @@ static int trace_kprobe_create(int argc, const char *argv[])
trace_probe_log_err(0, BAD_INSN_BNDRY); trace_probe_log_err(0, BAD_INSN_BNDRY);
else if (ret == -ENOENT) else if (ret == -ENOENT)
trace_probe_log_err(0, BAD_PROBE_ADDR); trace_probe_log_err(0, BAD_PROBE_ADDR);
else if (ret != -ENOMEM) else if (ret != -ENOMEM && ret != -EEXIST)
trace_probe_log_err(0, FAIL_REG_PROBE); trace_probe_log_err(0, FAIL_REG_PROBE);
goto error; goto error;
} }
......
...@@ -886,6 +886,35 @@ int traceprobe_define_arg_fields(struct trace_event_call *event_call, ...@@ -886,6 +886,35 @@ int traceprobe_define_arg_fields(struct trace_event_call *event_call,
return 0; return 0;
} }
static void trace_probe_event_free(struct trace_probe_event *tpe)
{
kfree(tpe->class.system);
kfree(tpe->call.name);
kfree(tpe->call.print_fmt);
kfree(tpe);
}
int trace_probe_append(struct trace_probe *tp, struct trace_probe *to)
{
if (trace_probe_has_sibling(tp))
return -EBUSY;
list_del_init(&tp->list);
trace_probe_event_free(tp->event);
tp->event = to->event;
list_add_tail(&tp->list, trace_probe_probe_list(to));
return 0;
}
void trace_probe_unlink(struct trace_probe *tp)
{
list_del_init(&tp->list);
if (list_empty(trace_probe_probe_list(tp)))
trace_probe_event_free(tp->event);
tp->event = NULL;
}
void trace_probe_cleanup(struct trace_probe *tp) void trace_probe_cleanup(struct trace_probe *tp)
{ {
...@@ -894,15 +923,8 @@ void trace_probe_cleanup(struct trace_probe *tp) ...@@ -894,15 +923,8 @@ void trace_probe_cleanup(struct trace_probe *tp)
for (i = 0; i < tp->nr_args; i++) for (i = 0; i < tp->nr_args; i++)
traceprobe_free_probe_arg(&tp->args[i]); traceprobe_free_probe_arg(&tp->args[i]);
if (tp->event) { if (tp->event)
struct trace_event_call *call = trace_probe_event_call(tp); trace_probe_unlink(tp);
kfree(tp->event->class.system);
kfree(call->name);
kfree(call->print_fmt);
kfree(tp->event);
tp->event = NULL;
}
} }
int trace_probe_init(struct trace_probe *tp, const char *event, int trace_probe_init(struct trace_probe *tp, const char *event,
...@@ -1006,3 +1028,22 @@ int trace_probe_remove_file(struct trace_probe *tp, ...@@ -1006,3 +1028,22 @@ int trace_probe_remove_file(struct trace_probe *tp,
return 0; return 0;
} }
/*
* Return the smallest index of different type argument (start from 1).
* If all argument types and name are same, return 0.
*/
int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b)
{
int i;
for (i = 0; i < a->nr_args; i++) {
if ((b->nr_args <= i) ||
((a->args[i].type != b->args[i].type) ||
(a->args[i].count != b->args[i].count) ||
strcmp(a->args[i].name, b->args[i].name)))
return i + 1;
}
return 0;
}
...@@ -302,6 +302,13 @@ static inline struct list_head *trace_probe_probe_list(struct trace_probe *tp) ...@@ -302,6 +302,13 @@ static inline struct list_head *trace_probe_probe_list(struct trace_probe *tp)
return &tp->event->probes; return &tp->event->probes;
} }
static inline bool trace_probe_has_sibling(struct trace_probe *tp)
{
struct list_head *list = trace_probe_probe_list(tp);
return !list_empty(list) && !list_is_singular(list);
}
static inline int trace_probe_unregister_event_call(struct trace_probe *tp) static inline int trace_probe_unregister_event_call(struct trace_probe *tp)
{ {
/* tp->event is unregistered in trace_remove_event_call() */ /* tp->event is unregistered in trace_remove_event_call() */
...@@ -316,12 +323,15 @@ static inline bool trace_probe_has_single_file(struct trace_probe *tp) ...@@ -316,12 +323,15 @@ static inline bool trace_probe_has_single_file(struct trace_probe *tp)
int trace_probe_init(struct trace_probe *tp, const char *event, int trace_probe_init(struct trace_probe *tp, const char *event,
const char *group); const char *group);
void trace_probe_cleanup(struct trace_probe *tp); void trace_probe_cleanup(struct trace_probe *tp);
int trace_probe_append(struct trace_probe *tp, struct trace_probe *to);
void trace_probe_unlink(struct trace_probe *tp);
int trace_probe_register_event_call(struct trace_probe *tp); int trace_probe_register_event_call(struct trace_probe *tp);
int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file); int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file);
int trace_probe_remove_file(struct trace_probe *tp, int trace_probe_remove_file(struct trace_probe *tp,
struct trace_event_file *file); struct trace_event_file *file);
struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp, struct event_file_link *trace_probe_get_file_link(struct trace_probe *tp,
struct trace_event_file *file); struct trace_event_file *file);
int trace_probe_compare_arg_type(struct trace_probe *a, struct trace_probe *b);
#define trace_probe_for_each_link(pos, tp) \ #define trace_probe_for_each_link(pos, tp) \
list_for_each_entry(pos, &(tp)->event->files, list) list_for_each_entry(pos, &(tp)->event->files, list)
...@@ -419,7 +429,9 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call, ...@@ -419,7 +429,9 @@ extern int traceprobe_define_arg_fields(struct trace_event_call *event_call,
C(ARG_TOO_LONG, "Argument expression is too long"), \ C(ARG_TOO_LONG, "Argument expression is too long"), \
C(NO_ARG_BODY, "No argument expression"), \ C(NO_ARG_BODY, "No argument expression"), \
C(BAD_INSN_BNDRY, "Probe point is not an instruction boundary"),\ C(BAD_INSN_BNDRY, "Probe point is not an instruction boundary"),\
C(FAIL_REG_PROBE, "Failed to register probe event"), C(FAIL_REG_PROBE, "Failed to register probe event"),\
C(DIFF_PROBE_TYPE, "Probe type is different from existing probe"),\
C(DIFF_ARG_TYPE, "Argument type or name is different from existing probe"),
#undef C #undef C
#define C(a, b) TP_ERR_##a #define C(a, b) TP_ERR_##a
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment