Re: [RFC PATCH -tip 3/3] x86/kprobes,orc: Unwind optprobe trampoline correctly
From: Masami Hiramatsu
Date: Wed Mar 31 2021 - 21:55:18 EST
On Wed, 31 Mar 2021 14:44:56 +0900
Masami Hiramatsu <mhiramat@xxxxxxxxxx> wrote:
> +#ifdef CONFIG_UNWINDER_ORC
> +unsigned long recover_optprobe_trampoline(unsigned long addr, unsigned long *sp)
> +{
> + unsigned long offset, entry, probe_addr;
> + struct optimized_kprobe *op;
> + struct orc_entry *orc;
> +
> + entry = find_kprobe_optinsn_slot_entry(addr);
> + if (!entry)
> + return addr;
> +
> + offset = addr - entry;
> +
> + /* Decode arg1 and get the optprobe */
> + op = (void *)extract_set_arg1((void *)(entry + TMPL_MOVE_IDX));
> + if (!op)
> + return addr;
> +
> + probe_addr = (unsigned long)op->kp.addr;
> +
> + if (offset < TMPL_END_IDX) {
Maybe I should add a comment here.
/*
* Since this is on the trampoline code based on the template code,
* ORC information on the template code can be used for adjusting
* stack pointer. The template code may change the stack pointer to
* store pt_regs.
*/
> + orc = orc_find((unsigned long)optprobe_template_func + offset);
> + if (!orc || orc->sp_reg != ORC_REG_SP)
> + return addr;
> + /*
> + * Since optprobe trampoline doesn't push caller on the stack,
> + * need to decrement 1 stack entry size
> + */
> + *sp += orc->sp_offset - sizeof(long);
> + return probe_addr;
> + } else {
/*
* In this case, the address is on the instruction copied from probed
* address, and jump instruction. Here the stack pointer is exactly
* the same as the value where it was copied by the kprobes.
*/
> + return probe_addr + offset - TMPL_END_IDX;
> + }
> +}
> +#endif
> +
Thank you,
--
Masami Hiramatsu <mhiramat@xxxxxxxxxx>