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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/iters_testmod_seq.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
  2 /* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */
  3 
  4 #include "vmlinux.h"
  5 #include <bpf/bpf_helpers.h>
  6 #include "bpf_misc.h"
  7 
  8 struct bpf_iter_testmod_seq {
  9         u64 :64;
 10         u64 :64;
 11 };
 12 
 13 extern int bpf_iter_testmod_seq_new(struct bpf_iter_testmod_seq *it, s64 value, int cnt) __ksym;
 14 extern s64 *bpf_iter_testmod_seq_next(struct bpf_iter_testmod_seq *it) __ksym;
 15 extern s64 bpf_iter_testmod_seq_value(int blah, struct bpf_iter_testmod_seq *it) __ksym;
 16 extern void bpf_iter_testmod_seq_destroy(struct bpf_iter_testmod_seq *it) __ksym;
 17 
 18 const volatile __s64 exp_empty = 0 + 1;
 19 __s64 res_empty;
 20 
 21 SEC("raw_tp/sys_enter")
 22 __success __log_level(2)
 23 __msg("fp-16_w=iter_testmod_seq(ref_id=1,state=active,depth=0)")
 24 __msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)")
 25 __msg("call bpf_iter_testmod_seq_destroy")
 26 int testmod_seq_empty(const void *ctx)
 27 {
 28         __s64 sum = 0, *i;
 29 
 30         bpf_for_each(testmod_seq, i, 1000, 0) sum += *i;
 31         res_empty = 1 + sum;
 32 
 33         return 0;
 34 }
 35 
 36 const volatile __s64 exp_full = 1000000;
 37 __s64 res_full;
 38 
 39 SEC("raw_tp/sys_enter")
 40 __success __log_level(2)
 41 __msg("fp-16_w=iter_testmod_seq(ref_id=1,state=active,depth=0)")
 42 __msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)")
 43 __msg("call bpf_iter_testmod_seq_destroy")
 44 int testmod_seq_full(const void *ctx)
 45 {
 46         __s64 sum = 0, *i;
 47 
 48         bpf_for_each(testmod_seq, i, 1000, 1000) sum += *i;
 49         res_full = sum;
 50 
 51         return 0;
 52 }
 53 
 54 const volatile __s64 exp_truncated = 10 * 1000000;
 55 __s64 res_truncated;
 56 
 57 static volatile int zero = 0;
 58 
 59 SEC("raw_tp/sys_enter")
 60 __success __log_level(2)
 61 __msg("fp-16_w=iter_testmod_seq(ref_id=1,state=active,depth=0)")
 62 __msg("fp-16=iter_testmod_seq(ref_id=1,state=drained,depth=0)")
 63 __msg("call bpf_iter_testmod_seq_destroy")
 64 int testmod_seq_truncated(const void *ctx)
 65 {
 66         __s64 sum = 0, *i;
 67         int cnt = zero;
 68 
 69         bpf_for_each(testmod_seq, i, 10, 2000000) {
 70                 sum += *i;
 71                 cnt++;
 72                 if (cnt >= 1000000)
 73                         break;
 74         }
 75         res_truncated = sum;
 76 
 77         return 0;
 78 }
 79 
 80 SEC("?raw_tp")
 81 __failure
 82 __msg("expected an initialized iter_testmod_seq as arg #2")
 83 int testmod_seq_getter_before_bad(const void *ctx)
 84 {
 85         struct bpf_iter_testmod_seq it;
 86 
 87         return bpf_iter_testmod_seq_value(0, &it);
 88 }
 89 
 90 SEC("?raw_tp")
 91 __failure
 92 __msg("expected an initialized iter_testmod_seq as arg #2")
 93 int testmod_seq_getter_after_bad(const void *ctx)
 94 {
 95         struct bpf_iter_testmod_seq it;
 96         s64 sum = 0, *v;
 97 
 98         bpf_iter_testmod_seq_new(&it, 100, 100);
 99 
100         while ((v = bpf_iter_testmod_seq_next(&it))) {
101                 sum += *v;
102         }
103 
104         bpf_iter_testmod_seq_destroy(&it);
105 
106         return sum + bpf_iter_testmod_seq_value(0, &it);
107 }
108 
109 SEC("?socket")
110 __success __retval(1000000)
111 int testmod_seq_getter_good(const void *ctx)
112 {
113         struct bpf_iter_testmod_seq it;
114         s64 sum = 0, *v;
115 
116         bpf_iter_testmod_seq_new(&it, 100, 100);
117 
118         while ((v = bpf_iter_testmod_seq_next(&it))) {
119                 sum += *v;
120         }
121 
122         sum *= bpf_iter_testmod_seq_value(0, &it);
123 
124         bpf_iter_testmod_seq_destroy(&it);
125 
126         return sum;
127 }
128 
129 char _license[] SEC("license") = "GPL";
130 

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