]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: Always specify expected_attach_type on program load if supported
authorAndrii Nakryiko <andriin@fb.com>
Tue, 14 Apr 2020 18:26:45 +0000 (11:26 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 15 Apr 2020 11:22:43 +0000 (13:22 +0200)
commita54634244fe763092c63a7e1591f263e17522f67
treecc579427faea0bdaa8d7b4087eb048c863ac7906
parent73256f1c3d39a30876ee20a34242501d149ca2e9
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 75c980841d07 ("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: 44883cfe9d9c ("bpf: cgroup inet skb programs can return 0 to 3")
Fixes: 75c980841d07 ("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
tools/lib/bpf/libbpf.c
tools/testing/selftests/bpf/prog_tests/section_names.c