linux/tools
Andrii Nakryiko 25498a1969 libbpf: Always specify expected_attach_type on program load if supported
For some types of BPF programs that utilize expected_attach_type, libbpf won't
set load_attr.expected_attach_type, even if expected_attach_type is known from
section definition. This was done to preserve backwards compatibility with old
kernels that didn't recognize expected_attach_type attribute yet (which was
added in 5e43f899b0 ("bpf: Check attach type at prog load time"). But this
is problematic for some BPF programs that utilize newer features that require
kernel to know specific expected_attach_type (e.g., extended set of return
codes for cgroup_skb/egress programs).

This patch makes libbpf specify expected_attach_type by default, but also
detect support for this field in kernel and not set it during program load.
This allows to have a good metadata for bpf_program
(e.g., bpf_program__get_extected_attach_type()), but still work with old
kernels (for cases where it can work at all).

Additionally, due to expected_attach_type being always set for recognized
program types, bpf_program__attach_cgroup doesn't have to do extra checks to
determine correct attach type, so remove that additional logic.

Also adjust section_names selftest to account for this change.

More detailed discussion can be found in [0].

  [0] https://lore.kernel.org/bpf/20200412003604.GA15986@rdna-mbp.dhcp.thefacebook.com/

Fixes: 5cf1e91456 ("bpf: cgroup inet skb programs can return 0 to 3")
Fixes: 5e43f899b0 ("bpf: Check attach type at prog load time")
Reported-by: Andrey Ignatov <rdna@fb.com>
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <songliubraving@fb.com>
Acked-by: Andrey Ignatov <rdna@fb.com>
Link: https://lore.kernel.org/bpf/20200414182645.1368174-1-andriin@fb.com
2020-04-15 13:22:43 +02:00
..
accounting SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
arch ARM: 2020-04-02 15:13:15 -07:00
bootconfig New tracing features: 2020-04-05 10:36:18 -07:00
bpf tools, bpftool: Fix struct_ops command invalid pointer free 2020-04-14 21:33:53 +02:00
build perf updates all over the place: 2020-04-05 12:26:24 -07:00
cgroup .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
debugging
edid tools/edid: Move EDID data sets from Documentation/ 2020-02-19 04:10:32 -07:00
firewire
firmware
gpio This is the bulk of GPIO development for the v5.7 kernel cycle. 2020-04-04 10:27:00 -07:00
hv Tools: hv: Reopen the devices if read() or write() returns errors 2020-01-26 22:10:10 -05:00
iio .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
include perf updates all over the place: 2020-04-05 12:26:24 -07:00
io_uring
kvm/kvm_stat tools/kvm_stat: add command line switch '-c' to log in csv format 2020-03-23 15:44:21 -04:00
laptop .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
leds .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
lib libbpf: Always specify expected_attach_type on program load if supported 2020-04-15 13:22:43 +02:00
memory-model .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
nfsd
objtool SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
pci tools: PCI: Add 'e' to clear IRQ 2020-04-02 17:57:10 +01:00
pcmcia .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
perf perf updates all over the place: 2020-04-05 12:26:24 -07:00
power SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
scripts Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-03-25 18:58:11 -07:00
spi SPDX patches for 5.7-rc1. 2020-04-03 13:12:26 -07:00
testing libbpf: Always specify expected_attach_type on program load if supported 2020-04-15 13:22:43 +02:00
thermal/tmon .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
time
usb .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
virtio .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
vm .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
wmi
Makefile tools: bootconfig: Add bootconfig command 2020-01-13 13:19:39 -05:00