Commit | Line | Data |
---|---|---|
b06457c8 SRV |
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> | |
8c3526fb | 6 | #ifndef CONFIG_ARM64 |
1254cfbc | 7 | #include <asm/asm-offsets.h> |
8c3526fb | 8 | #endif |
b06457c8 | 9 | |
0daf5cb2 JO |
10 | extern void my_direct_func(struct task_struct *p); |
11 | ||
b06457c8 SRV |
12 | void my_direct_func(struct task_struct *p) |
13 | { | |
760f8bc7 | 14 | trace_printk("waking up %s-%d\n", p->comm, p->pid); |
b06457c8 SRV |
15 | } |
16 | ||
17 | extern void my_tramp(void *); | |
18 | ||
1254cfbc HC |
19 | #ifdef CONFIG_X86_64 |
20 | ||
0aec21cf | 21 | #include <asm/ibt.h> |
01678fbc | 22 | #include <asm/nospec-branch.h> |
0aec21cf | 23 | |
b06457c8 SRV |
24 | asm ( |
25 | " .pushsection .text, \"ax\", @progbits\n" | |
9d907f1a | 26 | " .type my_tramp, @function\n" |
983df5f2 | 27 | " .globl my_tramp\n" |
b06457c8 | 28 | " my_tramp:" |
0aec21cf | 29 | ASM_ENDBR |
b06457c8 SRV |
30 | " pushq %rbp\n" |
31 | " movq %rsp, %rbp\n" | |
ee3e2469 | 32 | CALL_DEPTH_ACCOUNT |
b06457c8 SRV |
33 | " pushq %rdi\n" |
34 | " call my_direct_func\n" | |
35 | " popq %rdi\n" | |
36 | " leave\n" | |
b17c2baa | 37 | ASM_RET |
9d907f1a | 38 | " .size my_tramp, .-my_tramp\n" |
b06457c8 SRV |
39 | " .popsection\n" |
40 | ); | |
41 | ||
1254cfbc HC |
42 | #endif /* CONFIG_X86_64 */ |
43 | ||
44 | #ifdef CONFIG_S390 | |
45 | ||
46 | asm ( | |
47 | " .pushsection .text, \"ax\", @progbits\n" | |
48 | " .type my_tramp, @function\n" | |
49 | " .globl my_tramp\n" | |
50 | " my_tramp:" | |
51 | " lgr %r1,%r15\n" | |
52 | " stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n" | |
53 | " stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n" | |
54 | " aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n" | |
55 | " stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n" | |
56 | " brasl %r14,my_direct_func\n" | |
57 | " aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n" | |
58 | " lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n" | |
59 | " lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n" | |
60 | " lgr %r1,%r0\n" | |
61 | " br %r1\n" | |
62 | " .size my_tramp, .-my_tramp\n" | |
63 | " .popsection\n" | |
64 | ); | |
65 | ||
66 | #endif /* CONFIG_S390 */ | |
b06457c8 | 67 | |
8c3526fb FR |
68 | #ifdef CONFIG_ARM64 |
69 | ||
70 | asm ( | |
71 | " .pushsection .text, \"ax\", @progbits\n" | |
72 | " .type my_tramp, @function\n" | |
73 | " .globl my_tramp\n" | |
74 | " my_tramp:" | |
e332938e | 75 | " hint 34\n" // bti c |
8c3526fb FR |
76 | " sub sp, sp, #32\n" |
77 | " stp x9, x30, [sp]\n" | |
78 | " str x0, [sp, #16]\n" | |
79 | " bl my_direct_func\n" | |
80 | " ldp x30, x9, [sp]\n" | |
81 | " ldr x0, [sp, #16]\n" | |
82 | " add sp, sp, #32\n" | |
83 | " ret x9\n" | |
84 | " .size my_tramp, .-my_tramp\n" | |
85 | " .popsection\n" | |
86 | ); | |
87 | ||
88 | #endif /* CONFIG_ARM64 */ | |
89 | ||
22f367a6 YT |
90 | #ifdef CONFIG_LOONGARCH |
91 | ||
92 | asm ( | |
93 | " .pushsection .text, \"ax\", @progbits\n" | |
94 | " .type my_tramp, @function\n" | |
95 | " .globl my_tramp\n" | |
96 | " my_tramp:\n" | |
97 | " addi.d $sp, $sp, -32\n" | |
98 | " st.d $a0, $sp, 0\n" | |
99 | " st.d $t0, $sp, 8\n" | |
100 | " st.d $ra, $sp, 16\n" | |
101 | " bl my_direct_func\n" | |
102 | " ld.d $a0, $sp, 0\n" | |
103 | " ld.d $t0, $sp, 8\n" | |
104 | " ld.d $ra, $sp, 16\n" | |
105 | " addi.d $sp, $sp, 32\n" | |
106 | " jr $t0\n" | |
107 | " .size my_tramp, .-my_tramp\n" | |
108 | " .popsection\n" | |
109 | ); | |
110 | ||
111 | #endif /* CONFIG_LOONGARCH */ | |
112 | ||
23edf483 FR |
113 | static struct ftrace_ops direct; |
114 | ||
b06457c8 SRV |
115 | static int __init ftrace_direct_init(void) |
116 | { | |
23edf483 FR |
117 | ftrace_set_filter_ip(&direct, (unsigned long) wake_up_process, 0, 0); |
118 | ||
da8bdfbd | 119 | return register_ftrace_direct(&direct, (unsigned long) my_tramp); |
b06457c8 SRV |
120 | } |
121 | ||
122 | static void __exit ftrace_direct_exit(void) | |
123 | { | |
da8bdfbd | 124 | unregister_ftrace_direct(&direct, (unsigned long)my_tramp, true); |
b06457c8 SRV |
125 | } |
126 | ||
127 | module_init(ftrace_direct_init); | |
128 | module_exit(ftrace_direct_exit); | |
129 | ||
130 | MODULE_AUTHOR("Steven Rostedt"); | |
da8bdfbd | 131 | MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()"); |
b06457c8 | 132 | MODULE_LICENSE("GPL"); |