aya-rs / aya

Aya is an eBPF library for the Rust programming language, built with a focus on developer experience and operability.
https://aya-rs.dev/book/
Apache License 2.0
3.26k stars 291 forks source link

xdp_hello example fails verifier in docker rust container #1104

Closed esemeniuc closed 18 hours ago

esemeniuc commented 1 day ago

Running the xdp_hello example with the following commands fails in:

docker run -it --privileged --network host --rm -v ~/dev/aya-book:/myapp -w /myapp rust bash

Inside the container, I ran:

rustup install nightly
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
cargo install bpf-linker
cd examples/xdp-hello/
cargo xtask build-ebpf

Output

   Compiling xdp-hello-common v0.1.0 (/myapp/examples/xdp-hello/xdp-hello-common)
   Compiling xdp-hello v0.1.0 (/myapp/examples/xdp-hello/xdp-hello)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 6.26s
Error: the BPF_PROG_LOAD syscall failed. Verifier output: last insn is not an exit or jmp
verification time 9 usec
stack depth 0+0+0
processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0

Caused by:
    Invalid argument (os error 22)

Host OS: arch running 6.6.52-1-lts

esemeniuc commented 1 day ago

Issue: info! calls must be removed. The demo is broken due to that. See https://discord.com/channels/855676609003651072/1310568860738388059/1312632243574931517

An alternative is to use bpf_printk instead

unsafe {
    aya_ebpf::bpf_printk!(b"packet  received!");
}

To see output, open another terminal enable tracing: echo 1 | sudo tee /sys/kernel/debug/tracing/tracing_on

Then to see output sudo cat /sys/kernel/debug/tracing/trace_pipe

From another terminal, ping the interface ping 127.0.0.1

Source: https://dev.to/stevelatif/aya-rust-tutorial-part-four-xdp-hello-world-4c85

tamird commented 19 hours ago

Does it work if you use --release?

tamird commented 18 hours ago

The template and book have been updated to only build ebpf in release mode. Please file an issue against those if you continue to be able to reproduce.

esemeniuc commented 17 hours ago

Yes this works, thank you very much

rustup install nightly
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
cargo install bpf-linker
cd examples/xdp-hello/
cargo xtask build-ebpf --release
cargo build --release