From: Wang ShaoBo <bobo.shaobowang@huawei.com>
Cc: <cj.chengjian@huawei.com>, <huawei.libin@huawei.com>,
<xiexiuqi@huawei.com>, <liwei391@huawei.com>,
<linux-kernel@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<catalin.marinas@arm.com>, <will@kernel.org>,
<rostedt@goodmis.org>, <mark.rutland@arm.com>,
<bobo.shaobowang@huawei.com>, <zengshun.wu@outlook.com>
Subject: [RFC PATCH -next v2 2/4] arm64/ftrace: introduce ftrace dynamic trampoline entrances
Date: Wed, 16 Mar 2022 18:01:30 +0800 [thread overview]
Message-ID: <20220316100132.244849-3-bobo.shaobowang@huawei.com> (raw)
In-Reply-To: <20220316100132.244849-1-bobo.shaobowang@huawei.com>
From: Cheng Jian <cj.chengjian@huawei.com>
We introduce two function entrances ftrace_(regs)_caller_tramp
for dynamic trampoline use, which are put into Read-Only section
and should be entirely copied to the space allocated for trampoline.
Signed-off-by: Cheng Jian <cj.chengjian@huawei.com>
Signed-off-by: Wang ShaoBo <bobo.shaobowang@huawei.com>
---
arch/arm64/kernel/entry-ftrace.S | 80 +++++++++++++++++++++++++-------
1 file changed, 64 insertions(+), 16 deletions(-)
diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
index e535480a4069..88462d925446 100644
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -76,6 +76,23 @@
add x29, sp, #S_STACKFRAME
.endm
+ .macro ftrace_regs_restore
+ /* Restore function arguments */
+ ldp x0, x1, [sp]
+ ldp x2, x3, [sp, #S_X2]
+ ldp x4, x5, [sp, #S_X4]
+ ldp x6, x7, [sp, #S_X6]
+ ldr x8, [sp, #S_X8]
+
+ /* Restore the callsite's FP, LR, PC */
+ ldr x29, [sp, #S_FP]
+ ldr x30, [sp, #S_LR]
+ ldr x9, [sp, #S_PC]
+
+ /* Restore the callsite's SP */
+ add sp, sp, #PT_REGS_SIZE + 16
+ .endm
+
SYM_CODE_START(ftrace_regs_caller)
bti c
ftrace_regs_entry 1
@@ -108,22 +125,8 @@ SYM_INNER_LABEL(ftrace_graph_call, SYM_L_GLOBAL) // ftrace_graph_caller();
* x19-x29 per the AAPCS, and we created frame records upon entry, so we need
* to restore x0-x8, x29, and x30.
*/
-ftrace_common_return:
- /* Restore function arguments */
- ldp x0, x1, [sp]
- ldp x2, x3, [sp, #S_X2]
- ldp x4, x5, [sp, #S_X4]
- ldp x6, x7, [sp, #S_X6]
- ldr x8, [sp, #S_X8]
-
- /* Restore the callsite's FP, LR, PC */
- ldr x29, [sp, #S_FP]
- ldr x30, [sp, #S_LR]
- ldr x9, [sp, #S_PC]
-
- /* Restore the callsite's SP */
- add sp, sp, #PT_REGS_SIZE + 16
-
+SYM_INNER_LABEL(ftrace_common_return, SYM_L_GLOBAL)
+ ftrace_regs_restore
ret x9
SYM_CODE_END(ftrace_common)
@@ -138,6 +141,51 @@ SYM_CODE_START(ftrace_graph_caller)
SYM_CODE_END(ftrace_graph_caller)
#endif
+.pushsection ".rodata", "a"
+// ftrace trampoline for ftrace_regs_caller
+SYM_CODE_START(ftrace_regs_caller_tramp)
+ bti c
+ ftrace_regs_entry 1 // save all regs
+
+ sub x0, x30, #AARCH64_INSN_SIZE // ip (callsite's BL insn)
+ mov x1, x9 // parent_ip (callsite's LR)
+SYM_INNER_LABEL(ftrace_regs_caller_tramp_ops, SYM_L_GLOBAL)
+ ldr x2, 0 // ops
+ mov x3, sp // regs
+SYM_INNER_LABEL(ftrace_regs_caller_tramp_call, SYM_L_GLOBAL)
+ nop
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+SYM_INNER_LABEL(ftrace_regs_caller_tramp_graph_call, SYM_L_GLOBAL)
+ nop // ftrace_graph_caller()
+#endif
+ ftrace_regs_restore
+SYM_INNER_LABEL(ftrace_regs_caller_tramp_end, SYM_L_GLOBAL)
+ ret x9
+SYM_CODE_END(ftrace_regs_caller_tramp)
+
+// ftrace trampoline for ftrace_caller
+SYM_CODE_START(ftrace_caller_tramp)
+ bti c
+ ftrace_regs_entry 0 // save all regs
+
+ sub x0, x30, #AARCH64_INSN_SIZE // ip (callsite's BL insn)
+ mov x1, x9 // parent_ip (callsite's LR)
+SYM_INNER_LABEL(ftrace_caller_tramp_ops, SYM_L_GLOBAL)
+ ldr x2, 0 // ops
+ mov x3, sp // regs
+SYM_INNER_LABEL(ftrace_caller_tramp_call, SYM_L_GLOBAL)
+ nop
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+SYM_INNER_LABEL(ftrace_caller_tramp_graph_call, SYM_L_GLOBAL)
+ nop // ftrace_graph_caller()
+#endif
+ ftrace_regs_restore
+SYM_INNER_LABEL(ftrace_caller_tramp_end, SYM_L_GLOBAL)
+ ret x9
+SYM_CODE_END(ftrace_caller_tramp)
+.popsection // .rodata
+
+
#else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
/*
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2022-03-16 9:53 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-16 10:01 [RFC PATCH -next v2 0/4] arm64/ftrace: support dynamic trampoline Wang ShaoBo
2022-03-16 10:01 ` [RFC PATCH -next v2 1/4] arm64: introduce aarch64_insn_gen_load_literal Wang ShaoBo
2022-03-16 10:01 ` Wang ShaoBo [this message]
2022-03-16 10:01 ` [RFC PATCH -next v2 3/4] arm64/ftrace: support dynamically allocated trampolines Wang ShaoBo
2022-04-21 13:10 ` Mark Rutland
2022-04-21 14:06 ` Steven Rostedt
2022-04-21 14:08 ` Steven Rostedt
2022-04-21 15:14 ` Mark Rutland
2022-04-21 15:42 ` Steven Rostedt
2022-04-21 16:27 ` Mark Rutland
2022-04-21 17:06 ` Steven Rostedt
2022-04-22 10:12 ` Mark Rutland
2022-04-22 15:45 ` Steven Rostedt
2022-04-22 17:27 ` Mark Rutland
2022-04-26 8:47 ` Masami Hiramatsu
2022-05-04 10:24 ` Mark Rutland
2022-05-05 3:15 ` Masami Hiramatsu
2022-05-09 18:22 ` Steven Rostedt
2022-05-10 9:10 ` Masami Hiramatsu
2022-05-10 14:44 ` Steven Rostedt
2022-05-11 14:34 ` Masami Hiramatsu
2022-05-11 15:12 ` Steven Rostedt
2022-05-12 12:02 ` Masami Hiramatsu
2022-05-12 13:50 ` Steven Rostedt
2022-05-25 12:17 ` Mark Rutland
2022-05-25 13:43 ` Steven Rostedt
2022-05-25 17:12 ` Mark Rutland
2022-05-30 1:03 ` Masami Hiramatsu
2022-05-30 12:38 ` Jiri Olsa
2022-05-31 1:00 ` Masami Hiramatsu
2022-05-04 12:43 ` Mark Rutland
2022-05-05 2:57 ` Wangshaobo (bobo)
2022-05-25 12:27 ` Mark Rutland
2022-04-27 8:54 ` Wangshaobo (bobo)
2022-03-16 10:01 ` [RFC PATCH -next v2 4/4] arm64/ftrace: implement long jump for dynamic trampolines Wang ShaoBo
2022-04-21 13:47 ` Mark Rutland
2022-03-16 14:29 ` [RFC PATCH -next v2 0/4] arm64/ftrace: support dynamic trampoline Steven Rostedt
2022-04-20 18:11 ` Steven Rostedt
2022-04-21 1:13 ` Wangshaobo (bobo)
2022-04-21 12:37 ` Steven Rostedt
2022-05-25 12:45 ` Mark Rutland
2022-05-25 13:58 ` Steven Rostedt
2022-05-25 17:26 ` Mark Rutland
2022-04-21 12:53 ` Mark Rutland
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=20220316100132.244849-3-bobo.shaobowang@huawei.com \
--to=bobo.shaobowang@huawei.com \
--cc=catalin.marinas@arm.com \
--cc=cj.chengjian@huawei.com \
--cc=huawei.libin@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liwei391@huawei.com \
--cc=mark.rutland@arm.com \
--cc=rostedt@goodmis.org \
--cc=will@kernel.org \
--cc=xiexiuqi@huawei.com \
--cc=zengshun.wu@outlook.com \
/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;
as well as URLs for NNTP newsgroup(s).