The <picture> picked its source with prefers-color-scheme, which follows
the browser or OS, not the theme chosen on GitHub. With GitHub on Light
and the system on dark, the dark logo was shown: its white wordmark
vanished on the white page and left the emblem alone at the left of a
3:1 box, so the logo looked off-centre.
docs/_static/pythonbpf-logo.svg is the light logo with its wordmark in
#3776ab, the emblem's own blue: 4.8:1 against GitHub's white and 3.9:1
against its dark background. The README links it by absolute URL so the
PyPI page, which renders the same README, shows it too.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The <picture> sat outside any centered block, so GitHub drew the logo at
the left edge. Wrap it in <p align="center"> like the badges below it
(GitHub strips style attributes but keeps align). Also drop the alt on
<source>, which ignores it, and give the <img> a real description.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
tests/c-form/map_update_from_lookup.bpf.c mirrors the two programs the
check covers. At -O0 clang passes bpf_map_update_elem the result of
`load ptr, ptr <prev's slot>`, in both copy() and rebind().
The old expected pattern only asked for some load of prev, and `if prev`
already does one, so it matched the buggy IR too. The check now requires
the value loaded from prev's slot to be the helper's value argument. It
fails on the code before dde720f and passes on this branch.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The overview example still labelled the LICENSE declaration as required,
which contradicts the GPL default documented in decorators.md and the
quickstart.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
retype, helper_cond, direct_assign and globals had no xfail entry and have
been passing at every level; their NOTE headers describe limits that have
since been lifted, so they are rewritten. xdp_pass was an xfail only because
it used the old count().lookup() spelling of a map call; in the current
syntax it compiles.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
handle_expr lowered a statement only when it was a call, and dropped any
other expression with an INFO log. So `print(a) if c else print(b)` compiled
to nothing at all, and failing_tests/conditionals/oneline.py passed. An
expression statement that contains a call is now a compile error; one
without (a docstring, a bare name) is still dropped. oneline.py becomes an
IR-level xfail.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`if dat:` on a local struct built Constant(struct_type, 0) in
convert_to_bool, and llvmlite failed later, while printing the module, with
"'int' object is not iterable". A struct has no truth value (C rejects
`if (s)`; Python would call any object true), so it is now a TypeError
that says to test a field. A pointer to a struct is unaffected.
The xfail was named struct_ptr but tests a struct value; it is renamed to
struct_value.py and becomes a negative test.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A local bound to a map lookup holds a pointer, and get_or_create_ptr_from_arg
handed a helper the address of that local's stack slot instead. So
count.update(k, prev) stored the kernel address of the map value, not the
value, and after prev = prev + 1 it stored the address of the temporary.
The verifier accepts both when loading as root, so nothing failed: the
failing_tests/vmlinux/named_arg.py example has been passing all along while
storing the wrong thing. The slot is now loaded when it holds a pointer.
named_arg.py moves to passing_tests, and both it and a new
map_update_from_lookup.py are pinned by IR assertions.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Without a LICENSE, @llvm.compiler.used still named one, and opt stopped on
"use of undefined value @LICENSE". A program with no LICENSE now gets "GPL",
the kernel's own license, and a warning that says so; an explicit LICENSE
is emitted as written.
The old failing license test becomes passing_tests/license_default.py: it
calls print, which lowers to the GPL-only bpf_trace_printk, so the verifier
accepts it only if the default reaches the kernel. license_non_gpl.py is
the counterpart, a verifier-level negative fixture pinned to the kernel's
GPL rejection, and test_license_ir.py checks both license sections and the
warning.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
-d asks the kernel for the instruction-level verifier log on every load. For
loop1, which makes the verifier walk nested loops, that log outgrows libbpf's
buffer; the kernel fails the load with ENOSPC, libbpf doubles the buffer and
verifies again, and on CI the load ran past the 30s timeout. A rejection
still comes with its log without -d, since libbpf retries a failed load at
log level 1 and prints it as a warning.
The timeout path also returned a bare string where callers expect stdout and
stderr, so a timeout surfaced as an AttributeError instead of the timeout.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Four programs from prog_tests/bpf_verif_scale.c that loops alone kept out.
The loop lowering matches clang's for the same C, but volatile, barrier()
and the no-unroll pragma have no spelling here: loop2 folds to a constant
and loop4 unrolls, so those two no longer make the verifier walk a loop.
Their headers and PORTING-NOTES.md say so.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
for/while lower since #106. The iterator loops (bpf_for, bpf_repeat) and the
bpf_loop helper do not, so they keep a hard label of their own, and a
do { } while (0) macro is no longer read as a loop. Against bpf-next 5714ca8
the programs with no hard blocker go from 29 to 39.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* Core: Lower annotated assignment (x: c_int32 = 0)
The annotation types the slot, so `x: c_int32 = 0` is an i32 where the
literal alone would give an i64; the store goes through the same
handle_variable_assignment plain assignment uses. A bare `x: T` makes the
slot and binds nothing.
The already-bound and global-shadowing bookkeeping that Assign allocation did
inline moves into _bind_name, which both statements now call.
* Tests: Annotated assignment passes now
* Core: Lower if-branches in the function's return type
handle_if processed its branches without passing ret_type down, so a
return inside an if fell back to process_stmt's i64 default: a -> c_int32
function got `ret i64 7`, which llc rejects. The branches now go through
process_block, which threads ret_type and stops at a statement that ends
the block instead of emitting after its terminator.
* Core: Lower for-over-range and while loops, with break and continue
`for i in range(...)` steps a hidden induction counter, allocated in the
entry block next to the loop variable, and copies it into the variable each
iteration, so rebinding the variable in the body leaves the trip count alone
as in Python (and the loop stays visibly bounded for the verifier). The
counter is 64-bit, signed unless the bounds make C's arithmetic unsigned.
Bounds are evaluated once, before the loop; the step must be a nonzero
integer literal, because its sign picks the loop test.
`while` re-evaluates its test at the top of each iteration. `break` and
`continue` branch through a loop-target stack on the compilation context;
outside a loop they are a SyntaxError, as in Python. A loop's else-branch
runs on normal exit only. Anything but range() as the iterable is rejected
with NotImplementedError.
The allocation pass now descends into loop bodies and counts helper temps in
loop headers. Checked against clang -O2 on tests/c-form/loops.bpf.c: the
constant-bound cases fold to the same ret, and a helper-bounded loop gets the
same rotated loop.
* Tests: Loops pass now, plus the cases the lowering promises
- passing_tests/loops/: the seven range/while/break/continue/nested tests
move over from failing_tests/, joined by rebinding the loop variable, a
negative step, loop else-branches, and a helper-bounded loop over a
@bpfglobal that survives -O2 as a real loop for the verifier.
- failing_tests/loops/: break outside a loop, and a non-literal range step.
- for_map_items stays xfail: map iteration needs its own design.
- c-form/loops.bpf.c: the clang reference the lowering was checked against.
* Tests: Indent the loop C reference with spaces
The remove-tabs pre-commit hook rejects tab indentation outside docs/ and
Makefiles, which failed the Format job.
* Core: Fix loop edge cases the lowering got wrong
- `pass` is accepted as a statement, the natural body of a loop run for its
side effects.
- Falling off the end of a function returns 0 in the function's own return
type. After `while True` that block is unreachable, but a c_int32 function
still emitted `ret i64 0`, which llc rejected.
- A range() step other than 1 could wrap the counter past INT64_MAX or
UINT64_MAX back inside the range and loop forever. The step block now ends
the loop when the distance left to stop, exact as an unsigned number, is
no longer than the step. That is a normal exit, so the else-branch runs.
Steps of 1 cannot overshoot and keep the plain loop, so the helper-bounded
loop the verifier walks is unchanged.
- A step of 2**64 or more no longer truncates to 0: it is a compile error,
since it does not fit the counter. Steps from 2**63 up are emitted by
their bits.
- The counter's signedness folds each bound into a signed 64-bit type rather
than joining the bounds alone, so only a c_uint64 bound makes it unsigned:
range(-1, n) over a c_uint32 n runs 4 times, as in C with an __s64 counter.
* Tests: Run loop programs on the host, plus adversarial loop cases
Levels 1 and 2 only prove a loop compiles; one can still run the wrong
number of times, or forever. test_loops_run.py JIT-compiles each
helper-free passing_tests/loops case on the host (framework/host_jit.py,
in a subprocess with a timeout) and checks its return value against what
CPython returns for the same body.
- passing_tests/loops/: pass bodies, `while True` exited by a return in a
c_int32 function, step overflow past INT64_MAX, INT64_MIN and UINT64_MAX,
a c_uint32 stop with a negative start, and loop variables that must stay
one local (a nested same-name loop, a read after the loop).
- failing_tests/loops/range_step_too_wide.py: a 2**64 step is a compile error.
- reuse_loop_var_signedness.py is xfail in test_loops_run.py: every local
gets one slot typed by its first binding, so a second loop's `i` inherits
the first loop's unsigned type. `x = n_u64; x = -3` does the same, so the
fix is general, not loop-specific.
ctx_field_into_slots.py stores 8-, 32- and 64-bit sk_buff fields into
locals declared at every width and into struct fields of every width,
with IR assertions on the slot widths and the truncation before each
store. It is the compact form of a 52-case matrix (four field widths,
nine local and four struct-field destinations) compiled on master and
here: every case compiles, nothing sign-extends a field on the way in,
and where master compiled the IR is identical except where master put a
narrow local in a 64-bit slot. c_bool.py covers the local, struct field,
map value and global.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
c_bool was missing from the ctypes table, so c_bool(5) was an unknown
call, its slot was never allocated, and the error read "Undefined
variable". It is C's _Bool: one bit, like the True/False locals, never
negative, and a value narrows to it by comparing with zero, which the
signedness rules already apply to 1-bit types. It works as a local, a
struct field, a map value and a global; in BTF it is a one-byte _Bool.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Two places took an integer's width as 32 or 64 bits. Ten sites computed
byte sizes as width // 8 (alignment, struct layout, globals), which is
zero for a 1-bit type; they now share byte_size(), which rounds up to
whole bytes. And debug info described every map key or value, and every
struct field, that was not 32 bits wide as unsigned long long: a c_uint8
or c_uint16 map value was declared 8 bytes wide in BTF, so the kernel
copied 8 bytes from a smaller slot. get_int_type() now gives the real
width and sign everywhere, globals included.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The printk formatter accepted 64- and 32-bit integers only and raised for
anything else. That went unnoticed while c_uint16(0) and friends silently
made 64-bit slots; with those slots now their declared width, printing
any 8- or 16-bit local failed. Every integer argument is already widened
to 64 bits per its sign before the call, so the 64-bit format fits every
width, and the sign now chooses %lld or %llu (an unsigned value above
INT_MAX printed as negative before).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
get_typed_operand fell through its Name branch for a name that is not a
local, a global or a vmlinux constant, and raised the generic
"Unsupported operand type" meant for unknown node kinds. Since return
goes through it, forgetting `from vmlinux import XDP_PASS` produced that
message; it says "Undefined variable XDP_PASS" now, like every other
read.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
helpers.py defined all five and return_utils mapped them, but only
XDP_DROP and XDP_PASS were exported, so the xdp_tx port had to import
XDP_TX from vmlinux and live under vmlinux/, skipped on any host without
a generated module. It imports from pythonbpf.helper and lives under
xdp/ now, returning XDP_TX bare like its siblings and the C original,
which is the shape the return fast path resolves without vmlinux.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Every xfail is strict with raises=Exception, so a verifier-level
negative fixture counted any rejection as the expected one, including
one caused by a codegen regression, or by bpftool failing. A verifier
entry may now carry match = "..."; the harness attaches it as a
verifier_match marker and test_kernel_verifier fails, through
pytest.fail (not swallowed by raises=Exception), when the program is
rejected for any other reason. xdp_devmap_helpers pins its documented
"invalid bpf_context access".
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
process_array_map was a stub raising NotImplementedError while ArrayMap
was exported from pythonbpf.maps as if usable. The lowering is the hash
map's with a different type constant: the same lookup/update/delete
helpers, and the kernel fixes the key at a 4-byte index. The lookup
allocation path accepts ARRAY alongside HASH, the audit tool lists
ARRAY as supported, and the array_map_lookup_update case is a passing
test now instead of a strict xfail.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The Field branch of handle_variable_assignment rebuilt the field's type
by name and duplicated the integer convert() path, and ctypes_to_ir
raises NotImplementedError for a pointer or array ctype before the
logged error is reached. An integer Field is now normalised to its
declared IntTy (field_int_type) before the integer path, in both
variable and struct-field assignment, so ctx fields go through the same
convert() call as everything else; the Field branch keeps only the
non-integer error.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
_allocate_for_call recognised only c_int32, c_int64, c_uint32, c_uint64
and c_void_p, so queue = c_uint16(0) fell through to an i64 slot and a
later store of a u32 field into it never narrowed. Any integer ctypes
constructor now declares a slot of its width, which is what the
ctx_field_narrow_store test claimed to pin; the IR assertion pins it.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
- The subprog_call pattern also matched SEC("?..."), so every
non-autoloaded program counted as a BPF-to-BPF call blocker, in
contradiction with the soft rule for the same syntax.
- The kfunc pattern matched any bpf_xdp_* or bpf_skb_* call, which are
ordinary helpers (bpf_skb_store_bytes is in SUPPORTED_HELPERS). Only
the kfunc families keep those prefixes; an unsupported helper is still
a hard blocker, classified as one.
- strip_comments removed // inside string literals, truncating section
names like SEC("uprobe//proc/self/exe:func") and classifying the file
as a shim. Strings are matched first and kept.
- Every bpf_map_* helper not in SUPPORTED_HELPERS was dropped before the
unsupported-helper test, so bpf_map_push_elem and friends never showed
up as blockers. The membership test classifies them now.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
except Exception turned every import-time defect in the generated module
into a skip of every vmlinux test, so CI could pass with no vmlinux
coverage. ImportError (no module) skips; anything else propagates.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
veristat_foo (three socket programs) is clean. test_perf_link,
test_enable_stats and test_cgroup_link count with __sync_fetch_and_add, which
becomes a plain `x += 1` tagged WORKAROUND(atomics) for a mechanical sweep
once atomics exist. connect4_dropper compares against bpf_htons(port), written
out as shifts on the low 16 bits. All five pass at IR, llc and verifier level,
and bring perf_event, raw_tracepoint/sys_enter, cgroup_skb/egress and
cgroup/connect4 under test.
The porting notes gain the third batch, the atomics tag, the current blocker
histogram from the checked-in audit tool, and how to re-run it.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DLMW3X7opqAPH6bjmTVkr7
The porting assessment was produced by a one-off script that scored every
program under tools/testing/selftests/bpf/progs against the compiler's
envelope; the notes recommended keeping it so the numbers can be regenerated
after each feature lands. This is that script, rebuilt: it strips comments,
skips include-shims and header-only fixtures, and reports per program the
hard blockers (language gaps) and soft flags (porting costs), with a
histogram and a near-miss listing. The helper, map and construct lists at
the top are the envelope and are maintained by hand.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DLMW3X7opqAPH6bjmTVkr7
Every program on the selftest audit's Tier 1 and Tier 2 lists that the compiler
can express today: xdp_dummy, priv_prog, test_xdp_link, xdp_tx, tc_dummy,
test_tc_bpf, cgroup_mprog, cgroup_skb_direct_packet_access, test_signed_loader,
test_signed_loader_data, test_netfilter_link_attach, kprobe_multi_empty,
uprobe_multi_bench, uprobe_multi_usdt, test_link_pinning and
test_xdp_devmap_helpers. Fifteen pass at every level, bringing tc, tcx,
cgroup/getsockopt, cgroup_skb, socket, netfilter, kprobe.multi, uprobe.multi,
usdt and tp_btf program types under test for the first time.
test_xdp_devmap_helpers is a negative fixture upstream: reading egress_ifindex
is only legal with expected_attach_type = BPF_XDP_DEVMAP and the driver asserts
the plain load fails. It is a strict verifier-level xfail here for the same
reason, until expected_attach_type can be expressed.
The porting notes record the batch and why each remaining program on the two
lists is still out of reach.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DLMW3X7opqAPH6bjmTVkr7
A sub-register context field is loaded zero-extended to i64, and the
assignment path accepted it only into a 64-bit slot or one whose type was
exactly the field's declared type. The second case never worked in practice:
`data_end = skb.data_end` into a c_uint32 global died in llvmlite with
"cannot store i64 to i32*" because the value was still i64.
Route the store through convert(), sizing from the physical value and signing
from the field, like every other integer store since the signedness work: a
no-op into an i64 slot, a trunc into anything narrower. Found by porting
cgroup_skb_direct_packet_access.c, which is that exact statement.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DLMW3X7opqAPH6bjmTVkr7
The selftest spike substituted a one-entry HashMap for every upstream global
because PythonBPF had no global variable support. Integer-scalar @bpfglobal
support has since landed, so the three affected ports now declare the upstream
globals directly: get_cgroup_id reads expected_pid and writes cg_id, autoattach
shares prog1_called/prog2_called between two programs, and perf_skip reads ip.
perf_skip stays a strict xfail on the nested ctx.regs.ip access.
Update the tests README and porting notes accordingly; the WORKAROUND tag no
longer exists in the tree.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DLMW3X7opqAPH6bjmTVkr7
xdp_md.data/data_end/data_meta and __sk_buff.data/data_end are u32 in
C and packet pointers to the verifier, so arithmetic on them directly
is rejected as 32-bit pointer arithmetic, for C and for us alike. A
TODO at the point where a field's rank is decided describes the planned
fix (64-bit pointer rank for those fields, no cast needed), and the
user guide documents the workaround until then: copy to a local or cast
through c_void_p.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
xdp_md.data is a u32 in C, but the verifier tracks it as a packet
pointer and rejects 32-bit arithmetic on it: "R0 32-bit pointer
arithmetic prohibited", the same for a C program, which is why C casts
it through (void *)(long) first. The u32 ranking the test pins is the
correct one; it just has to be pinned on a field that is a scalar to the
verifier too. ingress_ifindex is.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
One IR-shape case per fix: u32 >>= / //= / %= emit lshr/udiv/urem;
ktime() >> 1 and pid() // 3 emit lshr/udiv; p >> 63 on a c_uint64 map
value is lshr; ctx.data - c_int32 is a u32 subtraction with the
trunc/zext pair rather than a 64-bit one.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The binary-operation path chooses sdiv/udiv, srem/urem and ashr/lshr from
the promoted type; the augmented-assignment path computed the same
promoted type and then called apply_binop without it, so u32 >>= 4 was
an ashr and u32 //= 3 an sdiv. Same call as the binop path now.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
- A global's descriptor is built from the loaded value, not from None.
- get_operand_value, the [0] wrapper over get_typed_operand, had no
callers left; removed with its export.
- infer_int_type's map branch names the map's declared value type for
what it is (value_ctype), says that the key argument plays no part,
and applies only to lookup: update and delete return a status, not a
value of the map's type.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Two descriptors were built from the physical value instead of the
declaration. A sub-register vmlinux field is widened to i64 by
load_ctx_field, and its descriptor took that width, so ctx.data - k with
a c_int32 k was a 64-bit subtraction where C makes it a u32 one. A
map-lookup local dereferenced past its slot took the physical pointee
(i64, signed by default) and dropped the map's declared value ctype kept
in the symbol's metadata, so p >> 63 on a c_uint64 value was an ashr.
Both now read the declaration; the physical width still comes from the
value, as everywhere else.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
The registry types ktime, pid, uid, random, cgroup_id and smp_processor_id
as unsigned, and undeclared locals initialised from them already took
that sign. The expression value did not: each emitter returns
(value, plain i64), so ktime() >> 1 was an ashr and pid() // 3 an sdiv.
The dispatcher now substitutes the registered descriptor when the widths
agree, in one place instead of in every emitter.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>