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