Re: [PATCH] RISC-V: Don't check text_mutex during stop_machine

From: Steven Rostedt
Date: Fri May 28 2021 - 18:21:19 EST


On Sat, 22 May 2021 12:32:05 -0700 (PDT)
Palmer Dabbelt <palmer@xxxxxxxxxxx> wrote:

> we can then IPI to all the harts in order to get them on the same page
> about that trap, which we can then skip over. We'll need some way to
> differentiate this from accidental executions of unimp, but we can just
> build up a table somewhere (it wasn't immediately clear how x86 does

It currently uses the same code as the text_poke does, which does a
"batching" and keeps track of the locations that were modified. But before
that change (768ae4406a x86/ftrace: Use text_poke()), it had:

int ftrace_int3_handler(struct pt_regs *regs)
{
unsigned long ip;

if (WARN_ON_ONCE(!regs))
return 0;

ip = regs->ip - INT3_INSN_SIZE;

if (ftrace_location(ip)) {
int3_emulate_call(regs, (unsigned long)ftrace_regs_caller);
return 1;
} else if (is_ftrace_caller(ip)) {
if (!ftrace_update_func_call) {
int3_emulate_jmp(regs, ip + CALL_INSN_SIZE);
return 1;
}
int3_emulate_call(regs, ftrace_update_func_call);
return 1;
}

return 0;
}

That "ftrace_location()" is the table you are looking for. It will return
true if the location is registered with ftrace or not (i.e. the mcount
call).

The "int3_emulate_jmp()" is needed to handle the case that we switch from
one trampoline to another trampoline. But that's also an architecture
specific feature, and RISC-V may not have that yet.


-- Steve


> this). Then we have no ordering restrictions on converting the rest of
> the stub into what's necessary to trace a function, which should look
> the same as what we have now