1 // SPDX-License-Identifier: GPL-2.0-only 2 #include <linux/module.h> 3 4 #include <linux/mm.h> /* for handle_mm_fault() */ 5 #include <linux/ftrace.h> 6 #include <linux/sched/stat.h> 7 8 void my_direct_func(unsigned long ip) 9 { 10 trace_printk("ip %lx\n", ip); 11 } 12 13 extern void my_tramp(void *); 14 15 asm ( 16 " .pushsection .text, \"ax\", @progbits\n" 17 " .type my_tramp, @function\n" 18 " .globl my_tramp\n" 19 " my_tramp:" 20 " pushq %rbp\n" 21 " movq %rsp, %rbp\n" 22 " pushq %rdi\n" 23 " movq 8(%rbp), %rdi\n" 24 " call my_direct_func\n" 25 " popq %rdi\n" 26 " leave\n" 27 " ret\n" 28 " .size my_tramp, .-my_tramp\n" 29 " .popsection\n" 30 ); 31 32 static struct ftrace_ops direct; 33 34 static int __init ftrace_direct_multi_init(void) 35 { 36 ftrace_set_filter_ip(&direct, (unsigned long) wake_up_process, 0, 0); 37 ftrace_set_filter_ip(&direct, (unsigned long) schedule, 0, 0); 38 39 return register_ftrace_direct_multi(&direct, (unsigned long) my_tramp); 40 } 41 42 static void __exit ftrace_direct_multi_exit(void) 43 { 44 unregister_ftrace_direct_multi(&direct, (unsigned long) my_tramp); 45 } 46 47 module_init(ftrace_direct_multi_init); 48 module_exit(ftrace_direct_multi_exit); 49 50 MODULE_AUTHOR("Jiri Olsa"); 51 MODULE_DESCRIPTION("Example use case of using register_ftrace_direct_multi()"); 52 MODULE_LICENSE("GPL"); 53