]>
git.proxmox.com Git - mirror_ubuntu-impish-kernel.git/blob - arch/x86/kernel/kprobes/ftrace.c
373e5fa3ce1f620de4e079d271be0d4fb4c52622
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Dynamic Ftrace based Kprobes Optimization
5 * Copyright (C) Hitachi Ltd., 2012
7 #include <linux/kprobes.h>
8 #include <linux/ptrace.h>
9 #include <linux/hardirq.h>
10 #include <linux/preempt.h>
11 #include <linux/ftrace.h>
15 /* Ftrace callback handler for kprobes -- called under preepmt disabed */
16 void kprobe_ftrace_handler(unsigned long ip
, unsigned long parent_ip
,
17 struct ftrace_ops
*ops
, struct ftrace_regs
*fregs
)
19 struct pt_regs
*regs
= ftrace_get_regs(fregs
);
21 struct kprobe_ctlblk
*kcb
;
24 bit
= ftrace_test_recursion_trylock(ip
, parent_ip
);
28 preempt_disable_notrace();
29 p
= get_kprobe((kprobe_opcode_t
*)ip
);
30 if (unlikely(!p
) || kprobe_disabled(p
))
33 kcb
= get_kprobe_ctlblk();
34 if (kprobe_running()) {
35 kprobes_inc_nmissed_count(p
);
37 unsigned long orig_ip
= regs
->ip
;
38 /* Kprobe handler expects regs->ip = ip + 1 as breakpoint hit */
39 regs
->ip
= ip
+ sizeof(kprobe_opcode_t
);
41 __this_cpu_write(current_kprobe
, p
);
42 kcb
->kprobe_status
= KPROBE_HIT_ACTIVE
;
43 if (!p
->pre_handler
|| !p
->pre_handler(p
, regs
)) {
45 * Emulate singlestep (and also recover regs->ip)
46 * as if there is a 5byte nop
48 regs
->ip
= (unsigned long)p
->addr
+ MCOUNT_INSN_SIZE
;
49 if (unlikely(p
->post_handler
)) {
50 kcb
->kprobe_status
= KPROBE_HIT_SSDONE
;
51 p
->post_handler(p
, regs
, 0);
56 * If pre_handler returns !0, it changes regs->ip. We have to
57 * skip emulating post_handler.
59 __this_cpu_write(current_kprobe
, NULL
);
62 preempt_enable_notrace();
63 ftrace_test_recursion_unlock(bit
);
65 NOKPROBE_SYMBOL(kprobe_ftrace_handler
);
67 int arch_prepare_kprobe_ftrace(struct kprobe
*p
)
70 p
->ainsn
.boostable
= false;