".type kretprobe_trampoline, @function\n"
"kretprobe_trampoline:\n"
"nop\n"
+ "blr\n"
".size kretprobe_trampoline, .-kretprobe_trampoline\n");
/*
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);
/*
* 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