1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/module.h>
4 #include <linux/mm.h> /* for handle_mm_fault() */
5 #include <linux/ftrace.h>
6 #include <linux/sched/stat.h>
8 #include <asm/asm-offsets.h>
11 extern void my_direct_func(unsigned long ip);
13 void my_direct_func(unsigned long ip)
15 trace_printk("ip %lx\n", ip);
18 extern void my_tramp(void *);
23 #include <asm/nospec-branch.h>
26 " .pushsection .text, \"ax\", @progbits\n"
27 " .type my_tramp, @function\n"
35 " movq 8(%rbp), %rdi\n"
36 " call my_direct_func\n"
40 " .size my_tramp, .-my_tramp\n"
44 #endif /* CONFIG_X86_64 */
49 " .pushsection .text, \"ax\", @progbits\n"
50 " .type my_tramp, @function\n"
54 " stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
55 " stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
56 " aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n"
57 " stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n"
59 " brasl %r14,my_direct_func\n"
60 " aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n"
61 " lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
62 " lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
65 " .size my_tramp, .-my_tramp\n"
69 #endif /* CONFIG_S390 */
74 " .pushsection .text, \"ax\", @progbits\n"
75 " .type my_tramp, @function\n"
80 " stp x9, x30, [sp]\n"
81 " str x0, [sp, #16]\n"
83 " bl my_direct_func\n"
84 " ldp x30, x9, [sp]\n"
85 " ldr x0, [sp, #16]\n"
88 " .size my_tramp, .-my_tramp\n"
92 #endif /* CONFIG_ARM64 */
94 #ifdef CONFIG_LOONGARCH
98 " .pushsection .text, \"ax\", @progbits\n"
99 " .type my_tramp, @function\n"
102 " addi.d $sp, $sp, -32\n"
103 " st.d $a0, $sp, 0\n"
104 " st.d $t0, $sp, 8\n"
105 " st.d $ra, $sp, 16\n"
107 " bl my_direct_func\n"
108 " ld.d $a0, $sp, 0\n"
109 " ld.d $t0, $sp, 8\n"
110 " ld.d $ra, $sp, 16\n"
111 " addi.d $sp, $sp, 32\n"
113 " .size my_tramp, .-my_tramp\n"
117 #endif /* CONFIG_LOONGARCH */
119 static struct ftrace_ops direct;
121 static int __init ftrace_direct_multi_init(void)
123 ftrace_set_filter_ip(&direct, (unsigned long) wake_up_process, 0, 0);
124 ftrace_set_filter_ip(&direct, (unsigned long) schedule, 0, 0);
126 return register_ftrace_direct(&direct, (unsigned long) my_tramp);
129 static void __exit ftrace_direct_multi_exit(void)
131 unregister_ftrace_direct(&direct, (unsigned long) my_tramp, true);
134 module_init(ftrace_direct_multi_init);
135 module_exit(ftrace_direct_multi_exit);
137 MODULE_AUTHOR("Jiri Olsa");
138 MODULE_DESCRIPTION("Example use case of using register_ftrace_direct_multi()");
139 MODULE_LICENSE("GPL");