tracing: For this merge window
Subsystems (4)
Steven Rostedt
maintainercover tracing: For this merge window
I've been hammering this for some time, and Like this in this merge window.
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next
Head SHA1: a2acce536921bd793bae13fa344fcea157638e72
Masami Hiramatsu (15):
tracing: probeevent: Cleanup print argument functions
tracing: probeevent: Cleanup argument field definition
tracing: probeevent: Remove NOKPROBE_SYMBOL from print functions
tracing: probeevent: Introduce new argument fetching code
tracing: probeevent: Unify fetch type tables
tracing: probeevent: Return consumed bytes of dynamic area
tracing: probeevent: Append traceprobe_ for exported function
tracing: probeevent: Unify fetch_insn processing common part
tracing: probeevent: Add symbol type
tracing: probeevent: Add array type support
x86: ptrace: Add function argument access API
tracing: probeevent: Add $argN for accessing function args tracing/uprobes: Fix to return -EFAULT if copy_from_user failed tracing/kprobes: Check the probe on unloaded module correctly tracing/kprobes: Allow kprobe-events to record module symbol
Nikolay Borisov (1):
tracing: Export trace_dump_stack to modules
Steven Rostedt (VMware) (2):
tracing: probeevent: Fix uninitialized used of offset in parse args
tracing: Have stack tracer trace full stack
----
Documentation/trace/kprobetrace.rst | 23 +- arch/Kconfig | 7 + arch/x86/Kconfig | 1 + arch/x86/include/asm/ptrace.h | 38 ++ kernel/trace/trace.c | 10 +- kernel/trace/trace_kprobe.c | 403 +++++++++------------ kernel/trace/trace_probe.c | 672 ++++++++++++++++++------------------ kernel/trace/trace_probe.h | 286 +++++---------- kernel/trace/trace_probe_tmpl.h | 216 ++++++++++++ kernel/trace/trace_stack.c | 2 +- kernel/trace/trace_uprobe.c | 176 ++++------ 11 files changed, 930 insertions(+), 904 deletions(-) create mode 100644 kernel/trace/trace_probe_tmpl.h
Steven Rostedt
maintainerPATCH 1/18 tracing: probeevent: Cleanup print argument functions
From: Masami Hiramatsu <[email protected]>
Cleanup the print-argument function to decouple it into print-name and print-value, so that it can support more flexible expression, like array type.
--- kernel/trace/trace_kprobe.c | 20 ++++++-------------- kernel/trace/trace_probe.c | 12 +++++------- kernel/trace/trace_probe.h | 19 ++++++++++++++++--- kernel/trace/trace_uprobe.c | 9 ++------- 4 files changed, 29 insertions(+), 31 deletions(-)
kernel/trace/trace_kprobe.c +6 -14
@@ -1136,8 +1136,6 @@ print_kprobe_event(struct trace_iterator *iter, int flags,struct kprobe_trace_entry_head *field;struct trace_seq *s = &iter->seq;struct trace_probe *tp; -u8 *data; -int i; field = (struct kprobe_trace_entry_head *)iter->ent; tp = container_of(event, struct trace_probe, call.event);
@@ -1149,11 +1147,9 @@ print_kprobe_event(struct trace_iterator *iter, int flags,trace_seq_putc (s,')' ); - data = (u8 *)&field[1 ]; -for (i =0 ; i < tp->nr_args; i++) -if (!tp->args[i].type->if (print_probe_args (s, tp->args, tp->nr_args, + (u8 *)&field[1 ], field) <0 ) + goto out;trace_seq_putc (s,'\n' ); out:
@@ -1167,8 +1163,6 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,struct kretprobe_trace_entry_head *field;struct trace_seq *s = &iter->seq;struct trace_probe *tp; -u8 *data; -int i; field = (struct kretprobe_trace_entry_head *)iter->ent; tp = container_of(event, struct trace_probe, call.event);
@@ -1185,11 +1179,9 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,trace_seq_putc (s,')' ); - data = (u8 *)&field[1 ]; -for (i =0 ; i < tp->nr_args; i++) -if (!tp->args[i].type->if (print_probe_args (s, tp->args, tp->nr_args, + (u8 *)&field[1 ], field) <0 ) + goto out;trace_seq_putc (s,'\n' );
kernel/trace/trace_probe.c +5 -7
@@ -26,10 +26,9 @@ const char *reserved_field_names[] = {/* Printing in basic type function template */ #define DEFINE_BASIC_PRINT_TYPE_FUNC (tname, type, fmt) \ -int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, const char *name, \ - void *data, void *ent) \ +int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, void *data, void *ent)\ { \ - trace_seq_printf(s, " %s=" fmt, name, *(type *)data); \ + trace_seq_printf(s, fmt, *(type *)data); \ return !trace_seq_has_overflowed(s); \ } \ const char PRINT_TYPE_FMT_NAME(tname)[] = fmt; \
@@ -49,15 +48,14 @@ DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x")DEFINE_BASIC_PRINT_TYPE_FUNC (x64, u64,"0x%Lx" ) /* Print type function for string type */ -int PRINT_TYPE_FUNC_NAME (string )(struct trace_seq *s,const char *name, -void *data,void *ent) +int PRINT_TYPE_FUNC_NAME (string )(struct trace_seq *s,void *data,void *ent) {int len = *(u32 *)data >>16 ;if (!len) -trace_seq_printf (s," %s=(fault)" , name); +trace_seq_puts (s,"(fault)" );else -trace_seq_printf (s," %s=\"%s\"" , name, +trace_seq_printf (s,"\"%s\"" , (const char *)get_loc_data (data, ent));return !trace_seq_has_overflowed (s); }
kernel/trace/trace_probe.h +16 -3
@@ -82,7 +82,7 @@ static nokprobe_inline void *get_loc_data(u32 *dl, void *ent)/* Data fetch function type */ typedef void (*fetch_func_t )(struct pt_regs *,void *,void *);/* Printing function type */ -typedef int (*print_type_func_t )(struct trace_seq *,const char *,void *,void *); +typedef int (*print_type_func_t )(struct trace_seq *,void *,void *);/* Fetch types */ enum {
@@ -124,8 +124,7 @@ typedef u32 string_size;/* Printing in basic type function template */ #define DECLARE_BASIC_PRINT_TYPE_FUNC (type) \ -int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, const char *name, \ - void *data, void *ent); \ +int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s, void *data, void *ent);\ extern const char PRINT_TYPE_FMT_NAME(type)[]DECLARE_BASIC_PRINT_TYPE_FUNC (u8);
@@ -403,6 +402,20 @@ store_trace_args(int ent_size, struct trace_probe *tp, struct pt_regs *regs, } } +static inline int +print_probe_args (struct trace_seq *s,struct probe_arg *args,int nr_args, +u8 *data,void *field) +{ +int i; + +for (i =0 ; i < nr_args; i++) { +trace_seq_printf (s," %s=" , args[i].name); +if (!args[i].type->return -ENOMEM ; + } +return 0 ; +} +extern int set_print_fmt (struct trace_probe *tp,bool is_return);#ifdef CONFIG_PERF_EVENTS
kernel/trace/trace_uprobe.c +2 -7
@@ -892,7 +892,6 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *estruct trace_seq *s = &iter->seq;struct trace_uprobe *tu;u8 *data; -int i; entry = (struct uprobe_trace_entry_head *)iter->ent; tu = container_of(event, struct trace_uprobe, tp.call.event);
@@ -909,12 +908,8 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *e data =DATAOF_TRACE_ENTRY (entry, false); } -for (i =0 ; i < tu->tp.nr_args; i++) { -struct probe_arg *parg = &tu->tp.args[i]; - -if (!parg->type->if (print_probe_args (s, tu->tp.args, tu->tp.nr_args, data, entry) <0 ) + goto out;trace_seq_putc (s,'\n' );
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 2/18 tracing: probeevent: Cleanup argument field definition
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Cleanup event argument definition code in one place for maintenancability.
--- kernel/trace/trace_kprobe.c | 32 ++++---------------------------- kernel/trace/trace_probe.c | 21 +++++++++++++++++++++ kernel/trace/trace_probe.h | 2 ++ kernel/trace/trace_uprobe.c | 15 ++------------- 4 files changed, 29 insertions(+), 41 deletions(-)
kernel/trace/trace_kprobe.c +4 -28
@@ -1192,49 +1192,25 @@ print_kretprobe_event(struct trace_iterator *iter, int flags,static int kprobe_event_define_fields (struct trace_event_call *event_call) { -int ret, i; +int ret;struct kprobe_trace_entry_head field;struct trace_kprobe *tk = (struct trace_kprobe *)event_call->data; DEFINE_FIELD(unsigned long, ip, FIELD_STRING_IP, 0); -/* Set argument names as fields */ -for (i =0 ; i < tk->tp.nr_args; i++) { -struct probe_arg *parg = &tk->tp.args[i]; - ret =trace_define_field (event_call, parg->type->fmttype, - parg->name, -sizeof (field) + parg->offset, - parg->type->size, - parg->type->is_signed, -FILTER_OTHER ); -if (ret) -return ret; - } -return 0 ; +return traceprobe_define_arg_fields (event_call,sizeof (field), &tk->tp); }static int kretprobe_event_define_fields (struct trace_event_call *event_call) { -int ret, i; +int ret;struct kretprobe_trace_entry_head field;struct trace_kprobe *tk = (struct trace_kprobe *)event_call->data; DEFINE_FIELD(unsigned long, func, FIELD_STRING_FUNC, 0); DEFINE_FIELD(unsigned long, ret_ip, FIELD_STRING_RETIP, 0); -/* Set argument names as fields */ -for (i =0 ; i < tk->tp.nr_args; i++) { -struct probe_arg *parg = &tk->tp.args[i]; - ret =trace_define_field (event_call, parg->type->fmttype, - parg->name, -sizeof (field) + parg->offset, - parg->type->size, - parg->type->is_signed, -FILTER_OTHER ); -if (ret) -return ret; - } -return 0 ; +return traceprobe_define_arg_fields (event_call,sizeof (field), &tk->tp); }#ifdef CONFIG_PERF_EVENTS
kernel/trace/trace_probe.c +21 -0
@@ -668,3 +668,24 @@ int set_print_fmt(struct trace_probe *tp, bool is_return)return 0 ; } + +int traceprobe_define_arg_fields (struct trace_event_call *event_call, +size_t offset,struct trace_probe *tp) +{ +int ret, i; + +/* Set argument names as fields */ +for (i =0 ; i < tp->nr_args; i++) { +struct probe_arg *parg = &tp->args[i]; + + ret =trace_define_field (event_call, parg->type->fmttype, + parg->name, + offset + parg->offset, + parg->type->size, + parg->type->is_signed, +FILTER_OTHER ); +if (ret) +return ret; + } +return 0 ; +}
kernel/trace/trace_probe.h +2 -0
@@ -429,3 +429,5 @@ create_local_trace_uprobe(char *name, unsigned long offs, unsigned long ref_ctr_offset, bool is_return);extern void destroy_local_trace_uprobe (struct trace_event_call *event_call);#endif +extern int traceprobe_define_arg_fields (struct trace_event_call *event_call, +size_t offset,struct trace_probe *tp);
kernel/trace/trace_uprobe.c +2 -13
@@ -1018,7 +1018,7 @@ probe_event_disable(struct trace_uprobe *tu, struct trace_event_file *file)static int uprobe_event_define_fields (struct trace_event_call *event_call) { -int ret, i, size; +int ret, size;struct uprobe_trace_entry_head field;struct trace_uprobe *tu = event_call->data;
@@ -1030,19 +1030,8 @@ static int uprobe_event_define_fields(struct trace_event_call *event_call) DEFINE_FIELD(unsigned long, vaddr[0], FIELD_STRING_IP, 0); size =SIZEOF_TRACE_ENTRY (false); } -/* Set argument names as fields */ -for (i =0 ; i < tu->tp.nr_args; i++) { -struct probe_arg *parg = &tu->tp.args[i]; - - ret =trace_define_field (event_call, parg->type->fmttype, - parg->name, size + parg->offset, - parg->type->size, parg->type->is_signed, -FILTER_OTHER ); -if (ret) -return ret; - } -return 0 ; +return traceprobe_define_arg_fields (event_call, size, &tu->tp); }#ifdef CONFIG_PERF_EVENTS
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 3/18 tracing: probeevent: Remove NOKPROBE_SYMBOL from print functions
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Remove unneeded NOKPROBE_SYMBOL from print functions since the print functions are only used when printing out the trace data, and not from kprobe handler.
--- kernel/trace/trace_probe.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/trace/trace_probe.c +1 -3
@@ -31,8 +31,7 @@ int PRINT_TYPE_FUNC_NAME(tname)(struct trace_seq *s, void *data, void *ent)\trace_seq_printf (s, fmt, *(type *)data); \return !trace_seq_has_overflowed (s); \ } \ -const char PRINT_TYPE_FMT_NAME (tname )[] = fmt; \ -NOKPROBE_SYMBOL (PRINT_TYPE_FUNC_NAME (tname)); +const char PRINT_TYPE_FMT_NAME (tname )[] = fmt; DEFINE_BASIC_PRINT_TYPE_FUNC(u8, u8, "%u")DEFINE_BASIC_PRINT_TYPE_FUNC (u16, u16,"%u" )
@@ -59,7 +58,6 @@ int PRINT_TYPE_FUNC_NAME(string)(struct trace_seq *s, void *data, void *ent) (const char *)get_loc_data(data, ent));return !trace_seq_has_overflowed (s); } -NOKPROBE_SYMBOL (PRINT_TYPE_FUNC_NAME (string));const char PRINT_TYPE_FMT_NAME (string )[] ="\\\"%s\\\"" ;
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 4/18 tracing: probeevent: Introduce new argument fetching code
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Replace {k,u}probe event argument fetching framework with switch-case based. Currently that is implemented with structures, macros and chain of function-pointers, which is more complicated than necessary and may get a performance penalty by retpoline.
This simplify that with an array of "fetch_insn" (opcode and oprands), and make process_fetch_insn() just interprets it. No function pointers are used.
--- kernel/trace/trace_kprobe.c | 291 +++++++++++------------ kernel/trace/trace_probe.c | 401 +++++++++----------------------- kernel/trace/trace_probe.h | 230 ++++-------------- kernel/trace/trace_probe_tmpl.h | 120 ++++++++++ kernel/trace/trace_uprobe.c | 127 ++++++---- 5 files changed, 491 insertions(+), 678 deletions(-) create mode 100644 kernel/trace/trace_probe_tmpl.h
kernel/trace/trace_kprobe.c +131 -160
@@ -14,6 +14,7 @@#include "trace_kprobe_selftest.h" #include "trace_probe.h" +#include "trace_probe_tmpl.h" #define KPROBE_EVENT_SYSTEM "kprobes"#define KRETPROBE_MAXACTIVE_MAX 4096
@@ -120,160 +121,6 @@ static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs);static int kretprobe_dispatcher (struct kretprobe_instance *ri,struct pt_regs *regs); -/* Memory fetching by symbol */ -struct symbol_cache { -char *symbol; -long offset; -unsigned long addr; -}; - -unsigned long update_symbol_cache (struct symbol_cache *sc) -{ - sc->addr = (unsigned long )kallsyms_lookup_name (sc->symbol); - -if (sc->addr) - sc->addr += sc->offset; - -return sc->addr; -} - -void free_symbol_cache (struct symbol_cache *sc) -{ -kfree (sc->symbol); -kfree (sc); -} - -struct symbol_cache *alloc_symbol_cache (const char *sym,long offset) -{ -struct symbol_cache *sc; - -if (!sym ||strlen (sym) ==0 ) -return NULL ; - - sc =kzalloc (sizeof (struct symbol_cache ),GFP_KERNEL ); -if (!sc) -return NULL ; - - sc->symbol =kstrdup (sym,GFP_KERNEL ); -if (!sc->symbol) { -kfree (sc); -return NULL ; - } - sc->offset = offset; -update_symbol_cache (sc); - -return sc; -} - -/* -* Kprobes-specific fetch functions -*/ -#define DEFINE_FETCH_stack (type) \ -static void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs, \ - void *offset, void *dest) \ -{ \ - *(type *)dest = (type)regs_get_kernel_stack_nth(regs, \ - (unsigned int)((unsigned long)offset)); \ -} \ -NOKPROBE_SYMBOL(FETCH_FUNC_NAME(stack, type)); - -DEFINE_BASIC_FETCH_FUNCS (stack) -/* No string on the stack entry */ -#define fetch_stack_string NULL -#define fetch_stack_string_size NULL - -#define DEFINE_FETCH_memory (type) \ -static void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs, \ - void *addr, void *dest) \ -{ \ - type retval; \ - if (probe_kernel_address(addr, retval)) \ - *(type *)dest = 0; \ - else \ - *(type *)dest = retval; \ -} \ -NOKPROBE_SYMBOL(FETCH_FUNC_NAME(memory, type)); - -DEFINE_BASIC_FETCH_FUNCS (memory) -/* -* Fetch a null-terminated string. Caller MUST set *(u32 *)dest with max -* length and relative data location. -*/ -static void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs, -void *addr,void *dest) -{ -int maxlen =get_rloc_len (*(u32 *)dest); -u8 *dst =get_rloc_data (dest); -long ret; - -if (!maxlen) -return ; - -/* -* Try to get string again, since the string can be changed while -* probing. -*/ - ret =strncpy_from_unsafe (dst, addr, maxlen); - -if (ret <0 ) {/* Failed to fetch string */ - dst[0 ] ='\0' ; - *(u32 *)dest =make_data_rloc (0 ,get_rloc_offs (*(u32 *)dest)); - }else { - *(u32 *)dest =make_data_rloc (ret,get_rloc_offs (*(u32 *)dest)); - } -} -NOKPROBE_SYMBOL (FETCH_FUNC_NAME (memory, string)); - -/* Return the length of string -- including null terminal byte */ -static void FETCH_FUNC_NAME (memory ,string_size )(struct pt_regs *regs, -void *addr,void *dest) -{ -mm_segment_t old_fs; -int ret, len =0 ; -u8 c; - - old_fs =get_fs (); -set_fs (KERNEL_DS ); -pagefault_disable (); - -do { - ret =__copy_from_user_inatomic (&c, (u8 *)addr + len,1 ); - len++; - }while (c && ret ==0 && len <MAX_STRING_SIZE ); - -pagefault_enable (); -set_fs (old_fs); - -if (ret <0 )/* Failed to check the length */ - *(u32 *)dest =0 ; -else - *(u32 *)dest = len; -} -NOKPROBE_SYMBOL (FETCH_FUNC_NAME (memory, string_size)); - -#define DEFINE_FETCH_symbol (type) \ -void FETCH_FUNC_NAME(symbol, type)(struct pt_regs *regs, void *data, void *dest)\ -{ \ - struct symbol_cache *sc = data; \ - if (sc->addr) \ - fetch_memory_##type(regs, (void *)sc->addr, dest); \ - else \ - *(type *)dest = 0; \ -} \ -NOKPROBE_SYMBOL(FETCH_FUNC_NAME(symbol, type)); - -DEFINE_BASIC_FETCH_FUNCS(symbol) -DEFINE_FETCH_symbol(string) -DEFINE_FETCH_symbol(string_size) - -/* kprobes don't support file_offset fetch methods */ -#define fetch_file_offset_u8 NULL -#define fetch_file_offset_u16 NULL -#define fetch_file_offset_u32 NULL -#define fetch_file_offset_u64 NULL -#define fetch_file_offset_string NULL -#define fetch_file_offset_string_size NULL -/* Fetch type information table */ static const struct fetch_type kprobes_fetch_type_table[] = {/* Special types */
@@ -529,7 +376,7 @@ static bool within_notrace_func(struct trace_kprobe *tk)/* Internal register function - just handle k*probes and flags */ static int __register_trace_kprobe (struct trace_kprobe *tk) { -int i, ret; +int ret;if (trace_probe_is_registered (&tk->tp))return -EINVAL ;
@@ -540,9 +387,6 @@ static int __register_trace_kprobe(struct trace_kprobe *tk)return -EINVAL ; } -for (i =0 ; i < tk->tp.nr_args; i++) -traceprobe_update_arg (&tk->tp.args[i]); -/* Set/clear disabled flag according to tp->flag */ if (trace_probe_is_enabled (&tk->tp)) tk->rp.kp.flags &= ~KPROBE_FLAG_DISABLED ;
@@ -876,8 +720,8 @@ static int create_trace_kprobe(int argc, char **argv)/* Parse fetch argument */ ret =traceprobe_parse_probe_arg (arg, &tk->tp.size, parg, - is_return, true, - kprobes_fetch_type_table); + is_return, true, + kprobes_fetch_type_table);if (ret) {pr_info ("Parse error at argument[%d]. (%d)\n" , i, ret); goto error;
@@ -1031,6 +875,133 @@ static const struct file_operations kprobe_profile_ops = { .release = seq_release, }; +/* Kprobe specific fetch functions */ + +/* Return the length of string -- including null terminal byte */ +static nokprobe_inline void +fetch_store_strlen (unsigned long addr,void *dest) +{ +mm_segment_t old_fs; +int ret, len =0 ; +u8 c; + + old_fs =get_fs (); +set_fs (KERNEL_DS ); +pagefault_disable (); + +do { + ret =__copy_from_user_inatomic (&c, (u8 *)addr + len,1 ); + len++; + }while (c && ret ==0 && len <MAX_STRING_SIZE ); + +pagefault_enable (); +set_fs (old_fs); + +if (ret <0 )/* Failed to check the length */ + *(u32 *)dest =0 ; +else + *(u32 *)dest = len; +} + +/* +* Fetch a null-terminated string. Caller MUST set *(u32 *)buf with max +* length and relative data location. +*/ +static nokprobe_inline void +fetch_store_string (unsigned long addr,void *dest) +{ +int maxlen =get_rloc_len (*(u32 *)dest); +u8 *dst =get_rloc_data (dest); +long ret; + +if (!maxlen) +return ; + +/* +* Try to get string again, since the string can be changed while +* probing. +*/ + ret =strncpy_from_unsafe (dst, (void *)addr, maxlen); + +if (ret <0 ) {/* Failed to fetch string */ + dst[0 ] ='\0' ; + *(u32 *)dest =make_data_rloc (0 ,get_rloc_offs (*(u32 *)dest)); + }else { + *(u32 *)dest =make_data_rloc (ret,get_rloc_offs (*(u32 *)dest)); + } +} + +/* Note that we don't verify it, since the code does not come from user space */ +static int +process_fetch_insn (struct fetch_insn *code,struct pt_regs *regs,void *dest, +bool pre) +{ +unsigned long val; +int ret; + +/* 1st stage: get value from context */ +switch (code->op) { +case FETCH_OP_REG : + val =regs_get_register (regs, code->param); +break ; +case FETCH_OP_STACK : + val =regs_get_kernel_stack_nth (regs, code->param); +break ; +case FETCH_OP_STACKP : + val =kernel_stack_pointer (regs); +break ; +case FETCH_OP_RETVAL : + val =regs_return_value (regs); +break ; +case FETCH_OP_IMM : + val = code->immediate; +break ; +case FETCH_OP_COMM : + val = (unsigned long )current->comm; +break ; +default : +return -EILSEQ ; + } + code++; + +/* 2nd stage: dereference memory if needed */ +while (code->op ==FETCH_OP_DEREF ) { + ret =probe_kernel_read (&val, (void *)val + code->offset, +sizeof (val)); +if (ret) +return ret; + code++; + } + +/* 3rd stage: store value to buffer */ +switch (code->op) { +case FETCH_OP_ST_RAW : +fetch_store_raw (val, code, dest); +break ; +case FETCH_OP_ST_MEM : +probe_kernel_read (dest, (void *)val + code->offset, code->size); +break ; +case FETCH_OP_ST_STRING : +if (pre) +fetch_store_strlen (val + code->offset, dest); +else +fetch_store_string (val + code->offset, dest); +break ; +default : +return -EILSEQ ; + } + code++; + +/* 4th stage: modify stored value if needed */ +if (code->op ==FETCH_OP_MOD_BF ) { +fetch_apply_bitfield (code, dest); + code++; + } + +return code->op ==FETCH_OP_END ?0 : -EILSEQ ; +} +NOKPROBE_SYMBOL (process_fetch_insn) +/* Kprobe handler */ static nokprobe_inline void __kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs,
kernel/trace/trace_probe.c +112 -289
541 lines not on this page · raw message
kernel/trace/trace_probe.h +43 -187
294 lines not on this page · raw message
kernel/trace/trace_probe_tmpl.h new file +120 -0
120 lines not on this page · raw message
kernel/trace/trace_uprobe.c +85 -42
170 lines not on this page · raw message
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 5/18 tracing: probeevent: Unify fetch type tables
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Unify {k,u}probe_fetch_type_table to probe_fetch_type_table because the main difference of those type tables (fetcharg methods) are gone. Now we can consolidate it.
--- kernel/trace/trace_kprobe.c | 27 +------------------ kernel/trace/trace_probe.c | 54 ++++++++++++++++++++++++------------- kernel/trace/trace_probe.h | 6 +---- kernel/trace/trace_uprobe.c | 27 +------------------ 4 files changed, 39 insertions(+), 75 deletions(-)
kernel/trace/trace_kprobe.c +1 -26
@@ -121,30 +121,6 @@ static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs);static int kretprobe_dispatcher (struct kretprobe_instance *ri,struct pt_regs *regs); -/* Fetch type information table */ -static const struct fetch_type kprobes_fetch_type_table[] = { -/* Special types */ - [FETCH_TYPE_STRING ] =__ASSIGN_FETCH_TYPE ("string" , string, string, -sizeof (u32),1 ,"__data_loc char[]" ), - [FETCH_TYPE_STRSIZE ] =__ASSIGN_FETCH_TYPE ("string_size" , u32, - string_size,sizeof (u32),0 ,"u32" ), -/* Basic types */ -ASSIGN_FETCH_TYPE (u8, u8,0 ), -ASSIGN_FETCH_TYPE (u16, u16,0 ), -ASSIGN_FETCH_TYPE (u32, u32,0 ), -ASSIGN_FETCH_TYPE (u64, u64,0 ), -ASSIGN_FETCH_TYPE (s8, u8,1 ), -ASSIGN_FETCH_TYPE (s16, u16,1 ), -ASSIGN_FETCH_TYPE (s32, u32,1 ), -ASSIGN_FETCH_TYPE (s64, u64,1 ), -ASSIGN_FETCH_TYPE_ALIAS (x8, u8, u8,0 ), -ASSIGN_FETCH_TYPE_ALIAS (x16, u16, u16,0 ), -ASSIGN_FETCH_TYPE_ALIAS (x32, u32, u32,0 ), -ASSIGN_FETCH_TYPE_ALIAS (x64, u64, u64,0 ), - -ASSIGN_FETCH_TYPE_END -}; -/* * Allocate new trace_probe and initialize it (including kprobes). */
@@ -720,8 +696,7 @@ static int create_trace_kprobe(int argc, char **argv)/* Parse fetch argument */ ret =traceprobe_parse_probe_arg (arg, &tk->tp.size, parg, - is_return, true, - kprobes_fetch_type_table); + is_return, true);if (ret) {pr_info ("Parse error at argument[%d]. (%d)\n" , i, ret); goto error;
kernel/trace/trace_probe.c +36 -18
107 lines not on this page · raw message
kernel/trace/trace_probe.h +1 -5
@@ -184,9 +184,6 @@ DECLARE_BASIC_PRINT_TYPE_FUNC(string);#define ASSIGN_FETCH_TYPE_END {} -#define FETCH_TYPE_STRING 0 -#define FETCH_TYPE_STRSIZE 1 -#ifdef CONFIG_KPROBE_EVENTS bool trace_kprobe_on_func_entry (struct trace_event_call *call);bool trace_kprobe_error_injectable (struct trace_event_call *call);
@@ -261,8 +258,7 @@ find_event_file_link(struct trace_probe *tp, struct trace_event_file *file) }extern int traceprobe_parse_probe_arg (char *arg,ssize_t *size, -struct probe_arg *parg,bool is_return,bool is_kprobe, -const struct fetch_type *ftbl); +struct probe_arg *parg,bool is_return,bool is_kprobe);extern int traceprobe_conflict_field_name (const char *name,struct probe_arg *args,int narg);
kernel/trace/trace_uprobe.c +1 -26
@@ -161,30 +161,6 @@ static unsigned long translate_user_vaddr(unsigned long file_offset)return base_addr + file_offset; } -/* Fetch type information table */ -static const struct fetch_type uprobes_fetch_type_table[] = { -/* Special types */ - [FETCH_TYPE_STRING ] =__ASSIGN_FETCH_TYPE ("string" , string, string, -sizeof (u32),1 ,"__data_loc char[]" ), - [FETCH_TYPE_STRSIZE ] =__ASSIGN_FETCH_TYPE ("string_size" , u32, - string_size,sizeof (u32),0 ,"u32" ), -/* Basic types */ -ASSIGN_FETCH_TYPE (u8, u8,0 ), -ASSIGN_FETCH_TYPE (u16, u16,0 ), -ASSIGN_FETCH_TYPE (u32, u32,0 ), -ASSIGN_FETCH_TYPE (u64, u64,0 ), -ASSIGN_FETCH_TYPE (s8, u8,1 ), -ASSIGN_FETCH_TYPE (s16, u16,1 ), -ASSIGN_FETCH_TYPE (s32, u32,1 ), -ASSIGN_FETCH_TYPE (s64, u64,1 ), -ASSIGN_FETCH_TYPE_ALIAS (x8, u8, u8,0 ), -ASSIGN_FETCH_TYPE_ALIAS (x16, u16, u16,0 ), -ASSIGN_FETCH_TYPE_ALIAS (x32, u32, u32,0 ), -ASSIGN_FETCH_TYPE_ALIAS (x64, u64, u64,0 ), - -ASSIGN_FETCH_TYPE_END -}; -/* Note that we don't verify it, since the code does not come from user space */ static int process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest,
@@ -621,8 +597,7 @@ static int create_trace_uprobe(int argc, char **argv)/* Parse fetch argument */ ret =traceprobe_parse_probe_arg (arg, &tu->tp.size, parg, - is_return, false, - uprobes_fetch_type_table); + is_return, false);if (ret) {pr_info ("Parse error at argument[%d]. (%d)\n" , i, ret); goto error;
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 6/18 tracing: probeevent: Return consumed bytes of dynamic area
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Cleanup string fetching routine so that returns the consumed bytes of dynamic area and store the string information as data_loc format instead of data_rloc.
This simplifies the fetcharg loop.
--- kernel/trace/trace_kprobe.c | 57 +++++++++++++++--------------- kernel/trace/trace_probe.h | 26 ++++---------- kernel/trace/trace_probe_tmpl.h | 54 ++++++++++++++--------------- kernel/trace/trace_uprobe.c | 61 ++++++++++++++++----------------- 4 files changed, 88 insertions(+), 110 deletions(-)
kernel/trace/trace_kprobe.c +27 -30
@@ -853,8 +853,8 @@ static const struct file_operations kprobe_profile_ops = {/* Kprobe specific fetch functions */ /* Return the length of string -- including null terminal byte */ -static nokprobe_inline void -fetch_store_strlen (unsigned long addr,void *dest) +static nokprobe_inline int +fetch_store_strlen (unsigned long addr) {mm_segment_t old_fs;int ret, len =0 ;
@@ -872,47 +872,40 @@ fetch_store_strlen(unsigned long addr, void *dest)pagefault_enable ();set_fs (old_fs); -if (ret <0 )/* Failed to check the length */ - *(u32 *)dest =0 ; -else - *(u32 *)dest = len; +return (ret <0 ) ? ret : len; }/* * Fetch a null-terminated string. Caller MUST set *(u32 *)buf with max * length and relative data location. */ -static nokprobe_inline void -fetch_store_string (unsigned long addr,void *dest) +static nokprobe_inline int +fetch_store_string (unsigned long addr,void *dest,void *base) { -int maxlen =get_rloc_len (*(u32 *)dest); -u8 *dst =get_rloc_data (dest); +int maxlen =get_loc_len (*(u32 *)dest); +u8 *dst =get_loc_data (dest, base);long ret; -if (!maxlen) -return ; - +if (unlikely (!maxlen)) +return -ENOMEM ;/* * Try to get string again, since the string can be changed while * probing. */ ret =strncpy_from_unsafe (dst, (void *)addr, maxlen); -if (ret <0 ) {/* Failed to fetch string */ - dst[0 ] ='\0' ; - *(u32 *)dest =make_data_rloc (0 ,get_rloc_offs (*(u32 *)dest)); - }else { - *(u32 *)dest =make_data_rloc (ret,get_rloc_offs (*(u32 *)dest)); - } +if (ret >=0 ) + *(u32 *)dest =make_data_loc (ret, (void *)dst - base); +return ret; }/* Note that we don't verify it, since the code does not come from user space */ static int process_fetch_insn (struct fetch_insn *code,struct pt_regs *regs,void *dest, -bool pre) +void *base) {unsigned long val; -int ret; +int ret =0 ;/* 1st stage: get value from context */ switch (code->op) {
@@ -949,6 +942,13 @@ process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest, }/* 3rd stage: store value to buffer */ +if (unlikely (!dest)) { +if (code->op ==FETCH_OP_ST_STRING ) +return fetch_store_strlen (val + code->offset); +else +return -EILSEQ ; + } +switch (code->op) {case FETCH_OP_ST_RAW :fetch_store_raw (val, code, dest);
@@ -957,10 +957,7 @@ process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest,probe_kernel_read (dest, (void *)val + code->offset, code->size);break ;case FETCH_OP_ST_STRING : -if (pre) -fetch_store_strlen (val + code->offset, dest); -else -fetch_store_string (val + code->offset, dest); + ret =fetch_store_string (val + code->offset, dest, base);break ;default :return -EILSEQ ;
@@ -973,7 +970,7 @@ process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest, code++; } -return code->op ==FETCH_OP_END ?0 : -EILSEQ ; +return code->op ==FETCH_OP_END ? ret : -EILSEQ ; }NOKPROBE_SYMBOL (process_fetch_insn)
@@ -1008,7 +1005,7 @@ __kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs, entry =ring_buffer_event_data (event); entry->ip = (unsigned long )tk->rp.kp.addr; -store_trace_args (sizeof (*entry), &tk->tp, regs, (u8 *)&entry[1 ], dsize); +store_trace_args (&entry[1 ], &tk->tp, regs,sizeof (*entry), dsize);event_trigger_unlock_commit_regs (trace_file, buffer, event, entry, irq_flags, pc, regs);
@@ -1057,7 +1054,7 @@ __kretprobe_trace_func(struct trace_kprobe *tk, struct kretprobe_instance *ri, entry =ring_buffer_event_data (event); entry->func = (unsigned long )tk->rp.kp.addr; entry->ret_ip = (unsigned long )ri->ret_addr; -store_trace_args (sizeof (*entry), &tk->tp, regs, (u8 *)&entry[1 ], dsize); +store_trace_args (&entry[1 ], &tk->tp, regs,sizeof (*entry), dsize);event_trigger_unlock_commit_regs (trace_file, buffer, event, entry, irq_flags, pc, regs);
@@ -1203,7 +1200,7 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs) entry->ip = (unsigned long )tk->rp.kp.addr;memset (&entry[1 ],0 , dsize); -store_trace_args (sizeof (*entry), &tk->tp, regs, (u8 *)&entry[1 ], dsize); +store_trace_args (&entry[1 ], &tk->tp, regs,sizeof (*entry), dsize);perf_trace_buf_submit (entry, size, rctx, call->event.type,1 , regs, head,NULL );return 0 ;
@@ -1239,7 +1236,7 @@ kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri, entry->func = (unsigned long )tk->rp.kp.addr; entry->ret_ip = (unsigned long )ri->ret_addr; -store_trace_args (sizeof (*entry), &tk->tp, regs, (u8 *)&entry[1 ], dsize); +store_trace_args (&entry[1 ], &tk->tp, regs,sizeof (*entry), dsize);perf_trace_buf_submit (entry, size, rctx, call->event.type,1 , regs, head,NULL ); }
kernel/trace/trace_probe.h +6 -20
@@ -54,29 +54,15 @@#define TP_FLAG_PROFILE 2#define TP_FLAG_REGISTERED 4 +/* data_loc: data location, compatible with u32 */ +#define make_data_loc (len, offs) \ + (((u32)(len) << 16) | ((u32)(offs) & 0xffff)) +#define get_loc_len (dl) ((u32)(dl) >> 16) +#define get_loc_offs (dl) ((u32)(dl) & 0xffff) -/* data_rloc: data relative location, compatible with u32 */ -#define make_data_rloc (len, roffs) \ - (((u32)(len) << 16) | ((u32)(roffs) & 0xffff)) -#define get_rloc_len (dl) ((u32)(dl) >> 16) -#define get_rloc_offs (dl) ((u32)(dl) & 0xffff) - -/* -* Convert data_rloc to data_loc: -* data_rloc stores the offset from data_rloc itself, but data_loc -* stores the offset from event entry. -*/ -#define convert_rloc_to_loc (dl, offs) ((u32)(dl) + (offs)) - -static nokprobe_inline void *get_rloc_data(u32 *dl) -{ -return (u8 *)dl +get_rloc_offs (*dl); -} - -/* For data_loc conversion */ static nokprobe_inline void *get_loc_data(u32 *dl, void *ent) { -return (u8 *)ent +get_rloc_offs (*dl); +return (u8 *)ent +get_loc_offs (*dl); }/* Printing function type */
kernel/trace/trace_probe_tmpl.h +25 -29
83 lines not on this page · raw message
kernel/trace/trace_uprobe.c +30 -31
122 lines not on this page · raw message
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 7/18 tracing: probeevent: Append traceprobe_ for exported function
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Append traceprobe_ for exported function set_print_fmt() as same as other functions.
--- kernel/trace/trace_kprobe.c | 4 ++-- kernel/trace/trace_probe.c | 2 +- kernel/trace/trace_probe.h | 2 +- kernel/trace/trace_uprobe.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-)
kernel/trace/trace_kprobe.c +2 -2
@@ -1371,7 +1371,7 @@ static int register_kprobe_event(struct trace_kprobe *tk)init_trace_event_call (tk, call); -if (set_print_fmt (&tk->tp,trace_kprobe_is_return (tk)) <0 ) +if (traceprobe_set_print_fmt (&tk->tp,trace_kprobe_is_return (tk)) <0 )return -ENOMEM ; ret =register_trace_event (&call->event);if (!ret) {
@@ -1428,7 +1428,7 @@ create_local_trace_kprobe(char *func, void *addr, unsigned long offs,init_trace_event_call (tk, &tk->tp.call); -if (set_print_fmt (&tk->tp,trace_kprobe_is_return (tk)) <0 ) { +if (traceprobe_set_print_fmt (&tk->tp,trace_kprobe_is_return (tk)) <0 ) { ret = -ENOMEM ; goto error; }
kernel/trace/trace_probe.c +1 -1
@@ -490,7 +490,7 @@ static int __set_print_fmt(struct trace_probe *tp, char *buf, int len,return pos; } -int set_print_fmt (struct trace_probe *tp,bool is_return) +int traceprobe_set_print_fmt (struct trace_probe *tp,bool is_return) {int len;char *print_fmt;
kernel/trace/trace_probe.h +1 -1
@@ -254,7 +254,7 @@ extern void traceprobe_free_probe_arg(struct probe_arg *arg);extern int traceprobe_split_symbol_offset (char *symbol,long *offset); -extern int set_print_fmt (struct trace_probe *tp,bool is_return); +extern int traceprobe_set_print_fmt (struct trace_probe *tp,bool is_return);#ifdef CONFIG_PERF_EVENTS extern struct trace_event_call *
kernel/trace/trace_uprobe.c +2 -2
@@ -1370,7 +1370,7 @@ static int register_uprobe_event(struct trace_uprobe *tu)init_trace_event_call (tu, call); -if (set_print_fmt (&tu->tp,is_ret_probe (tu)) <0 ) +if (traceprobe_set_print_fmt (&tu->tp,is_ret_probe (tu)) <0 )return -ENOMEM ; ret =register_trace_event (&call->event);
@@ -1443,7 +1443,7 @@ create_local_trace_uprobe(char *name, unsigned long offs, tu->filename =kstrdup (name,GFP_KERNEL );init_trace_event_call (tu, &tu->tp.call); -if (set_print_fmt (&tu->tp,is_ret_probe (tu)) <0 ) { +if (traceprobe_set_print_fmt (&tu->tp,is_ret_probe (tu)) <0 ) { ret = -ENOMEM ; goto error; }
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 8/18 tracing: probeevent: Unify fetch_insn processing common part
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Unify the fetch_insn bottom process (from stage 2: dereference indirect data) from kprobe and uprobe events, since those are mostly same.
--- kernel/trace/trace_kprobe.c | 47 +++++----------------------- kernel/trace/trace_probe_tmpl.h | 55 ++++++++++++++++++++++++++++++++- kernel/trace/trace_uprobe.c | 43 ++------------------------ 3 files changed, 63 insertions(+), 82 deletions(-)
kernel/trace/trace_kprobe.c +7 -40
@@ -899,13 +899,18 @@ fetch_store_string(unsigned long addr, void *dest, void *base)return ret; } +static nokprobe_inline int +probe_mem_read (void *dest,void *src,size_t size) +{ +return probe_kernel_read (dest, src, size); +} +/* Note that we don't verify it, since the code does not come from user space */ static int process_fetch_insn (struct fetch_insn *code,struct pt_regs *regs,void *dest,void *base) {unsigned long val; -int ret =0 ;/* 1st stage: get value from context */ switch (code->op) {
@@ -932,45 +937,7 @@ process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest, } code++; -/* 2nd stage: dereference memory if needed */ -while (code->op ==FETCH_OP_DEREF ) { - ret =probe_kernel_read (&val, (void *)val + code->offset, -sizeof (val)); -if (ret) -return ret; - code++; - } - -/* 3rd stage: store value to buffer */ -if (unlikely (!dest)) { -if (code->op ==FETCH_OP_ST_STRING ) -return fetch_store_strlen (val + code->offset); -else -return -EILSEQ ; - } - -switch (code->op) { -case FETCH_OP_ST_RAW : -fetch_store_raw (val, code, dest); -break ; -case FETCH_OP_ST_MEM : -probe_kernel_read (dest, (void *)val + code->offset, code->size); -break ; -case FETCH_OP_ST_STRING : - ret =fetch_store_string (val + code->offset, dest, base); -break ; -default : -return -EILSEQ ; - } - code++; - -/* 4th stage: modify stored value if needed */ -if (code->op ==FETCH_OP_MOD_BF ) { -fetch_apply_bitfield (code, dest); - code++; - } - -return code->op ==FETCH_OP_END ? ret : -EILSEQ ; +return process_fetch_insn_bottom (code, val, dest, base); }NOKPROBE_SYMBOL (process_fetch_insn)
kernel/trace/trace_probe_tmpl.h +54 -1
67 lines not on this page · raw message
kernel/trace/trace_uprobe.c +2 -41
61 lines not on this page · raw message
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 9/18 tracing: probeevent: Add symbol type
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add "symbol" type to probeevent, which is an alias of u32 or u64 (depends on BITS_PER_LONG). This shows the result value in symbol+offset style. This type is only available with kprobe events.
--- Documentation/trace/kprobetrace.rst | 2 ++ kernel/trace/trace.c | 2 +- kernel/trace/trace_probe.c | 8 ++++++++ kernel/trace/trace_probe.h | 12 +++++++++--- 4 files changed, 20 insertions(+), 4 deletions(-)
Documentation/trace/kprobetrace.rst +2 -0
@@ -72,6 +72,8 @@ offset, and container-size (usually 32). The syntax is:: b<bit-width>@<bit-offset>/<container-size> +Symbol type('symbol') is an alias of u32 or u64 type (depends on BITS_PER_LONG) +which shows given pointer in "symbol+offset" style. For $comm, the default type is "string"; any other type is invalid.
kernel/trace/trace.c +1 -1
@@ -4626,7 +4626,7 @@ static const char readme_msg[] ="\t args: <name>=fetcharg[:type]\n" "\t fetcharg: %<register>, @<address>, @<symbol>[+|-<offset>],\n" "\t $stack<index>, $stack, $retval, $comm\n" -"\t type: s8/16/32/64, u8/16/32/64, x8/16/32/64, string,\n" +"\t type: s8/16/32/64, u8/16/32/64, x8/16/32/64, string, symbol,\n" "\t b<bit-width>@<bit-offset>/<container-size>\n"#endif " events/\t\t- Directory containing all trace event subsystems:\n"
kernel/trace/trace_probe.c +8 -0
@@ -46,6 +46,13 @@ DEFINE_BASIC_PRINT_TYPE_FUNC(x16, u16, "0x%x") DEFINE_BASIC_PRINT_TYPE_FUNC(x32, u32, "0x%x") DEFINE_BASIC_PRINT_TYPE_FUNC(x64, u64, "0x%Lx") +int PRINT_TYPE_FUNC_NAME (symbol )(struct trace_seq *s,void *data,void *ent) +{ +trace_seq_printf (s,"%pS" , (void *)*(unsigned long *)data); +return !trace_seq_has_overflowed (s); +} +const char PRINT_TYPE_FMT_NAME (symbol )[] ="%pS" ; +/* Print type function for string type */ int PRINT_TYPE_FUNC_NAME (string )(struct trace_seq *s,void *data,void *ent) {
@@ -79,6 +86,7 @@ static const struct fetch_type probe_fetch_types[] = {ASSIGN_FETCH_TYPE_ALIAS (x16, u16, u16,0 ),ASSIGN_FETCH_TYPE_ALIAS (x32, u32, u32,0 ),ASSIGN_FETCH_TYPE_ALIAS (x64, u64, u64,0 ), +ASSIGN_FETCH_TYPE_ALIAS (symbol,ADDR_FETCH_TYPE ,ADDR_FETCH_TYPE ,0 ), ASSIGN_FETCH_TYPE_END };
kernel/trace/trace_probe.h +9 -3
@@ -145,6 +145,7 @@ DECLARE_BASIC_PRINT_TYPE_FUNC(x32);DECLARE_BASIC_PRINT_TYPE_FUNC (x64);DECLARE_BASIC_PRINT_TYPE_FUNC (string); +DECLARE_BASIC_PRINT_TYPE_FUNC (symbol);/* Default (unsigned long) fetch type */ #define __DEFAULT_FETCH_TYPE (t) x##t
@@ -152,6 +153,10 @@ DECLARE_BASIC_PRINT_TYPE_FUNC(string);#define DEFAULT_FETCH_TYPE _DEFAULT_FETCH_TYPE(BITS_PER_LONG)#define DEFAULT_FETCH_TYPE_STR __stringify(DEFAULT_FETCH_TYPE) +#define __ADDR_FETCH_TYPE (t) u##t +#define _ADDR_FETCH_TYPE (t) __ADDR_FETCH_TYPE(t) +#define ADDR_FETCH_TYPE _ADDR_FETCH_TYPE(BITS_PER_LONG) +#define __ASSIGN_FETCH_TYPE (_name, ptype, ftype, _size, sign, _fmttype) \ {.name = _name, \ .size = _size, \
@@ -160,13 +165,14 @@ DECLARE_BASIC_PRINT_TYPE_FUNC(string); .fmt = PRINT_TYPE_FMT_NAME(ptype), \ .fmttype = _fmttype, \ } - +#define _ASSIGN_FETCH_TYPE (_name, ptype, ftype, _size, sign, _fmttype) \ + __ASSIGN_FETCH_TYPE(_name, ptype, ftype, _size, sign, #_fmttype)#define ASSIGN_FETCH_TYPE (ptype, ftype, sign) \ - __ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, #ptype) + _ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, ptype)/* If ptype is an alias of atype, use this macro (show atype in format) */ #define ASSIGN_FETCH_TYPE_ALIAS (ptype, atype, ftype, sign) \ - __ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, #atype) + _ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, atype)#define ASSIGN_FETCH_TYPE_END {}
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 10/18 tracing: probeevent: Add array type support
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add array type support for probe events.
This allows user to get arraied types from memory address. The array type syntax is
TYPE[N]
Where TYPE is one of types (u8/16/32/64,s8/16/32/64, x8/16/32/64, symbol, string) and N is a fixed value less than 64.
The string array type is a bit different from other types. For other base types, <base-type>[1] is equal to <base-type> (e.g. +0(%di):x32[1] is same as +0(%di):x32.) But string[1] is not equal to string. The string type itself represents "char array", but string array type represents "char * array". So, for example, +0(%di):string[1] is equal to +0(+0(%di)):string.
--- Documentation/trace/kprobetrace.rst | 11 +++ kernel/trace/trace.c | 3 +- kernel/trace/trace_probe.c | 130 +++++++++++++++++++++------- kernel/trace/trace_probe.h | 14 +++ kernel/trace/trace_probe_tmpl.h | 63 ++++++++++++-- 5 files changed, 181 insertions(+), 40 deletions(-)
Documentation/trace/kprobetrace.rst +11 -0
@@ -64,9 +64,20 @@ respectively. 'x' prefix implies it is unsigned. Traced arguments are shown in decimal ('s' and 'u') or hexadecimal ('x'). Without type casting, 'x32' or 'x64' is used depends on the architecture (e.g. x86-32 uses x32, and x86-64 uses x64). +These value types can be an array. To record array data, you can add '[N]' +(where N is a fixed number, less than 64) to the base type. +E.g. 'x16[4]' means an array of x16 (2bytes hex) with 4 elements. +Note that the array can be applied to memory type fetchargs, you can not +apply it to registers/stack-entries etc. (for example, '$stack1:x8[8]' is +wrong, but '+8($stack):x8[8]' is OK.) String type is a special type, which fetches a "null-terminated" string from kernel space. This means it will fail and store NULL if the string container has been paged out. +The string array type is a bit different from other types. For other base +types, <base-type>[1] is equal to <base-type> (e.g. +0(%di):x32[1] is same +as +0(%di):x32.) But string[1] is not equal to string. The string type itself +represents "char array", but string array type represents "char * array". +So, for example, +0(%di):string[1] is equal to +0(+0(%di)):string. Bitfield is another special type, which takes 3 parameters, bit-width, bit- offset, and container-size (usually 32). The syntax is::
kernel/trace/trace.c +2 -1
@@ -4627,7 +4627,8 @@ static const char readme_msg[] ="\t fetcharg: %<register>, @<address>, @<symbol>[+|-<offset>],\n" "\t $stack<index>, $stack, $retval, $comm\n" "\t type: s8/16/32/64, u8/16/32/64, x8/16/32/64, string, symbol,\n" - "\t b<bit-width>@<bit-offset>/<container-size>\n" +"\t b<bit-width>@<bit-offset>/<container-size>,\n" + "\t <type>\\[<array-size>\\]\n"#endif " events/\t\t- Directory containing all trace event subsystems:\n" " enable\t\t- Write 0/1 to enable/disable tracing of all events\n"
kernel/trace/trace_probe.c +99 -31
212 lines not on this page · raw message
kernel/trace/trace_probe.h +14 -0
@@ -30,6 +30,7 @@#define MAX_TRACE_ARGS 128#define MAX_ARGSTR_LEN 63 +#define MAX_ARRAY_LEN 64#define MAX_STRING_SIZE PATH_MAX/* Reserved field names */
@@ -65,6 +66,14 @@ static nokprobe_inline void *get_loc_data(u32 *dl, void *ent)return (u8 *)ent +get_loc_offs (*dl); } +static nokprobe_inline u32 update_data_loc(u32 loc, int consumed) +{ +u32 maxlen =get_loc_len (loc); +u32 offset =get_loc_offs (loc); + +return make_data_loc (maxlen - consumed, offset + consumed); +} +/* Printing function type */ typedef int (*print_type_func_t )(struct trace_seq *,void *,void *);
@@ -86,6 +95,8 @@ enum fetch_op {FETCH_OP_ST_STRING ,/* String: .offset, .size */ // Stage 4 (modify) op FETCH_OP_MOD_BF ,/* Bitfield: .basesize, .lshift, .rshift */ +// Stage 5 (loop) op +FETCH_OP_LP_ARRAY ,/* Array: .param = loop count */ FETCH_OP_END, };
@@ -175,6 +186,7 @@ DECLARE_BASIC_PRINT_TYPE_FUNC(symbol); _ASSIGN_FETCH_TYPE(#ptype, ptype, ftype, sizeof(ftype), sign, atype)#define ASSIGN_FETCH_TYPE_END {} +#define MAX_ARRAY_LEN 64#ifdef CONFIG_KPROBE_EVENTS bool trace_kprobe_on_func_entry (struct trace_event_call *call);
@@ -195,8 +207,10 @@ struct probe_arg {struct fetch_insn *code;bool dynamic;/* Dynamic array (string) is used */ unsigned int offset;/* Offset from argument entry */ +unsigned int count;/* Array count */ const char *name;/* Name of this argument */ const char *comm;/* Command of this argument */ +char *fmt;/* Format string if needed */ const struct fetch_type *type;/* Type of this argument */ };
kernel/trace/trace_probe_tmpl.h +55 -8
100 lines not on this page · raw message
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 11/18 x86: ptrace: Add function argument access API
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add regs_get_argument() which returns N th argument of the function call.
Note that this chooses most probably assignment, in some case it can be incorrect (e.g. passing data structure or floating point etc.)
This is expected to be called from kprobes or ftrace with regs where the top of stack is the return address.
--- arch/Kconfig | 7 +++++++ arch/x86/Kconfig | 1 + arch/x86/include/asm/ptrace.h | 38 +++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+)
arch/Kconfig +7 -0
@@ -290,6 +290,13 @@ config HAVE_RSEQ This symbol should be selected by an architecture if it supports an implementation of restartable sequences. +config HAVE_FUNCTION_ARG_ACCESS_API + bool + help + This symbol should be selected by an architecure if it supports + the API needed to access function arguments from pt_regs, + declared in asm/ptrace.h + config HAVE_CLK bool help
arch/x86/Kconfig +1 -0
@@ -184,6 +184,7 @@ config X86 select HAVE_RCU_TABLE_INVALIDATE if HAVE_RCU_TABLE_FREE select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE if X86_64 && (UNWINDER_FRAME_POINTER || UNWINDER_ORC) && STACK_VALIDATION + select HAVE_FUNCTION_ARG_ACCESS_API select HAVE_STACKPROTECTOR if CC_HAS_SANE_STACKPROTECTOR select HAVE_STACK_VALIDATION if X86_64 select HAVE_RSEQ
arch/x86/include/asm/ptrace.h +38 -0
@@ -256,6 +256,44 @@ static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,return 0 ; } +/** +* regs_get_kernel_argument() - get Nth function argument in kernel +* @regs: pt_regs of that context +* @n: function argument number (start from 0) +* +* regs_get_argument() returns @n th argument of the function call. +* Note that this chooses most probably assignment, in some case +* it can be incorrect. +* This is expected to be called from kprobes or ftrace with regs +* where the top of stack is the return address. +*/ +static inline unsigned long regs_get_kernel_argument (struct pt_regs *regs, +unsigned int n) +{ +static const unsigned int argument_offs[] = { +#ifdef __i386__ + offsetof(struct pt_regs , ax), + offsetof(struct pt_regs , cx), + offsetof(struct pt_regs , dx), +#define NR_REG_ARGUMENTS 3 +#else + offsetof(struct pt_regs , di), + offsetof(struct pt_regs , si), + offsetof(struct pt_regs , dx), + offsetof(struct pt_regs , cx), + offsetof(struct pt_regs , r8), + offsetof(struct pt_regs , r9), +#define NR_REG_ARGUMENTS 6 +#endif + }; + +if (n >=NR_REG_ARGUMENTS ) { + n -=NR_REG_ARGUMENTS -1 ; +return regs_get_kernel_stack_nth (regs, n); + }else +return regs_get_register (regs, argument_offs[n]); +} +#define arch_has_single_step () (1)#ifdef CONFIG_X86_DEBUGCTLMSR #define arch_has_block_step () (1)
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 12/18 tracing: probeevent: Add $argN for accessing function args
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add $argN special fetch variable for accessing function arguments. This allows user to trace the Nth argument easily at the function entry.
Note that this returns most probably assignment of registers and stacks. In some case, it may not work well. If you need to access correct registers or stacks you should use perf-probe.
--- Documentation/trace/kprobetrace.rst | 10 ++++---- kernel/trace/trace.c | 4 ++++ kernel/trace/trace_kprobe.c | 18 +++++++++++---- kernel/trace/trace_probe.c | 36 ++++++++++++++++++----------- kernel/trace/trace_probe.h | 9 +++++++- kernel/trace/trace_uprobe.c | 2 +- 6 files changed, 55 insertions(+), 24 deletions(-)
Documentation/trace/kprobetrace.rst +6 -4
@@ -45,16 +45,18 @@ Synopsis of kprobe_events @SYM[+|-offs] : Fetch memory at SYM +|- offs (SYM should be a data symbol) $stackN : Fetch Nth entry of stack (N >= 0) $stack : Fetch stack address. - $retval : Fetch return value.(*) + $argN : Fetch the Nth function argument. (N >= 1) (\*1) + $retval : Fetch return value.(\*2) $comm : Fetch current task comm. - +|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**) + +|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(\*3) NAME=FETCHARG : Set NAME as the argument name of FETCHARG. FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types (u8/u16/u32/u64/s8/s16/s32/s64), hexadecimal types (x8/x16/x32/x64), "string" and bitfield are supported. - (*) only for return probe. - (**) this is useful for fetching a field of data structures. + (\*1) only for the probe on function entry (offs == 0). + (\*2) only for return probe. + (\*3) this is useful for fetching a field of data structures. Types -----
kernel/trace/trace.c +4 -0
@@ -4625,7 +4625,11 @@ static const char readme_msg[] =#endif "\t args: <name>=fetcharg[:type]\n" "\t fetcharg: %<register>, @<address>, @<symbol>[+|-<offset>],\n" +#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API + "\t $stack<index>, $stack, $retval, $comm, $arg<N>\n" +#else"\t $stack<index>, $stack, $retval, $comm\n" +#endif"\t type: s8/16/32/64, u8/16/32/64, x8/16/32/64, string, symbol,\n" "\t b<bit-width>@<bit-offset>/<container-size>,\n" "\t <type>\\[<array-size>\\]\n"
kernel/trace/trace_kprobe.c +13 -5
@@ -533,13 +533,15 @@ static int create_trace_kprobe(int argc, char **argv)long offset =0 ;void *addr =NULL ;char buf[MAX_EVENT_NAME_LEN ]; +unsigned int flags =TPARG_FL_KERNEL ;/* argc must be >= 1 */ if (argv[0 ][0 ] =='p' ) is_return = false; -else if (argv[0 ][0 ] =='r' ) +else if (argv[0 ][0 ] =='r' ) { is_return = true; -else if (argv[0 ][0 ] =='-' ) + flags |=TPARG_FL_RETURN ; + }else if (argv[0 ][0 ] =='-' ) is_delete = true;else { pr_info("Probe definition must be started with 'p', 'r' or"
@@ -625,8 +627,9 @@ static int create_trace_kprobe(int argc, char **argv)pr_info ("Failed to parse either an address or a symbol.\n" );return ret; } -if (offset && is_return && - !kprobe_on_func_entry (NULL , symbol, offset)) { +if (kprobe_on_func_entry (NULL , symbol, offset)) + flags |=TPARG_FL_FENTRY ; +if (offset && is_return && !(flags &TPARG_FL_FENTRY )) {pr_info ("Given offset is not valid for return probe.\n" );return -EINVAL ; }
@@ -696,7 +699,7 @@ static int create_trace_kprobe(int argc, char **argv)/* Parse fetch argument */ ret =traceprobe_parse_probe_arg (arg, &tk->tp.size, parg, - is_return, true); + flags);if (ret) {pr_info ("Parse error at argument[%d]. (%d)\n" , i, ret); goto error;
@@ -932,6 +935,11 @@ process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest,case FETCH_OP_COMM : val = (unsigned long )current->comm;break ; +#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API +case FETCH_OP_ARG : + val =regs_get_kernel_argument (regs, code->param); +break ; +#endif default :return -EILSEQ ; }
kernel/trace/trace_probe.c +23 -13
@@ -157,14 +157,13 @@ int traceprobe_split_symbol_offset(char *symbol, long *offset)#define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long))static int parse_probe_vars (char *arg,const struct fetch_type *t, -struct fetch_insn *code,bool is_return, -bool is_kprobe) +struct fetch_insn *code,unsigned int flags) {int ret =0 ;unsigned long param;if (strcmp (arg,"retval" ) ==0 ) { -if (is_return) +if (flags &TPARG_FL_RETURN ) code->op =FETCH_OP_RETVAL ;else ret = -EINVAL ;
@@ -173,7 +172,8 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t, code->op =FETCH_OP_STACKP ; }else if (isdigit (arg[5 ])) { ret =kstrtoul (arg +5 ,10 , ¶m); -if (ret || (is_kprobe && param >PARAM_MAX_STACK )) +if (ret || ((flags &TPARG_FL_KERNEL ) && + param >PARAM_MAX_STACK )) ret = -EINVAL ;else { code->op =FETCH_OP_STACK ;
@@ -183,6 +183,18 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t, ret = -EINVAL ; }else if (strcmp (arg,"comm" ) ==0 ) { code->op =FETCH_OP_COMM ; +#ifdef CONFIG_HAVE_FUNCTION_ARG_ACCESS_API + }else if (((flags &TPARG_FL_MASK ) == + (TPARG_FL_KERNEL |TPARG_FL_FENTRY )) && +strncmp (arg,"arg" ,3 ) ==0 ) { +if (!isdigit (arg[3 ])) +return -EINVAL ; + ret =kstrtoul (arg +3 ,10 , ¶m); +if (ret || !param || param >PARAM_MAX_STACK ) +return -EINVAL ; + code->op =FETCH_OP_ARG ; + code->param = (unsigned int )param -1 ; +#endif }else ret = -EINVAL ;
@@ -193,7 +205,7 @@ static int parse_probe_vars(char *arg, const struct fetch_type *t,static int parse_probe_arg (char *arg,const struct fetch_type *type,struct fetch_insn **pcode,struct fetch_insn *end, -bool is_return,bool is_kprobe) +unsigned int flags) {struct fetch_insn *code = *pcode;unsigned long param;
@@ -203,8 +215,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type,switch (arg[0 ]) {case '$' : - ret =parse_probe_vars (arg +1 , type, code, - is_return, is_kprobe); + ret =parse_probe_vars (arg +1 , type, code, flags);break ;case '%' :/* named register */
@@ -226,7 +237,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type, code->immediate = param; }else if (arg[1 ] =='+' ) {/* kprobes don't support file offsets */ -if (is_kprobe) +if (flags &TPARG_FL_KERNEL )return -EINVAL ; ret =kstrtol (arg +2 ,0 , &offset);
@@ -237,7 +248,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type, code->immediate = (unsigned long )offset;// imm64? }else {/* uprobes don't support symbols */ -if (!is_kprobe) +if (!(flags &TPARG_FL_KERNEL ))return -EINVAL ; ret =traceprobe_split_symbol_offset (arg +1 , &offset);
@@ -278,8 +289,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type,const struct fetch_type *t2 =find_fetch_type (NULL ); *tmp ='\0' ; - ret =parse_probe_arg (arg, t2, &code, end, is_return, - is_kprobe); + ret =parse_probe_arg (arg, t2, &code, end, flags);if (ret)break ;if (code->op ==FETCH_OP_COMM )
@@ -339,7 +349,7 @@ static int __parse_bitfield_probe_arg(const char *bf,/* String length checking wrapper */ int traceprobe_parse_probe_arg (char *arg,ssize_t *size, -struct probe_arg *parg,bool is_return,bool is_kprobe) +struct probe_arg *parg,unsigned int flags) {struct fetch_insn *code, *scode, *tmp =NULL ;char *t, *t2;
@@ -397,7 +407,7 @@ int traceprobe_parse_probe_arg(char *arg, ssize_t *size, code[FETCH_INSN_MAX -1 ].op =FETCH_OP_END ; ret =parse_probe_arg (arg, parg->type, &code, &code[FETCH_INSN_MAX -1 ], - is_return, is_kprobe); + flags);if (ret) goto fail;
kernel/trace/trace_probe.h +8 -1
@@ -23,6 +23,7 @@#include <linux/stringify.h> #include <linux/limits.h> #include <linux/uaccess.h> +#include <linux/bitops.h> #include <asm/bitsperlong.h> #include "trace.h"
@@ -86,6 +87,7 @@ enum fetch_op {FETCH_OP_RETVAL ,/* Return value */ FETCH_OP_IMM ,/* Immediate : .immediate */ FETCH_OP_COMM ,/* Current comm */ +FETCH_OP_ARG ,/* Function argument : .param */ FETCH_OP_FOFFS ,/* File offset: .immediate */ // Stage 2 (dereference) op FETCH_OP_DEREF, /* Dereference: .offset */
@@ -263,8 +265,13 @@ find_event_file_link(struct trace_probe *tp, struct trace_event_file *file)return NULL ; } +#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) +extern int traceprobe_parse_probe_arg (char *arg,ssize_t *size, -struct probe_arg *parg,bool is_return,bool is_kprobe); +struct probe_arg *parg,unsigned int flags);extern int traceprobe_conflict_field_name (const char *name,struct probe_arg *args,int narg);
kernel/trace/trace_uprobe.c +1 -1
@@ -557,7 +557,7 @@ static int create_trace_uprobe(int argc, char **argv)/* Parse fetch argument */ ret =traceprobe_parse_probe_arg (arg, &tu->tp.size, parg, - is_return, false); + is_return ?TPARG_FL_RETURN :0 );if (ret) {pr_info ("Parse error at argument[%d]. (%d)\n" , i, ret); goto error;
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 13/18 tracing/uprobes: Fix to return -EFAULT if copy_from_user failed
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Fix probe_mem_read() to return -EFAULT if copy_from_user() failed. The copy_from_user() returns remaining bytes when it failed, but probe_mem_read() caller expects it returns error code like as probe_kernel_read().
--- kernel/trace/trace_uprobe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_uprobe.c +1 -1
@@ -105,7 +105,7 @@ probe_mem_read(void *dest, void *src, size_t size) {void __user *vaddr = (void __force __user *)src; -return copy_from_user (dest, vaddr, size); +return copy_from_user (dest, vaddr, size) ? -EFAULT :0 ; }/* * Fetch a null-terminated string. Caller MUST set *(u32 *)dest with max
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 14/18 tracing/kprobes: Check the probe on unloaded module correctly
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Current kprobe event doesn't checks correctly whether the given event is on unloaded module or not. It just checks the event has ":" in the name.
That is not enough because if we define a probe on non-exist symbol on loaded module, it allows to define that (with warning message)
To ensure it correctly, this searches the module name on loaded module list and only if there is not, it allows to define it. (this event will be available when the target module is loaded)
--- kernel/trace/trace_kprobe.c | 39 ++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-)
kernel/trace/trace_kprobe.c +26 -13
@@ -62,9 +62,23 @@ static nokprobe_inline bool trace_kprobe_within_module(struct trace_kprobe *tk,return strncmp (mod->name, name, len) ==0 && name[len] ==':' ; } -static nokprobe_inline bool trace_kprobe_is_on_module(struct trace_kprobe *tk) +static nokprobe_inline bool trace_kprobe_module_exist(struct trace_kprobe *tk) { -return !!strchr (trace_kprobe_symbol (tk),':' ); +char *p; +bool ret; + +if (!tk->symbol) +return false; + p =strchr (tk->symbol,':' ); +if (!p) +return true; + *p ='\0' ; +mutex_lock (&module_mutex); + ret = !!find_module (tk->symbol); +mutex_unlock (&module_mutex); + *p =':' ; + +return ret; }static nokprobe_inline unsigned long trace_kprobe_nhit (struct trace_kprobe *tk)
@@ -374,19 +388,13 @@ static int __register_trace_kprobe(struct trace_kprobe *tk)else ret =register_kprobe (&tk->rp.kp); -if (ret ==0 ) +if (ret ==0 ) { tk->tp.flags |=TP_FLAG_REGISTERED ; -else { -if (ret == -ENOENT &&trace_kprobe_is_on_module (tk)) { -pr_warn ("This probe might be able to register after target module is loaded. Continue.\n" ); - ret =0 ; - }else if (ret == -EILSEQ ) { -pr_warn ("Probing address(0x%p) is not an instruction boundary.\n" , - tk->rp.kp.addr); - ret = -EINVAL ; - } + }else if (ret == -EILSEQ ) { +pr_warn ("Probing address(0x%p) is not an instruction boundary.\n" , + tk->rp.kp.addr); + ret = -EINVAL ; } -return ret; }
@@ -449,6 +457,11 @@ static int register_trace_kprobe(struct trace_kprobe *tk)/* 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 <0 )unregister_kprobe_event (tk);else
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 15/18 tracing/kprobes: Allow kprobe-events to record module symbol
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Allow kprobe-events to record module symbols.
Since data symbols in a non-loaded module doesn't exist, it fails to define such symbol as an argument of kprobe-event. But if the kprobe event is defined on that module, we can defer to resolve the symbol address.
Note that if given symbol is not found, the event is kept unavailable. User can enable it but the event is not recorded.
--- kernel/trace/trace_kprobe.c | 12 ++++++- kernel/trace/trace_probe.c | 62 ++++++++++++++++++++++++++++++++----- kernel/trace/trace_probe.h | 4 ++- 3 files changed, 68 insertions(+), 10 deletions(-)
kernel/trace/trace_kprobe.c +11 -1
@@ -366,7 +366,7 @@ static bool within_notrace_func(struct trace_kprobe *tk)/* Internal register function - just handle k*probes and flags */ static int __register_trace_kprobe (struct trace_kprobe *tk) { -int ret; +int i, ret;if (trace_probe_is_registered (&tk->tp))return -EINVAL ;
@@ -377,6 +377,12 @@ static int __register_trace_kprobe(struct trace_kprobe *tk)return -EINVAL ; } +for (i =0 ; i < tk->tp.nr_args; i++) { + ret =traceprobe_update_arg (&tk->tp.args[i]); +if (ret) +return ret; + } +/* Set/clear disabled flag according to tp->flag */ if (trace_probe_is_enabled (&tk->tp)) tk->rp.kp.flags &= ~KPROBE_FLAG_DISABLED ;
@@ -928,6 +934,7 @@ process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest, {unsigned long val; +retry:/* 1st stage: get value from context */ switch (code->op) {case FETCH_OP_REG :
@@ -953,6 +960,9 @@ process_fetch_insn(struct fetch_insn *code, struct pt_regs *regs, void *dest, val =regs_get_kernel_argument (regs, code->param);break ;#endif +case FETCH_NOP_SYMBOL :/* Ignore a place holder */ + code++; + goto retry;default :return -EILSEQ ; }
kernel/trace/trace_probe.c +54 -8
88 lines not on this page · raw message
kernel/trace/trace_probe.h +3 -1
@@ -100,6 +100,7 @@ enum fetch_op {// Stage 5 (loop) op FETCH_OP_LP_ARRAY ,/* Array: .param = loop count */ FETCH_OP_END , + FETCH_NOP_SYMBOL, /* Unresolved Symbol holder */ }; struct fetch_insn {
@@ -116,6 +117,7 @@ struct fetch_insn {unsigned char rshift; };unsigned long immediate; +void *data; }; };
@@ -276,7 +278,7 @@ extern int traceprobe_parse_probe_arg(char *arg, ssize_t *size,extern int traceprobe_conflict_field_name (const char *name,struct probe_arg *args,int narg); -extern void traceprobe_update_arg (struct probe_arg *arg); +extern int traceprobe_update_arg (struct probe_arg *arg);extern void traceprobe_free_probe_arg (struct probe_arg *arg);extern int traceprobe_split_symbol_offset (char *symbol,long *offset);
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 16/18 tracing: probeevent: Fix uninitialized used of offset in parse args
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
Dan's smatch utility found an uninitialized use of offset in a path in parse_probe_args(). Unless an offset is specifically specified for commands that allow them, it should default to zero.
--- kernel/trace/trace_probe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_probe.c +1 -1
@@ -209,7 +209,7 @@ parse_probe_arg(char *arg, const struct fetch_type *type, {struct fetch_insn *code = *pcode;unsigned long param; -long offset; +long offset =0 ;char *tmp;int ret =0 ;
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 17/18 tracing: Export trace_dump_stack to modules
In reply to Steven RostedtFrom: Nikolay Borisov <[email protected]>
There is no reason for this function to be unexprted and it's a useful debugging aid.
--- kernel/trace/trace.c | 1 + 1 file changed, 1 insertion(+)
kernel/trace/trace.c +1 -0
@@ -2727,6 +2727,7 @@ void trace_dump_stack(int skip)__ftrace_trace_stack (global_trace.trace_buffer.buffer, flags, skip,preempt_count (),NULL ); } +EXPORT_SYMBOL_GPL (trace_dump_stack); static DEFINE_PER_CPU(int, user_stack_count);
Signature · 1 line
2.19.0
Steven Rostedt
maintainerPATCH 18/18 tracing: Have stack tracer trace full stack
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
The stack tracer traces every function call checking the current stack (in non interrupt context), looking for the deepest stack, and saving it when it finds a new max depth. The problem is that it calls save_stack_trace(), and with the new ORC unwinder, it can skip too much. As it looks at the ip of the function call in the backtrace to find where it should start, it doesn't need to skip anything.
The stack trace selftest would fail when the kernel was complied with the ORC UNDWINDER enabled. Without skipping functions when doing the stack trace, it now passes again.
--- kernel/trace/trace_stack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_stack.c +1 -1
@@ -111,7 +111,7 @@ check_stack(unsigned long ip, unsigned long *stack) stack_trace_max_size = this_size; stack_trace_max.nr_entries =0 ; - stack_trace_max.skip =3 ; + stack_trace_max.skip =0 ;save_stack_trace (&stack_trace_max);
Signature · 1 line
2.19.0