iovisor / iovisor/bcc

__bpf_vprintk is not working

Open
#4,058 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
10d 4h
Merged PRs (30d)
3

Description

When I use __bpf_vprintk on my xdp.c, it reports the following error. If I don’t use __bpf_vprintk, the error is gone. Any hints will be appreaciated:

```
go run -exec sudo ./pkg ens160
2022/06/17 05:00:51 loading objects: field XdpProgFunc: program xdp_prog_func: load program: invalid argument: ; int xdp_prog_func(struct xdp_md *ctx)
0: (b7) r0 = 0
; void *data_end = (void *)(long)ctx->data_end;
1: (61) r9 = *(u32 *)(r1 +4)
; void *data = (void *)(long)ctx->data;
2: (61) r6 = *(u32 *)(r1 +0)
; if (data + sizeof(struct ethhdr) > data_end)
3: (bf) r1 = r6
4: (07) r1 += 14
; if (data + sizeof(struct ethhdr) > data_end)
5: (2d) if r1 > r9 goto pc+702
R0_w=inv0 R1_w=pkt(id=0,off=14,r=14,imm=0) R6_w=pkt(id=0,off=0,r=14,imm=0) R9_w=pkt_end(id=0,off=0,imm=0) R10=fp0
; if (ethh->h_proto != bpf_htons(ETH_P_IP))
6: (71) r1 = *(u8 *)(r6 +12)
7: (71) r2 = *(u8 *)(r6 +13)
8: (67) r2 <<= 8
9: (4f) r2 |= r1
10: (b7) r0 = 2
; if (ethh->h_proto != bpf_htons(ETH_P_IP))
11: (55) if r2 != 0x8 goto pc+696
R0_w=inv2 R1_w=inv(id=0,umax_value=255,var_off=(0x0; 0xff)) R2_w=inv8 R6_w=pkt(id=0,off=0,r=14,imm=0) R9_w=pkt_end(id=0,off=0,imm=0) R10=fp0
; if (data + sizeof(struct ethhdr) + sizeof(struct iphdr) > data_end)
12: (bf) r7 = r6
13: (07) r7 += 34
14: (b7) r0 = 0
; if (data + sizeof(struct ethhdr) + sizeof(struct iphdr) > data_end)
15: (2d) if r7 > r9 goto pc+692
R0=inv0 R1=inv(id=0,umax_value=255,var_off=(0x0; 0xff)) R2=inv8 R6=pkt(id=0,off=0,r=34,imm=0) R7=pkt(id=0,off=34,r=34,imm=0) R9=pkt_end(id=0,off=0,imm=0) R10=fp0
; if (iph->protocol != IPPROTO_TCP)
16: (71) r1 = *(u8 *)(r6 +23)
17: (b7) r0 = 2
; if (iph->protocol != IPPROTO_TCP)
18: (55) if r1 != 0x6 goto pc+689
R0_w=inv2 R1_w=inv6 R2=inv8 R6=pkt(id=0,off=0,r=34,imm=0) R7=pkt(id=0,off=34,r=34,imm=0) R9=pkt_end(id=0,off=0,imm=0) R10=fp0
; if (data + sizeof(struct ethhdr) + sizeof(struct iphdr) + sizeof(struct tcphdr) > data_end)
19: (bf) r1 = r6
20: (07) r1 += 54
21: (b7) r0 = 0
; if (data + sizeof(struct ethhdr) + sizeof(struct iphdr) + sizeof(struct tcphdr) > data_end)
22: (2d) if r1 > r9 goto pc+685
R0_w=inv0 R1_w=pkt(id=0,off=54,r=54,imm=0) R2=inv8 R6=pkt(id=0,off=0,r=54,imm=0) R7=pkt(id=0,off=34,r=54,imm=0) R9=pkt_end(id=0,off=0,imm=0) R10=fp0
; __bpf_vprintk("\nHello: port=%d, port=%d,port=%d,port=%d\n", __bpf_ntohs(tcph->source), __bpf_ntohs(tcph->source), __bpf_ntohs(tcph->source), __bpf_ntohs(tcph->source));
23: (69) r1 = *(u16 *)(r6 +34)
24: (dc) r1 = be16 r1
25: (7b) *(u64 *)(r10 -8) = r1
26: (7b) *(u64 *)(r10 -16) = r1
27: (7b) *(u64 *)(r10 -24) = r1
28: (7b) *(u64 *)(r10 -32) = r1
29: (bf) r3 = r10
30: (07) r3 += -32
31: (18) r1 = 0xffff8a22c384e123
33: (b7) r2 = 42
34: (b7) r4 = 32
35: (85) call unknown#177
invalid func unknown#177
processed 35 insns (limit 1000000

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the __bpf_vprintk call in xdp.c and reproduce the failure using `go run -exec sudo ./pkg ens160`. Inspect the verifier output around `call unknown#177`; done means determining why this call is rejected and documenting or implementing a compatible resolution.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.