0001
0002 #include <linux/module.h>
0003
0004 #include <linux/mm.h> /* for handle_mm_fault() */
0005 #include <linux/ftrace.h>
0006 #include <linux/sched/stat.h>
0007 #include <asm/asm-offsets.h>
0008
0009 extern void my_direct_func(unsigned long ip);
0010
0011 void my_direct_func(unsigned long ip)
0012 {
0013 trace_printk("ip %lx\n", ip);
0014 }
0015
0016 extern void my_tramp(void *);
0017
0018 #ifdef CONFIG_X86_64
0019
0020 #include <asm/ibt.h>
0021
0022 asm (
0023 " .pushsection .text, \"ax\", @progbits\n"
0024 " .type my_tramp, @function\n"
0025 " .globl my_tramp\n"
0026 " my_tramp:"
0027 ASM_ENDBR
0028 " pushq %rbp\n"
0029 " movq %rsp, %rbp\n"
0030 " pushq %rdi\n"
0031 " movq 8(%rbp), %rdi\n"
0032 " call my_direct_func\n"
0033 " popq %rdi\n"
0034 " leave\n"
0035 ASM_RET
0036 " .size my_tramp, .-my_tramp\n"
0037 " .popsection\n"
0038 );
0039
0040 #endif
0041
0042 #ifdef CONFIG_S390
0043
0044 asm (
0045 " .pushsection .text, \"ax\", @progbits\n"
0046 " .type my_tramp, @function\n"
0047 " .globl my_tramp\n"
0048 " my_tramp:"
0049 " lgr %r1,%r15\n"
0050 " stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
0051 " stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
0052 " aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n"
0053 " stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n"
0054 " lgr %r2,%r0\n"
0055 " brasl %r14,my_direct_func\n"
0056 " aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n"
0057 " lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
0058 " lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
0059 " lgr %r1,%r0\n"
0060 " br %r1\n"
0061 " .size my_tramp, .-my_tramp\n"
0062 " .popsection\n"
0063 );
0064
0065 #endif
0066
0067 static struct ftrace_ops direct;
0068
0069 static int __init ftrace_direct_multi_init(void)
0070 {
0071 ftrace_set_filter_ip(&direct, (unsigned long) wake_up_process, 0, 0);
0072 ftrace_set_filter_ip(&direct, (unsigned long) schedule, 0, 0);
0073
0074 return register_ftrace_direct_multi(&direct, (unsigned long) my_tramp);
0075 }
0076
0077 static void __exit ftrace_direct_multi_exit(void)
0078 {
0079 unregister_ftrace_direct_multi(&direct, (unsigned long) my_tramp);
0080 }
0081
0082 module_init(ftrace_direct_multi_init);
0083 module_exit(ftrace_direct_multi_exit);
0084
0085 MODULE_AUTHOR("Jiri Olsa");
0086 MODULE_DESCRIPTION("Example use case of using register_ftrace_direct_multi()");
0087 MODULE_LICENSE("GPL");