Skip to contentSkip to conversation

Assume libbpf 1.0 in build

PATCH Superseded Ian Rogers 3 participants 6 messages Jan 9, 2023 – Jan 10, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

cover Assume libbpf 1.0 in build

libbpf 1.0 was a major change in API. Perf has partially supported older libbpf's but an implementation may be:
..

       pr_err("%s: not support, update libbpf\n", __func__);
       return -ENOTSUP;

..

Rather than build a binary that would fail at runtime it is preferrential just to build libbpf statically and link against that. The static version is in the kernel tools tree and newer than 1.0.

These patches change the libbpf test to only pass when at least version 1.0 is installed, then remove the conditional build and feature logic.

The issue is discussed here:
https://lore.kernel.org/lkml/[email protected]/

Ian Rogers (3):
tools build: Pass libbpf feature only if libbpf 1.0+ perf build: Remove libbpf pre-1.0 feature tests perf bpf: Remove pre libbpf 1.0 conditional logic

 tools/build/feature/Makefile                  |  7 --
 .../feature/test-libbpf-bpf_map_create.c      |  8 ---
 .../test-libbpf-bpf_object__next_map.c        |  8 ---
 .../test-libbpf-bpf_object__next_program.c    |  8 ---
 .../build/feature/test-libbpf-bpf_prog_load.c |  9 ---
 .../test-libbpf-bpf_program__set_insns.c      |  8 ---
 .../test-libbpf-btf__load_from_kernel_by_id.c |  8 ---
 .../build/feature/test-libbpf-btf__raw_data.c |  8 ---
 tools/build/feature/test-libbpf.c             |  4 ++
 tools/perf/Makefile.config                    | 37 +----------
 tools/perf/util/bpf-event.c                   | 66 -------------------
 tools/perf/util/bpf-loader.c                  | 18 -----
 tools/perf/util/bpf_counter.c                 | 18 -----
 13 files changed, 5 insertions(+), 202 deletions(-)
 delete mode 100644 tools/build/feature/test-libbpf-bpf_map_create.c
 delete mode 100644 tools/build/feature/test-libbpf-bpf_object__next_map.c
 delete mode 100644 tools/build/feature/test-libbpf-bpf_object__next_program.c
 delete mode 100644 tools/build/feature/test-libbpf-bpf_prog_load.c
 delete mode 100644 tools/build/feature/test-libbpf-bpf_program__set_insns.c
 delete mode 100644 tools/build/feature/test-libbpf-btf__load_from_kernel_by_id.c
 delete mode 100644 tools/build/feature/test-libbpf-btf__raw_data.c
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
author reviewer
#1 lore raw

PATCH 1/3 tools build: Pass libbpf feature only if libbpf 1.0+

libbpf 1.0 represented a cleanup and stabilization of APIs. Simplify development by only passing the feature test if libbpf 1.0 is installed.

---
 tools/build/feature/test-libbpf.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/build/feature/test-libbpf.c +4 -0
index a508756cf4cc..cd9989f52119 100644
@@ -1,6 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <bpf/libbpf.h>
 
+#if !defined(LIBBPF_MAJOR_VERSION) || (LIBBPF_MAJOR_VERSION < 1)
+#error At least libbpf 1.0 is required for Linux tools.
+#endif
+
 int main(void)
 {
 	return bpf_object__open("test") ? 0 : -1;
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
author reviewer
#2 lore raw

PATCH 2/3 perf build: Remove libbpf pre-1.0 feature tests

In reply to Ian Rogers

The feature tests were necessary for libbpf pre-1.0, but as the libbpf implies at least 1.0 we can remove these now.

---
 tools/build/feature/Makefile                  |  7 ---
 .../feature/test-libbpf-bpf_map_create.c      |  8 ----
 .../test-libbpf-bpf_object__next_map.c        |  8 ----
 .../test-libbpf-bpf_object__next_program.c    |  8 ----
 .../build/feature/test-libbpf-bpf_prog_load.c |  9 ----
 .../test-libbpf-bpf_program__set_insns.c      |  8 ----
 .../test-libbpf-btf__load_from_kernel_by_id.c |  8 ----
 .../build/feature/test-libbpf-btf__raw_data.c |  8 ----
 tools/perf/Makefile.config                    | 46 ++++---------------
 9 files changed, 10 insertions(+), 100 deletions(-)
 delete mode 100644 tools/build/feature/test-libbpf-bpf_map_create.c
 delete mode 100644 tools/build/feature/test-libbpf-bpf_object__next_map.c
 delete mode 100644 tools/build/feature/test-libbpf-bpf_object__next_program.c
 delete mode 100644 tools/build/feature/test-libbpf-bpf_prog_load.c
 delete mode 100644 tools/build/feature/test-libbpf-bpf_program__set_insns.c
 delete mode 100644 tools/build/feature/test-libbpf-btf__load_from_kernel_by_id.c
 delete mode 100644 tools/build/feature/test-libbpf-btf__raw_data.c
tools/build/feature/Makefile +0 -7
index 690fe97be190..dc9323e01e42 100644
@@ -58,13 +58,6 @@ FILES=                                          \
          test-lzma.bin                          \
          test-bpf.bin                           \
          test-libbpf.bin                        \
-         test-libbpf-btf__load_from_kernel_by_id.bin	\
-         test-libbpf-bpf_prog_load.bin          \
-         test-libbpf-bpf_map_create.bin		\
-         test-libbpf-bpf_object__next_program.bin \
-         test-libbpf-bpf_object__next_map.bin   \
-         test-libbpf-bpf_program__set_insns.bin	\
-         test-libbpf-btf__raw_data.bin          \
          test-get_cpuid.bin                     \
          test-sdt.bin                           \
          test-cxx.bin                           \
tools/build/feature/test-libbpf-bpf_map_create.c deleted +0 -8
deleted file mode 100644
index b9f550e332c8..000000000000
@@ -1,8 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <bpf/bpf.h>
-
-int main(void)
-{
-	return bpf_map_create(0 /* map_type */, NULL /* map_name */, 0, /* key_size */,
-			      0 /* value_size */, 0 /* max_entries */, NULL /* opts */);
-}
tools/build/feature/test-libbpf-bpf_object__next_map.c deleted +0 -8
deleted file mode 100644
index 64adb519e97e..000000000000
@@ -1,8 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <bpf/libbpf.h>
-
-int main(void)
-{
-	bpf_object__next_map(NULL /* obj */, NULL /* prev */);
-	return 0;
-}
tools/build/feature/test-libbpf-bpf_object__next_program.c deleted +0 -8
deleted file mode 100644
index 8bf4fd26b545..000000000000
@@ -1,8 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <bpf/libbpf.h>
-
-int main(void)
-{
-	bpf_object__next_program(NULL /* obj */, NULL /* prev */);
-	return 0;
-}
tools/build/feature/test-libbpf-bpf_prog_load.c deleted +0 -9
deleted file mode 100644
index 47f516d63ebc..000000000000
@@ -1,9 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <bpf/bpf.h>
-
-int main(void)
-{
-	return bpf_prog_load(0 /* prog_type */, NULL /* prog_name */,
-			     NULL /* license */, NULL /* insns */,
-			     0 /* insn_cnt */, NULL /* opts */);
-}
tools/build/feature/test-libbpf-bpf_program__set_insns.c deleted +0 -8
deleted file mode 100644
index f3b7f18c8f49..000000000000
@@ -1,8 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <bpf/libbpf.h>
-
-int main(void)
-{
-	bpf_program__set_insns(NULL /* prog */, NULL /* new_insns */, 0 /* new_insn_cnt */);
-	return 0;
-}
tools/build/feature/test-libbpf-btf__load_from_kernel_by_id.c deleted +0 -8
deleted file mode 100644
index a17647f7d5a4..000000000000
@@ -1,8 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <bpf/btf.h>
-
-int main(void)
-{
-	btf__load_from_kernel_by_id(20151128);
-	return 0;
-}
tools/build/feature/test-libbpf-btf__raw_data.c deleted +0 -8
deleted file mode 100644
index 57da31dd7581..000000000000
@@ -1,8 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-#include <bpf/btf.h>
-
-int main(void)
-{
-	btf__raw_data(NULL /* btf_ro */, NULL /* size */);
-	return 0;
-}
tools/perf/Makefile.config +10 -36

62 lines not on this page · raw message

Signature · 1 line
2.39.0.314.g84b9a713c41-goog
author reviewer
#3 lore raw

PATCH 3/3 perf bpf: Remove pre libbpf 1.0 conditional logic

In reply to Ian Rogers

Tests are no longer applicable as libbpf 1.0 can be assumed.

---
 tools/perf/Makefile.config    |  9 -----
 tools/perf/util/bpf-event.c   | 66 -----------------------------------
 tools/perf/util/bpf-loader.c  | 18 ----------
 tools/perf/util/bpf_counter.c | 18 ----------
 4 files changed, 111 deletions(-)
tools/perf/Makefile.config +0 -9
index 399e03338613..2197970bd503 100644
@@ -566,15 +566,6 @@ ifndef NO_LIBELF
       # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status
       $(call feature_check,libbpf)
 
-      # Feature test requires libbpf 1.0 so we can assume the following:
-      CFLAGS += -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID
-      CFLAGS += -DHAVE_LIBBPF_BPF_PROG_LOAD
-      CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM
-      CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_MAP
-      CFLAGS += -DHAVE_LIBBPF_BPF_PROGRAM__SET_INSNS
-      CFLAGS += -DHAVE_LIBBPF_BTF__RAW_DATA
-      CFLAGS += -DHAVE_LIBBPF_BPF_MAP_CREATE
-
       ifdef LIBBPF_DYNAMIC
         ifeq ($(feature-libbpf), 1)
           EXTLIBS += -lbpf
tools/perf/util/bpf-event.c +0 -66

72 lines not on this page · raw message

tools/perf/util/bpf-loader.c +0 -18
index 6e9b06cf06ee..44cde27d6389 100644
@@ -32,24 +32,6 @@
 
 #include <internal/xyarray.h>
 
-#ifndef HAVE_LIBBPF_BPF_PROGRAM__SET_INSNS
-int bpf_program__set_insns(struct bpf_program *prog __maybe_unused,
-			   struct bpf_insn *new_insns __maybe_unused, size_t new_insn_cnt __maybe_unused)
-{
-	pr_err("%s: not support, update libbpf\n", __func__);
-	return -ENOTSUP;
-}
-
-int libbpf_register_prog_handler(const char *sec __maybe_unused,
-                                 enum bpf_prog_type prog_type __maybe_unused,
-                                 enum bpf_attach_type exp_attach_type __maybe_unused,
-                                 const struct libbpf_prog_handler_opts *opts __maybe_unused)
-{
-	pr_err("%s: not support, update libbpf\n", __func__);
-	return -ENOTSUP;
-}
-#endif
-
 /* temporarily disable libbpf deprecation warnings */
 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 
tools/perf/util/bpf_counter.c +0 -18
index eeee899fcf34..aa78a15a6f0a 100644
@@ -312,24 +312,6 @@ static bool bperf_attr_map_compatible(int attr_map_fd)
 		(map_info.value_size == sizeof(struct perf_event_attr_map_entry));
 }
 
-#ifndef HAVE_LIBBPF_BPF_MAP_CREATE
-LIBBPF_API int bpf_create_map(enum bpf_map_type map_type, int key_size,
-                              int value_size, int max_entries, __u32 map_flags);
-int
-bpf_map_create(enum bpf_map_type map_type,
-	       const char *map_name __maybe_unused,
-	       __u32 key_size,
-	       __u32 value_size,
-	       __u32 max_entries,
-	       const struct bpf_map_create_opts *opts __maybe_unused)
-{
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-	return bpf_create_map(map_type, key_size, value_size, max_entries, 0);
-#pragma GCC diagnostic pop
-}
-#endif
-
 static int bperf_lock_attr_map(struct target *target)
 {
 	char path[PATH_MAX];
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
#4 lore raw
In reply to Ian Rogers
Quoted 24 lines · Ian Rogers

libbpf 1.0 was a major change in API. Perf has partially supported older libbpf's but an implementation may be:
..

       pr_err("%s: not support, update libbpf\n", __func__);
       return -ENOTSUP;

..

Rather than build a binary that would fail at runtime it is preferrential just to build libbpf statically and link against that. The static version is in the kernel tools tree and newer than 1.0.

These patches change the libbpf test to only pass when at least version 1.0 is installed, then remove the conditional build and feature logic.

The issue is discussed here:
https://lore.kernel.org/lkml/[email protected]/

Ian Rogers (3):
tools build: Pass libbpf feature only if libbpf 1.0+ perf build: Remove libbpf pre-1.0 feature tests perf bpf: Remove pre libbpf 1.0 conditional logic

Quoted 14 lines
 tools/build/feature/Makefile                  |  7 --
 .../feature/test-libbpf-bpf_map_create.c      |  8 ---
 .../test-libbpf-bpf_object__next_map.c        |  8 ---
 .../test-libbpf-bpf_object__next_program.c    |  8 ---
 .../build/feature/test-libbpf-bpf_prog_load.c |  9 ---
 .../test-libbpf-bpf_program__set_insns.c      |  8 ---
 .../test-libbpf-btf__load_from_kernel_by_id.c |  8 ---
 .../build/feature/test-libbpf-btf__raw_data.c |  8 ---
 tools/build/feature/test-libbpf.c             |  4 ++
 tools/perf/Makefile.config                    | 37 +----------
 tools/perf/util/bpf-event.c                   | 66 -------------------
 tools/perf/util/bpf-loader.c                  | 18 -----
 tools/perf/util/bpf_counter.c                 | 18 -----
 13 files changed, 5 insertions(+), 202 deletions(-)

nice, I like that.. I was able to build perf on fedora with (dynamic) and without (static) libbpf 1.0

I hope supporting allowing dynamic link just with libbpf 1.0 won't mess up backport world too much.. cc-ing Michael

other than that looks ok to me

Acked/Tested-by: Jiri Olsa <[email protected]>

also for the 2 dependency patches

thanks,
jirka

Quoted 11 lines
 delete mode 100644 tools/build/feature/test-libbpf-bpf_map_create.c
 delete mode 100644 tools/build/feature/test-libbpf-bpf_object__next_map.c
 delete mode 100644 tools/build/feature/test-libbpf-bpf_object__next_program.c
 delete mode 100644 tools/build/feature/test-libbpf-bpf_prog_load.c
 delete mode 100644 tools/build/feature/test-libbpf-bpf_program__set_insns.c
 delete mode 100644 tools/build/feature/test-libbpf-btf__load_from_kernel_by_id.c
 delete mode 100644 tools/build/feature/test-libbpf-btf__raw_data.c
Signature · 1 line
2.39.0.314.g84b9a713c41-goog
#5 lore raw

Em Tue, Jan 10, 2023 at 01:34:56PM +0100, Jiri Olsa escreveu:

Quoted 40 lines · Ian Rogers
Quoted 24 lines

libbpf 1.0 was a major change in API. Perf has partially supported older libbpf's but an implementation may be:
..

       pr_err("%s: not support, update libbpf\n", __func__);
       return -ENOTSUP;

..

Rather than build a binary that would fail at runtime it is preferrential just to build libbpf statically and link against that. The static version is in the kernel tools tree and newer than 1.0.

These patches change the libbpf test to only pass when at least version 1.0 is installed, then remove the conditional build and feature logic.

The issue is discussed here:
https://lore.kernel.org/lkml/[email protected]/

Ian Rogers (3):
tools build: Pass libbpf feature only if libbpf 1.0+ perf build: Remove libbpf pre-1.0 feature tests perf bpf: Remove pre libbpf 1.0 conditional logic

Quoted 14 lines
 tools/build/feature/Makefile                  |  7 --
 .../feature/test-libbpf-bpf_map_create.c      |  8 ---
 .../test-libbpf-bpf_object__next_map.c        |  8 ---
 .../test-libbpf-bpf_object__next_program.c    |  8 ---
 .../build/feature/test-libbpf-bpf_prog_load.c |  9 ---
 .../test-libbpf-bpf_program__set_insns.c      |  8 ---
 .../test-libbpf-btf__load_from_kernel_by_id.c |  8 ---
 .../build/feature/test-libbpf-btf__raw_data.c |  8 ---
 tools/build/feature/test-libbpf.c             |  4 ++
 tools/perf/Makefile.config                    | 37 +----------
 tools/perf/util/bpf-event.c                   | 66 -------------------
 tools/perf/util/bpf-loader.c                  | 18 -----
 tools/perf/util/bpf_counter.c                 | 18 -----
 13 files changed, 5 insertions(+), 202 deletions(-)
Quoted 5 lines

nice, I like that.. I was able to build perf on fedora with (dynamic) and without (static) libbpf 1.0

I hope supporting allowing dynamic link just with libbpf 1.0 won't mess up backport world too much.. cc-ing Michael

Yeah, would be nice to hear from Michael and other distro maintainers.

- Arnaldo

Quoted 5 lines

other than that looks ok to me

Acked/Tested-by: Jiri Olsa <[email protected]>

also for the 2 dependency patches

ok!