tracing/uprobes: Convert to struct trace_probe

Convert struct trace_uprobe to make use of the common trace_probe
structure.

Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Acked-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Cc: zhangwei(Jovi) <jovi.zhangwei@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
Namhyung Kim 2013-07-03 15:42:53 +09:00 committed by Steven Rostedt
parent c31ffb3ff6
commit 14577c3992
1 changed files with 79 additions and 80 deletions

View File

@ -51,22 +51,17 @@ struct trace_uprobe_filter {
*/ */
struct trace_uprobe { struct trace_uprobe {
struct list_head list; struct list_head list;
struct ftrace_event_class class;
struct ftrace_event_call call;
struct trace_uprobe_filter filter; struct trace_uprobe_filter filter;
struct uprobe_consumer consumer; struct uprobe_consumer consumer;
struct inode *inode; struct inode *inode;
char *filename; char *filename;
unsigned long offset; unsigned long offset;
unsigned long nhit; unsigned long nhit;
unsigned int flags; /* For TP_FLAG_* */ struct trace_probe tp;
ssize_t size; /* trace entry size */
unsigned int nr_args;
struct probe_arg args[];
}; };
#define SIZEOF_TRACE_UPROBE(n) \ #define SIZEOF_TRACE_UPROBE(n) \
(offsetof(struct trace_uprobe, args) + \ (offsetof(struct trace_uprobe, tp.args) + \
(sizeof(struct probe_arg) * (n))) (sizeof(struct probe_arg) * (n)))
static int register_uprobe_event(struct trace_uprobe *tu); static int register_uprobe_event(struct trace_uprobe *tu);
@ -114,13 +109,13 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
if (!tu) if (!tu)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
tu->call.class = &tu->class; tu->tp.call.class = &tu->tp.class;
tu->call.name = kstrdup(event, GFP_KERNEL); tu->tp.call.name = kstrdup(event, GFP_KERNEL);
if (!tu->call.name) if (!tu->tp.call.name)
goto error; goto error;
tu->class.system = kstrdup(group, GFP_KERNEL); tu->tp.class.system = kstrdup(group, GFP_KERNEL);
if (!tu->class.system) if (!tu->tp.class.system)
goto error; goto error;
INIT_LIST_HEAD(&tu->list); INIT_LIST_HEAD(&tu->list);
@ -128,11 +123,11 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)
if (is_ret) if (is_ret)
tu->consumer.ret_handler = uretprobe_dispatcher; tu->consumer.ret_handler = uretprobe_dispatcher;
init_trace_uprobe_filter(&tu->filter); init_trace_uprobe_filter(&tu->filter);
tu->call.flags |= TRACE_EVENT_FL_USE_CALL_FILTER; tu->tp.call.flags |= TRACE_EVENT_FL_USE_CALL_FILTER;
return tu; return tu;
error: error:
kfree(tu->call.name); kfree(tu->tp.call.name);
kfree(tu); kfree(tu);
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
@ -142,12 +137,12 @@ static void free_trace_uprobe(struct trace_uprobe *tu)
{ {
int i; int i;
for (i = 0; i < tu->nr_args; i++) for (i = 0; i < tu->tp.nr_args; i++)
traceprobe_free_probe_arg(&tu->args[i]); traceprobe_free_probe_arg(&tu->tp.args[i]);
iput(tu->inode); iput(tu->inode);
kfree(tu->call.class->system); kfree(tu->tp.call.class->system);
kfree(tu->call.name); kfree(tu->tp.call.name);
kfree(tu->filename); kfree(tu->filename);
kfree(tu); kfree(tu);
} }
@ -157,8 +152,8 @@ static struct trace_uprobe *find_probe_event(const char *event, const char *grou
struct trace_uprobe *tu; struct trace_uprobe *tu;
list_for_each_entry(tu, &uprobe_list, list) list_for_each_entry(tu, &uprobe_list, list)
if (strcmp(tu->call.name, event) == 0 && if (strcmp(tu->tp.call.name, event) == 0 &&
strcmp(tu->call.class->system, group) == 0) strcmp(tu->tp.call.class->system, group) == 0)
return tu; return tu;
return NULL; return NULL;
@ -181,16 +176,16 @@ static int unregister_trace_uprobe(struct trace_uprobe *tu)
/* Register a trace_uprobe and probe_event */ /* Register a trace_uprobe and probe_event */
static int register_trace_uprobe(struct trace_uprobe *tu) static int register_trace_uprobe(struct trace_uprobe *tu)
{ {
struct trace_uprobe *old_tp; struct trace_uprobe *old_tu;
int ret; int ret;
mutex_lock(&uprobe_lock); mutex_lock(&uprobe_lock);
/* register as an event */ /* register as an event */
old_tp = find_probe_event(tu->call.name, tu->call.class->system); old_tu = find_probe_event(tu->tp.call.name, tu->tp.call.class->system);
if (old_tp) { if (old_tu) {
/* delete old event */ /* delete old event */
ret = unregister_trace_uprobe(old_tp); ret = unregister_trace_uprobe(old_tu);
if (ret) if (ret)
goto end; goto end;
} }
@ -360,34 +355,36 @@ static int create_trace_uprobe(int argc, char **argv)
/* parse arguments */ /* parse arguments */
ret = 0; ret = 0;
for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) { for (i = 0; i < argc && i < MAX_TRACE_ARGS; i++) {
struct probe_arg *parg = &tu->tp.args[i];
/* Increment count for freeing args in error case */ /* Increment count for freeing args in error case */
tu->nr_args++; tu->tp.nr_args++;
/* Parse argument name */ /* Parse argument name */
arg = strchr(argv[i], '='); arg = strchr(argv[i], '=');
if (arg) { if (arg) {
*arg++ = '\0'; *arg++ = '\0';
tu->args[i].name = kstrdup(argv[i], GFP_KERNEL); parg->name = kstrdup(argv[i], GFP_KERNEL);
} else { } else {
arg = argv[i]; arg = argv[i];
/* If argument name is omitted, set "argN" */ /* If argument name is omitted, set "argN" */
snprintf(buf, MAX_EVENT_NAME_LEN, "arg%d", i + 1); snprintf(buf, MAX_EVENT_NAME_LEN, "arg%d", i + 1);
tu->args[i].name = kstrdup(buf, GFP_KERNEL); parg->name = kstrdup(buf, GFP_KERNEL);
} }
if (!tu->args[i].name) { if (!parg->name) {
pr_info("Failed to allocate argument[%d] name.\n", i); pr_info("Failed to allocate argument[%d] name.\n", i);
ret = -ENOMEM; ret = -ENOMEM;
goto error; goto error;
} }
if (!is_good_name(tu->args[i].name)) { if (!is_good_name(parg->name)) {
pr_info("Invalid argument[%d] name: %s\n", i, tu->args[i].name); pr_info("Invalid argument[%d] name: %s\n", i, parg->name);
ret = -EINVAL; ret = -EINVAL;
goto error; goto error;
} }
if (traceprobe_conflict_field_name(tu->args[i].name, tu->args, i)) { if (traceprobe_conflict_field_name(parg->name, tu->tp.args, i)) {
pr_info("Argument[%d] name '%s' conflicts with " pr_info("Argument[%d] name '%s' conflicts with "
"another field.\n", i, argv[i]); "another field.\n", i, argv[i]);
ret = -EINVAL; ret = -EINVAL;
@ -395,7 +392,8 @@ static int create_trace_uprobe(int argc, char **argv)
} }
/* Parse fetch argument */ /* Parse fetch argument */
ret = traceprobe_parse_probe_arg(arg, &tu->size, &tu->args[i], false, false); ret = traceprobe_parse_probe_arg(arg, &tu->tp.size, parg,
false, false);
if (ret) { if (ret) {
pr_info("Parse error at argument[%d]. (%d)\n", i, ret); pr_info("Parse error at argument[%d]. (%d)\n", i, ret);
goto error; goto error;
@ -459,11 +457,11 @@ static int probes_seq_show(struct seq_file *m, void *v)
char c = is_ret_probe(tu) ? 'r' : 'p'; char c = is_ret_probe(tu) ? 'r' : 'p';
int i; int i;
seq_printf(m, "%c:%s/%s", c, tu->call.class->system, tu->call.name); seq_printf(m, "%c:%s/%s", c, tu->tp.call.class->system, tu->tp.call.name);
seq_printf(m, " %s:0x%p", tu->filename, (void *)tu->offset); seq_printf(m, " %s:0x%p", tu->filename, (void *)tu->offset);
for (i = 0; i < tu->nr_args; i++) for (i = 0; i < tu->tp.nr_args; i++)
seq_printf(m, " %s=%s", tu->args[i].name, tu->args[i].comm); seq_printf(m, " %s=%s", tu->tp.args[i].name, tu->tp.args[i].comm);
seq_printf(m, "\n"); seq_printf(m, "\n");
return 0; return 0;
@ -509,7 +507,7 @@ static int probes_profile_seq_show(struct seq_file *m, void *v)
{ {
struct trace_uprobe *tu = v; struct trace_uprobe *tu = v;
seq_printf(m, " %s %-44s %15lu\n", tu->filename, tu->call.name, tu->nhit); seq_printf(m, " %s %-44s %15lu\n", tu->filename, tu->tp.call.name, tu->nhit);
return 0; return 0;
} }
@ -541,11 +539,11 @@ static void uprobe_trace_print(struct trace_uprobe *tu,
struct ring_buffer *buffer; struct ring_buffer *buffer;
void *data; void *data;
int size, i; int size, i;
struct ftrace_event_call *call = &tu->call; struct ftrace_event_call *call = &tu->tp.call;
size = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); size = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
event = trace_current_buffer_lock_reserve(&buffer, call->event.type, event = trace_current_buffer_lock_reserve(&buffer, call->event.type,
size + tu->size, 0, 0); size + tu->tp.size, 0, 0);
if (!event) if (!event)
return; return;
@ -559,8 +557,10 @@ static void uprobe_trace_print(struct trace_uprobe *tu,
data = DATAOF_TRACE_ENTRY(entry, false); data = DATAOF_TRACE_ENTRY(entry, false);
} }
for (i = 0; i < tu->nr_args; i++) for (i = 0; i < tu->tp.nr_args; i++) {
call_fetch(&tu->args[i].fetch, regs, data + tu->args[i].offset); call_fetch(&tu->tp.args[i].fetch, regs,
data + tu->tp.args[i].offset);
}
if (!call_filter_check_discard(call, entry, buffer, event)) if (!call_filter_check_discard(call, entry, buffer, event))
trace_buffer_unlock_commit(buffer, event, 0, 0); trace_buffer_unlock_commit(buffer, event, 0, 0);
@ -591,23 +591,24 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e
int i; int i;
entry = (struct uprobe_trace_entry_head *)iter->ent; entry = (struct uprobe_trace_entry_head *)iter->ent;
tu = container_of(event, struct trace_uprobe, call.event); tu = container_of(event, struct trace_uprobe, tp.call.event);
if (is_ret_probe(tu)) { if (is_ret_probe(tu)) {
if (!trace_seq_printf(s, "%s: (0x%lx <- 0x%lx)", tu->call.name, if (!trace_seq_printf(s, "%s: (0x%lx <- 0x%lx)", tu->tp.call.name,
entry->vaddr[1], entry->vaddr[0])) entry->vaddr[1], entry->vaddr[0]))
goto partial; goto partial;
data = DATAOF_TRACE_ENTRY(entry, true); data = DATAOF_TRACE_ENTRY(entry, true);
} else { } else {
if (!trace_seq_printf(s, "%s: (0x%lx)", tu->call.name, if (!trace_seq_printf(s, "%s: (0x%lx)", tu->tp.call.name,
entry->vaddr[0])) entry->vaddr[0]))
goto partial; goto partial;
data = DATAOF_TRACE_ENTRY(entry, false); data = DATAOF_TRACE_ENTRY(entry, false);
} }
for (i = 0; i < tu->nr_args; i++) { for (i = 0; i < tu->tp.nr_args; i++) {
if (!tu->args[i].type->print(s, tu->args[i].name, struct probe_arg *parg = &tu->tp.args[i];
data + tu->args[i].offset, entry))
if (!parg->type->print(s, parg->name, data + parg->offset, entry))
goto partial; goto partial;
} }
@ -618,11 +619,6 @@ partial:
return TRACE_TYPE_PARTIAL_LINE; return TRACE_TYPE_PARTIAL_LINE;
} }
static inline bool is_trace_uprobe_enabled(struct trace_uprobe *tu)
{
return tu->flags & (TP_FLAG_TRACE | TP_FLAG_PROFILE);
}
typedef bool (*filter_func_t)(struct uprobe_consumer *self, typedef bool (*filter_func_t)(struct uprobe_consumer *self,
enum uprobe_filter_ctx ctx, enum uprobe_filter_ctx ctx,
struct mm_struct *mm); struct mm_struct *mm);
@ -632,29 +628,29 @@ probe_event_enable(struct trace_uprobe *tu, int flag, filter_func_t filter)
{ {
int ret = 0; int ret = 0;
if (is_trace_uprobe_enabled(tu)) if (trace_probe_is_enabled(&tu->tp))
return -EINTR; return -EINTR;
WARN_ON(!uprobe_filter_is_empty(&tu->filter)); WARN_ON(!uprobe_filter_is_empty(&tu->filter));
tu->flags |= flag; tu->tp.flags |= flag;
tu->consumer.filter = filter; tu->consumer.filter = filter;
ret = uprobe_register(tu->inode, tu->offset, &tu->consumer); ret = uprobe_register(tu->inode, tu->offset, &tu->consumer);
if (ret) if (ret)
tu->flags &= ~flag; tu->tp.flags &= ~flag;
return ret; return ret;
} }
static void probe_event_disable(struct trace_uprobe *tu, int flag) static void probe_event_disable(struct trace_uprobe *tu, int flag)
{ {
if (!is_trace_uprobe_enabled(tu)) if (!trace_probe_is_enabled(&tu->tp))
return; return;
WARN_ON(!uprobe_filter_is_empty(&tu->filter)); WARN_ON(!uprobe_filter_is_empty(&tu->filter));
uprobe_unregister(tu->inode, tu->offset, &tu->consumer); uprobe_unregister(tu->inode, tu->offset, &tu->consumer);
tu->flags &= ~flag; tu->tp.flags &= ~flag;
} }
static int uprobe_event_define_fields(struct ftrace_event_call *event_call) static int uprobe_event_define_fields(struct ftrace_event_call *event_call)
@ -672,12 +668,12 @@ static int uprobe_event_define_fields(struct ftrace_event_call *event_call)
size = SIZEOF_TRACE_ENTRY(false); size = SIZEOF_TRACE_ENTRY(false);
} }
/* Set argument names as fields */ /* Set argument names as fields */
for (i = 0; i < tu->nr_args; i++) { for (i = 0; i < tu->tp.nr_args; i++) {
ret = trace_define_field(event_call, tu->args[i].type->fmttype, struct probe_arg *parg = &tu->tp.args[i];
tu->args[i].name,
size + tu->args[i].offset, ret = trace_define_field(event_call, parg->type->fmttype,
tu->args[i].type->size, parg->name, size + parg->offset,
tu->args[i].type->is_signed, parg->type->size, parg->type->is_signed,
FILTER_OTHER); FILTER_OTHER);
if (ret) if (ret)
@ -705,16 +701,16 @@ static int __set_print_fmt(struct trace_uprobe *tu, char *buf, int len)
pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt); pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
for (i = 0; i < tu->nr_args; i++) { for (i = 0; i < tu->tp.nr_args; i++) {
pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s", pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s",
tu->args[i].name, tu->args[i].type->fmt); tu->tp.args[i].name, tu->tp.args[i].type->fmt);
} }
pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg); pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
for (i = 0; i < tu->nr_args; i++) { for (i = 0; i < tu->tp.nr_args; i++) {
pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s", pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s",
tu->args[i].name); tu->tp.args[i].name);
} }
return pos; /* return the length of print_fmt */ return pos; /* return the length of print_fmt */
@ -734,7 +730,7 @@ static int set_print_fmt(struct trace_uprobe *tu)
/* Second: actually write the @print_fmt */ /* Second: actually write the @print_fmt */
__set_print_fmt(tu, print_fmt, len + 1); __set_print_fmt(tu, print_fmt, len + 1);
tu->call.print_fmt = print_fmt; tu->tp.call.print_fmt = print_fmt;
return 0; return 0;
} }
@ -831,14 +827,14 @@ static bool uprobe_perf_filter(struct uprobe_consumer *uc,
static void uprobe_perf_print(struct trace_uprobe *tu, static void uprobe_perf_print(struct trace_uprobe *tu,
unsigned long func, struct pt_regs *regs) unsigned long func, struct pt_regs *regs)
{ {
struct ftrace_event_call *call = &tu->call; struct ftrace_event_call *call = &tu->tp.call;
struct uprobe_trace_entry_head *entry; struct uprobe_trace_entry_head *entry;
struct hlist_head *head; struct hlist_head *head;
void *data; void *data;
int size, rctx, i; int size, rctx, i;
size = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); size = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
size = ALIGN(size + tu->size + sizeof(u32), sizeof(u64)) - sizeof(u32); size = ALIGN(size + tu->tp.size + sizeof(u32), sizeof(u64)) - sizeof(u32);
preempt_disable(); preempt_disable();
head = this_cpu_ptr(call->perf_events); head = this_cpu_ptr(call->perf_events);
@ -858,8 +854,11 @@ static void uprobe_perf_print(struct trace_uprobe *tu,
data = DATAOF_TRACE_ENTRY(entry, false); data = DATAOF_TRACE_ENTRY(entry, false);
} }
for (i = 0; i < tu->nr_args; i++) for (i = 0; i < tu->tp.nr_args; i++) {
call_fetch(&tu->args[i].fetch, regs, data + tu->args[i].offset); struct probe_arg *parg = &tu->tp.args[i];
call_fetch(&parg->fetch, regs, data + parg->offset);
}
perf_trace_buf_submit(entry, size, rctx, 0, 1, regs, head, NULL); perf_trace_buf_submit(entry, size, rctx, 0, 1, regs, head, NULL);
out: out:
@ -926,11 +925,11 @@ static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs)
tu = container_of(con, struct trace_uprobe, consumer); tu = container_of(con, struct trace_uprobe, consumer);
tu->nhit++; tu->nhit++;
if (tu->flags & TP_FLAG_TRACE) if (tu->tp.flags & TP_FLAG_TRACE)
ret |= uprobe_trace_func(tu, regs); ret |= uprobe_trace_func(tu, regs);
#ifdef CONFIG_PERF_EVENTS #ifdef CONFIG_PERF_EVENTS
if (tu->flags & TP_FLAG_PROFILE) if (tu->tp.flags & TP_FLAG_PROFILE)
ret |= uprobe_perf_func(tu, regs); ret |= uprobe_perf_func(tu, regs);
#endif #endif
return ret; return ret;
@ -943,11 +942,11 @@ static int uretprobe_dispatcher(struct uprobe_consumer *con,
tu = container_of(con, struct trace_uprobe, consumer); tu = container_of(con, struct trace_uprobe, consumer);
if (tu->flags & TP_FLAG_TRACE) if (tu->tp.flags & TP_FLAG_TRACE)
uretprobe_trace_func(tu, func, regs); uretprobe_trace_func(tu, func, regs);
#ifdef CONFIG_PERF_EVENTS #ifdef CONFIG_PERF_EVENTS
if (tu->flags & TP_FLAG_PROFILE) if (tu->tp.flags & TP_FLAG_PROFILE)
uretprobe_perf_func(tu, func, regs); uretprobe_perf_func(tu, func, regs);
#endif #endif
return 0; return 0;
@ -959,7 +958,7 @@ static struct trace_event_functions uprobe_funcs = {
static int register_uprobe_event(struct trace_uprobe *tu) static int register_uprobe_event(struct trace_uprobe *tu)
{ {
struct ftrace_event_call *call = &tu->call; struct ftrace_event_call *call = &tu->tp.call;
int ret; int ret;
/* Initialize ftrace_event_call */ /* Initialize ftrace_event_call */
@ -994,11 +993,11 @@ static int unregister_uprobe_event(struct trace_uprobe *tu)
int ret; int ret;
/* tu->event is unregistered in trace_remove_event_call() */ /* tu->event is unregistered in trace_remove_event_call() */
ret = trace_remove_event_call(&tu->call); ret = trace_remove_event_call(&tu->tp.call);
if (ret) if (ret)
return ret; return ret;
kfree(tu->call.print_fmt); kfree(tu->tp.call.print_fmt);
tu->call.print_fmt = NULL; tu->tp.call.print_fmt = NULL;
return 0; return 0;
} }