tracing: More updates for 5.3
Subsystems (3)
Steven Rostedt
maintainercover tracing: More updates for 5.3
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next
Head SHA1: 730a95953b1f4816cc50793c2de1f339b4c2818c
Gustavo A. R. Silva (1):
tracepoint: Use struct_size() in kmalloc()
Masami Hiramatsu (10):
kprobes: Fix to init kprobes in subsys_initcall tracing/kprobe: Set print format right after parsed command tracing/uprobe: Set print format when parsing command tracing/probe: Add trace_probe init and free functions tracing/probe: Add trace_event_call register API for trace_probe tracing/probe: Add trace_event_file access APIs for trace_probe tracing/probe: Add trace flag access APIs for trace_probe tracing/probe: Add probe event name and group name accesses APIs tracing/probe: Add trace_event_call accesses APIs tracing/kprobe: Check registered state using kprobe
Steven Rostedt (VMware) (1):
ring-buffer: Remove HAVE_64BIT_ALIGNED_ACCESS
----
arch/Kconfig | 16 --- kernel/kprobes.c | 2 +- kernel/trace/ring_buffer.c | 17 +-- kernel/trace/trace_kprobe.c | 247 +++++++++++++++++--------------------------- kernel/trace/trace_probe.c | 105 ++++++++++++++++++- kernel/trace/trace_probe.h | 74 ++++++++++--- kernel/trace/trace_uprobe.c | 161 +++++++++-------------------- kernel/tracepoint.c | 4 +- 8 files changed, 312 insertions(+), 314 deletions(-)
Steven Rostedt
maintainerPATCH 1/12 ring-buffer: Remove HAVE_64BIT_ALIGNED_ACCESS
From: "Steven Rostedt (VMware)" <[email protected]>
Commit c19fa94a8fed ("Add HAVE_64BIT_ALIGNED_ACCESS") added the config for architectures that required 64bit aligned access for all 64bit words. As the ftrace ring buffer stores data on 4 byte alignment, this config option was used to force it to store data on 8 byte alignment to make sure the data being stored and written directly into the ring buffer was 8 byte aligned as it would cause issues trying to write an 8 byte word on a 4 not 8 byte aligned memory location.
But with the removal of the metag architecture, which was the only architecture to use this, there is no architecture supported by Linux that requires 8 byte aligne access for all 8 byte words (4 byte alignment is good enough). Removing this config can simplify the code a bit.
--- arch/Kconfig | 16 ---------------- kernel/trace/ring_buffer.c | 17 ++++------------- 2 files changed, 4 insertions(+), 29 deletions(-)
arch/Kconfig +0 -16
@@ -128,22 +128,6 @@ config UPROBES managed by the kernel and kept transparent to the probed application. ) -config HAVE_64BIT_ALIGNED_ACCESS - def_bool 64BIT && !HAVE_EFFICIENT_UNALIGNED_ACCESS - help - Some architectures require 64 bit accesses to be 64 bit - aligned, which also requires structs containing 64 bit values - to be 64 bit aligned too. This includes some 32 bit - architectures which can do 64 bit accesses, as well as 64 bit - architectures without unaligned access. - - This symbol should be selected by an architecture if 64 bit - accesses are required to be 64 bit aligned in this way even - though it is not a 64 bit architecture. - - See Documentation/unaligned-memory-access.txt for more - information on the topic of unaligned memory accesses. - config HAVE_EFFICIENT_UNALIGNED_ACCESS bool help
kernel/trace/ring_buffer.c +4 -13
@@ -128,16 +128,7 @@ int ring_buffer_print_entry_header(struct trace_seq *s)#define RB_ALIGNMENT 4U#define RB_MAX_SMALL_DATA (RB_ALIGNMENT * RINGBUF_TYPE_DATA_TYPE_LEN_MAX)#define RB_EVNT_MIN_SIZE 8U/* two 32bit words */ - -#ifndef CONFIG_HAVE_64BIT_ALIGNED_ACCESS -# define RB_FORCE_8BYTE_ALIGNMENT 0 -# define RB_ARCH_ALIGNMENT RB_ALIGNMENT -#else -# define RB_FORCE_8BYTE_ALIGNMENT 1 -# define RB_ARCH_ALIGNMENT 8U -#endif - -#define RB_ALIGN_DATA __aligned(RB_ARCH_ALIGNMENT) +#define RB_ALIGN_DATA __aligned(RB_ALIGNMENT)/* define RINGBUF_TYPE_DATA for 'case RINGBUF_TYPE_DATA:' */ #define RINGBUF_TYPE_DATA 0 ... RINGBUF_TYPE_DATA_TYPE_LEN_MAX
@@ -2373,7 +2364,7 @@ rb_update_event(struct ring_buffer_per_cpu *cpu_buffer, event->time_delta = delta; length -=RB_EVNT_HDR_SIZE ; -if (length >RB_MAX_SMALL_DATA ||RB_FORCE_8BYTE_ALIGNMENT ) { +if (length >RB_MAX_SMALL_DATA ) { event->type_len =0 ; event->array[0 ] = length; }else
@@ -2388,11 +2379,11 @@ static unsigned rb_calculate_event_length(unsigned length)if (!length) length++; -if (length >RB_MAX_SMALL_DATA ||RB_FORCE_8BYTE_ALIGNMENT ) +if (length >RB_MAX_SMALL_DATA ) length +=sizeof (event.array[0 ]); length +=RB_EVNT_HDR_SIZE ; - length =ALIGN (length,RB_ARCH_ALIGNMENT ); + length =ALIGN (length,RB_ALIGNMENT );/* * In case the time delta is larger than the 27 bits for it
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 2/12 tracepoint: Use struct_size() in kmalloc()
In reply to Steven RostedtFrom: "Gustavo A. R. Silva" <[email protected]>
One of the more common cases of allocation size calculations is finding the size of a structure that has a zero-sized array at the end, along with memory for some number of elements for that array. For example:
struct tp_probes {
...
struct tracepoint_func probes[0];
};instance = kmalloc(sizeof(sizeof(struct tp_probes) +
sizeof(struct tracepoint_func) * count, GFP_KERNEL);
Instead of leaving these open-coded and prone to type mistakes, we can now use the new struct_size() helper:
instance = kmalloc(struct_size(instance, probes, count) GFP_KERNEL);
This code was detected with the help of Coccinelle.
--- kernel/tracepoint.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/tracepoint.c +2 -2
@@ -68,8 +68,8 @@ struct tp_probes {static inline void *allocate_probes (int count) { -struct tp_probes *p =kmalloc (count *sizeof (struct tracepoint_func ) - +sizeof (struct tp_probes ),GFP_KERNEL ); +struct tp_probes *p =kmalloc (struct_size (p, probes, count), +GFP_KERNEL );return p ==NULL ?NULL : p->probes; }
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 3/12 kprobes: Fix to init kprobes in subsys_initcall
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Since arm64 kernel initializes breakpoint trap vector in arch_initcall(), initializing kprobe (and run smoke test) in postcore_initcall() causes a kernel panic.
To fix this issue, move the kprobe initialization in subsys_initcall() (which is called right afer the arch_initcall).
In-kernel kprobe users (ftrace and bpf) are using fs_initcall() which is called after subsys_initcall(), so this shouldn't cause more problem.
--- kernel/kprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kprobes.c +1 -1
@@ -2289,7 +2289,7 @@ static int __init init_kprobes(void)init_test_probes ();return err; } -postcore_initcall (init_kprobes); +subsys_initcall (init_kprobes);#ifdef CONFIG_DEBUG_FS static void report_probe(struct seq_file *pi, struct kprobe *p,
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 4/12 tracing/kprobe: Set print format right after parsed command
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Set event call's print format right after parsed command for simplifying (un)register_kprobe_event().
--- kernel/trace/trace_kprobe.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-)
kernel/trace/trace_kprobe.c +9 -16
@@ -272,6 +272,7 @@ static void free_trace_kprobe(struct trace_kprobe *tk)kfree (tk->tp.call.class->system);kfree (tk->tp.call.name); +kfree (tk->tp.call.print_fmt);kfree (tk->symbol);free_percpu (tk->nhit);kfree (tk);
@@ -730,6 +731,10 @@ static int trace_kprobe_create(int argc, const char *argv[]) goto error;/* This can be -ENOMEM */ } + ret =traceprobe_set_print_fmt (&tk->tp, is_return); +if (ret <0 ) + goto error; + ret =register_trace_kprobe (tk);if (ret) {trace_probe_log_set_index (1 );
@@ -1416,18 +1421,14 @@ static int register_kprobe_event(struct trace_kprobe *tk)init_trace_event_call (tk, call); -if (traceprobe_set_print_fmt (&tk->tp,trace_kprobe_is_return (tk)) <0 ) -return -ENOMEM ; ret =register_trace_event (&call->event); -if (!ret) { -kfree (call->print_fmt); +if (!ret)return -ENODEV ; - } + ret =trace_add_event_call (call);if (ret) {pr_info ("Failed to register kprobe event: %s\n" ,trace_event_name (call)); -kfree (call->print_fmt);unregister_trace_event (&call->event); }return ret;
@@ -1435,13 +1436,8 @@ static int register_kprobe_event(struct trace_kprobe *tk)static int unregister_kprobe_event (struct trace_kprobe *tk) { -int ret; -/* tp->event is unregistered in trace_remove_event_call() */ - ret =trace_remove_event_call (&tk->tp.call); -if (!ret) -kfree (tk->tp.call.print_fmt); -return ret; +return trace_remove_event_call (&tk->tp.call); }#ifdef CONFIG_PERF_EVENTS
@@ -1479,10 +1475,8 @@ create_local_trace_kprobe(char *func, void *addr, unsigned long offs, } ret =__register_trace_kprobe (tk); -if (ret <0 ) { -kfree (tk->tp.call.print_fmt); +if (ret <0 ) goto error; - }return &tk->tp.call; error:
@@ -1503,7 +1497,6 @@ void destroy_local_trace_kprobe(struct trace_event_call *event_call)__unregister_trace_kprobe (tk); -kfree (tk->tp.call.print_fmt); free_trace_kprobe(tk); }#endif /* CONFIG_PERF_EVENTS */
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 5/12 tracing/uprobe: Set print format when parsing command
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Set event call's print format right after parsed command for simplifying (un)register_uprobe_event().
--- kernel/trace/trace_uprobe.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-)
kernel/trace/trace_uprobe.c +7 -18
@@ -345,6 +345,7 @@ static void free_trace_uprobe(struct trace_uprobe *tu)path_put (&tu->path);kfree (tu->tp.call.class->system);kfree (tu->tp.call.name); +kfree (tu->tp.call.print_fmt);kfree (tu->filename);kfree (tu); }
@@ -592,6 +593,10 @@ static int trace_uprobe_create(int argc, const char **argv) goto error; } + ret =traceprobe_set_print_fmt (&tu->tp,is_ret_probe (tu)); +if (ret <0 ) + goto error; + ret =register_trace_uprobe (tu);if (!ret) goto out;
@@ -1362,21 +1367,15 @@ static int register_uprobe_event(struct trace_uprobe *tu)init_trace_event_call (tu, call); -if (traceprobe_set_print_fmt (&tu->tp,is_ret_probe (tu)) <0 ) -return -ENOMEM ; - ret =register_trace_event (&call->event); -if (!ret) { -kfree (call->print_fmt); +if (!ret)return -ENODEV ; - } ret =trace_add_event_call (call);if (ret) {pr_info ("Failed to register uprobe event: %s\n" ,trace_event_name (call)); -kfree (call->print_fmt);unregister_trace_event (&call->event); }
@@ -1385,15 +1384,8 @@ static int register_uprobe_event(struct trace_uprobe *tu)static int unregister_uprobe_event (struct trace_uprobe *tu) { -int ret; -/* tu->event is unregistered in trace_remove_event_call() */ - ret =trace_remove_event_call (&tu->tp.call); -if (ret) -return ret; -kfree (tu->tp.call.print_fmt); - tu->tp.call.print_fmt =NULL ; -return 0 ; +return trace_remove_event_call (&tu->tp.call); }#ifdef CONFIG_PERF_EVENTS
@@ -1452,9 +1444,6 @@ void destroy_local_trace_uprobe(struct trace_event_call *event_call) tu = container_of(event_call, struct trace_uprobe, tp.call); -kfree (tu->tp.call.print_fmt); - tu->tp.call.print_fmt =NULL ; - free_trace_uprobe(tu); }#endif /* CONFIG_PERF_EVENTS */
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 6/12 tracing/probe: Add trace_probe init and free functions
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add common trace_probe init and cleanup function in trace_probe.c, and use it from trace_kprobe.c and trace_uprobe.c
--- kernel/trace/trace_kprobe.c | 49 ++++++++++--------------------------- kernel/trace/trace_probe.c | 36 +++++++++++++++++++++++++++ kernel/trace/trace_probe.h | 4 +++ kernel/trace/trace_uprobe.c | 27 ++++---------------- 4 files changed, 58 insertions(+), 58 deletions(-)
kernel/trace/trace_kprobe.c +13 -36
@@ -197,6 +197,16 @@ static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs);static int kretprobe_dispatcher (struct kretprobe_instance *ri,struct pt_regs *regs); +static void free_trace_kprobe (struct trace_kprobe *tk) +{ +if (tk) { +trace_probe_cleanup (&tk->tp); +kfree (tk->symbol); +free_percpu (tk->nhit); +kfree (tk); + } +} +/* * Allocate new trace_probe and initialize it (including kprobes). */
@@ -235,49 +245,17 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group, tk->rp.maxactive = maxactive; -if (!event || !group) { - ret = -EINVAL ; - goto error; - } - - tk->tp.call.class = &tk->tp.class; - tk->tp.call.name =kstrdup (event,GFP_KERNEL ); -if (!tk->tp.call.name) - goto error; - - tk->tp.class.system =kstrdup (group,GFP_KERNEL ); -if (!tk->tp.class.system) + ret =trace_probe_init (&tk->tp, event, group); +if (ret <0 ) goto error;dyn_event_init (&tk->devent, &trace_kprobe_ops); -INIT_LIST_HEAD (&tk->tp.files);return tk; error: -kfree (tk->tp.call.name); -kfree (tk->symbol); -free_percpu (tk->nhit); -kfree (tk); +free_trace_kprobe (tk);return ERR_PTR (ret); } -static void free_trace_kprobe (struct trace_kprobe *tk) -{ -int i; - -if (!tk) -return ; - -for (i =0 ; i < tk->tp.nr_args; i++) -traceprobe_free_probe_arg (&tk->tp.args[i]); - -kfree (tk->tp.call.class->system); -kfree (tk->tp.call.name); -kfree (tk->tp.call.print_fmt); -kfree (tk->symbol); -free_percpu (tk->nhit); -kfree (tk); -} -static struct trace_kprobe *find_trace_kprobe (const char *event,const char *group) {
@@ -1400,7 +1378,6 @@ static struct trace_event_functions kprobe_funcs = {static inline void init_trace_event_call (struct trace_kprobe *tk,struct trace_event_call *call) { -INIT_LIST_HEAD (&call->class->fields);if (trace_kprobe_is_return (tk)) { call->event.funcs = &kretprobe_funcs; call->class->define_fields = kretprobe_event_define_fields;
kernel/trace/trace_probe.c +36 -0
@@ -884,3 +884,39 @@ int traceprobe_define_arg_fields(struct trace_event_call *event_call, }return 0 ; } + + +void trace_probe_cleanup (struct trace_probe *tp) +{ +int i; + +for (i =0 ; i < tp->nr_args; i++) +traceprobe_free_probe_arg (&tp->args[i]); + +kfree (tp->call.class->system); +kfree (tp->call.name); +kfree (tp->call.print_fmt); +} + +int trace_probe_init (struct trace_probe *tp,const char *event, +const char *group) +{ +if (!event || !group) +return -EINVAL ; + + tp->call.class = &tp->class; + tp->call.name =kstrdup (event,GFP_KERNEL ); +if (!tp->call.name) +return -ENOMEM ; + + tp->class.system =kstrdup (group,GFP_KERNEL ); +if (!tp->class.system) { +kfree (tp->call.name); + tp->call.name =NULL ; +return -ENOMEM ; + } +INIT_LIST_HEAD (&tp->files); +INIT_LIST_HEAD (&tp->class.fields); + +return 0 ; +}
kernel/trace/trace_probe.h +4 -0
@@ -248,6 +248,10 @@ static inline bool trace_probe_is_registered(struct trace_probe *tp)return !!(tp->flags &TP_FLAG_REGISTERED ); } +int trace_probe_init (struct trace_probe *tp,const char *event, +const char *group); +void trace_probe_cleanup (struct trace_probe *tp); +/* Check the name is good for event/group/fields */ static inline bool is_good_name (const char *name) {
kernel/trace/trace_uprobe.c +5 -22
@@ -300,25 +300,17 @@ static struct trace_uprobe * alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret) { struct trace_uprobe *tu; - -if (!event || !group) -return ERR_PTR (-EINVAL ); +int ret; tu =kzalloc (SIZEOF_TRACE_UPROBE (nargs),GFP_KERNEL );if (!tu)return ERR_PTR (-ENOMEM ); - tu->tp.call.class = &tu->tp.class; - tu->tp.call.name =kstrdup (event,GFP_KERNEL ); -if (!tu->tp.call.name) - goto error; - - tu->tp.class.system =kstrdup (group,GFP_KERNEL ); -if (!tu->tp.class.system) + ret =trace_probe_init (&tu->tp, event, group); +if (ret <0 ) goto error;dyn_event_init (&tu->devent, &trace_uprobe_ops); -INIT_LIST_HEAD (&tu->tp.files); tu->consumer.handler = uprobe_dispatcher;if (is_ret) tu->consumer.ret_handler = uretprobe_dispatcher;
@@ -326,26 +318,18 @@ alloc_trace_uprobe(const char *group, const char *event, int nargs, bool is_ret)return tu; error: -kfree (tu->tp.call.name);kfree (tu); -return ERR_PTR (-ENOMEM ); +return ERR_PTR (ret); }static void free_trace_uprobe (struct trace_uprobe *tu) { -int i; -if (!tu)return ; -for (i =0 ; i < tu->tp.nr_args; i++) -traceprobe_free_probe_arg (&tu->tp.args[i]); -path_put (&tu->path); -kfree (tu->tp.call.class->system); -kfree (tu->tp.call.name); -kfree (tu->tp.call.print_fmt); +trace_probe_cleanup (&tu->tp);kfree (tu->filename);kfree (tu); }
@@ -1351,7 +1335,6 @@ static struct trace_event_functions uprobe_funcs = {static inline void init_trace_event_call (struct trace_uprobe *tu,struct trace_event_call *call) { -INIT_LIST_HEAD (&call->class->fields); call->event.funcs = &uprobe_funcs; call->class->define_fields = uprobe_event_define_fields;
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 7/12 tracing/probe: Add trace_event_call register API for trace_probe
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Since trace_event_call is a field of trace_probe, these operations should be done in trace_probe.c. trace_kprobe and trace_uprobe use new functions to register/unregister trace_event_call.
--- kernel/trace/trace_kprobe.c | 20 +++----------------- kernel/trace/trace_probe.c | 16 ++++++++++++++++ kernel/trace/trace_probe.h | 6 ++++++ kernel/trace/trace_uprobe.c | 22 +++------------------- 4 files changed, 28 insertions(+), 36 deletions(-)
kernel/trace/trace_kprobe.c +3 -17
@@ -1393,28 +1393,14 @@ static inline void init_trace_event_call(struct trace_kprobe *tk,static int register_kprobe_event (struct trace_kprobe *tk) { -struct trace_event_call *call = &tk->tp.call; -int ret =0 ; - -init_trace_event_call (tk, call); - - ret =register_trace_event (&call->event); -if (!ret) -return -ENODEV ; +init_trace_event_call (tk, &tk->tp.call); - ret =trace_add_event_call (call); -if (ret) { -pr_info ("Failed to register kprobe event: %s\n" , -trace_event_name (call)); -unregister_trace_event (&call->event); - } -return ret; +return trace_probe_register_event_call (&tk->tp); }static int unregister_kprobe_event (struct trace_kprobe *tk) { -/* tp->event is unregistered in trace_remove_event_call() */ -return trace_remove_event_call (&tk->tp.call); +return trace_probe_unregister_event_call (&tk->tp); }#ifdef CONFIG_PERF_EVENTS
kernel/trace/trace_probe.c +16 -0
@@ -920,3 +920,19 @@ int trace_probe_init(struct trace_probe *tp, const char *event,return 0 ; } + +int trace_probe_register_event_call (struct trace_probe *tp) +{ +struct trace_event_call *call = &tp->call; +int ret; + + ret =register_trace_event (&call->event); +if (!ret) +return -ENODEV ; + + ret =trace_add_event_call (call); +if (ret) +unregister_trace_event (&call->event); + +return ret; +}
kernel/trace/trace_probe.h +6 -0
@@ -251,6 +251,12 @@ static inline bool trace_probe_is_registered(struct trace_probe *tp)int trace_probe_init (struct trace_probe *tp,const char *event,const char *group);void trace_probe_cleanup (struct trace_probe *tp); +int trace_probe_register_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() */ +return trace_remove_event_call (&tp->call); +}/* Check the name is good for event/group/fields */ static inline bool is_good_name (const char *name)
kernel/trace/trace_uprobe.c +3 -19
@@ -1345,30 +1345,14 @@ static inline void init_trace_event_call(struct trace_uprobe *tu,static int register_uprobe_event (struct trace_uprobe *tu) { -struct trace_event_call *call = &tu->tp.call; -int ret =0 ; - -init_trace_event_call (tu, call); - - ret =register_trace_event (&call->event); -if (!ret) -return -ENODEV ; - - ret =trace_add_event_call (call); - -if (ret) { -pr_info ("Failed to register uprobe event: %s\n" , -trace_event_name (call)); -unregister_trace_event (&call->event); - } +init_trace_event_call (tu, &tu->tp.call); -return ret; +return trace_probe_register_event_call (&tu->tp); }static int unregister_uprobe_event (struct trace_uprobe *tu) { -/* tu->event is unregistered in trace_remove_event_call() */ -return trace_remove_event_call (&tu->tp.call); +return trace_probe_unregister_event_call (&tu->tp); }#ifdef CONFIG_PERF_EVENTS
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 8/12 tracing/probe: Add trace_event_file access APIs for trace_probe
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add trace_event_file access APIs for trace_probe data structure. This simplifies enabling/disabling operations in uprobe and kprobe events so that those don't touch deep inside the trace_probe.
This also removing a redundant synchronization when the kprobe event is used from perf, since the perf itself uses tracepoint_synchronize_unregister() after disabling (ftrace- defined) event, thus we don't have to synchronize in that path. Also we don't need to identify local trace_kprobe too anymore.
--- kernel/trace/trace_kprobe.c | 85 +++++++++++++------------------------ kernel/trace/trace_probe.c | 47 ++++++++++++++++++++ kernel/trace/trace_probe.h | 36 +++++++++------- kernel/trace/trace_uprobe.c | 42 ++++++------------ 4 files changed, 109 insertions(+), 101 deletions(-)
kernel/trace/trace_kprobe.c +29 -56
@@ -290,34 +290,27 @@ static inline int __enable_trace_kprobe(struct trace_kprobe *tk)static int enable_trace_kprobe (struct trace_kprobe *tk,struct trace_event_file *file) { -struct event_file_link *link; +bool enabled =trace_probe_is_enabled (&tk->tp);int ret =0 ;if (file) { - link =kmalloc (sizeof (*link),GFP_KERNEL ); -if (!link) { - ret = -ENOMEM ; - goto out; - } - - link->file = file; -list_add_tail_rcu (&link->list, &tk->tp.files); + ret =trace_probe_add_file (&tk->tp, file); +if (ret) +return ret; + }else + tk->tp.flags |=TP_FLAG_PROFILE ; - tk->tp.flags |=TP_FLAG_TRACE ; - ret =__enable_trace_kprobe (tk); -if (ret) { -list_del_rcu (&link->list); -kfree (link); - tk->tp.flags &= ~TP_FLAG_TRACE ; - } +if (enabled) +return 0 ; - }else { - tk->tp.flags |=TP_FLAG_PROFILE ; - ret =__enable_trace_kprobe (tk); -if (ret) + ret =__enable_trace_kprobe (tk); +if (ret) { +if (file) +trace_probe_remove_file (&tk->tp, file); +else tk->tp.flags &= ~TP_FLAG_PROFILE ; } - out: +return ret; }
@@ -328,54 +321,34 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)static int disable_trace_kprobe (struct trace_kprobe *tk,struct trace_event_file *file) { -struct event_file_link *link =NULL ; -int wait =0 ; +struct trace_probe *tp = &tk->tp;int ret =0 ;if (file) { - link =find_event_file_link (&tk->tp, file); -if (!link) { - ret = -EINVAL ; - goto out; - } - -list_del_rcu (&link->list); - wait =1 ; -if (!list_empty (&tk->tp.files)) +if (!trace_probe_get_file_link (tp, file)) +return -ENOENT ; +if (!trace_probe_has_single_file (tp)) goto out; - - tk->tp.flags &= ~TP_FLAG_TRACE ; + tp->flags &= ~TP_FLAG_TRACE ; }else - tk->tp.flags &= ~TP_FLAG_PROFILE ; + tp->flags &= ~TP_FLAG_PROFILE ; -if (!trace_probe_is_enabled (&tk->tp) &&trace_probe_is_registered (&tk->tp)) { +if (!trace_probe_is_enabled (tp) &&trace_probe_is_registered (tp)) {if (trace_kprobe_is_return (tk))disable_kretprobe (&tk->rp);else disable_kprobe (&tk->rp.kp); - wait =1 ; } -/* -* if tk is not added to any list, it must be a local trace_kprobe -* created with perf_event_open. We don't need to wait for these -* trace_kprobes -*/ -if (list_empty (&tk->devent.list)) - wait =0 ; out: -if (wait) { +if (file)/* -* Synchronize with kprobe_trace_func/kretprobe_trace_func -* to ensure disabled (all running handlers are finished). -* This is not only for kfree(), but also the caller, -* trace_remove_event_call() supposes it for releasing -* event_call related objects, which will be accessed in -* the kprobe_trace_func/kretprobe_trace_func. +* Synchronization is done in below function. For perf event, +* file == NULL and perf_trace_event_unreg() calls +* tracepoint_synchronize_unregister() to ensure synchronize +* event. We don't need to care about it. */ -synchronize_rcu (); -kfree (link);/* Ignored if link == NULL */ - } +trace_probe_remove_file (tp, file);return ret; }
@@ -1044,7 +1017,7 @@ kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs) {struct event_file_link *link; -list_for_each_entry_rcu (link, &tk->tp.files, list) +trace_probe_for_each_link_rcu (link, &tk->tp)__kprobe_trace_func (tk, regs, link->file); }NOKPROBE_SYMBOL (kprobe_trace_func);
@@ -1094,7 +1067,7 @@ kretprobe_trace_func(struct trace_kprobe *tk, struct kretprobe_instance *ri, {struct event_file_link *link; -list_for_each_entry_rcu (link, &tk->tp.files, list) +trace_probe_for_each_link_rcu (link, &tk->tp)__kretprobe_trace_func (tk, ri, regs, link->file); }NOKPROBE_SYMBOL (kretprobe_trace_func);
kernel/trace/trace_probe.c +47 -0
50 lines not on this page · raw message
kernel/trace/trace_probe.h +20 -16
@@ -248,16 +248,32 @@ static inline bool trace_probe_is_registered(struct trace_probe *tp)return !!(tp->flags &TP_FLAG_REGISTERED ); } -int trace_probe_init (struct trace_probe *tp,const char *event, -const char *group); -void trace_probe_cleanup (struct trace_probe *tp); -int trace_probe_register_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() */ return trace_remove_event_call (&tp->call); } +static inline bool trace_probe_has_single_file (struct trace_probe *tp) +{ +return !!list_is_singular (&tp->files); +} + +int trace_probe_init (struct trace_probe *tp,const char *event, +const char *group); +void trace_probe_cleanup (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_remove_file (struct trace_probe *tp, +struct trace_event_file *file); +struct event_file_link *trace_probe_get_file_link (struct trace_probe *tp, +struct trace_event_file *file); + +#define trace_probe_for_each_link (pos, tp) \ + list_for_each_entry(pos, &(tp)->files, list) +#define trace_probe_for_each_link_rcu (pos, tp) \ + list_for_each_entry_rcu(pos, &(tp)->files, list) +/* Check the name is good for event/group/fields */ static inline bool is_good_name (const char *name) {
@@ -270,18 +286,6 @@ static inline bool is_good_name(const char *name)return true; } -static inline struct event_file_link * -find_event_file_link (struct trace_probe *tp,struct trace_event_file *file) -{ -struct event_file_link *link; - -list_for_each_entry (link, &tp->files, list) -if (link->file == file) -return link; - -return NULL ; -} -#define TPARG_FL_RETURN BIT(0)#define TPARG_FL_KERNEL BIT(1)#define TPARG_FL_FENTRY BIT(2)
kernel/trace/trace_uprobe.c +13 -29
87 lines not on this page · raw message
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 9/12 tracing/probe: Add trace flag access APIs for trace_probe
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add trace_probe_test/set/clear_flag() functions for accessing trace_probe.flag field.
This flags field should not be accessed directly.
--- kernel/trace/trace_kprobe.c | 20 ++++++++++---------- kernel/trace/trace_probe.c | 4 ++-- kernel/trace/trace_probe.h | 22 ++++++++++++++++++++-- kernel/trace/trace_uprobe.c | 18 +++++++++--------- 4 files changed, 41 insertions(+), 23 deletions(-)
kernel/trace/trace_kprobe.c +10 -10
@@ -298,7 +298,7 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)if (ret)return ret; }else - tk->tp.flags |=TP_FLAG_PROFILE ; +trace_probe_set_flag (&tk->tp,TP_FLAG_PROFILE );if (enabled)return 0 ;
@@ -308,7 +308,7 @@ enable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)if (file)trace_probe_remove_file (&tk->tp, file);else - tk->tp.flags &= ~TP_FLAG_PROFILE ; +trace_probe_clear_flag (&tk->tp,TP_FLAG_PROFILE ); }return ret;
@@ -329,9 +329,9 @@ disable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file)return -ENOENT ;if (!trace_probe_has_single_file (tp)) goto out; - tp->flags &= ~TP_FLAG_TRACE ; +trace_probe_clear_flag (tp,TP_FLAG_TRACE ); }else - tp->flags &= ~TP_FLAG_PROFILE ; +trace_probe_clear_flag (tp,TP_FLAG_PROFILE );if (!trace_probe_is_enabled (tp) &&trace_probe_is_registered (tp)) {if (trace_kprobe_is_return (tk))
@@ -408,7 +408,7 @@ static int __register_trace_kprobe(struct trace_kprobe *tk) ret =register_kprobe (&tk->rp.kp);if (ret ==0 ) - tk->tp.flags |=TP_FLAG_REGISTERED ; +trace_probe_set_flag (&tk->tp,TP_FLAG_REGISTERED );return ret; }
@@ -420,7 +420,7 @@ static void __unregister_trace_kprobe(struct trace_kprobe *tk)unregister_kretprobe (&tk->rp); else unregister_kprobe(&tk->rp.kp); - tk->tp.flags &= ~TP_FLAG_REGISTERED ; +trace_probe_clear_flag (&tk->tp,TP_FLAG_REGISTERED );/* Cleanup kprobe for reuse */ if (tk->rp.kp.symbol_name) tk->rp.kp.addr =NULL ;
@@ -1313,10 +1313,10 @@ static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs)raw_cpu_inc (*tk->nhit); -if (tk->tp.flags &TP_FLAG_TRACE ) +if (trace_probe_test_flag (&tk->tp,TP_FLAG_TRACE ))kprobe_trace_func (tk, regs);#ifdef CONFIG_PERF_EVENTS -if (tk->tp.flags &TP_FLAG_PROFILE ) +if (trace_probe_test_flag (&tk->tp,TP_FLAG_PROFILE )) ret =kprobe_perf_func (tk, regs);#endif return ret;
@@ -1330,10 +1330,10 @@ kretprobe_dispatcher(struct kretprobe_instance *ri, struct pt_regs *regs)raw_cpu_inc (*tk->nhit); -if (tk->tp.flags &TP_FLAG_TRACE ) +if (trace_probe_test_flag (&tk->tp,TP_FLAG_TRACE ))kretprobe_trace_func (tk, ri, regs);#ifdef CONFIG_PERF_EVENTS -if (tk->tp.flags &TP_FLAG_PROFILE ) +if (trace_probe_test_flag (&tk->tp,TP_FLAG_PROFILE ))kretprobe_perf_func (tk, ri, regs);#endif return 0 ;/* We don't tweek kernel, so just return 0 */
kernel/trace/trace_probe.c +2 -2
@@ -948,7 +948,7 @@ int trace_probe_add_file(struct trace_probe *tp, struct trace_event_file *file) link->file = file;INIT_LIST_HEAD (&link->list);list_add_tail_rcu (&link->list, &tp->files); - tp->flags |=TP_FLAG_TRACE ; +trace_probe_set_flag (tp,TP_FLAG_TRACE );return 0 ; }
@@ -979,7 +979,7 @@ int trace_probe_remove_file(struct trace_probe *tp,kfree (link);if (list_empty (&tp->files)) - tp->flags &= ~TP_FLAG_TRACE ; +trace_probe_clear_flag (tp,TP_FLAG_TRACE );return 0 ; }
kernel/trace/trace_probe.h +20 -2
@@ -238,14 +238,32 @@ struct event_file_link {struct list_head list; }; +static inline bool trace_probe_test_flag (struct trace_probe *tp, +unsigned int flag) +{ +return !!(tp->flags & flag); +} + +static inline void trace_probe_set_flag (struct trace_probe *tp, +unsigned int flag) +{ + tp->flags |= flag; +} + +static inline void trace_probe_clear_flag (struct trace_probe *tp, +unsigned int flag) +{ + tp->flags &= ~flag; +} +static inline bool trace_probe_is_enabled (struct trace_probe *tp) { -return !!(tp->flags & (TP_FLAG_TRACE |TP_FLAG_PROFILE )); +return trace_probe_test_flag (tp,TP_FLAG_TRACE |TP_FLAG_PROFILE ); }static inline bool trace_probe_is_registered (struct trace_probe *tp) { -return !!(tp->flags &TP_FLAG_REGISTERED ); +return trace_probe_test_flag (tp,TP_FLAG_REGISTERED ); }static inline int trace_probe_unregister_event_call (struct trace_probe *tp)
kernel/trace/trace_uprobe.c +9 -9
@@ -927,17 +927,17 @@ probe_event_enable(struct trace_uprobe *tu, struct trace_event_file *file,int ret;if (file) { -if (tu->tp.flags &TP_FLAG_PROFILE ) +if (trace_probe_test_flag (&tu->tp,TP_FLAG_PROFILE ))return -EINTR ; ret =trace_probe_add_file (&tu->tp, file);if (ret <0 )return ret; }else { -if (tu->tp.flags &TP_FLAG_TRACE ) +if (trace_probe_test_flag (&tu->tp,TP_FLAG_TRACE ))return -EINTR ; - tu->tp.flags |=TP_FLAG_PROFILE ; +trace_probe_set_flag (&tu->tp,TP_FLAG_PROFILE ); }WARN_ON (!uprobe_filter_is_empty (&tu->filter));
@@ -970,7 +970,7 @@ probe_event_enable(struct trace_uprobe *tu, struct trace_event_file *file,if (file)trace_probe_remove_file (&tu->tp, file);else - tu->tp.flags &= ~TP_FLAG_PROFILE ; +trace_probe_clear_flag (&tu->tp,TP_FLAG_PROFILE );return ret; }
@@ -988,7 +988,7 @@ probe_event_disable(struct trace_uprobe *tu, struct trace_event_file *file)if (trace_probe_is_enabled (&tu->tp))return ; }else - tu->tp.flags &= ~TP_FLAG_PROFILE ; +trace_probe_clear_flag (&tu->tp,TP_FLAG_PROFILE );WARN_ON (!uprobe_filter_is_empty (&tu->filter));
@@ -1266,11 +1266,11 @@ static int uprobe_dispatcher(struct uprobe_consumer *con, struct pt_regs *regs) ucb =uprobe_buffer_get ();store_trace_args (ucb->buf, &tu->tp, regs, esize, dsize); -if (tu->tp.flags &TP_FLAG_TRACE ) +if (trace_probe_test_flag (&tu->tp,TP_FLAG_TRACE )) ret |=uprobe_trace_func (tu, regs, ucb, dsize);#ifdef CONFIG_PERF_EVENTS -if (tu->tp.flags &TP_FLAG_PROFILE ) +if (trace_probe_test_flag (&tu->tp,TP_FLAG_PROFILE )) ret |=uprobe_perf_func (tu, regs, ucb, dsize);#endif uprobe_buffer_put (ucb);
@@ -1301,11 +1301,11 @@ static int uretprobe_dispatcher(struct uprobe_consumer *con, ucb =uprobe_buffer_get ();store_trace_args (ucb->buf, &tu->tp, regs, esize, dsize); -if (tu->tp.flags &TP_FLAG_TRACE ) +if (trace_probe_test_flag (&tu->tp,TP_FLAG_TRACE ))uretprobe_trace_func (tu, func, regs, ucb, dsize);#ifdef CONFIG_PERF_EVENTS -if (tu->tp.flags &TP_FLAG_PROFILE ) +if (trace_probe_test_flag (&tu->tp,TP_FLAG_PROFILE ))uretprobe_perf_func (tu, func, regs, ucb, dsize);#endif uprobe_buffer_put (ucb);
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 10/12 tracing/probe: Add probe event name and group name accesses APIs
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add trace_probe_name() and trace_probe_group_name() functions for accessing probe name and group name of trace_probe.
--- kernel/trace/trace_kprobe.c | 24 ++++++++++++------------ kernel/trace/trace_probe.h | 10 ++++++++++ kernel/trace/trace_uprobe.c | 22 +++++++++++----------- 3 files changed, 33 insertions(+), 23 deletions(-)
kernel/trace/trace_kprobe.c +12 -12
@@ -142,8 +142,8 @@ static bool trace_kprobe_match(const char *system, const char *event, {struct trace_kprobe *tk =to_trace_kprobe (ev); -return strcmp (trace_event_name (&tk->tp.call), event) ==0 && - (!system ||strcmp (tk->tp.call.class->system, system) ==0 ); +return strcmp (trace_probe_name (&tk->tp), event) ==0 && + (!system ||strcmp (trace_probe_group_name (&tk->tp), system) ==0 ); }static nokprobe_inline unsigned long trace_kprobe_nhit (struct trace_kprobe *tk)
@@ -263,8 +263,8 @@ static struct trace_kprobe *find_trace_kprobe(const char *event,struct trace_kprobe *tk;for_each_trace_kprobe (tk, pos) -if (strcmp (trace_event_name (&tk->tp.call), event) ==0 && -strcmp (tk->tp.call.class->system, group) ==0 ) +if (strcmp (trace_probe_name (&tk->tp), event) ==0 && +strcmp (trace_probe_group_name (&tk->tp), group) ==0 )return tk;return NULL ; }
@@ -453,8 +453,8 @@ static int register_trace_kprobe(struct trace_kprobe *tk)mutex_lock (&event_mutex);/* Delete old (same name) event if exist */ - old_tk =find_trace_kprobe (trace_event_name (&tk->tp.call), - tk->tp.call.class->system); + old_tk =find_trace_kprobe (trace_probe_name (&tk->tp), +trace_probe_group_name (&tk->tp));if (old_tk) { ret =unregister_trace_kprobe (old_tk);if (ret <0 )
@@ -507,7 +507,7 @@ static int trace_kprobe_module_callback(struct notifier_block *nb, ret =__register_trace_kprobe (tk);if (ret)pr_warn ("Failed to re-register probe %s on %s: %d\n" , -trace_event_name (&tk->tp.call), +trace_probe_name (&tk->tp), mod->name, ret); } }
@@ -737,8 +737,8 @@ static int trace_kprobe_show(struct seq_file *m, struct dyn_event *ev)int i;seq_putc (m,trace_kprobe_is_return (tk) ?'r' :'p' ); -seq_printf (m,":%s/%s" , tk->tp.call.class->system, -trace_event_name (&tk->tp.call)); +seq_printf (m,":%s/%s" ,trace_probe_group_name (&tk->tp), +trace_probe_name (&tk->tp));if (!tk->symbol)seq_printf (m," 0x%p" , tk->rp.kp.addr);
@@ -812,7 +812,7 @@ static int probes_profile_seq_show(struct seq_file *m, void *v) tk =to_trace_kprobe (ev);seq_printf (m," %-44s %15lu %15lu\n" , -trace_event_name (&tk->tp.call), +trace_probe_name (&tk->tp),trace_kprobe_nhit (tk), tk->rp.kp.nmissed);
@@ -1084,7 +1084,7 @@ print_kprobe_event(struct trace_iterator *iter, int flags, field = (struct kprobe_trace_entry_head *)iter->ent; tp = container_of(event, struct trace_probe, call.event); -trace_seq_printf (s,"%s: (" ,trace_event_name (&tp->call)); +trace_seq_printf (s,"%s: (" ,trace_probe_name (tp));if (!seq_print_ip_sym (s, field->ip, flags |TRACE_ITER_SYM_OFFSET )) goto out;
@@ -1111,7 +1111,7 @@ print_kretprobe_event(struct trace_iterator *iter, int flags, field = (struct kretprobe_trace_entry_head *)iter->ent; tp = container_of(event, struct trace_probe, call.event); -trace_seq_printf (s,"%s: (" ,trace_event_name (&tp->call)); +trace_seq_printf (s,"%s: (" ,trace_probe_name (tp));if (!seq_print_ip_sym (s, field->ret_ip, flags |TRACE_ITER_SYM_OFFSET )) goto out;
kernel/trace/trace_probe.h +10 -0
@@ -266,6 +266,16 @@ static inline bool trace_probe_is_registered(struct trace_probe *tp)return trace_probe_test_flag (tp,TP_FLAG_REGISTERED ); } +static inline const char *trace_probe_name (struct trace_probe *tp) +{ +return trace_event_name (&tp->call); +} + +static inline const char *trace_probe_group_name (struct trace_probe *tp) +{ +return tp->call.class->system; +} +static inline int trace_probe_unregister_event_call (struct trace_probe *tp) {/* tp->event is unregistered in trace_remove_event_call() */
kernel/trace/trace_uprobe.c +11 -11
@@ -289,8 +289,8 @@ static bool trace_uprobe_match(const char *system, const char *event, {struct trace_uprobe *tu =to_trace_uprobe (ev); -return strcmp (trace_event_name (&tu->tp.call), event) ==0 && - (!system ||strcmp (tu->tp.call.class->system, system) ==0 ); +return strcmp (trace_probe_name (&tu->tp), event) ==0 && + (!system ||strcmp (trace_probe_group_name (&tu->tp), system) ==0 ); }/*
@@ -340,8 +340,8 @@ static struct trace_uprobe *find_probe_event(const char *event, const char *groustruct trace_uprobe *tu;for_each_trace_uprobe (tu, pos) -if (strcmp (trace_event_name (&tu->tp.call), event) ==0 && -strcmp (tu->tp.call.class->system, group) ==0 ) +if (strcmp (trace_probe_name (&tu->tp), event) ==0 && +strcmp (trace_probe_group_name (&tu->tp), group) ==0 )return tu;return NULL ;
@@ -376,8 +376,8 @@ static struct trace_uprobe *find_old_trace_uprobe(struct trace_uprobe *new)struct trace_uprobe *tmp, *old =NULL ;struct inode *new_inode =d_real_inode (new->path.dentry); - old =find_probe_event (trace_event_name (&new->tp.call), - new->tp.call.class->system); + old =find_probe_event (trace_probe_name (&new->tp), +trace_probe_group_name (&new->tp));for_each_trace_uprobe (tmp, pos) { if ((old ? old != tmp : true) &&
@@ -624,8 +624,8 @@ static int trace_uprobe_show(struct seq_file *m, struct dyn_event *ev)char c =is_ret_probe (tu) ?'r' :'p' ;int i; -seq_printf (m,"%c:%s/%s %s:0x%0*lx" , c, tu->tp.call.class->system, -trace_event_name (&tu->tp.call), tu->filename, +seq_printf (m,"%c:%s/%s %s:0x%0*lx" , c,trace_probe_group_name (&tu->tp), +trace_probe_name (&tu->tp), tu->filename, (int )(sizeof (void *) *2 ), tu->offset);if (tu->ref_ctr_offset)
@@ -695,7 +695,7 @@ static int probes_profile_seq_show(struct seq_file *m, void *v) tu =to_trace_uprobe (ev);seq_printf (m," %s %-44s %15lu\n" , tu->filename, -trace_event_name (&tu->tp.call), tu->nhit); +trace_probe_name (&tu->tp), tu->nhit);return 0 ; }
@@ -896,12 +896,12 @@ print_uprobe_event(struct trace_iterator *iter, int flags, struct trace_event *eif (is_ret_probe (tu)) {trace_seq_printf (s,"%s: (0x%lx <- 0x%lx)" , -trace_event_name (&tu->tp.call), +trace_probe_name (&tu->tp), entry->vaddr[1 ], entry->vaddr[0 ]); data =DATAOF_TRACE_ENTRY (entry, true); }else {trace_seq_printf (s,"%s: (0x%lx)" , -trace_event_name (&tu->tp.call), +trace_probe_name (&tu->tp), entry->vaddr[0 ]); data =DATAOF_TRACE_ENTRY (entry, false); }
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 11/12 tracing/probe: Add trace_event_call accesses APIs
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Add trace_event_call access APIs for trace_probe. Instead of accessing trace_probe.call directly, use those accesses by trace_probe_event_call() method. This hides the relationship of trace_event_call and trace_probe from trace_kprobe and trace_uprobe.
--- kernel/trace/trace_kprobe.c | 23 ++++++++++++----------- kernel/trace/trace_probe.c | 24 ++++++++++++++---------- kernel/trace/trace_probe.h | 6 ++++++ kernel/trace/trace_uprobe.c | 15 ++++++++------- 4 files changed, 40 insertions(+), 28 deletions(-)
kernel/trace/trace_kprobe.c +12 -11
@@ -985,7 +985,7 @@ __kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs,struct ring_buffer *buffer;int size, dsize, pc;unsigned long irq_flags; -struct trace_event_call *call = &tk->tp.call; +struct trace_event_call *call =trace_probe_event_call (&tk->tp);WARN_ON (call != trace_file->event_call);
@@ -1033,7 +1033,7 @@ __kretprobe_trace_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,struct ring_buffer *buffer;int size, pc, dsize;unsigned long irq_flags; -struct trace_event_call *call = &tk->tp.call; +struct trace_event_call *call =trace_probe_event_call (&tk->tp);WARN_ON (call != trace_file->event_call);
@@ -1163,7 +1163,7 @@ static int kretprobe_event_define_fields(struct trace_event_call *event_call)static int kprobe_perf_func (struct trace_kprobe *tk,struct pt_regs *regs) { -struct trace_event_call *call = &tk->tp.call; +struct trace_event_call *call =trace_probe_event_call (&tk->tp);struct kprobe_trace_entry_head *entry;struct hlist_head *head;int size, __size, dsize;
@@ -1213,7 +1213,7 @@ static void kretprobe_perf_func(struct trace_kprobe *tk, struct kretprobe_instance *ri, struct pt_regs *regs) { - struct trace_event_call *call = &tk->tp.call; + struct trace_event_call *call = trace_probe_event_call(&tk->tp);struct kretprobe_trace_entry_head *entry;struct hlist_head *head;int size, __size, dsize;
@@ -1348,9 +1348,10 @@ static struct trace_event_functions kprobe_funcs = { .trace = print_kprobe_event }; -static inline void init_trace_event_call (struct trace_kprobe *tk, -struct trace_event_call *call) +static inline void init_trace_event_call (struct trace_kprobe *tk) { +struct trace_event_call *call =trace_probe_event_call (&tk->tp); +if (trace_kprobe_is_return (tk)) { call->event.funcs = &kretprobe_funcs; call->class->define_fields = kretprobe_event_define_fields;
@@ -1366,7 +1367,7 @@ static inline void init_trace_event_call(struct trace_kprobe *tk,static int register_kprobe_event (struct trace_kprobe *tk) { -init_trace_event_call (tk, &tk->tp.call); +init_trace_event_call (tk);return trace_probe_register_event_call (&tk->tp); }
@@ -1403,7 +1404,7 @@ create_local_trace_kprobe(char *func, void *addr, unsigned long offs,return ERR_CAST (tk); } -init_trace_event_call (tk, &tk->tp.call); +init_trace_event_call (tk);if (traceprobe_set_print_fmt (&tk->tp,trace_kprobe_is_return (tk)) <0 ) { ret = -ENOMEM ;
@@ -1414,7 +1415,7 @@ create_local_trace_kprobe(char *func, void *addr, unsigned long offs,if (ret <0 ) goto error; -return &tk->tp.call; +return trace_probe_event_call (&tk->tp); error:free_trace_kprobe (tk);return ERR_PTR (ret);
@@ -1447,7 +1448,7 @@ static __init void enable_boot_kprobe_events(void)mutex_lock (&event_mutex);for_each_trace_kprobe (tk, pos) {list_for_each_entry (file, &tr->events, list) -if (file->event_call == &tk->tp.call) +if (file->event_call ==trace_probe_event_call (&tk->tp))trace_event_enable_disable (file,1 ,0 ); }mutex_unlock (&event_mutex);
@@ -1523,7 +1524,7 @@ find_trace_probe_file(struct trace_kprobe *tk, struct trace_array *tr)struct trace_event_file *file;list_for_each_entry (file, &tr->events, list) -if (file->event_call == &tk->tp.call) +if (file->event_call ==trace_probe_event_call (&tk->tp))return file;return NULL ;
kernel/trace/trace_probe.c +14 -10
@@ -844,6 +844,7 @@ static int __set_print_fmt(struct trace_probe *tp, char *buf, int len,int traceprobe_set_print_fmt (struct trace_probe *tp,bool is_return) { +struct trace_event_call *call =trace_probe_event_call (tp);int len;char *print_fmt;
@@ -855,7 +856,7 @@ int traceprobe_set_print_fmt(struct trace_probe *tp, bool is_return)/* Second: actually write the @print_fmt */ __set_print_fmt (tp, print_fmt, len +1 , is_return); - tp->call.print_fmt = print_fmt; + call->print_fmt = print_fmt;return 0 ; }
@@ -888,31 +889,34 @@ int traceprobe_define_arg_fields(struct trace_event_call *event_call,void trace_probe_cleanup (struct trace_probe *tp) { +struct trace_event_call *call =trace_probe_event_call (tp);int i;for (i =0 ; i < tp->nr_args; i++)traceprobe_free_probe_arg (&tp->args[i]); -kfree (tp->call.class->system); -kfree (tp->call.name); -kfree (tp->call.print_fmt); +kfree (call->class->system); +kfree (call->name); +kfree (call->print_fmt); }int trace_probe_init (struct trace_probe *tp,const char *event,const char *group) { +struct trace_event_call *call =trace_probe_event_call (tp); +if (!event || !group)return -EINVAL ; - tp->call.class = &tp->class; - tp->call.name =kstrdup (event,GFP_KERNEL ); -if (!tp->call.name) + call->class = &tp->class; + call->name =kstrdup (event,GFP_KERNEL ); +if (!call->name)return -ENOMEM ; tp->class.system =kstrdup (group,GFP_KERNEL );if (!tp->class.system) { -kfree (tp->call.name); - tp->call.name =NULL ; +kfree (call->name); + call->name =NULL ;return -ENOMEM ; }INIT_LIST_HEAD (&tp->files);
@@ -923,7 +927,7 @@ int trace_probe_init(struct trace_probe *tp, const char *event,int trace_probe_register_event_call (struct trace_probe *tp) { -struct trace_event_call *call = &tp->call; +struct trace_event_call *call =trace_probe_event_call (tp);int ret; ret =register_trace_event (&call->event);
kernel/trace/trace_probe.h +6 -0
@@ -276,6 +276,12 @@ static inline const char *trace_probe_group_name(struct trace_probe *tp)return tp->call.class->system; } +static inline struct trace_event_call * +trace_probe_event_call (struct trace_probe *tp) +{ +return &tp->call; +} +static inline int trace_probe_unregister_event_call (struct trace_probe *tp) {/* tp->event is unregistered in trace_remove_event_call() */
kernel/trace/trace_uprobe.c +8 -7
@@ -821,7 +821,7 @@ static void __uprobe_trace_func(struct trace_uprobe *tu,struct ring_buffer *buffer;void *data;int size, esize; -struct trace_event_call *call = &tu->tp.call; +struct trace_event_call *call =trace_probe_event_call (&tu->tp);WARN_ON (call != trace_file->event_call);
@@ -1113,7 +1113,7 @@ static void __uprobe_perf_func(struct trace_uprobe *tu, unsigned long func, struct pt_regs *regs, struct uprobe_cpu_buffer *ucb, int dsize) { - struct trace_event_call *call = &tu->tp.call; + struct trace_event_call *call = trace_probe_event_call(&tu->tp);struct uprobe_trace_entry_head *entry;struct hlist_head *head;void *data;
@@ -1316,9 +1316,10 @@ static struct trace_event_functions uprobe_funcs = { .trace = print_uprobe_event }; -static inline void init_trace_event_call (struct trace_uprobe *tu, -struct trace_event_call *call) +static inline void init_trace_event_call (struct trace_uprobe *tu) { +struct trace_event_call *call =trace_probe_event_call (&tu->tp); + call->event.funcs = &uprobe_funcs; call->class->define_fields = uprobe_event_define_fields;
@@ -1329,7 +1330,7 @@ static inline void init_trace_event_call(struct trace_uprobe *tu,static int register_uprobe_event (struct trace_uprobe *tu) { -init_trace_event_call (tu, &tu->tp.call); +init_trace_event_call (tu);return trace_probe_register_event_call (&tu->tp); }
@@ -1376,14 +1377,14 @@ create_local_trace_uprobe(char *name, unsigned long offs, tu->path = path; tu->ref_ctr_offset = ref_ctr_offset; tu->filename =kstrdup (name,GFP_KERNEL ); -init_trace_event_call (tu, &tu->tp.call); +init_trace_event_call (tu);if (traceprobe_set_print_fmt (&tu->tp,is_ret_probe (tu)) <0 ) { ret = -ENOMEM ; goto error; } -return &tu->tp.call; +return trace_probe_event_call (&tu->tp); error:free_trace_uprobe (tu);return ERR_PTR (ret);
Signature · 1 line
2.20.1
Steven Rostedt
maintainerPATCH 12/12 tracing/kprobe: Check registered state using kprobe
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Change registered check only by trace_kprobe and remove TP_FLAG_REGISTERED from trace_probe, since this feature is only used for trace_kprobe.
--- kernel/trace/trace_kprobe.c | 23 +++++++++++++++-------- kernel/trace/trace_probe.h | 6 ------ 2 files changed, 15 insertions(+), 14 deletions(-)
kernel/trace/trace_kprobe.c +15 -8
@@ -157,6 +157,12 @@ static nokprobe_inline unsigned long trace_kprobe_nhit(struct trace_kprobe *tk)return nhit; } +static nokprobe_inline bool trace_kprobe_is_registered(struct trace_kprobe *tk) +{ +return !(list_empty (&tk->rp.kp.list) && +hlist_unhashed (&tk->rp.kp.hlist)); +} +/* Return 0 if it fails to find the symbol address */ static nokprobe_inline unsigned long trace_kprobe_address (struct trace_kprobe *tk)
@@ -244,6 +250,8 @@ static struct trace_kprobe *alloc_trace_kprobe(const char *group, tk->rp.kp.pre_handler = kprobe_dispatcher; tk->rp.maxactive = maxactive; +INIT_HLIST_NODE (&tk->rp.kp.hlist); +INIT_LIST_HEAD (&tk->rp.kp.list); ret =trace_probe_init (&tk->tp, event, group);if (ret <0 )
@@ -273,7 +281,7 @@ static inline int __enable_trace_kprobe(struct trace_kprobe *tk) {int ret =0 ; -if (trace_probe_is_registered (&tk->tp) && !trace_kprobe_has_gone (tk)) { +if (trace_kprobe_is_registered (tk) && !trace_kprobe_has_gone (tk)) {if (trace_kprobe_is_return (tk)) ret =enable_kretprobe (&tk->rp);else
@@ -333,7 +341,7 @@ disable_trace_kprobe(struct trace_kprobe *tk, struct trace_event_file *file) }else trace_probe_clear_flag (tp,TP_FLAG_PROFILE ); -if (!trace_probe_is_enabled (tp) &&trace_probe_is_registered (tp)) { +if (!trace_probe_is_enabled (tp) &&trace_kprobe_is_registered (tk)) {if (trace_kprobe_is_return (tk))disable_kretprobe (&tk->rp);else
@@ -381,7 +389,7 @@ static int __register_trace_kprobe(struct trace_kprobe *tk) {int i, ret; -if (trace_probe_is_registered (&tk->tp)) +if (trace_kprobe_is_registered (tk))return -EINVAL ;if (within_notrace_func (tk)) {
@@ -407,21 +415,20 @@ static int __register_trace_kprobe(struct trace_kprobe *tk)else ret =register_kprobe (&tk->rp.kp); -if (ret ==0 ) -trace_probe_set_flag (&tk->tp,TP_FLAG_REGISTERED );return ret; }/* Internal unregister function - just handle k*probes and flags */ static void __unregister_trace_kprobe (struct trace_kprobe *tk) { -if (trace_probe_is_registered (&tk->tp)) { +if (trace_kprobe_is_registered (tk)) {if (trace_kprobe_is_return (tk))unregister_kretprobe (&tk->rp);else unregister_kprobe (&tk->rp.kp); -trace_probe_clear_flag (&tk->tp,TP_FLAG_REGISTERED ); -/* Cleanup kprobe for reuse */ +/* Cleanup kprobe for reuse and mark it unregistered */ +INIT_HLIST_NODE (&tk->rp.kp.hlist); +INIT_LIST_HEAD (&tk->rp.kp.list);if (tk->rp.kp.symbol_name) tk->rp.kp.addr =NULL ; }
kernel/trace/trace_probe.h +0 -6
@@ -55,7 +55,6 @@/* Flags for trace_probe */ #define TP_FLAG_TRACE 1#define TP_FLAG_PROFILE 2 -#define TP_FLAG_REGISTERED 4/* data_loc: data location, compatible with u32 */ #define make_data_loc (len, offs) \
@@ -261,11 +260,6 @@ static inline bool trace_probe_is_enabled(struct trace_probe *tp)return trace_probe_test_flag (tp,TP_FLAG_TRACE |TP_FLAG_PROFILE ); } -static inline bool trace_probe_is_registered (struct trace_probe *tp) -{ -return trace_probe_test_flag (tp,TP_FLAG_REGISTERED ); -} -static inline const char *trace_probe_name (struct trace_probe *tp) {return trace_event_name (&tp->call);
Signature · 1 line
2.20.1