diff --git a/tests/failing_tests/vmlinux/ctx_data_arith.py b/tests/failing_tests/vmlinux/ctx_data_arith.py new file mode 100644 index 0000000..d09a5d6 --- /dev/null +++ b/tests/failing_tests/vmlinux/ctx_data_arith.py @@ -0,0 +1,27 @@ +# xdp_md.data is declared u32, so C's rules make ctx.data - k a 32-bit +# subtraction, and that is what the compiler emits (w0 += -1). The verifier +# tracks data as a packet pointer and rejects it: "R0 32-bit pointer +# arithmetic prohibited". C hits the same and casts through (void *)(long). +# The planned fix gives the packet-pointer fields 64-bit pointer rank so no +# cast is needed; see the TODO in expr_pass._descriptor. The same u32 rank on +# a scalar field is pinned as passing in passing_tests/vmlinux/ctx_field_rank.py. +from ctypes import c_int32, c_int64 +from pythonbpf import bpf, section, bpfglobal, compile +from vmlinux import struct_xdp_md + + +@bpf +@section("xdp") +def prog(ctx: struct_xdp_md) -> c_int64: + k = c_int32(1) + d = ctx.data - k + return c_int64(d) + + +@bpf +@bpfglobal +def LICENSE() -> str: + return "GPL" + + +compile() diff --git a/tests/test_config.toml b/tests/test_config.toml index 6f9bec0..3f81509 100644 --- a/tests/test_config.toml +++ b/tests/test_config.toml @@ -60,3 +60,7 @@ "failing_tests/loops/for_continue.py" = {reason = "for/while loops not implemented: continue is not supported", level = "ir"} "failing_tests/loops/for_map_items.py" = {reason = "for/while loops not implemented: no sugar over bpf_for_each_map_elem()-style map iteration exists yet", level = "ir"} + +# 32-bit arithmetic on a packet-pointer context field. IR and llc succeed; the +# verifier rejects it with "R0 32-bit pointer arithmetic prohibited". +"failing_tests/vmlinux/ctx_data_arith.py" = {reason = "xdp_md.data is u32 in C but a packet pointer to the verifier; 32-bit arithmetic on it is prohibited until packet-pointer fields get 64-bit pointer rank", level = "verifier"}