Skip to content

Commit 8c3526f

Browse files
FlorentRevestrostedt
authored andcommitted
arm64: ftrace: Add direct call trampoline samples support
The ftrace samples need per-architecture trampoline implementations to save and restore argument registers around the calls to my_direct_func* and to restore polluted registers (eg: x30). These samples also include <asm/asm-offsets.h> which, on arm64, is not necessary and redefines previously defined macros (resulting in warnings) so these includes are guarded by !CONFIG_ARM64. Link: https://lkml.kernel.org/r/[email protected] Reviewed-by: Mark Rutland <[email protected]> Tested-by: Mark Rutland <[email protected]> Acked-by: Catalin Marinas <[email protected]> Signed-off-by: Florent Revest <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 8564c31 commit 8c3526f

File tree

6 files changed

+151
-0
lines changed

6 files changed

+151
-0
lines changed

arch/arm64/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ config ARM64
197197
!CC_OPTIMIZE_FOR_SIZE)
198198
select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY \
199199
if DYNAMIC_FTRACE_WITH_ARGS
200+
select HAVE_SAMPLE_FTRACE_DIRECT
201+
select HAVE_SAMPLE_FTRACE_DIRECT_MULTI
200202
select HAVE_EFFICIENT_UNALIGNED_ACCESS
201203
select HAVE_FAST_GUP
202204
select HAVE_FTRACE_MCOUNT_RECORD

samples/ftrace/ftrace-direct-modify.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#include <linux/module.h>
33
#include <linux/kthread.h>
44
#include <linux/ftrace.h>
5+
#ifndef CONFIG_ARM64
56
#include <asm/asm-offsets.h>
7+
#endif
68

79
extern void my_direct_func1(void);
810
extern void my_direct_func2(void);
@@ -96,6 +98,38 @@ asm (
9698

9799
#endif /* CONFIG_S390 */
98100

101+
#ifdef CONFIG_ARM64
102+
103+
asm (
104+
" .pushsection .text, \"ax\", @progbits\n"
105+
" .type my_tramp1, @function\n"
106+
" .globl my_tramp1\n"
107+
" my_tramp1:"
108+
" bti c\n"
109+
" sub sp, sp, #16\n"
110+
" stp x9, x30, [sp]\n"
111+
" bl my_direct_func1\n"
112+
" ldp x30, x9, [sp]\n"
113+
" add sp, sp, #16\n"
114+
" ret x9\n"
115+
" .size my_tramp1, .-my_tramp1\n"
116+
117+
" .type my_tramp2, @function\n"
118+
" .globl my_tramp2\n"
119+
" my_tramp2:"
120+
" bti c\n"
121+
" sub sp, sp, #16\n"
122+
" stp x9, x30, [sp]\n"
123+
" bl my_direct_func2\n"
124+
" ldp x30, x9, [sp]\n"
125+
" add sp, sp, #16\n"
126+
" ret x9\n"
127+
" .size my_tramp2, .-my_tramp2\n"
128+
" .popsection\n"
129+
);
130+
131+
#endif /* CONFIG_ARM64 */
132+
99133
#ifdef CONFIG_LOONGARCH
100134

101135
asm (

samples/ftrace/ftrace-direct-multi-modify.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#include <linux/module.h>
33
#include <linux/kthread.h>
44
#include <linux/ftrace.h>
5+
#ifndef CONFIG_ARM64
56
#include <asm/asm-offsets.h>
7+
#endif
68

79
extern void my_direct_func1(unsigned long ip);
810
extern void my_direct_func2(unsigned long ip);
@@ -103,6 +105,44 @@ asm (
103105

104106
#endif /* CONFIG_S390 */
105107

108+
#ifdef CONFIG_ARM64
109+
110+
asm (
111+
" .pushsection .text, \"ax\", @progbits\n"
112+
" .type my_tramp1, @function\n"
113+
" .globl my_tramp1\n"
114+
" my_tramp1:"
115+
" bti c\n"
116+
" sub sp, sp, #32\n"
117+
" stp x9, x30, [sp]\n"
118+
" str x0, [sp, #16]\n"
119+
" mov x0, x30\n"
120+
" bl my_direct_func1\n"
121+
" ldp x30, x9, [sp]\n"
122+
" ldr x0, [sp, #16]\n"
123+
" add sp, sp, #32\n"
124+
" ret x9\n"
125+
" .size my_tramp1, .-my_tramp1\n"
126+
127+
" .type my_tramp2, @function\n"
128+
" .globl my_tramp2\n"
129+
" my_tramp2:"
130+
" bti c\n"
131+
" sub sp, sp, #32\n"
132+
" stp x9, x30, [sp]\n"
133+
" str x0, [sp, #16]\n"
134+
" mov x0, x30\n"
135+
" bl my_direct_func2\n"
136+
" ldp x30, x9, [sp]\n"
137+
" ldr x0, [sp, #16]\n"
138+
" add sp, sp, #32\n"
139+
" ret x9\n"
140+
" .size my_tramp2, .-my_tramp2\n"
141+
" .popsection\n"
142+
);
143+
144+
#endif /* CONFIG_ARM64 */
145+
106146
#ifdef CONFIG_LOONGARCH
107147
#include <asm/asm.h>
108148

samples/ftrace/ftrace-direct-multi.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include <linux/mm.h> /* for handle_mm_fault() */
55
#include <linux/ftrace.h>
66
#include <linux/sched/stat.h>
7+
#ifndef CONFIG_ARM64
78
#include <asm/asm-offsets.h>
9+
#endif
810

911
extern void my_direct_func(unsigned long ip);
1012

@@ -66,6 +68,29 @@ asm (
6668

6769
#endif /* CONFIG_S390 */
6870

71+
#ifdef CONFIG_ARM64
72+
73+
asm (
74+
" .pushsection .text, \"ax\", @progbits\n"
75+
" .type my_tramp, @function\n"
76+
" .globl my_tramp\n"
77+
" my_tramp:"
78+
" bti c\n"
79+
" sub sp, sp, #32\n"
80+
" stp x9, x30, [sp]\n"
81+
" str x0, [sp, #16]\n"
82+
" mov x0, x30\n"
83+
" bl my_direct_func\n"
84+
" ldp x30, x9, [sp]\n"
85+
" ldr x0, [sp, #16]\n"
86+
" add sp, sp, #32\n"
87+
" ret x9\n"
88+
" .size my_tramp, .-my_tramp\n"
89+
" .popsection\n"
90+
);
91+
92+
#endif /* CONFIG_ARM64 */
93+
6994
#ifdef CONFIG_LOONGARCH
7095

7196
#include <asm/asm.h>

samples/ftrace/ftrace-direct-too.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
#include <linux/mm.h> /* for handle_mm_fault() */
55
#include <linux/ftrace.h>
6+
#ifndef CONFIG_ARM64
67
#include <asm/asm-offsets.h>
8+
#endif
79

810
extern void my_direct_func(struct vm_area_struct *vma, unsigned long address,
911
unsigned int flags, struct pt_regs *regs);
@@ -72,6 +74,30 @@ asm (
7274

7375
#endif /* CONFIG_S390 */
7476

77+
#ifdef CONFIG_ARM64
78+
79+
asm (
80+
" .pushsection .text, \"ax\", @progbits\n"
81+
" .type my_tramp, @function\n"
82+
" .globl my_tramp\n"
83+
" my_tramp:"
84+
" bti c\n"
85+
" sub sp, sp, #48\n"
86+
" stp x9, x30, [sp]\n"
87+
" stp x0, x1, [sp, #16]\n"
88+
" stp x2, x3, [sp, #32]\n"
89+
" bl my_direct_func\n"
90+
" ldp x30, x9, [sp]\n"
91+
" ldp x0, x1, [sp, #16]\n"
92+
" ldp x2, x3, [sp, #32]\n"
93+
" add sp, sp, #48\n"
94+
" ret x9\n"
95+
" .size my_tramp, .-my_tramp\n"
96+
" .popsection\n"
97+
);
98+
99+
#endif /* CONFIG_ARM64 */
100+
75101
#ifdef CONFIG_LOONGARCH
76102

77103
asm (

samples/ftrace/ftrace-direct.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
#include <linux/sched.h> /* for wake_up_process() */
55
#include <linux/ftrace.h>
6+
#ifndef CONFIG_ARM64
67
#include <asm/asm-offsets.h>
8+
#endif
79

810
extern void my_direct_func(struct task_struct *p);
911

@@ -63,6 +65,28 @@ asm (
6365

6466
#endif /* CONFIG_S390 */
6567

68+
#ifdef CONFIG_ARM64
69+
70+
asm (
71+
" .pushsection .text, \"ax\", @progbits\n"
72+
" .type my_tramp, @function\n"
73+
" .globl my_tramp\n"
74+
" my_tramp:"
75+
" bti c\n"
76+
" sub sp, sp, #32\n"
77+
" stp x9, x30, [sp]\n"
78+
" str x0, [sp, #16]\n"
79+
" bl my_direct_func\n"
80+
" ldp x30, x9, [sp]\n"
81+
" ldr x0, [sp, #16]\n"
82+
" add sp, sp, #32\n"
83+
" ret x9\n"
84+
" .size my_tramp, .-my_tramp\n"
85+
" .popsection\n"
86+
);
87+
88+
#endif /* CONFIG_ARM64 */
89+
6690
#ifdef CONFIG_LOONGARCH
6791

6892
asm (

0 commit comments

Comments
 (0)