Re: [RFC][PATCH] ftrace/x86: Emulate call function while updating in breakpoint handler

From: Peter Zijlstra
Date: Wed May 01 2019 - 15:04:36 EST


On Wed, May 01, 2019 at 02:58:24PM -0400, Steven Rostedt wrote:
> > + if (ftrace_location(ip)) {
> > + int3_emulate_call(regs, ftrace_update_func_call);
>
> Should be:
>
> int3_emulate_call(regs, (unsigned long)ftrace_regs_caller);

Ah, I lost the plot a little there.

> > + return 1;
> > + } else if (is_ftrace_caller(ip)) {
> > + if (!ftrace_update_func_call) {
> > + int3_emulate_jmp(regs, regs->ip - INT3_INSN_SIZE + CALL_INSN_SIZE);
>
> I see what you did here, but I think:
>
> int3_emulate_jmp(regs, ip + CALL_INSN_SIZE);
>
> looks better. But that said, we could in the beginning do:
>
> ip = regs->ip - INT3_INSN_SIZE;
>
> instead of
>
> ip = regs->ip - 1;
>
> I made these updates and posted them to Linus.

I was actually considering:

static inline void int3_emulate_nop(struct pt_regs *regs, unsigned long size)
{
int3_emulate_jmp(regs, regs->ip - INT3_INSN_SIZE + size);
}

And then the above becomes:

int3_emulate_nop(regs, CALL_INSN_SIZE);

Hmm?