Skip to content

Commit 83f7444

Browse files
olsajirirostedt
authored andcommitted
ftrace: Show all functions with addresses in available_filter_functions_addrs
Adding new available_filter_functions_addrs file that shows all available functions (same as available_filter_functions) together with addresses, like: # cat available_filter_functions_addrs | head ffffffff81000770 __traceiter_initcall_level ffffffff810007c0 __traceiter_initcall_start ffffffff81000810 __traceiter_initcall_finish ffffffff81000860 trace_initcall_finish_cb ... Note displayed address is the patch-site address and can differ from /proc/kallsyms address. It's useful to have address avilable for traceable symbols, so we don't need to allways cross check kallsyms with available_filter_functions (or the other way around) and have all the data in single file. For backwards compatibility reasons we can't change the existing available_filter_functions file output, but we need to add new file. The problem is that we need to do 2 passes: - through available_filter_functions and find out if the function is traceable - through /proc/kallsyms to get the address for traceable function Having available_filter_functions symbols together with addresses allow us to skip the kallsyms step and we are ok with the address in available_filter_functions_addr not being the function entry, because kprobe_multi uses fprobe and that handles both entry and patch-site address properly. We have 2 interfaces how to create kprobe_multi link: a) passing symbols to kernel 1) user gathers symbols and need to ensure that they are trace-able -> pass through available_filter_functions file 2) kernel takes those symbols and translates them to addresses through kallsyms api 3) addresses are passed to fprobe/ftrace through: register_fprobe_ips -> ftrace_set_filter_ips b) passing addresses to kernel 1) user gathers symbols and needs to ensure that they are trace-able -> pass through available_filter_functions file 2) user takes those symbols and translates them to addresses through /proc/kallsyms 3) addresses are passed to the kernel and kernel calls: register_fprobe_ips -> ftrace_set_filter_ips The new available_filter_functions_addrs file helps us with option b), because we can make 'b 1' and 'b 2' in one step - while filtering traceable functions, we get the address directly. Link: https://lore.kernel.org/linux-trace-kernel/[email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Andrii Nakryiko <[email protected]> Tested-by: Jackie Liu <[email protected]> # x86 Suggested-by: Steven Rostedt (Google) <[email protected]> Suggested-by: Andrii Nakryiko <[email protected]> Signed-off-by: Jiri Olsa <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 6009177 commit 83f7444

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

Documentation/trace/ftrace.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ of ftrace. Here is a list of some of the key files:
324324
"set_graph_function", or "set_graph_notrace".
325325
(See the section "dynamic ftrace" below for more details.)
326326

327+
available_filter_functions_addrs:
328+
329+
Similar to available_filter_functions, but with address displayed
330+
for each function. The displayed address is the patch-site address
331+
and can differ from /proc/kallsyms address.
332+
327333
dyn_ftrace_total_info:
328334

329335
This file is for debugging purposes. The number of functions that

include/linux/ftrace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ enum {
633633
FTRACE_ITER_MOD = (1 << 5),
634634
FTRACE_ITER_ENABLED = (1 << 6),
635635
FTRACE_ITER_TOUCHED = (1 << 7),
636+
FTRACE_ITER_ADDRS = (1 << 8),
636637
};
637638

638639
void arch_ftrace_update_code(int command);

kernel/trace/ftrace.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3861,6 +3861,9 @@ static int t_show(struct seq_file *m, void *v)
38613861
if (!rec)
38623862
return 0;
38633863

3864+
if (iter->flags & FTRACE_ITER_ADDRS)
3865+
seq_printf(m, "%lx ", rec->ip);
3866+
38643867
if (print_rec(m, rec->ip)) {
38653868
/* This should only happen when a rec is disabled */
38663869
WARN_ON_ONCE(!(rec->flags & FTRACE_FL_DISABLED));
@@ -3996,6 +3999,30 @@ ftrace_touched_open(struct inode *inode, struct file *file)
39963999
return 0;
39974000
}
39984001

4002+
static int
4003+
ftrace_avail_addrs_open(struct inode *inode, struct file *file)
4004+
{
4005+
struct ftrace_iterator *iter;
4006+
int ret;
4007+
4008+
ret = security_locked_down(LOCKDOWN_TRACEFS);
4009+
if (ret)
4010+
return ret;
4011+
4012+
if (unlikely(ftrace_disabled))
4013+
return -ENODEV;
4014+
4015+
iter = __seq_open_private(file, &show_ftrace_seq_ops, sizeof(*iter));
4016+
if (!iter)
4017+
return -ENOMEM;
4018+
4019+
iter->pg = ftrace_pages_start;
4020+
iter->flags = FTRACE_ITER_ADDRS;
4021+
iter->ops = &global_ops;
4022+
4023+
return 0;
4024+
}
4025+
39994026
/**
40004027
* ftrace_regex_open - initialize function tracer filter files
40014028
* @ops: The ftrace_ops that hold the hash filters
@@ -5916,6 +5943,13 @@ static const struct file_operations ftrace_touched_fops = {
59165943
.release = seq_release_private,
59175944
};
59185945

5946+
static const struct file_operations ftrace_avail_addrs_fops = {
5947+
.open = ftrace_avail_addrs_open,
5948+
.read = seq_read,
5949+
.llseek = seq_lseek,
5950+
.release = seq_release_private,
5951+
};
5952+
59195953
static const struct file_operations ftrace_filter_fops = {
59205954
.open = ftrace_filter_open,
59215955
.read = seq_read,
@@ -6377,6 +6411,9 @@ static __init int ftrace_init_dyn_tracefs(struct dentry *d_tracer)
63776411
trace_create_file("available_filter_functions", TRACE_MODE_READ,
63786412
d_tracer, NULL, &ftrace_avail_fops);
63796413

6414+
trace_create_file("available_filter_functions_addrs", TRACE_MODE_READ,
6415+
d_tracer, NULL, &ftrace_avail_addrs_fops);
6416+
63806417
trace_create_file("enabled_functions", TRACE_MODE_READ,
63816418
d_tracer, NULL, &ftrace_enabled_fops);
63826419

0 commit comments

Comments
 (0)