Linux Trace Kernel
 help / color / mirror / Atom feed
From: "Rui Qi" <qirui.001@bytedance.com>
To: <rostedt@goodmis.org>
Cc: "Albert Ou" <aou@eecs.berkeley.edu>,
	"Alexandre Ghiti" <alex@ghiti.fr>,
	"Björn Töpel" <bjorn@rivosinc.com>,
	"Chunyan Zhang" <zhangchunyan@iscas.ac.cn>,
	"Guo Ren" <guoren@kernel.org>,
	"Jiakai Xu" <xujiakai2025@iscas.ac.cn>,
	linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
	linux-trace-kernel@vger.kernel.org,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Paul Walmsley" <pjw@kernel.org>,
	"Song Shuai" <suagrfillet@gmail.com>
Subject: [PATCH 0/2] riscv: ftrace: use frame CFA as the function graph retp identity
Date: Sat, 19 Sep 2026 11:37:24 +0800	[thread overview]
Message-ID: <20260919033726.1361382-1-qirui.001@bytedance.com> (raw)

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

             reply	other threads:[~2026-09-19  3:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-19  3:37 Rui Qi [this message]
2026-09-19  3:37 ` [PATCH 1/2] ftrace: Clarify function graph retp identity Rui Qi
2026-09-19  3:37 ` [PATCH 2/2] riscv: ftrace: Use frame CFA for function graph retp Rui Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260919033726.1361382-1-qirui.001@bytedance.com \
    --to=qirui.001@bytedance.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=bjorn@rivosinc.com \
    --cc=guoren@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=suagrfillet@gmail.com \
    --cc=xujiakai2025@iscas.ac.cn \
    --cc=zhangchunyan@iscas.ac.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox