• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

benchs/18-Mar-2025-2,8682,272

bpf_testmod/18-Mar-2025-345268

gnu/18-Mar-2025-20

map_tests/18-Mar-2025-1,6131,283

prog_tests/18-Mar-2025-54,92442,859

progs/18-Mar-2025-43,56232,342

verifier/18-Mar-2025-25,65924,437

.gitignoreD18-Mar-2025671 4948

DENYLISTD18-Mar-2025165 76

DENYLIST.s390xD18-Mar-20258.7 KiB7877

MakefileD18-Mar-202524 KiB620478

Makefile.docsD18-Mar-20252.2 KiB8458

README.rstD18-Mar-20258.9 KiB269190

bench.cD18-Mar-202518.4 KiB651557

bench.hD18-Mar-20252.5 KiB10488

bpf_legacy.hD18-Mar-2025519 179

bpf_rand.hD18-Mar-20253.1 KiB8172

bpf_sockopt_helpers.hD18-Mar-2025457 2211

bpf_tcp_helpers.hD18-Mar-20256.6 KiB242187

bpf_util.hD18-Mar-20251 KiB4433

btf_helpers.cD18-Mar-20256.8 KiB293250

btf_helpers.hD18-Mar-2025608 2013

cap_helpers.cD18-Mar-20251.5 KiB6850

cap_helpers.hD18-Mar-2025360 2013

cgroup_getset_retval_hooks.hD18-Mar-20251.5 KiB2623

cgroup_helpers.cD18-Mar-202514 KiB554328

cgroup_helpers.hD18-Mar-20251.1 KiB3725

configD18-Mar-20251.5 KiB7473

config.s390xD18-Mar-20253.1 KiB148147

config.x86_64D18-Mar-20255.5 KiB247246

flow_dissector_load.cD18-Mar-20252.3 KiB11290

flow_dissector_load.hD18-Mar-20251.4 KiB6954

get_cgroup_id_user.cD18-Mar-20253.8 KiB147115

ima_setup.shD18-Mar-20253.3 KiB157118

netcnt_common.hD18-Mar-2025910 4526

network_helpers.cD18-Mar-202510 KiB467371

network_helpers.hD18-Mar-20251.9 KiB7054

sdt-config.hD18-Mar-2025276 71

sdt.hD18-Mar-202521.9 KiB514355

settingsD18-Mar-202510 21

task_local_storage_helpers.hD18-Mar-2025367 1913

test_bpftool.pyD18-Mar-20255.3 KiB175126

test_bpftool.shD18-Mar-2025415 124

test_bpftool_build.shD18-Mar-20253.9 KiB15296

test_bpftool_metadata.shD18-Mar-20251.6 KiB8355

test_bpftool_synctypes.pyD18-Mar-202521.1 KiB611482

test_btf.hD18-Mar-20252.8 KiB8256

test_cgroup_storage.cD18-Mar-20254.7 KiB175134

test_cpp.cppD18-Mar-20252.5 KiB12486

test_dev_cgroup.cD18-Mar-20252 KiB8655

test_doc_build.shD18-Mar-2025638 2113

test_flow_dissector.cD18-Mar-202518.2 KiB781642

test_flow_dissector.shD18-Mar-20255.5 KiB177107

test_ftrace.shD18-Mar-2025701 4027

test_iptunnel_common.hD18-Mar-2025457 3526

test_kmod.shD18-Mar-20251.5 KiB7454

test_lirc_mode2.shD18-Mar-2025764 4231

test_lirc_mode2_user.cD18-Mar-20254.3 KiB178118

test_lpm_map.cD18-Mar-202523.1 KiB798562

test_lru_map.cD18-Mar-202523.1 KiB886557

test_lwt_ip_encap.shD18-Mar-202514.6 KiB476336

test_lwt_seg6local.shD18-Mar-20256.1 KiB156108

test_maps.cD18-Mar-202550 KiB1,9291,463

test_maps.hD18-Mar-2025369 2014

test_offload.pyD18-Mar-202550.7 KiB1,4071,134

test_progs.cD18-Mar-202538.4 KiB1,7241,364

test_progs.hD18-Mar-202510.3 KiB400350

test_select_reuseport_common.hD18-Mar-2025587 3727

test_skb_cgroup_id.shD18-Mar-20251.3 KiB6449

test_skb_cgroup_id_user.cD18-Mar-20253.5 KiB184144

test_sock.cD18-Mar-202513 KiB557480

test_sock_addr.cD18-Mar-202530.7 KiB1,4341,228

test_sock_addr.shD18-Mar-20251.1 KiB5947

test_sockmap.cD18-Mar-202545.3 KiB2,0991,775

test_sysctl.cD18-Mar-202540.1 KiB1,6341,142

test_tag.cD18-Mar-20254.3 KiB207165

test_tc_edt.shD18-Mar-20252.7 KiB10065

test_tc_tunnel.shD18-Mar-20257.5 KiB305221

test_tcp_check_syncookie.shD18-Mar-20251.7 KiB8667

test_tcp_check_syncookie_user.cD18-Mar-20256.2 KiB300237

test_tcp_hdr_options.hD18-Mar-20253.3 KiB153125

test_tcpbpf.hD18-Mar-2025434 2319

test_tcpnotify.hD18-Mar-2025273 2014

test_tcpnotify_user.cD18-Mar-20253.7 KiB169139

test_tunnel.shD18-Mar-202516.5 KiB698532

test_verifier.cD18-Mar-202546.4 KiB1,7821,435

test_verifier_log.cD18-Mar-20253.9 KiB176138

test_xdp_meta.shD18-Mar-20251.4 KiB5840

test_xdp_redirect.shD18-Mar-20251.8 KiB8051

test_xdp_redirect_multi.shD18-Mar-20256.2 KiB215148

test_xdp_veth.shD18-Mar-20253.2 KiB12281

test_xdp_vlan.shD18-Mar-20255.9 KiB234152

test_xdp_vlan_mode_generic.shD18-Mar-2025186 103

test_xdp_vlan_mode_native.shD18-Mar-2025180 103

test_xdping.shD18-Mar-20252.1 KiB10454

test_xsk.shD18-Mar-20254.9 KiB209101

testing_helpers.cD18-Mar-20254.7 KiB232189

testing_helpers.hD18-Mar-2025810 2315

trace_helpers.cD18-Mar-20254.3 KiB227162

trace_helpers.hD18-Mar-2025521 2515

urandom_read.cD18-Mar-20251.9 KiB8958

urandom_read_aux.cD18-Mar-2025286 105

urandom_read_lib1.cD18-Mar-2025411 148

urandom_read_lib2.cD18-Mar-2025265 95

verify_sig_setup.shD18-Mar-20252 KiB10576

veristat.cD18-Mar-202532.3 KiB1,3231,088

veristat.cfgD18-Mar-2025310 1817

vmtest.shD18-Mar-20259.7 KiB429337

with_addr.shD18-Mar-20251.3 KiB5540

with_tunnels.shD18-Mar-2025693 3723

xdp_redirect_multi.cD18-Mar-20255.2 KiB227188

xdp_synproxy.cD18-Mar-202510.7 KiB467408

xdping.cD18-Mar-20255.7 KiB255202

xdping.hD18-Mar-2025283 149

xsk.cD18-Mar-202528.3 KiB1,269985

xsk.hD18-Mar-20258.3 KiB317219

xsk_prereqs.shD18-Mar-20251.7 KiB9374

xskxceiver.cD18-Mar-202550.8 KiB1,9681,518

xskxceiver.hD18-Mar-20253.9 KiB182157

README.rst

1==================
2BPF Selftest Notes
3==================
4General instructions on running selftests can be found in
5`Documentation/bpf/bpf_devel_QA.rst`__.
6
7__ /Documentation/bpf/bpf_devel_QA.rst#q-how-to-run-bpf-selftests
8
9=========================
10Running Selftests in a VM
11=========================
12
13It's now possible to run the selftests using ``tools/testing/selftests/bpf/vmtest.sh``.
14The script tries to ensure that the tests are run with the same environment as they
15would be run post-submit in the CI used by the Maintainers.
16
17This script downloads a suitable Kconfig and VM userspace image from the system used by
18the CI. It builds the kernel (without overwriting your existing Kconfig), recompiles the
19bpf selftests, runs them (by default ``tools/testing/selftests/bpf/test_progs``) and
20saves the resulting output (by default in ``~/.bpf_selftests``).
21
22Script dependencies:
23- clang (preferably built from sources, https://github.com/llvm/llvm-project);
24- pahole (preferably built from sources, https://git.kernel.org/pub/scm/devel/pahole/pahole.git/);
25- qemu;
26- docutils (for ``rst2man``);
27- libcap-devel.
28
29For more information on about using the script, run:
30
31.. code-block:: console
32
33  $ tools/testing/selftests/bpf/vmtest.sh -h
34
35In case of linker errors when running selftests, try using static linking:
36
37.. code-block:: console
38
39  $ LDLIBS=-static vmtest.sh
40
41.. note:: Some distros may not support static linking.
42
43.. note:: The script uses pahole and clang based on host environment setting.
44          If you want to change pahole and llvm, you can change `PATH` environment
45          variable in the beginning of script.
46
47.. note:: The script currently only supports x86_64 and s390x architectures.
48
49Additional information about selftest failures are
50documented here.
51
52profiler[23] test failures with clang/llvm <12.0.0
53==================================================
54
55With clang/llvm <12.0.0, the profiler[23] test may fail.
56The symptom looks like
57
58.. code-block:: c
59
60  // r9 is a pointer to map_value
61  // r7 is a scalar
62  17:       bf 96 00 00 00 00 00 00 r6 = r9
63  18:       0f 76 00 00 00 00 00 00 r6 += r7
64  math between map_value pointer and register with unbounded min value is not allowed
65
66  // the instructions below will not be seen in the verifier log
67  19:       a5 07 01 00 01 01 00 00 if r7 < 257 goto +1
68  20:       bf 96 00 00 00 00 00 00 r6 = r9
69  // r6 is used here
70
71The verifier will reject such code with above error.
72At insn 18 the r7 is indeed unbounded. The later insn 19 checks the bounds and
73the insn 20 undoes map_value addition. It is currently impossible for the
74verifier to understand such speculative pointer arithmetic.
75Hence `this patch`__ addresses it on the compiler side. It was committed on llvm 12.
76
77__ https://reviews.llvm.org/D85570
78
79The corresponding C code
80
81.. code-block:: c
82
83  for (int i = 0; i < MAX_CGROUPS_PATH_DEPTH; i++) {
84          filepart_length = bpf_probe_read_str(payload, ...);
85          if (filepart_length <= MAX_PATH) {
86                  barrier_var(filepart_length); // workaround
87                  payload += filepart_length;
88          }
89  }
90
91bpf_iter test failures with clang/llvm 10.0.0
92=============================================
93
94With clang/llvm 10.0.0, the following two bpf_iter tests failed:
95  * ``bpf_iter/ipv6_route``
96  * ``bpf_iter/netlink``
97
98The symptom for ``bpf_iter/ipv6_route`` looks like
99
100.. code-block:: c
101
102  2: (79) r8 = *(u64 *)(r1 +8)
103  ...
104  14: (bf) r2 = r8
105  15: (0f) r2 += r1
106  ; BPF_SEQ_PRINTF(seq, "%pi6 %02x ", &rt->fib6_dst.addr, rt->fib6_dst.plen);
107  16: (7b) *(u64 *)(r8 +64) = r2
108  only read is supported
109
110The symptom for ``bpf_iter/netlink`` looks like
111
112.. code-block:: c
113
114  ; struct netlink_sock *nlk = ctx->sk;
115  2: (79) r7 = *(u64 *)(r1 +8)
116  ...
117  15: (bf) r2 = r7
118  16: (0f) r2 += r1
119  ; BPF_SEQ_PRINTF(seq, "%pK %-3d ", s, s->sk_protocol);
120  17: (7b) *(u64 *)(r7 +0) = r2
121  only read is supported
122
123This is due to a llvm BPF backend bug. `The fix`__
124has been pushed to llvm 10.x release branch and will be
125available in 10.0.1. The patch is available in llvm 11.0.0 trunk.
126
127__  https://reviews.llvm.org/D78466
128
129bpf_verif_scale/loop6.bpf.o test failure with Clang 12
130======================================================
131
132With Clang 12, the following bpf_verif_scale test failed:
133  * ``bpf_verif_scale/loop6.bpf.o``
134
135The verifier output looks like
136
137.. code-block:: c
138
139  R1 type=ctx expected=fp
140  The sequence of 8193 jumps is too complex.
141
142The reason is compiler generating the following code
143
144.. code-block:: c
145
146  ;       for (i = 0; (i < VIRTIO_MAX_SGS) && (i < num); i++) {
147      14:       16 05 40 00 00 00 00 00 if w5 == 0 goto +64 <LBB0_6>
148      15:       bc 51 00 00 00 00 00 00 w1 = w5
149      16:       04 01 00 00 ff ff ff ff w1 += -1
150      17:       67 05 00 00 20 00 00 00 r5 <<= 32
151      18:       77 05 00 00 20 00 00 00 r5 >>= 32
152      19:       a6 01 01 00 05 00 00 00 if w1 < 5 goto +1 <LBB0_4>
153      20:       b7 05 00 00 06 00 00 00 r5 = 6
154  00000000000000a8 <LBB0_4>:
155      21:       b7 02 00 00 00 00 00 00 r2 = 0
156      22:       b7 01 00 00 00 00 00 00 r1 = 0
157  ;       for (i = 0; (i < VIRTIO_MAX_SGS) && (i < num); i++) {
158      23:       7b 1a e0 ff 00 00 00 00 *(u64 *)(r10 - 32) = r1
159      24:       7b 5a c0 ff 00 00 00 00 *(u64 *)(r10 - 64) = r5
160
161Note that insn #15 has w1 = w5 and w1 is refined later but
162r5(w5) is eventually saved on stack at insn #24 for later use.
163This cause later verifier failure. The bug has been `fixed`__ in
164Clang 13.
165
166__  https://reviews.llvm.org/D97479
167
168BPF CO-RE-based tests and Clang version
169=======================================
170
171A set of selftests use BPF target-specific built-ins, which might require
172bleeding-edge Clang versions (Clang 12 nightly at this time).
173
174Few sub-tests of core_reloc test suit (part of test_progs test runner) require
175the following built-ins, listed with corresponding Clang diffs introducing
176them to Clang/LLVM. These sub-tests are going to be skipped if Clang is too
177old to support them, they shouldn't cause build failures or runtime test
178failures:
179
180- __builtin_btf_type_id() [0_, 1_, 2_];
181- __builtin_preserve_type_info(), __builtin_preserve_enum_value() [3_, 4_].
182
183.. _0: https://reviews.llvm.org/D74572
184.. _1: https://reviews.llvm.org/D74668
185.. _2: https://reviews.llvm.org/D85174
186.. _3: https://reviews.llvm.org/D83878
187.. _4: https://reviews.llvm.org/D83242
188
189Floating-point tests and Clang version
190======================================
191
192Certain selftests, e.g. core_reloc, require support for the floating-point
193types, which was introduced in `Clang 13`__. The older Clang versions will
194either crash when compiling these tests, or generate an incorrect BTF.
195
196__  https://reviews.llvm.org/D83289
197
198Kernel function call test and Clang version
199===========================================
200
201Some selftests (e.g. kfunc_call and bpf_tcp_ca) require a LLVM support
202to generate extern function in BTF.  It was introduced in `Clang 13`__.
203
204Without it, the error from compiling bpf selftests looks like:
205
206.. code-block:: console
207
208  libbpf: failed to find BTF for extern 'tcp_slow_start' [25] section: -2
209
210__ https://reviews.llvm.org/D93563
211
212btf_tag test and Clang version
213==============================
214
215The btf_tag selftest requires LLVM support to recognize the btf_decl_tag and
216btf_type_tag attributes. They are introduced in `Clang 14` [0_, 1_].
217The subtests ``btf_type_tag_user_{mod1, mod2, vmlinux}`` also requires
218pahole version ``1.23``.
219
220Without them, the btf_tag selftest will be skipped and you will observe:
221
222.. code-block:: console
223
224  #<test_num> btf_tag:SKIP
225
226.. _0: https://reviews.llvm.org/D111588
227.. _1: https://reviews.llvm.org/D111199
228
229Clang dependencies for static linking tests
230===========================================
231
232linked_vars, linked_maps, and linked_funcs tests depend on `Clang fix`__ to
233generate valid BTF information for weak variables. Please make sure you use
234Clang that contains the fix.
235
236__ https://reviews.llvm.org/D100362
237
238Clang relocation changes
239========================
240
241Clang 13 patch `clang reloc patch`_  made some changes on relocations such
242that existing relocation types are broken into more types and
243each new type corresponds to only one way to resolve relocation.
244See `kernel llvm reloc`_ for more explanation and some examples.
245Using clang 13 to compile old libbpf which has static linker support,
246there will be a compilation failure::
247
248  libbpf: ELF relo #0 in section #6 has unexpected type 2 in .../bpf_tcp_nogpl.bpf.o
249
250Here, ``type 2`` refers to new relocation type ``R_BPF_64_ABS64``.
251To fix this issue, user newer libbpf.
252
253.. Links
254.. _clang reloc patch: https://reviews.llvm.org/D102712
255.. _kernel llvm reloc: /Documentation/bpf/llvm_reloc.rst
256
257Clang dependencies for the u32 spill test (xdpwall)
258===================================================
259The xdpwall selftest requires a change in `Clang 14`__.
260
261Without it, the xdpwall selftest will fail and the error message
262from running test_progs will look like:
263
264.. code-block:: console
265
266  test_xdpwall:FAIL:Does LLVM have https://reviews.llvm.org/D109073? unexpected error: -4007
267
268__ https://reviews.llvm.org/D109073
269