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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/missed.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 <test_progs.h>
  3 #include "missed_kprobe.skel.h"
  4 #include "missed_kprobe_recursion.skel.h"
  5 #include "missed_tp_recursion.skel.h"
  6 
  7 /*
  8  * Putting kprobe on bpf_fentry_test1 that calls bpf_kfunc_common_test
  9  * kfunc, which has also kprobe on. The latter won't get triggered due
 10  * to kprobe recursion check and kprobe missed counter is incremented.
 11  */
 12 static void test_missed_perf_kprobe(void)
 13 {
 14         LIBBPF_OPTS(bpf_test_run_opts, topts);
 15         struct bpf_link_info info = {};
 16         struct missed_kprobe *skel;
 17         __u32 len = sizeof(info);
 18         int err, prog_fd;
 19 
 20         skel = missed_kprobe__open_and_load();
 21         if (!ASSERT_OK_PTR(skel, "missed_kprobe__open_and_load"))
 22                 goto cleanup;
 23 
 24         err = missed_kprobe__attach(skel);
 25         if (!ASSERT_OK(err, "missed_kprobe__attach"))
 26                 goto cleanup;
 27 
 28         prog_fd = bpf_program__fd(skel->progs.trigger);
 29         err = bpf_prog_test_run_opts(prog_fd, &topts);
 30         ASSERT_OK(err, "test_run");
 31         ASSERT_EQ(topts.retval, 0, "test_run");
 32 
 33         err = bpf_link_get_info_by_fd(bpf_link__fd(skel->links.test2), &info, &len);
 34         if (!ASSERT_OK(err, "bpf_link_get_info_by_fd"))
 35                 goto cleanup;
 36 
 37         ASSERT_EQ(info.type, BPF_LINK_TYPE_PERF_EVENT, "info.type");
 38         ASSERT_EQ(info.perf_event.type, BPF_PERF_EVENT_KPROBE, "info.perf_event.type");
 39         ASSERT_EQ(info.perf_event.kprobe.missed, 1, "info.perf_event.kprobe.missed");
 40 
 41 cleanup:
 42         missed_kprobe__destroy(skel);
 43 }
 44 
 45 static __u64 get_missed_count(int fd)
 46 {
 47         struct bpf_prog_info info = {};
 48         __u32 len = sizeof(info);
 49         int err;
 50 
 51         err = bpf_prog_get_info_by_fd(fd, &info, &len);
 52         if (!ASSERT_OK(err, "bpf_prog_get_info_by_fd"))
 53                 return (__u64) -1;
 54         return info.recursion_misses;
 55 }
 56 
 57 /*
 58  * Putting kprobe.multi on bpf_fentry_test1 that calls bpf_kfunc_common_test
 59  * kfunc which has 3 perf event kprobes and 1 kprobe.multi attached.
 60  *
 61  * Because fprobe (kprobe.multi attach layear) does not have strict recursion
 62  * check the kprobe's bpf_prog_active check is hit for test2-5.
 63  */
 64 static void test_missed_kprobe_recursion(void)
 65 {
 66         LIBBPF_OPTS(bpf_test_run_opts, topts);
 67         struct missed_kprobe_recursion *skel;
 68         int err, prog_fd;
 69 
 70         skel = missed_kprobe_recursion__open_and_load();
 71         if (!ASSERT_OK_PTR(skel, "missed_kprobe_recursion__open_and_load"))
 72                 goto cleanup;
 73 
 74         err = missed_kprobe_recursion__attach(skel);
 75         if (!ASSERT_OK(err, "missed_kprobe_recursion__attach"))
 76                 goto cleanup;
 77 
 78         prog_fd = bpf_program__fd(skel->progs.trigger);
 79         err = bpf_prog_test_run_opts(prog_fd, &topts);
 80         ASSERT_OK(err, "test_run");
 81         ASSERT_EQ(topts.retval, 0, "test_run");
 82 
 83         ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test1)), 0, "test1_recursion_misses");
 84         ASSERT_GE(get_missed_count(bpf_program__fd(skel->progs.test2)), 1, "test2_recursion_misses");
 85         ASSERT_GE(get_missed_count(bpf_program__fd(skel->progs.test3)), 1, "test3_recursion_misses");
 86         ASSERT_GE(get_missed_count(bpf_program__fd(skel->progs.test4)), 1, "test4_recursion_misses");
 87         ASSERT_GE(get_missed_count(bpf_program__fd(skel->progs.test5)), 1, "test5_recursion_misses");
 88 
 89 cleanup:
 90         missed_kprobe_recursion__destroy(skel);
 91 }
 92 
 93 /*
 94  * Putting kprobe on bpf_fentry_test1 that calls bpf_printk and invokes
 95  * bpf_trace_printk tracepoint. The bpf_trace_printk tracepoint has test[234]
 96  * programs attached to it.
 97  *
 98  * Because kprobe execution goes through bpf_prog_active check, programs
 99  * attached to the tracepoint will fail the recursion check and increment
100  * the recursion_misses stats.
101  */
102 static void test_missed_tp_recursion(void)
103 {
104         LIBBPF_OPTS(bpf_test_run_opts, topts);
105         struct missed_tp_recursion *skel;
106         int err, prog_fd;
107 
108         skel = missed_tp_recursion__open_and_load();
109         if (!ASSERT_OK_PTR(skel, "missed_tp_recursion__open_and_load"))
110                 goto cleanup;
111 
112         err = missed_tp_recursion__attach(skel);
113         if (!ASSERT_OK(err, "missed_tp_recursion__attach"))
114                 goto cleanup;
115 
116         prog_fd = bpf_program__fd(skel->progs.trigger);
117         err = bpf_prog_test_run_opts(prog_fd, &topts);
118         ASSERT_OK(err, "test_run");
119         ASSERT_EQ(topts.retval, 0, "test_run");
120 
121         ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test1)), 0, "test1_recursion_misses");
122         ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test2)), 1, "test2_recursion_misses");
123         ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test3)), 1, "test3_recursion_misses");
124         ASSERT_EQ(get_missed_count(bpf_program__fd(skel->progs.test4)), 1, "test4_recursion_misses");
125 
126 cleanup:
127         missed_tp_recursion__destroy(skel);
128 }
129 
130 void test_missed(void)
131 {
132         if (test__start_subtest("perf_kprobe"))
133                 test_missed_perf_kprobe();
134         if (test__start_subtest("kprobe_recursion"))
135                 test_missed_kprobe_recursion();
136         if (test__start_subtest("tp_recursion"))
137                 test_missed_tp_recursion();
138 }
139 

~ [ 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