cregit-Linux how code gets into the kernel

Release 4.15 kernel/trace/trace_syscalls.c

Directory: kernel/trace
// SPDX-License-Identifier: GPL-2.0
#include <trace/syscall.h>
#include <trace/events/syscalls.h>
#include <linux/syscalls.h>
#include <linux/slab.h>
#include <linux/kernel.h>
#include <linux/module.h>	/* for MODULE_NAME_LEN via KSYM_SYMBOL_LEN */
#include <linux/ftrace.h>
#include <linux/perf_event.h>
#include <asm/syscall.h>

#include "trace_output.h"
#include "trace.h"

static DEFINE_MUTEX(syscall_trace_lock);

static int syscall_enter_register(struct trace_event_call *event,
				 enum trace_reg type, void *data);
static int syscall_exit_register(struct trace_event_call *event,
				 enum trace_reg type, void *data);


static struct list_head * syscall_get_enter_fields(struct trace_event_call *call) { struct syscall_metadata *entry = call->data; return &entry->enter_fields; }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt28100.00%2100.00%
Total28100.00%2100.00%

extern struct syscall_metadata *__start_syscalls_metadata[]; extern struct syscall_metadata *__stop_syscalls_metadata[]; static struct syscall_metadata **syscalls_metadata; #ifndef ARCH_HAS_SYSCALL_MATCH_SYM_NAME
static inline bool arch_syscall_match_sym_name(const char *sym, const char *name) { /* * Only compare after the "sys" prefix. Archs that use * syscall wrappers may have syscalls symbols aliases prefixed * with ".SyS" or ".sys" instead of "sys", leading to an unwanted * mismatch. */ return !strcmp(sym + 3, name + 3); }

Contributors

PersonTokensPropCommitsCommitProp
Ian Munsie3096.77%150.00%
Jovi Zhangwei13.23%150.00%
Total31100.00%2100.00%

#endif #ifdef ARCH_TRACE_IGNORE_COMPAT_SYSCALLS /* * Some architectures that allow for 32bit applications * to run on a 64bit kernel, do not map the syscalls for * the 32bit tasks the same as they do for 64bit tasks. * * *cough*x86*cough* * * In such a case, instead of reporting the wrong syscalls, * simply ignore them. * * For an arch to ignore the compat syscalls it needs to * define ARCH_TRACE_IGNORE_COMPAT_SYSCALLS as well as * define the function arch_trace_is_compat_syscall() to let * the tracing system know that it should ignore it. */
static int trace_get_syscall_nr(struct task_struct *task, struct pt_regs *regs) { if (unlikely(arch_trace_is_compat_syscall(regs))) return -1; return syscall_get_nr(task, regs); }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt38100.00%1100.00%
Total38100.00%1100.00%

#else
static inline int trace_get_syscall_nr(struct task_struct *task, struct pt_regs *regs) { return syscall_get_nr(task, regs); }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt25100.00%1100.00%
Total25100.00%1100.00%

#endif /* ARCH_TRACE_IGNORE_COMPAT_SYSCALLS */ static __init struct syscall_metadata * find_syscall_meta(unsigned long syscall) { struct syscall_metadata **start; struct syscall_metadata **stop; char str[KSYM_SYMBOL_LEN]; start = __start_syscalls_metadata; stop = __stop_syscalls_metadata; kallsyms_lookup(syscall, NULL, NULL, NULL, str); if (arch_syscall_match_sym_name(str, "sys_ni_syscall")) return NULL; for ( ; start < stop; start++) { if ((*start)->name && arch_syscall_match_sym_name(str, (*start)->name)) return *start; } return NULL;
} static struct syscall_metadata *syscall_nr_to_meta(int nr) { if (!syscalls_metadata || nr >= NR_syscalls || nr < 0) return NULL; return syscalls_metadata[nr]; }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker3296.97%150.00%
Steven Rostedt13.03%150.00%
Total33100.00%2100.00%


const char *get_syscall_name(int syscall) { struct syscall_metadata *entry; entry = syscall_nr_to_meta(syscall); if (!entry) return NULL; return entry->name; }

Contributors

PersonTokensPropCommitsCommitProp
Tom Zanussi35100.00%1100.00%
Total35100.00%1100.00%


static enum print_line_t print_syscall_enter(struct trace_iterator *iter, int flags, struct trace_event *event) { struct trace_array *tr = iter->tr; struct trace_seq *s = &iter->seq; struct trace_entry *ent = iter->ent; struct syscall_trace_enter *trace; struct syscall_metadata *entry; int i, syscall; trace = (typeof(trace))ent; syscall = trace->nr; entry = syscall_nr_to_meta(syscall); if (!entry) goto end; if (entry->enter_event->event.type != ent->type) { WARN_ON_ONCE(1); goto end; } trace_seq_printf(s, "%s(", entry->name); for (i = 0; i < entry->nb_args; i++) { if (trace_seq_has_overflowed(s)) goto end; /* parameter types */ if (tr->trace_flags & TRACE_ITER_VERBOSE) trace_seq_printf(s, "%s ", entry->types[i]); /* parameter values */ trace_seq_printf(s, "%s: %lx%s", entry->args[i], trace->args[i], i == entry->nb_args - 1 ? "" : ", "); } trace_seq_putc(s, ')'); end: trace_seq_putc(s, '\n'); return trace_handle_return(s); }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker15967.66%110.00%
Steven Rostedt3314.04%440.00%
Jason Baron2510.64%110.00%
Li Zefan156.38%220.00%
Lai Jiangshan20.85%110.00%
Fengguang Wu10.43%110.00%
Total235100.00%10100.00%


static enum print_line_t print_syscall_exit(struct trace_iterator *iter, int flags, struct trace_event *event) { struct trace_seq *s = &iter->seq; struct trace_entry *ent = iter->ent; struct syscall_trace_exit *trace; int syscall; struct syscall_metadata *entry; trace = (typeof(trace))ent; syscall = trace->nr; entry = syscall_nr_to_meta(syscall); if (!entry) { trace_seq_putc(s, '\n'); goto out; } if (entry->exit_event->event.type != ent->type) { WARN_ON_ONCE(1); return TRACE_TYPE_UNHANDLED; } trace_seq_printf(s, "%s -> 0x%lx\n", entry->name, trace->ret); out: return trace_handle_return(s); }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker9266.19%112.50%
Jason Baron2517.99%112.50%
Steven Rostedt1712.23%337.50%
Lai Jiangshan21.44%112.50%
Jovi Zhangwei21.44%112.50%
Fengguang Wu10.72%112.50%
Total139100.00%8100.00%

extern char *__bad_type_size(void); #define SYSCALL_FIELD(type, field, name) \ sizeof(type) != sizeof(trace.field) ? \ __bad_type_size() : \ #type, #name, offsetof(typeof(trace), field), \ sizeof(trace.field), is_signed_type(type)
static int __init __set_enter_print_fmt(struct syscall_metadata *entry, char *buf, int len) { int i; int pos = 0; /* When len=0, we just calculate the needed length */ #define LEN_OR_ZERO (len ? len - pos : 0) pos += snprintf(buf + pos, LEN_OR_ZERO, "\""); for (i = 0; i < entry->nb_args; i++) { pos += snprintf(buf + pos, LEN_OR_ZERO, "%s: 0x%%0%zulx%s", entry->args[i], sizeof(unsigned long), i == entry->nb_args - 1 ? "" : ", "); } pos += snprintf(buf + pos, LEN_OR_ZERO, "\""); for (i = 0; i < entry->nb_args; i++) { pos += snprintf(buf + pos, LEN_OR_ZERO, ", ((unsigned long)(REC->%s))", entry->args[i]); } #undef LEN_OR_ZERO /* return the length of print_fmt */ return pos; }

Contributors

PersonTokensPropCommitsCommitProp
Lai Jiangshan15699.36%150.00%
Li Zefan10.64%150.00%
Total157100.00%2100.00%


static int __init set_syscall_print_fmt(struct trace_event_call *call) { char *print_fmt; int len; struct syscall_metadata *entry = call->data; if (entry->enter_event != call) { call->print_fmt = "\"0x%lx\", REC->ret"; return 0; } /* First: called with 0 length to calculate the needed length */ len = __set_enter_print_fmt(entry, NULL, 0); print_fmt = kmalloc(len + 1, GFP_KERNEL); if (!print_fmt) return -ENOMEM; /* Second: actually write the @print_fmt */ __set_enter_print_fmt(entry, print_fmt, len + 1); call->print_fmt = print_fmt; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Lai Jiangshan9898.00%133.33%
Steven Rostedt11.00%133.33%
Li Zefan11.00%133.33%
Total100100.00%3100.00%


static void __init free_syscall_print_fmt(struct trace_event_call *call) { struct syscall_metadata *entry = call->data; if (entry->enter_event == call) kfree(call->print_fmt); }

Contributors

PersonTokensPropCommitsCommitProp
Lai Jiangshan3494.44%133.33%
Steven Rostedt12.78%133.33%
Li Zefan12.78%133.33%
Total36100.00%3100.00%


static int __init syscall_enter_define_fields(struct trace_event_call *call) { struct syscall_trace_enter trace; struct syscall_metadata *meta = call->data; int ret; int i; int offset = offsetof(typeof(trace), args); ret = trace_define_field(call, SYSCALL_FIELD(int, nr, __syscall_nr), FILTER_OTHER); if (ret) return ret; for (i = 0; i < meta->nb_args; i++) { ret = trace_define_field(call, meta->types[i], meta->args[i], offset, sizeof(unsigned long), 0, FILTER_OTHER); offset += sizeof(unsigned long); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Li Zefan10177.69%337.50%
Lai Jiangshan2519.23%225.00%
Taeung Song21.54%112.50%
Steven Rostedt21.54%225.00%
Total130100.00%8100.00%


static int __init syscall_exit_define_fields(struct trace_event_call *call) { struct syscall_trace_exit trace; int ret; ret = trace_define_field(call, SYSCALL_FIELD(int, nr, __syscall_nr), FILTER_OTHER); if (ret) return ret; ret = trace_define_field(call, SYSCALL_FIELD(long, ret, ret), FILTER_OTHER); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Li Zefan3452.31%337.50%
Lai Jiangshan2335.38%112.50%
Taeung Song46.15%112.50%
Tom Zanussi23.08%112.50%
Steven Rostedt23.08%225.00%
Total65100.00%8100.00%


static void ftrace_syscall_enter(void *data, struct pt_regs *regs, long id) { struct trace_array *tr = data; struct trace_event_file *trace_file; struct syscall_trace_enter *entry; struct syscall_metadata *sys_data; struct ring_buffer_event *event; struct ring_buffer *buffer; unsigned long irq_flags; int pc; int syscall_nr; int size; syscall_nr = trace_get_syscall_nr(current, regs); if (syscall_nr < 0 || syscall_nr >= NR_syscalls) return; /* Here we're inside tp handler's rcu_read_lock_sched (__DO_TRACE) */ trace_file = rcu_dereference_sched(tr->enter_syscall_files[syscall_nr]); if (!trace_file) return; if (trace_trigger_soft_disabled(trace_file)) return; sys_data = syscall_nr_to_meta(syscall_nr); if (!sys_data) return; size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args; local_save_flags(irq_flags); pc = preempt_count(); buffer = tr->trace_buffer.buffer; event = trace_buffer_lock_reserve(buffer, sys_data->enter_event->event.type, size, irq_flags, pc); if (!event) return; entry = ring_buffer_event_data(event); entry->nr = syscall_nr; syscall_get_arguments(current, regs, 0, sys_data->nb_args, entry->args); event_trigger_unlock_commit(trace_file, buffer, event, entry, irq_flags, pc); }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker11650.22%29.09%
Steven Rostedt4117.75%940.91%
Tom Zanussi2611.26%313.64%
Jovi Zhangwei219.09%14.55%
Jason Baron104.33%29.09%
Hendrik Brueckner73.03%14.55%
Rabin Vincent41.73%14.55%
Li Zefan31.30%14.55%
Lai Jiangshan20.87%14.55%
Fengguang Wu10.43%14.55%
Total231100.00%22100.00%


static void ftrace_syscall_exit(void *data, struct pt_regs *regs, long ret) { struct trace_array *tr = data; struct trace_event_file *trace_file; struct syscall_trace_exit *entry; struct syscall_metadata *sys_data; struct ring_buffer_event *event; struct ring_buffer *buffer; unsigned long irq_flags; int pc; int syscall_nr; syscall_nr = trace_get_syscall_nr(current, regs); if (syscall_nr < 0 || syscall_nr >= NR_syscalls) return; /* Here we're inside tp handler's rcu_read_lock_sched (__DO_TRACE()) */ trace_file = rcu_dereference_sched(tr->exit_syscall_files[syscall_nr]); if (!trace_file) return; if (trace_trigger_soft_disabled(trace_file)) return; sys_data = syscall_nr_to_meta(syscall_nr); if (!sys_data) return; local_save_flags(irq_flags); pc = preempt_count(); buffer = tr->trace_buffer.buffer; event = trace_buffer_lock_reserve(buffer, sys_data->exit_event->event.type, sizeof(*entry), irq_flags, pc); if (!event) return; entry = ring_buffer_event_data(event); entry->nr = syscall_nr; entry->ret = syscall_get_return_value(current, regs); event_trigger_unlock_commit(trace_file, buffer, event, entry, irq_flags, pc); }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker9545.67%29.09%
Steven Rostedt3918.75%940.91%
Tom Zanussi2612.50%313.64%
Jovi Zhangwei2110.10%14.55%
Jason Baron104.81%29.09%
Hendrik Brueckner73.37%14.55%
Rabin Vincent41.92%14.55%
Li Zefan31.44%14.55%
Lai Jiangshan20.96%14.55%
Fengguang Wu10.48%14.55%
Total208100.00%22100.00%


static int reg_event_syscall_enter(struct trace_event_file *file, struct trace_event_call *call) { struct trace_array *tr = file->tr; int ret = 0; int num; num = ((struct syscall_metadata *)call->data)->syscall_nr; if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls)) return -ENOSYS; mutex_lock(&syscall_trace_lock); if (!tr->sys_refcount_enter) ret = register_trace_sys_enter(ftrace_syscall_enter, tr); if (!ret) { rcu_assign_pointer(tr->enter_syscall_files[num], file); tr->sys_refcount_enter++; } mutex_unlock(&syscall_trace_lock); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jason Baron6050.00%212.50%
Steven Rostedt2319.17%425.00%
Frédéric Weisbecker1210.00%212.50%
Tom Zanussi75.83%16.25%
Lai Jiangshan75.83%212.50%
Masami Hiramatsu54.17%16.25%
Ian Munsie32.50%16.25%
Li Zefan10.83%16.25%
Josh Stone10.83%16.25%
Fengguang Wu10.83%16.25%
Total120100.00%16100.00%


static void unreg_event_syscall_enter(struct trace_event_file *file, struct trace_event_call *call) { struct trace_array *tr = file->tr; int num; num = ((struct syscall_metadata *)call->data)->syscall_nr; if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls)) return; mutex_lock(&syscall_trace_lock); tr->sys_refcount_enter--; RCU_INIT_POINTER(tr->enter_syscall_files[num], NULL); if (!tr->sys_refcount_enter) unregister_trace_sys_enter(ftrace_syscall_enter, tr); mutex_unlock(&syscall_trace_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Jason Baron4949.00%212.50%
Steven Rostedt2323.00%425.00%
Lai Jiangshan77.00%212.50%
Tom Zanussi66.00%16.25%
Masami Hiramatsu55.00%16.25%
Frédéric Weisbecker44.00%212.50%
Ian Munsie33.00%16.25%
Andreea-Cristina Bernat11.00%16.25%
Fengguang Wu11.00%16.25%
Josh Stone11.00%16.25%
Total100100.00%16100.00%


static int reg_event_syscall_exit(struct trace_event_file *file, struct trace_event_call *call) { struct trace_array *tr = file->tr; int ret = 0; int num; num = ((struct syscall_metadata *)call->data)->syscall_nr; if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls)) return -ENOSYS; mutex_lock(&syscall_trace_lock); if (!tr->sys_refcount_exit) ret = register_trace_sys_exit(ftrace_syscall_exit, tr); if (!ret) { rcu_assign_pointer(tr->exit_syscall_files[num], file); tr->sys_refcount_exit++; } mutex_unlock(&syscall_trace_lock); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jason Baron4638.33%213.33%
Steven Rostedt2319.17%426.67%
Frédéric Weisbecker2319.17%16.67%
Lai Jiangshan108.33%213.33%
Tom Zanussi75.83%16.67%
Masami Hiramatsu54.17%16.67%
Ian Munsie32.50%16.67%
Li Zefan10.83%16.67%
Josh Stone10.83%16.67%
Fengguang Wu10.83%16.67%
Total120100.00%15100.00%


static void unreg_event_syscall_exit(struct trace_event_file *file, struct trace_event_call *call) { struct trace_array *tr = file->tr; int num; num = ((struct syscall_metadata *)call->data)->syscall_nr; if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls)) return; mutex_lock(&syscall_trace_lock); tr->sys_refcount_exit--; RCU_INIT_POINTER(tr->exit_syscall_files[num], NULL); if (!tr->sys_refcount_exit) unregister_trace_sys_exit(ftrace_syscall_exit, tr); mutex_unlock(&syscall_trace_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Jason Baron3636.00%213.33%
Steven Rostedt2323.00%426.67%
Frédéric Weisbecker1414.00%16.67%
Lai Jiangshan1010.00%213.33%
Tom Zanussi66.00%16.67%
Masami Hiramatsu55.00%16.67%
Ian Munsie33.00%16.67%
Fengguang Wu11.00%16.67%
Josh Stone11.00%16.67%
Andreea-Cristina Bernat11.00%16.67%
Total100100.00%15100.00%


static int __init init_syscall_trace(struct trace_event_call *call) { int id; int num; num = ((struct syscall_metadata *)call->data)->syscall_nr; if (num < 0 || num >= NR_syscalls) { pr_debug("syscall %s metadata not mapped, disabling ftrace event\n", ((struct syscall_metadata *)call->data)->name); return -ENOSYS; } if (set_syscall_print_fmt(call) < 0) return -ENOMEM; id = trace_event_raw_init(call); if (id < 0) { free_syscall_print_fmt(call); return id; } return id; }

Contributors

PersonTokensPropCommitsCommitProp
Ian Munsie5249.06%114.29%
Lai Jiangshan4643.40%228.57%
Steven Rostedt65.66%228.57%
Li Zefan10.94%114.29%
Vaibhav Nagarnaik10.94%114.29%
Total106100.00%7100.00%

struct trace_event_functions enter_syscall_print_funcs = { .trace = print_syscall_enter, }; struct trace_event_functions exit_syscall_print_funcs = { .trace = print_syscall_exit, }; struct trace_event_class __refdata event_class_syscall_enter = { .system = "syscalls", .reg = syscall_enter_register, .define_fields = syscall_enter_define_fields, .get_fields = syscall_get_enter_fields, .raw_init = init_syscall_trace, }; struct trace_event_class __refdata event_class_syscall_exit = { .system = "syscalls", .reg = syscall_exit_register, .define_fields = syscall_exit_define_fields, .fields = LIST_HEAD_INIT(event_class_syscall_exit.fields), .raw_init = init_syscall_trace, };
unsigned long __init __weak arch_syscall_addr(int nr) { return (unsigned long)sys_call_table[nr]; }

Contributors

PersonTokensPropCommitsCommitProp
Mike Frysinger2095.24%150.00%
Ian Munsie14.76%150.00%
Total21100.00%2100.00%


void __init init_ftrace_syscalls(void) { struct syscall_metadata *meta; unsigned long addr; int i; syscalls_metadata = kcalloc(NR_syscalls, sizeof(*syscalls_metadata), GFP_KERNEL); if (!syscalls_metadata) { WARN_ON(1); return; } for (i = 0; i < NR_syscalls; i++) { addr = arch_syscall_addr(i); meta = find_syscall_meta(addr); if (!meta) continue; meta->syscall_nr = i; syscalls_metadata[i] = meta; } }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker7982.29%125.00%
Lai Jiangshan1212.50%125.00%
Thomas Meyer33.12%125.00%
Steven Rostedt22.08%125.00%
Total96100.00%4100.00%

#ifdef CONFIG_PERF_EVENTS static DECLARE_BITMAP(enabled_perf_enter_syscalls, NR_syscalls); static DECLARE_BITMAP(enabled_perf_exit_syscalls, NR_syscalls); static int sys_perf_refcount_enter; static int sys_perf_refcount_exit;
static int perf_call_bpf_enter(struct trace_event_call *call, struct pt_regs *regs, struct syscall_metadata *sys_data, struct syscall_trace_enter *rec) { struct syscall_tp_t { unsigned long long regs; unsigned long syscall_nr; unsigned long args[SYSCALL_DEFINE_MAXARGS]; } param; int i; *(struct pt_regs **)&param = regs; param.syscall_nr = rec->nr; for (i = 0; i < sys_data->nb_args; i++) param.args[i] = rec->args[i]; return trace_call_bpf(call, &param); }

Contributors

PersonTokensPropCommitsCommitProp
Yonghong Song109100.00%3100.00%
Total109100.00%3100.00%


static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id) { struct syscall_metadata *sys_data; struct syscall_trace_enter *rec; struct hlist_head *head; bool valid_prog_array; int syscall_nr; int rctx; int size; syscall_nr = trace_get_syscall_nr(current, regs); if (syscall_nr < 0 || syscall_nr >= NR_syscalls) return; if (!test_bit(syscall_nr, enabled_perf_enter_syscalls)) return; sys_data = syscall_nr_to_meta(syscall_nr); if (!sys_data) return; head = this_cpu_ptr(sys_data->enter_event->perf_events); valid_prog_array = bpf_prog_array_valid(sys_data->enter_event); if (!valid_prog_array && hlist_empty(head)) return; /* get the size after alignment with the u32 buffer size field */ size = sizeof(unsigned long) * sys_data->nb_args + sizeof(*rec); size = ALIGN(size + sizeof(u32), sizeof(u64)); size -= sizeof(u32); rec = perf_trace_buf_alloc(size, NULL, &rctx); if (!rec) return; rec->nr = syscall_nr; syscall_get_arguments(current, regs, 0, sys_data->nb_args, (unsigned long *)&rec->args); if ((valid_prog_array && !perf_call_bpf_enter(sys_data->enter_event, regs, sys_data, rec)) || hlist_empty(head)) { perf_swevent_put_recursion_context(rctx); return; } perf_trace_buf_submit(rec, size, rctx, sys_data->enter_event->event.type, 1, regs, head, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker9234.33%522.73%
Yonghong Song5219.40%29.09%
Jason Baron5119.03%14.55%
Oleg Nesterov155.60%14.55%
Xiao Guangrong155.60%14.55%
Peter Zijlstra103.73%522.73%
Alexei Starovoitov82.99%14.55%
Will Deacon72.61%14.55%
Li Zefan72.61%14.55%
Steven Rostedt51.87%29.09%
Rabin Vincent41.49%14.55%
Andrey Vagin20.75%14.55%
Total268100.00%22100.00%


static int perf_sysenter_enable(struct trace_event_call *call) { int ret = 0; int num; num = ((struct syscall_metadata *)call->data)->syscall_nr; mutex_lock(&syscall_trace_lock); if (!sys_perf_refcount_enter) ret = register_trace_sys_enter(perf_syscall_enter, NULL); if (ret) { pr_info("event trace: Could not activate syscall entry trace point"); } else { set_bit(num, enabled_perf_enter_syscalls); sys_perf_refcount_enter++; } mutex_unlock(&syscall_trace_lock); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jason Baron6271.26%112.50%
Lai Jiangshan1416.09%112.50%
Frédéric Weisbecker55.75%112.50%
Steven Rostedt33.45%225.00%
Vaibhav Nagarnaik11.15%112.50%
Colin Ian King11.15%112.50%
Josh Stone11.15%112.50%
Total87100.00%8100.00%


static void perf_sysenter_disable(struct trace_event_call *call) { int num; num = ((struct syscall_metadata *)call->data)->syscall_nr; mutex_lock(&syscall_trace_lock); sys_perf_refcount_enter--; clear_bit(num, enabled_perf_enter_syscalls); if (!sys_perf_refcount_enter) unregister_trace_sys_enter(perf_syscall_enter, NULL); mutex_unlock(&syscall_trace_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Jason Baron3961.90%114.29%
Lai Jiangshan1422.22%114.29%
Frédéric Weisbecker57.94%114.29%
Steven Rostedt34.76%228.57%
Vaibhav Nagarnaik11.59%114.29%
Josh Stone11.59%114.29%
Total63100.00%7100.00%


static int perf_call_bpf_exit(struct trace_event_call *call, struct pt_regs *regs, struct syscall_trace_exit *rec) { struct syscall_tp_t { unsigned long long regs; unsigned long syscall_nr; unsigned long ret; } param; *(struct pt_regs **)&param = regs; param.syscall_nr = rec->nr; param.ret = rec->ret; return trace_call_bpf(call, &param); }

Contributors

PersonTokensPropCommitsCommitProp
Yonghong Song77100.00%2100.00%
Total77100.00%2100.00%


static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret) { struct syscall_metadata *sys_data; struct syscall_trace_exit *rec; struct hlist_head *head; bool valid_prog_array; int syscall_nr; int rctx; int size; syscall_nr = trace_get_syscall_nr(current, regs); if (syscall_nr < 0 || syscall_nr >= NR_syscalls) return; if (!test_bit(syscall_nr, enabled_perf_exit_syscalls)) return; sys_data = syscall_nr_to_meta(syscall_nr); if (!sys_data) return; head = this_cpu_ptr(sys_data->exit_event->perf_events); valid_prog_array = bpf_prog_array_valid(sys_data->exit_event); if (!valid_prog_array && hlist_empty(head)) return; /* We can probably do that at build time */ size = ALIGN(sizeof(*rec) + sizeof(u32), sizeof(u64)); size -= sizeof(u32); rec = perf_trace_buf_alloc(size, NULL, &rctx); if (!rec) return; rec->nr = syscall_nr; rec->ret = syscall_get_return_value(current, regs); if ((valid_prog_array && !perf_call_bpf_exit(sys_data->exit_event, regs, rec)) || hlist_empty(head)) { perf_swevent_put_recursion_context(rctx); return; } perf_trace_buf_submit(rec, size, rctx, sys_data->exit_event->event.type, 1, regs, head, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker6025.00%522.73%
Jason Baron5924.58%14.55%
Yonghong Song5020.83%29.09%
Xiao Guangrong156.25%14.55%
Oleg Nesterov156.25%14.55%
Peter Zijlstra93.75%522.73%
Alexei Starovoitov83.33%14.55%
Will Deacon72.92%14.55%
Li Zefan62.50%14.55%
Steven Rostedt52.08%29.09%
Rabin Vincent41.67%14.55%
Andrey Vagin20.83%14.55%
Total240100.00%22100.00%


static int perf_sysexit_enable(struct trace_event_call *call) { int ret = 0; int num; num = ((struct syscall_metadata *)call->data)->syscall_nr; mutex_lock(&syscall_trace_lock); if (!sys_perf_refcount_exit) ret = register_trace_sys_exit(perf_syscall_exit, NULL); if (ret) { pr_info("event trace: Could not activate syscall exit trace point"); } else { set_bit(num, enabled_perf_exit_syscalls); sys_perf_refcount_exit++; } mutex_unlock(&syscall_trace_lock); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Jason Baron6271.26%112.50%
Lai Jiangshan1416.09%112.50%
Frédéric Weisbecker55.75%112.50%
Steven Rostedt33.45%225.00%
Josh Stone11.15%112.50%
Colin Ian King11.15%112.50%
Vaibhav Nagarnaik11.15%112.50%
Total87100.00%8100.00%


static void perf_sysexit_disable(struct trace_event_call *call) { int num; num = ((struct syscall_metadata *)call->data)->syscall_nr; mutex_lock(&syscall_trace_lock); sys_perf_refcount_exit--; clear_bit(num, enabled_perf_exit_syscalls); if (!sys_perf_refcount_exit) unregister_trace_sys_exit(perf_syscall_exit, NULL); mutex_unlock(&syscall_trace_lock); }

Contributors

PersonTokensPropCommitsCommitProp
Jason Baron3961.90%114.29%
Lai Jiangshan1422.22%114.29%
Frédéric Weisbecker57.94%114.29%
Steven Rostedt34.76%228.57%
Vaibhav Nagarnaik11.59%114.29%
Josh Stone11.59%114.29%
Total63100.00%7100.00%

#endif /* CONFIG_PERF_EVENTS */
static int syscall_enter_register(struct trace_event_call *event, enum trace_reg type, void *data) { struct trace_event_file *file = data; switch (type) { case TRACE_REG_REGISTER: return reg_event_syscall_enter(file, event); case TRACE_REG_UNREGISTER: unreg_event_syscall_enter(file, event); return 0; #ifdef CONFIG_PERF_EVENTS case TRACE_REG_PERF_REGISTER: return perf_sysenter_enable(event); case TRACE_REG_PERF_UNREGISTER: perf_sysenter_disable(event); return 0; case TRACE_REG_PERF_OPEN: case TRACE_REG_PERF_CLOSE: case TRACE_REG_PERF_ADD: case TRACE_REG_PERF_DEL: return 0; #endif } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt8080.81%466.67%
Jiri Olsa1919.19%233.33%
Total99100.00%6100.00%


static int syscall_exit_register(struct trace_event_call *event, enum trace_reg type, void *data) { struct trace_event_file *file = data; switch (type) { case TRACE_REG_REGISTER: return reg_event_syscall_exit(file, event); case TRACE_REG_UNREGISTER: unreg_event_syscall_exit(file, event); return 0; #ifdef CONFIG_PERF_EVENTS case TRACE_REG_PERF_REGISTER: return perf_sysexit_enable(event); case TRACE_REG_PERF_UNREGISTER: perf_sysexit_disable(event); return 0; case TRACE_REG_PERF_OPEN: case TRACE_REG_PERF_CLOSE: case TRACE_REG_PERF_ADD: case TRACE_REG_PERF_DEL: return 0; #endif } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Steven Rostedt8080.81%466.67%
Jiri Olsa1919.19%233.33%
Total99100.00%6100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Frédéric Weisbecker89224.12%1010.87%
Jason Baron60816.44%44.35%
Steven Rostedt58215.74%1819.57%
Lai Jiangshan49213.30%77.61%
Yonghong Song2887.79%33.26%
Li Zefan1965.30%1010.87%
Ian Munsie1153.11%55.43%
Tom Zanussi1153.11%55.43%
Vaibhav Nagarnaik922.49%11.09%
Jiri Olsa461.24%22.17%
Jovi Zhangwei451.22%33.26%
Oleg Nesterov300.81%11.09%
Xiao Guangrong300.81%11.09%
Masami Hiramatsu200.54%11.09%
Mike Frysinger200.54%11.09%
Peter Zijlstra190.51%55.43%
Alexei Starovoitov160.43%11.09%
Rabin Vincent160.43%11.09%
Hendrik Brueckner140.38%11.09%
Will Deacon140.38%11.09%
Josh Stone110.30%11.09%
Taeung Song90.24%11.09%
Fengguang Wu80.22%11.09%
Andrey Vagin40.11%11.09%
Paul Gortmaker40.11%11.09%
Tejun Heo30.08%11.09%
Thomas Meyer30.08%11.09%
Colin Ian King20.05%11.09%
Andreea-Cristina Bernat20.05%11.09%
Greg Kroah-Hartman10.03%11.09%
Ingo Molnar10.03%11.09%
Total3698100.00%92100.00%
Directory: kernel/trace
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.