]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
powerpc/kprobes: Optimize kprobe in kretprobe_trampoline()
authorAnju T <anju@linux.vnet.ibm.com>
Wed, 8 Feb 2017 09:50:52 +0000 (15:20 +0530)
committerTim Gardner <tim.gardner@canonical.com>
Mon, 20 Feb 2017 22:33:31 +0000 (15:33 -0700)
BugLink: http://bugs.launchpad.net/bugs/1585741
Kprobe placed on the  kretprobe_trampoline() during boot time can be
optimized, since the instruction at probe point is a 'nop'.

Signed-off-by: Anju T Sudhakar <anju@linux.vnet.ibm.com>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
(cherry picked from linux-next commit 762df10bad6954b353ee649c387a8ffacf6dc347)
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
arch/powerpc/kernel/kprobes.c
arch/powerpc/kernel/optprobes.c

index 735ff3d3f77d9ad796b88dc2d47ad344bbbf24ab..45e4f82b230dad3783bc756fc34449b4990a8819 100644 (file)
@@ -285,6 +285,7 @@ asm(".global kretprobe_trampoline\n"
        ".type kretprobe_trampoline, @function\n"
        "kretprobe_trampoline:\n"
        "nop\n"
+       "blr\n"
        ".size kretprobe_trampoline, .-kretprobe_trampoline\n");
 
 /*
@@ -337,6 +338,13 @@ static int __kprobes trampoline_probe_handler(struct kprobe *p,
 
        kretprobe_assert(ri, orig_ret_address, trampoline_address);
        regs->nip = orig_ret_address;
+       /*
+        * Make LR point to the orig_ret_address.
+        * When the 'nop' inside the kretprobe_trampoline
+        * is optimized, we can do a 'blr' after executing the
+        * detour buffer code.
+        */
+       regs->link = orig_ret_address;
 
        reset_current_kprobe();
        kretprobe_hash_unlock(current, &flags);
index 17f4c94142d3e36ca3d59132a657401222c5a3b2..2282bf4e63cd16373ae23f362c6dad0c3f112740 100644 (file)
@@ -72,12 +72,11 @@ static unsigned long can_optimize(struct kprobe *p)
 
        /*
         * kprobe placed for kretprobe during boot time
-        * is not optimizing now.
-        *
-        * TODO: Optimize kprobe in kretprobe_trampoline
+        * has a 'nop' instruction, which can be emulated.
+        * So further checks can be skipped.
         */
        if (p->addr == (kprobe_opcode_t *)&kretprobe_trampoline)
-               return 0;
+               return (unsigned long)p->addr + sizeof(kprobe_opcode_t);
 
        /*
         * We only support optimizing kernel addresses, but not