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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/module_attach.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 /* Copyright (c) 2020 Facebook */
  3 
  4 #include <test_progs.h>
  5 #include <stdbool.h>
  6 #include "test_module_attach.skel.h"
  7 #include "testing_helpers.h"
  8 
  9 static int duration;
 10 
 11 static int trigger_module_test_writable(int *val)
 12 {
 13         int fd, err;
 14         char buf[65];
 15         ssize_t rd;
 16 
 17         fd = open(BPF_TESTMOD_TEST_FILE, O_RDONLY);
 18         err = -errno;
 19         if (!ASSERT_GE(fd, 0, "testmode_file_open"))
 20                 return err;
 21 
 22         rd = read(fd, buf, sizeof(buf) - 1);
 23         err = -errno;
 24         if (!ASSERT_GT(rd, 0, "testmod_file_rd_val")) {
 25                 close(fd);
 26                 return err;
 27         }
 28 
 29         buf[rd] = '\0';
 30         *val = strtol(buf, NULL, 0);
 31         close(fd);
 32 
 33         return 0;
 34 }
 35 
 36 void test_module_attach(void)
 37 {
 38         const int READ_SZ = 456;
 39         const int WRITE_SZ = 457;
 40         struct test_module_attach* skel;
 41         struct test_module_attach__bss *bss;
 42         struct bpf_link *link;
 43         int err;
 44         int writable_val = 0;
 45 
 46         skel = test_module_attach__open();
 47         if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
 48                 return;
 49 
 50         err = bpf_program__set_attach_target(skel->progs.handle_fentry_manual,
 51                                              0, "bpf_testmod_test_read");
 52         ASSERT_OK(err, "set_attach_target");
 53 
 54         err = bpf_program__set_attach_target(skel->progs.handle_fentry_explicit_manual,
 55                                              0, "bpf_testmod:bpf_testmod_test_read");
 56         ASSERT_OK(err, "set_attach_target_explicit");
 57 
 58         err = test_module_attach__load(skel);
 59         if (CHECK(err, "skel_load", "failed to load skeleton\n"))
 60                 return;
 61 
 62         bss = skel->bss;
 63 
 64         err = test_module_attach__attach(skel);
 65         if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
 66                 goto cleanup;
 67 
 68         /* trigger tracepoint */
 69         ASSERT_OK(trigger_module_test_read(READ_SZ), "trigger_read");
 70         ASSERT_OK(trigger_module_test_write(WRITE_SZ), "trigger_write");
 71 
 72         ASSERT_EQ(bss->raw_tp_read_sz, READ_SZ, "raw_tp");
 73         ASSERT_EQ(bss->raw_tp_bare_write_sz, WRITE_SZ, "raw_tp_bare");
 74         ASSERT_EQ(bss->tp_btf_read_sz, READ_SZ, "tp_btf");
 75         ASSERT_EQ(bss->fentry_read_sz, READ_SZ, "fentry");
 76         ASSERT_EQ(bss->fentry_manual_read_sz, READ_SZ, "fentry_manual");
 77         ASSERT_EQ(bss->fentry_explicit_read_sz, READ_SZ, "fentry_explicit");
 78         ASSERT_EQ(bss->fentry_explicit_manual_read_sz, READ_SZ, "fentry_explicit_manual");
 79         ASSERT_EQ(bss->fexit_read_sz, READ_SZ, "fexit");
 80         ASSERT_EQ(bss->fexit_ret, -EIO, "fexit_tet");
 81         ASSERT_EQ(bss->fmod_ret_read_sz, READ_SZ, "fmod_ret");
 82 
 83         bss->raw_tp_writable_bare_early_ret = true;
 84         bss->raw_tp_writable_bare_out_val = 0xf1f2f3f4;
 85         ASSERT_OK(trigger_module_test_writable(&writable_val),
 86                   "trigger_writable");
 87         ASSERT_EQ(bss->raw_tp_writable_bare_in_val, 1024, "writable_test_in");
 88         ASSERT_EQ(bss->raw_tp_writable_bare_out_val, writable_val,
 89                   "writable_test_out");
 90 
 91         test_module_attach__detach(skel);
 92 
 93         /* attach fentry/fexit and make sure it get's module reference */
 94         link = bpf_program__attach(skel->progs.handle_fentry);
 95         if (!ASSERT_OK_PTR(link, "attach_fentry"))
 96                 goto cleanup;
 97 
 98         ASSERT_ERR(unload_bpf_testmod(false), "unload_bpf_testmod");
 99         bpf_link__destroy(link);
100 
101         link = bpf_program__attach(skel->progs.handle_fexit);
102         if (!ASSERT_OK_PTR(link, "attach_fexit"))
103                 goto cleanup;
104 
105         ASSERT_ERR(unload_bpf_testmod(false), "unload_bpf_testmod");
106         bpf_link__destroy(link);
107 
108         link = bpf_program__attach(skel->progs.kprobe_multi);
109         if (!ASSERT_OK_PTR(link, "attach_kprobe_multi"))
110                 goto cleanup;
111 
112         ASSERT_ERR(unload_bpf_testmod(false), "unload_bpf_testmod");
113         bpf_link__destroy(link);
114 
115 cleanup:
116         test_module_attach__destroy(skel);
117 }
118 

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