lkml.org 
[lkml]   [2021]   [Mar]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [RFC PATCH -tip 3/3] x86/kprobes,orc: Unwind optprobe trampoline correctly
On Wed, 31 Mar 2021 14:44:56 +0900
Masami Hiramatsu <mhiramat@kernel.org> 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@kernel.org>

\
 
 \ /
  Last update: 2021-04-01 03:57    [W:0.067 / U:2.628 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site