~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/samples/ftrace/ftrace-direct.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 #include <linux/module.h>
  3 
  4 #include <linux/sched.h> /* for wake_up_process() */
  5 #include <linux/ftrace.h>
  6 #ifndef CONFIG_ARM64
  7 #include <asm/asm-offsets.h>
  8 #endif
  9 
 10 extern void my_direct_func(struct task_struct *p);
 11 
 12 void my_direct_func(struct task_struct *p)
 13 {
 14         trace_printk("waking up %s-%d\n", p->comm, p->pid);
 15 }
 16 
 17 extern void my_tramp(void *);
 18 
 19 #ifdef CONFIG_RISCV
 20 #include <asm/asm.h>
 21 
 22 asm (
 23 "       .pushsection    .text, \"ax\", @progbits\n"
 24 "       .type           my_tramp, @function\n"
 25 "       .globl          my_tramp\n"
 26 "   my_tramp:\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"
 36 "       jr      t0\n"
 37 "       .size           my_tramp, .-my_tramp\n"
 38 "       .popsection\n"
 39 );
 40 
 41 #endif /* CONFIG_RISCV */
 42 
 43 #ifdef CONFIG_X86_64
 44 
 45 #include <asm/ibt.h>
 46 #include <asm/nospec-branch.h>
 47 
 48 asm (
 49 "       .pushsection    .text, \"ax\", @progbits\n"
 50 "       .type           my_tramp, @function\n"
 51 "       .globl          my_tramp\n"
 52 "   my_tramp:"
 53         ASM_ENDBR
 54 "       pushq %rbp\n"
 55 "       movq %rsp, %rbp\n"
 56         CALL_DEPTH_ACCOUNT
 57 "       pushq %rdi\n"
 58 "       call my_direct_func\n"
 59 "       popq %rdi\n"
 60 "       leave\n"
 61         ASM_RET
 62 "       .size           my_tramp, .-my_tramp\n"
 63 "       .popsection\n"
 64 );
 65 
 66 #endif /* CONFIG_X86_64 */
 67 
 68 #ifdef CONFIG_S390
 69 
 70 asm (
 71 "       .pushsection    .text, \"ax\", @progbits\n"
 72 "       .type           my_tramp, @function\n"
 73 "       .globl          my_tramp\n"
 74 "   my_tramp:"
 75 "       lgr             %r1,%r15\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"
 84 "       lgr             %r1,%r0\n"
 85 "       br              %r1\n"
 86 "       .size           my_tramp, .-my_tramp\n"
 87 "       .popsection\n"
 88 );
 89 
 90 #endif /* CONFIG_S390 */
 91 
 92 #ifdef CONFIG_ARM64
 93 
 94 asm (
 95 "       .pushsection    .text, \"ax\", @progbits\n"
 96 "       .type           my_tramp, @function\n"
 97 "       .globl          my_tramp\n"
 98 "   my_tramp:"
 99 "       hint    34\n" // bti    c
100 "       sub     sp, sp, #32\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"
106 "       add     sp, sp, #32\n"
107 "       ret     x9\n"
108 "       .size           my_tramp, .-my_tramp\n"
109 "       .popsection\n"
110 );
111 
112 #endif /* CONFIG_ARM64 */
113 
114 #ifdef CONFIG_LOONGARCH
115 
116 asm (
117 "       .pushsection    .text, \"ax\", @progbits\n"
118 "       .type           my_tramp, @function\n"
119 "       .globl          my_tramp\n"
120 "   my_tramp:\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"
130 "       jr      $t0\n"
131 "       .size           my_tramp, .-my_tramp\n"
132 "       .popsection\n"
133 );
134 
135 #endif /* CONFIG_LOONGARCH */
136 
137 static struct ftrace_ops direct;
138 
139 static int __init ftrace_direct_init(void)
140 {
141         ftrace_set_filter_ip(&direct, (unsigned long) wake_up_process, 0, 0);
142 
143         return register_ftrace_direct(&direct, (unsigned long) my_tramp);
144 }
145 
146 static void __exit ftrace_direct_exit(void)
147 {
148         unregister_ftrace_direct(&direct, (unsigned long)my_tramp, true);
149 }
150 
151 module_init(ftrace_direct_init);
152 module_exit(ftrace_direct_exit);
153 
154 MODULE_AUTHOR("Steven Rostedt");
155 MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()");
156 MODULE_LICENSE("GPL");
157 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php