~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/kprobe_multi.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #include <linux/bpf.h>
  3 #include <bpf/bpf_helpers.h>
  4 #include <bpf/bpf_tracing.h>
  5 #include <stdbool.h>
  6 
  7 char _license[] SEC("license") = "GPL";
  8 
  9 extern const void bpf_fentry_test1 __ksym;
 10 extern const void bpf_fentry_test2 __ksym;
 11 extern const void bpf_fentry_test3 __ksym;
 12 extern const void bpf_fentry_test4 __ksym;
 13 extern const void bpf_fentry_test5 __ksym;
 14 extern const void bpf_fentry_test6 __ksym;
 15 extern const void bpf_fentry_test7 __ksym;
 16 extern const void bpf_fentry_test8 __ksym;
 17 
 18 int pid = 0;
 19 bool test_cookie = false;
 20 
 21 __u64 kprobe_test1_result = 0;
 22 __u64 kprobe_test2_result = 0;
 23 __u64 kprobe_test3_result = 0;
 24 __u64 kprobe_test4_result = 0;
 25 __u64 kprobe_test5_result = 0;
 26 __u64 kprobe_test6_result = 0;
 27 __u64 kprobe_test7_result = 0;
 28 __u64 kprobe_test8_result = 0;
 29 
 30 __u64 kretprobe_test1_result = 0;
 31 __u64 kretprobe_test2_result = 0;
 32 __u64 kretprobe_test3_result = 0;
 33 __u64 kretprobe_test4_result = 0;
 34 __u64 kretprobe_test5_result = 0;
 35 __u64 kretprobe_test6_result = 0;
 36 __u64 kretprobe_test7_result = 0;
 37 __u64 kretprobe_test8_result = 0;
 38 
 39 static void kprobe_multi_check(void *ctx, bool is_return)
 40 {
 41         if (bpf_get_current_pid_tgid() >> 32 != pid)
 42                 return;
 43 
 44         __u64 cookie = test_cookie ? bpf_get_attach_cookie(ctx) : 0;
 45         __u64 addr = bpf_get_func_ip(ctx);
 46 
 47 #define SET(__var, __addr, __cookie) ({                 \
 48         if (((const void *) addr == __addr) &&          \
 49              (!test_cookie || (cookie == __cookie)))    \
 50                 __var = 1;                              \
 51 })
 52 
 53         if (is_return) {
 54                 SET(kretprobe_test1_result, &bpf_fentry_test1, 8);
 55                 SET(kretprobe_test2_result, &bpf_fentry_test2, 2);
 56                 SET(kretprobe_test3_result, &bpf_fentry_test3, 7);
 57                 SET(kretprobe_test4_result, &bpf_fentry_test4, 6);
 58                 SET(kretprobe_test5_result, &bpf_fentry_test5, 5);
 59                 SET(kretprobe_test6_result, &bpf_fentry_test6, 4);
 60                 SET(kretprobe_test7_result, &bpf_fentry_test7, 3);
 61                 SET(kretprobe_test8_result, &bpf_fentry_test8, 1);
 62         } else {
 63                 SET(kprobe_test1_result, &bpf_fentry_test1, 1);
 64                 SET(kprobe_test2_result, &bpf_fentry_test2, 7);
 65                 SET(kprobe_test3_result, &bpf_fentry_test3, 2);
 66                 SET(kprobe_test4_result, &bpf_fentry_test4, 3);
 67                 SET(kprobe_test5_result, &bpf_fentry_test5, 4);
 68                 SET(kprobe_test6_result, &bpf_fentry_test6, 5);
 69                 SET(kprobe_test7_result, &bpf_fentry_test7, 6);
 70                 SET(kprobe_test8_result, &bpf_fentry_test8, 8);
 71         }
 72 
 73 #undef SET
 74 }
 75 
 76 /*
 77  * No tests in here, just to trigger 'bpf_fentry_test*'
 78  * through tracing test_run
 79  */
 80 SEC("fentry/bpf_modify_return_test")
 81 int BPF_PROG(trigger)
 82 {
 83         return 0;
 84 }
 85 
 86 SEC("kprobe.multi/bpf_fentry_tes??")
 87 int test_kprobe(struct pt_regs *ctx)
 88 {
 89         kprobe_multi_check(ctx, false);
 90         return 0;
 91 }
 92 
 93 SEC("kretprobe.multi/bpf_fentry_test*")
 94 int test_kretprobe(struct pt_regs *ctx)
 95 {
 96         kprobe_multi_check(ctx, true);
 97         return 0;
 98 }
 99 
100 SEC("kprobe.multi")
101 int test_kprobe_manual(struct pt_regs *ctx)
102 {
103         kprobe_multi_check(ctx, false);
104         return 0;
105 }
106 
107 SEC("kretprobe.multi")
108 int test_kretprobe_manual(struct pt_regs *ctx)
109 {
110         kprobe_multi_check(ctx, true);
111         return 0;
112 }
113 
114 extern const void bpf_testmod_fentry_test1 __ksym;
115 extern const void bpf_testmod_fentry_test2 __ksym;
116 extern const void bpf_testmod_fentry_test3 __ksym;
117 
118 __u64 kprobe_testmod_test1_result = 0;
119 __u64 kprobe_testmod_test2_result = 0;
120 __u64 kprobe_testmod_test3_result = 0;
121 
122 __u64 kretprobe_testmod_test1_result = 0;
123 __u64 kretprobe_testmod_test2_result = 0;
124 __u64 kretprobe_testmod_test3_result = 0;
125 
126 static void kprobe_multi_testmod_check(void *ctx, bool is_return)
127 {
128         if (bpf_get_current_pid_tgid() >> 32 != pid)
129                 return;
130 
131         __u64 addr = bpf_get_func_ip(ctx);
132 
133         if (is_return) {
134                 if ((const void *) addr == &bpf_testmod_fentry_test1)
135                         kretprobe_testmod_test1_result = 1;
136                 if ((const void *) addr == &bpf_testmod_fentry_test2)
137                         kretprobe_testmod_test2_result = 1;
138                 if ((const void *) addr == &bpf_testmod_fentry_test3)
139                         kretprobe_testmod_test3_result = 1;
140         } else {
141                 if ((const void *) addr == &bpf_testmod_fentry_test1)
142                         kprobe_testmod_test1_result = 1;
143                 if ((const void *) addr == &bpf_testmod_fentry_test2)
144                         kprobe_testmod_test2_result = 1;
145                 if ((const void *) addr == &bpf_testmod_fentry_test3)
146                         kprobe_testmod_test3_result = 1;
147         }
148 }
149 
150 SEC("kprobe.multi")
151 int test_kprobe_testmod(struct pt_regs *ctx)
152 {
153         kprobe_multi_testmod_check(ctx, false);
154         return 0;
155 }
156 
157 SEC("kretprobe.multi")
158 int test_kretprobe_testmod(struct pt_regs *ctx)
159 {
160         kprobe_multi_testmod_check(ctx, true);
161         return 0;
162 }
163 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php