0

我有一个与XDP program ip link error: Prog section denied: Operation not allowed类似的问题,Linux 5.4.0 除外。

我能够运行一些 XDP eBPF 程序,但不能运行 AF_XDP:

➜ uname -r
5.4.0
➜ sudo strace -e bpf ./xdpsock -i eth0 -t -q1 -F
bpf(BPF_PROG_GET_FD_BY_ID, {prog_id=35, next_id=0}, 112) = 4
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=208, info=0xptr}}, 112) = 0
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=4, info_len=208, info=0xptr}}, 112) = 0
bpf(BPF_MAP_GET_FD_BY_ID, {map_id=35, next_id=0}, 112) = 5
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=5, info_len=80, info=0xptr}}, 112) = 0
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=5, key=0xkeyptr, value=0xvalptr, flags=BPF_ANY}, 112) = -1 E2BIG (Argument list too long)
bpf(BPF_MAP_DELETE_ELEM, {map_fd=5, key=0xkeyptr}, 112) = -1 EINVAL (Invalid argument)
samples/bpf/xdpsock_user.c:xsk_configure_socket:331: errno: 1/"Operation not permitted"
program on interface changed, not removing
+++ exited with 1 +++

但是,rxq_info 示例程序确实有效:

➜ sudo strace -e bpf ./xdp_rxq_info -d eth0 -F
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2, insns=0xptr, license="GPL", log_level=0, log_size=0, log_buf=0, kern_version=0, prog_flags=0}, 1
12) = 4
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=2, insns=0xptr, license="GPL", log_level=0, log_size=0, log_buf=0, kern_version=0, prog_flags=0, ..
.}, 112) = 4
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_ARRAY, key_size=4, value_size=32, max_entries=1, map_flags=0, inner_map_fd=0}, 112) = 4
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_SOCKET_FILTER, insn_cnt=5, insns=0xptr, license="GPL", log_level=0, log_size=0, log_buf=0, kern_version=0, prog_flags=0}, 1
12) = 5
bpf(0x12 /* BPF_??? */, 0xptr, 112) = 4
bpf(0x12 /* BPF_??? */, 0xptr, 112) = 4
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_ARRAY, key_size=4, value_size=12, max_entries=1, map_flags=0, inner_map_fd=0, ...}, 112) = 3
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERCPU_ARRAY, key_size=4, value_size=16, max_entries=1, map_flags=0, inner_map_fd=0, ...}, 112) = 4
bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_PERCPU_ARRAY, key_size=4, value_size=16, max_entries=65, map_flags=0, inner_map_fd=0, ...}, 112) = 5
bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_XDP, insn_cnt=81, insns=0xptr, license="GPL", log_level=0, log_size=0, log_buf=0, kern_version=0, prog_flags=0, ...}, 112)
= 6
bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0xptr, value=0xptr, flags=BPF_ANY}, 112) = 0
bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=6, info_len=208, info=0xptr}}, 112) = 0
bpf(BPF_MAP_LOOKUP_ELEM, {map_fd=4, key=0xptr, value=0xptr}, 112) = 0

并且 XDP 已启用(否则 rxq_info 示例程序将无法工作):

➜ grep XDP /boot/config-`uname -r`
CONFIG_XDP_SOCKETS=y
CONFIG_XDP_SOCKETS_DIAG=y

失败的调用在这里:https ://elixir.bootlin.com/linux/v5.4/source/tools/lib/bpf/xsk.c#L475 。为什么运行 xdpsock 会导致错误?

4

0 回答 0