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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/pro_epilogue.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
  3 
  4 #include <test_progs.h>
  5 #include "pro_epilogue.skel.h"
  6 #include "epilogue_tailcall.skel.h"
  7 #include "pro_epilogue_goto_start.skel.h"
  8 #include "epilogue_exit.skel.h"
  9 
 10 struct st_ops_args {
 11         __u64 a;
 12 };
 13 
 14 static void test_tailcall(void)
 15 {
 16         LIBBPF_OPTS(bpf_test_run_opts, topts);
 17         struct epilogue_tailcall *skel;
 18         struct st_ops_args args;
 19         int err, prog_fd;
 20 
 21         skel = epilogue_tailcall__open_and_load();
 22         if (!ASSERT_OK_PTR(skel, "epilogue_tailcall__open_and_load"))
 23                 return;
 24 
 25         topts.ctx_in = &args;
 26         topts.ctx_size_in = sizeof(args);
 27 
 28         skel->links.epilogue_tailcall =
 29                 bpf_map__attach_struct_ops(skel->maps.epilogue_tailcall);
 30         if (!ASSERT_OK_PTR(skel->links.epilogue_tailcall, "attach_struct_ops"))
 31                 goto done;
 32 
 33         /* Both test_epilogue_tailcall and test_epilogue_subprog are
 34          * patched with epilogue. When syscall_epilogue_tailcall()
 35          * is run, test_epilogue_tailcall() is triggered.
 36          * It executes a tail call and control is transferred to
 37          * test_epilogue_subprog(). Only test_epilogue_subprog()
 38          * does args->a += 1, thus final args.a value of 10001
 39          * guarantees that only the epilogue of the
 40          * test_epilogue_subprog is executed.
 41          */
 42         memset(&args, 0, sizeof(args));
 43         prog_fd = bpf_program__fd(skel->progs.syscall_epilogue_tailcall);
 44         err = bpf_prog_test_run_opts(prog_fd, &topts);
 45         ASSERT_OK(err, "bpf_prog_test_run_opts");
 46         ASSERT_EQ(args.a, 10001, "args.a");
 47         ASSERT_EQ(topts.retval, 10001 * 2, "topts.retval");
 48 
 49 done:
 50         epilogue_tailcall__destroy(skel);
 51 }
 52 
 53 void test_pro_epilogue(void)
 54 {
 55         RUN_TESTS(pro_epilogue);
 56         RUN_TESTS(pro_epilogue_goto_start);
 57         RUN_TESTS(epilogue_exit);
 58         if (test__start_subtest("tailcall"))
 59                 test_tailcall();
 60 }
 61 

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