diff --git a/bpftool-define-a-local-bpf_perf_link-to-fix-accessin.patch b/bpftool-define-a-local-bpf_perf_link-to-fix-accessin.patch deleted file mode 100644 index a6f09c336ae82610a01b25f64cf5e3f237e15d4a..0000000000000000000000000000000000000000 --- a/bpftool-define-a-local-bpf_perf_link-to-fix-accessin.patch +++ /dev/null @@ -1,69 +0,0 @@ -From 0773871e3aa0ef8b928748ec53d77a1203b42543 Mon Sep 17 00:00:00 2001 -From: Alexander Lobakin -Date: Fri, 7 Jul 2023 10:54:23 +0100 -Subject: [PATCH] bpftool: Define a local bpf_perf_link to fix accessing its - fields - -When building bpftool with !CONFIG_PERF_EVENTS: - -skeleton/pid_iter.bpf.c:47:14: error: incomplete definition of type 'struct bpf_perf_link' - perf_link = container_of(link, struct bpf_perf_link, link); - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helpers.h:74:22: note: expanded from macro 'container_of' - ((type *)(__mptr - offsetof(type, member))); \ - ^~~~~~~~~~~~~~~~~~~~~~ -tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helpers.h:68:60: note: expanded from macro 'offsetof' - #define offsetof(TYPE, MEMBER) ((unsigned long)&((TYPE *)0)->MEMBER) - ~~~~~~~~~~~^ -skeleton/pid_iter.bpf.c:44:9: note: forward declaration of 'struct bpf_perf_link' - struct bpf_perf_link *perf_link; - ^ - -&bpf_perf_link is being defined and used only under the ifdef. -Define struct bpf_perf_link___local with the `preserve_access_index` -attribute inside the pid_iter BPF prog to allow compiling on any -configs. CO-RE will substitute it with the real struct bpf_perf_link -accesses later on. -container_of() uses offsetof(), which does the necessary CO-RE -relocation if the field is specified with `preserve_access_index` - as -is the case for struct bpf_perf_link___local. - -Fixes: cbdaf71f7e65 ("bpftool: Add bpf_cookie to link output") -Suggested-by: Andrii Nakryiko -Signed-off-by: Alexander Lobakin -Signed-off-by: Quentin Monnet -Signed-off-by: Andrii Nakryiko -Link: https://lore.kernel.org/bpf/20230707095425.168126-3-quentin@isovalent.com ---- - src/skeleton/pid_iter.bpf.c | 9 +++++++-- - 1 file changed, 7 insertions(+), 2 deletions(-) - -diff --git a/src/skeleton/pid_iter.bpf.c b/src/skeleton/pid_iter.bpf.c -index e2af8e5..3a4c4f7 100644 ---- a/src/skeleton/pid_iter.bpf.c -+++ b/src/skeleton/pid_iter.bpf.c -@@ -15,6 +15,11 @@ enum bpf_obj_type { - BPF_OBJ_BTF, - }; - -+struct bpf_perf_link___local { -+ struct bpf_link link; -+ struct file *perf_file; -+} __attribute__((preserve_access_index)); -+ - struct perf_event___local { - u64 bpf_cookie; - } __attribute__((preserve_access_index)); -@@ -45,10 +50,10 @@ static __always_inline __u32 get_obj_id(void *ent, enum bpf_obj_type type) - /* could be used only with BPF_LINK_TYPE_PERF_EVENT links */ - static __u64 get_bpf_cookie(struct bpf_link *link) - { -+ struct bpf_perf_link___local *perf_link; - struct perf_event___local *event; -- struct bpf_perf_link *perf_link; - -- perf_link = container_of(link, struct bpf_perf_link, link); -+ perf_link = container_of(link, struct bpf_perf_link___local, link); - event = BPF_CORE_READ(perf_link, perf_file, private_data); - return BPF_CORE_READ(event, bpf_cookie); - } diff --git a/bpftool-libbpf-v7.2.0.tar.gz b/bpftool-libbpf-v7.2.0.tar.gz deleted file mode 100644 index 554f23f3f6f48fb4a11d40439490379337bb8449..0000000000000000000000000000000000000000 Binary files a/bpftool-libbpf-v7.2.0.tar.gz and /dev/null differ diff --git a/bpftool-libbpf-v7.4.0-sources.tar.gz b/bpftool-libbpf-v7.4.0-sources.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..0c35c681210a6a047da592e5d5a2277cd65c93b9 Binary files /dev/null and b/bpftool-libbpf-v7.4.0-sources.tar.gz differ diff --git a/bpftool-use-a-local-bpf_perf_event_value-to-fix-acce.patch b/bpftool-use-a-local-bpf_perf_event_value-to-fix-acce.patch deleted file mode 100644 index 88b35221eec75e5dd2f5b939cd369559c0e872bd..0000000000000000000000000000000000000000 --- a/bpftool-use-a-local-bpf_perf_event_value-to-fix-acce.patch +++ /dev/null @@ -1,130 +0,0 @@ -From b00d0c5587d2da425904a26b8537abca184df3e2 Mon Sep 17 00:00:00 2001 -From: Alexander Lobakin -Date: Fri, 7 Jul 2023 10:54:25 +0100 -Subject: [PATCH] bpftool: Use a local bpf_perf_event_value to fix accessing - its fields - -Fix the following error when building bpftool: - - CLANG profiler.bpf.o - CLANG pid_iter.bpf.o -skeleton/profiler.bpf.c:18:21: error: invalid application of 'sizeof' to an incomplete type 'struct bpf_perf_event_value' - __uint(value_size, sizeof(struct bpf_perf_event_value)); - ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helpers.h:13:39: note: expanded from macro '__uint' -tools/bpf/bpftool/bootstrap/libbpf/include/bpf/bpf_helper_defs.h:7:8: note: forward declaration of 'struct bpf_perf_event_value' -struct bpf_perf_event_value; - ^ - -struct bpf_perf_event_value is being used in the kernel only when -CONFIG_BPF_EVENTS is enabled, so it misses a BTF entry then. -Define struct bpf_perf_event_value___local with the -`preserve_access_index` attribute inside the pid_iter BPF prog to -allow compiling on any configs. It is a full mirror of a UAPI -structure, so is compatible both with and w/o CO-RE. -bpf_perf_event_read_value() requires a pointer of the original type, -so a cast is needed. - -Fixes: 47c09d6a9f67 ("bpftool: Introduce "prog profile" command") -Suggested-by: Andrii Nakryiko -Signed-off-by: Alexander Lobakin -Signed-off-by: Quentin Monnet -Signed-off-by: Andrii Nakryiko -Link: https://lore.kernel.org/bpf/20230707095425.168126-5-quentin@isovalent.com ---- - src/skeleton/profiler.bpf.c | 27 +++++++++++++++++---------- - 1 file changed, 17 insertions(+), 10 deletions(-) - -diff --git a/src/skeleton/profiler.bpf.c b/src/skeleton/profiler.bpf.c -index ce5b65e..2f80edc 100644 ---- a/src/skeleton/profiler.bpf.c -+++ b/src/skeleton/profiler.bpf.c -@@ -4,6 +4,12 @@ - #include - #include - -+struct bpf_perf_event_value___local { -+ __u64 counter; -+ __u64 enabled; -+ __u64 running; -+} __attribute__((preserve_access_index)); -+ - /* map of perf event fds, num_cpu * num_metric entries */ - struct { - __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY); -@@ -15,14 +21,14 @@ struct { - struct { - __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); - __uint(key_size, sizeof(u32)); -- __uint(value_size, sizeof(struct bpf_perf_event_value)); -+ __uint(value_size, sizeof(struct bpf_perf_event_value___local)); - } fentry_readings SEC(".maps"); - - /* accumulated readings */ - struct { - __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY); - __uint(key_size, sizeof(u32)); -- __uint(value_size, sizeof(struct bpf_perf_event_value)); -+ __uint(value_size, sizeof(struct bpf_perf_event_value___local)); - } accum_readings SEC(".maps"); - - /* sample counts, one per cpu */ -@@ -39,7 +45,7 @@ const volatile __u32 num_metric = 1; - SEC("fentry/XXX") - int BPF_PROG(fentry_XXX) - { -- struct bpf_perf_event_value *ptrs[MAX_NUM_MATRICS]; -+ struct bpf_perf_event_value___local *ptrs[MAX_NUM_MATRICS]; - u32 key = bpf_get_smp_processor_id(); - u32 i; - -@@ -53,10 +59,10 @@ int BPF_PROG(fentry_XXX) - } - - for (i = 0; i < num_metric && i < MAX_NUM_MATRICS; i++) { -- struct bpf_perf_event_value reading; -+ struct bpf_perf_event_value___local reading; - int err; - -- err = bpf_perf_event_read_value(&events, key, &reading, -+ err = bpf_perf_event_read_value(&events, key, (void *)&reading, - sizeof(reading)); - if (err) - return 0; -@@ -68,14 +74,14 @@ int BPF_PROG(fentry_XXX) - } - - static inline void --fexit_update_maps(u32 id, struct bpf_perf_event_value *after) -+fexit_update_maps(u32 id, struct bpf_perf_event_value___local *after) - { -- struct bpf_perf_event_value *before, diff; -+ struct bpf_perf_event_value___local *before, diff; - - before = bpf_map_lookup_elem(&fentry_readings, &id); - /* only account samples with a valid fentry_reading */ - if (before && before->counter) { -- struct bpf_perf_event_value *accum; -+ struct bpf_perf_event_value___local *accum; - - diff.counter = after->counter - before->counter; - diff.enabled = after->enabled - before->enabled; -@@ -93,7 +99,7 @@ fexit_update_maps(u32 id, struct bpf_perf_event_value *after) - SEC("fexit/XXX") - int BPF_PROG(fexit_XXX) - { -- struct bpf_perf_event_value readings[MAX_NUM_MATRICS]; -+ struct bpf_perf_event_value___local readings[MAX_NUM_MATRICS]; - u32 cpu = bpf_get_smp_processor_id(); - u32 i, zero = 0; - int err; -@@ -102,7 +108,8 @@ int BPF_PROG(fexit_XXX) - /* read all events before updating the maps, to reduce error */ - for (i = 0; i < num_metric && i < MAX_NUM_MATRICS; i++) { - err = bpf_perf_event_read_value(&events, cpu + i * num_cpu, -- readings + i, sizeof(*readings)); -+ (void *)(readings + i), -+ sizeof(*readings)); - if (err) - return 0; - } diff --git a/bpftool-use-a-local-copy-of-bpf_link_type_perf_event.patch b/bpftool-use-a-local-copy-of-bpf_link_type_perf_event.patch deleted file mode 100644 index dd1e94bdff813abfb7c292c4eec72cecd867ff0e..0000000000000000000000000000000000000000 --- a/bpftool-use-a-local-copy-of-bpf_link_type_perf_event.patch +++ /dev/null @@ -1,51 +0,0 @@ -From fc96090dd8e4e9aaa59b3fd14d39b21deef592db Mon Sep 17 00:00:00 2001 -From: Quentin Monnet -Date: Fri, 7 Jul 2023 10:54:24 +0100 -Subject: [PATCH] bpftool: Use a local copy of BPF_LINK_TYPE_PERF_EVENT in - pid_iter.bpf.c - -In order to allow the BPF program in bpftool's pid_iter.bpf.c to compile -correctly on hosts where vmlinux.h does not define -BPF_LINK_TYPE_PERF_EVENT (running kernel versions lower than 5.15, for -example), define and use a local copy of the enum value. This requires -LLVM 12 or newer to build the BPF program. - -Fixes: cbdaf71f7e65 ("bpftool: Add bpf_cookie to link output") -Signed-off-by: Quentin Monnet -Signed-off-by: Andrii Nakryiko -Link: https://lore.kernel.org/bpf/20230707095425.168126-4-quentin@isovalent.com ---- - src/skeleton/pid_iter.bpf.c | 11 +++++++++-- - 1 file changed, 9 insertions(+), 2 deletions(-) - -diff --git a/src/skeleton/pid_iter.bpf.c b/src/skeleton/pid_iter.bpf.c -index 3a4c4f7..26004f0 100644 ---- a/src/skeleton/pid_iter.bpf.c -+++ b/src/skeleton/pid_iter.bpf.c -@@ -24,6 +24,10 @@ struct perf_event___local { - u64 bpf_cookie; - } __attribute__((preserve_access_index)); - -+enum bpf_link_type___local { -+ BPF_LINK_TYPE_PERF_EVENT___local = 7, -+}; -+ - extern const void bpf_link_fops __ksym; - extern const void bpf_map_fops __ksym; - extern const void bpf_prog_fops __ksym; -@@ -93,10 +97,13 @@ int iter(struct bpf_iter__task_file *ctx) - e.pid = task->tgid; - e.id = get_obj_id(file->private_data, obj_type); - -- if (obj_type == BPF_OBJ_LINK) { -+ if (obj_type == BPF_OBJ_LINK && -+ bpf_core_enum_value_exists(enum bpf_link_type___local, -+ BPF_LINK_TYPE_PERF_EVENT___local)) { - struct bpf_link *link = (struct bpf_link *) file->private_data; - -- if (BPF_CORE_READ(link, type) == BPF_LINK_TYPE_PERF_EVENT) { -+ if (link->type == bpf_core_enum_value(enum bpf_link_type___local, -+ BPF_LINK_TYPE_PERF_EVENT___local)) { - e.has_bpf_cookie = true; - e.bpf_cookie = get_bpf_cookie(link); - } diff --git a/bpftool-use-a-local-copy-of-perf_event-to-fix-access.patch b/bpftool-use-a-local-copy-of-perf_event-to-fix-access.patch deleted file mode 100644 index 5d35764bc43f311e8d8eaefe8f16008e5c105e38..0000000000000000000000000000000000000000 --- a/bpftool-use-a-local-copy-of-perf_event-to-fix-access.patch +++ /dev/null @@ -1,62 +0,0 @@ -From 1f5829e1e8b0bd4b3ac11629fe66aea2eb519ca8 Mon Sep 17 00:00:00 2001 -From: Alexander Lobakin -Date: Fri, 7 Jul 2023 10:54:22 +0100 -Subject: [PATCH] bpftool: use a local copy of perf_event to fix accessing :: - Bpf_cookie - -When CONFIG_PERF_EVENTS is not set, struct perf_event remains empty. -However, the structure is being used by bpftool indirectly via BTF. -This leads to: - -skeleton/pid_iter.bpf.c:49:30: error: no member named 'bpf_cookie' in 'struct perf_event' - return BPF_CORE_READ(event, bpf_cookie); - ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~ - -... - -skeleton/pid_iter.bpf.c:49:9: error: returning 'void' from a function with incompatible result type '__u64' (aka 'unsigned long long') - return BPF_CORE_READ(event, bpf_cookie); - ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Tools and samples can't use any CONFIG_ definitions, so the fields -used there should always be present. -Define struct perf_event___local with the `preserve_access_index` -attribute inside the pid_iter BPF prog to allow compiling on any -configs. CO-RE will substitute it with the real struct perf_event -accesses later on. - -Fixes: cbdaf71f7e65 ("bpftool: Add bpf_cookie to link output") -Suggested-by: Andrii Nakryiko -Signed-off-by: Alexander Lobakin -Signed-off-by: Quentin Monnet -Signed-off-by: Andrii Nakryiko -Link: https://lore.kernel.org/bpf/20230707095425.168126-2-quentin@isovalent.com ---- - src/skeleton/pid_iter.bpf.c | 6 +++++- - 1 file changed, 5 insertions(+), 1 deletion(-) - -diff --git a/src/skeleton/pid_iter.bpf.c b/src/skeleton/pid_iter.bpf.c -index eb05ea5..e2af8e5 100644 ---- a/src/skeleton/pid_iter.bpf.c -+++ b/src/skeleton/pid_iter.bpf.c -@@ -15,6 +15,10 @@ enum bpf_obj_type { - BPF_OBJ_BTF, - }; - -+struct perf_event___local { -+ u64 bpf_cookie; -+} __attribute__((preserve_access_index)); -+ - extern const void bpf_link_fops __ksym; - extern const void bpf_map_fops __ksym; - extern const void bpf_prog_fops __ksym; -@@ -41,8 +45,8 @@ static __always_inline __u32 get_obj_id(void *ent, enum bpf_obj_type type) - /* could be used only with BPF_LINK_TYPE_PERF_EVENT links */ - static __u64 get_bpf_cookie(struct bpf_link *link) - { -+ struct perf_event___local *event; - struct bpf_perf_link *perf_link; -- struct perf_event *event; - - perf_link = container_of(link, struct bpf_perf_link, link); - event = BPF_CORE_READ(perf_link, perf_file, private_data); diff --git a/bpftool.spec b/bpftool.spec index 946c75472ff9d97a7003f5d04582b2f466bea90e..fed5ba0d66db0086c83047b2af59a3d62418450e 100644 --- a/bpftool.spec +++ b/bpftool.spec @@ -1,24 +1,19 @@ Name: bpftool -Version: 7.2.0 +Version: 7.4.0 Release: 1 Summary: Tool for inspection and manipulation of BPF programs and maps License: GPL-2.0-only URL: https://www.kernel.org/ BuildRequires: elfutils-devel libcap-devel binutils-devel clang python3-docutils llvm-devel -Source0: https://github.com/libbpf/bpftool/archive/refs/tags/%{name}-libbpf-v%{version}.tar.gz - -Patch0: bpftool-use-a-local-copy-of-perf_event-to-fix-access.patch -Patch1: bpftool-define-a-local-bpf_perf_link-to-fix-accessin.patch -Patch2: bpftool-use-a-local-copy-of-bpf_link_type_perf_event.patch -Patch3: bpftool-use-a-local-bpf_perf_event_value-to-fix-acce.patch +Source0: https://github.com/libbpf/bpftool/releases/download/v%{version}/%{name}-libbpf-v%{version}-sources.tar.gz %description bpftool allows for inspection and simple modification of BPF objects (programs and maps) on the system. %prep -%autosetup -p1 -n %{name}-%{version} +%autosetup -p1 -n %{name}-libbpf-v%{version}-sources %build %make_build -C src V=1 @@ -38,5 +33,8 @@ mv %{buildroot}%{_datadir}/bash-completion/completions/bpftool %{buildroot}%{_sy %{_sysconfdir}/bash_completion.d/bpftool %changelog +* Mon Jul 15 2024 kywqs - 7.4.0-1 +- update version to 7.4.0 + * Sat Jan 20 2024 liuxin - 7.2.0-1 - Init package