if (addr == FTRACE_ADDR) return &plt[FTRACE_PLT_IDX]; if (addr == FTRACE_REGS_ADDR &&
IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS)) return &plt[FTRACE_REGS_PLT_IDX];
return NULL;
}
/* * Find the address the callsite must branch to in order to reach '*addr'. * * Due to the limited range of 'bl' instruction, modules may be placed too far * away to branch directly and we must use a PLT. * * Returns true when '*addr' contains a reachable target address, or has been * modified to contain a PLT address. Returns false otherwise.
*/ staticbool ftrace_find_callable_addr(struct dyn_ftrace *rec, struct module *mod, unsignedlong *addr)
{ unsignedlong pc = rec->ip + LOONGARCH_INSN_SIZE; struct plt_entry *plt;
/* * If a custom trampoline is unreachable, rely on the ftrace_regs_caller * trampoline which knows how to indirectly reach that trampoline through * ops->direct_call.
*/ if (*addr != FTRACE_ADDR && *addr != FTRACE_REGS_ADDR && !reachable_by_bl(*addr, pc))
*addr = FTRACE_REGS_ADDR;
/* * When the target is within range of the 'bl' instruction, use 'addr' * as-is and branch to that directly.
*/ if (reachable_by_bl(*addr, pc)) returntrue;
/* * 'mod' is only set at module load time, but if we end up * dealing with an out-of-range condition, we can assume it * is due to a module being loaded far away from the kernel. * * NOTE: __module_text_address() must be called within a RCU read * section, but we can rely on ftrace_lock to ensure that 'mod' * retains its validity throughout the remainder of this code.
*/ if (!mod) {
scoped_guard(rcu)
mod = __module_text_address(pc);
}
if (WARN_ON(!mod)) returnfalse;
plt = get_ftrace_plt(mod, *addr); if (!plt) {
pr_err("ftrace: no module PLT for %ps\n", (void *)*addr); returnfalse;
}
int ftrace_update_ftrace_func(ftrace_func_t func)
{
u32 new; unsignedlong pc;
pc = (unsignedlong)&ftrace_call; new = larch_insn_gen_bl(pc, (unsignedlong)func);
return ftrace_modify_code(pc, 0, new, false);
}
/* * The compiler has inserted 2 NOPs before the regular function prologue. * T series registers are available and safe because of LoongArch's psABI. * * At runtime, we can replace nop with bl to enable ftrace call and replace bl * with nop to disable ftrace call. The bl requires us to save the original RA * value, so it saves RA at t0 here. * * Details are: * * | Compiled | Disabled | Enabled | * +------------+------------------------+------------------------+ * | nop | move t0, ra | move t0, ra | * | nop | nop | bl ftrace_caller | * | func_body | func_body | func_body | * * The RA value will be recovered by ftrace_regs_entry, and restored into RA * before returning to the regular function prologue. When a function is not * being traced, the "move t0, ra" is not harmful.
*/
__this_cpu_write(current_kprobe, p);
kcb->kprobe_status = KPROBE_HIT_ACTIVE; if (!p->pre_handler || !p->pre_handler(p, regs)) { /* * Emulate singlestep (and also recover regs->csr_era) * as if there is a nop
*/
instruction_pointer_set(regs, (unsignedlong)p->addr + MCOUNT_INSN_SIZE); if (unlikely(p->post_handler)) {
kcb->kprobe_status = KPROBE_HIT_SSDONE;
p->post_handler(p, regs, 0);
}
instruction_pointer_set(regs, orig_ip);
}
/* * If pre_handler returns !0, it changes regs->csr_era. We have to * skip emulating post_handler.
*/
__this_cpu_write(current_kprobe, NULL);
}
out:
ftrace_test_recursion_unlock(bit);
}
NOKPROBE_SYMBOL(kprobe_ftrace_handler);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.