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

From: Steven Rostedt
Date: Tue Apr 30 2019 - 21:35:45 EST


On Tue, 30 Apr 2019 17:53:34 -0400
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> + if (ftrace_location(ip)) {
> + /* A breakpoint at the beginning of the function was hit */
> + if (in_nmi()) {
> + /* NMIs have their own trampoline */
> + this_cpu_write(ftrace_bp_call_nmi_return, (void *)ip + MCOUNT_INSN_SIZE);
> + regs->ip = (unsigned long) ftrace_emulate_call_nmi;
> + return 1;
> + }
> + this_cpu_write(ftrace_bp_call_return, (void *)ip + MCOUNT_INSN_SIZE);
> + if (regs->flags & X86_EFLAGS_IF) {
> + regs->flags &= ~X86_EFLAGS_IF;
> + regs->ip = (unsigned long) ftrace_emulate_call_irqoff;
> + /* Tell lockdep here we are enabling interrupts */
> + trace_hardirqs_on();

This isn't good enough. The return from interrupt does call lockdep
saying interrupts are disabled. Need to add the lockdep tracking in the
asm as well.

Probably easier to move it from inline asm to ftrace_X.S and use the
lockdep TRACE_ON/OFF macros.

-- Steve




> + } else {
> + regs->ip = (unsigned long) ftrace_emulate_call_irqon;
> + }
> + return 1;
> + } else if (is_ftrace_caller(ip)) {
> + /* An ftrace trampoline is being updated */
> + if (!ftrace_update_func_call) {
> + /* If it's a jump, just need to skip it */
> + regs->ip += MCOUNT_INSN_SIZE -1;
> + return 1;
> + }
> + if (in_nmi()) {
> + /* NMIs have their own trampoline */
> + this_cpu_write(ftrace_bp_call_nmi_return, (void *)ip + MCOUNT_INSN_SIZE);
> + regs->ip = (unsigned long) ftrace_emulate_call_update_nmi;
> + return 1;
> + }
> + this_cpu_write(ftrace_bp_call_return, (void *)ip + MCOUNT_INSN_SIZE);
> + if (regs->flags & X86_EFLAGS_IF) {
> + regs->flags &= ~X86_EFLAGS_IF;
> + regs->ip = (unsigned long) ftrace_emulate_call_update_irqoff;
> + trace_hardirqs_on();
> + } else {
> + regs->ip = (unsigned long) ftrace_emulate_call_update_irqon;
> + }
> + return 1;
> + }
>
> - return 1;
> + return 0;
> }