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
1072 static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, in __arm_kprobe_ftrace() argument
1079 ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 0, 0); in __arm_kprobe_ftrace()
1080 if (WARN_ONCE(ret < 0, "Failed to arm kprobe-ftrace at %pS (error %d)\n", p->addr, ret)) in __arm_kprobe_ftrace()
1097 ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0); in __arm_kprobe_ftrace()
1101 static int arm_kprobe_ftrace(struct kprobe *p) in arm_kprobe_ftrace() argument
1103 bool ipmodify = (p->post_handler != NULL); in arm_kprobe_ftrace()
1105 return __arm_kprobe_ftrace(p, in arm_kprobe_ftrace()
1110 static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, in __disarm_kprobe_ftrace() argument
1125 ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0); in __disarm_kprobe_ftrace()
1127 p->addr, ret); in __disarm_kprobe_ftrace()
1131 static int disarm_kprobe_ftrace(struct kprobe *p) in disarm_kprobe_ftrace() argument
1133 bool ipmodify = (p->post_handler != NULL); in disarm_kprobe_ftrace()
1135 return __disarm_kprobe_ftrace(p, in disarm_kprobe_ftrace()
1140 static inline int arm_kprobe_ftrace(struct kprobe *p) in arm_kprobe_ftrace() argument
1145 static inline int disarm_kprobe_ftrace(struct kprobe *p) in disarm_kprobe_ftrace() argument
1151 static int prepare_kprobe(struct kprobe *p) in prepare_kprobe() argument
1154 if (kprobe_ftrace(p)) in prepare_kprobe()
1155 return arch_prepare_kprobe_ftrace(p); in prepare_kprobe()
1157 return arch_prepare_kprobe(p); in prepare_kprobe()
1192 static int aggr_pre_handler(struct kprobe *p, struct pt_regs *regs) in aggr_pre_handler() argument
1196 list_for_each_entry_rcu(kp, &p->list, list) { in aggr_pre_handler()
1208 static void aggr_post_handler(struct kprobe *p, struct pt_regs *regs, in aggr_post_handler() argument
1213 list_for_each_entry_rcu(kp, &p->list, list) { in aggr_post_handler()
1224 void kprobes_inc_nmissed_count(struct kprobe *p) in kprobes_inc_nmissed_count() argument
1228 if (!kprobe_aggrprobe(p)) { in kprobes_inc_nmissed_count()
1229 p->nmissed++; in kprobes_inc_nmissed_count()
1231 list_for_each_entry_rcu(kp, &p->list, list) in kprobes_inc_nmissed_count()
1258 static int add_new_kprobe(struct kprobe *ap, struct kprobe *p) in add_new_kprobe() argument
1260 if (p->post_handler) in add_new_kprobe()
1263 list_add_rcu(&p->list, &ap->list); in add_new_kprobe()
1264 if (p->post_handler && !ap->post_handler) in add_new_kprobe()
1274 static void init_aggr_kprobe(struct kprobe *ap, struct kprobe *p) in init_aggr_kprobe() argument
1277 copy_kprobe(p, ap); in init_aggr_kprobe()
1279 ap->addr = p->addr; in init_aggr_kprobe()
1280 ap->flags = p->flags & ~KPROBE_FLAG_OPTIMIZED; in init_aggr_kprobe()
1283 if (p->post_handler && !kprobe_gone(p)) in init_aggr_kprobe()
1289 list_add_rcu(&p->list, &ap->list); in init_aggr_kprobe()
1290 hlist_replace_rcu(&p->hlist, &ap->hlist); in init_aggr_kprobe()
1296 static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p) in register_aggr_kprobe() argument
1350 copy_kprobe(ap, p); in register_aggr_kprobe()
1351 ret = add_new_kprobe(ap, p); in register_aggr_kprobe()
1358 if (ret == 0 && kprobe_disabled(ap) && !kprobe_disabled(p)) { in register_aggr_kprobe()
1365 list_del_rcu(&p->list); in register_aggr_kprobe()
1399 char symname[KSYM_NAME_LEN], *p; in within_kprobe_blacklist() local
1406 p = strchr(symname, '.'); in within_kprobe_blacklist()
1407 if (!p) in within_kprobe_blacklist()
1409 *p = '\0'; in within_kprobe_blacklist()
1487 static kprobe_opcode_t *kprobe_addr(struct kprobe *p) in kprobe_addr() argument
1490 return _kprobe_addr(p->addr, p->symbol_name, p->offset, &on_func_entry); in kprobe_addr()
1497 static struct kprobe *__get_valid_kprobe(struct kprobe *p) in __get_valid_kprobe() argument
1503 ap = get_kprobe(p->addr); in __get_valid_kprobe()
1507 if (p != ap) { in __get_valid_kprobe()
1509 if (list_p == p) in __get_valid_kprobe()
1522 static inline int warn_kprobe_rereg(struct kprobe *p) in warn_kprobe_rereg() argument
1527 if (WARN_ON_ONCE(__get_valid_kprobe(p))) in warn_kprobe_rereg()
1534 static int check_ftrace_location(struct kprobe *p) in check_ftrace_location() argument
1536 unsigned long addr = (unsigned long)p->addr; in check_ftrace_location()
1540 p->flags |= KPROBE_FLAG_FTRACE; in check_ftrace_location()
1559 static int check_kprobe_address_safe(struct kprobe *p, in check_kprobe_address_safe() argument
1564 ret = check_ftrace_location(p); in check_kprobe_address_safe()
1571 if (!(core_kernel_text((unsigned long) p->addr) || in check_kprobe_address_safe()
1572 is_module_text_address((unsigned long) p->addr)) || in check_kprobe_address_safe()
1573 in_gate_area_no_mm((unsigned long) p->addr) || in check_kprobe_address_safe()
1574 within_kprobe_blacklist((unsigned long) p->addr) || in check_kprobe_address_safe()
1575 jump_label_text_reserved(p->addr, p->addr) || in check_kprobe_address_safe()
1576 static_call_text_reserved(p->addr, p->addr) || in check_kprobe_address_safe()
1577 find_bug((unsigned long)p->addr) || in check_kprobe_address_safe()
1578 is_cfi_preamble_symbol((unsigned long)p->addr)) { in check_kprobe_address_safe()
1584 *probed_mod = __module_text_address((unsigned long) p->addr); in check_kprobe_address_safe()
1599 if (within_module_init((unsigned long)p->addr, *probed_mod) && in check_kprobe_address_safe()
1613 int register_kprobe(struct kprobe *p) in register_kprobe() argument
1622 addr = _kprobe_addr(p->addr, p->symbol_name, p->offset, &on_func_entry); in register_kprobe()
1625 p->addr = addr; in register_kprobe()
1627 ret = warn_kprobe_rereg(p); in register_kprobe()
1632 p->flags &= KPROBE_FLAG_DISABLED; in register_kprobe()
1633 p->nmissed = 0; in register_kprobe()
1634 INIT_LIST_HEAD(&p->list); in register_kprobe()
1636 ret = check_kprobe_address_safe(p, &probed_mod); in register_kprobe()
1643 p->flags |= KPROBE_FLAG_ON_FUNC_ENTRY; in register_kprobe()
1645 old_p = get_kprobe(p->addr); in register_kprobe()
1648 ret = register_aggr_kprobe(old_p, p); in register_kprobe()
1655 ret = prepare_kprobe(p); in register_kprobe()
1661 INIT_HLIST_NODE(&p->hlist); in register_kprobe()
1662 hlist_add_head_rcu(&p->hlist, in register_kprobe()
1663 &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]); in register_kprobe()
1665 if (!kprobes_all_disarmed && !kprobe_disabled(p)) { in register_kprobe()
1666 ret = arm_kprobe(p); in register_kprobe()
1668 hlist_del_rcu(&p->hlist); in register_kprobe()
1675 try_to_optimize_kprobe(p); in register_kprobe()
1704 static struct kprobe *__disable_kprobe(struct kprobe *p) in __disable_kprobe() argument
1712 orig_p = __get_valid_kprobe(p); in __disable_kprobe()
1716 if (!kprobe_disabled(p)) { in __disable_kprobe()
1718 if (p != orig_p) in __disable_kprobe()
1719 p->flags |= KPROBE_FLAG_DISABLED; in __disable_kprobe()
1722 if (p == orig_p || aggr_kprobe_disabled(orig_p)) { in __disable_kprobe()
1732 p->flags &= ~KPROBE_FLAG_DISABLED; in __disable_kprobe()
1746 static int __unregister_kprobe_top(struct kprobe *p) in __unregister_kprobe_top() argument
1751 ap = __disable_kprobe(p); in __unregister_kprobe_top()
1755 if (ap == p) in __unregister_kprobe_top()
1773 if (p->post_handler && !kprobe_gone(p)) { in __unregister_kprobe_top()
1775 if ((list_p != p) && (list_p->post_handler)) in __unregister_kprobe_top()
1791 list_del_rcu(&p->list); in __unregister_kprobe_top()
1806 static void __unregister_kprobe_bottom(struct kprobe *p) in __unregister_kprobe_bottom() argument
1810 if (list_empty(&p->list)) in __unregister_kprobe_bottom()
1812 arch_remove_kprobe(p); in __unregister_kprobe_bottom()
1813 else if (list_is_singular(&p->list)) { in __unregister_kprobe_bottom()
1815 ap = list_entry(p->list.next, struct kprobe, list); in __unregister_kprobe_bottom()
1816 list_del(&p->list); in __unregister_kprobe_bottom()
1840 void unregister_kprobe(struct kprobe *p) in unregister_kprobe() argument
1842 unregister_kprobes(&p, 1); in unregister_kprobe()
2087 static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs) in NOKPROBE_SYMBOL()
2089 struct kretprobe *rp = container_of(p, struct kretprobe, kp); in NOKPROBE_SYMBOL()
2118 static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs) in pre_handler_kretprobe() argument
2120 struct kretprobe *rp = container_of(p, struct kretprobe, kp); in pre_handler_kretprobe()
2135 rethook_hook(rhn, regs, kprobe_ftrace(p)); in pre_handler_kretprobe()
2357 static int pre_handler_kretprobe(struct kprobe *p, struct pt_regs *regs) in pre_handler_kretprobe() argument
2366 static void kill_kprobe(struct kprobe *p) in kill_kprobe() argument
2377 if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed) in kill_kprobe()
2378 disarm_kprobe_ftrace(p); in kill_kprobe()
2380 p->flags |= KPROBE_FLAG_GONE; in kill_kprobe()
2381 if (kprobe_aggrprobe(p)) { in kill_kprobe()
2386 list_for_each_entry(kp, &p->list, list) in kill_kprobe()
2388 p->post_handler = NULL; in kill_kprobe()
2389 kill_optimized_kprobe(p); in kill_kprobe()
2395 arch_remove_kprobe(p); in kill_kprobe()
2402 struct kprobe *p; in disable_kprobe() local
2407 p = __disable_kprobe(kp); in disable_kprobe()
2408 if (IS_ERR(p)) in disable_kprobe()
2409 ret = PTR_ERR(p); in disable_kprobe()
2420 struct kprobe *p; in enable_kprobe() local
2425 p = __get_valid_kprobe(kp); in enable_kprobe()
2426 if (unlikely(p == NULL)) { in enable_kprobe()
2437 if (p != kp) in enable_kprobe()
2440 if (!kprobes_all_disarmed && kprobe_disabled(p)) { in enable_kprobe()
2441 p->flags &= ~KPROBE_FLAG_DISABLED; in enable_kprobe()
2442 ret = arm_kprobe(p); in enable_kprobe()
2444 p->flags |= KPROBE_FLAG_DISABLED; in enable_kprobe()
2445 if (p != kp) in enable_kprobe()
2633 struct kprobe *p; in kprobes_module_callback() local
2654 hlist_for_each_entry(p, head, hlist) in kprobes_module_callback()
2655 if (within_module_init((unsigned long)p->addr, mod) || in kprobes_module_callback()
2657 within_module_core((unsigned long)p->addr, mod))) { in kprobes_module_callback()
2669 kill_kprobe(p); in kprobes_module_callback()
2688 struct kprobe *p; in kprobe_free_init_mem() local
2696 hlist_for_each_entry(p, head, hlist) { in kprobe_free_init_mem()
2697 if (start <= (void *)p->addr && (void *)p->addr < end) in kprobe_free_init_mem()
2698 kill_kprobe(p); in kprobe_free_init_mem()
2766 static void report_probe(struct seq_file *pi, struct kprobe *p, in report_probe() argument
2770 void *addr = p->addr; in report_probe()
2772 if (p->pre_handler == pre_handler_kretprobe) in report_probe()
2786 addr, kprobe_type, p->addr); in report_probe()
2789 pp = p; in report_probe()
2791 (kprobe_gone(p) ? "[GONE]" : ""), in report_probe()
2792 ((kprobe_disabled(p) && !kprobe_gone(p)) ? "[DISABLED]" : ""), in report_probe()
2818 struct kprobe *p, *kp; in show_kprobe_addr() local
2826 hlist_for_each_entry_rcu(p, head, hlist) { in show_kprobe_addr()
2827 sym = kallsyms_lookup((unsigned long)p->addr, NULL, in show_kprobe_addr()
2829 if (kprobe_aggrprobe(p)) { in show_kprobe_addr()
2830 list_for_each_entry_rcu(kp, &p->list, list) in show_kprobe_addr()
2831 report_probe(pi, kp, sym, offset, modname, p); in show_kprobe_addr()
2833 report_probe(pi, p, sym, offset, modname, NULL); in show_kprobe_addr()
2894 struct kprobe *p; in arm_all_kprobes() local
2914 hlist_for_each_entry(p, head, hlist) { in arm_all_kprobes()
2915 if (!kprobe_disabled(p)) { in arm_all_kprobes()
2916 err = arm_kprobe(p); in arm_all_kprobes()
2940 struct kprobe *p; in disarm_all_kprobes() local
2957 hlist_for_each_entry(p, head, hlist) { in disarm_all_kprobes()
2958 if (!arch_trampoline_kprobe(p) && !kprobe_disabled(p)) { in disarm_all_kprobes()
2959 err = disarm_kprobe(p, false); in disarm_all_kprobes()