aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorMasami Hiramatsu <masami.hiramatsu.pt@hitachi.com>2012-09-05 10:31:25 -0400
committerSteven Rostedt <rostedt@goodmis.org>2012-09-13 22:52:11 -0400
commitc6aaf4d0bb86e2154ea31a33804cec300611255f (patch)
tree34f973a7ee081daa773b8d4cea9cffaf28bf018a /arch
parent47d5a5f88b9d25d6464c9b60c28f391e84e3ed65 (diff)
kprobes/x86: Fix to support jprobes on ftrace-based kprobe
Fix kprobes/x86 to support jprobes on ftrace-based kprobes. Because of -mfentry support of ftrace, ftrace is now put on the beginning of function where jprobes are put. Originally ftrace-based kprobes doesn't support jprobe because it will change regs->ip and ftrace doesn't support changing IP and ftrace itself doesn't conflict jprobe. However, ftrace -mfentry support moves mcount call on the top of functions where jprobes are put. This means that jprobe always conflicts with ftrace-based kprobe and fails. This patch allows ftrace-based kprobes to support jprobes by allowing to modify regs->ip and kprobes breakpoint handler also allows to skip singlestepping because there is a ftrace call (not an original instruction). Link: http://lkml.kernel.org/r/20120905143125.10329.90836.stgit@localhost.localdomain Reported-by: Fengguang Wu <fengguang.wu@intel.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: "H. Peter Anvin" <hpa@zytor.com> Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/kernel/kprobes.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
index f49f60cca40d..b7c2a85d1926 100644
--- a/arch/x86/kernel/kprobes.c
+++ b/arch/x86/kernel/kprobes.c
@@ -541,6 +541,8 @@ reenter_kprobe(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb
541 return 1; 541 return 1;
542} 542}
543 543
544static void __kprobes skip_singlestep(struct kprobe *p, struct pt_regs *regs,
545 struct kprobe_ctlblk *kcb);
544/* 546/*
545 * Interrupts are disabled on entry as trap3 is an interrupt gate and they 547 * Interrupts are disabled on entry as trap3 is an interrupt gate and they
546 * remain disabled throughout this function. 548 * remain disabled throughout this function.
@@ -599,6 +601,12 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
599 } else if (kprobe_running()) { 601 } else if (kprobe_running()) {
600 p = __this_cpu_read(current_kprobe); 602 p = __this_cpu_read(current_kprobe);
601 if (p->break_handler && p->break_handler(p, regs)) { 603 if (p->break_handler && p->break_handler(p, regs)) {
604#ifdef KPROBES_CAN_USE_FTRACE
605 if (kprobe_ftrace(p)) {
606 skip_singlestep(p, regs, kcb);
607 return 1;
608 }
609#endif
602 setup_singlestep(p, regs, kcb, 0); 610 setup_singlestep(p, regs, kcb, 0);
603 return 1; 611 return 1;
604 } 612 }
@@ -1053,6 +1061,21 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
1053} 1061}
1054 1062
1055#ifdef KPROBES_CAN_USE_FTRACE 1063#ifdef KPROBES_CAN_USE_FTRACE
1064static void __kprobes skip_singlestep(struct kprobe *p, struct pt_regs *regs,
1065 struct kprobe_ctlblk *kcb)
1066{
1067 /*
1068 * Emulate singlestep (and also recover regs->ip)
1069 * as if there is a 5byte nop
1070 */
1071 regs->ip = (unsigned long)p->addr + MCOUNT_INSN_SIZE;
1072 if (unlikely(p->post_handler)) {
1073 kcb->kprobe_status = KPROBE_HIT_SSDONE;
1074 p->post_handler(p, regs, 0);
1075 }
1076 __this_cpu_write(current_kprobe, NULL);
1077}
1078
1056/* Ftrace callback handler for kprobes */ 1079/* Ftrace callback handler for kprobes */
1057void __kprobes kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, 1080void __kprobes kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
1058 struct ftrace_ops *ops, struct pt_regs *regs) 1081 struct ftrace_ops *ops, struct pt_regs *regs)
@@ -1077,19 +1100,12 @@ void __kprobes kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip,
1077 1100
1078 __this_cpu_write(current_kprobe, p); 1101 __this_cpu_write(current_kprobe, p);
1079 kcb->kprobe_status = KPROBE_HIT_ACTIVE; 1102 kcb->kprobe_status = KPROBE_HIT_ACTIVE;
1080 if (p->pre_handler) 1103 if (!p->pre_handler || !p->pre_handler(p, regs))
1081 p->pre_handler(p, regs); 1104 skip_singlestep(p, regs, kcb);
1082 1105 /*
1083 if (unlikely(p->post_handler)) { 1106 * If pre_handler returns !0, it sets regs->ip and
1084 /* 1107 * resets current kprobe.
1085 * Emulate singlestep (and also recover regs->ip) 1108 */
1086 * as if there is a 5byte nop
1087 */
1088 regs->ip = ip + MCOUNT_INSN_SIZE;
1089 kcb->kprobe_status = KPROBE_HIT_SSDONE;
1090 p->post_handler(p, regs, 0);
1091 }
1092 __this_cpu_write(current_kprobe, NULL);
1093 } 1109 }
1094end: 1110end:
1095 local_irq_restore(flags); 1111 local_irq_restore(flags);