Commit | Line | Data |
---|---|---|
156473a0 SRV |
1 | // 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> | |
1254cfbc | 6 | #include <asm/asm-offsets.h> |
156473a0 SRV |
7 | |
8 | void my_direct_func(struct vm_area_struct *vma, | |
9 | unsigned long address, unsigned int flags) | |
10 | { | |
11 | trace_printk("handle mm fault vma=%p address=%lx flags=%x\n", | |
12 | vma, address, flags); | |
13 | } | |
14 | ||
15 | extern void my_tramp(void *); | |
16 | ||
1254cfbc HC |
17 | #ifdef CONFIG_X86_64 |
18 | ||
156473a0 SRV |
19 | asm ( |
20 | " .pushsection .text, \"ax\", @progbits\n" | |
9d907f1a | 21 | " .type my_tramp, @function\n" |
983df5f2 | 22 | " .globl my_tramp\n" |
156473a0 SRV |
23 | " my_tramp:" |
24 | " pushq %rbp\n" | |
25 | " movq %rsp, %rbp\n" | |
26 | " pushq %rdi\n" | |
27 | " pushq %rsi\n" | |
28 | " pushq %rdx\n" | |
29 | " call my_direct_func\n" | |
30 | " popq %rdx\n" | |
31 | " popq %rsi\n" | |
32 | " popq %rdi\n" | |
33 | " leave\n" | |
34 | " ret\n" | |
9d907f1a | 35 | " .size my_tramp, .-my_tramp\n" |
156473a0 SRV |
36 | " .popsection\n" |
37 | ); | |
38 | ||
1254cfbc HC |
39 | #endif /* CONFIG_X86_64 */ |
40 | ||
41 | #ifdef CONFIG_S390 | |
42 | ||
43 | asm ( | |
44 | " .pushsection .text, \"ax\", @progbits\n" | |
45 | " .type my_tramp, @function\n" | |
46 | " .globl my_tramp\n" | |
47 | " my_tramp:" | |
48 | " lgr %r1,%r15\n" | |
49 | " stmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n" | |
50 | " stg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n" | |
51 | " aghi %r15,"__stringify(-STACK_FRAME_OVERHEAD)"\n" | |
52 | " stg %r1,"__stringify(__SF_BACKCHAIN)"(%r15)\n" | |
53 | " brasl %r14,my_direct_func\n" | |
54 | " aghi %r15,"__stringify(STACK_FRAME_OVERHEAD)"\n" | |
55 | " lmg %r0,%r5,"__stringify(__SF_GPRS)"(%r15)\n" | |
56 | " lg %r14,"__stringify(__SF_GPRS+8*8)"(%r15)\n" | |
57 | " lgr %r1,%r0\n" | |
58 | " br %r1\n" | |
59 | " .size my_tramp, .-my_tramp\n" | |
60 | " .popsection\n" | |
61 | ); | |
62 | ||
63 | #endif /* CONFIG_S390 */ | |
156473a0 SRV |
64 | |
65 | static int __init ftrace_direct_init(void) | |
66 | { | |
67 | return register_ftrace_direct((unsigned long)handle_mm_fault, | |
68 | (unsigned long)my_tramp); | |
69 | } | |
70 | ||
71 | static void __exit ftrace_direct_exit(void) | |
72 | { | |
73 | unregister_ftrace_direct((unsigned long)handle_mm_fault, | |
74 | (unsigned long)my_tramp); | |
75 | } | |
76 | ||
77 | module_init(ftrace_direct_init); | |
78 | module_exit(ftrace_direct_exit); | |
79 | ||
80 | MODULE_AUTHOR("Steven Rostedt"); | |
81 | MODULE_DESCRIPTION("Another example use case of using register_ftrace_direct()"); | |
82 | MODULE_LICENSE("GPL"); |