Linux Trace Kernel
 help / color / mirror / Atom feed
* [PATCH 0/2] riscv: ftrace: use frame CFA as the function graph retp identity
@ 2026-09-19  3:37 Rui Qi
  2026-09-19  3:37 ` [PATCH 1/2] ftrace: Clarify " Rui Qi
  2026-09-19  3:37 ` [PATCH 2/2] riscv: ftrace: Use frame CFA for function graph retp Rui Qi
  0 siblings, 2 replies; 3+ messages in thread
From: Rui Qi @ 2026-09-19  3:37 UTC (permalink / raw)
  To: rostedt
  Cc: Albert Ou, Alexandre Ghiti, Björn Töpel, Chunyan Zhang,
	Guo Ren, Jiakai Xu, linux-kernel, linux-riscv, linux-trace-kernel,
	Mark Rutland, Masami Hiramatsu, Mathieu Desnoyers, Palmer Dabbelt,
	Paul Walmsley, Song Shuai

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-19  3:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-19  3:37 [PATCH 0/2] riscv: ftrace: use frame CFA as the function graph retp identity Rui Qi
2026-09-19  3:37 ` [PATCH 1/2] ftrace: Clarify " Rui Qi
2026-09-19  3:37 ` [PATCH 2/2] riscv: ftrace: Use frame CFA for function graph retp Rui Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox