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 *);
23 " .pushsection .text, \"ax\", @progbits\n"
24 " .type my_tramp, @function\n"
27 " addi sp,sp,-3*"SZREG
"\n"
28 " "REG_S
" a0,0*"SZREG
"(sp)\n"
29 " "REG_S
" t0,1*"SZREG
"(sp)\n"
30 " "REG_S
" ra,2*"SZREG
"(sp)\n"
31 " call my_direct_func\n"
32 " "REG_L
" a0,0*"SZREG
"(sp)\n"
33 " "REG_L
" t0,1*"SZREG
"(sp)\n"
34 " "REG_L
" ra,2*"SZREG
"(sp)\n"
35 " addi sp,sp,3*"SZREG
"\n"
37 " .size my_tramp, .-my_tramp\n"
41 #endif /* CONFIG_RISCV */
46 #include <asm/nospec-branch.h>
49 " .pushsection .text, \"ax\", @progbits\n"
50 " .type my_tramp, @function\n"
58 " call my_direct_func\n"
62 " .size my_tramp, .-my_tramp\n"
66 #endif /* CONFIG_X86_64 */
71 " .pushsection .text, \"ax\", @progbits\n"
72 " .type my_tramp, @function\n"
76 " stmg %r0,%r5,"__stringify(__SF_GPRS
)"(%r15)\n"
77 " stg %r14,"__stringify(__SF_GPRS
+8*8)"(%r15)\n"
78 " aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD
)"\n"
79 " stg %r1,"__stringify(__SF_BACKCHAIN
)"(%r15)\n"
80 " brasl %r14,my_direct_func\n"
81 " aghi %r15,"__stringify(STACK_FRAME_OVERHEAD
)"\n"
82 " lmg %r0,%r5,"__stringify(__SF_GPRS
)"(%r15)\n"
83 " lg %r14,"__stringify(__SF_GPRS
+8*8)"(%r15)\n"
86 " .size my_tramp, .-my_tramp\n"
90 #endif /* CONFIG_S390 */
95 " .pushsection .text, \"ax\", @progbits\n"
96 " .type my_tramp, @function\n"
101 " stp x9, x30, [sp]\n"
102 " str x0, [sp, #16]\n"
103 " bl my_direct_func\n"
104 " ldp x30, x9, [sp]\n"
105 " ldr x0, [sp, #16]\n"
108 " .size my_tramp, .-my_tramp\n"
112 #endif /* CONFIG_ARM64 */
114 #ifdef CONFIG_LOONGARCH
117 " .pushsection .text, \"ax\", @progbits\n"
118 " .type my_tramp, @function\n"
121 " addi.d $sp, $sp, -32\n"
122 " st.d $a0, $sp, 0\n"
123 " st.d $t0, $sp, 8\n"
124 " st.d $ra, $sp, 16\n"
125 " bl my_direct_func\n"
126 " ld.d $a0, $sp, 0\n"
127 " ld.d $t0, $sp, 8\n"
128 " ld.d $ra, $sp, 16\n"
129 " addi.d $sp, $sp, 32\n"
131 " .size my_tramp, .-my_tramp\n"
135 #endif /* CONFIG_LOONGARCH */
137 static struct ftrace_ops direct
;
139 static int __init
ftrace_direct_init(void)
141 ftrace_set_filter_ip(&direct
, (unsigned long) wake_up_process
, 0, 0);
143 return register_ftrace_direct(&direct
, (unsigned long) my_tramp
);
146 static void __exit
ftrace_direct_exit(void)
148 unregister_ftrace_direct(&direct
, (unsigned long)my_tramp
, true);
151 module_init(ftrace_direct_init
);
152 module_exit(ftrace_direct_exit
);
154 MODULE_AUTHOR("Steven Rostedt");
155 MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()");
156 MODULE_LICENSE("GPL");