Lines Matching refs:p
379 struct kprobe *p; in get_kprobe() local
382 hlist_for_each_entry_rcu(p, head, hlist, in get_kprobe()
384 if (p->addr == addr) in get_kprobe()
385 return p; in get_kprobe()
392 static int aggr_pre_handler(struct kprobe *p, struct pt_regs *regs);
395 static inline bool kprobe_aggrprobe(struct kprobe *p) in kprobe_aggrprobe() argument
397 return p->pre_handler == aggr_pre_handler; in kprobe_aggrprobe()
401 static inline bool kprobe_unused(struct kprobe *p) in kprobe_unused() argument
403 return kprobe_aggrprobe(p) && kprobe_disabled(p) && in kprobe_unused()
404 list_empty(&p->list); in kprobe_unused()
408 static inline void copy_kprobe(struct kprobe *ap, struct kprobe *p) in copy_kprobe() argument
410 memcpy(&p->opcode, &ap->opcode, sizeof(kprobe_opcode_t)); in copy_kprobe()
411 memcpy(&p->ainsn, &ap->ainsn, sizeof(struct arch_specific_insn)); in copy_kprobe()
422 void opt_pre_handler(struct kprobe *p, struct pt_regs *regs) in opt_pre_handler() argument
426 list_for_each_entry_rcu(kp, &p->list, list) { in opt_pre_handler()
437 static void free_aggr_kprobe(struct kprobe *p) in free_aggr_kprobe() argument
441 op = container_of(p, struct optimized_kprobe, kp); in free_aggr_kprobe()
443 arch_remove_kprobe(p); in free_aggr_kprobe()
448 static inline int kprobe_optready(struct kprobe *p) in kprobe_optready() argument
452 if (kprobe_aggrprobe(p)) { in kprobe_optready()
453 op = container_of(p, struct optimized_kprobe, kp); in kprobe_optready()
461 bool kprobe_disarmed(struct kprobe *p) in kprobe_disarmed() argument
466 if (!kprobe_aggrprobe(p)) in kprobe_disarmed()
467 return kprobe_disabled(p); in kprobe_disarmed()
469 op = container_of(p, struct optimized_kprobe, kp); in kprobe_disarmed()
471 return kprobe_disabled(p) && list_empty(&op->list); in kprobe_disarmed()
475 static bool kprobe_queued(struct kprobe *p) in kprobe_queued() argument
479 if (kprobe_aggrprobe(p)) { in kprobe_queued()
480 op = container_of(p, struct optimized_kprobe, kp); in kprobe_queued()
494 struct kprobe *p = NULL; in get_optimized_kprobe() local
498 for (i = 1; !p && i < MAX_OPTIMIZED_LENGTH / sizeof(kprobe_opcode_t); i++) in get_optimized_kprobe()
499 p = get_kprobe(addr - i); in get_optimized_kprobe()
501 if (p && kprobe_optready(p)) { in get_optimized_kprobe()
502 op = container_of(p, struct optimized_kprobe, kp); in get_optimized_kprobe()
504 return p; in get_optimized_kprobe()
676 static void optimize_kprobe(struct kprobe *p) in optimize_kprobe() argument
681 if (!kprobe_optready(p) || !kprobes_allow_optimization || in optimize_kprobe()
682 (kprobe_disabled(p) || kprobes_all_disarmed)) in optimize_kprobe()
686 if (p->post_handler) in optimize_kprobe()
689 op = container_of(p, struct optimized_kprobe, kp); in optimize_kprobe()
725 static void unoptimize_kprobe(struct kprobe *p, bool force) in unoptimize_kprobe() argument
729 if (!kprobe_aggrprobe(p) || kprobe_disarmed(p)) in unoptimize_kprobe()
732 op = container_of(p, struct optimized_kprobe, kp); in unoptimize_kprobe()
733 if (!kprobe_optimized(p)) in unoptimize_kprobe()
787 static void kill_optimized_kprobe(struct kprobe *p) in kill_optimized_kprobe() argument
791 op = container_of(p, struct optimized_kprobe, kp); in kill_optimized_kprobe()
797 if (kprobe_unused(p)) { in kill_optimized_kprobe()
812 void __prepare_optimized_kprobe(struct optimized_kprobe *op, struct kprobe *p) in __prepare_optimized_kprobe() argument
814 if (!kprobe_ftrace(p)) in __prepare_optimized_kprobe()
815 arch_prepare_optimized_kprobe(op, p); in __prepare_optimized_kprobe()
819 static void prepare_optimized_kprobe(struct kprobe *p) in prepare_optimized_kprobe() argument
823 op = container_of(p, struct optimized_kprobe, kp); in prepare_optimized_kprobe()
824 __prepare_optimized_kprobe(op, p); in prepare_optimized_kprobe()
828 static struct kprobe *alloc_aggr_kprobe(struct kprobe *p) in alloc_aggr_kprobe() argument
837 op->kp.addr = p->addr; in alloc_aggr_kprobe()
838 __prepare_optimized_kprobe(op, p); in alloc_aggr_kprobe()
843 static void init_aggr_kprobe(struct kprobe *ap, struct kprobe *p);
849 static void try_to_optimize_kprobe(struct kprobe *p) in try_to_optimize_kprobe() argument
855 if (kprobe_ftrace(p)) in try_to_optimize_kprobe()
863 ap = alloc_aggr_kprobe(p); in try_to_optimize_kprobe()
875 init_aggr_kprobe(ap, p); in try_to_optimize_kprobe()
887 struct kprobe *p; in optimize_all_kprobes() local
899 hlist_for_each_entry(p, head, hlist) in optimize_all_kprobes()
900 if (!kprobe_disabled(p)) in optimize_all_kprobes()
901 optimize_kprobe(p); in optimize_all_kprobes()
913 struct kprobe *p; in unoptimize_all_kprobes() local
927 hlist_for_each_entry(p, head, hlist) { in unoptimize_all_kprobes()
928 if (!kprobe_disabled(p)) in unoptimize_all_kprobes()
929 unoptimize_kprobe(p, false); in unoptimize_all_kprobes()
981 static void __arm_kprobe(struct kprobe *p) in __arm_kprobe() argument
988 _p = get_optimized_kprobe(p->addr); in __arm_kprobe()
993 arch_arm_kprobe(p); in __arm_kprobe()
994 optimize_kprobe(p); /* Try to optimize (add kprobe to a list) */ in __arm_kprobe()
998 static void __disarm_kprobe(struct kprobe *p, bool reopt) in __disarm_kprobe() argument
1005 unoptimize_kprobe(p, kprobes_all_disarmed); in __disarm_kprobe()
1007 if (!kprobe_queued(p)) { in __disarm_kprobe()
1008 arch_disarm_kprobe(p); in __disarm_kprobe()
1010 _p = get_optimized_kprobe(p->addr); in __disarm_kprobe()
1024 #define optimize_kprobe(p) do {} while (0) argument
1025 #define unoptimize_kprobe(p, f) do {} while (0) argument
1026 #define kill_optimized_kprobe(p) do {} while (0) argument
1027 #define prepare_optimized_kprobe(p) do {} while (0) argument
1028 #define try_to_optimize_kprobe(p) do {} while (0) argument
1029 #define __arm_kprobe(p) arch_arm_kprobe(p) argument
1030 #define __disarm_kprobe(p, o) arch_disarm_kprobe(p) argument
1031 #define kprobe_disarmed(p) kprobe_disabled(p) argument
1046 static void free_aggr_kprobe(struct kprobe *p) in free_aggr_kprobe() argument
1048 arch_remove_kprobe(p); in free_aggr_kprobe()
1049 kfree(p); in free_aggr_kprobe()
1052 static struct kprobe *alloc_aggr_kprobe(struct kprobe *p) in alloc_aggr_kprobe() argument
1073 static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, in __arm_kprobe_ftrace() argument
1080 ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 0, 0); in __arm_kprobe_ftrace()
1081 if (WARN_ONCE(ret < 0, "Failed to arm kprobe-ftrace at %pS (error %d)\n", p->addr, ret)) in __arm_kprobe_ftrace()
1098 ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0); in __arm_kprobe_ftrace()
1102 static int arm_kprobe_ftrace(struct kprobe *p) in arm_kprobe_ftrace() argument
1104 bool ipmodify = (p->post_handler != NULL); in arm_kprobe_ftrace()
1106 return __arm_kprobe_ftrace(p, in arm_kprobe_ftrace()
1111 static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, in __disarm_kprobe_ftrace() argument
1126 ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0); in __disarm_kprobe_ftrace()
1128 p->addr, ret); in __disarm_kprobe_ftrace()
1132 static int disarm_kprobe_ftrace(struct kprobe *p) in disarm_kprobe_ftrace() argument
1134 bool ipmodify = (p->post_handler != NULL); in disarm_kprobe_ftrace()
1136 return __disarm_kprobe_ftrace(p, in disarm_kprobe_ftrace()
1146 static inline int arm_kprobe_ftrace(struct kprobe *p) in arm_kprobe_ftrace() argument
1151 static inline int disarm_kprobe_ftrace(struct kprobe *p) in disarm_kprobe_ftrace() argument
1157 static int prepare_kprobe(struct kprobe *p) in prepare_kprobe() argument
1160 if (kprobe_ftrace(p)) in prepare_kprobe()
1161 return arch_prepare_kprobe_ftrace(p); in prepare_kprobe()
1163 return arch_prepare_kprobe(p); in prepare_kprobe()
1198 static int aggr_pre_handler(struct kprobe *p, struct pt_regs *regs) in aggr_pre_handler() argument
1202 list_for_each_entry_rcu(kp, &p->list, list) { in aggr_pre_handler()
1214 static void aggr_post_handler(struct kprobe *p, struct pt_regs *regs, in aggr_post_handler() argument
1219 list_for_each_entry_rcu(kp, &p->list, list) { in aggr_post_handler()
1230 void kprobes_inc_nmissed_count(struct kprobe *p) in kprobes_inc_nmissed_count() argument
1234 if (!kprobe_aggrprobe(p)) { in kprobes_inc_nmissed_count()
1235 p->nmissed++; in kprobes_inc_nmissed_count()
1237 list_for_each_entry_rcu(kp, &p->list, list) in kprobes_inc_nmissed_count()
1264 static int add_new_kprobe(struct kprobe *ap, struct kprobe *p) in add_new_kprobe() argument
1266 if (p->post_handler) in add_new_kprobe()
1269 list_add_rcu(&p->list, &ap->list); in add_new_kprobe()
1270 if (p->post_handler && !ap->post_handler) in add_new_kprobe()
1280 static void init_aggr_kprobe(struct kprobe *ap, struct kprobe *p) in init_aggr_kprobe() argument
1283 copy_kprobe(p, ap); in init_aggr_kprobe()
1285 ap->addr = p->addr; in init_aggr_kprobe()
1286 ap->flags = p->flags & ~KPROBE_FLAG_OPTIMIZED; in init_aggr_kprobe()
1289 if (p->post_handler && !kprobe_gone(p)) in init_aggr_kprobe()
1295 list_add_rcu(&p->list, &ap->list); in init_aggr_kprobe()
1296 hlist_replace_rcu(&p->hlist, &ap->hlist); in init_aggr_kprobe()
1302 static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p) in register_aggr_kprobe() argument
1356 copy_kprobe(ap, p); in register_aggr_kprobe()
1357 ret = add_new_kprobe(ap, p); in register_aggr_kprobe()
1364 if (ret == 0 && kprobe_disabled(ap) && !kprobe_disabled(p)) { in register_aggr_kprobe()
1371 list_del_rcu(&p->list); in register_aggr_kprobe()
1405 char symname[KSYM_NAME_LEN], *p; in within_kprobe_blacklist() local
1412 p = strchr(symname, '.'); in within_kprobe_blacklist()
1413 if (!p) in within_kprobe_blacklist()
1415 *p = '\0'; in within_kprobe_blacklist()
1493 static kprobe_opcode_t *kprobe_addr(struct kprobe *p) in kprobe_addr() argument
1496 return _kprobe_addr(p->addr, p->symbol_name, p->offset, &on_func_entry); in kprobe_addr()
1503 static struct kprobe *__get_valid_kprobe(struct kprobe *p) in __get_valid_kprobe() argument
1509 ap = get_kprobe(p->addr); in __get_valid_kprobe()
1513 if (p != ap) { in __get_valid_kprobe()
1515 if (list_p == p) in __get_valid_kprobe()
1528 static inline int warn_kprobe_rereg(struct kprobe *p) in warn_kprobe_rereg() argument
1533 if (WARN_ON_ONCE(__get_valid_kprobe(p))) in warn_kprobe_rereg()
1540 static int check_ftrace_location(struct kprobe *p) in check_ftrace_location() argument
1542 unsigned long addr = (unsigned long)p->addr; in check_ftrace_location()
1546 p->flags |= KPROBE_FLAG_FTRACE; in check_ftrace_location()
1565 static int check_kprobe_address_safe(struct kprobe *p, in check_kprobe_address_safe() argument
1570 ret = check_ftrace_location(p); in check_kprobe_address_safe()
1578 if (!core_kernel_text((unsigned long) p->addr)) { in check_kprobe_address_safe()
1579 *probed_mod = __module_text_address((unsigned long) p->addr); in check_kprobe_address_safe()
1586 if (in_gate_area_no_mm((unsigned long) p->addr) || in check_kprobe_address_safe()
1587 within_kprobe_blacklist((unsigned long) p->addr) || in check_kprobe_address_safe()
1588 jump_label_text_reserved(p->addr, p->addr) || in check_kprobe_address_safe()
1589 static_call_text_reserved(p->addr, p->addr) || in check_kprobe_address_safe()
1590 find_bug((unsigned long)p->addr) || in check_kprobe_address_safe()
1591 is_cfi_preamble_symbol((unsigned long)p->addr)) { in check_kprobe_address_safe()
1611 if (within_module_init((unsigned long)p->addr, *probed_mod) && in check_kprobe_address_safe()
1625 int register_kprobe(struct kprobe *p) in register_kprobe() argument
1634 addr = _kprobe_addr(p->addr, p->symbol_name, p->offset, &on_func_entry); in register_kprobe()
1637 p->addr = addr; in register_kprobe()
1639 ret = warn_kprobe_rereg(p); in register_kprobe()
1644 p->flags &= KPROBE_FLAG_DISABLED; in register_kprobe()
1645 p->nmissed = 0; in register_kprobe()
1646 INIT_LIST_HEAD(&p->list); in register_kprobe()
1648 ret = check_kprobe_address_safe(p, &probed_mod); in register_kprobe()
1655 p->flags |= KPROBE_FLAG_ON_FUNC_ENTRY; in register_kprobe()
1657 old_p = get_kprobe(p->addr); in register_kprobe()
1660 ret = register_aggr_kprobe(old_p, p); in register_kprobe()
1667 ret = prepare_kprobe(p); in register_kprobe()
1673 INIT_HLIST_NODE(&p->hlist); in register_kprobe()
1674 hlist_add_head_rcu(&p->hlist, in register_kprobe()
1675 &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]); in register_kprobe()
1677 if (!kprobes_all_disarmed && !kprobe_disabled(p)) { in register_kprobe()
1678 ret = arm_kprobe(p); in register_kprobe()
1680 hlist_del_rcu(&p->hlist); in register_kprobe()
1687 try_to_optimize_kprobe(p); in register_kprobe()
1716 static struct kprobe *__disable_kprobe(struct kprobe *p) in __disable_kprobe() argument
1724 orig_p = __get_valid_kprobe(p); in __disable_kprobe()
1728 if (!kprobe_disabled(p)) { in __disable_kprobe()
1730 if (p != orig_p) in __disable_kprobe()
1731 p->flags |= KPROBE_FLAG_DISABLED; in __disable_kprobe()
1734 if (p == orig_p || aggr_kprobe_disabled(orig_p)) { in __disable_kprobe()
1744 p->flags &= ~KPROBE_FLAG_DISABLED; in __disable_kprobe()
1758 static int __unregister_kprobe_top(struct kprobe *p) in __unregister_kprobe_top() argument
1763 ap = __disable_kprobe(p); in __unregister_kprobe_top()
1767 if (ap == p) in __unregister_kprobe_top()
1785 if (p->post_handler && !kprobe_gone(p)) { in __unregister_kprobe_top()
1787 if ((list_p != p) && (list_p->post_handler)) in __unregister_kprobe_top()
1803 list_del_rcu(&p->list); in __unregister_kprobe_top()
1818 static void __unregister_kprobe_bottom(struct kprobe *p) in __unregister_kprobe_bottom() argument
1822 if (list_empty(&p->list)) in __unregister_kprobe_bottom()
1824 arch_remove_kprobe(p); in __unregister_kprobe_bottom()
1825 else if (list_is_singular(&p->list)) { in __unregister_kprobe_bottom()
1827 ap = list_entry(p->list.next, struct kprobe, list); in __unregister_kprobe_bottom()
1828 list_del(&p->list); in __unregister_kprobe_bottom()
1852 void unregister_kprobe(struct kprobe *p) in unregister_kprobe() argument
1854 unregister_kprobes(&p, 1); in unregister_kprobe()
2099 static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs) in NOKPROBE_SYMBOL()
2101 struct kretprobe *rp = container_of(p, struct kretprobe, kp); in NOKPROBE_SYMBOL()
2130 static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs) in pre_handler_kretprobe() argument
2132 struct kretprobe *rp = container_of(p, struct kretprobe, kp); in pre_handler_kretprobe()
2147 rethook_hook(rhn, regs, kprobe_ftrace(p)); in pre_handler_kretprobe()
2368 static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs) in pre_handler_kretprobe() argument
2377 static void kill_kprobe(struct kprobe *p) in kill_kprobe() argument
2388 if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed) in kill_kprobe()
2389 disarm_kprobe_ftrace(p); in kill_kprobe()
2391 p->flags |= KPROBE_FLAG_GONE; in kill_kprobe()
2392 if (kprobe_aggrprobe(p)) { in kill_kprobe()
2397 list_for_each_entry(kp, &p->list, list) in kill_kprobe()
2399 p->post_handler = NULL; in kill_kprobe()
2400 kill_optimized_kprobe(p); in kill_kprobe()
2406 arch_remove_kprobe(p); in kill_kprobe()
2413 struct kprobe *p; in disable_kprobe() local
2418 p = __disable_kprobe(kp); in disable_kprobe()
2419 if (IS_ERR(p)) in disable_kprobe()
2420 ret = PTR_ERR(p); in disable_kprobe()
2431 struct kprobe *p; in enable_kprobe() local
2436 p = __get_valid_kprobe(kp); in enable_kprobe()
2437 if (unlikely(p == NULL)) { in enable_kprobe()
2448 if (p != kp) in enable_kprobe()
2451 if (!kprobes_all_disarmed && kprobe_disabled(p)) { in enable_kprobe()
2452 p->flags &= ~KPROBE_FLAG_DISABLED; in enable_kprobe()
2453 ret = arm_kprobe(p); in enable_kprobe()
2455 p->flags |= KPROBE_FLAG_DISABLED; in enable_kprobe()
2456 if (p != kp) in enable_kprobe()
2644 struct kprobe *p; in kprobes_module_callback() local
2665 hlist_for_each_entry(p, head, hlist) in kprobes_module_callback()
2666 if (within_module_init((unsigned long)p->addr, mod) || in kprobes_module_callback()
2668 within_module_core((unsigned long)p->addr, mod))) { in kprobes_module_callback()
2680 kill_kprobe(p); in kprobes_module_callback()
2699 struct kprobe *p; in kprobe_free_init_mem() local
2707 hlist_for_each_entry(p, head, hlist) { in kprobe_free_init_mem()
2708 if (start <= (void *)p->addr && (void *)p->addr < end) in kprobe_free_init_mem()
2709 kill_kprobe(p); in kprobe_free_init_mem()
2777 static void report_probe(struct seq_file *pi, struct kprobe *p, in report_probe() argument
2781 void *addr = p->addr; in report_probe()
2783 if (p->pre_handler == pre_handler_kretprobe) in report_probe()
2797 addr, kprobe_type, p->addr); in report_probe()
2800 pp = p; in report_probe()
2802 (kprobe_gone(p) ? "[GONE]" : ""), in report_probe()
2803 ((kprobe_disabled(p) && !kprobe_gone(p)) ? "[DISABLED]" : ""), in report_probe()
2829 struct kprobe *p, *kp; in show_kprobe_addr() local
2837 hlist_for_each_entry_rcu(p, head, hlist) { in show_kprobe_addr()
2838 sym = kallsyms_lookup((unsigned long)p->addr, NULL, in show_kprobe_addr()
2840 if (kprobe_aggrprobe(p)) { in show_kprobe_addr()
2841 list_for_each_entry_rcu(kp, &p->list, list) in show_kprobe_addr()
2842 report_probe(pi, kp, sym, offset, modname, p); in show_kprobe_addr()
2844 report_probe(pi, p, sym, offset, modname, NULL); in show_kprobe_addr()
2905 struct kprobe *p; in arm_all_kprobes() local
2925 hlist_for_each_entry(p, head, hlist) { in arm_all_kprobes()
2926 if (!kprobe_disabled(p)) { in arm_all_kprobes()
2927 err = arm_kprobe(p); in arm_all_kprobes()
2951 struct kprobe *p; in disarm_all_kprobes() local
2968 hlist_for_each_entry(p, head, hlist) { in disarm_all_kprobes()
2969 if (!arch_trampoline_kprobe(p) && !kprobe_disabled(p)) { in disarm_all_kprobes()
2970 err = disarm_kprobe(p, false); in disarm_all_kprobes()