[PATCH 0/2] riscv: ftrace: use frame CFA as the function graph retp identity

From: Rui Qi

Date: Fri Sep 18 2026 - 23:38:07 EST


RISC-V dynamic function graph tracing currently saves &fregs->ra as the
graph retp -- the lookup key that ftrace_graph_ret_addr() matches against
shadow stack entries. That address points into ftrace_caller's temporary
fregs frame, which disappears once ftrace_caller returns. Later stack
unwinding finds return_to_handler in the traced function's own frame and
looks it up with the frame CFA, so the saved entry can never match. The
same mismatch breaks function_get_true_parent_ip(), which looks up the
original parent with the saved entry SP rather than &fregs->ra.

Patch 1 clarifies the ftrace_graph_ret_addr() documentation: retp is
compared, not dereferenced, and may be any stable frame identity as long
as the graph entry path and the unwinder use the same value.

Patch 2 makes RISC-V use the frame CFA for that identity: the static _mcount
path derives it from &frame->ra, the dynamic ftrace path uses the saved
entry SP, and the frame-pointer unwinder tracks the same CFA when
recovering graph return addresses.

Build-tested for rv64 with gcc and clang (full vmlinux).

Rui Qi (2):
ftrace: Clarify function graph retp identity
riscv: ftrace: Use frame CFA for function graph retp

arch/riscv/kernel/ftrace.c | 10 ++++++++--
arch/riscv/kernel/stacktrace.c | 2 +-
kernel/trace/fgraph.c | 7 +++++--
3 files changed, 14 insertions(+), 5 deletions(-)

--
2.20.1