selftests/bpf: Fix erroneous bitmask operation
[platform/kernel/linux-rpi.git] / tools / testing / selftests / bpf / progs / get_func_ip_test.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include "vmlinux.h"
3 #include <bpf/bpf_helpers.h>
4 #include <bpf/bpf_tracing.h>
5
6 char _license[] SEC("license") = "GPL";
7
8 extern const void bpf_fentry_test1 __ksym;
9 extern const void bpf_fentry_test2 __ksym;
10 extern const void bpf_fentry_test3 __ksym;
11 extern const void bpf_fentry_test4 __ksym;
12 extern const void bpf_modify_return_test __ksym;
13 extern const void bpf_fentry_test6 __ksym;
14 extern const void bpf_fentry_test7 __ksym;
15
16 extern bool CONFIG_X86_KERNEL_IBT __kconfig __weak;
17
18 /* This function is here to have CONFIG_X86_KERNEL_IBT
19  * used and added to object BTF.
20  */
21 int unused(void)
22 {
23         return CONFIG_X86_KERNEL_IBT ? 0 : 1;
24 }
25
26 __u64 test1_result = 0;
27 SEC("fentry/bpf_fentry_test1")
28 int BPF_PROG(test1, int a)
29 {
30         __u64 addr = bpf_get_func_ip(ctx);
31
32         test1_result = (const void *) addr == &bpf_fentry_test1;
33         return 0;
34 }
35
36 __u64 test2_result = 0;
37 SEC("fexit/bpf_fentry_test2")
38 int BPF_PROG(test2, int a)
39 {
40         __u64 addr = bpf_get_func_ip(ctx);
41
42         test2_result = (const void *) addr == &bpf_fentry_test2;
43         return 0;
44 }
45
46 __u64 test3_result = 0;
47 SEC("kprobe/bpf_fentry_test3")
48 int test3(struct pt_regs *ctx)
49 {
50         __u64 addr = bpf_get_func_ip(ctx);
51
52         test3_result = (const void *) addr == &bpf_fentry_test3;
53         return 0;
54 }
55
56 __u64 test4_result = 0;
57 SEC("kretprobe/bpf_fentry_test4")
58 int BPF_KRETPROBE(test4)
59 {
60         __u64 addr = bpf_get_func_ip(ctx);
61
62         test4_result = (const void *) addr == &bpf_fentry_test4;
63         return 0;
64 }
65
66 __u64 test5_result = 0;
67 SEC("fmod_ret/bpf_modify_return_test")
68 int BPF_PROG(test5, int a, int *b, int ret)
69 {
70         __u64 addr = bpf_get_func_ip(ctx);
71
72         test5_result = (const void *) addr == &bpf_modify_return_test;
73         return ret;
74 }
75
76 __u64 test6_result = 0;
77 SEC("?kprobe")
78 int test6(struct pt_regs *ctx)
79 {
80         __u64 addr = bpf_get_func_ip(ctx);
81
82         test6_result = (const void *) addr == 0;
83         return 0;
84 }
85
86 unsigned long uprobe_trigger;
87
88 __u64 test7_result = 0;
89 SEC("uprobe//proc/self/exe:uprobe_trigger")
90 int BPF_UPROBE(test7)
91 {
92         __u64 addr = bpf_get_func_ip(ctx);
93
94         test7_result = (const void *) addr == (const void *) uprobe_trigger;
95         return 0;
96 }
97
98 __u64 test8_result = 0;
99 SEC("uretprobe//proc/self/exe:uprobe_trigger")
100 int BPF_URETPROBE(test8, int ret)
101 {
102         __u64 addr = bpf_get_func_ip(ctx);
103
104         test8_result = (const void *) addr == (const void *) uprobe_trigger;
105         return 0;
106 }