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>
6 #include <asm/asm-offsets.h>
8 extern void my_direct_func(struct task_struct *p);
10 void my_direct_func(struct task_struct *p)
12 trace_printk("waking up %s-%d\n", p->comm, p->pid);
15 extern void my_tramp(void *);
20 #include <asm/nospec-branch.h>
23 " .pushsection .text, \"ax\", @progbits\n"
24 " .type my_tramp, @function\n"
32 " call my_direct_func\n"
36 " .size my_tramp, .-my_tramp\n"
40 #endif /* CONFIG_X86_64 */
45 " .pushsection .text, \"ax\", @progbits\n"
46 " .type my_tramp, @function\n"
50 " stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
51 " stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
52 " aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n"
53 " stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n"
54 " brasl %r14,my_direct_func\n"
55 " aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n"
56 " lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
57 " lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
60 " .size my_tramp, .-my_tramp\n"
64 #endif /* CONFIG_S390 */
66 #ifdef CONFIG_LOONGARCH
69 " .pushsection .text, \"ax\", @progbits\n"
70 " .type my_tramp, @function\n"
73 " addi.d $sp, $sp, -32\n"
76 " st.d $ra, $sp, 16\n"
77 " bl my_direct_func\n"
80 " ld.d $ra, $sp, 16\n"
81 " addi.d $sp, $sp, 32\n"
83 " .size my_tramp, .-my_tramp\n"
87 #endif /* CONFIG_LOONGARCH */
89 static struct ftrace_ops direct;
91 static int __init ftrace_direct_init(void)
93 ftrace_set_filter_ip(&direct, (unsigned long) wake_up_process, 0, 0);
95 return register_ftrace_direct(&direct, (unsigned long) my_tramp);
98 static void __exit ftrace_direct_exit(void)
100 unregister_ftrace_direct(&direct, (unsigned long)my_tramp, true);
103 module_init(ftrace_direct_init);
104 module_exit(ftrace_direct_exit);
106 MODULE_AUTHOR("Steven Rostedt");
107 MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()");
108 MODULE_LICENSE("GPL");