Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

libbpf: Schedule open_opts.attach_prog_fd deprecation since v0.7

bpf_object_open_opts.attach_prog_fd makes a pretty strong assumption
that bpf_object contains either only single freplace BPF program or all
of BPF programs in BPF object are freplaces intended to replace
different subprograms of the same target BPF program. This seems both
a bit confusing, too assuming, and limiting.

We've had bpf_program__set_attach_target() API which allows more
fine-grained control over this, on a per-program level. As such, mark
open_opts.attach_prog_fd as deprecated starting from v0.7, so that we
have one more universal way of setting freplace targets. With previous
change to allow NULL attach_func_name argument, and especially combined
with BPF skeleton, arguable bpf_program__set_attach_target() is a more
convenient and explicit API as well.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20210916015836.1248906-7-andrii@kernel.org

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
91b555d7 60aed220

+10
+3
tools/lib/bpf/libbpf.c
··· 6415 6415 bpf_program__set_type(prog, prog->sec_def->prog_type); 6416 6416 bpf_program__set_expected_attach_type(prog, prog->sec_def->expected_attach_type); 6417 6417 6418 + #pragma GCC diagnostic push 6419 + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 6418 6420 if (prog->sec_def->prog_type == BPF_PROG_TYPE_TRACING || 6419 6421 prog->sec_def->prog_type == BPF_PROG_TYPE_EXT) 6420 6422 prog->attach_prog_fd = OPTS_GET(opts, attach_prog_fd, 0); 6423 + #pragma GCC diagnostic pop 6421 6424 } 6422 6425 6423 6426 return 0;
+2
tools/lib/bpf/libbpf.h
··· 90 90 * auto-pinned to that path on load; defaults to "/sys/fs/bpf". 91 91 */ 92 92 const char *pin_root_path; 93 + 94 + LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_program__set_attach_target() on each individual bpf_program") 93 95 __u32 attach_prog_fd; 94 96 /* Additional kernel config content that augments and overrides 95 97 * system Kconfig for CONFIG_xxx externs.
+5
tools/lib/bpf/libbpf_common.h
··· 35 35 #else 36 36 #define __LIBBPF_MARK_DEPRECATED_0_6(X) 37 37 #endif 38 + #if __LIBBPF_CURRENT_VERSION_GEQ(0, 7) 39 + #define __LIBBPF_MARK_DEPRECATED_0_7(X) X 40 + #else 41 + #define __LIBBPF_MARK_DEPRECATED_0_7(X) 42 + #endif 38 43 39 44 /* Helper macro to declare and initialize libbpf options struct 40 45 *