Skip to content

Commit

Permalink
powerpc/kprobes: Optimize kprobe in kretprobe_trampoline()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
anjutsudhakar authored and mpe committed Feb 10, 2017
1 parent 51c9c08 commit 762df10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 8 additions & 0 deletions arch/powerpc/kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

/*
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions arch/powerpc/kernel/optprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 762df10

Please sign in to comment.