Skip to content

Commit 6e5fd3a

Browse files
mhiramatingomolnar
authored andcommitted
powerpc/kprobes: Don't call the ->break_handler() in powerpc kprobes code
Don't call the ->break_handler() from the powerpc kprobes code, because it was only used by jprobes which got removed. This also removes skip_singlestep() and embeds it in the caller, kprobe_ftrace_handler(), which simplifies regs->nip operation around there. Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> Acked-by: Thomas Gleixner <tglx@linutronix.de> Acked-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: linux-arch@vger.kernel.org Cc: linuxppc-dev@lists.ozlabs.org Link: https://lore.kernel.org/lkml/152942477127.15209.8982613703787878618.stgit@devbox Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent c9abd55 commit 6e5fd3a

3 files changed

Lines changed: 23 additions & 64 deletions

File tree

‎arch/powerpc/include/asm/kprobes.h‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,6 @@ extern int kprobe_exceptions_notify(struct notifier_block *self,
102102
extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
103103
extern int kprobe_handler(struct pt_regs *regs);
104104
extern int kprobe_post_handler(struct pt_regs *regs);
105-
#ifdef CONFIG_KPROBES_ON_FTRACE
106-
extern int skip_singlestep(struct kprobe *p, struct pt_regs *regs,
107-
struct kprobe_ctlblk *kcb);
108-
#else
109-
static inline int skip_singlestep(struct kprobe *p, struct pt_regs *regs,
110-
struct kprobe_ctlblk *kcb)
111-
{
112-
return 0;
113-
}
114-
#endif
115105
#else
116106
static inline int kprobe_handler(struct pt_regs *regs) { return 0; }
117107
static inline int kprobe_post_handler(struct pt_regs *regs) { return 0; }

‎arch/powerpc/kernel/kprobes-ftrace.c‎

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,6 @@
2525
#include <linux/preempt.h>
2626
#include <linux/ftrace.h>
2727

28-
static nokprobe_inline
29-
int __skip_singlestep(struct kprobe *p, struct pt_regs *regs,
30-
struct kprobe_ctlblk *kcb, unsigned long orig_nip)
31-
{
32-
/*
33-
* Emulate singlestep (and also recover regs->nip)
34-
* as if there is a nop
35-
*/
36-
regs->nip = (unsigned long)p->addr + MCOUNT_INSN_SIZE;
37-
if (unlikely(p->post_handler)) {
38-
kcb->kprobe_status = KPROBE_HIT_SSDONE;
39-
p->post_handler(p, regs, 0);
40-
}
41-
__this_cpu_write(current_kprobe, NULL);
42-
if (orig_nip)
43-
regs->nip = orig_nip;
44-
return 1;
45-
}
46-
47-
int skip_singlestep(struct kprobe *p, struct pt_regs *regs,
48-
struct kprobe_ctlblk *kcb)
49-
{
50-
if (kprobe_ftrace(p))
51-
return __skip_singlestep(p, regs, kcb, 0);
52-
else
53-
return 0;
54-
}
55-
NOKPROBE_SYMBOL(skip_singlestep);
56-
5728
/* Ftrace callback handler for kprobes */
5829
void kprobe_ftrace_handler(unsigned long nip, unsigned long parent_nip,
5930
struct ftrace_ops *ops, struct pt_regs *regs)
@@ -71,8 +42,6 @@ void kprobe_ftrace_handler(unsigned long nip, unsigned long parent_nip,
7142
if (kprobe_running()) {
7243
kprobes_inc_nmissed_count(p);
7344
} else {
74-
unsigned long orig_nip = regs->nip;
75-
7645
/*
7746
* On powerpc, NIP is *before* this instruction for the
7847
* pre handler
@@ -81,9 +50,18 @@ void kprobe_ftrace_handler(unsigned long nip, unsigned long parent_nip,
8150

8251
__this_cpu_write(current_kprobe, p);
8352
kcb->kprobe_status = KPROBE_HIT_ACTIVE;
84-
if (!p->pre_handler || !p->pre_handler(p, regs))
85-
__skip_singlestep(p, regs, kcb, orig_nip);
86-
else {
53+
if (!p->pre_handler || !p->pre_handler(p, regs)) {
54+
/*
55+
* Emulate singlestep (and also recover regs->nip)
56+
* as if there is a nop
57+
*/
58+
regs->nip += MCOUNT_INSN_SIZE;
59+
if (unlikely(p->post_handler)) {
60+
kcb->kprobe_status = KPROBE_HIT_SSDONE;
61+
p->post_handler(p, regs, 0);
62+
}
63+
__this_cpu_write(current_kprobe, NULL);
64+
} else {
8765
/*
8866
* If pre_handler returns !0, it sets regs->nip and
8967
* resets current kprobe. In this case, we should not

‎arch/powerpc/kernel/kprobes.c‎

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -317,25 +317,17 @@ int kprobe_handler(struct pt_regs *regs)
317317
}
318318
prepare_singlestep(p, regs);
319319
return 1;
320-
} else {
321-
if (*addr != BREAKPOINT_INSTRUCTION) {
322-
/* If trap variant, then it belongs not to us */
323-
kprobe_opcode_t cur_insn = *addr;
324-
if (is_trap(cur_insn))
325-
goto no_kprobe;
326-
/* The breakpoint instruction was removed by
327-
* another cpu right after we hit, no further
328-
* handling of this interrupt is appropriate
329-
*/
330-
ret = 1;
320+
} else if (*addr != BREAKPOINT_INSTRUCTION) {
321+
/* If trap variant, then it belongs not to us */
322+
kprobe_opcode_t cur_insn = *addr;
323+
324+
if (is_trap(cur_insn))
331325
goto no_kprobe;
332-
}
333-
p = __this_cpu_read(current_kprobe);
334-
if (p->break_handler && p->break_handler(p, regs)) {
335-
if (!skip_singlestep(p, regs, kcb))
336-
goto ss_probe;
337-
ret = 1;
338-
}
326+
/* The breakpoint instruction was removed by
327+
* another cpu right after we hit, no further
328+
* handling of this interrupt is appropriate
329+
*/
330+
ret = 1;
339331
}
340332
goto no_kprobe;
341333
}
@@ -350,7 +342,7 @@ int kprobe_handler(struct pt_regs *regs)
350342
*/
351343
kprobe_opcode_t cur_insn = *addr;
352344
if (is_trap(cur_insn))
353-
goto no_kprobe;
345+
goto no_kprobe;
354346
/*
355347
* The breakpoint instruction was removed right
356348
* after we hit it. Another cpu has removed
@@ -370,7 +362,6 @@ int kprobe_handler(struct pt_regs *regs)
370362
/* handler has already set things up, so skip ss setup */
371363
return 1;
372364

373-
ss_probe:
374365
if (p->ainsn.boostable >= 0) {
375366
ret = try_to_emulate(p, regs);
376367

0 commit comments

Comments
 (0)