powerpc/ftrace: Add support for DYNAMIC_FTRACE_WITH_DIRECT_CALLS
authorNaveen N Rao <naveen@kernel.org>
Wed, 30 Oct 2024 07:08:48 +0000 (12:38 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 31 Oct 2024 00:00:55 +0000 (11:00 +1100)
commita52f6043a2238d656ddd23ce0499cf4f12645faa
treeebe1db9c7dd95c9e11a84bfc6b17961cc8281cdf
parente717754f0bb5c5347aac82232691340955735ce1
powerpc/ftrace: Add support for DYNAMIC_FTRACE_WITH_DIRECT_CALLS

Add support for DYNAMIC_FTRACE_WITH_DIRECT_CALLS similar to the arm64
implementation.

ftrace direct calls allow custom trampolines to be called into directly
from function ftrace call sites, bypassing the ftrace trampoline
completely. This functionality is currently utilized by BPF trampolines
to hook into kernel function entries.

Since we have limited relative branch range, we support ftrace direct
calls through support for DYNAMIC_FTRACE_WITH_CALL_OPS. In this
approach, ftrace trampoline is not entirely bypassed. Rather, it is
re-purposed into a stub that reads direct_call field from the associated
ftrace_ops structure and branches into that, if it is not NULL. For
this, it is sufficient if we can ensure that the ftrace trampoline is
reachable from all traceable functions.

When multiple ftrace_ops are associated with a call site, we utilize a
call back to set pt_regs->orig_gpr3 that can then be tested on the
return path from the ftrace trampoline to branch into the direct caller.

Signed-off-by: Naveen N Rao <naveen@kernel.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://patch.msgid.link/20241030070850.1361304-16-hbathini@linux.ibm.com
arch/powerpc/Kconfig
arch/powerpc/include/asm/ftrace.h
arch/powerpc/kernel/asm-offsets.c
arch/powerpc/kernel/trace/ftrace.c
arch/powerpc/kernel/trace/ftrace_entry.S