Add new kprobe on tracepoint
PATCH 1/1 Add new kprobe on tracepoint
From: "Tzvetomir (VMware) Stoyanov" <[email protected]>
Hi Steven,
That is my progress so far on kprobe tracepoint implementation, it is still far from a working prototype. Looks like I have to add a new trigger type, as existing ones cannot be used. Triggers are designed to be configured from the user and that's why there is a lot of logic for that - the cmd_ops field in struct event_trigger_data. There are a lot of mandatory callbacks, that should be dummy functions in the new trigger type, as it will not be set through tracefs. I could implement these as dummy callbacks, or the logic could be changed so these callbacks can be optional. Which is the right approach?
--- include/linux/kprobes.h | 10 + include/linux/trace_events.h | 1 + kernel/trace/trace_kprobe.c | 349 +++++++++++++++++++++++++++++++++-- kernel/trace/trace_probe.c | 25 ++- kernel/trace/trace_probe.h | 7 +- kernel/trace/trace_uprobe.c | 2 +- 6 files changed, 373 insertions(+), 21 deletions(-)
include/linux/kprobes.h +10 -0
@@ -162,6 +162,16 @@ struct kretprobe {struct kretprobe_holder *rph; }; +struct keventprobe { +/* tracepoint system */ +const char *event_system; + +/* tracepoint event */ +const char *event_name; + +struct trace_event_call *tp; +}; +struct kretprobe_instance {union {struct freelist_node freelist;
include/linux/trace_events.h +1 -0
@@ -581,6 +581,7 @@ enum event_trigger_type {ETT_EVENT_ENABLE = (1 <<3 ),ETT_EVENT_HIST = (1 <<4 ),ETT_HIST_ENABLE = (1 <<5 ), + ETT_EVENT_KPROBE = (1 << 6), };extern int filter_match_preds (struct event_filter *filter,void *rec);
kernel/trace/trace_kprobe.c +335 -14
432 lines not on this page · raw message
kernel/trace/trace_probe.c +21 -4
@@ -227,12 +227,12 @@ int traceprobe_split_symbol_offset(char *symbol, long *offset)/* @buf must has MAX_EVENT_NAME_LEN size */ int traceprobe_parse_event_name (const char **pevent,const char **pgroup, -char *buf,int offset) +char *buf,int offset,int delim) {const char *slash, *event = *pevent;int len; - slash =strchr (event,'/' ); + slash =strchr (event, delim);if (slash) {if (slash == event) {trace_probe_log_err (offset,NO_GROUP_NAME );
@@ -316,6 +316,13 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t, code->op =FETCH_OP_ARG ; code->param = (unsigned int )param -1 ;#endif + }else if (flags &TPARG_FL_TPOINT ) { +if (code->data) +return -EFAULT ; + code->data =kstrdup (arg,GFP_KERNEL ); +if (!code->data) +return -ENOMEM ; + code->op =FETCH_OP_TP_ARG ; }else goto inval_var;
@@ -633,14 +640,15 @@ static int traceprobe_parse_probe_arg_body(char *arg, ssize_t *size, !strcmp(parg->type->name, "ustring")) {if (code->op !=FETCH_OP_DEREF && code->op !=FETCH_OP_UDEREF && code->op !=FETCH_OP_IMM && code->op !=FETCH_OP_COMM && - code->op !=FETCH_OP_DATA ) { + code->op !=FETCH_OP_DATA && code->op !=FETCH_OP_TP_ARG ) {trace_probe_log_err (offset + (t ? (t - arg) :0 ),BAD_STRING ); ret = -EINVAL ; goto fail; }if ((code->op ==FETCH_OP_IMM || code->op ==FETCH_OP_COMM || - code->op ==FETCH_OP_DATA ) || parg->count) { + code->op ==FETCH_OP_DATA ) || code->op ==FETCH_OP_TP_ARG || + parg->count) {/* * IMM, DATA and COMM is pointing actual address, those * must be kept, and if parg->count != 0, this is an
@@ -985,6 +993,15 @@ void trace_probe_cleanup(struct trace_probe *tp)trace_probe_unlink (tp); } +void trace_event_probe_cleanup (struct keventprobe *ep) +{ +kfree (ep->event_name); +kfree (ep->event_system); +if (ep->tp) +module_put (ep->tp->mod); +kfree (ep); +} +int trace_probe_init (struct trace_probe *tp,const char *event,const char *group,bool alloc_filter) {
kernel/trace/trace_probe.h +5 -2
@@ -102,6 +102,7 @@ enum fetch_op {FETCH_OP_MOD_BF ,/* Bitfield: .basesize, .lshift, .rshift */ // Stage 5 (loop) op FETCH_OP_LP_ARRAY ,/* Array: .param = loop count */ +FETCH_OP_TP_ARG ,/* Trace Point argument */ FETCH_OP_END , FETCH_NOP_SYMBOL, /* Unresolved Symbol holder */ };
@@ -330,6 +331,7 @@ static inline bool trace_probe_has_single_file(struct trace_probe *tp)int trace_probe_init (struct trace_probe *tp,const char *event,const char *group,bool alloc_filter);void trace_probe_cleanup (struct trace_probe *tp); +void trace_event_probe_cleanup (struct keventprobe *ep);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);
@@ -350,7 +352,8 @@ bool trace_probe_match_command_args(struct trace_probe *tp,#define TPARG_FL_RETURN BIT(0)#define TPARG_FL_KERNEL BIT(1)#define TPARG_FL_FENTRY BIT(2) -#define TPARG_FL_MASK GENMASK(2, 0) +#define TPARG_FL_TPOINT BIT(3) +#define TPARG_FL_MASK GENMASK(3, 0)extern int traceprobe_parse_probe_arg (struct trace_probe *tp,int i,char *arg,unsigned int flags);
@@ -360,7 +363,7 @@ extern void traceprobe_free_probe_arg(struct probe_arg *arg);extern int traceprobe_split_symbol_offset (char *symbol,long *offset);int traceprobe_parse_event_name (const char **pevent,const char **pgroup, -char *buf,int offset); +char *buf,int offset,int delim);extern int traceprobe_set_print_fmt (struct trace_probe *tp,bool is_return);
kernel/trace/trace_uprobe.c +1 -1
@@ -641,7 +641,7 @@ static int trace_uprobe_create(int argc, const char **argv)trace_probe_log_set_index (0 );if (event) { ret =traceprobe_parse_event_name (&event, &group, buf, - event - argv[0 ]); + event - argv[0 ],'/' );if (ret) goto fail_address_parse; }else {
Signature · 1 line
2.29.2