Steven Rostedt (VMware) | b06457c | 2019-11-08 13:12:33 -0500 | [diff] [blame] | 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> |
Heiko Carstens | 1254cfbc | 2021-10-12 15:38:02 +0200 | [diff] [blame^] | 6 | #include <asm/asm-offsets.h> |
Steven Rostedt (VMware) | b06457c | 2019-11-08 13:12:33 -0500 | [diff] [blame] | 7 | |
| 8 | void my_direct_func(struct task_struct *p) |
| 9 | { |
Colin Ian King | 760f8bc | 2019-11-15 08:59:38 +0000 | [diff] [blame] | 10 | trace_printk("waking up %s-%d\n", p->comm, p->pid); |
Steven Rostedt (VMware) | b06457c | 2019-11-08 13:12:33 -0500 | [diff] [blame] | 11 | } |
| 12 | |
| 13 | extern void my_tramp(void *); |
| 14 | |
Heiko Carstens | 1254cfbc | 2021-10-12 15:38:02 +0200 | [diff] [blame^] | 15 | #ifdef CONFIG_X86_64 |
| 16 | |
Steven Rostedt (VMware) | b06457c | 2019-11-08 13:12:33 -0500 | [diff] [blame] | 17 | asm ( |
| 18 | " .pushsection .text, \"ax\", @progbits\n" |
Josh Poimboeuf | 9d907f1 | 2020-04-24 15:40:43 -0500 | [diff] [blame] | 19 | " .type my_tramp, @function\n" |
Sami Tolvanen | 983df5f | 2020-11-13 10:34:14 -0800 | [diff] [blame] | 20 | " .globl my_tramp\n" |
Steven Rostedt (VMware) | b06457c | 2019-11-08 13:12:33 -0500 | [diff] [blame] | 21 | " my_tramp:" |
| 22 | " pushq %rbp\n" |
| 23 | " movq %rsp, %rbp\n" |
| 24 | " pushq %rdi\n" |
| 25 | " call my_direct_func\n" |
| 26 | " popq %rdi\n" |
| 27 | " leave\n" |
| 28 | " ret\n" |
Josh Poimboeuf | 9d907f1 | 2020-04-24 15:40:43 -0500 | [diff] [blame] | 29 | " .size my_tramp, .-my_tramp\n" |
Steven Rostedt (VMware) | b06457c | 2019-11-08 13:12:33 -0500 | [diff] [blame] | 30 | " .popsection\n" |
| 31 | ); |
| 32 | |
Heiko Carstens | 1254cfbc | 2021-10-12 15:38:02 +0200 | [diff] [blame^] | 33 | #endif /* CONFIG_X86_64 */ |
| 34 | |
| 35 | #ifdef CONFIG_S390 |
| 36 | |
| 37 | asm ( |
| 38 | " .pushsection .text, \"ax\", @progbits\n" |
| 39 | " .type my_tramp, @function\n" |
| 40 | " .globl my_tramp\n" |
| 41 | " my_tramp:" |
| 42 | " lgr %r1,%r15\n" |
| 43 | " stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n" |
| 44 | " stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n" |
| 45 | " aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n" |
| 46 | " stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n" |
| 47 | " brasl %r14,my_direct_func\n" |
| 48 | " aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n" |
| 49 | " lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n" |
| 50 | " lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n" |
| 51 | " lgr %r1,%r0\n" |
| 52 | " br %r1\n" |
| 53 | " .size my_tramp, .-my_tramp\n" |
| 54 | " .popsection\n" |
| 55 | ); |
| 56 | |
| 57 | #endif /* CONFIG_S390 */ |
Steven Rostedt (VMware) | b06457c | 2019-11-08 13:12:33 -0500 | [diff] [blame] | 58 | |
| 59 | static int __init ftrace_direct_init(void) |
| 60 | { |
| 61 | return register_ftrace_direct((unsigned long)wake_up_process, |
| 62 | (unsigned long)my_tramp); |
| 63 | } |
| 64 | |
| 65 | static void __exit ftrace_direct_exit(void) |
| 66 | { |
| 67 | unregister_ftrace_direct((unsigned long)wake_up_process, |
| 68 | (unsigned long)my_tramp); |
| 69 | } |
| 70 | |
| 71 | module_init(ftrace_direct_init); |
| 72 | module_exit(ftrace_direct_exit); |
| 73 | |
| 74 | MODULE_AUTHOR("Steven Rostedt"); |
| 75 | MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()"); |
| 76 | MODULE_LICENSE("GPL"); |