Skip to content

Commit fab456b

Browse files
r41k0uclaude
andcommitted
Tests: Pin 32-bit arithmetic on xdp_md.data as a verifier-level xfail
xdp_md.data is u32 in C, so ctx.data - k lowers to a 32-bit add on the loaded value, exactly as C ranks it, and the verifier rejects it: it tracks data as a packet pointer and prohibits 32-bit pointer arithmetic (observed in CI). IR and llc succeed, so the entry is at the verifier level. It flips to passing when packet-pointer fields get 64-bit pointer rank (TODO in expr_pass._descriptor). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent dc628ee commit fab456b

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# xdp_md.data is declared u32, so C's rules make ctx.data - k a 32-bit
2+
# subtraction, and that is what the compiler emits (w0 += -1). The verifier
3+
# tracks data as a packet pointer and rejects it: "R0 32-bit pointer
4+
# arithmetic prohibited". C hits the same and casts through (void *)(long).
5+
# The planned fix gives the packet-pointer fields 64-bit pointer rank so no
6+
# cast is needed; see the TODO in expr_pass._descriptor. The same u32 rank on
7+
# a scalar field is pinned as passing in passing_tests/vmlinux/ctx_field_rank.py.
8+
from ctypes import c_int32, c_int64
9+
from pythonbpf import bpf, section, bpfglobal, compile
10+
from vmlinux import struct_xdp_md
11+
12+
13+
@bpf
14+
@section("xdp")
15+
def prog(ctx: struct_xdp_md) -> c_int64:
16+
k = c_int32(1)
17+
d = ctx.data - k
18+
return c_int64(d)
19+
20+
21+
@bpf
22+
@bpfglobal
23+
def LICENSE() -> str:
24+
return "GPL"
25+
26+
27+
compile()

‎tests/test_config.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@
6060
"failing_tests/loops/for_continue.py" = {reason = "for/while loops not implemented: continue is not supported", level = "ir"}
6161

6262
"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"}
63+
64+
# 32-bit arithmetic on a packet-pointer context field. IR and llc succeed; the
65+
# verifier rejects it with "R0 32-bit pointer arithmetic prohibited".
66+
"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"}

0 commit comments

Comments
 (0)