]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
powerpc/kprobes: Invoke handlers directly
authorNaveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Mon, 21 Nov 2016 17:06:41 +0000 (22:36 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 23 Nov 2016 11:56:25 +0000 (22:56 +1100)
Invoke the kprobe handlers directly rather than through notify_die(), to
reduce path taken for handling kprobes. Similar to commit 6f6343f53d13
("kprobes/x86: Call exception handlers directly from do_int3/do_debug").

While at it, rename post_kprobe_handler() to kprobe_post_handler() for
more uniform naming.

Reported-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/kprobes.h
arch/powerpc/kernel/kprobes.c
arch/powerpc/kernel/traps.c

index 2c9759bdb63bc2853760dcb98f9a1413c8c810c2..97b8c1f83453038c3c594bae8820fa9e7b128ec5 100644 (file)
@@ -32,6 +32,7 @@
 #include <asm/probes.h>
 #include <asm/code-patching.h>
 
+#ifdef CONFIG_KPROBES
 #define  __ARCH_WANT_KPROBES_INSN_SLOT
 
 struct pt_regs;
@@ -127,5 +128,11 @@ struct kprobe_ctlblk {
 extern int kprobe_exceptions_notify(struct notifier_block *self,
                                        unsigned long val, void *data);
 extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
+extern int kprobe_handler(struct pt_regs *regs);
+extern int kprobe_post_handler(struct pt_regs *regs);
+#else
+static inline int kprobe_handler(struct pt_regs *regs) { return 0; }
+static inline int kprobe_post_handler(struct pt_regs *regs) { return 0; }
+#endif /* CONFIG_KPROBES */
 #endif /* __KERNEL__ */
 #endif /* _ASM_POWERPC_KPROBES_H */
index 9479d8e360cfe9b6ba8d677072898dec25e7b5a5..ad108b842669566130cc2734e947f51203f55914 100644 (file)
@@ -140,13 +140,16 @@ void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
        regs->link = (unsigned long)kretprobe_trampoline;
 }
 
-static int __kprobes kprobe_handler(struct pt_regs *regs)
+int __kprobes kprobe_handler(struct pt_regs *regs)
 {
        struct kprobe *p;
        int ret = 0;
        unsigned int *addr = (unsigned int *)regs->nip;
        struct kprobe_ctlblk *kcb;
 
+       if (user_mode(regs))
+               return 0;
+
        /*
         * We don't want to be preempted for the entire
         * duration of kprobe processing
@@ -359,12 +362,12 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
  * single-stepped a copy of the instruction.  The address of this
  * copy is p->ainsn.insn.
  */
-static int __kprobes post_kprobe_handler(struct pt_regs *regs)
+int __kprobes kprobe_post_handler(struct pt_regs *regs)
 {
        struct kprobe *cur = kprobe_running();
        struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
 
-       if (!cur)
+       if (!cur || user_mode(regs))
                return 0;
 
        /* make sure we got here for instruction we have a kprobe on */
@@ -470,25 +473,7 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
 int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
                                       unsigned long val, void *data)
 {
-       struct die_args *args = (struct die_args *)data;
-       int ret = NOTIFY_DONE;
-
-       if (args->regs && user_mode(args->regs))
-               return ret;
-
-       switch (val) {
-       case DIE_BPT:
-               if (kprobe_handler(args->regs))
-                       ret = NOTIFY_STOP;
-               break;
-       case DIE_SSTEP:
-               if (post_kprobe_handler(args->regs))
-                       ret = NOTIFY_STOP;
-               break;
-       default:
-               break;
-       }
-       return ret;
+       return NOTIFY_DONE;
 }
 
 unsigned long arch_deref_entry_point(void *entry)
index 3eb20d16c67c37b5a24c8dc9fd36b7e0e66731d8..b922c6f4a2fed0ec058ea8fdd43dbf8bfb4f4927 100644 (file)
@@ -64,6 +64,7 @@
 #include <asm/asm-prototypes.h>
 #include <asm/hmi.h>
 #include <sysdev/fsl_pci.h>
+#include <asm/kprobes.h>
 
 #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
 int (*__debugger)(struct pt_regs *regs) __read_mostly;
@@ -826,6 +827,9 @@ void single_step_exception(struct pt_regs *regs)
 
        clear_single_step(regs);
 
+       if (kprobe_post_handler(regs))
+               return;
+
        if (notify_die(DIE_SSTEP, "single_step", regs, 5,
                                        5, SIGTRAP) == NOTIFY_STOP)
                goto bail;
@@ -1179,6 +1183,9 @@ void program_check_exception(struct pt_regs *regs)
                if (debugger_bpt(regs))
                        goto bail;
 
+               if (kprobe_handler(regs))
+                       goto bail;
+
                /* trap exception */
                if (notify_die(DIE_BPT, "breakpoint", regs, 5, 5, SIGTRAP)
                                == NOTIFY_STOP)
@@ -1747,6 +1754,9 @@ void DebugException(struct pt_regs *regs, unsigned long debug_status)
                        return;
                }
 
+               if (kprobe_post_handler(regs))
+                       return;
+
                if (notify_die(DIE_SSTEP, "block_step", regs, 5,
                               5, SIGTRAP) == NOTIFY_STOP) {
                        return;
@@ -1761,6 +1771,9 @@ void DebugException(struct pt_regs *regs, unsigned long debug_status)
                /* Clear the instruction completion event */
                mtspr(SPRN_DBSR, DBSR_IC);
 
+               if (kprobe_post_handler(regs))
+                       return;
+
                if (notify_die(DIE_SSTEP, "single_step", regs, 5,
                               5, SIGTRAP) == NOTIFY_STOP) {
                        return;