diff --git a/backport-libbpf-Ensure-functions-with-always_inline-attribute-are-inline.patch b/backport-libbpf-Ensure-functions-with-always_inline-attribute-are-inline.patch new file mode 100644 index 0000000000000000000000000000000000000000..e0ab0c6aee74caae5b7f864e7100c930e0e613a3 --- /dev/null +++ b/backport-libbpf-Ensure-functions-with-always_inline-attribute-are-inline.patch @@ -0,0 +1,83 @@ +From 69d537ba0b5cd736cd5081d84928f4393856d3db Mon Sep 17 00:00:00 2001 +From: James Hilliard +Date: Wed, 3 Aug 2022 09:14:03 -0600 +Subject: [PATCH] libbpf: Ensure functions with always_inline attribute are + inline +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +GCC expects the always_inline attribute to only be set on inline +functions, as such we should make all functions with this attribute +use the __always_inline macro which makes the function inline and +sets the attribute. + +Fixes errors like: +/home/buildroot/bpf-next/tools/testing/selftests/bpf/tools/include/bpf/bpf_tracing.h:439:1: error: ‘always_inline’ function might not be inlinable [-Werror=attributes] + 439 | ____##name(unsigned long long *ctx, ##args) + | ^~~~ + +Signed-off-by: James Hilliard +Signed-off-by: Andrii Nakryiko +Acked-by: Jiri Olsa +Link: https://lore.kernel.org/bpf/20220803151403.793024-1-james.hilliard1@gmail.com + +Conflict: remove the modify of src/usdt.bpf.h because the include file +src/usdt.bpf.h is not exist in current version +Reference: https://github.com/libbpf/libbpf/commit/69d537ba0b5cd736cd5081d84928f4393856d3db +--- + src/bpf_tracing.h | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/src/bpf_tracing.h b/src/bpf_tracing.h +index f9ef377..12c0bb5 100644 +--- a/src/bpf_tracing.h ++++ b/src/bpf_tracing.h +@@ -336,7 +336,7 @@ struct pt_regs; + */ + #define BPF_PROG(name, args...) \ + name(unsigned long long *ctx); \ +-static __attribute__((always_inline)) typeof(name(0)) \ ++static __always_inline typeof(name(0)) \ + ____##name(unsigned long long *ctx, ##args); \ + typeof(name(0)) name(unsigned long long *ctx) \ + { \ +@@ -345,7 +345,7 @@ typeof(name(0)) name(unsigned long long *ctx) \ + return ____##name(___bpf_ctx_cast(args)); \ + _Pragma("GCC diagnostic pop") \ + } \ +-static __attribute__((always_inline)) typeof(name(0)) \ ++static __always_inline typeof(name(0)) \ + ____##name(unsigned long long *ctx, ##args) + + struct pt_regs; +@@ -376,7 +376,7 @@ struct pt_regs; + */ + #define BPF_KPROBE(name, args...) \ + name(struct pt_regs *ctx); \ +-static __attribute__((always_inline)) typeof(name(0)) \ ++static __always_inline typeof(name(0)) \ + ____##name(struct pt_regs *ctx, ##args); \ + typeof(name(0)) name(struct pt_regs *ctx) \ + { \ +@@ -385,7 +385,7 @@ typeof(name(0)) name(struct pt_regs *ctx) \ + return ____##name(___bpf_kprobe_args(args)); \ + _Pragma("GCC diagnostic pop") \ + } \ +-static __attribute__((always_inline)) typeof(name(0)) \ ++static __always_inline typeof(name(0)) \ + ____##name(struct pt_regs *ctx, ##args) + + #define ___bpf_kretprobe_args0() ctx +@@ -402,7 +402,7 @@ ____##name(struct pt_regs *ctx, ##args) + */ + #define BPF_KRETPROBE(name, args...) \ + name(struct pt_regs *ctx); \ +-static __attribute__((always_inline)) typeof(name(0)) \ ++static __always_inline typeof(name(0)) \ + ____##name(struct pt_regs *ctx, ##args); \ + typeof(name(0)) name(struct pt_regs *ctx) \ + { \ +-- +2.33.0 + diff --git a/backport-libbpf-Fix-the-name-of-a-reused-map.patch b/backport-libbpf-Fix-the-name-of-a-reused-map.patch new file mode 100644 index 0000000000000000000000000000000000000000..8cfd5e51c558231380648f4f49b79527d6ffa207 --- /dev/null +++ b/backport-libbpf-Fix-the-name-of-a-reused-map.patch @@ -0,0 +1,66 @@ +From 9b6f4eb1570c219474f6029caea71584d7a2188a Mon Sep 17 00:00:00 2001 +From: Anquan Wu +Date: Tue, 12 Jul 2022 11:15:40 +0800 +Subject: [PATCH] libbpf: Fix the name of a reused map +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +BPF map name is limited to BPF_OBJ_NAME_LEN. +A map name is defined as being longer than BPF_OBJ_NAME_LEN, +it will be truncated to BPF_OBJ_NAME_LEN when a userspace program +calls libbpf to create the map. A pinned map also generates a path +in the /sys. If the previous program wanted to reuse the map, +it can not get bpf_map by name, because the name of the map is only +partially the same as the name which get from pinned path. + +The syscall information below show that map name "process_pinned_map" +is truncated to "process_pinned_". + + bpf(BPF_OBJ_GET, {pathname="/sys/fs/bpf/process_pinned_map", + bpf_fd=0, file_flags=0}, 144) = -1 ENOENT (No such file or directory) + + bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_HASH, key_size=4, + value_size=4,max_entries=1024, map_flags=0, inner_map_fd=0, + map_name="process_pinned_",map_ifindex=0, btf_fd=3, btf_key_type_id=6, + btf_value_type_id=10,btf_vmlinux_value_type_id=0}, 72) = 4 + +This patch check that if the name of pinned map are the same as the +actual name for the first (BPF_OBJ_NAME_LEN - 1), +bpf map still uses the name which is included in bpf object. + +Fixes: 26736eb9a483 ("tools: libbpf: allow map reuse") +Signed-off-by: Anquan Wu +Signed-off-by: Andrii Nakryiko +Link: https://lore.kernel.org/bpf/OSZP286MB1725CEA1C95C5CB8E7CCC53FB8869@OSZP286MB1725.JPNP286.PROD.OUTLOOK.COM +--- + src/libbpf.c | 9 +++++++-- + 1 file changed, 7 insertions(+), 2 deletions(-) + +diff --git a/src/libbpf.c b/src/libbpf.c +index 72548798..68da1aca 100644 +--- a/src/libbpf.c ++++ b/src/libbpf.c +@@ -3327,7 +3327,7 @@ int bpf_map__set_autocreate(struct bpf_map *map, bool autocreate) + int bpf_map__reuse_fd(struct bpf_map *map, int fd) + { + struct bpf_map_info info = {}; +- __u32 len = sizeof(info); ++ __u32 len = sizeof(info), name_len; + int new_fd, err; + char *new_name; + +@@ -3335,7 +3335,12 @@ int bpf_map__reuse_fd(struct bpf_map *map, int fd) + if (err) + return err; + +- new_name = strdup(info.name); ++ name_len = strlen(info.name); ++ if (name_len == BPF_OBJ_NAME_LEN - 1 && strncmp(map->name, info.name, name_len) == 0) ++ new_name = strdup(map->name); ++ else ++ new_name = strdup(info.name); ++ + if (!new_name) + return -errno; + diff --git a/backport-libbpf-preserve-errno-across-pr_warn-pr_info-pr_debug.patch b/backport-libbpf-preserve-errno-across-pr_warn-pr_info-pr_debug.patch new file mode 100644 index 0000000000000000000000000000000000000000..48bd8dfe3b74c33116ca341360db46367062fbb4 --- /dev/null +++ b/backport-libbpf-preserve-errno-across-pr_warn-pr_info-pr_debug.patch @@ -0,0 +1,52 @@ +From 45dca19bd2f3fff624f03e903be9241af7cb26c6 Mon Sep 17 00:00:00 2001 +From: Andrii Nakryiko +Date: Wed, 10 Aug 2022 11:34:25 -0700 +Subject: [PATCH] libbpf: preserve errno across pr_warn/pr_info/pr_debug +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +As suggested in [0], make sure that libbpf_print saves and restored +errno and as such guaranteed that no matter what actual print callback +user installs, macros like pr_warn/pr_info/pr_debug are completely +transparent as far as errno goes. + +While libbpf code is pretty careful about not clobbering important errno +values accidentally with pr_warn(), it's a trivial change to make sure +that pr_warn can be used anywhere without a risk of clobbering errno. + +No functional changes, just future proofing. + + [0] https://github.com/libbpf/libbpf/pull/536 + +Signed-off-by: Andrii Nakryiko +Acked-by: Daniel Müller +Link: https://lore.kernel.org/r/20220810183425.1998735-1-andrii@kernel.org +Signed-off-by: Alexei Starovoitov +--- + src/libbpf.c | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/src/libbpf.c b/src/libbpf.c +index f7364ea8..917d975b 100644 +--- a/src/libbpf.c ++++ b/src/libbpf.c +@@ -103,13 +103,18 @@ __printf(2, 3) + void libbpf_print(enum libbpf_print_level level, const char *format, ...) + { + va_list args; ++ int old_errno; + + if (!__libbpf_pr) + return; + ++ old_errno = errno; ++ + va_start(args, format); + __libbpf_pr(level, format, args); + va_end(args); ++ ++ errno = old_errno; + } + + static void pr_perm_msg(int err) diff --git a/libbpf.spec b/libbpf.spec index d4673d1697c7d7cd3b3c06621be7d54610ec7ff7..79cd588fd2328d384b2e8aa942bc12ae3fbb0304 100644 --- a/libbpf.spec +++ b/libbpf.spec @@ -4,7 +4,7 @@ Name: %{githubname} Version: %{githubver} -Release: 1 +Release: 2 Summary: Libbpf library License: LGPLv2 or BSD @@ -13,6 +13,9 @@ Source: https://github.com/%{githubname}/%{githubname}/archive/v%{github BuildRequires: gcc elfutils-libelf-devel elfutils-devel Patch6000: backport-libbpf-Support-detecting-and-attaching-of-writable-t.patch +Patch6001: backport-libbpf-Ensure-functions-with-always_inline-attribute-are-inline.patch +Patch6002: backport-libbpf-Fix-the-name-of-a-reused-map.patch +Patch6003: backport-libbpf-preserve-errno-across-pr_warn-pr_info-pr_debug.patch # This package supersedes libbpf from kernel-tools, # which has default Epoch: 0. By having Epoch: 1 @@ -64,6 +67,11 @@ developing applications that use %{name} %{_libdir}/libbpf.a %changelog +* Sun Jan 15 2023 zhangmingyi - 2:0.3-2 +- backporting: backport-libbpf-Ensure-functions-with-always_inline-attribute-are-inline.patch + backport-libbpf-Fix-the-name-of-a-reused-map.patch + backport-libbpf-preserve-errno-across-pr_warn-pr_info-pr_debug.patch + * Tue Aug 23 2022 hujiawang - 2:0.3-1 - updata libbpf v0.1.1 to v0.3