blob: 2fafc9afcbf0fcf31df7eaebd8fd0c19fa44fd28 [file] [log] [blame]
Jiri Olsa5fae9412021-10-08 11:13:36 +02001// SPDX-License-Identifier: GPL-2.0-only
2#include <linux/module.h>
3
4#include <linux/mm.h> /* for handle_mm_fault() */
5#include <linux/ftrace.h>
6#include <linux/sched/stat.h>
Heiko Carstens890e3dc2021-11-15 20:56:14 +01007#include <asm/asm-offsets.h>
Jiri Olsa5fae9412021-10-08 11:13:36 +02008
Jiri Olsa67d4f6e2021-11-01 16:39:07 +01009extern void my_direct_func(unsigned long ip);
10
Jiri Olsa5fae9412021-10-08 11:13:36 +020011void my_direct_func(unsigned long ip)
12{
13 trace_printk("ip %lx\n", ip);
14}
15
16extern void my_tramp(void *);
17
Heiko Carstens890e3dc2021-11-15 20:56:14 +010018#ifdef CONFIG_X86_64
19
Jiri Olsa5fae9412021-10-08 11:13:36 +020020asm (
21" .pushsection .text, \"ax\", @progbits\n"
22" .type my_tramp, @function\n"
23" .globl my_tramp\n"
24" my_tramp:"
25" pushq %rbp\n"
26" movq %rsp, %rbp\n"
27" pushq %rdi\n"
28" movq 8(%rbp), %rdi\n"
29" call my_direct_func\n"
30" popq %rdi\n"
31" leave\n"
32" ret\n"
33" .size my_tramp, .-my_tramp\n"
34" .popsection\n"
35);
36
Heiko Carstens890e3dc2021-11-15 20:56:14 +010037#endif /* CONFIG_X86_64 */
38
39#ifdef CONFIG_S390
40
41asm (
42" .pushsection .text, \"ax\", @progbits\n"
43" .type my_tramp, @function\n"
44" .globl my_tramp\n"
45" my_tramp:"
46" lgr %r1,%r15\n"
47" stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
48" stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
49" aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n"
50" stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n"
51" lgr %r2,%r0\n"
52" brasl %r14,my_direct_func\n"
53" aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n"
54" lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n"
55" lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n"
56" lgr %r1,%r0\n"
57" br %r1\n"
58" .size my_tramp, .-my_tramp\n"
59" .popsection\n"
60);
61
62#endif /* CONFIG_S390 */
63
Jiri Olsa5fae9412021-10-08 11:13:36 +020064static struct ftrace_ops direct;
65
66static int __init ftrace_direct_multi_init(void)
67{
68 ftrace_set_filter_ip(&direct, (unsigned long) wake_up_process, 0, 0);
69 ftrace_set_filter_ip(&direct, (unsigned long) schedule, 0, 0);
70
71 return register_ftrace_direct_multi(&direct, (unsigned long) my_tramp);
72}
73
74static void __exit ftrace_direct_multi_exit(void)
75{
76 unregister_ftrace_direct_multi(&direct, (unsigned long) my_tramp);
77}
78
79module_init(ftrace_direct_multi_init);
80module_exit(ftrace_direct_multi_exit);
81
82MODULE_AUTHOR("Jiri Olsa");
83MODULE_DESCRIPTION("Example use case of using register_ftrace_direct_multi()");
84MODULE_LICENSE("GPL");