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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/progs/verifier_bits_iter.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-only
  2 /* Copyright (c) 2024 Yafang Shao <laoar.shao@gmail.com> */
  3 
  4 #include "vmlinux.h"
  5 #include <bpf/bpf_helpers.h>
  6 #include <bpf/bpf_tracing.h>
  7 
  8 #include "bpf_misc.h"
  9 #include "task_kfunc_common.h"
 10 
 11 char _license[] SEC("license") = "GPL";
 12 
 13 int bpf_iter_bits_new(struct bpf_iter_bits *it, const u64 *unsafe_ptr__ign,
 14                       u32 nr_bits) __ksym __weak;
 15 int *bpf_iter_bits_next(struct bpf_iter_bits *it) __ksym __weak;
 16 void bpf_iter_bits_destroy(struct bpf_iter_bits *it) __ksym __weak;
 17 
 18 SEC("iter.s/cgroup")
 19 __description("bits iter without destroy")
 20 __failure __msg("Unreleased reference")
 21 int BPF_PROG(no_destroy, struct bpf_iter_meta *meta, struct cgroup *cgrp)
 22 {
 23         struct bpf_iter_bits it;
 24         u64 data = 1;
 25 
 26         bpf_iter_bits_new(&it, &data, 1);
 27         bpf_iter_bits_next(&it);
 28         return 0;
 29 }
 30 
 31 SEC("iter/cgroup")
 32 __description("uninitialized iter in ->next()")
 33 __failure __msg("expected an initialized iter_bits as arg #1")
 34 int BPF_PROG(next_uninit, struct bpf_iter_meta *meta, struct cgroup *cgrp)
 35 {
 36         struct bpf_iter_bits *it = NULL;
 37 
 38         bpf_iter_bits_next(it);
 39         return 0;
 40 }
 41 
 42 SEC("iter/cgroup")
 43 __description("uninitialized iter in ->destroy()")
 44 __failure __msg("expected an initialized iter_bits as arg #1")
 45 int BPF_PROG(destroy_uninit, struct bpf_iter_meta *meta, struct cgroup *cgrp)
 46 {
 47         struct bpf_iter_bits it = {};
 48 
 49         bpf_iter_bits_destroy(&it);
 50         return 0;
 51 }
 52 
 53 SEC("syscall")
 54 __description("null pointer")
 55 __success __retval(0)
 56 int null_pointer(void)
 57 {
 58         int nr = 0;
 59         int *bit;
 60 
 61         bpf_for_each(bits, bit, NULL, 1)
 62                 nr++;
 63         return nr;
 64 }
 65 
 66 SEC("syscall")
 67 __description("bits copy")
 68 __success __retval(10)
 69 int bits_copy(void)
 70 {
 71         u64 data = 0xf7310UL; /* 4 + 3 + 2 + 1 + 0*/
 72         int nr = 0;
 73         int *bit;
 74 
 75         bpf_for_each(bits, bit, &data, 1)
 76                 nr++;
 77         return nr;
 78 }
 79 
 80 SEC("syscall")
 81 __description("bits memalloc")
 82 __success __retval(64)
 83 int bits_memalloc(void)
 84 {
 85         u64 data[2];
 86         int nr = 0;
 87         int *bit;
 88 
 89         __builtin_memset(&data, 0xf0, sizeof(data)); /* 4 * 16 */
 90         bpf_for_each(bits, bit, &data[0], sizeof(data) / sizeof(u64))
 91                 nr++;
 92         return nr;
 93 }
 94 
 95 SEC("syscall")
 96 __description("bit index")
 97 __success __retval(8)
 98 int bit_index(void)
 99 {
100         u64 data = 0x100;
101         int bit_idx = 0;
102         int *bit;
103 
104         bpf_for_each(bits, bit, &data, 1) {
105                 if (*bit == 0)
106                         continue;
107                 bit_idx = *bit;
108         }
109         return bit_idx;
110 }
111 
112 SEC("syscall")
113 __description("bits nomem")
114 __success __retval(0)
115 int bits_nomem(void)
116 {
117         u64 data[4];
118         int nr = 0;
119         int *bit;
120 
121         __builtin_memset(&data, 0xff, sizeof(data));
122         bpf_for_each(bits, bit, &data[0], 513) /* Be greater than 512 */
123                 nr++;
124         return nr;
125 }
126 
127 SEC("syscall")
128 __description("fewer words")
129 __success __retval(1)
130 int fewer_words(void)
131 {
132         u64 data[2] = {0x1, 0xff};
133         int nr = 0;
134         int *bit;
135 
136         bpf_for_each(bits, bit, &data[0], 1)
137                 nr++;
138         return nr;
139 }
140 
141 SEC("syscall")
142 __description("zero words")
143 __success __retval(0)
144 int zero_words(void)
145 {
146         u64 data[2] = {0x1, 0xff};
147         int nr = 0;
148         int *bit;
149 
150         bpf_for_each(bits, bit, &data[0], 0)
151                 nr++;
152         return nr;
153 }
154 

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