mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
pping: Add hint on XDP failure
Due to a kernel bug for XDP programs loaded via libxdp that use global functions (see https://lore.kernel.org/bpf/8735gkwy8h.fsf@toke.dk/t/), XDP mode only works on relatively recent kernels where the bug is patched (or kernels where the patch has been backported). As many users may not have such a recent kernel they will only see a confusing verifier error like the following: Starting ePPing in standard mode tracking TCP on test123 libbpf: elf: skipping unrecognized data section(7) xdp_metadata libbpf: elf: skipping unrecognized data section(7) xdp_metadata libbpf: prog 'pping_xdp_ingress': BPF program load failed: Invalid argument libbpf: prog 'pping_xdp_ingress': -- BEGIN PROG LOAD LOG -- Func#1 is safe for any args that match its prototype Validating pping_xdp_ingress() func#0... 0: R1=ctx(id=0,off=0,imm=0) R10=fp0 ; int pping_xdp_ingress(struct xdp_md *ctx) 0: (bf) r6 = r1 ; R1=ctx(id=0,off=0,imm=0) R6_w=ctx(id=0,off=0,imm=0) 1: (b7) r7 = 0 ; R7_w=invP0 ; struct packet_info p_info = { 0 }; 2: (7b) *(u64 *)(r10 -8) = r7 ; R7_w=invP0 R10=fp0 fp-8_w=00000000 3: (7b) *(u64 *)(r10 -16) = r7 ; R7_w=invP0 R10=fp0 fp-16_w=00000000 4: (7b) *(u64 *)(r10 -24) = r7 ; R7_w=invP0 R10=fp0 fp-24_w=00000000 5: (7b) *(u64 *)(r10 -32) = r7 ; R7_w=invP0 R10=fp0 fp-32_w=00000000 6: (7b) *(u64 *)(r10 -40) = r7 ; R7_w=invP0 R10=fp0 fp-40_w=00000000 7: (7b) *(u64 *)(r10 -48) = r7 ; R7_w=invP0 R10=fp0 fp-48_w=00000000 8: (7b) *(u64 *)(r10 -56) = r7 ; R7_w=invP0 R10=fp0 fp-56_w=00000000 9: (7b) *(u64 *)(r10 -64) = r7 ; R7_w=invP0 R10=fp0 fp-64_w=00000000 10: (7b) *(u64 *)(r10 -72) = r7 ; R7_w=invP0 R10=fp0 fp-72_w=00000000 11: (7b) *(u64 *)(r10 -80) = r7 ; R7_w=invP0 R10=fp0 fp-80_w=00000000 12: (7b) *(u64 *)(r10 -88) = r7 ; R7_w=invP0 R10=fp0 fp-88_w=00000000 13: (7b) *(u64 *)(r10 -96) = r7 ; R7_w=invP0 R10=fp0 fp-96_w=00000000 14: (7b) *(u64 *)(r10 -104) = r7 ; R7_w=invP0 R10=fp0 fp-104_w=00000000 15: (7b) *(u64 *)(r10 -112) = r7 ; R7_w=invP0 R10=fp0 fp-112_w=00000000 16: (7b) *(u64 *)(r10 -120) = r7 ; R7_w=invP0 R10=fp0 fp-120_w=00000000 17: (7b) *(u64 *)(r10 -128) = r7 ; R7_w=invP0 R10=fp0 fp-128_w=00000000 18: (bf) r2 = r10 ; R2_w=fp0 R10=fp0 ; 19: (07) r2 += -128 ; R2=fp-128 ; if (parse_packet_identifer_xdp(ctx, &p_info) < 0) 20: (85) call pc+13 R1 type=ctx expected=fp Caller passes invalid args into func#1 processed 206542 insns (limit 1000000) max_states_per_insn 32 total_states 13238 peak_states 792 mark_read 40 -- END PROG LOAD LOG -- libbpf: failed to load program 'pping_xdp_ingress' libbpf: failed to load object 'pping_kern.o' Failed attaching ingress BPF program on interface test123: Invalid argument Failed loading and attaching BPF programs in pping_kern.o To help users that run into this issue when loading the program in generic or unspecified mode, add a small hint suggesting to upgrade the kernel or use the tc ingress mode instead in case attaching the XDP program fails. However, if loaded in native mode, instead give the suggestion to try loading in generic mode instead. While libbpf and libxdp already add some messages hinting at this, this hint clarifies how to do this with ePPing (using the --xdp-mode argument). Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
This commit is contained in:
@@ -911,6 +911,16 @@ static int load_attach_bpfprogs(struct bpf_object **obj,
|
||||
/* xdp_attach() loads 'obj' through libxdp */
|
||||
err = xdp_attach(*obj, config->ingress_prog, config->ifindex,
|
||||
&config->xdp_prog, config->xdp_mode);
|
||||
if (err) {
|
||||
fprintf(stderr, "Failed attaching XDP program\n");
|
||||
if (config->xdp_mode == XDP_MODE_NATIVE)
|
||||
fprintf(stderr,
|
||||
"%s may not have driver support for XDP, try --xdp-mode generic instead\n",
|
||||
config->ifname);
|
||||
else
|
||||
fprintf(stderr,
|
||||
"Try updating kernel or use --ingress-hook tc instead\n");
|
||||
}
|
||||
} else {
|
||||
err = bpf_object__load(*obj);
|
||||
if (err) {
|
||||
|
Reference in New Issue
Block a user