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, fregs); 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()
1066 if (op->trampoline && op->trampoline_size) in ftrace_ops_trampoline()
1067 if (addr >= op->trampoline && in ftrace_ops_trampoline()
1068 addr < op->trampoline + op->trampoline_size) { in ftrace_ops_trampoline()
1105 if (hash->size_bits > 0) in ftrace_hash_key()
1106 return hash_long(ip, hash->size_bits); in ftrace_hash_key()
1120 hhd = &hash->buckets[key]; in __ftrace_lookup_ip()
1123 if (entry->ip == ip) in __ftrace_lookup_ip()
1130 * ftrace_lookup_ip - Test to see if an ip exists in an ftrace_hash
1154 key = ftrace_hash_key(hash, entry->ip); in __add_hash_entry()
1155 hhd = &hash->buckets[key]; in __add_hash_entry()
1156 hlist_add_head(&entry->hlist, hhd); in __add_hash_entry()
1157 hash->count++; in __add_hash_entry()
1166 return -ENOMEM; in add_hash_entry()
1168 entry->ip = ip; in add_hash_entry()
1178 hlist_del(&entry->hlist); in free_hash_entry()
1180 hash->count--; in free_hash_entry()
1187 hlist_del_rcu(&entry->hlist); in remove_hash_entry()
1188 hash->count--; in remove_hash_entry()
1196 int size = 1 << hash->size_bits; in ftrace_hash_clear()
1199 if (!hash->count) in ftrace_hash_clear()
1203 hhd = &hash->buckets[i]; in ftrace_hash_clear()
1207 FTRACE_WARN_ON(hash->count); in ftrace_hash_clear()
1212 list_del(&ftrace_mod->list); in free_ftrace_mod()
1213 kfree(ftrace_mod->module); in free_ftrace_mod()
1214 kfree(ftrace_mod->func); in free_ftrace_mod()
1237 kfree(hash->buckets); in free_ftrace_hash()
1253 call_rcu(&hash->rcu, __free_ftrace_hash_rcu); in free_ftrace_hash_rcu()
1259 free_ftrace_hash(ops->func_hash->filter_hash); in ftrace_free_filter()
1260 free_ftrace_hash(ops->func_hash->notrace_hash); in ftrace_free_filter()
1273 hash->buckets = kcalloc(size, sizeof(*hash->buckets), GFP_KERNEL); in alloc_ftrace_hash()
1275 if (!hash->buckets) { in alloc_ftrace_hash()
1280 hash->size_bits = size_bits; in alloc_ftrace_hash()
1291 struct list_head *mod_head = enable ? &tr->mod_trace : &tr->mod_notrace; in ftrace_add_mod()
1295 return -ENOMEM; in ftrace_add_mod()
1297 ftrace_mod->func = kstrdup(func, GFP_KERNEL); in ftrace_add_mod()
1298 ftrace_mod->module = kstrdup(module, GFP_KERNEL); in ftrace_add_mod()
1299 ftrace_mod->enable = enable; in ftrace_add_mod()
1301 if (!ftrace_mod->func || !ftrace_mod->module) in ftrace_add_mod()
1304 list_add(&ftrace_mod->list, mod_head); in ftrace_add_mod()
1311 return -ENOMEM; in ftrace_add_mod()
1328 new_hash->flags = hash->flags; in alloc_and_copy_ftrace_hash()
1334 size = 1 << hash->size_bits; in alloc_and_copy_ftrace_hash()
1336 hlist_for_each_entry(entry, &hash->buckets[i], hlist) { in alloc_and_copy_ftrace_hash()
1337 ret = add_hash_entry(new_hash, entry->ip); in alloc_and_copy_ftrace_hash()
1343 FTRACE_WARN_ON(new_hash->count != hash->count); in alloc_and_copy_ftrace_hash()
1383 new_hash->flags = src->flags; in dup_hash()
1385 size = 1 << src->size_bits; in dup_hash()
1387 hhd = &src->buckets[i]; in dup_hash()
1399 int size = src->count; in __ftrace_hash_move()
1418 if (ops->flags & FTRACE_OPS_FL_IPMODIFY && !enable) in ftrace_hash_move()
1419 return -EINVAL; in ftrace_hash_move()
1423 return -ENOMEM; in ftrace_hash_move()
1457 return (ftrace_hash_empty(hash->filter_hash) || in hash_contains_ip()
1458 __ftrace_lookup_ip(hash->filter_hash, ip)) && in hash_contains_ip()
1459 (ftrace_hash_empty(hash->notrace_hash) || in hash_contains_ip()
1460 !__ftrace_lookup_ip(hash->notrace_hash, ip)); in hash_contains_ip()
1465 * the ops->func or not.
1467 * It's a match if the ip is in the ops->filter_hash or
1470 * the ip is not in the ops->notrace_hash.
1487 if (regs == NULL && (ops->flags & FTRACE_OPS_FL_SAVE_REGS)) in ftrace_ops_test()
1491 rcu_assign_pointer(hash.filter_hash, ops->func_hash->filter_hash); in ftrace_ops_test()
1492 rcu_assign_pointer(hash.notrace_hash, ops->func_hash->notrace_hash); in ftrace_ops_test()
1507 for (pg = ftrace_pages_start; pg; pg = pg->next) { \
1509 for (_____i = 0; _____i < pg->index; _____i++) { \
1510 rec = &pg->records[_____i];
1522 if (key->flags < rec->ip) in ftrace_cmp_recs()
1523 return -1; in ftrace_cmp_recs()
1524 if (key->ip >= rec->ip + MCOUNT_INSN_SIZE) in ftrace_cmp_recs()
1538 for (pg = ftrace_pages_start; pg; pg = pg->next) { in lookup_rec()
1539 if (end < pg->records[0].ip || in lookup_rec()
1540 start >= (pg->records[pg->index - 1].ip + MCOUNT_INSN_SIZE)) in lookup_rec()
1542 rec = bsearch(&key, pg->records, pg->index, in lookup_rec()
1552 * ftrace_location_range - return the first address of a traced location
1558 * Returns rec->ip if the related ftrace location is a least partly within
1569 return rec->ip; in ftrace_location_range()
1575 * ftrace_location - return true if the ip giving is a traced location
1578 * Returns rec->ip if @ip given is a pointer to a ftrace location.
1589 * ftrace_text_reserved - return true if range contains an ftrace location
1615 ops != &ftrace_list_end; ops = ops->next) { in test_rec_ops_needs_regs()
1616 /* pass rec in as regs to have non-NULL val */ in test_rec_ops_needs_regs()
1617 if (ftrace_ops_test(ops, rec->ip, rec)) { in test_rec_ops_needs_regs()
1618 if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) { in test_rec_ops_needs_regs()
1648 if (!(ops->flags & FTRACE_OPS_FL_ENABLED)) in __ftrace_hash_rec_update()
1663 hash = ops->func_hash->filter_hash; in __ftrace_hash_rec_update()
1664 other_hash = ops->func_hash->notrace_hash; in __ftrace_hash_rec_update()
1669 hash = ops->func_hash->notrace_hash; in __ftrace_hash_rec_update()
1670 other_hash = ops->func_hash->filter_hash; in __ftrace_hash_rec_update()
1684 if (rec->flags & FTRACE_FL_DISABLED) in __ftrace_hash_rec_update()
1692 if (!other_hash || !ftrace_lookup_ip(other_hash, rec->ip)) in __ftrace_hash_rec_update()
1695 in_hash = !!ftrace_lookup_ip(hash, rec->ip); in __ftrace_hash_rec_update()
1696 in_other_hash = !!ftrace_lookup_ip(other_hash, rec->ip); in __ftrace_hash_rec_update()
1718 rec->flags++; in __ftrace_hash_rec_update()
1722 if (ops->flags & FTRACE_OPS_FL_DIRECT) in __ftrace_hash_rec_update()
1723 rec->flags |= FTRACE_FL_DIRECT; in __ftrace_hash_rec_update()
1730 if (ftrace_rec_count(rec) == 1 && ops->trampoline) in __ftrace_hash_rec_update()
1731 rec->flags |= FTRACE_FL_TRAMP; in __ftrace_hash_rec_update()
1739 rec->flags &= ~FTRACE_FL_TRAMP; in __ftrace_hash_rec_update()
1745 if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) in __ftrace_hash_rec_update()
1746 rec->flags |= FTRACE_FL_REGS; in __ftrace_hash_rec_update()
1750 rec->flags--; in __ftrace_hash_rec_update()
1758 if (ops->flags & FTRACE_OPS_FL_DIRECT) in __ftrace_hash_rec_update()
1759 rec->flags &= ~FTRACE_FL_DIRECT; in __ftrace_hash_rec_update()
1768 rec->flags & FTRACE_FL_REGS && in __ftrace_hash_rec_update()
1769 ops->flags & FTRACE_OPS_FL_SAVE_REGS) { in __ftrace_hash_rec_update()
1771 rec->flags &= ~FTRACE_FL_REGS; in __ftrace_hash_rec_update()
1783 rec->flags |= FTRACE_FL_TRAMP; in __ftrace_hash_rec_update()
1785 rec->flags &= ~FTRACE_FL_TRAMP; in __ftrace_hash_rec_update()
1798 if (!all && count == hash->count) in __ftrace_hash_rec_update()
1824 if (ops->func_hash != &global_ops.local_hash) in ftrace_hash_rec_update_modify()
1835 if (op->func_hash == &global_ops.local_hash) in ftrace_hash_rec_update_modify()
1854 * or no-needed to update, -EBUSY if it detects a conflict of the flag
1855 * on a ftrace_rec, and -EINVAL if the new_hash tries to trace all recs.
1857 * - If the hash is NULL, it hits all recs (if IPMODIFY is set, this is rejected)
1858 * - If the hash is EMPTY_HASH, it hits nothing
1859 * - Anything else hits the recs which match the hash entries.
1870 if (!(ops->flags & FTRACE_OPS_FL_ENABLED)) in __ftrace_hash_update_ipmodify()
1873 if (!(ops->flags & FTRACE_OPS_FL_IPMODIFY)) in __ftrace_hash_update_ipmodify()
1881 return -EINVAL; in __ftrace_hash_update_ipmodify()
1883 /* Update rec->flags */ in __ftrace_hash_update_ipmodify()
1886 if (rec->flags & FTRACE_FL_DISABLED) in __ftrace_hash_update_ipmodify()
1890 in_old = !!ftrace_lookup_ip(old_hash, rec->ip); in __ftrace_hash_update_ipmodify()
1891 in_new = !!ftrace_lookup_ip(new_hash, rec->ip); in __ftrace_hash_update_ipmodify()
1897 if (rec->flags & FTRACE_FL_IPMODIFY) in __ftrace_hash_update_ipmodify()
1899 rec->flags |= FTRACE_FL_IPMODIFY; in __ftrace_hash_update_ipmodify()
1901 rec->flags &= ~FTRACE_FL_IPMODIFY; in __ftrace_hash_update_ipmodify()
1912 if (rec->flags & FTRACE_FL_DISABLED) in __ftrace_hash_update_ipmodify()
1918 in_old = !!ftrace_lookup_ip(old_hash, rec->ip); in __ftrace_hash_update_ipmodify()
1919 in_new = !!ftrace_lookup_ip(new_hash, rec->ip); in __ftrace_hash_update_ipmodify()
1924 rec->flags &= ~FTRACE_FL_IPMODIFY; in __ftrace_hash_update_ipmodify()
1926 rec->flags |= FTRACE_FL_IPMODIFY; in __ftrace_hash_update_ipmodify()
1930 return -EBUSY; in __ftrace_hash_update_ipmodify()
1935 struct ftrace_hash *hash = ops->func_hash->filter_hash; in ftrace_hash_ipmodify_enable()
1946 struct ftrace_hash *hash = ops->func_hash->filter_hash; in ftrace_hash_ipmodify_disable()
1957 struct ftrace_hash *old_hash = ops->func_hash->filter_hash; in ftrace_hash_ipmodify_update()
2008 * ftrace_bug - report and shutdown function tracer
2015 * EFAULT - if the problem happens on reading the @ip address
2016 * EINVAL - if what is read at @ip is not what was expected
2017 * EPERM - if the problem happens on writing to the @ip address
2021 unsigned long ip = rec ? rec->ip : 0; in ftrace_bug()
2023 pr_info("------------[ ftrace bug ]------------\n"); in ftrace_bug()
2026 case -EFAULT: in ftrace_bug()
2030 case -EINVAL: in ftrace_bug()
2040 case -EPERM: in ftrace_bug()
2052 pr_info("ftrace record flags: %lx\n", rec->flags); in ftrace_bug()
2054 rec->flags & FTRACE_FL_REGS ? " R" : " "); in ftrace_bug()
2055 if (rec->flags & FTRACE_FL_TRAMP_EN) { in ftrace_bug()
2060 (void *)ops->trampoline, in ftrace_bug()
2061 (void *)ops->func); in ftrace_bug()
2081 if (rec->flags & FTRACE_FL_DISABLED) in ftrace_check_record()
2105 if (!(rec->flags & FTRACE_FL_REGS) != in ftrace_check_record()
2106 !(rec->flags & FTRACE_FL_REGS_EN)) in ftrace_check_record()
2109 if (!(rec->flags & FTRACE_FL_TRAMP) != in ftrace_check_record()
2110 !(rec->flags & FTRACE_FL_TRAMP_EN)) in ftrace_check_record()
2124 if (!(rec->flags & FTRACE_FL_DIRECT) != in ftrace_check_record()
2125 !(rec->flags & FTRACE_FL_DIRECT_EN)) in ftrace_check_record()
2127 } else if (rec->flags & FTRACE_FL_DIRECT_EN) { in ftrace_check_record()
2133 if ((rec->flags & FTRACE_FL_ENABLED) == flag) in ftrace_check_record()
2138 flag ^= rec->flags & FTRACE_FL_ENABLED; in ftrace_check_record()
2141 rec->flags |= FTRACE_FL_ENABLED; in ftrace_check_record()
2143 if (rec->flags & FTRACE_FL_REGS) in ftrace_check_record()
2144 rec->flags |= FTRACE_FL_REGS_EN; in ftrace_check_record()
2146 rec->flags &= ~FTRACE_FL_REGS_EN; in ftrace_check_record()
2149 if (rec->flags & FTRACE_FL_TRAMP) in ftrace_check_record()
2150 rec->flags |= FTRACE_FL_TRAMP_EN; in ftrace_check_record()
2152 rec->flags &= ~FTRACE_FL_TRAMP_EN; in ftrace_check_record()
2162 if (rec->flags & FTRACE_FL_DIRECT) in ftrace_check_record()
2163 rec->flags |= FTRACE_FL_DIRECT_EN; in ftrace_check_record()
2165 rec->flags &= ~FTRACE_FL_DIRECT_EN; in ftrace_check_record()
2171 rec->flags &= ~FTRACE_FL_DIRECT_EN; in ftrace_check_record()
2181 * from the save regs, to a non-save regs function or in ftrace_check_record()
2196 rec->flags = 0; in ftrace_check_record()
2202 rec->flags &= ~(FTRACE_FL_ENABLED | FTRACE_FL_TRAMP_EN | in ftrace_check_record()
2211 * ftrace_update_record - set a record that now is tracing or not
2224 * ftrace_test_record - check if the record has been enabled or not
2241 unsigned long ip = rec->ip; in ftrace_find_tramp_ops_any()
2245 if (!op->trampoline) in ftrace_find_tramp_ops_any()
2248 if (hash_contains_ip(ip, op->func_hash)) in ftrace_find_tramp_ops_any()
2259 unsigned long ip = rec->ip; in ftrace_find_tramp_ops_any_other()
2263 if (op == op_exclude || !op->trampoline) in ftrace_find_tramp_ops_any_other()
2266 if (hash_contains_ip(ip, op->func_hash)) in ftrace_find_tramp_ops_any_other()
2277 unsigned long ip = rec->ip; in ftrace_find_tramp_ops_next()
2281 if (!op->trampoline) in ftrace_find_tramp_ops_next()
2284 if (hash_contains_ip(ip, op->func_hash)) in ftrace_find_tramp_ops_next()
2295 unsigned long ip = rec->ip; in ftrace_find_tramp_ops_curr()
2304 if (hash_contains_ip(ip, &removed_ops->old_hash)) in ftrace_find_tramp_ops_curr()
2328 if (!op->trampoline) in ftrace_find_tramp_ops_curr()
2335 if (op->flags & FTRACE_OPS_FL_ADDING) in ftrace_find_tramp_ops_curr()
2344 if ((op->flags & FTRACE_OPS_FL_MODIFYING) && in ftrace_find_tramp_ops_curr()
2345 hash_contains_ip(ip, &op->old_hash)) in ftrace_find_tramp_ops_curr()
2352 if (!(op->flags & FTRACE_OPS_FL_MODIFYING) && in ftrace_find_tramp_ops_curr()
2353 hash_contains_ip(ip, op->func_hash)) in ftrace_find_tramp_ops_curr()
2365 unsigned long ip = rec->ip; in ftrace_find_tramp_ops_new()
2368 /* pass rec in as regs to have non-NULL val */ in ftrace_find_tramp_ops_new()
2369 if (hash_contains_ip(ip, op->func_hash)) in ftrace_find_tramp_ops_new()
2394 return entry->direct; in ftrace_find_rec_direct()
2427 * ftrace_get_addr_new - Get the call address to set to
2441 if ((rec->flags & FTRACE_FL_DIRECT) && in ftrace_get_addr_new()
2443 addr = ftrace_find_rec_direct(rec->ip); in ftrace_get_addr_new()
2450 if (rec->flags & FTRACE_FL_TRAMP) { in ftrace_get_addr_new()
2452 if (FTRACE_WARN_ON(!ops || !ops->trampoline)) { in ftrace_get_addr_new()
2454 (void *)rec->ip, (void *)rec->ip, rec->flags); in ftrace_get_addr_new()
2458 return ops->trampoline; in ftrace_get_addr_new()
2461 if (rec->flags & FTRACE_FL_REGS) in ftrace_get_addr_new()
2468 * ftrace_get_addr_curr - Get the call address that is already there
2483 if (rec->flags & FTRACE_FL_DIRECT_EN) { in ftrace_get_addr_curr()
2484 addr = ftrace_find_rec_direct(rec->ip); in ftrace_get_addr_curr()
2491 if (rec->flags & FTRACE_FL_TRAMP_EN) { in ftrace_get_addr_curr()
2495 (void *)rec->ip, (void *)rec->ip); in ftrace_get_addr_curr()
2499 return ops->trampoline; in ftrace_get_addr_curr()
2502 if (rec->flags & FTRACE_FL_REGS_EN) in ftrace_get_addr_curr()
2541 return -1; /* unknown ftrace bug */ in __ftrace_replace_code()
2557 if (rec->flags & FTRACE_FL_DISABLED) in ftrace_replace_code()
2577 * ftrace_rec_iter_start - start up iterating over traced functions
2594 iter->pg = ftrace_pages_start; in ftrace_rec_iter_start()
2595 iter->index = 0; in ftrace_rec_iter_start()
2598 while (iter->pg && !iter->pg->index) in ftrace_rec_iter_start()
2599 iter->pg = iter->pg->next; in ftrace_rec_iter_start()
2601 if (!iter->pg) in ftrace_rec_iter_start()
2608 * ftrace_rec_iter_next - get the next record to process.
2615 iter->index++; in ftrace_rec_iter_next()
2617 if (iter->index >= iter->pg->index) { in ftrace_rec_iter_next()
2618 iter->pg = iter->pg->next; in ftrace_rec_iter_next()
2619 iter->index = 0; in ftrace_rec_iter_next()
2622 while (iter->pg && !iter->pg->index) in ftrace_rec_iter_next()
2623 iter->pg = iter->pg->next; in ftrace_rec_iter_next()
2626 if (!iter->pg) in ftrace_rec_iter_next()
2633 * ftrace_rec_iter_record - get the record at the iterator location
2640 return &iter->pg->records[iter->index]; in ftrace_rec_iter_record()
2736 * ftrace_run_stop_machine - go back to the stop machine method
2748 * arch_ftrace_update_code - modify the code to trace or not trace
2783 ops->flags |= FTRACE_OPS_FL_MODIFYING; in ftrace_run_modify_code()
2784 ops->old_hash.filter_hash = old_hash->filter_hash; in ftrace_run_modify_code()
2785 ops->old_hash.notrace_hash = old_hash->notrace_hash; in ftrace_run_modify_code()
2787 ops->old_hash.filter_hash = NULL; in ftrace_run_modify_code()
2788 ops->old_hash.notrace_hash = NULL; in ftrace_run_modify_code()
2789 ops->flags &= ~FTRACE_OPS_FL_MODIFYING; in ftrace_run_modify_code()
2805 list_add_rcu(&ops->list, &ftrace_ops_trampoline_list); in ftrace_add_trampoline_to_kallsyms()
2811 list_del_rcu(&ops->list); in ftrace_remove_trampoline_from_kallsyms()
2825 if (ops && (ops->flags & FTRACE_OPS_FL_ALLOC_TRAMP) && in ftrace_trampoline_free()
2826 ops->trampoline) { in ftrace_trampoline_free()
2831 perf_event_text_poke((void *)ops->trampoline, in ftrace_trampoline_free()
2832 (void *)ops->trampoline, in ftrace_trampoline_free()
2833 ops->trampoline_size, NULL, 0); in ftrace_trampoline_free()
2835 ops->trampoline, ops->trampoline_size, in ftrace_trampoline_free()
2869 return -ENODEV; in ftrace_startup()
2885 ops->flags |= FTRACE_OPS_FL_ENABLED | FTRACE_OPS_FL_ADDING; in ftrace_startup()
2891 ftrace_start_up--; in ftrace_startup()
2892 ops->flags &= ~FTRACE_OPS_FL_ENABLED; in ftrace_startup()
2893 if (ops->flags & FTRACE_OPS_FL_DYNAMIC) in ftrace_startup()
2903 ops->flags &= ~FTRACE_OPS_FL_ADDING; in ftrace_startup()
2913 return -ENODEV; in ftrace_shutdown()
2919 ftrace_start_up--; in ftrace_shutdown()
2933 ops->flags &= ~FTRACE_OPS_FL_ENABLED; in ftrace_shutdown()
2947 if (ops->flags & FTRACE_OPS_FL_DYNAMIC) in ftrace_shutdown()
2957 ops->flags |= FTRACE_OPS_FL_REMOVING; in ftrace_shutdown()
2961 ops->old_hash.filter_hash = ops->func_hash->filter_hash; in ftrace_shutdown()
2962 ops->old_hash.notrace_hash = ops->func_hash->notrace_hash; in ftrace_shutdown()
2976 if (FTRACE_WARN_ON_ONCE(rec->flags & ~FTRACE_FL_DISABLED)) in ftrace_shutdown()
2978 (void *)rec->ip, rec->flags); in ftrace_shutdown()
2982 ops->old_hash.filter_hash = NULL; in ftrace_shutdown()
2983 ops->old_hash.notrace_hash = NULL; in ftrace_shutdown()
2986 ops->flags &= ~FTRACE_OPS_FL_REMOVING; in ftrace_shutdown()
2994 if (ops->flags & FTRACE_OPS_FL_DYNAMIC) { in ftrace_shutdown()
3067 return ftrace_hash_empty(ops->func_hash->filter_hash) && in ops_traces_mod()
3068 ftrace_hash_empty(ops->func_hash->notrace_hash); in ops_traces_mod()
3082 if (!(ops->flags & FTRACE_OPS_FL_ENABLED)) in ops_references_rec()
3090 if (!ftrace_hash_empty(ops->func_hash->filter_hash) && in ops_references_rec()
3091 !__ftrace_lookup_ip(ops->func_hash->filter_hash, rec->ip)) in ops_references_rec()
3095 if (ftrace_lookup_ip(ops->func_hash->notrace_hash, rec->ip)) in ops_references_rec()
3118 * read-only, the modification of enabling ftrace can fail if in ftrace_update_code()
3119 * the read-only is done while ftrace is converting the calls. in ftrace_update_code()
3122 * to read-only. in ftrace_update_code()
3127 for (pg = new_pgs; pg; pg = pg->next) { in ftrace_update_code()
3129 for (i = 0; i < pg->index; i++) { in ftrace_update_code()
3133 return -1; in ftrace_update_code()
3135 p = &pg->records[i]; in ftrace_update_code()
3136 p->flags = rec_flags; in ftrace_update_code()
3150 ftrace_update_time = stop - start; in ftrace_update_code()
3163 return -EINVAL; in ftrace_allocate_records()
3167 order = fls(pages) - 1; in ftrace_allocate_records()
3170 pg->records = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, order); in ftrace_allocate_records()
3172 if (!pg->records) { in ftrace_allocate_records()
3175 return -ENOMEM; in ftrace_allocate_records()
3184 pg->order = order; 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 if (pg->records) { in ftrace_allocate_pages()
3233 free_pages((unsigned long)pg->records, pg->order); in ftrace_allocate_pages()
3234 ftrace_number_of_pages -= 1 << pg->order; in ftrace_allocate_pages()
3236 start_pg = pg->next; in ftrace_allocate_pages()
3239 ftrace_number_of_groups--; in ftrace_allocate_pages()
3268 struct ftrace_iterator *iter = m->private; in t_probe_next()
3269 struct trace_array *tr = iter->ops->private; in t_probe_next()
3278 iter->pos = *pos; in t_probe_next()
3283 func_probes = &tr->func_probes; in t_probe_next()
3287 if (!iter->probe) { in t_probe_next()
3288 next = func_probes->next; in t_probe_next()
3289 iter->probe = list_entry(next, struct ftrace_func_probe, list); in t_probe_next()
3292 if (iter->probe_entry) in t_probe_next()
3293 hnd = &iter->probe_entry->hlist; in t_probe_next()
3295 hash = iter->probe->ops.func_hash->filter_hash; in t_probe_next()
3304 size = 1 << hash->size_bits; in t_probe_next()
3307 if (iter->pidx >= size) { in t_probe_next()
3308 if (iter->probe->list.next == func_probes) in t_probe_next()
3310 next = iter->probe->list.next; in t_probe_next()
3311 iter->probe = list_entry(next, struct ftrace_func_probe, list); in t_probe_next()
3312 hash = iter->probe->ops.func_hash->filter_hash; in t_probe_next()
3313 size = 1 << hash->size_bits; in t_probe_next()
3314 iter->pidx = 0; in t_probe_next()
3317 hhd = &hash->buckets[iter->pidx]; in t_probe_next()
3320 iter->pidx++; in t_probe_next()
3326 hnd = hhd->first; in t_probe_next()
3328 hnd = hnd->next; in t_probe_next()
3330 iter->pidx++; in t_probe_next()
3338 iter->probe_entry = hlist_entry(hnd, struct ftrace_func_entry, hlist); in t_probe_next()
3345 struct ftrace_iterator *iter = m->private; in t_probe_start()
3349 if (!(iter->flags & FTRACE_ITER_DO_PROBES)) in t_probe_start()
3352 if (iter->mod_pos > *pos) in t_probe_start()
3355 iter->probe = NULL; in t_probe_start()
3356 iter->probe_entry = NULL; in t_probe_start()
3357 iter->pidx = 0; in t_probe_start()
3358 for (l = 0; l <= (*pos - iter->mod_pos); ) { in t_probe_start()
3367 iter->flags |= FTRACE_ITER_PROBE; in t_probe_start()
3379 probe = iter->probe; in t_probe_show()
3380 probe_entry = iter->probe_entry; in t_probe_show()
3383 return -EIO; in t_probe_show()
3385 probe_ops = probe->probe_ops; in t_probe_show()
3387 if (probe_ops->print) in t_probe_show()
3388 return probe_ops->print(m, probe_entry->ip, probe_ops, probe->data); in t_probe_show()
3390 seq_printf(m, "%ps:%ps\n", (void *)probe_entry->ip, in t_probe_show()
3391 (void *)probe_ops->func); in t_probe_show()
3399 struct ftrace_iterator *iter = m->private; in t_mod_next()
3400 struct trace_array *tr = iter->tr; in t_mod_next()
3403 iter->pos = *pos; in t_mod_next()
3405 iter->mod_list = iter->mod_list->next; in t_mod_next()
3407 if (iter->mod_list == &tr->mod_trace || in t_mod_next()
3408 iter->mod_list == &tr->mod_notrace) { in t_mod_next()
3409 iter->flags &= ~FTRACE_ITER_MOD; in t_mod_next()
3413 iter->mod_pos = *pos; in t_mod_next()
3420 struct ftrace_iterator *iter = m->private; in t_mod_start()
3424 if (iter->func_pos > *pos) in t_mod_start()
3427 iter->mod_pos = iter->func_pos; in t_mod_start()
3430 if (!iter->tr) in t_mod_start()
3433 for (l = 0; l <= (*pos - iter->func_pos); ) { in t_mod_start()
3439 iter->flags &= ~FTRACE_ITER_MOD; in t_mod_start()
3444 iter->flags |= FTRACE_ITER_MOD; in t_mod_start()
3453 struct trace_array *tr = iter->tr; in t_mod_show()
3455 if (WARN_ON_ONCE(!iter->mod_list) || in t_mod_show()
3456 iter->mod_list == &tr->mod_trace || in t_mod_show()
3457 iter->mod_list == &tr->mod_notrace) in t_mod_show()
3458 return -EIO; in t_mod_show()
3460 ftrace_mod = list_entry(iter->mod_list, struct ftrace_mod_load, list); in t_mod_show()
3462 if (ftrace_mod->func) in t_mod_show()
3463 seq_printf(m, "%s", ftrace_mod->func); in t_mod_show()
3467 seq_printf(m, ":mod:%s\n", ftrace_mod->module); in t_mod_show()
3475 struct ftrace_iterator *iter = m->private; in t_func_next()
3481 if (iter->idx >= iter->pg->index) { in t_func_next()
3482 if (iter->pg->next) { in t_func_next()
3483 iter->pg = iter->pg->next; in t_func_next()
3484 iter->idx = 0; in t_func_next()
3488 rec = &iter->pg->records[iter->idx++]; in t_func_next()
3489 if (((iter->flags & (FTRACE_ITER_FILTER | FTRACE_ITER_NOTRACE)) && in t_func_next()
3490 !ftrace_lookup_ip(iter->hash, rec->ip)) || in t_func_next()
3492 ((iter->flags & FTRACE_ITER_ENABLED) && in t_func_next()
3493 !(rec->flags & FTRACE_FL_ENABLED))) { in t_func_next()
3503 iter->pos = iter->func_pos = *pos; in t_func_next()
3504 iter->func = rec; in t_func_next()
3512 struct ftrace_iterator *iter = m->private; in t_next()
3519 if (iter->flags & FTRACE_ITER_PROBE) in t_next()
3522 if (iter->flags & FTRACE_ITER_MOD) in t_next()
3525 if (iter->flags & FTRACE_ITER_PRINTALL) { in t_next()
3541 iter->pos = 0; in reset_iter_read()
3542 iter->func_pos = 0; in reset_iter_read()
3543 iter->flags &= ~(FTRACE_ITER_PRINTALL | FTRACE_ITER_PROBE | FTRACE_ITER_MOD); in reset_iter_read()
3548 struct ftrace_iterator *iter = m->private; in t_start()
3560 if (*pos < iter->pos) in t_start()
3568 if ((iter->flags & (FTRACE_ITER_FILTER | FTRACE_ITER_NOTRACE)) && in t_start()
3569 ftrace_hash_empty(iter->hash)) { in t_start()
3570 iter->func_pos = 1; /* Account for the message */ in t_start()
3573 iter->flags |= FTRACE_ITER_PRINTALL; in t_start()
3575 iter->flags &= ~FTRACE_ITER_PROBE; in t_start()
3579 if (iter->flags & FTRACE_ITER_MOD) in t_start()
3587 iter->pg = ftrace_pages_start; in t_start()
3588 iter->idx = 0; in t_start()
3619 seq_printf(m, " ->%pS", ptr); in add_trampoline_func()
3624 struct ftrace_iterator *iter = m->private; in t_show()
3627 if (iter->flags & FTRACE_ITER_PROBE) in t_show()
3630 if (iter->flags & FTRACE_ITER_MOD) in t_show()
3633 if (iter->flags & FTRACE_ITER_PRINTALL) { in t_show()
3634 if (iter->flags & FTRACE_ITER_NOTRACE) in t_show()
3641 rec = iter->func; in t_show()
3646 seq_printf(m, "%ps", (void *)rec->ip); in t_show()
3647 if (iter->flags & FTRACE_ITER_ENABLED) { in t_show()
3652 rec->flags & FTRACE_FL_REGS ? " R" : " ", in t_show()
3653 rec->flags & FTRACE_FL_IPMODIFY ? " I" : " ", in t_show()
3654 rec->flags & FTRACE_FL_DIRECT ? " D" : " "); in t_show()
3655 if (rec->flags & FTRACE_FL_TRAMP_EN) { in t_show()
3660 (void *)ops->trampoline, in t_show()
3661 (void *)ops->func); in t_show()
3670 if (rec->flags & FTRACE_FL_DIRECT) { in t_show()
3673 direct = ftrace_find_rec_direct(rec->ip); in t_show()
3675 seq_printf(m, "\n\tdirect-->%pS", (void *)direct); in t_show()
3702 return -ENODEV; in ftrace_avail_open()
3706 return -ENOMEM; in ftrace_avail_open()
3708 iter->pg = ftrace_pages_start; in ftrace_avail_open()
3709 iter->ops = &global_ops; in ftrace_avail_open()
3730 return -ENOMEM; in ftrace_enabled_open()
3732 iter->pg = ftrace_pages_start; in ftrace_enabled_open()
3733 iter->flags = FTRACE_ITER_ENABLED; in ftrace_enabled_open()
3734 iter->ops = &global_ops; in ftrace_enabled_open()
3740 * ftrace_regex_open - initialize function tracer filter files
3762 struct trace_array *tr = ops->private; in ftrace_regex_open()
3763 int ret = -ENOMEM; in ftrace_regex_open()
3768 return -ENODEV; in ftrace_regex_open()
3771 return -ENODEV; in ftrace_regex_open()
3777 if (trace_parser_get_init(&iter->parser, FTRACE_BUFF_MAX)) in ftrace_regex_open()
3780 iter->ops = ops; in ftrace_regex_open()
3781 iter->flags = flag; in ftrace_regex_open()
3782 iter->tr = tr; in ftrace_regex_open()
3784 mutex_lock(&ops->func_hash->regex_lock); in ftrace_regex_open()
3787 hash = ops->func_hash->notrace_hash; in ftrace_regex_open()
3788 mod_head = tr ? &tr->mod_notrace : NULL; in ftrace_regex_open()
3790 hash = ops->func_hash->filter_hash; in ftrace_regex_open()
3791 mod_head = tr ? &tr->mod_trace : NULL; in ftrace_regex_open()
3794 iter->mod_list = mod_head; in ftrace_regex_open()
3796 if (file->f_mode & FMODE_WRITE) { in ftrace_regex_open()
3799 if (file->f_flags & O_TRUNC) { in ftrace_regex_open()
3800 iter->hash = alloc_ftrace_hash(size_bits); in ftrace_regex_open()
3803 iter->hash = alloc_and_copy_ftrace_hash(size_bits, hash); in ftrace_regex_open()
3806 if (!iter->hash) { in ftrace_regex_open()
3807 trace_parser_put(&iter->parser); in ftrace_regex_open()
3811 iter->hash = hash; in ftrace_regex_open()
3815 if (file->f_mode & FMODE_READ) { in ftrace_regex_open()
3816 iter->pg = ftrace_pages_start; in ftrace_regex_open()
3820 struct seq_file *m = file->private_data; in ftrace_regex_open()
3821 m->private = iter; in ftrace_regex_open()
3824 free_ftrace_hash(iter->hash); in ftrace_regex_open()
3825 trace_parser_put(&iter->parser); in ftrace_regex_open()
3828 file->private_data = iter; in ftrace_regex_open()
3831 mutex_unlock(&ops->func_hash->regex_lock); in ftrace_regex_open()
3846 struct ftrace_ops *ops = inode->i_private; in ftrace_filter_open()
3857 struct ftrace_ops *ops = inode->i_private; in ftrace_notrace_open()
3872 * If symbols in an architecture don't correspond exactly to the user-visible
3886 str = arch_ftrace_match_adjust(str, g->search); in ftrace_match()
3888 switch (g->type) { in ftrace_match()
3890 if (strcmp(str, g->search) == 0) in ftrace_match()
3894 if (strncmp(str, g->search, g->len) == 0) in ftrace_match()
3898 if (strstr(str, g->search)) in ftrace_match()
3903 if (slen >= g->len && in ftrace_match()
3904 memcmp(str + slen - g->len, g->search, g->len) == 0) in ftrace_match()
3908 if (glob_match(g->search, str)) in ftrace_match()
3922 entry = ftrace_lookup_ip(hash, rec->ip); in enter_record()
3934 ret = add_hash_entry(hash, rec->ip); in enter_record()
3943 long index = simple_strtoul(func_g->search, NULL, 0); in add_rec_by_index()
3948 if (--index < 0) in add_rec_by_index()
3952 if (pg->index <= index) { in add_rec_by_index()
3953 index -= pg->index; in add_rec_by_index()
3957 rec = &pg->records[index]; in add_rec_by_index()
3971 kallsyms_lookup(rec->ip, NULL, NULL, &modname, str); in ftrace_match_record()
3977 if (!mod_g->len) { in ftrace_match_record()
3995 if (!func_g->len) in ftrace_match_record()
4039 if (rec->flags & FTRACE_FL_DISABLED) in match_records()
4071 if (ops->flags & FTRACE_OPS_FL_ENABLED) { in ftrace_ops_update_code()
4077 * If this is the shared global_ops filter, then we need to in ftrace_ops_update_code()
4081 if (ops->func_hash != &global_ops.local_hash) in ftrace_ops_update_code()
4085 if (op->func_hash == &global_ops.local_hash && in ftrace_ops_update_code()
4086 op->flags & FTRACE_OPS_FL_ENABLED) { in ftrace_ops_update_code()
4104 old_hash_ops.filter_hash = ops->func_hash->filter_hash; in ftrace_hash_move_and_update_ops()
4105 old_hash_ops.notrace_hash = ops->func_hash->notrace_hash; in ftrace_hash_move_and_update_ops()
4124 if (n > sizeof(modname) - 1) in module_exists()
4135 struct list_head *head = enable ? &tr->mod_trace : &tr->mod_notrace; in cache_mod()
4143 ret = -EINVAL; in cache_mod()
4147 if (strcmp(ftrace_mod->module, module) != 0) in cache_mod()
4152 (ftrace_mod->func && in cache_mod()
4153 strcmp(ftrace_mod->func, func) == 0)) { in cache_mod()
4162 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_move(&ftrace_mod->list, &process_mods); in process_mod_list()
4218 kfree(ftrace_mod->func); in process_mod_list()
4219 ftrace_mod->func = func; in process_mod_list()
4226 func = ftrace_mod->func; in process_mod_list()
4234 new_hash->flags &= ~FTRACE_HASH_FL_MOD; in process_mod_list()
4243 mutex_unlock(&ops->func_hash->regex_lock); in process_mod_list()
4259 if (!list_empty(&tr->mod_trace)) in process_cached_mods()
4260 process_mod_list(&tr->mod_trace, tr->ops, mod, true); in process_cached_mods()
4261 if (!list_empty(&tr->mod_notrace)) in process_cached_mods()
4262 process_mod_list(&tr->mod_notrace, tr->ops, mod, false); in process_cached_mods()
4285 return -ENOMEM; in ftrace_mod_callback()
4322 probe_ops = probe->probe_ops; in function_trace_probe_call()
4330 probe_ops->func(ip, parent_ip, probe->tr, probe_ops, probe->data); in function_trace_probe_call()
4344 * allocate_ftrace_func_mapper - allocate a new ftrace_func_mapper
4362 * ftrace_func_mapper_find_ip - Find some data mapped to an ip
4378 entry = ftrace_lookup_ip(&mapper->hash, ip); in ftrace_func_mapper_find_ip()
4383 return &map->data; in ftrace_func_mapper_find_ip()
4387 * ftrace_func_mapper_add_ip - Map some data to an ip
4400 entry = ftrace_lookup_ip(&mapper->hash, ip); in ftrace_func_mapper_add_ip()
4402 return -EBUSY; in ftrace_func_mapper_add_ip()
4406 return -ENOMEM; in ftrace_func_mapper_add_ip()
4408 map->entry.ip = ip; in ftrace_func_mapper_add_ip()
4409 map->data = data; in ftrace_func_mapper_add_ip()
4411 __add_hash_entry(&mapper->hash, &map->entry); in ftrace_func_mapper_add_ip()
4417 * ftrace_func_mapper_remove_ip - Remove an ip from the mapping
4433 entry = ftrace_lookup_ip(&mapper->hash, ip); in ftrace_func_mapper_remove_ip()
4438 data = map->data; in ftrace_func_mapper_remove_ip()
4440 remove_hash_entry(&mapper->hash, entry); in ftrace_func_mapper_remove_ip()
4447 * free_ftrace_func_mapper - free a mapping of ips and data
4465 if (free_func && mapper->hash.count) { in free_ftrace_func_mapper()
4466 size = 1 << mapper->hash.size_bits; in free_ftrace_func_mapper()
4468 hhd = &mapper->hash.buckets[i]; in free_ftrace_func_mapper()
4475 free_ftrace_hash(&mapper->hash); in free_ftrace_func_mapper()
4484 WARN_ON(probe->ref <= 0); in release_probe()
4487 probe->ref--; in release_probe()
4489 if (!probe->ref) { in release_probe()
4490 probe_ops = probe->probe_ops; in release_probe()
4493 * the probe->data itself in release_probe()
4495 if (probe_ops->free) in release_probe()
4496 probe_ops->free(probe_ops, probe->tr, 0, probe->data); in release_probe()
4497 list_del(&probe->list); in release_probe()
4509 probe->ref++; in acquire_probe_locked()
4528 return -EINVAL; in register_ftrace_function_probe()
4532 return -EINVAL; in register_ftrace_function_probe()
4537 list_for_each_entry(probe, &tr->func_probes, list) { in register_ftrace_function_probe()
4538 if (probe->probe_ops == probe_ops) in register_ftrace_function_probe()
4541 if (&probe->list == &tr->func_probes) { in register_ftrace_function_probe()
4545 return -ENOMEM; in register_ftrace_function_probe()
4547 probe->probe_ops = probe_ops; in register_ftrace_function_probe()
4548 probe->ops.func = function_trace_probe_call; in register_ftrace_function_probe()
4549 probe->tr = tr; in register_ftrace_function_probe()
4550 ftrace_ops_init(&probe->ops); in register_ftrace_function_probe()
4551 list_add(&probe->list, &tr->func_probes); in register_ftrace_function_probe()
4559 * Note, there's a small window here that the func_hash->filter_hash in register_ftrace_function_probe()
4562 mutex_lock(&probe->ops.func_hash->regex_lock); in register_ftrace_function_probe()
4564 orig_hash = &probe->ops.func_hash->filter_hash; in register_ftrace_function_probe()
4569 ret = -ENOMEM; in register_ftrace_function_probe()
4577 ret = -EINVAL; in register_ftrace_function_probe()
4582 size = 1 << hash->size_bits; in register_ftrace_function_probe()
4584 hlist_for_each_entry(entry, &hash->buckets[i], hlist) { in register_ftrace_function_probe()
4585 if (ftrace_lookup_ip(old_hash, entry->ip)) in register_ftrace_function_probe()
4592 if (probe_ops->init) { in register_ftrace_function_probe()
4593 ret = probe_ops->init(probe_ops, tr, in register_ftrace_function_probe()
4594 entry->ip, data, in register_ftrace_function_probe()
4595 &probe->data); in register_ftrace_function_probe()
4597 if (probe_ops->free && count) in register_ftrace_function_probe()
4598 probe_ops->free(probe_ops, tr, in register_ftrace_function_probe()
4599 0, probe->data); in register_ftrace_function_probe()
4600 probe->data = NULL; in register_ftrace_function_probe()
4612 ret = -EINVAL; in register_ftrace_function_probe()
4616 ret = ftrace_hash_move_and_update_ops(&probe->ops, orig_hash, in register_ftrace_function_probe()
4622 probe->ref += count; in register_ftrace_function_probe()
4624 if (!(probe->ops.flags & FTRACE_OPS_FL_ENABLED)) in register_ftrace_function_probe()
4625 ret = ftrace_startup(&probe->ops, 0); in register_ftrace_function_probe()
4633 mutex_unlock(&probe->ops.func_hash->regex_lock); in register_ftrace_function_probe()
4641 if (!probe_ops->free || !count) in register_ftrace_function_probe()
4646 hlist_for_each_entry(entry, &hash->buckets[i], hlist) { in register_ftrace_function_probe()
4647 if (ftrace_lookup_ip(old_hash, entry->ip)) in register_ftrace_function_probe()
4649 probe_ops->free(probe_ops, tr, entry->ip, probe->data); in register_ftrace_function_probe()
4670 int i, ret = -ENODEV; in unregister_ftrace_function_probe_func()
4684 return -EINVAL; in unregister_ftrace_function_probe_func()
4689 list_for_each_entry(probe, &tr->func_probes, list) { in unregister_ftrace_function_probe_func()
4690 if (probe->probe_ops == probe_ops) in unregister_ftrace_function_probe_func()
4693 if (&probe->list == &tr->func_probes) in unregister_ftrace_function_probe_func()
4696 ret = -EINVAL; in unregister_ftrace_function_probe_func()
4697 if (!(probe->ops.flags & FTRACE_OPS_FL_INITIALIZED)) in unregister_ftrace_function_probe_func()
4704 mutex_lock(&probe->ops.func_hash->regex_lock); in unregister_ftrace_function_probe_func()
4706 orig_hash = &probe->ops.func_hash->filter_hash; in unregister_ftrace_function_probe_func()
4716 ret = -ENOMEM; in unregister_ftrace_function_probe_func()
4723 size = 1 << hash->size_bits; in unregister_ftrace_function_probe_func()
4725 hlist_for_each_entry_safe(entry, tmp, &hash->buckets[i], hlist) { in unregister_ftrace_function_probe_func()
4728 kallsyms_lookup(entry->ip, NULL, NULL, in unregister_ftrace_function_probe_func()
4735 hlist_add_head(&entry->hlist, &hhd); in unregister_ftrace_function_probe_func()
4741 ret = -EINVAL; in unregister_ftrace_function_probe_func()
4747 WARN_ON(probe->ref < count); in unregister_ftrace_function_probe_func()
4749 probe->ref -= count; in unregister_ftrace_function_probe_func()
4752 ftrace_shutdown(&probe->ops, 0); in unregister_ftrace_function_probe_func()
4754 ret = ftrace_hash_move_and_update_ops(&probe->ops, orig_hash, in unregister_ftrace_function_probe_func()
4759 ftrace_run_modify_code(&probe->ops, FTRACE_UPDATE_CALLS, in unregister_ftrace_function_probe_func()
4764 hlist_del(&entry->hlist); in unregister_ftrace_function_probe_func()
4765 if (probe_ops->free) in unregister_ftrace_function_probe_func()
4766 probe_ops->free(probe_ops, tr, entry->ip, probe->data); in unregister_ftrace_function_probe_func()
4772 mutex_unlock(&probe->ops.func_hash->regex_lock); in unregister_ftrace_function_probe_func()
4788 list_for_each_entry_safe(probe, n, &tr->func_probes, list) in clear_ftrace_function_probes()
4789 unregister_ftrace_function_probe_func(NULL, tr, probe->probe_ops); in clear_ftrace_function_probes()
4806 if (strcmp(cmd->name, p->name) == 0) { in register_ftrace_command()
4807 ret = -EBUSY; in register_ftrace_command()
4811 list_add(&cmd->list, &ftrace_commands); in register_ftrace_command()
4825 int ret = -ENODEV; in unregister_ftrace_command()
4829 if (strcmp(cmd->name, p->name) == 0) { in unregister_ftrace_command()
4831 list_del_init(&p->list); in unregister_ftrace_command()
4844 struct ftrace_hash *hash = iter->hash; in ftrace_process_regex()
4845 struct trace_array *tr = iter->ops->private; in ftrace_process_regex()
4848 int ret = -EINVAL; in ftrace_process_regex()
4855 ret = -EINVAL; in ftrace_process_regex()
4867 if (strcmp(p->name, command) == 0) { in ftrace_process_regex()
4868 ret = p->func(tr, hash, func, command, next, enable); in ftrace_process_regex()
4889 if (file->f_mode & FMODE_READ) { in ftrace_regex_write()
4890 struct seq_file *m = file->private_data; in ftrace_regex_write()
4891 iter = m->private; in ftrace_regex_write()
4893 iter = file->private_data; in ftrace_regex_write()
4896 return -ENODEV; in ftrace_regex_write()
4898 /* iter->hash is a local copy, so we don't need regex_lock */ in ftrace_regex_write()
4900 parser = &iter->parser; in ftrace_regex_write()
4905 ret = ftrace_process_regex(iter, parser->buffer, in ftrace_regex_write()
4906 parser->idx, enable); in ftrace_regex_write()
4937 return -EINVAL; in ftrace_match_addr()
4942 return -ENOENT; in ftrace_match_addr()
4959 return -ENODEV; in ftrace_set_hash()
4961 mutex_lock(&ops->func_hash->regex_lock); in ftrace_set_hash()
4964 orig_hash = &ops->func_hash->filter_hash; in ftrace_set_hash()
4966 orig_hash = &ops->func_hash->notrace_hash; in ftrace_set_hash()
4974 ret = -ENOMEM; in ftrace_set_hash()
4979 ret = -EINVAL; in ftrace_set_hash()
4993 mutex_unlock(&ops->func_hash->regex_lock); in ftrace_set_hash()
5017 * ftrace_find_direct_func - test an address if it is a registered direct caller
5036 if (entry->addr == addr) { in ftrace_find_direct_func()
5054 direct->addr = addr; in ftrace_alloc_direct_func()
5055 direct->count = 0; in ftrace_alloc_direct_func()
5056 list_add_rcu(&direct->next, &ftrace_direct_funcs); in ftrace_alloc_direct_func()
5062 * register_ftrace_direct - Call a custom trampoline directly
5074 * -EBUSY - Another direct function is already attached (there can be only one)
5075 * -ENODEV - @ip does not point to a ftrace nop location (or not supported)
5076 * -ENOMEM - There was an allocation failure.
5084 int ret = -EBUSY; in register_ftrace_direct()
5092 ret = -ENODEV; in register_ftrace_direct()
5101 if (WARN_ON(rec->flags & FTRACE_FL_DIRECT)) in register_ftrace_direct()
5105 if (ip != rec->ip) { in register_ftrace_direct()
5106 ip = rec->ip; in register_ftrace_direct()
5112 ret = -ENOMEM; in register_ftrace_direct()
5114 direct_functions->count > 2 * (1 << direct_functions->size_bits)) { in register_ftrace_direct()
5117 direct_functions->count + 1; in register_ftrace_direct()
5143 entry->ip = ip; in register_ftrace_direct()
5144 entry->direct = addr; in register_ftrace_direct()
5159 if (!direct->count) { in register_ftrace_direct()
5160 list_del_rcu(&direct->next); in register_ftrace_direct()
5166 ftrace_direct_func_count--; in register_ftrace_direct()
5169 direct->count++; in register_ftrace_direct()
5193 entry = __ftrace_lookup_ip(direct_functions, rec->ip); in find_direct_entry()
5195 WARN_ON(rec->flags & FTRACE_FL_DIRECT); in find_direct_entry()
5199 WARN_ON(!(rec->flags & FTRACE_FL_DIRECT)); in find_direct_entry()
5202 *ip = rec->ip; in find_direct_entry()
5214 int ret = -ENODEV; in unregister_ftrace_direct()
5222 if (direct_functions->count == 1) in unregister_ftrace_direct()
5234 direct->count--; in unregister_ftrace_direct()
5235 WARN_ON(direct->count < 0); in unregister_ftrace_direct()
5236 if (!direct->count) { in unregister_ftrace_direct()
5237 list_del_rcu(&direct->next); in unregister_ftrace_direct()
5241 ftrace_direct_func_count--; in unregister_ftrace_direct()
5256 * ftrace_modify_direct_caller - modify ftrace nop directly
5259 * @old_addr: The location that the site at @rec->ip currently calls
5260 * @new_addr: The location that the site at @rec->ip should call
5270 * @rec->ip is currently calling @old_addr. And this must
5271 * also update entry->direct to @new_addr.
5278 unsigned long ip = rec->ip; in ftrace_modify_direct_caller()
5309 entry->direct = new_addr; in ftrace_modify_direct_caller()
5325 * modify_ftrace_direct - Modify an existing direct call to call something else
5335 * -ENODEV : the @ip given has no direct caller attached
5336 * -EINVAL : the @old_addr does not match the current direct caller
5344 int ret = -ENODEV; in modify_ftrace_direct()
5353 ret = -EINVAL; in modify_ftrace_direct()
5354 if (entry->direct != old_addr) in modify_ftrace_direct()
5360 if (direct->count > 1) { in modify_ftrace_direct()
5361 ret = -ENOMEM; in modify_ftrace_direct()
5365 direct->count--; in modify_ftrace_direct()
5366 new_direct->count++; in modify_ftrace_direct()
5368 direct->addr = new_addr; in modify_ftrace_direct()
5372 * If there's no other ftrace callback on the rec->ip location, in modify_ftrace_direct()
5380 entry->direct = new_addr; in modify_ftrace_direct()
5385 direct->count++; in modify_ftrace_direct()
5386 list_del_rcu(&new_direct->next); in modify_ftrace_direct()
5389 ftrace_direct_func_count--; in modify_ftrace_direct()
5401 * ftrace_set_filter_ip - set a function to filter on in ftrace by address
5402 * @ops - the ops to set the filter with
5403 * @ip - the address to add to or remove from the filter.
5404 * @remove - non zero to remove the ip from the filter
5405 * @reset - non zero to reset all filters before applying this filter.
5419 * ftrace_ops_set_global_filter - setup ops to use global filters
5420 * @ops - the ops which will use the global filters
5427 if (ops->flags & FTRACE_OPS_FL_INITIALIZED) in ftrace_ops_set_global_filter()
5431 ops->func_hash = &global_ops.local_hash; in ftrace_ops_set_global_filter()
5443 * ftrace_set_filter - set a function to filter on in ftrace
5444 * @ops - the ops to set the filter with
5445 * @buf - the string that holds the function filter text.
5446 * @len - the length of the string.
5447 * @reset - non zero to reset all filters before applying this filter.
5461 * ftrace_set_notrace - set a function to not trace in ftrace
5462 * @ops - the ops to set the notrace filter with
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.
5479 * ftrace_set_global_filter - set a function to filter on with global tracers
5480 * @buf - the string that holds the function filter text.
5481 * @len - the length of the string.
5482 * @reset - non zero to reset all filters before applying this filter.
5494 * ftrace_set_global_notrace - set a function to not trace with global tracers
5495 * @buf - the string that holds the function notrace text.
5496 * @len - the length of the string.
5497 * @reset - non zero to reset all filters before applying this filter.
5618 struct seq_file *m = (struct seq_file *)file->private_data; in ftrace_regex_release()
5624 if (file->f_mode & FMODE_READ) { in ftrace_regex_release()
5625 iter = m->private; in ftrace_regex_release()
5628 iter = file->private_data; in ftrace_regex_release()
5630 parser = &iter->parser; in ftrace_regex_release()
5632 int enable = !(iter->flags & FTRACE_ITER_NOTRACE); in ftrace_regex_release()
5634 ftrace_process_regex(iter, parser->buffer, in ftrace_regex_release()
5635 parser->idx, enable); in ftrace_regex_release()
5640 mutex_lock(&iter->ops->func_hash->regex_lock); in ftrace_regex_release()
5642 if (file->f_mode & FMODE_WRITE) { in ftrace_regex_release()
5643 filter_hash = !!(iter->flags & FTRACE_ITER_FILTER); in ftrace_regex_release()
5646 orig_hash = &iter->ops->func_hash->filter_hash; in ftrace_regex_release()
5647 if (iter->tr && !list_empty(&iter->tr->mod_trace)) in ftrace_regex_release()
5648 iter->hash->flags |= FTRACE_HASH_FL_MOD; in ftrace_regex_release()
5650 orig_hash = &iter->ops->func_hash->notrace_hash; in ftrace_regex_release()
5653 ftrace_hash_move_and_update_ops(iter->ops, orig_hash, in ftrace_regex_release()
5654 iter->hash, filter_hash); in ftrace_regex_release()
5658 iter->hash = NULL; in ftrace_regex_release()
5661 mutex_unlock(&iter->ops->func_hash->regex_lock); in ftrace_regex_release()
5662 free_ftrace_hash(iter->hash); in ftrace_regex_release()
5663 if (iter->tr) in ftrace_regex_release()
5664 trace_array_put(iter->tr); in ftrace_regex_release()
5727 struct ftrace_graph_data *fgd = m->private; in __g_next()
5728 struct ftrace_func_entry *entry = fgd->entry; in __g_next()
5730 int i, idx = fgd->idx; in __g_next()
5732 if (*pos >= fgd->hash->count) in __g_next()
5737 fgd->entry = entry; in __g_next()
5744 for (i = idx; i < 1 << fgd->hash->size_bits; i++) { in __g_next()
5745 head = &fgd->hash->buckets[i]; in __g_next()
5747 fgd->entry = entry; in __g_next()
5748 fgd->idx = i; in __g_next()
5764 struct ftrace_graph_data *fgd = m->private; in g_start()
5768 if (fgd->type == GRAPH_FILTER_FUNCTION) in g_start()
5769 fgd->hash = rcu_dereference_protected(ftrace_graph_hash, in g_start()
5772 fgd->hash = rcu_dereference_protected(ftrace_graph_notrace_hash, in g_start()
5776 if (ftrace_hash_empty(fgd->hash) && !*pos) in g_start()
5779 fgd->idx = 0; in g_start()
5780 fgd->entry = NULL; in g_start()
5797 struct ftrace_graph_data *fgd = m->private; in g_show()
5799 if (fgd->type == GRAPH_FILTER_FUNCTION) in g_show()
5806 seq_printf(m, "%ps\n", (void *)entry->ip); in g_show()
5829 if (file->f_mode & FMODE_WRITE) { in __ftrace_graph_open()
5832 if (trace_parser_get_init(&fgd->parser, FTRACE_BUFF_MAX)) in __ftrace_graph_open()
5833 return -ENOMEM; in __ftrace_graph_open()
5835 if (file->f_flags & O_TRUNC) in __ftrace_graph_open()
5839 fgd->hash); in __ftrace_graph_open()
5841 ret = -ENOMEM; in __ftrace_graph_open()
5846 if (file->f_mode & FMODE_READ) { in __ftrace_graph_open()
5849 struct seq_file *m = file->private_data; in __ftrace_graph_open()
5850 m->private = fgd; in __ftrace_graph_open()
5857 file->private_data = fgd; in __ftrace_graph_open()
5860 if (ret < 0 && file->f_mode & FMODE_WRITE) in __ftrace_graph_open()
5861 trace_parser_put(&fgd->parser); in __ftrace_graph_open()
5863 fgd->new_hash = new_hash; in __ftrace_graph_open()
5866 * All uses of fgd->hash must be taken with the graph_lock in __ftrace_graph_open()
5868 * fgd->hash to be reinitialized when it is taken again. in __ftrace_graph_open()
5870 fgd->hash = NULL; in __ftrace_graph_open()
5882 return -ENODEV; in ftrace_graph_open()
5886 return -ENOMEM; in ftrace_graph_open()
5890 fgd->hash = rcu_dereference_protected(ftrace_graph_hash, in ftrace_graph_open()
5892 fgd->type = GRAPH_FILTER_FUNCTION; in ftrace_graph_open()
5893 fgd->seq_ops = &ftrace_graph_seq_ops; in ftrace_graph_open()
5910 return -ENODEV; in ftrace_graph_notrace_open()
5914 return -ENOMEM; in ftrace_graph_notrace_open()
5918 fgd->hash = rcu_dereference_protected(ftrace_graph_notrace_hash, in ftrace_graph_notrace_open()
5920 fgd->type = GRAPH_FILTER_NOTRACE; in ftrace_graph_notrace_open()
5921 fgd->seq_ops = &ftrace_graph_seq_ops; in ftrace_graph_notrace_open()
5939 if (file->f_mode & FMODE_READ) { in ftrace_graph_release()
5940 struct seq_file *m = file->private_data; in ftrace_graph_release()
5942 fgd = m->private; in ftrace_graph_release()
5945 fgd = file->private_data; in ftrace_graph_release()
5949 if (file->f_mode & FMODE_WRITE) { in ftrace_graph_release()
5951 parser = &fgd->parser; in ftrace_graph_release()
5954 ret = ftrace_graph_set_hash(fgd->new_hash, in ftrace_graph_release()
5955 parser->buffer); in ftrace_graph_release()
5960 new_hash = __ftrace_hash_move(fgd->new_hash); in ftrace_graph_release()
5962 ret = -ENOMEM; in ftrace_graph_release()
5968 if (fgd->type == GRAPH_FILTER_FUNCTION) { in ftrace_graph_release()
5995 free_ftrace_hash(fgd->new_hash); in ftrace_graph_release()
6021 return -ENODEV; in ftrace_graph_set_hash()
6026 if (rec->flags & FTRACE_FL_DISABLED) in ftrace_graph_set_hash()
6030 entry = ftrace_lookup_ip(hash, rec->ip); in ftrace_graph_set_hash()
6037 if (add_hash_entry(hash, rec->ip) < 0) in ftrace_graph_set_hash()
6051 return -EINVAL; in ftrace_graph_set_hash()
6061 struct ftrace_graph_data *fgd = file->private_data; in ftrace_graph_write()
6068 if (file->f_mode & FMODE_READ) { in ftrace_graph_write()
6069 struct seq_file *m = file->private_data; in ftrace_graph_write()
6070 fgd = m->private; in ftrace_graph_write()
6073 parser = &fgd->parser; in ftrace_graph_write()
6080 ret = ftrace_graph_set_hash(fgd->new_hash, in ftrace_graph_write()
6081 parser->buffer); in ftrace_graph_write()
6132 if (ops->flags & FTRACE_OPS_FL_ENABLED) in ftrace_destroy_filter_files()
6134 ops->flags |= FTRACE_OPS_FL_DELETED; in ftrace_destroy_filter_files()
6164 const unsigned long *ipa = a; in ftrace_cmp_ips() local
6167 if (*ipa > *ipb) in ftrace_cmp_ips()
6169 if (*ipa < *ipb) in ftrace_cmp_ips()
6170 return -1; in ftrace_cmp_ips()
6185 int ret = -ENOMEM; in ftrace_process_locs()
6187 count = end - start; in ftrace_process_locs()
6197 return -ENOMEM; in ftrace_process_locs()
6214 if (WARN_ON(ftrace_pages->next)) { in ftrace_process_locs()
6216 while (ftrace_pages->next) in ftrace_process_locs()
6217 ftrace_pages = ftrace_pages->next; in ftrace_process_locs()
6220 ftrace_pages->next = start_pg; in ftrace_process_locs()
6237 end_offset = (pg->index+1) * sizeof(pg->records[0]); in ftrace_process_locs()
6238 if (end_offset > PAGE_SIZE << pg->order) { in ftrace_process_locs()
6240 if (WARN_ON(!pg->next)) in ftrace_process_locs()
6242 pg = pg->next; in ftrace_process_locs()
6245 rec = &pg->records[pg->index++]; in ftrace_process_locs()
6246 rec->ip = addr; in ftrace_process_locs()
6250 WARN_ON(pg->next); in ftrace_process_locs()
6300 if (!op->trampoline || symnum--) in ftrace_get_trampoline_kallsym()
6302 *value = op->trampoline; in ftrace_get_trampoline_kallsym()
6310 return -ERANGE; in ftrace_get_trampoline_kallsym()
6324 for (ops = ftrace_ops_list; ops != &ftrace_list_end; ops = ops->next) { in referenced_filters()
6326 if (WARN_ON_ONCE(ops->flags & FTRACE_OPS_FL_DIRECT)) in referenced_filters()
6328 if (WARN_ON_ONCE(ops->flags & FTRACE_OPS_FL_IPMODIFY)) in referenced_filters()
6331 if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) in referenced_filters()
6332 rec->flags |= FTRACE_FL_REGS; in referenced_filters()
6333 if (cnt == 1 && ops->trampoline) in referenced_filters()
6334 rec->flags |= FTRACE_FL_TRAMP; in referenced_filters()
6336 rec->flags &= ~FTRACE_FL_TRAMP; in referenced_filters()
6353 for (i = 0; i < pg->index; i++) { in clear_mod_from_hash()
6354 rec = &pg->records[i]; in clear_mod_from_hash()
6355 entry = __ftrace_lookup_ip(hash, rec->ip); in clear_mod_from_hash()
6362 entry->ip = 0; in clear_mod_from_hash()
6373 if (!tr->ops || !tr->ops->func_hash) in clear_mod_from_hashes()
6375 mutex_lock(&tr->ops->func_hash->regex_lock); in clear_mod_from_hashes()
6376 clear_mod_from_hash(pg, tr->ops->func_hash->filter_hash); in clear_mod_from_hashes()
6377 clear_mod_from_hash(pg, tr->ops->func_hash->notrace_hash); in clear_mod_from_hashes()
6378 mutex_unlock(&tr->ops->func_hash->regex_lock); in clear_mod_from_hashes()
6390 list_for_each_entry_safe(mod_func, n, &mod_map->funcs, list) { in ftrace_free_mod_map()
6391 kfree(mod_func->name); in ftrace_free_mod_map()
6392 list_del(&mod_func->list); in ftrace_free_mod_map()
6414 if (mod_map->mod == mod) { in ftrace_release_mod()
6415 list_del_rcu(&mod_map->list); in ftrace_release_mod()
6416 call_rcu(&mod_map->rcu, ftrace_free_mod_map); in ftrace_release_mod()
6427 rec = &pg->records[0]; in ftrace_release_mod()
6428 if (within_module_core(rec->ip, mod) || in ftrace_release_mod()
6429 within_module_init(rec->ip, mod)) { in ftrace_release_mod()
6441 ftrace_update_tot_cnt -= pg->index; in ftrace_release_mod()
6442 *last_pg = pg->next; in ftrace_release_mod()
6444 pg->next = tmp_page; in ftrace_release_mod()
6447 last_pg = &pg->next; in ftrace_release_mod()
6457 if (pg->records) { in ftrace_release_mod()
6458 free_pages((unsigned long)pg->records, pg->order); in ftrace_release_mod()
6459 ftrace_number_of_pages -= 1 << pg->order; in ftrace_release_mod()
6461 tmp_page = pg->next; in ftrace_release_mod()
6463 ftrace_number_of_groups--; in ftrace_release_mod()
6487 * text to read-only, as we now need to set it back to read-write in ftrace_module_enable()
6501 if (!within_module_core(rec->ip, mod) && in ftrace_module_enable()
6502 !within_module_init(rec->ip, mod)) in ftrace_module_enable()
6516 rec->flags &= ~FTRACE_FL_DISABLED; in ftrace_module_enable()
6517 rec->flags += cnt; in ftrace_module_enable()
6536 process_cached_mods(mod->name); in ftrace_module_enable()
6541 if (ftrace_disabled || !mod->num_ftrace_callsites) in ftrace_module_init()
6544 ftrace_process_locs(mod, mod->ftrace_callsites, in ftrace_module_init()
6545 mod->ftrace_callsites + mod->num_ftrace_callsites); in ftrace_module_init()
6558 ret = kallsyms_lookup(rec->ip, &symsize, &offset, &modname, str); in save_ftrace_mod_rec()
6566 mod_func->name = kstrdup(str, GFP_KERNEL); in save_ftrace_mod_rec()
6567 if (!mod_func->name) { in save_ftrace_mod_rec()
6572 mod_func->ip = rec->ip - offset; in save_ftrace_mod_rec()
6573 mod_func->size = symsize; in save_ftrace_mod_rec()
6575 mod_map->num_funcs++; in save_ftrace_mod_rec()
6577 list_add_rcu(&mod_func->list, &mod_map->funcs); in save_ftrace_mod_rec()
6590 mod_map->mod = mod; in allocate_ftrace_mod_map()
6591 mod_map->start_addr = start; in allocate_ftrace_mod_map()
6592 mod_map->end_addr = end; in allocate_ftrace_mod_map()
6593 mod_map->num_funcs = 0; in allocate_ftrace_mod_map()
6595 INIT_LIST_HEAD_RCU(&mod_map->funcs); in allocate_ftrace_mod_map()
6597 list_add_rcu(&mod_map->list, &ftrace_mod_maps); in allocate_ftrace_mod_map()
6610 list_for_each_entry_rcu(mod_func, &mod_map->funcs, list) { in ftrace_func_address_lookup()
6611 if (addr >= mod_func->ip && in ftrace_func_address_lookup()
6612 addr < mod_func->ip + mod_func->size) { in ftrace_func_address_lookup()
6620 *size = found_func->size; in ftrace_func_address_lookup()
6622 *off = addr - found_func->ip; in ftrace_func_address_lookup()
6624 strlcpy(sym, found_func->name, KSYM_NAME_LEN); in ftrace_func_address_lookup()
6626 return found_func->name; in ftrace_func_address_lookup()
6645 *modname = mod_map->mod->name; in ftrace_mod_address_lookup()
6665 if (symnum >= mod_map->num_funcs) { in ftrace_mod_get_kallsym()
6666 symnum -= mod_map->num_funcs; in ftrace_mod_get_kallsym()
6670 list_for_each_entry_rcu(mod_func, &mod_map->funcs, list) { in ftrace_mod_get_kallsym()
6672 symnum--; in ftrace_mod_get_kallsym()
6676 *value = mod_func->ip; in ftrace_mod_get_kallsym()
6678 strlcpy(name, mod_func->name, KSYM_NAME_LEN); in ftrace_mod_get_kallsym()
6679 strlcpy(module_name, mod_map->mod->name, MODULE_NAME_LEN); in ftrace_mod_get_kallsym()
6727 entry = ftrace_lookup_ip(hash, func->ip); in clear_func_from_hash()
6734 entry->ip = 0; in clear_func_from_hash()
6744 if (!tr->ops || !tr->ops->func_hash) in clear_func_from_hashes()
6746 mutex_lock(&tr->ops->func_hash->regex_lock); in clear_func_from_hashes()
6747 clear_func_from_hash(func, tr->ops->func_hash->filter_hash); in clear_func_from_hashes()
6748 clear_func_from_hash(func, tr->ops->func_hash->notrace_hash); in clear_func_from_hashes()
6749 mutex_unlock(&tr->ops->func_hash->regex_lock); in clear_func_from_hashes()
6765 func->ip = rec->ip; in add_to_clear_hash_list()
6766 list_add(&func->list, clear_list); in add_to_clear_hash_list()
6796 for (pg = ftrace_pages_start; pg; last_pg = &pg->next, pg = *last_pg) { in ftrace_free_mem()
6797 if (end < pg->records[0].ip || in ftrace_free_mem()
6798 start >= (pg->records[pg->index - 1].ip + MCOUNT_INSN_SIZE)) in ftrace_free_mem()
6801 rec = bsearch(&key, pg->records, pg->index, in ftrace_free_mem()
6813 pg->index--; in ftrace_free_mem()
6814 ftrace_update_tot_cnt--; in ftrace_free_mem()
6815 if (!pg->index) { in ftrace_free_mem()
6816 *last_pg = pg->next; in ftrace_free_mem()
6817 if (pg->records) { in ftrace_free_mem()
6818 free_pages((unsigned long)pg->records, pg->order); in ftrace_free_mem()
6819 ftrace_number_of_pages -= 1 << pg->order; in ftrace_free_mem()
6821 ftrace_number_of_groups--; in ftrace_free_mem()
6829 (pg->index - (rec - pg->records)) * sizeof(*rec)); in ftrace_free_mem()
6862 count = __stop_mcount_loc - __start_mcount_loc; in ftrace_init()
6894 unsigned long trampoline = ops->trampoline; in ftrace_update_trampoline()
6897 if (ops->trampoline && ops->trampoline != trampoline && in ftrace_update_trampoline()
6898 (ops->flags & FTRACE_OPS_FL_ALLOC_TRAMP)) { in ftrace_update_trampoline()
6902 ops->trampoline, ops->trampoline_size, false, in ftrace_update_trampoline()
6908 perf_event_text_poke((void *)ops->trampoline, NULL, 0, in ftrace_update_trampoline()
6909 (void *)ops->trampoline, in ftrace_update_trampoline()
6910 ops->trampoline_size); in ftrace_update_trampoline()
6916 INIT_LIST_HEAD(&tr->func_probes); in ftrace_init_trace_array()
6917 INIT_LIST_HEAD(&tr->mod_trace); in ftrace_init_trace_array()
6918 INIT_LIST_HEAD(&tr->mod_notrace); in ftrace_init_trace_array()
6950 tr->ops = &global_ops; in ftrace_init_global_array_ops()
6951 tr->ops->private = tr; in ftrace_init_global_array_ops()
6958 if (tr->flags & TRACE_ARRAY_FL_GLOBAL) { in ftrace_init_array_ops()
6959 if (WARN_ON(tr->ops->func != ftrace_stub)) in ftrace_init_array_ops()
6961 tr->ops->func); in ftrace_init_array_ops()
6963 tr->ops->func = func; in ftrace_init_array_ops()
6964 tr->ops->private = tr; in ftrace_init_array_ops()
6969 tr->ops->func = ftrace_stub; in ftrace_reset_array_ops()
6992 if (op->flags & FTRACE_OPS_FL_STUB) in __ftrace_ops_list_func()
7001 * If any of the above fails then the op->func() is not executed. in __ftrace_ops_list_func()
7003 if ((!(op->flags & FTRACE_OPS_FL_RCU) || rcu_is_watching()) && in __ftrace_ops_list_func()
7005 if (FTRACE_WARN_ON(!op->func)) { in __ftrace_ops_list_func()
7009 op->func(ip, parent_ip, op, fregs); in __ftrace_ops_list_func()
7061 if (!(op->flags & FTRACE_OPS_FL_RCU) || rcu_is_watching()) in ftrace_ops_assist_func()
7062 op->func(ip, parent_ip, op, fregs); in ftrace_ops_assist_func()
7070 * ftrace_ops_get_func - get the function a trampoline should call
7073 * Normally the mcount trampoline will call the ops->func, but there
7086 if (ops->flags & (FTRACE_OPS_FL_RECURSION | in ftrace_ops_get_func()
7090 return ops->func; in ftrace_ops_get_func()
7101 pid_list = rcu_dereference_sched(tr->function_pids); in ftrace_filter_pid_sched_switch_probe()
7102 no_pid_list = rcu_dereference_sched(tr->function_no_pids); in ftrace_filter_pid_sched_switch_probe()
7105 this_cpu_write(tr->array_buffer.data->ftrace_ignore_pid, in ftrace_filter_pid_sched_switch_probe()
7108 this_cpu_write(tr->array_buffer.data->ftrace_ignore_pid, in ftrace_filter_pid_sched_switch_probe()
7109 next->pid); in ftrace_filter_pid_sched_switch_probe()
7120 pid_list = rcu_dereference_sched(tr->function_pids); in ftrace_pid_follow_sched_process_fork()
7123 pid_list = rcu_dereference_sched(tr->function_no_pids); in ftrace_pid_follow_sched_process_fork()
7133 pid_list = rcu_dereference_sched(tr->function_pids); in ftrace_pid_follow_sched_process_exit()
7136 pid_list = rcu_dereference_sched(tr->function_no_pids); in ftrace_pid_follow_sched_process_exit()
7161 pid_list = rcu_dereference_protected(tr->function_pids, in clear_ftrace_pids()
7163 no_pid_list = rcu_dereference_protected(tr->function_no_pids, in clear_ftrace_pids()
7174 per_cpu_ptr(tr->array_buffer.data, cpu)->ftrace_ignore_pid = FTRACE_PID_TRACE; in clear_ftrace_pids()
7178 rcu_assign_pointer(tr->function_pids, NULL); in clear_ftrace_pids()
7181 rcu_assign_pointer(tr->function_no_pids, NULL); in clear_ftrace_pids()
7220 struct trace_array *tr = m->private; in fpid_start()
7225 pid_list = rcu_dereference_sched(tr->function_pids); in fpid_start()
7235 struct trace_array *tr = m->private; in fpid_next()
7236 struct trace_pid_list *pid_list = rcu_dereference_sched(tr->function_pids); in fpid_next()
7273 struct trace_array *tr = m->private; in fnpid_start()
7278 pid_list = rcu_dereference_sched(tr->function_no_pids); in fnpid_start()
7288 struct trace_array *tr = m->private; in fnpid_next()
7289 struct trace_pid_list *pid_list = rcu_dereference_sched(tr->function_no_pids); in fnpid_next()
7308 struct trace_array *tr = inode->i_private; in pid_open()
7316 if ((file->f_mode & FMODE_WRITE) && in pid_open()
7317 (file->f_flags & O_TRUNC)) in pid_open()
7330 return -EINVAL; in pid_open()
7337 m = file->private_data; in pid_open()
7339 m->private = tr; in pid_open()
7367 pid_list = rcu_dereference_protected(tr->function_pids, in ignore_task_cpu()
7369 no_pid_list = rcu_dereference_protected(tr->function_no_pids, in ignore_task_cpu()
7373 this_cpu_write(tr->array_buffer.data->ftrace_ignore_pid, in ignore_task_cpu()
7376 this_cpu_write(tr->array_buffer.data->ftrace_ignore_pid, in ignore_task_cpu()
7377 current->pid); in ignore_task_cpu()
7384 struct seq_file *m = filp->private_data; in pid_write()
7385 struct trace_array *tr = m->private; in pid_write()
7398 filtered_pids = rcu_dereference_protected(tr->function_pids, in pid_write()
7400 other_pids = rcu_dereference_protected(tr->function_no_pids, in pid_write()
7404 filtered_pids = rcu_dereference_protected(tr->function_no_pids, in pid_write()
7406 other_pids = rcu_dereference_protected(tr->function_pids, in pid_write()
7410 ret = -EINVAL; in pid_write()
7421 rcu_assign_pointer(tr->function_pids, pid_list); in pid_write()
7424 rcu_assign_pointer(tr->function_no_pids, pid_list); in pid_write()
7472 struct trace_array *tr = inode->i_private; in ftrace_pid_release()
7507 WARN_ON(!(tr->flags & TRACE_ARRAY_FL_GLOBAL)); in ftrace_init_tracefs_toplevel()
7514 * ftrace_kill - kill ftrace
7518 * from a non-atomic section, use ftrace_kill.
7528 * ftrace_is_dead - Test if ftrace is dead or not.
7538 * register_ftrace_function - register a function for profiling
7539 * @ops - ops structure that holds the function for profiling.
7544 * Note: @ops->func and all the functions it calls must be labeled
7565 * unregister_ftrace_function - unregister a function for profiling.
7566 * @ops - ops structure that holds the function to unregister
7587 if (op->flags & FTRACE_OPS_FL_PERMANENT) in is_permanent_ops_registered()
7598 int ret = -ENODEV; in ftrace_enable_sysctl()
7622 ret = -EBUSY; in ftrace_enable_sysctl()