raspberrypi / linux

Kernel source tree for Raspberry Pi-provided kernel builds. Issues unrelated to the linux kernel should be posted on the community forum at https://forums.raspberrypi.com/
Other
11.02k stars 4.95k forks source link

NIC card driver does not set `xdp->frame_sz` properly in `bpf_xdp_adjust_tail` #4948

Open myl7 opened 2 years ago

myl7 commented 2 years ago

Describe the bug

Calling bpf_xdp_adjust_tail in XDP always fails with -EINVAL, even when shrinking the frame, because xdp->frame_sz > PAGE_SIZE returns false since xdp->frame_sz is over 30000 but PAGE_SIZE is 4096.

Steps to reproduce the behaviour

Device (s)

Raspberry Pi 3 Mod. B+

System

Raspberry Pi OS (64-bit)

Raspberry Pi reference 2022-01-28
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, fbe448ccdc995d295d24c7596e5f0ef62cc2488f, stage2
Jan 20 2022 13:58:22 
Copyright (c) 2012 Broadcom
version bd88f66f8952d34e4e0613a85c7a6d3da49e13e2 (clean) (release) (start)

Self built on recent latest commit

Linux pi 5.15.28-v8+ #6 SMP PREEMPT Thu Mar 17 18:20:21 CST 2022 aarch64 GNU/Linux

Logs

No response

Additional context

According to the description from the author:

The idea is to catch drivers that forgot to update xdp_buff->frame_sz, by doing some sanity checks on this uninit value. If I correctly updated all XDP drivers in this patchset, then these checks should be unnecessary, but will this be valuable for driver developers converting new drivers to XDP to have these WARN checks?

So it should be the problem of the NIC card driver

I am not sure whether XDP is considered supported in Raspberry Pi, but since the feature is enabled:

modprobe configs
zgrep -E "(BPF|XDP)" /proc/config.gz
CONFIG_BPF=y
CONFIG_HAVE_EBPF_JIT=y
CONFIG_ARCH_WANT_DEFAULT_BPF_JIT=y
# BPF subsystem
CONFIG_BPF_SYSCALL=y
# CONFIG_BPF_JIT is not set
# CONFIG_BPF_UNPRIV_DEFAULT_OFF is not set
# CONFIG_BPF_PRELOAD is not set
# end of BPF subsystem
CONFIG_CGROUP_BPF=y
# CONFIG_XDP_SOCKETS is not set
CONFIG_NETFILTER_XT_MATCH_BPF=m
# CONFIG_BPFILTER is not set
# CONFIG_NET_CLS_BPF is not set
# CONFIG_NET_ACT_BPF is not set
# CONFIG_BPF_STREAM_PARSER is not set
CONFIG_LWTUNNEL_BPF=y
CONFIG_BPF_LIRC_MODE2=y
CONFIG_BPF_EVENTS=y
# CONFIG_BPF_KPROBE_OVERRIDE is not set
# CONFIG_TEST_BPF is not set

and other simple things just work, the failure of bpf_xdp_adjust_tail should be unexpected

pelwell commented 2 years ago

As I understand it (which is not in any depth), BPF is a useful thing to have in and of itself. There may be ways to use it with XDP, but XDP is not a requirement.

Looking at your search of the config settings, almost all of them are BPF matches (and quite a few are not enabled). Breaking down the search into categories you get:

Enabled BPF:

CONFIG_BPF=y
CONFIG_HAVE_EBPF_JIT=y
CONFIG_BPF_SYSCALL=y
CONFIG_CGROUP_BPF=y
CONFIG_NETFILTER_XT_MATCH_BPF=m
CONFIG_LWTUNNEL_BPF=y
CONFIG_BPF_LIRC_MODE2=y
CONFIG_BPF_EVENTS=y

Disabled BPF:

# CONFIG_BPF_JIT is not set
# CONFIG_BPF_UNPRIV_DEFAULT_OFF is not set
# CONFIG_BPF_PRELOAD is not set
# CONFIG_BPFILTER is not set
# CONFIG_NET_CLS_BPF is not set
# CONFIG_NET_ACT_BPF is not set
# CONFIG_BPF_STREAM_PARSER is not set
# CONFIG_NBPFAXI_DMA is not set
# CONFIG_TEST_BPF is not set

Enabled XDP:

< This space intentionally left blank >

Disabled XDP:

# CONFIG_XDP_SOCKETS is not set

Out of 493 drivers in the 5.15 kernel (counting .ndo_open methods), only 34 have .ndo_bpf methods, and only 25 also have .ndo_xdp_xmit methods. This leads me to conclude that XDP is currently only sparsely supported, and nothing in the Raspberry Pi kernel configurations should suggest that it ought to work.

Unless you know otherwise.