1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/module.h>
4 #include <linux/sched.h> /* for wake_up_process() */
5 #include <linux/ftrace.h>
7 #include <asm/asm-offsets.h>
10 extern void my_direct_func(struct task_struct *p);
12 void my_direct_func(struct task_struct *p)
14 trace_printk("waking up %s-%d\n", p->comm, p->pid);
17 extern void my_tramp(void *);
22 #include <asm/nospec-branch.h>
25 " .pushsection .text, \"ax\", @progbits\n"
26 " .type my_tramp, @function\n"
34 " call my_direct_func\n"
38 " .size my_tramp, .-my_tramp\n"
42 #endif /* CONFIG_X86_64 */
47 " .pushsection .text, \"ax\", @progbits\n"
48 " .type my_tramp, @function\n"
52 " stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
53 " stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
54 " aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n"
55 " stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n"
56 " brasl %r14,my_direct_func\n"
57 " aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n"
58 " lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
59 " lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
62 " .size my_tramp, .-my_tramp\n"
66 #endif /* CONFIG_S390 */
71 " .pushsection .text, \"ax\", @progbits\n"
72 " .type my_tramp, @function\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"
84 " .size my_tramp, .-my_tramp\n"
88 #endif /* CONFIG_ARM64 */
90 #ifdef CONFIG_LOONGARCH
93 " .pushsection .text, \"ax\", @progbits\n"
94 " .type my_tramp, @function\n"
97 " addi.d $sp, $sp, -32\n"
100 " st.d $ra, $sp, 16\n"
101 " bl my_direct_func\n"
102 " ld.d $a0, $sp, 0\n"
103 " ld.d $t0, $sp, 8\n"
104 " ld.d $ra, $sp, 16\n"
105 " addi.d $sp, $sp, 32\n"
107 " .size my_tramp, .-my_tramp\n"
111 #endif /* CONFIG_LOONGARCH */
113 static struct ftrace_ops direct;
115 static int __init ftrace_direct_init(void)
117 ftrace_set_filter_ip(&direct, (unsigned long) wake_up_process, 0, 0);
119 return register_ftrace_direct(&direct, (unsigned long) my_tramp);
122 static void __exit ftrace_direct_exit(void)
124 unregister_ftrace_direct(&direct, (unsigned long)my_tramp, true);
127 module_init(ftrace_direct_init);
128 module_exit(ftrace_direct_exit);
130 MODULE_AUTHOR("Steven Rostedt");
131 MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()");
132 MODULE_LICENSE("GPL");