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 <asm/asm-offsets.h>
8 extern void my_direct_func(struct vm_area_struct *vma,
9 unsigned long address, unsigned int flags);
11 void my_direct_func(struct vm_area_struct *vma,
12 unsigned long address, unsigned int flags)
14 trace_printk("handle mm fault vma=%p address=%lx flags=%x\n",
18 extern void my_tramp(void *);
23 #include <asm/nospec-branch.h>
26 " .pushsection .text, \"ax\", @progbits\n"
27 " .type my_tramp, @function\n"
37 " call my_direct_func\n"
43 " .size my_tramp, .-my_tramp\n"
47 #endif /* CONFIG_X86_64 */
52 " .pushsection .text, \"ax\", @progbits\n"
53 " .type my_tramp, @function\n"
57 " stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
58 " stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
59 " aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n"
60 " stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n"
61 " brasl %r14,my_direct_func\n"
62 " aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n"
63 " lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
64 " lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
67 " .size my_tramp, .-my_tramp\n"
71 #endif /* CONFIG_S390 */
73 #ifdef CONFIG_LOONGARCH
76 " .pushsection .text, \"ax\", @progbits\n"
77 " .type my_tramp, @function\n"
80 " addi.d $sp, $sp, -48\n"
83 " st.d $a2, $sp, 16\n"
84 " st.d $t0, $sp, 24\n"
85 " st.d $ra, $sp, 32\n"
86 " bl my_direct_func\n"
89 " ld.d $a2, $sp, 16\n"
90 " ld.d $t0, $sp, 24\n"
91 " ld.d $ra, $sp, 32\n"
92 " addi.d $sp, $sp, 48\n"
94 " .size my_tramp, .-my_tramp\n"
98 #endif /* CONFIG_LOONGARCH */
100 static struct ftrace_ops direct;
102 static int __init ftrace_direct_init(void)
104 ftrace_set_filter_ip(&direct, (unsigned long) handle_mm_fault, 0, 0);
106 return register_ftrace_direct(&direct, (unsigned long) my_tramp);
109 static void __exit ftrace_direct_exit(void)
111 unregister_ftrace_direct(&direct, (unsigned long)my_tramp, true);
114 module_init(ftrace_direct_init);
115 module_exit(ftrace_direct_exit);
117 MODULE_AUTHOR("Steven Rostedt");
118 MODULE_DESCRIPTION("Another example use case of using register_ftrace_direct()");
119 MODULE_LICENSE("GPL");