From: bot+bpf-ci@kernel.org
To: duanchenghao@kylinos.cn,yangtiezhu@loongson.cn,rostedt@goodmis.org,mhiramat@kernel.org,mark.rutland@arm.com,hengqi.chen@gmail.com,chenhuacai@kernel.org
Cc: kernel@xen0n.name,zhangtianyang@loongson.cn,masahiroy@kernel.org,linux-kernel@vger.kernel.org,loongarch@lists.linux.dev,bpf@vger.kernel.org,duanchenghao@kylinos.cn,youling.tang@linux.dev,jianghaoran@kylinos.cn,vincent.mc.li@gmail.com,linux-trace-kernel@vger.kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,clm@meta.com,ihor.solodrai@linux.dev
Subject: Re: [PATCH v4 1/7] LoongArch: ftrace: Refactor register restoration in ftrace_common_return
Date: Wed, 17 Dec 2025 06:55:00 +0000 (UTC) [thread overview]
Message-ID: <5c7c7239a6f89e685f69093ff84fe686c75cf6b9b051dcbf812841f00ab3bc31@mail.kernel.org> (raw)
In-Reply-To: <20251217061435.802204-2-duanchenghao@kylinos.cn>
[-- Attachment #1: Type: text/plain, Size: 3096 bytes --]
> diff --git a/arch/loongarch/kernel/mcount_dyn.S b/arch/loongarch/kernel/mcount_dyn.S
> index d6b474ad1d5e..5729c20e5b8b 100644
> --- a/arch/loongarch/kernel/mcount_dyn.S
> +++ b/arch/loongarch/kernel/mcount_dyn.S
> @@ -94,7 +94,6 @@ SYM_INNER_LABEL(ftrace_graph_call, SYM_L_GLOBAL)
> * at the callsite, so there is no need to restore the T series regs.
> */
> ftrace_common_return:
> - PTR_L ra, sp, PT_R1
> PTR_L a0, sp, PT_R4
> PTR_L a1, sp, PT_R5
> PTR_L a2, sp, PT_R6
> @@ -104,12 +103,17 @@ ftrace_common_return:
> PTR_L a6, sp, PT_R10
> PTR_L a7, sp, PT_R11
> PTR_L fp, sp, PT_R22
> - PTR_L t0, sp, PT_ERA
> PTR_L t1, sp, PT_R13
> - PTR_ADDI sp, sp, PT_SIZE
> bnez t1, .Ldirect
> +
> + PTR_L ra, sp, PT_R1
> + PTR_L t0, sp, PT_ERA
> + PTR_ADDI sp, sp, PT_SIZE
> jr t0
> .Ldirect:
> + PTR_L t0, sp, PT_R1
> + PTR_L ra, sp, PT_ERA
^^^^^^^^^^^^^^^^^^^
Does this break existing ftrace direct trampolines?
Before this change, direct trampolines received:
ra = parent return address (from PT_R1)
t0 = traced function address (from PT_ERA)
After this change, direct trampolines receive:
t0 = parent return address (from PT_R1)
ra = traced function address (from PT_ERA)
The sample trampolines in samples/ftrace/ were written for the old
convention. For example, samples/ftrace/ftrace-direct.c does:
my_tramp:
st.d $t0, $sp, 8 # Save what it thinks is traced func addr
st.d $ra, $sp, 16 # Save what it thinks is parent addr
bl my_direct_func
ld.d $t0, $sp, 8 # Restore
ld.d $ra, $sp, 16 # Restore
jr $t0 # Jump to what it thinks is traced function
With the new convention, the sample would save parent address in the
t0 slot, restore it to t0, and then jump to the parent instead of the
traced function, skipping the traced function entirely.
This was fixed later in commit 055e392f3be7 "LoongArch: ftrace: Adjust
register stack restore order in direct call trampolines" which updated
all the samples to match the new convention. However, any out-of-tree
direct trampolines written before this commit would be broken by this
change.
Was this ABI break intentional? The commit message mentions matching
"the state when ftrace was entered" but doesn't explain why breaking
compatibility was necessary. RISC-V uses the opposite convention
(t0 = traced func, ra = parent), which the original LoongArch code
matched.
> + PTR_ADDI sp, sp, PT_SIZE
> jr t1
> SYM_CODE_END(ftrace_common)
[ ... ]
> @@ -161,6 +165,8 @@ SYM_CODE_END(return_to_handler)
> #ifdef CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
> SYM_CODE_START(ftrace_stub_direct_tramp)
> UNWIND_HINT_UNDEFINED
> - jr t0
> + move t1, ra
> + move ra, t0
> + jr t1
> SYM_CODE_END(ftrace_stub_direct_tramp)
> #endif /* CONFIG_DYNAMIC_FTRACE_WITH_DIRECT_CALLS */
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/20293821855
next prev parent reply other threads:[~2025-12-17 6:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-17 6:14 [PATCH v4 0/7] Fix the failure issue of the module_attach test case Chenghao Duan
2025-12-17 6:14 ` [PATCH v4 1/7] LoongArch: ftrace: Refactor register restoration in ftrace_common_return Chenghao Duan
2025-12-17 6:55 ` bot+bpf-ci [this message]
2025-12-18 1:26 ` Chenghao Duan
2025-12-18 15:26 ` Chris Mason
2025-12-17 6:14 ` [PATCH v4 2/7] LoongArch: Enable exception fixup for specific ADE subcode Chenghao Duan
2025-12-17 6:14 ` [PATCH v4 3/7] LoongArch: BPF: Enable and fix trampoline-based tracing for module functions Chenghao Duan
2025-12-17 6:14 ` [PATCH v4 4/7] LoongArch: BPF: Save return address register ra to t0 before trampoline Chenghao Duan
2025-12-17 6:14 ` [PATCH v4 5/7] LoongArch: BPF: Adjust the jump offset of tail calls Chenghao Duan
2025-12-17 6:14 ` [PATCH v4 6/7] LoongArch: BPF: Enhance the bpf_arch_text_poke() function Chenghao Duan
2025-12-20 14:07 ` Hengqi Chen
2025-12-22 1:50 ` Chenghao Duan
2025-12-23 2:23 ` Hengqi Chen
2025-12-23 8:49 ` Huacai Chen
2025-12-17 6:14 ` [PATCH v4 7/7] LoongArch: ftrace: Adjust register stack restore order in direct call trampolines Chenghao Duan
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=5c7c7239a6f89e685f69093ff84fe686c75cf6b9b051dcbf812841f00ab3bc31@mail.kernel.org \
--to=bot+bpf-ci@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chenhuacai@kernel.org \
--cc=clm@meta.com \
--cc=daniel@iogearbox.net \
--cc=duanchenghao@kylinos.cn \
--cc=eddyz87@gmail.com \
--cc=hengqi.chen@gmail.com \
--cc=ihor.solodrai@linux.dev \
--cc=jianghaoran@kylinos.cn \
--cc=kernel@xen0n.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=martin.lau@kernel.org \
--cc=masahiroy@kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=vincent.mc.li@gmail.com \
--cc=yangtiezhu@loongson.cn \
--cc=yonghong.song@linux.dev \
--cc=youling.tang@linux.dev \
--cc=zhangtianyang@loongson.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
all inboxes | Powered by JetHome®