From: Jinyang He <hejinyang@loongson.cn>
To: Steven Rostedt <rostedt@goodmis.org>, Qing Zhang <zhangqing@loongson.cn>
Cc: Huacai Chen <chenhuacai@kernel.org>,
Ingo Molnar <mingo@redhat.com>, WANG Xuerui <kernel@xen0n.name>,
loongarch@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-arch@vger.kernel.org, Jiaxun Yang <jiaxun.yang@flygoat.com>
Subject: Re: [PATCH 1/9] LoongArch/ftrace: Add basic support
Date: Sat, 20 Aug 2022 09:38:21 +0800 [thread overview]
Message-ID: <246779c0-b834-16a6-ec68-c06d8f9a375d@loongson.cn> (raw)
In-Reply-To: <20220819132509.127a1353@gandalf.local.home>
On 08/20/2022 01:25 AM, Steven Rostedt wrote:
> On Fri, 19 Aug 2022 16:13:55 +0800
> Qing Zhang <zhangqing@loongson.cn> wrote:
>
>> +#define MCOUNT_STACK_SIZE (2 * SZREG)
>> +#define MCOUNT_S0_OFFSET (0)
>> +#define MCOUNT_RA_OFFSET (SZREG)
>> +
>> + .macro MCOUNT_SAVE_REGS
>> + PTR_ADDI sp, sp, -MCOUNT_STACK_SIZE
>> + PTR_S s0, sp, MCOUNT_S0_OFFSET
>> + PTR_S ra, sp, MCOUNT_RA_OFFSET
>> + move s0, a0
>> + .endm
>> +
>> + .macro MCOUNT_RESTORE_REGS
>> + move a0, s0
>> + PTR_L ra, sp, MCOUNT_RA_OFFSET
>> + PTR_L s0, sp, MCOUNT_S0_OFFSET
>> + PTR_ADDI sp, sp, MCOUNT_STACK_SIZE
>> + .endm
>> +
>> +
>> +SYM_FUNC_START(_mcount)
>> + la t1, ftrace_stub
>> + la t2, ftrace_trace_function /* Prepare t2 for (1) */
>> + PTR_L t2, t2, 0
>> + beq t1, t2, fgraph_trace
>> +
>> + MCOUNT_SAVE_REGS
>> +
>> + move a0, ra /* arg0: self return address */
>> + move a1, s0 /* arg1: parent's return address */
>> + jirl ra, t2, 0 /* (1) call *ftrace_trace_function */
>> +
>> + MCOUNT_RESTORE_REGS
> You know, if you can implement CONFIG_FTRACE_WITH_ARGS, where the default
> function callback gets a ftrace_regs pointer (that only holds what is
> needed for the arguments of the function as well as the stack pointer),
> then you could also implement function graph on top of that, and remove the
> need for the below "fgraph_trace" trampoline.
>
> I'd really would like all architectures to go that way. Also, the
> CONFIG_FTRACE_WITH_ARGS is all you need for live kernel patching.
Hi, Steve,
I think we have implemented CONFIG_FTRACE_WITH_ARGS in dynamic ftrace
in the [Patch3/9]. But, for non dynamic ftrace, it is hardly to
implement it. Because the LoongArch compiler gcc treats mount as a
really call, like 'call _mcount(__builtin_return_address(0))'. That
means, they decrease stack, save args to callee saved regs and may
do some optimization before calling mcount. It is difficult to find the
original args and apply changes from tracers.
Thanks,
Jinyang
>
>
>> +
>> +fgraph_trace:
>> +#ifdef CONFIG_FUNCTION_GRAPH_TRACER
>> + la t1, ftrace_stub
>> + la t3, ftrace_graph_return
>> + PTR_L t3, t3, 0
>> + bne t1, t3, ftrace_graph_caller
>> + la t1, ftrace_graph_entry_stub
>> + la t3, ftrace_graph_entry
>> + PTR_L t3, t3, 0
>> + bne t1, t3, ftrace_graph_caller
>> +#endif
>> +
>> + .globl ftrace_stub
>> +ftrace_stub:
>> + jirl zero, ra, 0
>> +SYM_FUNC_END(_mcount)
>> +EXPORT_SYMBOL(_mcount)
>> +
>> +#ifdef CONFIG_FUNCTION_GRAPH_TRACER
>> +SYM_FUNC_START(ftrace_graph_caller)
>> + MCOUNT_SAVE_REGS
>> +
>> + PTR_ADDI a0, ra, -4 /* arg0: Callsite self return addr */
>> + PTR_ADDI a1, sp, MCOUNT_STACK_SIZE /* arg1: Callsite sp */
>> + move a2, s0 /* arg2: Callsite parent ra */
>> + bl prepare_ftrace_return
>> +
>> + MCOUNT_RESTORE_REGS
>> + jirl zero, ra, 0
>> +SYM_FUNC_END(ftrace_graph_caller)
next prev parent reply other threads:[~2022-08-20 1:38 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-19 8:13 [PATCH 0/9] LoongArch: Add ftrace support Qing Zhang
2022-08-19 8:13 ` [PATCH 1/9] LoongArch/ftrace: Add basic support Qing Zhang
2022-08-19 9:29 ` Jinyang He
2022-08-19 16:53 ` Steven Rostedt
2022-08-20 1:34 ` Qing Zhang
2022-08-20 2:16 ` Huacai Chen
2022-08-19 17:25 ` Steven Rostedt
2022-08-20 1:35 ` Qing Zhang
2022-08-20 1:38 ` Jinyang He [this message]
2022-08-20 1:52 ` Steven Rostedt
2022-08-20 3:16 ` Jinyang He
2022-08-19 8:13 ` [PATCH 2/9] LoongArch/ftrace: Add recordmcount support Qing Zhang
2022-08-19 8:13 ` [PATCH 3/9] LoongArch/ftrace: Add dynamic function tracer support Qing Zhang
2022-08-19 8:13 ` [PATCH 4/9] Loongarch/ftrace: Add dynamic function graph " Qing Zhang
2022-08-19 8:13 ` [PATCH 5/9] Loongarch/ftrace: Add DYNAMIC_FTRACE_WITH_REGS support Qing Zhang
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=246779c0-b834-16a6-ec68-c06d8f9a375d@loongson.cn \
--to=hejinyang@loongson.cn \
--cc=chenhuacai@kernel.org \
--cc=jiaxun.yang@flygoat.com \
--cc=kernel@xen0n.name \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
--cc=zhangqing@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