Merge tag 'percpu-for-6.6' of git://git.kernel.org/pub/scm/linux/kernel/git/dennis...
[linux-2.6-block.git] / samples / ftrace / ftrace-direct-too.c
CommitLineData
156473a0
SRV
1// SPDX-License-Identifier: GPL-2.0-only
2#include <linux/module.h>
3
4#include <linux/mm.h> /* for handle_mm_fault() */
5#include <linux/ftrace.h>
8c3526fb 6#ifndef CONFIG_ARM64
1254cfbc 7#include <asm/asm-offsets.h>
8c3526fb 8#endif
156473a0 9
8564c315
FR
10extern void my_direct_func(struct vm_area_struct *vma, unsigned long address,
11 unsigned int flags, struct pt_regs *regs);
0daf5cb2 12
8564c315
FR
13void my_direct_func(struct vm_area_struct *vma, unsigned long address,
14 unsigned int flags, struct pt_regs *regs)
156473a0 15{
8564c315
FR
16 trace_printk("handle mm fault vma=%p address=%lx flags=%x regs=%p\n",
17 vma, address, flags, regs);
156473a0
SRV
18}
19
20extern void my_tramp(void *);
21
1254cfbc
HC
22#ifdef CONFIG_X86_64
23
0aec21cf 24#include <asm/ibt.h>
01678fbc 25#include <asm/nospec-branch.h>
0aec21cf 26
156473a0
SRV
27asm (
28" .pushsection .text, \"ax\", @progbits\n"
9d907f1a 29" .type my_tramp, @function\n"
983df5f2 30" .globl my_tramp\n"
156473a0 31" my_tramp:"
0aec21cf 32 ASM_ENDBR
156473a0
SRV
33" pushq %rbp\n"
34" movq %rsp, %rbp\n"
ee3e2469 35 CALL_DEPTH_ACCOUNT
156473a0
SRV
36" pushq %rdi\n"
37" pushq %rsi\n"
38" pushq %rdx\n"
8564c315 39" pushq %rcx\n"
156473a0 40" call my_direct_func\n"
8564c315 41" popq %rcx\n"
156473a0
SRV
42" popq %rdx\n"
43" popq %rsi\n"
44" popq %rdi\n"
45" leave\n"
b17c2baa 46 ASM_RET
9d907f1a 47" .size my_tramp, .-my_tramp\n"
156473a0
SRV
48" .popsection\n"
49);
50
1254cfbc
HC
51#endif /* CONFIG_X86_64 */
52
53#ifdef CONFIG_S390
54
55asm (
56" .pushsection .text, \"ax\", @progbits\n"
57" .type my_tramp, @function\n"
58" .globl my_tramp\n"
59" my_tramp:"
60" lgr %r1,%r15\n"
61" stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
62" stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
63" aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n"
64" stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n"
65" brasl %r14,my_direct_func\n"
66" aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n"
67" lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
68" lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
69" lgr %r1,%r0\n"
70" br %r1\n"
71" .size my_tramp, .-my_tramp\n"
72" .popsection\n"
73);
74
75#endif /* CONFIG_S390 */
156473a0 76
8c3526fb
FR
77#ifdef CONFIG_ARM64
78
79asm (
80" .pushsection .text, \"ax\", @progbits\n"
81" .type my_tramp, @function\n"
82" .globl my_tramp\n"
83" my_tramp:"
e332938e 84" hint 34\n" // bti c
8c3526fb
FR
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
22f367a6
YT
101#ifdef CONFIG_LOONGARCH
102
103asm (
104" .pushsection .text, \"ax\", @progbits\n"
105" .type my_tramp, @function\n"
106" .globl my_tramp\n"
107" my_tramp:\n"
108" addi.d $sp, $sp, -48\n"
109" st.d $a0, $sp, 0\n"
110" st.d $a1, $sp, 8\n"
111" st.d $a2, $sp, 16\n"
112" st.d $t0, $sp, 24\n"
113" st.d $ra, $sp, 32\n"
114" bl my_direct_func\n"
115" ld.d $a0, $sp, 0\n"
116" ld.d $a1, $sp, 8\n"
117" ld.d $a2, $sp, 16\n"
118" ld.d $t0, $sp, 24\n"
119" ld.d $ra, $sp, 32\n"
120" addi.d $sp, $sp, 48\n"
121" jr $t0\n"
122" .size my_tramp, .-my_tramp\n"
123" .popsection\n"
124);
125
126#endif /* CONFIG_LOONGARCH */
127
23edf483
FR
128static struct ftrace_ops direct;
129
156473a0
SRV
130static int __init ftrace_direct_init(void)
131{
23edf483
FR
132 ftrace_set_filter_ip(&direct, (unsigned long) handle_mm_fault, 0, 0);
133
da8bdfbd 134 return register_ftrace_direct(&direct, (unsigned long) my_tramp);
156473a0
SRV
135}
136
137static void __exit ftrace_direct_exit(void)
138{
da8bdfbd 139 unregister_ftrace_direct(&direct, (unsigned long)my_tramp, true);
156473a0
SRV
140}
141
142module_init(ftrace_direct_init);
143module_exit(ftrace_direct_exit);
144
145MODULE_AUTHOR("Steven Rostedt");
da8bdfbd 146MODULE_DESCRIPTION("Another example use case of using register_ftrace_direct()");
156473a0 147MODULE_LICENSE("GPL");