Lines Matching +full:ipa +full:- +full:shared

1 // SPDX-License-Identifier: GPL-2.0
3 * Infrastructure for profiling code inserted by 'gcc -pg'.
5 * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
6 * Copyright (C) 2004-2008 Ingo Molnar <mingo@redhat.com>
8 * Originally ported from the -rt patch by:
13 * Copyright (C) 2004-2006 Ingo Molnar
100 if (!(ops->flags & FTRACE_OPS_FL_PID) || !ops->private) in ftrace_pids_enabled()
103 tr = ops->private; in ftrace_pids_enabled()
105 return tr->function_pids != NULL || tr->function_no_pids != NULL; in ftrace_pids_enabled()
134 if (!(ops->flags & FTRACE_OPS_FL_INITIALIZED)) { in ftrace_ops_init()
135 mutex_init(&ops->local_hash.regex_lock); in ftrace_ops_init()
136 ops->func_hash = &ops->local_hash; in ftrace_ops_init()
137 ops->flags |= FTRACE_OPS_FL_INITIALIZED; in ftrace_ops_init()
145 struct trace_array *tr = op->private; in ftrace_pid_func()
149 pid = this_cpu_read(tr->array_buffer.data->ftrace_ignore_pid); in ftrace_pid_func()
153 pid != current->pid) in ftrace_pid_func()
157 op->saved_func(ip, parent_ip, op, regs); in ftrace_pid_func()
172 if (ops->flags & (FTRACE_OPS_FL_DYNAMIC | FTRACE_OPS_FL_RCU) || in ftrace_ops_get_list_func()
200 } else if (rcu_dereference_protected(ftrace_ops_list->next, in update_ftrace_function()
261 rcu_assign_pointer(ops->next, *list); in add_ftrace_ops()
266 * the ops->next pointer is valid before another CPU sees in add_ftrace_ops()
283 rcu_dereference_protected(ops->next, in remove_ftrace_ops()
289 for (p = list; *p != &ftrace_list_end; p = &(*p)->next) in remove_ftrace_ops()
294 return -1; in remove_ftrace_ops()
296 *p = (*p)->next; in remove_ftrace_ops()
304 if (ops->flags & FTRACE_OPS_FL_DELETED) in __register_ftrace_function()
305 return -EINVAL; in __register_ftrace_function()
307 if (WARN_ON(ops->flags & FTRACE_OPS_FL_ENABLED)) in __register_ftrace_function()
308 return -EBUSY; in __register_ftrace_function()
316 if (ops->flags & FTRACE_OPS_FL_SAVE_REGS && in __register_ftrace_function()
317 !(ops->flags & FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED)) in __register_ftrace_function()
318 return -EINVAL; in __register_ftrace_function()
320 if (ops->flags & FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED) in __register_ftrace_function()
321 ops->flags |= FTRACE_OPS_FL_SAVE_REGS; in __register_ftrace_function()
323 if (!ftrace_enabled && (ops->flags & FTRACE_OPS_FL_PERMANENT)) in __register_ftrace_function()
324 return -EBUSY; in __register_ftrace_function()
327 ops->flags |= FTRACE_OPS_FL_DYNAMIC; in __register_ftrace_function()
332 ops->saved_func = ops->func; in __register_ftrace_function()
335 ops->func = ftrace_pid_func; in __register_ftrace_function()
349 if (WARN_ON(!(ops->flags & FTRACE_OPS_FL_ENABLED))) in __unregister_ftrace_function()
350 return -EBUSY; in __unregister_ftrace_function()
360 ops->func = ops->saved_func; in __unregister_ftrace_function()
374 if (op->flags & FTRACE_OPS_FL_PID) { in ftrace_update_pid_func()
375 op->func = ftrace_pids_enabled(op) ? in ftrace_update_pid_func()
376 ftrace_pid_func : op->saved_func; in ftrace_update_pid_func()
410 (PAGE_SIZE - offsetof(struct ftrace_profile_page, records))
417 /* ftrace_profile_lock - synchronize the enable and disable of the profiler */
437 if ((void *)rec >= (void *)&pg->records[pg->index]) { in function_stat_next()
438 pg = pg->next; in function_stat_next()
441 rec = &pg->records[0]; in function_stat_next()
442 if (!rec->counter) in function_stat_next()
454 if (!stat || !stat->start) in function_stat_start()
457 return function_stat_next(&stat->start->records[0], 0); in function_stat_start()
467 if (a->time < b->time) in function_stat_cmp()
468 return -1; in function_stat_cmp()
469 if (a->time > b->time) in function_stat_cmp()
481 if (a->counter < b->counter) in function_stat_cmp()
482 return -1; in function_stat_cmp()
483 if (a->counter > b->counter) in function_stat_cmp()
495 " -------- " in function_stat_headers()
496 "--- ---- --- ---\n"); in function_stat_headers()
499 " -------- ---\n"); in function_stat_headers()
517 if (unlikely(rec->counter == 0)) { in function_stat_show()
518 ret = -EBUSY; in function_stat_show()
523 avg = div64_ul(rec->time, rec->counter); in function_stat_show()
528 kallsyms_lookup(rec->ip, NULL, NULL, NULL, str); in function_stat_show()
529 seq_printf(m, " %-30.30s %10lu", str, rec->counter); in function_stat_show()
535 if (rec->counter <= 1) in function_stat_show()
540 * s^2 = 1 / (n * (n-1)) * (n * \Sum (x_i)^2 - (\Sum x_i)^2) in function_stat_show()
542 stddev = rec->counter * rec->time_squared - in function_stat_show()
543 rec->time * rec->time; in function_stat_show()
546 * Divide only 1000 for ns^2 -> us^2 conversion. in function_stat_show()
550 rec->counter * (rec->counter - 1) * 1000); in function_stat_show()
554 trace_print_graph_duration(rec->time, &s); in function_stat_show()
572 pg = stat->pages = stat->start; in ftrace_profile_reset()
575 memset(pg->records, 0, PROFILE_RECORDS_SIZE); in ftrace_profile_reset()
576 pg->index = 0; in ftrace_profile_reset()
577 pg = pg->next; in ftrace_profile_reset()
580 memset(stat->hash, 0, in ftrace_profile_reset()
592 if (stat->pages) in ftrace_profile_pages_init()
595 stat->pages = (void *)get_zeroed_page(GFP_KERNEL); in ftrace_profile_pages_init()
596 if (!stat->pages) in ftrace_profile_pages_init()
597 return -ENOMEM; in ftrace_profile_pages_init()
612 pg = stat->start = stat->pages; in ftrace_profile_pages_init()
617 pg->next = (void *)get_zeroed_page(GFP_KERNEL); in ftrace_profile_pages_init()
618 if (!pg->next) in ftrace_profile_pages_init()
620 pg = pg->next; in ftrace_profile_pages_init()
626 pg = stat->start; in ftrace_profile_pages_init()
630 pg = pg->next; in ftrace_profile_pages_init()
634 stat->pages = NULL; in ftrace_profile_pages_init()
635 stat->start = NULL; in ftrace_profile_pages_init()
637 return -ENOMEM; in ftrace_profile_pages_init()
647 if (stat->hash) { in ftrace_profile_init_cpu()
659 stat->hash = kcalloc(size, sizeof(struct hlist_head), GFP_KERNEL); in ftrace_profile_init_cpu()
661 if (!stat->hash) in ftrace_profile_init_cpu()
662 return -ENOMEM; in ftrace_profile_init_cpu()
666 kfree(stat->hash); in ftrace_profile_init_cpu()
667 stat->hash = NULL; in ftrace_profile_init_cpu()
668 return -ENOMEM; in ftrace_profile_init_cpu()
697 hhd = &stat->hash[key]; in ftrace_find_profiled_func()
703 if (rec->ip == ip) in ftrace_find_profiled_func()
715 key = hash_long(rec->ip, FTRACE_PROFILE_HASH_BITS); in ftrace_add_profile()
716 hlist_add_head_rcu(&rec->node, &stat->hash[key]); in ftrace_add_profile()
728 if (atomic_inc_return(&stat->disabled) != 1) in ftrace_profile_alloc()
739 if (stat->pages->index == PROFILES_PER_PAGE) { in ftrace_profile_alloc()
740 if (!stat->pages->next) in ftrace_profile_alloc()
742 stat->pages = stat->pages->next; in ftrace_profile_alloc()
745 rec = &stat->pages->records[stat->pages->index++]; in ftrace_profile_alloc()
746 rec->ip = ip; in ftrace_profile_alloc()
750 atomic_dec(&stat->disabled); in ftrace_profile_alloc()
769 if (!stat->hash || !ftrace_profile_enabled) in function_profile_call()
779 rec->counter++; in function_profile_call()
796 function_profile_call(trace->func, 0, NULL, NULL); in profile_graph_entry()
799 if (!current->ret_stack) in profile_graph_entry()
804 ret_stack->subtime = 0; in profile_graph_entry()
819 if (!stat->hash || !ftrace_profile_enabled) in profile_graph_return()
823 if (!trace->calltime) in profile_graph_return()
826 calltime = trace->rettime - trace->calltime; in profile_graph_return()
833 ret_stack->subtime += calltime; in profile_graph_return()
836 if (ret_stack && ret_stack->subtime < calltime) in profile_graph_return()
837 calltime -= ret_stack->subtime; in profile_graph_return()
842 rec = ftrace_find_profiled_func(stat, trace->func); in profile_graph_return()
844 rec->time += calltime; in profile_graph_return()
845 rec->time_squared += calltime * calltime; in profile_graph_return()
979 stat->stat = function_stats; in ftrace_profile_tracefs()
980 stat->stat.name = name; in ftrace_profile_tracefs()
981 ret = register_stat_tracer(&stat->stat); in ftrace_profile_tracefs()
1067 if (op->trampoline && op->trampoline_size) in ftrace_ops_trampoline()
1068 if (addr >= op->trampoline && in ftrace_ops_trampoline()
1069 addr < op->trampoline + op->trampoline_size) { in ftrace_ops_trampoline()
1106 if (hash->size_bits > 0) in ftrace_hash_key()
1107 return hash_long(ip, hash->size_bits); in ftrace_hash_key()
1121 hhd = &hash->buckets[key]; in __ftrace_lookup_ip()
1124 if (entry->ip == ip) in __ftrace_lookup_ip()
1131 * ftrace_lookup_ip - Test to see if an ip exists in an ftrace_hash
1155 key = ftrace_hash_key(hash, entry->ip); in __add_hash_entry()
1156 hhd = &hash->buckets[key]; in __add_hash_entry()
1157 hlist_add_head(&entry->hlist, hhd); in __add_hash_entry()
1158 hash->count++; in __add_hash_entry()
1167 return -ENOMEM; in add_hash_entry()
1169 entry->ip = ip; in add_hash_entry()
1179 hlist_del(&entry->hlist); in free_hash_entry()
1181 hash->count--; in free_hash_entry()
1188 hlist_del_rcu(&entry->hlist); in remove_hash_entry()
1189 hash->count--; in remove_hash_entry()
1197 int size = 1 << hash->size_bits; in ftrace_hash_clear()
1200 if (!hash->count) in ftrace_hash_clear()
1204 hhd = &hash->buckets[i]; in ftrace_hash_clear()
1208 FTRACE_WARN_ON(hash->count); in ftrace_hash_clear()
1213 list_del(&ftrace_mod->list); in free_ftrace_mod()
1214 kfree(ftrace_mod->module); in free_ftrace_mod()
1215 kfree(ftrace_mod->func); in free_ftrace_mod()
1238 kfree(hash->buckets); in free_ftrace_hash()
1254 call_rcu(&hash->rcu, __free_ftrace_hash_rcu); in free_ftrace_hash_rcu()
1260 free_ftrace_hash(ops->func_hash->filter_hash); in ftrace_free_filter()
1261 free_ftrace_hash(ops->func_hash->notrace_hash); in ftrace_free_filter()
1274 hash->buckets = kcalloc(size, sizeof(*hash->buckets), GFP_KERNEL); in alloc_ftrace_hash()
1276 if (!hash->buckets) { in alloc_ftrace_hash()
1281 hash->size_bits = size_bits; in alloc_ftrace_hash()
1292 struct list_head *mod_head = enable ? &tr->mod_trace : &tr->mod_notrace; in ftrace_add_mod()
1296 return -ENOMEM; in ftrace_add_mod()
1298 ftrace_mod->func = kstrdup(func, GFP_KERNEL); in ftrace_add_mod()
1299 ftrace_mod->module = kstrdup(module, GFP_KERNEL); in ftrace_add_mod()
1300 ftrace_mod->enable = enable; in ftrace_add_mod()
1302 if (!ftrace_mod->func || !ftrace_mod->module) in ftrace_add_mod()
1305 list_add(&ftrace_mod->list, mod_head); in ftrace_add_mod()
1312 return -ENOMEM; in ftrace_add_mod()
1329 new_hash->flags = hash->flags; in alloc_and_copy_ftrace_hash()
1335 size = 1 << hash->size_bits; in alloc_and_copy_ftrace_hash()
1337 hlist_for_each_entry(entry, &hash->buckets[i], hlist) { in alloc_and_copy_ftrace_hash()
1338 ret = add_hash_entry(new_hash, entry->ip); in alloc_and_copy_ftrace_hash()
1344 FTRACE_WARN_ON(new_hash->count != hash->count); in alloc_and_copy_ftrace_hash()
1384 new_hash->flags = src->flags; in dup_hash()
1386 size = 1 << src->size_bits; in dup_hash()
1388 hhd = &src->buckets[i]; in dup_hash()
1400 int size = src->count; in __ftrace_hash_move()
1419 if (ops->flags & FTRACE_OPS_FL_IPMODIFY && !enable) in ftrace_hash_move()
1420 return -EINVAL; in ftrace_hash_move()
1424 return -ENOMEM; in ftrace_hash_move()
1458 return (ftrace_hash_empty(hash->filter_hash) || in hash_contains_ip()
1459 __ftrace_lookup_ip(hash->filter_hash, ip)) && in hash_contains_ip()
1460 (ftrace_hash_empty(hash->notrace_hash) || in hash_contains_ip()
1461 !__ftrace_lookup_ip(hash->notrace_hash, ip)); in hash_contains_ip()
1466 * the ops->func or not.
1468 * It's a match if the ip is in the ops->filter_hash or
1471 * the ip is not in the ops->notrace_hash.
1488 if (regs == NULL && (ops->flags & FTRACE_OPS_FL_SAVE_REGS)) in ftrace_ops_test()
1492 rcu_assign_pointer(hash.filter_hash, ops->func_hash->filter_hash); in ftrace_ops_test()
1493 rcu_assign_pointer(hash.notrace_hash, ops->func_hash->notrace_hash); in ftrace_ops_test()
1508 for (pg = ftrace_pages_start; pg; pg = pg->next) { \
1510 for (_____i = 0; _____i < pg->index; _____i++) { \
1511 rec = &pg->records[_____i];
1523 if (key->flags < rec->ip) in ftrace_cmp_recs()
1524 return -1; in ftrace_cmp_recs()
1525 if (key->ip >= rec->ip + MCOUNT_INSN_SIZE) in ftrace_cmp_recs()
1539 for (pg = ftrace_pages_start; pg; pg = pg->next) { in lookup_rec()
1540 if (end < pg->records[0].ip || in lookup_rec()
1541 start >= (pg->records[pg->index - 1].ip + MCOUNT_INSN_SIZE)) in lookup_rec()
1543 rec = bsearch(&key, pg->records, pg->index, in lookup_rec()
1553 * ftrace_location_range - return the first address of a traced location
1559 * Returns rec->ip if the related ftrace location is a least partly within
1570 return rec->ip; in ftrace_location_range()
1576 * ftrace_location - return true if the ip giving is a traced location
1579 * Returns rec->ip if @ip given is a pointer to a ftrace location.
1590 * ftrace_text_reserved - return true if range contains an ftrace location
1616 ops != &ftrace_list_end; ops = ops->next) { in test_rec_ops_needs_regs()
1617 /* pass rec in as regs to have non-NULL val */ in test_rec_ops_needs_regs()
1618 if (ftrace_ops_test(ops, rec->ip, rec)) { in test_rec_ops_needs_regs()
1619 if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) { in test_rec_ops_needs_regs()
1649 if (!(ops->flags & FTRACE_OPS_FL_ENABLED)) in __ftrace_hash_rec_update()
1664 hash = ops->func_hash->filter_hash; in __ftrace_hash_rec_update()
1665 other_hash = ops->func_hash->notrace_hash; in __ftrace_hash_rec_update()
1670 hash = ops->func_hash->notrace_hash; in __ftrace_hash_rec_update()
1671 other_hash = ops->func_hash->filter_hash; in __ftrace_hash_rec_update()
1685 if (rec->flags & FTRACE_FL_DISABLED) in __ftrace_hash_rec_update()
1693 if (!other_hash || !ftrace_lookup_ip(other_hash, rec->ip)) in __ftrace_hash_rec_update()
1696 in_hash = !!ftrace_lookup_ip(hash, rec->ip); in __ftrace_hash_rec_update()
1697 in_other_hash = !!ftrace_lookup_ip(other_hash, rec->ip); in __ftrace_hash_rec_update()
1719 rec->flags++; in __ftrace_hash_rec_update()
1723 if (ops->flags & FTRACE_OPS_FL_DIRECT) in __ftrace_hash_rec_update()
1724 rec->flags |= FTRACE_FL_DIRECT; in __ftrace_hash_rec_update()
1731 if (ftrace_rec_count(rec) == 1 && ops->trampoline) in __ftrace_hash_rec_update()
1732 rec->flags |= FTRACE_FL_TRAMP; in __ftrace_hash_rec_update()
1740 rec->flags &= ~FTRACE_FL_TRAMP; in __ftrace_hash_rec_update()
1746 if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) in __ftrace_hash_rec_update()
1747 rec->flags |= FTRACE_FL_REGS; in __ftrace_hash_rec_update()
1751 rec->flags--; in __ftrace_hash_rec_update()
1759 if (ops->flags & FTRACE_OPS_FL_DIRECT) in __ftrace_hash_rec_update()
1760 rec->flags &= ~FTRACE_FL_DIRECT; in __ftrace_hash_rec_update()
1769 rec->flags & FTRACE_FL_REGS && in __ftrace_hash_rec_update()
1770 ops->flags & FTRACE_OPS_FL_SAVE_REGS) { in __ftrace_hash_rec_update()
1772 rec->flags &= ~FTRACE_FL_REGS; in __ftrace_hash_rec_update()
1784 rec->flags |= FTRACE_FL_TRAMP; in __ftrace_hash_rec_update()
1786 rec->flags &= ~FTRACE_FL_TRAMP; in __ftrace_hash_rec_update()
1799 if (!all && count == hash->count) in __ftrace_hash_rec_update()
1825 if (ops->func_hash != &global_ops.local_hash) in ftrace_hash_rec_update_modify()
1836 if (op->func_hash == &global_ops.local_hash) in ftrace_hash_rec_update_modify()
1855 * or no-needed to update, -EBUSY if it detects a conflict of the flag
1856 * on a ftrace_rec, and -EINVAL if the new_hash tries to trace all recs.
1858 * - If the hash is NULL, it hits all recs (if IPMODIFY is set, this is rejected)
1859 * - If the hash is EMPTY_HASH, it hits nothing
1860 * - Anything else hits the recs which match the hash entries.
1871 if (!(ops->flags & FTRACE_OPS_FL_ENABLED)) in __ftrace_hash_update_ipmodify()
1874 if (!(ops->flags & FTRACE_OPS_FL_IPMODIFY)) in __ftrace_hash_update_ipmodify()
1882 return -EINVAL; in __ftrace_hash_update_ipmodify()
1884 /* Update rec->flags */ in __ftrace_hash_update_ipmodify()
1887 if (rec->flags & FTRACE_FL_DISABLED) in __ftrace_hash_update_ipmodify()
1891 in_old = !!ftrace_lookup_ip(old_hash, rec->ip); in __ftrace_hash_update_ipmodify()
1892 in_new = !!ftrace_lookup_ip(new_hash, rec->ip); in __ftrace_hash_update_ipmodify()
1898 if (rec->flags & FTRACE_FL_IPMODIFY) in __ftrace_hash_update_ipmodify()
1900 rec->flags |= FTRACE_FL_IPMODIFY; in __ftrace_hash_update_ipmodify()
1902 rec->flags &= ~FTRACE_FL_IPMODIFY; in __ftrace_hash_update_ipmodify()
1913 if (rec->flags & FTRACE_FL_DISABLED) in __ftrace_hash_update_ipmodify()
1919 in_old = !!ftrace_lookup_ip(old_hash, rec->ip); in __ftrace_hash_update_ipmodify()
1920 in_new = !!ftrace_lookup_ip(new_hash, rec->ip); in __ftrace_hash_update_ipmodify()
1925 rec->flags &= ~FTRACE_FL_IPMODIFY; in __ftrace_hash_update_ipmodify()
1927 rec->flags |= FTRACE_FL_IPMODIFY; in __ftrace_hash_update_ipmodify()
1931 return -EBUSY; in __ftrace_hash_update_ipmodify()
1936 struct ftrace_hash *hash = ops->func_hash->filter_hash; in ftrace_hash_ipmodify_enable()
1947 struct ftrace_hash *hash = ops->func_hash->filter_hash; in ftrace_hash_ipmodify_disable()
1958 struct ftrace_hash *old_hash = ops->func_hash->filter_hash; in ftrace_hash_ipmodify_update()
2003 * ftrace_bug - report and shutdown function tracer
2010 * EFAULT - if the problem happens on reading the @ip address
2011 * EINVAL - if what is read at @ip is not what was expected
2012 * EPERM - if the problem happens on writing to the @ip address
2016 unsigned long ip = rec ? rec->ip : 0; in ftrace_bug()
2018 pr_info("------------[ ftrace bug ]------------\n"); in ftrace_bug()
2021 case -EFAULT: in ftrace_bug()
2025 case -EINVAL: in ftrace_bug()
2035 case -EPERM: in ftrace_bug()
2047 pr_info("ftrace record flags: %lx\n", rec->flags); in ftrace_bug()
2049 rec->flags & FTRACE_FL_REGS ? " R" : " "); in ftrace_bug()
2050 if (rec->flags & FTRACE_FL_TRAMP_EN) { in ftrace_bug()
2055 (void *)ops->trampoline, in ftrace_bug()
2056 (void *)ops->func); in ftrace_bug()
2076 if (rec->flags & FTRACE_FL_DISABLED) in ftrace_check_record()
2100 if (!(rec->flags & FTRACE_FL_REGS) != in ftrace_check_record()
2101 !(rec->flags & FTRACE_FL_REGS_EN)) in ftrace_check_record()
2104 if (!(rec->flags & FTRACE_FL_TRAMP) != in ftrace_check_record()
2105 !(rec->flags & FTRACE_FL_TRAMP_EN)) in ftrace_check_record()
2119 if (!(rec->flags & FTRACE_FL_DIRECT) != in ftrace_check_record()
2120 !(rec->flags & FTRACE_FL_DIRECT_EN)) in ftrace_check_record()
2122 } else if (rec->flags & FTRACE_FL_DIRECT_EN) { in ftrace_check_record()
2128 if ((rec->flags & FTRACE_FL_ENABLED) == flag) in ftrace_check_record()
2133 flag ^= rec->flags & FTRACE_FL_ENABLED; in ftrace_check_record()
2136 rec->flags |= FTRACE_FL_ENABLED; in ftrace_check_record()
2138 if (rec->flags & FTRACE_FL_REGS) in ftrace_check_record()
2139 rec->flags |= FTRACE_FL_REGS_EN; in ftrace_check_record()
2141 rec->flags &= ~FTRACE_FL_REGS_EN; in ftrace_check_record()
2144 if (rec->flags & FTRACE_FL_TRAMP) in ftrace_check_record()
2145 rec->flags |= FTRACE_FL_TRAMP_EN; in ftrace_check_record()
2147 rec->flags &= ~FTRACE_FL_TRAMP_EN; in ftrace_check_record()
2156 if (rec->flags & FTRACE_FL_DIRECT) in ftrace_check_record()
2157 rec->flags |= FTRACE_FL_DIRECT_EN; in ftrace_check_record()
2159 rec->flags &= ~FTRACE_FL_DIRECT_EN; in ftrace_check_record()
2165 rec->flags &= ~FTRACE_FL_DIRECT_EN; in ftrace_check_record()
2175 * from the save regs, to a non-save regs function or in ftrace_check_record()
2190 rec->flags = 0; in ftrace_check_record()
2196 rec->flags &= ~(FTRACE_FL_ENABLED | FTRACE_FL_TRAMP_EN | in ftrace_check_record()
2235 unsigned long ip = rec->ip; in ftrace_find_tramp_ops_any()
2239 if (!op->trampoline) in ftrace_find_tramp_ops_any()
2242 if (hash_contains_ip(ip, op->func_hash)) in ftrace_find_tramp_ops_any()
2253 unsigned long ip = rec->ip; in ftrace_find_tramp_ops_any_other()
2257 if (op == op_exclude || !op->trampoline) in ftrace_find_tramp_ops_any_other()
2260 if (hash_contains_ip(ip, op->func_hash)) in ftrace_find_tramp_ops_any_other()
2271 unsigned long ip = rec->ip; in ftrace_find_tramp_ops_next()
2275 if (!op->trampoline) in ftrace_find_tramp_ops_next()
2278 if (hash_contains_ip(ip, op->func_hash)) in ftrace_find_tramp_ops_next()
2289 unsigned long ip = rec->ip; in ftrace_find_tramp_ops_curr()
2298 if (hash_contains_ip(ip, &removed_ops->old_hash)) in ftrace_find_tramp_ops_curr()
2322 if (!op->trampoline) in ftrace_find_tramp_ops_curr()
2329 if (op->flags & FTRACE_OPS_FL_ADDING) in ftrace_find_tramp_ops_curr()
2338 if ((op->flags & FTRACE_OPS_FL_MODIFYING) && in ftrace_find_tramp_ops_curr()
2339 hash_contains_ip(ip, &op->old_hash)) in ftrace_find_tramp_ops_curr()
2346 if (!(op->flags & FTRACE_OPS_FL_MODIFYING) && in ftrace_find_tramp_ops_curr()
2347 hash_contains_ip(ip, op->func_hash)) in ftrace_find_tramp_ops_curr()
2359 unsigned long ip = rec->ip; in ftrace_find_tramp_ops_new()
2362 /* pass rec in as regs to have non-NULL val */ in ftrace_find_tramp_ops_new()
2363 if (hash_contains_ip(ip, op->func_hash)) in ftrace_find_tramp_ops_new()
2388 return entry->direct; in ftrace_find_rec_direct()
2420 * ftrace_get_addr_new - Get the call address to set to
2434 if ((rec->flags & FTRACE_FL_DIRECT) && in ftrace_get_addr_new()
2436 addr = ftrace_find_rec_direct(rec->ip); in ftrace_get_addr_new()
2443 if (rec->flags & FTRACE_FL_TRAMP) { in ftrace_get_addr_new()
2445 if (FTRACE_WARN_ON(!ops || !ops->trampoline)) { in ftrace_get_addr_new()
2447 (void *)rec->ip, (void *)rec->ip, rec->flags); in ftrace_get_addr_new()
2451 return ops->trampoline; in ftrace_get_addr_new()
2454 if (rec->flags & FTRACE_FL_REGS) in ftrace_get_addr_new()
2461 * ftrace_get_addr_curr - Get the call address that is already there
2476 if (rec->flags & FTRACE_FL_DIRECT_EN) { in ftrace_get_addr_curr()
2477 addr = ftrace_find_rec_direct(rec->ip); in ftrace_get_addr_curr()
2484 if (rec->flags & FTRACE_FL_TRAMP_EN) { in ftrace_get_addr_curr()
2488 (void *)rec->ip, (void *)rec->ip); in ftrace_get_addr_curr()
2492 return ops->trampoline; in ftrace_get_addr_curr()
2495 if (rec->flags & FTRACE_FL_REGS_EN) in ftrace_get_addr_curr()
2534 return -1; /* unknown ftrace bug */ in __ftrace_replace_code()
2550 if (rec->flags & FTRACE_FL_DISABLED) in ftrace_replace_code()
2587 iter->pg = ftrace_pages_start; in ftrace_rec_iter_start()
2588 iter->index = 0; in ftrace_rec_iter_start()
2591 while (iter->pg && !iter->pg->index) in ftrace_rec_iter_start()
2592 iter->pg = iter->pg->next; in ftrace_rec_iter_start()
2594 if (!iter->pg) in ftrace_rec_iter_start()
2608 iter->index++; in ftrace_rec_iter_next()
2610 if (iter->index >= iter->pg->index) { in ftrace_rec_iter_next()
2611 iter->pg = iter->pg->next; in ftrace_rec_iter_next()
2612 iter->index = 0; in ftrace_rec_iter_next()
2615 while (iter->pg && !iter->pg->index) in ftrace_rec_iter_next()
2616 iter->pg = iter->pg->next; in ftrace_rec_iter_next()
2619 if (!iter->pg) in ftrace_rec_iter_next()
2633 return &iter->pg->records[iter->index]; in ftrace_rec_iter_record()
2776 ops->flags |= FTRACE_OPS_FL_MODIFYING; in ftrace_run_modify_code()
2777 ops->old_hash.filter_hash = old_hash->filter_hash; in ftrace_run_modify_code()
2778 ops->old_hash.notrace_hash = old_hash->notrace_hash; in ftrace_run_modify_code()
2780 ops->old_hash.filter_hash = NULL; in ftrace_run_modify_code()
2781 ops->old_hash.notrace_hash = NULL; in ftrace_run_modify_code()
2782 ops->flags &= ~FTRACE_OPS_FL_MODIFYING; in ftrace_run_modify_code()
2798 list_add_rcu(&ops->list, &ftrace_ops_trampoline_list); in ftrace_add_trampoline_to_kallsyms()
2804 list_del_rcu(&ops->list); in ftrace_remove_trampoline_from_kallsyms()
2818 if (ops && (ops->flags & FTRACE_OPS_FL_ALLOC_TRAMP) && in ftrace_trampoline_free()
2819 ops->trampoline) { in ftrace_trampoline_free()
2824 perf_event_text_poke((void *)ops->trampoline, in ftrace_trampoline_free()
2825 (void *)ops->trampoline, in ftrace_trampoline_free()
2826 ops->trampoline_size, NULL, 0); in ftrace_trampoline_free()
2828 ops->trampoline, ops->trampoline_size, in ftrace_trampoline_free()
2862 return -ENODEV; in ftrace_startup()
2878 ops->flags |= FTRACE_OPS_FL_ENABLED | FTRACE_OPS_FL_ADDING; in ftrace_startup()
2884 ftrace_start_up--; in ftrace_startup()
2885 ops->flags &= ~FTRACE_OPS_FL_ENABLED; in ftrace_startup()
2886 if (ops->flags & FTRACE_OPS_FL_DYNAMIC) in ftrace_startup()
2896 ops->flags &= ~FTRACE_OPS_FL_ADDING; in ftrace_startup()
2906 return -ENODEV; in ftrace_shutdown()
2912 ftrace_start_up--; in ftrace_shutdown()
2926 ops->flags &= ~FTRACE_OPS_FL_ENABLED; in ftrace_shutdown()
2940 if (ops->flags & FTRACE_OPS_FL_DYNAMIC) in ftrace_shutdown()
2950 ops->flags |= FTRACE_OPS_FL_REMOVING; in ftrace_shutdown()
2954 ops->old_hash.filter_hash = ops->func_hash->filter_hash; in ftrace_shutdown()
2955 ops->old_hash.notrace_hash = ops->func_hash->notrace_hash; in ftrace_shutdown()
2969 if (FTRACE_WARN_ON_ONCE(rec->flags & ~FTRACE_FL_DISABLED)) in ftrace_shutdown()
2971 (void *)rec->ip, rec->flags); in ftrace_shutdown()
2975 ops->old_hash.filter_hash = NULL; in ftrace_shutdown()
2976 ops->old_hash.notrace_hash = NULL; in ftrace_shutdown()
2979 ops->flags &= ~FTRACE_OPS_FL_REMOVING; in ftrace_shutdown()
2987 if (ops->flags & FTRACE_OPS_FL_DYNAMIC) { in ftrace_shutdown()
3060 return ftrace_hash_empty(ops->func_hash->filter_hash) && in ops_traces_mod()
3061 ftrace_hash_empty(ops->func_hash->notrace_hash); in ops_traces_mod()
3075 if (!(ops->flags & FTRACE_OPS_FL_ENABLED)) in ops_references_rec()
3083 if (!ftrace_hash_empty(ops->func_hash->filter_hash) && in ops_references_rec()
3084 !__ftrace_lookup_ip(ops->func_hash->filter_hash, rec->ip)) in ops_references_rec()
3088 if (ftrace_lookup_ip(ops->func_hash->notrace_hash, rec->ip)) in ops_references_rec()
3110 * read-only, the modification of enabling ftrace can fail if in ftrace_update_code()
3111 * the read-only is done while ftrace is converting the calls. in ftrace_update_code()
3114 * to read-only. in ftrace_update_code()
3119 for (pg = new_pgs; pg; pg = pg->next) { in ftrace_update_code()
3121 for (i = 0; i < pg->index; i++) { in ftrace_update_code()
3125 return -1; in ftrace_update_code()
3127 p = &pg->records[i]; in ftrace_update_code()
3128 p->flags = rec_flags; in ftrace_update_code()
3143 ftrace_update_time = stop - start; in ftrace_update_code()
3156 return -EINVAL; in ftrace_allocate_records()
3166 order--; in ftrace_allocate_records()
3169 pg->records = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, order); in ftrace_allocate_records()
3171 if (!pg->records) { in ftrace_allocate_records()
3174 return -ENOMEM; in ftrace_allocate_records()
3183 pg->size = cnt; in ftrace_allocate_records()
3216 num_to_init -= cnt; in ftrace_allocate_pages()
3220 pg->next = kzalloc(sizeof(*pg), GFP_KERNEL); in ftrace_allocate_pages()
3221 if (!pg->next) in ftrace_allocate_pages()
3224 pg = pg->next; in ftrace_allocate_pages()
3232 order = get_count_order(pg->size / ENTRIES_PER_PAGE); in ftrace_allocate_pages()
3233 free_pages((unsigned long)pg->records, order); in ftrace_allocate_pages()
3234 start_pg = pg->next; in ftrace_allocate_pages()
3237 ftrace_number_of_pages -= 1 << order; in ftrace_allocate_pages()
3238 ftrace_number_of_groups--; in ftrace_allocate_pages()
3267 struct ftrace_iterator *iter = m->private; in t_probe_next()
3268 struct trace_array *tr = iter->ops->private; in t_probe_next()
3277 iter->pos = *pos; in t_probe_next()
3282 func_probes = &tr->func_probes; in t_probe_next()
3286 if (!iter->probe) { in t_probe_next()
3287 next = func_probes->next; in t_probe_next()
3288 iter->probe = list_entry(next, struct ftrace_func_probe, list); in t_probe_next()
3291 if (iter->probe_entry) in t_probe_next()
3292 hnd = &iter->probe_entry->hlist; in t_probe_next()
3294 hash = iter->probe->ops.func_hash->filter_hash; in t_probe_next()
3303 size = 1 << hash->size_bits; in t_probe_next()
3306 if (iter->pidx >= size) { in t_probe_next()
3307 if (iter->probe->list.next == func_probes) in t_probe_next()
3309 next = iter->probe->list.next; in t_probe_next()
3310 iter->probe = list_entry(next, struct ftrace_func_probe, list); in t_probe_next()
3311 hash = iter->probe->ops.func_hash->filter_hash; in t_probe_next()
3312 size = 1 << hash->size_bits; in t_probe_next()
3313 iter->pidx = 0; in t_probe_next()
3316 hhd = &hash->buckets[iter->pidx]; in t_probe_next()
3319 iter->pidx++; in t_probe_next()
3325 hnd = hhd->first; in t_probe_next()
3327 hnd = hnd->next; in t_probe_next()
3329 iter->pidx++; in t_probe_next()
3337 iter->probe_entry = hlist_entry(hnd, struct ftrace_func_entry, hlist); in t_probe_next()
3344 struct ftrace_iterator *iter = m->private; in t_probe_start()
3348 if (!(iter->flags & FTRACE_ITER_DO_PROBES)) in t_probe_start()
3351 if (iter->mod_pos > *pos) in t_probe_start()
3354 iter->probe = NULL; in t_probe_start()
3355 iter->probe_entry = NULL; in t_probe_start()
3356 iter->pidx = 0; in t_probe_start()
3357 for (l = 0; l <= (*pos - iter->mod_pos); ) { in t_probe_start()
3366 iter->flags |= FTRACE_ITER_PROBE; in t_probe_start()
3378 probe = iter->probe; in t_probe_show()
3379 probe_entry = iter->probe_entry; in t_probe_show()
3382 return -EIO; in t_probe_show()
3384 probe_ops = probe->probe_ops; in t_probe_show()
3386 if (probe_ops->print) in t_probe_show()
3387 return probe_ops->print(m, probe_entry->ip, probe_ops, probe->data); in t_probe_show()
3389 seq_printf(m, "%ps:%ps\n", (void *)probe_entry->ip, in t_probe_show()
3390 (void *)probe_ops->func); in t_probe_show()
3398 struct ftrace_iterator *iter = m->private; in t_mod_next()
3399 struct trace_array *tr = iter->tr; in t_mod_next()
3402 iter->pos = *pos; in t_mod_next()
3404 iter->mod_list = iter->mod_list->next; in t_mod_next()
3406 if (iter->mod_list == &tr->mod_trace || in t_mod_next()
3407 iter->mod_list == &tr->mod_notrace) { in t_mod_next()
3408 iter->flags &= ~FTRACE_ITER_MOD; in t_mod_next()
3412 iter->mod_pos = *pos; in t_mod_next()
3419 struct ftrace_iterator *iter = m->private; in t_mod_start()
3423 if (iter->func_pos > *pos) in t_mod_start()
3426 iter->mod_pos = iter->func_pos; in t_mod_start()
3429 if (!iter->tr) in t_mod_start()
3432 for (l = 0; l <= (*pos - iter->func_pos); ) { in t_mod_start()
3438 iter->flags &= ~FTRACE_ITER_MOD; in t_mod_start()
3443 iter->flags |= FTRACE_ITER_MOD; in t_mod_start()
3452 struct trace_array *tr = iter->tr; in t_mod_show()
3454 if (WARN_ON_ONCE(!iter->mod_list) || in t_mod_show()
3455 iter->mod_list == &tr->mod_trace || in t_mod_show()
3456 iter->mod_list == &tr->mod_notrace) in t_mod_show()
3457 return -EIO; in t_mod_show()
3459 ftrace_mod = list_entry(iter->mod_list, struct ftrace_mod_load, list); in t_mod_show()
3461 if (ftrace_mod->func) in t_mod_show()
3462 seq_printf(m, "%s", ftrace_mod->func); in t_mod_show()
3466 seq_printf(m, ":mod:%s\n", ftrace_mod->module); in t_mod_show()
3474 struct ftrace_iterator *iter = m->private; in t_func_next()
3480 if (iter->idx >= iter->pg->index) { in t_func_next()
3481 if (iter->pg->next) { in t_func_next()
3482 iter->pg = iter->pg->next; in t_func_next()
3483 iter->idx = 0; in t_func_next()
3487 rec = &iter->pg->records[iter->idx++]; in t_func_next()
3488 if (((iter->flags & (FTRACE_ITER_FILTER | FTRACE_ITER_NOTRACE)) && in t_func_next()
3489 !ftrace_lookup_ip(iter->hash, rec->ip)) || in t_func_next()
3491 ((iter->flags & FTRACE_ITER_ENABLED) && in t_func_next()
3492 !(rec->flags & FTRACE_FL_ENABLED))) { in t_func_next()
3502 iter->pos = iter->func_pos = *pos; in t_func_next()
3503 iter->func = rec; in t_func_next()
3511 struct ftrace_iterator *iter = m->private; in t_next()
3518 if (iter->flags & FTRACE_ITER_PROBE) in t_next()
3521 if (iter->flags & FTRACE_ITER_MOD) in t_next()
3524 if (iter->flags & FTRACE_ITER_PRINTALL) { in t_next()
3540 iter->pos = 0; in reset_iter_read()
3541 iter->func_pos = 0; in reset_iter_read()
3542 iter->flags &= ~(FTRACE_ITER_PRINTALL | FTRACE_ITER_PROBE | FTRACE_ITER_MOD); in reset_iter_read()
3547 struct ftrace_iterator *iter = m->private; in t_start()
3559 if (*pos < iter->pos) in t_start()
3567 if ((iter->flags & (FTRACE_ITER_FILTER | FTRACE_ITER_NOTRACE)) && in t_start()
3568 ftrace_hash_empty(iter->hash)) { in t_start()
3569 iter->func_pos = 1; /* Account for the message */ in t_start()
3572 iter->flags |= FTRACE_ITER_PRINTALL; in t_start()
3574 iter->flags &= ~FTRACE_ITER_PROBE; in t_start()
3578 if (iter->flags & FTRACE_ITER_MOD) in t_start()
3586 iter->pg = ftrace_pages_start; in t_start()
3587 iter->idx = 0; in t_start()
3618 seq_printf(m, " ->%pS", ptr); in add_trampoline_func()
3623 struct ftrace_iterator *iter = m->private; in t_show()
3626 if (iter->flags & FTRACE_ITER_PROBE) in t_show()
3629 if (iter->flags & FTRACE_ITER_MOD) in t_show()
3632 if (iter->flags & FTRACE_ITER_PRINTALL) { in t_show()
3633 if (iter->flags & FTRACE_ITER_NOTRACE) in t_show()
3640 rec = iter->func; in t_show()
3645 seq_printf(m, "%ps", (void *)rec->ip); in t_show()
3646 if (iter->flags & FTRACE_ITER_ENABLED) { in t_show()
3651 rec->flags & FTRACE_FL_REGS ? " R" : " ", in t_show()
3652 rec->flags & FTRACE_FL_IPMODIFY ? " I" : " ", in t_show()
3653 rec->flags & FTRACE_FL_DIRECT ? " D" : " "); in t_show()
3654 if (rec->flags & FTRACE_FL_TRAMP_EN) { in t_show()
3659 (void *)ops->trampoline, in t_show()
3660 (void *)ops->func); in t_show()
3669 if (rec->flags & FTRACE_FL_DIRECT) { in t_show()
3672 direct = ftrace_find_rec_direct(rec->ip); in t_show()
3674 seq_printf(m, "\n\tdirect-->%pS", (void *)direct); in t_show()
3701 return -ENODEV; in ftrace_avail_open()
3705 return -ENOMEM; in ftrace_avail_open()
3707 iter->pg = ftrace_pages_start; in ftrace_avail_open()
3708 iter->ops = &global_ops; in ftrace_avail_open()
3729 return -ENOMEM; in ftrace_enabled_open()
3731 iter->pg = ftrace_pages_start; in ftrace_enabled_open()
3732 iter->flags = FTRACE_ITER_ENABLED; in ftrace_enabled_open()
3733 iter->ops = &global_ops; in ftrace_enabled_open()
3739 * ftrace_regex_open - initialize function tracer filter files
3761 struct trace_array *tr = ops->private; in ftrace_regex_open()
3762 int ret = -ENOMEM; in ftrace_regex_open()
3767 return -ENODEV; in ftrace_regex_open()
3770 return -ENODEV; in ftrace_regex_open()
3776 if (trace_parser_get_init(&iter->parser, FTRACE_BUFF_MAX)) in ftrace_regex_open()
3779 iter->ops = ops; in ftrace_regex_open()
3780 iter->flags = flag; in ftrace_regex_open()
3781 iter->tr = tr; in ftrace_regex_open()
3783 mutex_lock(&ops->func_hash->regex_lock); in ftrace_regex_open()
3786 hash = ops->func_hash->notrace_hash; in ftrace_regex_open()
3787 mod_head = tr ? &tr->mod_notrace : NULL; in ftrace_regex_open()
3789 hash = ops->func_hash->filter_hash; in ftrace_regex_open()
3790 mod_head = tr ? &tr->mod_trace : NULL; in ftrace_regex_open()
3793 iter->mod_list = mod_head; in ftrace_regex_open()
3795 if (file->f_mode & FMODE_WRITE) { in ftrace_regex_open()
3798 if (file->f_flags & O_TRUNC) { in ftrace_regex_open()
3799 iter->hash = alloc_ftrace_hash(size_bits); in ftrace_regex_open()
3802 iter->hash = alloc_and_copy_ftrace_hash(size_bits, hash); in ftrace_regex_open()
3805 if (!iter->hash) { in ftrace_regex_open()
3806 trace_parser_put(&iter->parser); in ftrace_regex_open()
3810 iter->hash = hash; in ftrace_regex_open()
3814 if (file->f_mode & FMODE_READ) { in ftrace_regex_open()
3815 iter->pg = ftrace_pages_start; in ftrace_regex_open()
3819 struct seq_file *m = file->private_data; in ftrace_regex_open()
3820 m->private = iter; in ftrace_regex_open()
3823 free_ftrace_hash(iter->hash); in ftrace_regex_open()
3824 trace_parser_put(&iter->parser); in ftrace_regex_open()
3827 file->private_data = iter; in ftrace_regex_open()
3830 mutex_unlock(&ops->func_hash->regex_lock); in ftrace_regex_open()
3845 struct ftrace_ops *ops = inode->i_private; in ftrace_filter_open()
3856 struct ftrace_ops *ops = inode->i_private; in ftrace_notrace_open()
3871 * If symbols in an architecture don't correspond exactly to the user-visible
3885 str = arch_ftrace_match_adjust(str, g->search); in ftrace_match()
3887 switch (g->type) { in ftrace_match()
3889 if (strcmp(str, g->search) == 0) in ftrace_match()
3893 if (strncmp(str, g->search, g->len) == 0) in ftrace_match()
3897 if (strstr(str, g->search)) in ftrace_match()
3902 if (slen >= g->len && in ftrace_match()
3903 memcmp(str + slen - g->len, g->search, g->len) == 0) in ftrace_match()
3907 if (glob_match(g->search, str)) in ftrace_match()
3921 entry = ftrace_lookup_ip(hash, rec->ip); in enter_record()
3933 ret = add_hash_entry(hash, rec->ip); in enter_record()
3942 long index = simple_strtoul(func_g->search, NULL, 0); in add_rec_by_index()
3947 if (--index < 0) in add_rec_by_index()
3951 if (pg->index <= index) { in add_rec_by_index()
3952 index -= pg->index; in add_rec_by_index()
3956 rec = &pg->records[index]; in add_rec_by_index()
3970 kallsyms_lookup(rec->ip, NULL, NULL, &modname, str); in ftrace_match_record()
3976 if (!mod_g->len) { in ftrace_match_record()
3994 if (!func_g->len) in ftrace_match_record()
4038 if (rec->flags & FTRACE_FL_DISABLED) in match_records()
4070 if (ops->flags & FTRACE_OPS_FL_ENABLED) { in ftrace_ops_update_code()
4076 * If this is the shared global_ops filter, then we need to in ftrace_ops_update_code()
4080 if (ops->func_hash != &global_ops.local_hash) in ftrace_ops_update_code()
4084 if (op->func_hash == &global_ops.local_hash && in ftrace_ops_update_code()
4085 op->flags & FTRACE_OPS_FL_ENABLED) { in ftrace_ops_update_code()
4103 old_hash_ops.filter_hash = ops->func_hash->filter_hash; in ftrace_hash_move_and_update_ops()
4104 old_hash_ops.notrace_hash = ops->func_hash->notrace_hash; in ftrace_hash_move_and_update_ops()
4123 if (n > sizeof(modname) - 1) in module_exists()
4134 struct list_head *head = enable ? &tr->mod_trace : &tr->mod_notrace; in cache_mod()
4142 ret = -EINVAL; in cache_mod()
4146 if (strcmp(ftrace_mod->module, module) != 0) in cache_mod()
4151 (ftrace_mod->func && in cache_mod()
4152 strcmp(ftrace_mod->func, func) == 0)) { in cache_mod()
4161 ret = -EINVAL; in cache_mod()
4188 mutex_lock(&ops->func_hash->regex_lock); in process_mod_list()
4191 orig_hash = &ops->func_hash->filter_hash; in process_mod_list()
4193 orig_hash = &ops->func_hash->notrace_hash; in process_mod_list()
4204 if (strcmp(ftrace_mod->module, mod) != 0) in process_mod_list()
4207 if (ftrace_mod->func) in process_mod_list()
4208 func = kstrdup(ftrace_mod->func, GFP_KERNEL); in process_mod_list()
4215 list_del(&ftrace_mod->list); in process_mod_list()
4216 list_add(&ftrace_mod->list, &process_mods); in process_mod_list()
4219 kfree(ftrace_mod->func); in process_mod_list()
4220 ftrace_mod->func = func; in process_mod_list()
4227 func = ftrace_mod->func; in process_mod_list()
4235 new_hash->flags &= ~FTRACE_HASH_FL_MOD; in process_mod_list()
4244 mutex_unlock(&ops->func_hash->regex_lock); in process_mod_list()
4260 if (!list_empty(&tr->mod_trace)) in process_cached_mods()
4261 process_mod_list(&tr->mod_trace, tr->ops, mod, true); in process_cached_mods()
4262 if (!list_empty(&tr->mod_notrace)) in process_cached_mods()
4263 process_mod_list(&tr->mod_notrace, tr->ops, mod, false); in process_cached_mods()
4286 return -ENOMEM; in ftrace_mod_callback()
4323 probe_ops = probe->probe_ops; in function_trace_probe_call()
4331 probe_ops->func(ip, parent_ip, probe->tr, probe_ops, probe->data); in function_trace_probe_call()
4345 * allocate_ftrace_func_mapper - allocate a new ftrace_func_mapper
4363 * ftrace_func_mapper_find_ip - Find some data mapped to an ip
4379 entry = ftrace_lookup_ip(&mapper->hash, ip); in ftrace_func_mapper_find_ip()
4384 return &map->data; in ftrace_func_mapper_find_ip()
4388 * ftrace_func_mapper_add_ip - Map some data to an ip
4401 entry = ftrace_lookup_ip(&mapper->hash, ip); in ftrace_func_mapper_add_ip()
4403 return -EBUSY; in ftrace_func_mapper_add_ip()
4407 return -ENOMEM; in ftrace_func_mapper_add_ip()
4409 map->entry.ip = ip; in ftrace_func_mapper_add_ip()
4410 map->data = data; in ftrace_func_mapper_add_ip()
4412 __add_hash_entry(&mapper->hash, &map->entry); in ftrace_func_mapper_add_ip()
4418 * ftrace_func_mapper_remove_ip - Remove an ip from the mapping
4434 entry = ftrace_lookup_ip(&mapper->hash, ip); in ftrace_func_mapper_remove_ip()
4439 data = map->data; in ftrace_func_mapper_remove_ip()
4441 remove_hash_entry(&mapper->hash, entry); in ftrace_func_mapper_remove_ip()
4448 * free_ftrace_func_mapper - free a mapping of ips and data
4466 if (free_func && mapper->hash.count) { in free_ftrace_func_mapper()
4467 size = 1 << mapper->hash.size_bits; in free_ftrace_func_mapper()
4469 hhd = &mapper->hash.buckets[i]; in free_ftrace_func_mapper()
4476 free_ftrace_hash(&mapper->hash); in free_ftrace_func_mapper()
4485 WARN_ON(probe->ref <= 0); in release_probe()
4488 probe->ref--; in release_probe()
4490 if (!probe->ref) { in release_probe()
4491 probe_ops = probe->probe_ops; in release_probe()
4494 * the probe->data itself in release_probe()
4496 if (probe_ops->free) in release_probe()
4497 probe_ops->free(probe_ops, probe->tr, 0, probe->data); in release_probe()
4498 list_del(&probe->list); in release_probe()
4510 probe->ref++; in acquire_probe_locked()
4529 return -EINVAL; in register_ftrace_function_probe()
4533 return -EINVAL; in register_ftrace_function_probe()
4538 list_for_each_entry(probe, &tr->func_probes, list) { in register_ftrace_function_probe()
4539 if (probe->probe_ops == probe_ops) in register_ftrace_function_probe()
4542 if (&probe->list == &tr->func_probes) { in register_ftrace_function_probe()
4546 return -ENOMEM; in register_ftrace_function_probe()
4548 probe->probe_ops = probe_ops; in register_ftrace_function_probe()
4549 probe->ops.func = function_trace_probe_call; in register_ftrace_function_probe()
4550 probe->tr = tr; in register_ftrace_function_probe()
4551 ftrace_ops_init(&probe->ops); in register_ftrace_function_probe()
4552 list_add(&probe->list, &tr->func_probes); in register_ftrace_function_probe()
4560 * Note, there's a small window here that the func_hash->filter_hash in register_ftrace_function_probe()
4563 mutex_lock(&probe->ops.func_hash->regex_lock); in register_ftrace_function_probe()
4565 orig_hash = &probe->ops.func_hash->filter_hash; in register_ftrace_function_probe()
4570 ret = -ENOMEM; in register_ftrace_function_probe()
4578 ret = -EINVAL; in register_ftrace_function_probe()
4583 size = 1 << hash->size_bits; in register_ftrace_function_probe()
4585 hlist_for_each_entry(entry, &hash->buckets[i], hlist) { in register_ftrace_function_probe()
4586 if (ftrace_lookup_ip(old_hash, entry->ip)) in register_ftrace_function_probe()
4593 if (probe_ops->init) { in register_ftrace_function_probe()
4594 ret = probe_ops->init(probe_ops, tr, in register_ftrace_function_probe()
4595 entry->ip, data, in register_ftrace_function_probe()
4596 &probe->data); in register_ftrace_function_probe()
4598 if (probe_ops->free && count) in register_ftrace_function_probe()
4599 probe_ops->free(probe_ops, tr, in register_ftrace_function_probe()
4600 0, probe->data); in register_ftrace_function_probe()
4601 probe->data = NULL; in register_ftrace_function_probe()
4613 ret = -EINVAL; in register_ftrace_function_probe()
4617 ret = ftrace_hash_move_and_update_ops(&probe->ops, orig_hash, in register_ftrace_function_probe()
4623 probe->ref += count; in register_ftrace_function_probe()
4625 if (!(probe->ops.flags & FTRACE_OPS_FL_ENABLED)) in register_ftrace_function_probe()
4626 ret = ftrace_startup(&probe->ops, 0); in register_ftrace_function_probe()
4634 mutex_unlock(&probe->ops.func_hash->regex_lock); in register_ftrace_function_probe()
4642 if (!probe_ops->free || !count) in register_ftrace_function_probe()
4647 hlist_for_each_entry(entry, &hash->buckets[i], hlist) { in register_ftrace_function_probe()
4648 if (ftrace_lookup_ip(old_hash, entry->ip)) in register_ftrace_function_probe()
4650 probe_ops->free(probe_ops, tr, entry->ip, probe->data); in register_ftrace_function_probe()
4671 int i, ret = -ENODEV; in unregister_ftrace_function_probe_func()
4685 return -EINVAL; in unregister_ftrace_function_probe_func()
4690 list_for_each_entry(probe, &tr->func_probes, list) { in unregister_ftrace_function_probe_func()
4691 if (probe->probe_ops == probe_ops) in unregister_ftrace_function_probe_func()
4694 if (&probe->list == &tr->func_probes) in unregister_ftrace_function_probe_func()
4697 ret = -EINVAL; in unregister_ftrace_function_probe_func()
4698 if (!(probe->ops.flags & FTRACE_OPS_FL_INITIALIZED)) in unregister_ftrace_function_probe_func()
4705 mutex_lock(&probe->ops.func_hash->regex_lock); in unregister_ftrace_function_probe_func()
4707 orig_hash = &probe->ops.func_hash->filter_hash; in unregister_ftrace_function_probe_func()
4717 ret = -ENOMEM; in unregister_ftrace_function_probe_func()
4724 size = 1 << hash->size_bits; in unregister_ftrace_function_probe_func()
4726 hlist_for_each_entry_safe(entry, tmp, &hash->buckets[i], hlist) { in unregister_ftrace_function_probe_func()
4729 kallsyms_lookup(entry->ip, NULL, NULL, in unregister_ftrace_function_probe_func()
4736 hlist_add_head(&entry->hlist, &hhd); in unregister_ftrace_function_probe_func()
4742 ret = -EINVAL; in unregister_ftrace_function_probe_func()
4748 WARN_ON(probe->ref < count); in unregister_ftrace_function_probe_func()
4750 probe->ref -= count; in unregister_ftrace_function_probe_func()
4753 ftrace_shutdown(&probe->ops, 0); in unregister_ftrace_function_probe_func()
4755 ret = ftrace_hash_move_and_update_ops(&probe->ops, orig_hash, in unregister_ftrace_function_probe_func()
4760 ftrace_run_modify_code(&probe->ops, FTRACE_UPDATE_CALLS, in unregister_ftrace_function_probe_func()
4765 hlist_del(&entry->hlist); in unregister_ftrace_function_probe_func()
4766 if (probe_ops->free) in unregister_ftrace_function_probe_func()
4767 probe_ops->free(probe_ops, tr, entry->ip, probe->data); in unregister_ftrace_function_probe_func()
4773 mutex_unlock(&probe->ops.func_hash->regex_lock); in unregister_ftrace_function_probe_func()
4789 list_for_each_entry_safe(probe, n, &tr->func_probes, list) in clear_ftrace_function_probes()
4790 unregister_ftrace_function_probe_func(NULL, tr, probe->probe_ops); in clear_ftrace_function_probes()
4807 if (strcmp(cmd->name, p->name) == 0) { in register_ftrace_command()
4808 ret = -EBUSY; in register_ftrace_command()
4812 list_add(&cmd->list, &ftrace_commands); in register_ftrace_command()
4826 int ret = -ENODEV; in unregister_ftrace_command()
4830 if (strcmp(cmd->name, p->name) == 0) { in unregister_ftrace_command()
4832 list_del_init(&p->list); in unregister_ftrace_command()
4845 struct ftrace_hash *hash = iter->hash; in ftrace_process_regex()
4846 struct trace_array *tr = iter->ops->private; in ftrace_process_regex()
4849 int ret = -EINVAL; in ftrace_process_regex()
4856 ret = -EINVAL; in ftrace_process_regex()
4868 if (strcmp(p->name, command) == 0) { in ftrace_process_regex()
4869 ret = p->func(tr, hash, func, command, next, enable); in ftrace_process_regex()
4890 if (file->f_mode & FMODE_READ) { in ftrace_regex_write()
4891 struct seq_file *m = file->private_data; in ftrace_regex_write()
4892 iter = m->private; in ftrace_regex_write()
4894 iter = file->private_data; in ftrace_regex_write()
4897 return -ENODEV; in ftrace_regex_write()
4899 /* iter->hash is a local copy, so we don't need regex_lock */ in ftrace_regex_write()
4901 parser = &iter->parser; in ftrace_regex_write()
4906 ret = ftrace_process_regex(iter, parser->buffer, in ftrace_regex_write()
4907 parser->idx, enable); in ftrace_regex_write()
4938 return -EINVAL; in ftrace_match_addr()
4943 return -ENOENT; in ftrace_match_addr()
4960 return -ENODEV; in ftrace_set_hash()
4962 mutex_lock(&ops->func_hash->regex_lock); in ftrace_set_hash()
4965 orig_hash = &ops->func_hash->filter_hash; in ftrace_set_hash()
4967 orig_hash = &ops->func_hash->notrace_hash; in ftrace_set_hash()
4975 ret = -ENOMEM; in ftrace_set_hash()
4980 ret = -EINVAL; in ftrace_set_hash()
4994 mutex_unlock(&ops->func_hash->regex_lock); in ftrace_set_hash()
5018 * ftrace_find_direct_func - test an address if it is a registered direct caller
5037 if (entry->addr == addr) { in ftrace_find_direct_func()
5049 * register_ftrace_direct - Call a custom trampoline directly
5061 * -EBUSY - Another direct function is already attached (there can be only one)
5062 * -ENODEV - @ip does not point to a ftrace nop location (or not supported)
5063 * -ENOMEM - There was an allocation failure.
5071 int ret = -EBUSY; in register_ftrace_direct()
5079 ret = -ENODEV; in register_ftrace_direct()
5088 if (WARN_ON(rec->flags & FTRACE_FL_DIRECT)) in register_ftrace_direct()
5092 if (ip != rec->ip) { in register_ftrace_direct()
5093 ip = rec->ip; in register_ftrace_direct()
5099 ret = -ENOMEM; in register_ftrace_direct()
5101 direct_functions->count > 2 * (1 << direct_functions->size_bits)) { in register_ftrace_direct()
5104 direct_functions->count + 1; in register_ftrace_direct()
5128 direct->addr = addr; in register_ftrace_direct()
5129 direct->count = 0; in register_ftrace_direct()
5130 list_add_rcu(&direct->next, &ftrace_direct_funcs); in register_ftrace_direct()
5134 entry->ip = ip; in register_ftrace_direct()
5135 entry->direct = addr; in register_ftrace_direct()
5150 if (!direct->count) { in register_ftrace_direct()
5151 list_del_rcu(&direct->next); in register_ftrace_direct()
5157 ftrace_direct_func_count--; in register_ftrace_direct()
5160 direct->count++; in register_ftrace_direct()
5184 entry = __ftrace_lookup_ip(direct_functions, rec->ip); in find_direct_entry()
5186 WARN_ON(rec->flags & FTRACE_FL_DIRECT); in find_direct_entry()
5190 WARN_ON(!(rec->flags & FTRACE_FL_DIRECT)); in find_direct_entry()
5193 *ip = rec->ip; in find_direct_entry()
5205 int ret = -ENODEV; in unregister_ftrace_direct()
5213 if (direct_functions->count == 1) in unregister_ftrace_direct()
5225 direct->count--; in unregister_ftrace_direct()
5226 WARN_ON(direct->count < 0); in unregister_ftrace_direct()
5227 if (!direct->count) { in unregister_ftrace_direct()
5228 list_del_rcu(&direct->next); in unregister_ftrace_direct()
5232 ftrace_direct_func_count--; in unregister_ftrace_direct()
5247 * ftrace_modify_direct_caller - modify ftrace nop directly
5250 * @old_addr: The location that the site at @rec->ip currently calls
5251 * @new_addr: The location that the site at @rec->ip should call
5261 * @rec->ip is currently calling @old_addr. And this must
5262 * also update entry->direct to @new_addr.
5269 unsigned long ip = rec->ip; in ftrace_modify_direct_caller()
5300 entry->direct = new_addr; in ftrace_modify_direct_caller()
5316 * modify_ftrace_direct - Modify an existing direct call to call something else
5326 * -ENODEV : the @ip given has no direct caller attached
5327 * -EINVAL : the @old_addr does not match the current direct caller
5334 int ret = -ENODEV; in modify_ftrace_direct()
5343 ret = -EINVAL; in modify_ftrace_direct()
5344 if (entry->direct != old_addr) in modify_ftrace_direct()
5348 * If there's no other ftrace callback on the rec->ip location, in modify_ftrace_direct()
5356 entry->direct = new_addr; in modify_ftrace_direct()
5369 * ftrace_set_filter_ip - set a function to filter on in ftrace by address
5370 * @ops - the ops to set the filter with
5371 * @ip - the address to add to or remove from the filter.
5372 * @remove - non zero to remove the ip from the filter
5373 * @reset - non zero to reset all filters before applying this filter.
5387 * ftrace_ops_set_global_filter - setup ops to use global filters
5388 * @ops - the ops which will use the global filters
5395 if (ops->flags & FTRACE_OPS_FL_INITIALIZED) in ftrace_ops_set_global_filter()
5399 ops->func_hash = &global_ops.local_hash; in ftrace_ops_set_global_filter()
5411 * ftrace_set_filter - set a function to filter on in ftrace
5412 * @ops - the ops to set the filter with
5413 * @buf - the string that holds the function filter text.
5414 * @len - the length of the string.
5415 * @reset - non zero to reset all filters before applying this filter.
5429 * ftrace_set_notrace - set a function to not trace in ftrace
5430 * @ops - the ops to set the notrace filter with
5431 * @buf - the string that holds the function notrace text.
5432 * @len - the length of the string.
5433 * @reset - non zero to reset all filters before applying this filter.
5447 * ftrace_set_global_filter - set a function to filter on with global tracers
5448 * @buf - the string that holds the function filter text.
5449 * @len - the length of the string.
5450 * @reset - non zero to reset all filters before applying this filter.
5462 * ftrace_set_global_notrace - set a function to not trace with global tracers
5463 * @buf - the string that holds the function notrace text.
5464 * @len - the length of the string.
5465 * @reset - non zero to reset all filters before applying this filter.
5586 struct seq_file *m = (struct seq_file *)file->private_data; in ftrace_regex_release()
5593 if (file->f_mode & FMODE_READ) { in ftrace_regex_release()
5594 iter = m->private; in ftrace_regex_release()
5597 iter = file->private_data; in ftrace_regex_release()
5599 parser = &iter->parser; in ftrace_regex_release()
5601 ftrace_match_records(iter->hash, parser->buffer, parser->idx); in ftrace_regex_release()
5606 mutex_lock(&iter->ops->func_hash->regex_lock); in ftrace_regex_release()
5608 if (file->f_mode & FMODE_WRITE) { in ftrace_regex_release()
5609 filter_hash = !!(iter->flags & FTRACE_ITER_FILTER); in ftrace_regex_release()
5612 orig_hash = &iter->ops->func_hash->filter_hash; in ftrace_regex_release()
5613 if (iter->tr && !list_empty(&iter->tr->mod_trace)) in ftrace_regex_release()
5614 iter->hash->flags |= FTRACE_HASH_FL_MOD; in ftrace_regex_release()
5616 orig_hash = &iter->ops->func_hash->notrace_hash; in ftrace_regex_release()
5619 ret = ftrace_hash_move_and_update_ops(iter->ops, orig_hash, in ftrace_regex_release()
5620 iter->hash, filter_hash); in ftrace_regex_release()
5624 iter->hash = NULL; in ftrace_regex_release()
5627 mutex_unlock(&iter->ops->func_hash->regex_lock); in ftrace_regex_release()
5628 free_ftrace_hash(iter->hash); in ftrace_regex_release()
5629 if (iter->tr) in ftrace_regex_release()
5630 trace_array_put(iter->tr); in ftrace_regex_release()
5693 struct ftrace_graph_data *fgd = m->private; in __g_next()
5694 struct ftrace_func_entry *entry = fgd->entry; in __g_next()
5696 int i, idx = fgd->idx; in __g_next()
5698 if (*pos >= fgd->hash->count) in __g_next()
5703 fgd->entry = entry; in __g_next()
5710 for (i = idx; i < 1 << fgd->hash->size_bits; i++) { in __g_next()
5711 head = &fgd->hash->buckets[i]; in __g_next()
5713 fgd->entry = entry; in __g_next()
5714 fgd->idx = i; in __g_next()
5730 struct ftrace_graph_data *fgd = m->private; in g_start()
5734 if (fgd->type == GRAPH_FILTER_FUNCTION) in g_start()
5735 fgd->hash = rcu_dereference_protected(ftrace_graph_hash, in g_start()
5738 fgd->hash = rcu_dereference_protected(ftrace_graph_notrace_hash, in g_start()
5742 if (ftrace_hash_empty(fgd->hash) && !*pos) in g_start()
5745 fgd->idx = 0; in g_start()
5746 fgd->entry = NULL; in g_start()
5763 struct ftrace_graph_data *fgd = m->private; in g_show()
5765 if (fgd->type == GRAPH_FILTER_FUNCTION) in g_show()
5772 seq_printf(m, "%ps\n", (void *)entry->ip); in g_show()
5795 if (file->f_mode & FMODE_WRITE) { in __ftrace_graph_open()
5798 if (trace_parser_get_init(&fgd->parser, FTRACE_BUFF_MAX)) in __ftrace_graph_open()
5799 return -ENOMEM; in __ftrace_graph_open()
5801 if (file->f_flags & O_TRUNC) in __ftrace_graph_open()
5805 fgd->hash); in __ftrace_graph_open()
5807 ret = -ENOMEM; in __ftrace_graph_open()
5812 if (file->f_mode & FMODE_READ) { in __ftrace_graph_open()
5815 struct seq_file *m = file->private_data; in __ftrace_graph_open()
5816 m->private = fgd; in __ftrace_graph_open()
5823 file->private_data = fgd; in __ftrace_graph_open()
5826 if (ret < 0 && file->f_mode & FMODE_WRITE) in __ftrace_graph_open()
5827 trace_parser_put(&fgd->parser); in __ftrace_graph_open()
5829 fgd->new_hash = new_hash; in __ftrace_graph_open()
5832 * All uses of fgd->hash must be taken with the graph_lock in __ftrace_graph_open()
5834 * fgd->hash to be reinitialized when it is taken again. in __ftrace_graph_open()
5836 fgd->hash = NULL; in __ftrace_graph_open()
5848 return -ENODEV; in ftrace_graph_open()
5852 return -ENOMEM; in ftrace_graph_open()
5856 fgd->hash = rcu_dereference_protected(ftrace_graph_hash, in ftrace_graph_open()
5858 fgd->type = GRAPH_FILTER_FUNCTION; in ftrace_graph_open()
5859 fgd->seq_ops = &ftrace_graph_seq_ops; in ftrace_graph_open()
5876 return -ENODEV; in ftrace_graph_notrace_open()
5880 return -ENOMEM; in ftrace_graph_notrace_open()
5884 fgd->hash = rcu_dereference_protected(ftrace_graph_notrace_hash, in ftrace_graph_notrace_open()
5886 fgd->type = GRAPH_FILTER_NOTRACE; in ftrace_graph_notrace_open()
5887 fgd->seq_ops = &ftrace_graph_seq_ops; in ftrace_graph_notrace_open()
5905 if (file->f_mode & FMODE_READ) { in ftrace_graph_release()
5906 struct seq_file *m = file->private_data; in ftrace_graph_release()
5908 fgd = m->private; in ftrace_graph_release()
5911 fgd = file->private_data; in ftrace_graph_release()
5915 if (file->f_mode & FMODE_WRITE) { in ftrace_graph_release()
5917 parser = &fgd->parser; in ftrace_graph_release()
5920 ret = ftrace_graph_set_hash(fgd->new_hash, in ftrace_graph_release()
5921 parser->buffer); in ftrace_graph_release()
5926 new_hash = __ftrace_hash_move(fgd->new_hash); in ftrace_graph_release()
5928 ret = -ENOMEM; in ftrace_graph_release()
5934 if (fgd->type == GRAPH_FILTER_FUNCTION) { in ftrace_graph_release()
5960 free_ftrace_hash(fgd->new_hash); in ftrace_graph_release()
5986 return -ENODEV; in ftrace_graph_set_hash()
5991 if (rec->flags & FTRACE_FL_DISABLED) in ftrace_graph_set_hash()
5995 entry = ftrace_lookup_ip(hash, rec->ip); in ftrace_graph_set_hash()
6002 if (add_hash_entry(hash, rec->ip) < 0) in ftrace_graph_set_hash()
6016 return -EINVAL; in ftrace_graph_set_hash()
6026 struct ftrace_graph_data *fgd = file->private_data; in ftrace_graph_write()
6033 if (file->f_mode & FMODE_READ) { in ftrace_graph_write()
6034 struct seq_file *m = file->private_data; in ftrace_graph_write()
6035 fgd = m->private; in ftrace_graph_write()
6038 parser = &fgd->parser; in ftrace_graph_write()
6045 ret = ftrace_graph_set_hash(fgd->new_hash, in ftrace_graph_write()
6046 parser->buffer); in ftrace_graph_write()
6097 if (ops->flags & FTRACE_OPS_FL_ENABLED) in ftrace_destroy_filter_files()
6099 ops->flags |= FTRACE_OPS_FL_DELETED; in ftrace_destroy_filter_files()
6129 const unsigned long *ipa = a; in ftrace_cmp_ips() local
6132 if (*ipa > *ipb) in ftrace_cmp_ips()
6134 if (*ipa < *ipb) in ftrace_cmp_ips()
6135 return -1; in ftrace_cmp_ips()
6150 int ret = -ENOMEM; in ftrace_process_locs()
6152 count = end - start; in ftrace_process_locs()
6162 return -ENOMEM; in ftrace_process_locs()
6179 if (WARN_ON(ftrace_pages->next)) { in ftrace_process_locs()
6181 while (ftrace_pages->next) in ftrace_process_locs()
6182 ftrace_pages = ftrace_pages->next; in ftrace_process_locs()
6185 ftrace_pages->next = start_pg; in ftrace_process_locs()
6201 if (pg->index == pg->size) { in ftrace_process_locs()
6203 if (WARN_ON(!pg->next)) in ftrace_process_locs()
6205 pg = pg->next; in ftrace_process_locs()
6208 rec = &pg->records[pg->index++]; in ftrace_process_locs()
6209 rec->ip = addr; in ftrace_process_locs()
6213 WARN_ON(pg->next); in ftrace_process_locs()
6263 if (!op->trampoline || symnum--) in ftrace_get_trampoline_kallsym()
6265 *value = op->trampoline; in ftrace_get_trampoline_kallsym()
6273 return -ERANGE; in ftrace_get_trampoline_kallsym()
6287 for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) { in referenced_filters()
6289 if (WARN_ON_ONCE(ops->flags & FTRACE_OPS_FL_DIRECT)) in referenced_filters()
6291 if (WARN_ON_ONCE(ops->flags & FTRACE_OPS_FL_IPMODIFY)) in referenced_filters()
6294 if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) in referenced_filters()
6295 rec->flags |= FTRACE_FL_REGS; in referenced_filters()
6296 if (cnt == 1 && ops->trampoline) in referenced_filters()
6297 rec->flags |= FTRACE_FL_TRAMP; in referenced_filters()
6299 rec->flags &= ~FTRACE_FL_TRAMP; in referenced_filters()
6316 for (i = 0; i < pg->index; i++) { in clear_mod_from_hash()
6317 rec = &pg->records[i]; in clear_mod_from_hash()
6318 entry = __ftrace_lookup_ip(hash, rec->ip); in clear_mod_from_hash()
6325 entry->ip = 0; in clear_mod_from_hash()
6336 if (!tr->ops || !tr->ops->func_hash) in clear_mod_from_hashes()
6338 mutex_lock(&tr->ops->func_hash->regex_lock); in clear_mod_from_hashes()
6339 clear_mod_from_hash(pg, tr->ops->func_hash->filter_hash); in clear_mod_from_hashes()
6340 clear_mod_from_hash(pg, tr->ops->func_hash->notrace_hash); in clear_mod_from_hashes()
6341 mutex_unlock(&tr->ops->func_hash->regex_lock); in clear_mod_from_hashes()
6353 list_for_each_entry_safe(mod_func, n, &mod_map->funcs, list) { in ftrace_free_mod_map()
6354 kfree(mod_func->name); in ftrace_free_mod_map()
6355 list_del(&mod_func->list); in ftrace_free_mod_map()
6378 if (mod_map->mod == mod) { in ftrace_release_mod()
6379 list_del_rcu(&mod_map->list); in ftrace_release_mod()
6380 call_rcu(&mod_map->rcu, ftrace_free_mod_map); in ftrace_release_mod()
6391 rec = &pg->records[0]; in ftrace_release_mod()
6392 if (within_module_core(rec->ip, mod) || in ftrace_release_mod()
6393 within_module_init(rec->ip, mod)) { in ftrace_release_mod()
6405 ftrace_update_tot_cnt -= pg->index; in ftrace_release_mod()
6406 *last_pg = pg->next; in ftrace_release_mod()
6408 pg->next = tmp_page; in ftrace_release_mod()
6411 last_pg = &pg->next; in ftrace_release_mod()
6421 order = get_count_order(pg->size / ENTRIES_PER_PAGE); in ftrace_release_mod()
6422 free_pages((unsigned long)pg->records, order); in ftrace_release_mod()
6423 tmp_page = pg->next; in ftrace_release_mod()
6425 ftrace_number_of_pages -= 1 << order; in ftrace_release_mod()
6426 ftrace_number_of_groups--; in ftrace_release_mod()
6450 * text to read-only, as we now need to set it back to read-write in ftrace_module_enable()
6464 if (!within_module_core(rec->ip, mod) && in ftrace_module_enable()
6465 !within_module_init(rec->ip, mod)) in ftrace_module_enable()
6479 rec->flags &= ~FTRACE_FL_DISABLED; in ftrace_module_enable()
6480 rec->flags += cnt; in ftrace_module_enable()
6499 process_cached_mods(mod->name); in ftrace_module_enable()
6504 if (ftrace_disabled || !mod->num_ftrace_callsites) in ftrace_module_init()
6507 ftrace_process_locs(mod, mod->ftrace_callsites, in ftrace_module_init()
6508 mod->ftrace_callsites + mod->num_ftrace_callsites); in ftrace_module_init()
6521 ret = kallsyms_lookup(rec->ip, &symsize, &offset, &modname, str); in save_ftrace_mod_rec()
6529 mod_func->name = kstrdup(str, GFP_KERNEL); in save_ftrace_mod_rec()
6530 if (!mod_func->name) { in save_ftrace_mod_rec()
6535 mod_func->ip = rec->ip - offset; in save_ftrace_mod_rec()
6536 mod_func->size = symsize; in save_ftrace_mod_rec()
6538 mod_map->num_funcs++; in save_ftrace_mod_rec()
6540 list_add_rcu(&mod_func->list, &mod_map->funcs); in save_ftrace_mod_rec()
6553 mod_map->mod = mod; in allocate_ftrace_mod_map()
6554 mod_map->start_addr = start; in allocate_ftrace_mod_map()
6555 mod_map->end_addr = end; in allocate_ftrace_mod_map()
6556 mod_map->num_funcs = 0; in allocate_ftrace_mod_map()
6558 INIT_LIST_HEAD_RCU(&mod_map->funcs); in allocate_ftrace_mod_map()
6560 list_add_rcu(&mod_map->list, &ftrace_mod_maps); in allocate_ftrace_mod_map()
6573 list_for_each_entry_rcu(mod_func, &mod_map->funcs, list) { in ftrace_func_address_lookup()
6574 if (addr >= mod_func->ip && in ftrace_func_address_lookup()
6575 addr < mod_func->ip + mod_func->size) { in ftrace_func_address_lookup()
6583 *size = found_func->size; in ftrace_func_address_lookup()
6585 *off = addr - found_func->ip; in ftrace_func_address_lookup()
6587 strlcpy(sym, found_func->name, KSYM_NAME_LEN); in ftrace_func_address_lookup()
6589 return found_func->name; in ftrace_func_address_lookup()
6608 *modname = mod_map->mod->name; in ftrace_mod_address_lookup()
6628 if (symnum >= mod_map->num_funcs) { in ftrace_mod_get_kallsym()
6629 symnum -= mod_map->num_funcs; in ftrace_mod_get_kallsym()
6633 list_for_each_entry_rcu(mod_func, &mod_map->funcs, list) { in ftrace_mod_get_kallsym()
6635 symnum--; in ftrace_mod_get_kallsym()
6639 *value = mod_func->ip; in ftrace_mod_get_kallsym()
6641 strlcpy(name, mod_func->name, KSYM_NAME_LEN); in ftrace_mod_get_kallsym()
6642 strlcpy(module_name, mod_map->mod->name, MODULE_NAME_LEN); in ftrace_mod_get_kallsym()
6690 entry = ftrace_lookup_ip(hash, func->ip); in clear_func_from_hash()
6697 entry->ip = 0; in clear_func_from_hash()
6707 if (!tr->ops || !tr->ops->func_hash) in clear_func_from_hashes()
6709 mutex_lock(&tr->ops->func_hash->regex_lock); in clear_func_from_hashes()
6710 clear_func_from_hash(func, tr->ops->func_hash->filter_hash); in clear_func_from_hashes()
6711 clear_func_from_hash(func, tr->ops->func_hash->notrace_hash); in clear_func_from_hashes()
6712 mutex_unlock(&tr->ops->func_hash->regex_lock); in clear_func_from_hashes()
6728 func->ip = rec->ip; in add_to_clear_hash_list()
6729 list_add(&func->list, clear_list); in add_to_clear_hash_list()
6760 for (pg = ftrace_pages_start; pg; last_pg = &pg->next, pg = *last_pg) { in ftrace_free_mem()
6761 if (end < pg->records[0].ip || in ftrace_free_mem()
6762 start >= (pg->records[pg->index - 1].ip + MCOUNT_INSN_SIZE)) in ftrace_free_mem()
6765 rec = bsearch(&key, pg->records, pg->index, in ftrace_free_mem()
6777 pg->index--; in ftrace_free_mem()
6778 ftrace_update_tot_cnt--; in ftrace_free_mem()
6779 if (!pg->index) { in ftrace_free_mem()
6780 *last_pg = pg->next; in ftrace_free_mem()
6781 order = get_count_order(pg->size / ENTRIES_PER_PAGE); in ftrace_free_mem()
6782 free_pages((unsigned long)pg->records, order); in ftrace_free_mem()
6783 ftrace_number_of_pages -= 1 << order; in ftrace_free_mem()
6784 ftrace_number_of_groups--; in ftrace_free_mem()
6792 (pg->index - (rec - pg->records)) * sizeof(*rec)); in ftrace_free_mem()
6825 count = __stop_mcount_loc - __start_mcount_loc; in ftrace_init()
6857 unsigned long trampoline = ops->trampoline; in ftrace_update_trampoline()
6860 if (ops->trampoline && ops->trampoline != trampoline && in ftrace_update_trampoline()
6861 (ops->flags & FTRACE_OPS_FL_ALLOC_TRAMP)) { in ftrace_update_trampoline()
6865 ops->trampoline, ops->trampoline_size, false, in ftrace_update_trampoline()
6871 perf_event_text_poke((void *)ops->trampoline, NULL, 0, in ftrace_update_trampoline()
6872 (void *)ops->trampoline, in ftrace_update_trampoline()
6873 ops->trampoline_size); in ftrace_update_trampoline()
6879 INIT_LIST_HEAD(&tr->func_probes); in ftrace_init_trace_array()
6880 INIT_LIST_HEAD(&tr->mod_trace); in ftrace_init_trace_array()
6881 INIT_LIST_HEAD(&tr->mod_notrace); in ftrace_init_trace_array()
6914 tr->ops = &global_ops; in ftrace_init_global_array_ops()
6915 tr->ops->private = tr; in ftrace_init_global_array_ops()
6922 if (tr->flags & TRACE_ARRAY_FL_GLOBAL) { in ftrace_init_array_ops()
6923 if (WARN_ON(tr->ops->func != ftrace_stub)) in ftrace_init_array_ops()
6925 tr->ops->func); in ftrace_init_array_ops()
6927 tr->ops->func = func; in ftrace_init_array_ops()
6928 tr->ops->private = tr; in ftrace_init_array_ops()
6933 tr->ops->func = ftrace_stub; in ftrace_reset_array_ops()
6955 if (op->flags & FTRACE_OPS_FL_STUB) in __ftrace_ops_list_func()
6964 * If any of the above fails then the op->func() is not executed. in __ftrace_ops_list_func()
6966 if ((!(op->flags & FTRACE_OPS_FL_RCU) || rcu_is_watching()) && in __ftrace_ops_list_func()
6968 if (FTRACE_WARN_ON(!op->func)) { in __ftrace_ops_list_func()
6972 op->func(ip, parent_ip, op, regs); in __ftrace_ops_list_func()
7024 if (!(op->flags & FTRACE_OPS_FL_RCU) || rcu_is_watching()) in ftrace_ops_assist_func()
7025 op->func(ip, parent_ip, op, regs); in ftrace_ops_assist_func()
7033 * ftrace_ops_get_func - get the function a trampoline should call
7036 * Normally the mcount trampoline will call the ops->func, but there
7049 if (!(ops->flags & FTRACE_OPS_FL_RECURSION_SAFE) || in ftrace_ops_get_func()
7050 ops->flags & FTRACE_OPS_FL_RCU) in ftrace_ops_get_func()
7053 return ops->func; in ftrace_ops_get_func()
7064 pid_list = rcu_dereference_sched(tr->function_pids); in ftrace_filter_pid_sched_switch_probe()
7065 no_pid_list = rcu_dereference_sched(tr->function_no_pids); in ftrace_filter_pid_sched_switch_probe()
7068 this_cpu_write(tr->array_buffer.data->ftrace_ignore_pid, in ftrace_filter_pid_sched_switch_probe()
7071 this_cpu_write(tr->array_buffer.data->ftrace_ignore_pid, in ftrace_filter_pid_sched_switch_probe()
7072 next->pid); in ftrace_filter_pid_sched_switch_probe()
7083 pid_list = rcu_dereference_sched(tr->function_pids); in ftrace_pid_follow_sched_process_fork()
7086 pid_list = rcu_dereference_sched(tr->function_no_pids); in ftrace_pid_follow_sched_process_fork()
7096 pid_list = rcu_dereference_sched(tr->function_pids); in ftrace_pid_follow_sched_process_exit()
7099 pid_list = rcu_dereference_sched(tr->function_no_pids); in ftrace_pid_follow_sched_process_exit()
7124 pid_list = rcu_dereference_protected(tr->function_pids, in clear_ftrace_pids()
7126 no_pid_list = rcu_dereference_protected(tr->function_no_pids, in clear_ftrace_pids()
7137 per_cpu_ptr(tr->array_buffer.data, cpu)->ftrace_ignore_pid = FTRACE_PID_TRACE; in clear_ftrace_pids()
7141 rcu_assign_pointer(tr->function_pids, NULL); in clear_ftrace_pids()
7144 rcu_assign_pointer(tr->function_no_pids, NULL); in clear_ftrace_pids()
7183 struct trace_array *tr = m->private; in fpid_start()
7188 pid_list = rcu_dereference_sched(tr->function_pids); in fpid_start()
7198 struct trace_array *tr = m->private; in fpid_next()
7199 struct trace_pid_list *pid_list = rcu_dereference_sched(tr->function_pids); in fpid_next()
7236 struct trace_array *tr = m->private; in fnpid_start()
7241 pid_list = rcu_dereference_sched(tr->function_no_pids); in fnpid_start()
7251 struct trace_array *tr = m->private; in fnpid_next()
7252 struct trace_pid_list *pid_list = rcu_dereference_sched(tr->function_no_pids); in fnpid_next()
7271 struct trace_array *tr = inode->i_private; in pid_open()
7279 if ((file->f_mode & FMODE_WRITE) && in pid_open()
7280 (file->f_flags & O_TRUNC)) in pid_open()
7293 return -EINVAL; in pid_open()
7300 m = file->private_data; in pid_open()
7302 m->private = tr; in pid_open()
7330 pid_list = rcu_dereference_protected(tr->function_pids, in ignore_task_cpu()
7332 no_pid_list = rcu_dereference_protected(tr->function_no_pids, in ignore_task_cpu()
7336 this_cpu_write(tr->array_buffer.data->ftrace_ignore_pid, in ignore_task_cpu()
7339 this_cpu_write(tr->array_buffer.data->ftrace_ignore_pid, in ignore_task_cpu()
7340 current->pid); in ignore_task_cpu()
7347 struct seq_file *m = filp->private_data; in pid_write()
7348 struct trace_array *tr = m->private; in pid_write()
7361 filtered_pids = rcu_dereference_protected(tr->function_pids, in pid_write()
7363 other_pids = rcu_dereference_protected(tr->function_no_pids, in pid_write()
7367 filtered_pids = rcu_dereference_protected(tr->function_no_pids, in pid_write()
7369 other_pids = rcu_dereference_protected(tr->function_pids, in pid_write()
7373 ret = -EINVAL; in pid_write()
7384 rcu_assign_pointer(tr->function_pids, pid_list); in pid_write()
7387 rcu_assign_pointer(tr->function_no_pids, pid_list); in pid_write()
7435 struct trace_array *tr = inode->i_private; in ftrace_pid_release()
7470 WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL)); in ftrace_init_tracefs_toplevel()
7477 * ftrace_kill - kill ftrace
7481 * from a non-atomic section, use ftrace_kill.
7499 * register_ftrace_function - register a function for profiling
7500 * @ops - ops structure that holds the function for profiling.
7505 * Note: @ops->func and all the functions it calls must be labeled
7511 int ret = -1; in register_ftrace_function()
7526 * unregister_ftrace_function - unregister a function for profiling.
7527 * @ops - ops structure that holds the function to unregister
7548 if (op->flags & FTRACE_OPS_FL_PERMANENT) in is_permanent_ops_registered()
7559 int ret = -ENODEV; in ftrace_enable_sysctl()
7583 ret = -EBUSY; in ftrace_enable_sysctl()