blob: 8b551e503a48e310183ac9cfa5f94f4cc6dd9d1b [file] [log] [blame]
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -05001// 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 Carstens1254cfbc2021-10-12 15:38:02 +02006#include <asm/asm-offsets.h>
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -05007
Jiri Olsa0daf5cb2021-12-19 14:53:17 +01008extern void my_direct_func(struct task_struct *p);
9
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -050010void my_direct_func(struct task_struct *p)
11{
Colin Ian King760f8bc2019-11-15 08:59:38 +000012 trace_printk("waking up %s-%d\n", p->comm, p->pid);
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -050013}
14
15extern void my_tramp(void *);
16
Heiko Carstens1254cfbc2021-10-12 15:38:02 +020017#ifdef CONFIG_X86_64
18
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -050019asm (
20" .pushsection .text, \"ax\", @progbits\n"
Josh Poimboeuf9d907f12020-04-24 15:40:43 -050021" .type my_tramp, @function\n"
Sami Tolvanen983df5f2020-11-13 10:34:14 -080022" .globl my_tramp\n"
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -050023" my_tramp:"
24" pushq %rbp\n"
25" movq %rsp, %rbp\n"
26" pushq %rdi\n"
27" call my_direct_func\n"
28" popq %rdi\n"
29" leave\n"
Peter Zijlstrab17c2ba2021-12-04 14:43:41 +010030 ASM_RET
Josh Poimboeuf9d907f12020-04-24 15:40:43 -050031" .size my_tramp, .-my_tramp\n"
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -050032" .popsection\n"
33);
34
Heiko Carstens1254cfbc2021-10-12 15:38:02 +020035#endif /* CONFIG_X86_64 */
36
37#ifdef CONFIG_S390
38
39asm (
40" .pushsection .text, \"ax\", @progbits\n"
41" .type my_tramp, @function\n"
42" .globl my_tramp\n"
43" my_tramp:"
44" lgr %r1,%r15\n"
45" stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
46" stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
47" aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n"
48" stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n"
49" brasl %r14,my_direct_func\n"
50" aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n"
51" lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
52" lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
53" lgr %r1,%r0\n"
54" br %r1\n"
55" .size my_tramp, .-my_tramp\n"
56" .popsection\n"
57);
58
59#endif /* CONFIG_S390 */
Steven Rostedt (VMware)b06457c2019-11-08 13:12:33 -050060
61static int __init ftrace_direct_init(void)
62{
63 return register_ftrace_direct((unsigned long)wake_up_process,
64 (unsigned long)my_tramp);
65}
66
67static void __exit ftrace_direct_exit(void)
68{
69 unregister_ftrace_direct((unsigned long)wake_up_process,
70 (unsigned long)my_tramp);
71}
72
73module_init(ftrace_direct_init);
74module_exit(ftrace_direct_exit);
75
76MODULE_AUTHOR("Steven Rostedt");
77MODULE_DESCRIPTION("Example use case of using register_ftrace_direct()");
78MODULE_LICENSE("GPL");