building eBPF
Cc XDP-newbies, as I cannot scale by doing individual "support".
Quoted 4 lines · On Sat, 25 Apr 2020 08:22:25 -0400 Sowmini Varadhan <[email protected]> wrote:
Hi Jesper,
I am trying to get some basic eBPF examples up and running and I ran into the problem you describe at https://lkml.org/lkml/2020/2/19/433
Yes, building kernel bpf selftests requires latest LLVM, currently works with LLVM-10.
Quoted 5 lines
I dont want to deal with building my own llvm (looks like it needs more disk space than is available in my test mmachine, and I dont want to go hunting for space just yet) so do you have some suggestions on how I can work around this (maybe skip some of the advanced tests?
The kernel's samples/bpf/ should still builds with LLVM-9 (and lower). Follow instructions in the README.rst file[1].
There are pre-build Debian and Ubuntu packages for LLVM-10 here:
https://apt.llvm.org/
Quoted 1 line
I am just trying to play with basic examples at this point)
I suggest you start with the XDP-tutorial[2], it (still) works with older LLVM versions: [2] https://github.com/xdp-project/xdp-tutorial
[1] https://github.com/torvalds/linux/blob/master/samples/bpf/README.rst
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer
Quoted 6 lines · Jesper Dangaard Brouer
Quoted 2 lines
I am trying to get some basic eBPF examples up and running and I ran into the problem you describe at https://lkml.org/lkml/2020/2/19/433
Yes, building kernel bpf selftests requires latest LLVM, currently works with LLVM-10.
ubuntu 20.04 was just released, and it has llvm-10. I have been using it to build and run the bpf selftests.
Quoted 6 lines · Jesper Dangaard Brouer
The kernel's
samples/bpf/should still builds with LLVM-9 (and lower). Follow instructions in theREADME.rstfile[1].There are pre-build Debian and Ubuntu packages for LLVM-10 here:
https://apt.llvm.org/
thanks that helped me install llvm-10
However, after all my adventures, I end up with
# ls /usr/bin/llc* /usr/bin/llc /usr/bin/llc-10 /usr/bin/llc-5.0 /usr/bin/llc-6.0 /usr/bin/llc-7 and the default points at 6.0 so I had to go and tweak Makefile to use clang-10 and llc-10
After that, samples builds and runs (thanks for that hint!). But not selftests. However, samples is good enough for my experiments, for now.
Quoted 2 lines
I suggest you start with the XDP-tutorial[2], it (still) works with older LLVM versions: [2] https://github.com/xdp-project/xdp-tutorial
will do.
--Sowmini
With the latest iproute2 (built from master, 'ip -V' reports iproute2-ss200330) when I try to run tc_l2_redirect.sh I get errors like the following. What am I missing?
(full transcript of output from run is in the run.out attachment)
:
+ tc filter add dev ve2 ingress bpf da obj ./tc_l2_redirect_kern.o sec l2_to_iptun_ingress_forward
BTF debug data section '.BTF' rejected: Invalid argument (22)!
- Length: 3554
Verifier analysis:
magic: 0xeb9f
version: 1
flags: 0x0hdr_len: 24type_off: 0type_len: 984str_off: 984str_len: 2546btf_total_size: 3554
[1] PTR (anon) type_id=2
[2] STRUCT __sk_buff size=184 vlen=32
len type_id=3 bits_offset=0
pkt_type type_id=3 bits_offset=32
mark type_id=3 bits_offset=64
queue_mapping type_id=3 bits_offset=96
protocol type_id=3 bits_offset=128
vlan_present type_id=3 bits_offset=160
vlan_tci type_id=3 bits_offset=192
vlan_proto type_id=3 bits_offset=224
:
:
+ [[ -z '' ]]
+ TC=tc
+ [[ -z '' ]]
+ IP=ip
+ REDIRECT_USER=./tc_l2_redirect
+ REDIRECT_BPF=./tc_l2_redirect_kern.o
+ RP_FILTER=0
+ IPV6_FORWARDING=1
+ cleanup
+ set +e
+ [[ -z '' ]]
+ ip netns delete ns1
+ ip netns delete ns2
+ ip link del ve1
+ ip link del ve2
+ ip link del ipt
+ ip link del ip6t
+ sysctl -q -w net.ipv4.conf.all.rp_filter=0
+ sysctl -q -w net.ipv6.conf.all.forwarding=1
+ rm -f /sys/fs/bpf/tc/globals/tun_iface
+ [[ -z '' ]]
+ set -e
+ test_names='l2_to_ipip l2_to_ip6tnl'
+ test_dirs='ingress egress'
+ [[ 0 -ge 2 ]]
+ [[ 0 -ge 1 ]]
+ for t in $test_names
+ for d in $test_dirs
+ l2_to_ipip ingress
+ echo -n 'l2_to_ipip ingress: 'l2_to_ipip ingress: + local dir=ingress
+ config_common ipip
+ local tun_type=ipip
+ ip netns add ns1
+ ip netns add ns2
+ ip link add ve1 type veth peer name vens1
+ ip link add ve2 type veth peer name vens2
+ ip link set dev ve1 up
+ ip link set dev ve2 up
+ ip link set dev ve1 mtu 1500
+ ip link set dev ve2 mtu 1500
+ ip link set dev vens1 netns ns1
+ ip link set dev vens2 netns ns2
+ ip -n ns1 link set dev lo up
+ ip -n ns1 link set dev vens1 up
+ ip -n ns1 addr add 10.1.1.101/24 dev vens1
+ ip -n ns1 addr add 2401:db01::65/64 dev vens1 nodad
+ ip -n ns1 route add default via 10.1.1.1 dev vens1
+ ip -n ns1 route add default via 2401:db01::1 dev vens1
+ ip -n ns2 link set dev lo up
+ ip -n ns2 link set dev vens2 up
+ ip -n ns2 addr add 10.2.1.102/24 dev vens2
+ ip -n ns2 addr add 2401:db02::66/64 dev vens2 nodad
+ ip -n ns2 addr add 10.10.1.102 dev lo
+ ip -n ns2 addr add 2401:face::66/64 dev lo nodad
+ ip -n ns2 link add ipt2 type ipip local 10.2.1.102 remote 10.2.1.1
+ ip -n ns2 link add ip6t2 type ip6tnl mode any local 2401:db02::66 remote 2401:db02::1
+ ip -n ns2 link set dev ipt2 up
+ ip -n ns2 link set dev ip6t2 up
+ ip netns exec ns2 tc qdisc add dev vens2 clsact
+ ip netns exec ns2 tc filter add dev vens2 ingress bpf da obj ./tc_l2_redirect_kern.o sec drop_non_tun_vip
BTF debug data section '.BTF' rejected: Invalid argument (22)!
- Length: 3554
Verifier analysis:
magic: 0xeb9f
version: 1
flags: 0x0hdr_len: 24type_off: 0type_len: 984str_off: 984str_len: 2546btf_total_size: 3554
[1] PTR (anon) type_id=2
[2] STRUCT __sk_buff size=184 vlen=32
len type_id=3 bits_offset=0 pkt_type type_id=3 bits_offset=32 mark type_id=3 bits_offset=64 queue_mapping type_id=3 bits_offset=96 protocol type_id=3 bits_offset=128 vlan_present type_id=3 bits_offset=160 vlan_tci type_id=3 bits_offset=192 vlan_proto type_id=3 bits_offset=224 priority type_id=3 bits_offset=256 ingress_ifindex type_id=3 bits_offset=288 ifindex type_id=3 bits_offset=320 tc_index type_id=3 bits_offset=352 cb type_id=5 bits_offset=384 hash type_id=3 bits_offset=544 tc_classid type_id=3 bits_offset=576 data type_id=3 bits_offset=608 data_end type_id=3 bits_offset=640 napi_id type_id=3 bits_offset=672 family type_id=3 bits_offset=704 remote_ip4 type_id=3 bits_offset=736 local_ip4 type_id=3 bits_offset=768 remote_ip6 type_id=7 bits_offset=800 local_ip6 type_id=7 bits_offset=928 remote_port type_id=3 bits_offset=1056 local_port type_id=3 bits_offset=1088 data_meta type_id=3 bits_offset=1120 (anon) type_id=8 bits_offset=1152 tstamp type_id=10 bits_offset=1216 wire_len type_id=3 bits_offset=1280 gso_segs type_id=3 bits_offset=1312 (anon) type_id=12 bits_offset=1344 gso_size type_id=3 bits_offset=1408
[3] TYPEDEF __u32 type_id=4
[4] INT unsigned int size=4 bits_offset=0 nr_bits=32 encoding=(none)
[5] ARRAY (anon) type_id=3 index_type_id=6 nr_elems=5
[6] INT __ARRAY_SIZE_TYPE__ size=4 bits_offset=0 nr_bits=32 encoding=(none)
[7] ARRAY (anon) type_id=3 index_type_id=6 nr_elems=4
[8] UNION (anon) size=8 vlen=1
flow_keys type_id=9 bits_offset=0
[9] PTR (anon) type_id=30
[10] TYPEDEF __u64 type_id=11
[11] INT long long unsigned int size=8 bits_offset=0 nr_bits=64 encoding=(none)
[12] UNION (anon) size=8 vlen=1
sk type_id=13 bits_offset=0
[13] PTR (anon) type_id=31
[14] FUNC_PROTO (anon) return=15 args=(1 skb)
[15] INT int size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
[16] FUNC _l2_to_iptun_ingress_forward type_id=14
[17] FUNC_PROTO (anon) return=15 args=(1 skb)
[18] FUNC _l2_to_iptun_ingress_redirect type_id=17
[19] FUNC_PROTO (anon) return=15 args=(1 skb)
[20] FUNC _l2_to_ip6tun_ingress_redirect type_id=19
[21] FUNC_PROTO (anon) return=15 args=(1 skb)
[22] FUNC _drop_non_tun_vip type_id=21
[23] STRUCT bpf_elf_map size=28 vlen=7
type type_id=3 bits_offset=0
size_key type_id=3 bits_offset=32 size_value type_id=3 bits_offset=64 max_elem type_id=3 bits_offset=96
flags type_id=3 bits_offset=128
id type_id=3 bits_offset=160
pinning type_id=3 bits_offset=192
[24] VAR tun_iface type_id=23 linkage=1
[25] INT char size=1 bits_offset=0 nr_bits=8 encoding=SIGNED
[26] ARRAY (anon) type_id=25 index_type_id=6 nr_elems=4
[27] VAR _license type_id=26 linkage=1
[28] DATASEC license size=0 vlen=1 size == 0
+ [[ ipip == \i\p\i\p ]]
+ ip -n ns2 route add 10.1.1.0/24 dev ipt2
+ ip netns exec ns2 sysctl -q -w net.ipv4.conf.all.rp_filter=0
+ ip netns exec ns2 sysctl -q -w net.ipv4.conf.ipt2.rp_filter=0
+ ip addr add 10.1.1.1/24 dev ve1
+ ip addr add 2401:db01::1/64 dev ve1 nodad
+ ip addr add 10.2.1.1/24 dev ve2
+ ip addr add 2401:db02::1/64 dev ve2 nodad
+ tc qdisc add dev ve2 clsact
+ tc filter add dev ve2 ingress bpf da obj ./tc_l2_redirect_kern.o sec l2_to_iptun_ingress_forward
BTF debug data section '.BTF' rejected: Invalid argument (22)!
- Length: 3554
Verifier analysis:
magic: 0xeb9f
version: 1
flags: 0x0hdr_len: 24type_off: 0type_len: 984str_off: 984str_len: 2546btf_total_size: 3554
[1] PTR (anon) type_id=2
[2] STRUCT __sk_buff size=184 vlen=32
len type_id=3 bits_offset=0 pkt_type type_id=3 bits_offset=32 mark type_id=3 bits_offset=64 queue_mapping type_id=3 bits_offset=96 protocol type_id=3 bits_offset=128 vlan_present type_id=3 bits_offset=160 vlan_tci type_id=3 bits_offset=192 vlan_proto type_id=3 bits_offset=224 priority type_id=3 bits_offset=256 ingress_ifindex type_id=3 bits_offset=288 ifindex type_id=3 bits_offset=320 tc_index type_id=3 bits_offset=352 cb type_id=5 bits_offset=384 hash type_id=3 bits_offset=544 tc_classid type_id=3 bits_offset=576 data type_id=3 bits_offset=608 data_end type_id=3 bits_offset=640 napi_id type_id=3 bits_offset=672 family type_id=3 bits_offset=704 remote_ip4 type_id=3 bits_offset=736 local_ip4 type_id=3 bits_offset=768 remote_ip6 type_id=7 bits_offset=800 local_ip6 type_id=7 bits_offset=928 remote_port type_id=3 bits_offset=1056 local_port type_id=3 bits_offset=1088 data_meta type_id=3 bits_offset=1120 (anon) type_id=8 bits_offset=1152 tstamp type_id=10 bits_offset=1216 wire_len type_id=3 bits_offset=1280 gso_segs type_id=3 bits_offset=1312 (anon) type_id=12 bits_offset=1344 gso_size type_id=3 bits_offset=1408
[3] TYPEDEF __u32 type_id=4
[4] INT unsigned int size=4 bits_offset=0 nr_bits=32 encoding=(none)
[5] ARRAY (anon) type_id=3 index_type_id=6 nr_elems=5
[6] INT __ARRAY_SIZE_TYPE__ size=4 bits_offset=0 nr_bits=32 encoding=(none)
[7] ARRAY (anon) type_id=3 index_type_id=6 nr_elems=4
[8] UNION (anon) size=8 vlen=1
flow_keys type_id=9 bits_offset=0
[9] PTR (anon) type_id=30
[10] TYPEDEF __u64 type_id=11
[11] INT long long unsigned int size=8 bits_offset=0 nr_bits=64 encoding=(none)
[12] UNION (anon) size=8 vlen=1
sk type_id=13 bits_offset=0
[13] PTR (anon) type_id=31
[14] FUNC_PROTO (anon) return=15 args=(1 skb)
[15] INT int size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
[16] FUNC _l2_to_iptun_ingress_forward type_id=14
[17] FUNC_PROTO (anon) return=15 args=(1 skb)
[18] FUNC _l2_to_iptun_ingress_redirect type_id=17
[19] FUNC_PROTO (anon) return=15 args=(1 skb)
[20] FUNC _l2_to_ip6tun_ingress_redirect type_id=19
[21] FUNC_PROTO (anon) return=15 args=(1 skb)
[22] FUNC _drop_non_tun_vip type_id=21
[23] STRUCT bpf_elf_map size=28 vlen=7
type type_id=3 bits_offset=0
size_key type_id=3 bits_offset=32 size_value type_id=3 bits_offset=64 max_elem type_id=3 bits_offset=96
flags type_id=3 bits_offset=128
id type_id=3 bits_offset=160
pinning type_id=3 bits_offset=192
[24] VAR tun_iface type_id=23 linkage=1
[25] INT char size=1 bits_offset=0 nr_bits=8 encoding=SIGNED
[26] ARRAY (anon) type_id=25 index_type_id=6 nr_elems=4
[27] VAR _license type_id=26 linkage=1
[28] DATASEC license size=0 vlen=1 size == 0
+ sysctl -q -w net.ipv4.conf.all.rp_filter=0
+ sysctl -q -w net.ipv6.conf.all.forwarding=1
+ ip link add ipt type ipip external
+ ip link set dev ipt up
+ sysctl -q -w net.ipv4.conf.ipt.rp_filter=0
+ sysctl -q -w net.ipv4.conf.ipt.forwarding=1
+ [[ ingress == \e\g\r\e\s\s ]]
+ tc qdisc add dev ve1 clsact
+ tc filter add dev ve1 ingress bpf da obj ./tc_l2_redirect_kern.o sec l2_to_iptun_ingress_redirect
BTF debug data section '.BTF' rejected: Invalid argument (22)!
- Length: 3554
Verifier analysis:
magic: 0xeb9f
version: 1
flags: 0x0hdr_len: 24type_off: 0type_len: 984str_off: 984str_len: 2546btf_total_size: 3554
[1] PTR (anon) type_id=2
[2] STRUCT __sk_buff size=184 vlen=32
len type_id=3 bits_offset=0 pkt_type type_id=3 bits_offset=32 mark type_id=3 bits_offset=64 queue_mapping type_id=3 bits_offset=96 protocol type_id=3 bits_offset=128 vlan_present type_id=3 bits_offset=160 vlan_tci type_id=3 bits_offset=192 vlan_proto type_id=3 bits_offset=224 priority type_id=3 bits_offset=256 ingress_ifindex type_id=3 bits_offset=288 ifindex type_id=3 bits_offset=320 tc_index type_id=3 bits_offset=352 cb type_id=5 bits_offset=384 hash type_id=3 bits_offset=544 tc_classid type_id=3 bits_offset=576 data type_id=3 bits_offset=608 data_end type_id=3 bits_offset=640 napi_id type_id=3 bits_offset=672 family type_id=3 bits_offset=704 remote_ip4 type_id=3 bits_offset=736 local_ip4 type_id=3 bits_offset=768 remote_ip6 type_id=7 bits_offset=800 local_ip6 type_id=7 bits_offset=928 remote_port type_id=3 bits_offset=1056 local_port type_id=3 bits_offset=1088 data_meta type_id=3 bits_offset=1120 (anon) type_id=8 bits_offset=1152 tstamp type_id=10 bits_offset=1216 wire_len type_id=3 bits_offset=1280 gso_segs type_id=3 bits_offset=1312 (anon) type_id=12 bits_offset=1344 gso_size type_id=3 bits_offset=1408
[3] TYPEDEF __u32 type_id=4
[4] INT unsigned int size=4 bits_offset=0 nr_bits=32 encoding=(none)
[5] ARRAY (anon) type_id=3 index_type_id=6 nr_elems=5
[6] INT __ARRAY_SIZE_TYPE__ size=4 bits_offset=0 nr_bits=32 encoding=(none)
[7] ARRAY (anon) type_id=3 index_type_id=6 nr_elems=4
[8] UNION (anon) size=8 vlen=1
flow_keys type_id=9 bits_offset=0
[9] PTR (anon) type_id=30
[10] TYPEDEF __u64 type_id=11
[11] INT long long unsigned int size=8 bits_offset=0 nr_bits=64 encoding=(none)
[12] UNION (anon) size=8 vlen=1
sk type_id=13 bits_offset=0
[13] PTR (anon) type_id=31
[14] FUNC_PROTO (anon) return=15 args=(1 skb)
[15] INT int size=4 bits_offset=0 nr_bits=32 encoding=SIGNED
[16] FUNC _l2_to_iptun_ingress_forward type_id=14
[17] FUNC_PROTO (anon) return=15 args=(1 skb)
[18] FUNC _l2_to_iptun_ingress_redirect type_id=17
[19] FUNC_PROTO (anon) return=15 args=(1 skb)
[20] FUNC _l2_to_ip6tun_ingress_redirect type_id=19
[21] FUNC_PROTO (anon) return=15 args=(1 skb)
[22] FUNC _drop_non_tun_vip type_id=21
[23] STRUCT bpf_elf_map size=28 vlen=7
type type_id=3 bits_offset=0
size_key type_id=3 bits_offset=32 size_value type_id=3 bits_offset=64 max_elem type_id=3 bits_offset=96
flags type_id=3 bits_offset=128
id type_id=3 bits_offset=160
pinning type_id=3 bits_offset=192
[24] VAR tun_iface type_id=23 linkage=1
[25] INT char size=1 bits_offset=0 nr_bits=8 encoding=SIGNED
[26] ARRAY (anon) type_id=25 index_type_id=6 nr_elems=4
[27] VAR _license type_id=26 linkage=1
[28] DATASEC license size=0 vlen=1 size == 0
+ ./tc_l2_redirect -U /sys/fs/bpf/tc/globals/tun_iface -i 19
+ ip netns exec ns1 ping -c1 10.10.1.102
+ [[ ingress == \e\g\r\e\s\s ]]
+ echo bail
bail
+ exit 1
Quoted 3 lines · On Sun, 26 Apr 2020 20:20:27 -0400 Sowmini Varadhan <[email protected]> wrote:
With the latest iproute2 (built from master, 'ip -V' reports iproute2-ss200330) when I try to run
tc_l2_redirect.shI get errors like the following. What am I missing?
The iproute2 BPF-loader does not support BTF. I think upstream agrees that it would be too much work to add (and maintain) it, so the current plan[1] is to convert iproute2 to use libbpf instead.
Also notice that BPF-map layout is not compatible with libbpf. Thus, yet another hint not to use iproute2 to load XDP programs. (Toke have done some initial work with libbpf maps, that will allow us AFAIK to be backward compatible when converting iproute2 to libbpf).
Why do you want to use 'tc' to load XDP?
The XDP-tutorial[2] shows how to use libbpf from your C-programs, and XDP-tools[3] contains a xdp-loader that you can use instead.
[1] https://xdp-project.net/#Port-iproute2-to-libbpf
[2] https://github.com/xdp-project/xdp-tutorial
[3] https://github.com/xdp-project/xdp-tools/tree/master/xdp-loader
Quoted 7 lines
(full transcript of output from run is in the run.out attachment)
:
+ tc filter add dev ve2 ingress bpf da obj ./tc_l2_redirect_kern.o secl2_to_iptun_ingress_forwardBTF debug data section '.BTF' rejected: Invalid argument (22)!
- Length: 3554
I actually think this is only a warning, and the program is actually loaded...
Signature · 4 lines
Best regards, Jesper Dangaard Brouer MSc.CS, Principal Kernel Engineer at Red Hat LinkedIn: http://www.linkedin.com/in/brouer
Quoted 8 lines · Sowmini Varadhan
Quoted 6 lines · Jesper Dangaard Brouer
The kernel's
samples/bpf/should still builds with LLVM-9 (and lower). Follow instructions in theREADME.rstfile[1].There are pre-build Debian and Ubuntu packages for LLVM-10 here:
https://apt.llvm.org/
Quoted 7 lines
thanks that helped me install llvm-10
However, after all my adventures, I end up with
# ls /usr/bin/llc* /usr/bin/llc /usr/bin/llc-10 /usr/bin/llc-5.0 /usr/bin/llc-6.0 /usr/bin/llc-7 and the default points at 6.0 so I had to go and tweak Makefile to use clang-10 and llc-10
Note that you can just override them on the command line. E.g.,
make CLANG=clang-10 LLC=llc-10
-Toke
Quoted 5 lines
The iproute2 BPF-loader does not support BTF. I think upstream agrees that it would be too much work to add (and maintain) it, so the current plan[1] is to convert iproute2 to use libbpf instead.
So I updated my iproute2 because I was initially getting an error like
" Error fixing up map structure, incompatible struct bpf_elf_map used?
Error fetching ELF ancillary data!
Unable to load program
"
with the native iproute2 binaries, and thought it may be due to a header mismatch.
Quoted 1 line
Why do you want to use 'tc' to load XDP?
I was merely using the exsiting example in samples to try to understand this. If the existing example is misleading, it should be removed.
Quoted 2 lines
I actually think this is only a warning, and the program is actually loaded...
no I dont believe it is. if you insert a break in the script before it gets to cleanup, and try
# ip netns exec ns2 bash # tc filter show dev vens2
it will not show any loaded filters.
--Sowmini
Quoted 4 lines · Sowmini Varadhan
Quoted 4 lines
The iproute2 BPF-loader does not support BTF. I think upstream agrees that it would be too much work to add (and maintain) it, so the current plan[1] is to convert iproute2 to use libbpf instead.
Not true, iproute2 does(did) support BTF, but afaik later versions of clang/ llvm broke it so it would need to be fixed again [0]. Emission of BTF can be removed as a workaround w/ omitting -g.
Quoted 17 lines
So I updated my iproute2 because I was initially getting an error like
" Error fixing up map structure, incompatible struct
bpf_elf_mapused?
Error fetching ELF ancillary data!
Unable to load program
"
with the native iproute2 binaries, and thought it may be due to a header mismatch.Quoted 1 line
Why do you want to use 'tc' to load XDP?
I was merely using the exsiting example in samples to try to understand this. If the existing example is misleading, it should be removed.
Quoted 2 lines
I actually think this is only a warning, and the program is actually loaded...
Quoted 7 lines
no I dont believe it is. if you insert a break in the script before it gets to cleanup, and try
# ip netns exec ns2 bash # tc filter show dev vens2it will not show any loaded filters.
Check out https://cilium.readthedocs.io/en/latest/bpf/#iproute2 for XDP + iproute2 examples examples for where to check; but agree you might rather want to go with libbpf's feature set overall.
Quoted 2 lines
--Sowmini