diff options
author | Soumya Sambu <soumya.sambu@windriver.com> | 2025-03-18 10:31:38 +0000 |
---|---|---|
committer | Khem Raj <raj.khem@gmail.com> | 2025-03-26 11:28:46 -0700 |
commit | 2b21544ca797b91f1739c965cf620c245766e309 (patch) | |
tree | 352feebce676908a3ab6c1f471c499f81f1faf1d | |
parent | 092eaa77f61f8ab6ceeb0429030d750a2618b1ab (diff) | |
download | meta-clang-2b21544ca797b91f1739c965cf620c245766e309.tar.gz |
bpftrace: Fix llvm-objcopy issue and backport libbpf patches for kirkstone-clang18kirkstone-clang18
Fix bpftrace do_configure failure for kirkstone-clang18:
| CMake Error at tests/data/CMakeLists.txt:6 (find_program):
| Could not find LLVM_OBJCOPY using the following names: llvm-objcopy,
| llvm-objcopy-18, llvm18-objcopy
This error occurs because bpftrace searches for llvm-objcopy-${LLVM_VERSION_MAJOR},
expecting llvm version 18.x, while llvm-native from oe-core provides v13.0.1.
Since clang-native provides v18.1.6, switching to it resolves the issue.
While fixing this, additional libbpf compatibility issues were identified during
bpftrace compilation, requiring backporting of multiple patches to resolve:
• Undefined BTF_KIND_ENUM64, replaced with BTF_KIND_ENUM.
• Missing kprobe_multi in bpf_link_create_opts.
• Undefined BPF_TRACE_KPROBE_MULTI.
• Undefined reference to btf_is_enum64 in libbpf.so
and other related libbpf errors
Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com>
9 files changed, 838 insertions, 2 deletions
diff --git a/dynamic-layers/openembedded-layer/recipes-devtools/bpftrace/bpftrace_0.20.1.bb b/dynamic-layers/openembedded-layer/recipes-devtools/bpftrace/bpftrace_0.20.1.bb index 355f427..1bd9150 100644 --- a/dynamic-layers/openembedded-layer/recipes-devtools/bpftrace/bpftrace_0.20.1.bb +++ b/dynamic-layers/openembedded-layer/recipes-devtools/bpftrace/bpftrace_0.20.1.bb | |||
@@ -12,7 +12,7 @@ DEPENDS += "bison-native \ | |||
12 | libcereal \ | 12 | libcereal \ |
13 | libbpf \ | 13 | libbpf \ |
14 | " | 14 | " |
15 | DEPENDS += "${@bb.utils.contains('PTEST_ENABLED', '1', 'pahole-native llvm-native', '', d)}" | 15 | DEPENDS += "${@bb.utils.contains('PTEST_ENABLED', '1', 'pahole-native clang-native', '', d)}" |
16 | 16 | ||
17 | RDEPENDS:${PN} += "bash python3 xz" | 17 | RDEPENDS:${PN} += "bash python3 xz" |
18 | 18 | ||
diff --git a/recipes-kernel/libbpf/libbpf/0001-bpf-Add-btf-enum64-support.patch b/recipes-kernel/libbpf/libbpf/0001-bpf-Add-btf-enum64-support.patch new file mode 100644 index 0000000..2c510f0 --- /dev/null +++ b/recipes-kernel/libbpf/libbpf/0001-bpf-Add-btf-enum64-support.patch | |||
@@ -0,0 +1,113 @@ | |||
1 | From 9a976c6b98de8da85341b341adb9be5b9850ad10 Mon Sep 17 00:00:00 2001 | ||
2 | From: Yonghong Song <yhs@fb.com> | ||
3 | Date: Mon, 6 Jun 2022 23:26:00 -0700 | ||
4 | Subject: [PATCH] bpf: Add btf enum64 support | ||
5 | |||
6 | Currently, BTF only supports upto 32bit enum value with BTF_KIND_ENUM. | ||
7 | But in kernel, some enum indeed has 64bit values, e.g., | ||
8 | in uapi bpf.h, we have | ||
9 | enum { | ||
10 | BPF_F_INDEX_MASK = 0xffffffffULL, | ||
11 | BPF_F_CURRENT_CPU = BPF_F_INDEX_MASK, | ||
12 | BPF_F_CTXLEN_MASK = (0xfffffULL << 32), | ||
13 | }; | ||
14 | In this case, BTF_KIND_ENUM will encode the value of BPF_F_CTXLEN_MASK | ||
15 | as 0, which certainly is incorrect. | ||
16 | |||
17 | This patch added a new btf kind, BTF_KIND_ENUM64, which permits | ||
18 | 64bit value to cover the above use case. The BTF_KIND_ENUM64 has | ||
19 | the following three fields followed by the common type: | ||
20 | struct bpf_enum64 { | ||
21 | __u32 nume_off; | ||
22 | __u32 val_lo32; | ||
23 | __u32 val_hi32; | ||
24 | }; | ||
25 | Currently, btf type section has an alignment of 4 as all element types | ||
26 | are u32. Representing the value with __u64 will introduce a pad | ||
27 | for bpf_enum64 and may also introduce misalignment for the 64bit value. | ||
28 | Hence, two members of val_hi32 and val_lo32 are chosen to avoid these issues. | ||
29 | |||
30 | The kflag is also introduced for BTF_KIND_ENUM and BTF_KIND_ENUM64 | ||
31 | to indicate whether the value is signed or unsigned. The kflag intends | ||
32 | to provide consistent output of BTF C fortmat with the original | ||
33 | source code. For example, the original BTF_KIND_ENUM bit value is 0xffffffff. | ||
34 | The format C has two choices, printing out 0xffffffff or -1 and current libbpf | ||
35 | prints out as unsigned value. But if the signedness is preserved in btf, | ||
36 | the value can be printed the same as the original source code. | ||
37 | The kflag value 0 means unsigned values, which is consistent to the default | ||
38 | by libbpf and should also cover most cases as well. | ||
39 | |||
40 | The new BTF_KIND_ENUM64 is intended to support the enum value represented as | ||
41 | 64bit value. But it can represent all BTF_KIND_ENUM values as well. | ||
42 | The compiler ([1]) and pahole will generate BTF_KIND_ENUM64 only if the value has | ||
43 | to be represented with 64 bits. | ||
44 | |||
45 | In addition, a static inline function btf_kind_core_compat() is introduced which | ||
46 | will be used later when libbpf relo_core.c changed. Here the kernel shares the | ||
47 | same relo_core.c with libbpf. | ||
48 | |||
49 | [1] https://reviews.llvm.org/D124641 | ||
50 | |||
51 | Acked-by: Andrii Nakryiko <andrii@kernel.org> | ||
52 | Signed-off-by: Yonghong Song <yhs@fb.com> | ||
53 | Link: https://lore.kernel.org/r/20220607062600.3716578-1-yhs@fb.com | ||
54 | Signed-off-by: Alexei Starovoitov <ast@kernel.org> | ||
55 | |||
56 | Upstream-Status: Backport [https://github.com/libbpf/libbpf/commit/9a976c6b98de8da85341b341adb9be5b9850ad10] | ||
57 | |||
58 | Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com> | ||
59 | --- | ||
60 | include/uapi/linux/btf.h | 17 ++++++++++++++--- | ||
61 | 1 file changed, 14 insertions(+), 3 deletions(-) | ||
62 | |||
63 | diff --git a/include/uapi/linux/btf.h b/include/uapi/linux/btf.h | ||
64 | index b0d8fea..9932126 100644 | ||
65 | --- a/include/uapi/linux/btf.h | ||
66 | +++ b/include/uapi/linux/btf.h | ||
67 | @@ -36,10 +36,10 @@ struct btf_type { | ||
68 | * bits 24-27: kind (e.g. int, ptr, array...etc) | ||
69 | * bits 28-30: unused | ||
70 | * bit 31: kind_flag, currently used by | ||
71 | - * struct, union and fwd | ||
72 | + * struct, union, enum, fwd and enum64 | ||
73 | */ | ||
74 | __u32 info; | ||
75 | - /* "size" is used by INT, ENUM, STRUCT, UNION and DATASEC. | ||
76 | + /* "size" is used by INT, ENUM, STRUCT, UNION, DATASEC and ENUM64. | ||
77 | * "size" tells the size of the type it is describing. | ||
78 | * | ||
79 | * "type" is used by PTR, TYPEDEF, VOLATILE, CONST, RESTRICT, | ||
80 | @@ -63,7 +63,7 @@ enum { | ||
81 | BTF_KIND_ARRAY = 3, /* Array */ | ||
82 | BTF_KIND_STRUCT = 4, /* Struct */ | ||
83 | BTF_KIND_UNION = 5, /* Union */ | ||
84 | - BTF_KIND_ENUM = 6, /* Enumeration */ | ||
85 | + BTF_KIND_ENUM = 6, /* Enumeration up to 32-bit values */ | ||
86 | BTF_KIND_FWD = 7, /* Forward */ | ||
87 | BTF_KIND_TYPEDEF = 8, /* Typedef */ | ||
88 | BTF_KIND_VOLATILE = 9, /* Volatile */ | ||
89 | @@ -76,6 +76,7 @@ enum { | ||
90 | BTF_KIND_FLOAT = 16, /* Floating point */ | ||
91 | BTF_KIND_DECL_TAG = 17, /* Decl Tag */ | ||
92 | BTF_KIND_TYPE_TAG = 18, /* Type Tag */ | ||
93 | + BTF_KIND_ENUM64 = 19, /* Enumeration up to 64-bit values */ | ||
94 | |||
95 | NR_BTF_KINDS, | ||
96 | BTF_KIND_MAX = NR_BTF_KINDS - 1, | ||
97 | @@ -186,4 +187,14 @@ struct btf_decl_tag { | ||
98 | __s32 component_idx; | ||
99 | }; | ||
100 | |||
101 | +/* BTF_KIND_ENUM64 is followed by multiple "struct btf_enum64". | ||
102 | + * The exact number of btf_enum64 is stored in the vlen (of the | ||
103 | + * info in "struct btf_type"). | ||
104 | + */ | ||
105 | +struct btf_enum64 { | ||
106 | + __u32 name_off; | ||
107 | + __u32 val_lo32; | ||
108 | + __u32 val_hi32; | ||
109 | +}; | ||
110 | + | ||
111 | #endif /* _UAPI__LINUX_BTF_H__ */ | ||
112 | -- | ||
113 | 2.40.0 | ||
diff --git a/recipes-kernel/libbpf/libbpf/0001-bpf-Add-cookie-support-to-programs-attached-with-kpr.patch b/recipes-kernel/libbpf/libbpf/0001-bpf-Add-cookie-support-to-programs-attached-with-kpr.patch new file mode 100644 index 0000000..3b03545 --- /dev/null +++ b/recipes-kernel/libbpf/libbpf/0001-bpf-Add-cookie-support-to-programs-attached-with-kpr.patch | |||
@@ -0,0 +1,44 @@ | |||
1 | From 50ae8c25d225c79f711e2484ccd15d9a4c228470 Mon Sep 17 00:00:00 2001 | ||
2 | From: Jiri Olsa <jolsa@kernel.org> | ||
3 | Date: Wed, 16 Mar 2022 13:24:12 +0100 | ||
4 | Subject: [PATCH] bpf: Add cookie support to programs attached with kprobe | ||
5 | multi link | ||
6 | |||
7 | Adding support to call bpf_get_attach_cookie helper from | ||
8 | kprobe programs attached with kprobe multi link. | ||
9 | |||
10 | The cookie is provided by array of u64 values, where each | ||
11 | value is paired with provided function address or symbol | ||
12 | with the same array index. | ||
13 | |||
14 | When cookie array is provided it's sorted together with | ||
15 | addresses (check bpf_kprobe_multi_cookie_swap). This way | ||
16 | we can find cookie based on the address in | ||
17 | bpf_get_attach_cookie helper. | ||
18 | |||
19 | Suggested-by: Andrii Nakryiko <andrii@kernel.org> | ||
20 | Signed-off-by: Jiri Olsa <jolsa@kernel.org> | ||
21 | Signed-off-by: Alexei Starovoitov <ast@kernel.org> | ||
22 | Link: https://lore.kernel.org/bpf/20220316122419.933957-7-jolsa@kernel.org | ||
23 | |||
24 | Upstream-Status: Backport [https://github.com/libbpf/libbpf/commit/50ae8c25d225c79f711e2484ccd15d9a4c228470] | ||
25 | |||
26 | Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com> | ||
27 | --- | ||
28 | include/uapi/linux/bpf.h | 1 + | ||
29 | 1 file changed, 1 insertion(+) | ||
30 | |||
31 | diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h | ||
32 | index 39a32fc..5413a84 100644 | ||
33 | --- a/include/uapi/linux/bpf.h | ||
34 | +++ b/include/uapi/linux/bpf.h | ||
35 | @@ -1484,6 +1484,7 @@ union bpf_attr { | ||
36 | __u32 cnt; | ||
37 | __aligned_u64 syms; | ||
38 | __aligned_u64 addrs; | ||
39 | + __aligned_u64 cookies; | ||
40 | } kprobe_multi; | ||
41 | }; | ||
42 | } link_create; | ||
43 | -- | ||
44 | 2.40.0 | ||
diff --git a/recipes-kernel/libbpf/libbpf/0001-bpf-Add-multi-kprobe-link.patch b/recipes-kernel/libbpf/libbpf/0001-bpf-Add-multi-kprobe-link.patch new file mode 100644 index 0000000..b8d6caf --- /dev/null +++ b/recipes-kernel/libbpf/libbpf/0001-bpf-Add-multi-kprobe-link.patch | |||
@@ -0,0 +1,91 @@ | |||
1 | From e85e26492d2c10029c6fe66b6d318a05fffe8b10 Mon Sep 17 00:00:00 2001 | ||
2 | From: Jiri Olsa <jolsa@kernel.org> | ||
3 | Date: Wed, 16 Mar 2022 13:24:09 +0100 | ||
4 | Subject: [PATCH] bpf: Add multi kprobe link | ||
5 | |||
6 | Adding new link type BPF_LINK_TYPE_KPROBE_MULTI that attaches kprobe | ||
7 | program through fprobe API. | ||
8 | |||
9 | The fprobe API allows to attach probe on multiple functions at once | ||
10 | very fast, because it works on top of ftrace. On the other hand this | ||
11 | limits the probe point to the function entry or return. | ||
12 | |||
13 | The kprobe program gets the same pt_regs input ctx as when it's attached | ||
14 | through the perf API. | ||
15 | |||
16 | Adding new attach type BPF_TRACE_KPROBE_MULTI that allows attachment | ||
17 | kprobe to multiple function with new link. | ||
18 | |||
19 | User provides array of addresses or symbols with count to attach the | ||
20 | kprobe program to. The new link_create uapi interface looks like: | ||
21 | |||
22 | struct { | ||
23 | __u32 flags; | ||
24 | __u32 cnt; | ||
25 | __aligned_u64 syms; | ||
26 | __aligned_u64 addrs; | ||
27 | } kprobe_multi; | ||
28 | |||
29 | The flags field allows single BPF_TRACE_KPROBE_MULTI bit to create | ||
30 | return multi kprobe. | ||
31 | |||
32 | Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> | ||
33 | Signed-off-by: Jiri Olsa <jolsa@kernel.org> | ||
34 | Signed-off-by: Alexei Starovoitov <ast@kernel.org> | ||
35 | Acked-by: Andrii Nakryiko <andrii@kernel.org> | ||
36 | Link: https://lore.kernel.org/bpf/20220316122419.933957-4-jolsa@kernel.org | ||
37 | |||
38 | Upstream-Status: Backport [https://github.com/libbpf/libbpf/commit/e85e26492d2c10029c6fe66b6d318a05fffe8b10] | ||
39 | |||
40 | Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com> | ||
41 | --- | ||
42 | include/uapi/linux/bpf.h | 13 +++++++++++++ | ||
43 | 1 file changed, 13 insertions(+) | ||
44 | |||
45 | diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h | ||
46 | index a7f0dde..39a32fc 100644 | ||
47 | --- a/include/uapi/linux/bpf.h | ||
48 | +++ b/include/uapi/linux/bpf.h | ||
49 | @@ -997,6 +997,7 @@ enum bpf_attach_type { | ||
50 | BPF_SK_REUSEPORT_SELECT, | ||
51 | BPF_SK_REUSEPORT_SELECT_OR_MIGRATE, | ||
52 | BPF_PERF_EVENT, | ||
53 | + BPF_TRACE_KPROBE_MULTI, | ||
54 | __MAX_BPF_ATTACH_TYPE | ||
55 | }; | ||
56 | |||
57 | @@ -1011,6 +1012,7 @@ enum bpf_link_type { | ||
58 | BPF_LINK_TYPE_NETNS = 5, | ||
59 | BPF_LINK_TYPE_XDP = 6, | ||
60 | BPF_LINK_TYPE_PERF_EVENT = 7, | ||
61 | + BPF_LINK_TYPE_KPROBE_MULTI = 8, | ||
62 | |||
63 | MAX_BPF_LINK_TYPE, | ||
64 | }; | ||
65 | @@ -1118,6 +1120,11 @@ enum bpf_link_type { | ||
66 | */ | ||
67 | #define BPF_F_XDP_HAS_FRAGS (1U << 5) | ||
68 | |||
69 | +/* link_create.kprobe_multi.flags used in LINK_CREATE command for | ||
70 | + * BPF_TRACE_KPROBE_MULTI attach type to create return probe. | ||
71 | + */ | ||
72 | +#define BPF_F_KPROBE_MULTI_RETURN (1U << 0) | ||
73 | + | ||
74 | /* When BPF ldimm64's insn[0].src_reg != 0 then this can have | ||
75 | * the following extensions: | ||
76 | * | ||
77 | @@ -1472,6 +1479,12 @@ union bpf_attr { | ||
78 | */ | ||
79 | __u64 bpf_cookie; | ||
80 | } perf_event; | ||
81 | + struct { | ||
82 | + __u32 flags; | ||
83 | + __u32 cnt; | ||
84 | + __aligned_u64 syms; | ||
85 | + __aligned_u64 addrs; | ||
86 | + } kprobe_multi; | ||
87 | }; | ||
88 | } link_create; | ||
89 | |||
90 | -- | ||
91 | 2.40.0 | ||
diff --git a/recipes-kernel/libbpf/libbpf/0001-libbpf-Add-bpf_link_create-support-for-multi-kprobes.patch b/recipes-kernel/libbpf/libbpf/0001-libbpf-Add-bpf_link_create-support-for-multi-kprobes.patch new file mode 100644 index 0000000..301d599 --- /dev/null +++ b/recipes-kernel/libbpf/libbpf/0001-libbpf-Add-bpf_link_create-support-for-multi-kprobes.patch | |||
@@ -0,0 +1,65 @@ | |||
1 | From 2e6e39ef809a64e0c77e7027e9231059a78677fb Mon Sep 17 00:00:00 2001 | ||
2 | From: Jiri Olsa <jolsa@kernel.org> | ||
3 | Date: Wed, 16 Mar 2022 13:24:14 +0100 | ||
4 | Subject: [PATCH] libbpf: Add bpf_link_create support for multi kprobes | ||
5 | |||
6 | Adding new kprobe_multi struct to bpf_link_create_opts object | ||
7 | to pass multiple kprobe data to link_create attr uapi. | ||
8 | |||
9 | Signed-off-by: Jiri Olsa <jolsa@kernel.org> | ||
10 | Signed-off-by: Alexei Starovoitov <ast@kernel.org> | ||
11 | Link: https://lore.kernel.org/bpf/20220316122419.933957-9-jolsa@kernel.org | ||
12 | |||
13 | Upstream-Status: Backport [https://github.com/libbpf/libbpf/commit/2e6e39ef809a64e0c77e7027e9231059a78677fb] | ||
14 | |||
15 | Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com> | ||
16 | --- | ||
17 | src/bpf.c | 9 +++++++++ | ||
18 | src/bpf.h | 9 ++++++++- | ||
19 | 2 files changed, 17 insertions(+), 1 deletion(-) | ||
20 | |||
21 | diff --git a/src/bpf.c b/src/bpf.c | ||
22 | index 7f4f4f7..9110a72 100644 | ||
23 | --- a/src/bpf.c | ||
24 | +++ b/src/bpf.c | ||
25 | @@ -853,6 +853,15 @@ int bpf_link_create(int prog_fd, int target_fd, | ||
26 | if (!OPTS_ZEROED(opts, perf_event)) | ||
27 | return libbpf_err(-EINVAL); | ||
28 | break; | ||
29 | + case BPF_TRACE_KPROBE_MULTI: | ||
30 | + attr.link_create.kprobe_multi.flags = OPTS_GET(opts, kprobe_multi.flags, 0); | ||
31 | + attr.link_create.kprobe_multi.cnt = OPTS_GET(opts, kprobe_multi.cnt, 0); | ||
32 | + attr.link_create.kprobe_multi.syms = ptr_to_u64(OPTS_GET(opts, kprobe_multi.syms, 0)); | ||
33 | + attr.link_create.kprobe_multi.addrs = ptr_to_u64(OPTS_GET(opts, kprobe_multi.addrs, 0)); | ||
34 | + attr.link_create.kprobe_multi.cookies = ptr_to_u64(OPTS_GET(opts, kprobe_multi.cookies, 0)); | ||
35 | + if (!OPTS_ZEROED(opts, kprobe_multi)) | ||
36 | + return libbpf_err(-EINVAL); | ||
37 | + break; | ||
38 | default: | ||
39 | if (!OPTS_ZEROED(opts, flags)) | ||
40 | return libbpf_err(-EINVAL); | ||
41 | diff --git a/src/bpf.h b/src/bpf.h | ||
42 | index 7e7f78e..ef6d3e2 100644 | ||
43 | --- a/src/bpf.h | ||
44 | +++ b/src/bpf.h | ||
45 | @@ -413,10 +413,17 @@ struct bpf_link_create_opts { | ||
46 | struct { | ||
47 | __u64 bpf_cookie; | ||
48 | } perf_event; | ||
49 | + struct { | ||
50 | + __u32 flags; | ||
51 | + __u32 cnt; | ||
52 | + const char **syms; | ||
53 | + const unsigned long *addrs; | ||
54 | + const __u64 *cookies; | ||
55 | + } kprobe_multi; | ||
56 | }; | ||
57 | size_t :0; | ||
58 | }; | ||
59 | -#define bpf_link_create_opts__last_field perf_event | ||
60 | +#define bpf_link_create_opts__last_field kprobe_multi.cookies | ||
61 | |||
62 | LIBBPF_API int bpf_link_create(int prog_fd, int target_fd, | ||
63 | enum bpf_attach_type attach_type, | ||
64 | -- | ||
65 | 2.40.0 | ||
diff --git a/recipes-kernel/libbpf/libbpf/0001-libbpf-Add-enum64-parsing-and-new-enum64-public-API.patch b/recipes-kernel/libbpf/libbpf/0001-libbpf-Add-enum64-parsing-and-new-enum64-public-API.patch new file mode 100644 index 0000000..055ada6 --- /dev/null +++ b/recipes-kernel/libbpf/libbpf/0001-libbpf-Add-enum64-parsing-and-new-enum64-public-API.patch | |||
@@ -0,0 +1,250 @@ | |||
1 | From c3f8eecb16ad02ebb3a41a31349f1b851cebe46b Mon Sep 17 00:00:00 2001 | ||
2 | From: Yonghong Song <yhs@fb.com> | ||
3 | Date: Mon, 6 Jun 2022 23:26:21 -0700 | ||
4 | Subject: [PATCH] libbpf: Add enum64 parsing and new enum64 public API | ||
5 | |||
6 | Add enum64 parsing support and two new enum64 public APIs: | ||
7 | btf__add_enum64 | ||
8 | btf__add_enum64_value | ||
9 | |||
10 | Also add support of signedness for BTF_KIND_ENUM. The | ||
11 | BTF_KIND_ENUM API signatures are not changed. The signedness | ||
12 | will be changed from unsigned to signed if btf__add_enum_value() | ||
13 | finds any negative values. | ||
14 | |||
15 | Acked-by: Andrii Nakryiko <andrii@kernel.org> | ||
16 | Signed-off-by: Yonghong Song <yhs@fb.com> | ||
17 | Link: https://lore.kernel.org/r/20220607062621.3719391-1-yhs@fb.com | ||
18 | Signed-off-by: Alexei Starovoitov <ast@kernel.org> | ||
19 | |||
20 | Upstream-Status: Backport [https://github.com/libbpf/libbpf/commit/c3f8eecb16ad02ebb3a41a31349f1b851cebe46b] | ||
21 | |||
22 | Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com> | ||
23 | --- | ||
24 | src/btf.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++ | ||
25 | src/btf.h | 12 ++++++ | ||
26 | src/libbpf.map | 2 + | ||
27 | 3 files changed, 117 insertions(+) | ||
28 | |||
29 | diff --git a/src/btf.c b/src/btf.c | ||
30 | index 5e0bf3c..bcaad6e 100644 | ||
31 | --- a/src/btf.c | ||
32 | +++ b/src/btf.c | ||
33 | @@ -305,6 +305,8 @@ static int btf_type_size(const struct btf_type *t) | ||
34 | return base_size + sizeof(__u32); | ||
35 | case BTF_KIND_ENUM: | ||
36 | return base_size + vlen * sizeof(struct btf_enum); | ||
37 | + case BTF_KIND_ENUM64: | ||
38 | + return base_size + vlen * sizeof(struct btf_enum64); | ||
39 | case BTF_KIND_ARRAY: | ||
40 | return base_size + sizeof(struct btf_array); | ||
41 | case BTF_KIND_STRUCT: | ||
42 | @@ -334,6 +336,7 @@ static void btf_bswap_type_base(struct btf_type *t) | ||
43 | static int btf_bswap_type_rest(struct btf_type *t) | ||
44 | { | ||
45 | struct btf_var_secinfo *v; | ||
46 | + struct btf_enum64 *e64; | ||
47 | struct btf_member *m; | ||
48 | struct btf_array *a; | ||
49 | struct btf_param *p; | ||
50 | @@ -361,6 +364,13 @@ static int btf_bswap_type_rest(struct btf_type *t) | ||
51 | e->val = bswap_32(e->val); | ||
52 | } | ||
53 | return 0; | ||
54 | + case BTF_KIND_ENUM64: | ||
55 | + for (i = 0, e64 = btf_enum64(t); i < vlen; i++, e64++) { | ||
56 | + e64->name_off = bswap_32(e64->name_off); | ||
57 | + e64->val_lo32 = bswap_32(e64->val_lo32); | ||
58 | + e64->val_hi32 = bswap_32(e64->val_hi32); | ||
59 | + } | ||
60 | + return 0; | ||
61 | case BTF_KIND_ARRAY: | ||
62 | a = btf_array(t); | ||
63 | a->type = bswap_32(a->type); | ||
64 | @@ -597,6 +607,7 @@ __s64 btf__resolve_size(const struct btf *btf, __u32 type_id) | ||
65 | case BTF_KIND_STRUCT: | ||
66 | case BTF_KIND_UNION: | ||
67 | case BTF_KIND_ENUM: | ||
68 | + case BTF_KIND_ENUM64: | ||
69 | case BTF_KIND_DATASEC: | ||
70 | case BTF_KIND_FLOAT: | ||
71 | size = t->size; | ||
72 | @@ -644,6 +655,7 @@ int btf__align_of(const struct btf *btf, __u32 id) | ||
73 | switch (kind) { | ||
74 | case BTF_KIND_INT: | ||
75 | case BTF_KIND_ENUM: | ||
76 | + case BTF_KIND_ENUM64: | ||
77 | case BTF_KIND_FLOAT: | ||
78 | return min(btf_ptr_sz(btf), (size_t)t->size); | ||
79 | case BTF_KIND_PTR: | ||
80 | @@ -2162,6 +2174,10 @@ static int btf_add_enum_common(struct btf *btf, const char *name, __u32 byte_sz, | ||
81 | */ | ||
82 | int btf__add_enum(struct btf *btf, const char *name, __u32 byte_sz) | ||
83 | { | ||
84 | + /* | ||
85 | + * set the signedness to be unsigned, it will change to signed | ||
86 | + * if any later enumerator is negative. | ||
87 | + */ | ||
88 | return btf_add_enum_common(btf, name, byte_sz, false, BTF_KIND_ENUM); | ||
89 | } | ||
90 | |||
91 | @@ -2212,6 +2228,82 @@ int btf__add_enum_value(struct btf *btf, const char *name, __s64 value) | ||
92 | t = btf_last_type(btf); | ||
93 | btf_type_inc_vlen(t); | ||
94 | |||
95 | + /* if negative value, set signedness to signed */ | ||
96 | + if (value < 0) | ||
97 | + t->info = btf_type_info(btf_kind(t), btf_vlen(t), true); | ||
98 | + | ||
99 | + btf->hdr->type_len += sz; | ||
100 | + btf->hdr->str_off += sz; | ||
101 | + return 0; | ||
102 | +} | ||
103 | + | ||
104 | +/* | ||
105 | + * Append new BTF_KIND_ENUM64 type with: | ||
106 | + * - *name* - name of the enum, can be NULL or empty for anonymous enums; | ||
107 | + * - *byte_sz* - size of the enum, in bytes. | ||
108 | + * - *is_signed* - whether the enum values are signed or not; | ||
109 | + * | ||
110 | + * Enum initially has no enum values in it (and corresponds to enum forward | ||
111 | + * declaration). Enumerator values can be added by btf__add_enum64_value() | ||
112 | + * immediately after btf__add_enum64() succeeds. | ||
113 | + * | ||
114 | + * Returns: | ||
115 | + * - >0, type ID of newly added BTF type; | ||
116 | + * - <0, on error. | ||
117 | + */ | ||
118 | +int btf__add_enum64(struct btf *btf, const char *name, __u32 byte_sz, | ||
119 | + bool is_signed) | ||
120 | +{ | ||
121 | + return btf_add_enum_common(btf, name, byte_sz, is_signed, | ||
122 | + BTF_KIND_ENUM64); | ||
123 | +} | ||
124 | + | ||
125 | +/* | ||
126 | + * Append new enum value for the current ENUM64 type with: | ||
127 | + * - *name* - name of the enumerator value, can't be NULL or empty; | ||
128 | + * - *value* - integer value corresponding to enum value *name*; | ||
129 | + * Returns: | ||
130 | + * - 0, on success; | ||
131 | + * - <0, on error. | ||
132 | + */ | ||
133 | +int btf__add_enum64_value(struct btf *btf, const char *name, __u64 value) | ||
134 | +{ | ||
135 | + struct btf_enum64 *v; | ||
136 | + struct btf_type *t; | ||
137 | + int sz, name_off; | ||
138 | + | ||
139 | + /* last type should be BTF_KIND_ENUM64 */ | ||
140 | + if (btf->nr_types == 0) | ||
141 | + return libbpf_err(-EINVAL); | ||
142 | + t = btf_last_type(btf); | ||
143 | + if (!btf_is_enum64(t)) | ||
144 | + return libbpf_err(-EINVAL); | ||
145 | + | ||
146 | + /* non-empty name */ | ||
147 | + if (!name || !name[0]) | ||
148 | + return libbpf_err(-EINVAL); | ||
149 | + | ||
150 | + /* decompose and invalidate raw data */ | ||
151 | + if (btf_ensure_modifiable(btf)) | ||
152 | + return libbpf_err(-ENOMEM); | ||
153 | + | ||
154 | + sz = sizeof(struct btf_enum64); | ||
155 | + v = btf_add_type_mem(btf, sz); | ||
156 | + if (!v) | ||
157 | + return libbpf_err(-ENOMEM); | ||
158 | + | ||
159 | + name_off = btf__add_str(btf, name); | ||
160 | + if (name_off < 0) | ||
161 | + return name_off; | ||
162 | + | ||
163 | + v->name_off = name_off; | ||
164 | + v->val_lo32 = (__u32)value; | ||
165 | + v->val_hi32 = value >> 32; | ||
166 | + | ||
167 | + /* update parent type's vlen */ | ||
168 | + t = btf_last_type(btf); | ||
169 | + btf_type_inc_vlen(t); | ||
170 | + | ||
171 | btf->hdr->type_len += sz; | ||
172 | btf->hdr->str_off += sz; | ||
173 | return 0; | ||
174 | @@ -4720,6 +4812,7 @@ int btf_type_visit_type_ids(struct btf_type *t, type_id_visit_fn visit, void *ct | ||
175 | case BTF_KIND_INT: | ||
176 | case BTF_KIND_FLOAT: | ||
177 | case BTF_KIND_ENUM: | ||
178 | + case BTF_KIND_ENUM64: | ||
179 | return 0; | ||
180 | |||
181 | case BTF_KIND_FWD: | ||
182 | @@ -4814,6 +4907,16 @@ int btf_type_visit_str_offs(struct btf_type *t, str_off_visit_fn visit, void *ct | ||
183 | } | ||
184 | break; | ||
185 | } | ||
186 | + case BTF_KIND_ENUM64: { | ||
187 | + struct btf_enum64 *m = btf_enum64(t); | ||
188 | + | ||
189 | + for (i = 0, n = btf_vlen(t); i < n; i++, m++) { | ||
190 | + err = visit(&m->name_off, ctx); | ||
191 | + if (err) | ||
192 | + return err; | ||
193 | + } | ||
194 | + break; | ||
195 | + } | ||
196 | case BTF_KIND_FUNC_PROTO: { | ||
197 | struct btf_param *m = btf_params(t); | ||
198 | |||
199 | diff --git a/src/btf.h b/src/btf.h | ||
200 | index bddc4b3..2dc963c 100644 | ||
201 | --- a/src/btf.h | ||
202 | +++ b/src/btf.h | ||
203 | @@ -215,6 +215,8 @@ LIBBPF_API int btf__add_field(struct btf *btf, const char *name, int field_type_ | ||
204 | /* enum construction APIs */ | ||
205 | LIBBPF_API int btf__add_enum(struct btf *btf, const char *name, __u32 bytes_sz); | ||
206 | LIBBPF_API int btf__add_enum_value(struct btf *btf, const char *name, __s64 value); | ||
207 | +LIBBPF_API int btf__add_enum64(struct btf *btf, const char *name, __u32 bytes_sz, bool is_signed); | ||
208 | +LIBBPF_API int btf__add_enum64_value(struct btf *btf, const char *name, __u64 value); | ||
209 | |||
210 | enum btf_fwd_kind { | ||
211 | BTF_FWD_STRUCT = 0, | ||
212 | @@ -455,6 +457,11 @@ static inline bool btf_is_enum(const struct btf_type *t) | ||
213 | return btf_kind(t) == BTF_KIND_ENUM; | ||
214 | } | ||
215 | |||
216 | +static inline bool btf_is_enum64(const struct btf_type *t) | ||
217 | +{ | ||
218 | + return btf_kind(t) == BTF_KIND_ENUM64; | ||
219 | +} | ||
220 | + | ||
221 | static inline bool btf_is_fwd(const struct btf_type *t) | ||
222 | { | ||
223 | return btf_kind(t) == BTF_KIND_FWD; | ||
224 | @@ -555,6 +562,11 @@ static inline struct btf_member *btf_members(const struct btf_type *t) | ||
225 | return (struct btf_member *)(t + 1); | ||
226 | } | ||
227 | |||
228 | +static inline struct btf_enum64 *btf_enum64(const struct btf_type *t) | ||
229 | +{ | ||
230 | + return (struct btf_enum64 *)(t + 1); | ||
231 | +} | ||
232 | + | ||
233 | /* Get bit offset of a member with specified index. */ | ||
234 | static inline __u32 btf_member_bit_offset(const struct btf_type *t, | ||
235 | __u32 member_idx) | ||
236 | diff --git a/src/libbpf.map b/src/libbpf.map | ||
237 | index c2df7aa..3f44c1d 100644 | ||
238 | --- a/src/libbpf.map | ||
239 | +++ b/src/libbpf.map | ||
240 | @@ -423,6 +423,8 @@ LIBBPF_0.6.0 { | ||
241 | |||
242 | LIBBPF_0.7.0 { | ||
243 | global: | ||
244 | + btf__add_enum64; | ||
245 | + btf__add_enum64_value; | ||
246 | bpf_btf_load; | ||
247 | bpf_program__expected_attach_type; | ||
248 | bpf_program__log_buf; | ||
249 | -- | ||
250 | 2.40.0 | ||
diff --git a/recipes-kernel/libbpf/libbpf/0001-libbpf-Add-enum64-sanitization.patch b/recipes-kernel/libbpf/libbpf/0001-libbpf-Add-enum64-sanitization.patch new file mode 100644 index 0000000..e13e0d3 --- /dev/null +++ b/recipes-kernel/libbpf/libbpf/0001-libbpf-Add-enum64-sanitization.patch | |||
@@ -0,0 +1,183 @@ | |||
1 | From a945df2439020ca182513b6e2f24175cbf2a2dc4 Mon Sep 17 00:00:00 2001 | ||
2 | From: Yonghong Song <yhs@fb.com> | ||
3 | Date: Mon, 6 Jun 2022 23:26:36 -0700 | ||
4 | Subject: [PATCH] libbpf: Add enum64 sanitization | ||
5 | |||
6 | When old kernel does not support enum64 but user space btf | ||
7 | contains non-zero enum kflag or enum64, libbpf needs to | ||
8 | do proper sanitization so modified btf can be accepted | ||
9 | by the kernel. | ||
10 | |||
11 | Sanitization for enum kflag can be achieved by clearing | ||
12 | the kflag bit. For enum64, the type is replaced with an | ||
13 | union of integer member types and the integer member size | ||
14 | must be smaller than enum64 size. If such an integer | ||
15 | type cannot be found, a new type is created and used | ||
16 | for union members. | ||
17 | |||
18 | Acked-by: Andrii Nakryiko <andrii@kernel.org> | ||
19 | Signed-off-by: Yonghong Song <yhs@fb.com> | ||
20 | Link: https://lore.kernel.org/r/20220607062636.3721375-1-yhs@fb.com | ||
21 | Signed-off-by: Alexei Starovoitov <ast@kernel.org> | ||
22 | |||
23 | Upstream-Status: Backport [https://github.com/libbpf/libbpf/commit/a945df2439020ca182513b6e2f24175cbf2a2dc4] | ||
24 | |||
25 | Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com> | ||
26 | --- | ||
27 | src/btf.h | 3 ++- | ||
28 | src/libbpf.c | 56 +++++++++++++++++++++++++++++++++++++++---- | ||
29 | src/libbpf_internal.h | 2 ++ | ||
30 | 3 files changed, 56 insertions(+), 5 deletions(-) | ||
31 | |||
32 | diff --git a/src/btf.h b/src/btf.h | ||
33 | index 951ac74..bddc4b3 100644 | ||
34 | --- a/src/btf.h | ||
35 | +++ b/src/btf.h | ||
36 | @@ -393,9 +393,10 @@ btf_dump__dump_type_data(struct btf_dump *d, __u32 id, | ||
37 | #ifndef BTF_KIND_FLOAT | ||
38 | #define BTF_KIND_FLOAT 16 /* Floating point */ | ||
39 | #endif | ||
40 | -/* The kernel header switched to enums, so these two were never #defined */ | ||
41 | +/* The kernel header switched to enums, so the following were never #defined */ | ||
42 | #define BTF_KIND_DECL_TAG 17 /* Decl Tag */ | ||
43 | #define BTF_KIND_TYPE_TAG 18 /* Type Tag */ | ||
44 | +#define BTF_KIND_ENUM64 19 /* Enum for up-to 64bit values */ | ||
45 | |||
46 | static inline __u16 btf_kind(const struct btf_type *t) | ||
47 | { | ||
48 | diff --git a/src/libbpf.c b/src/libbpf.c | ||
49 | index 2262bcd..5321025 100644 | ||
50 | --- a/src/libbpf.c | ||
51 | +++ b/src/libbpf.c | ||
52 | @@ -2110,6 +2110,7 @@ static const char *__btf_kind_str(__u16 kind) | ||
53 | case BTF_KIND_FLOAT: return "float"; | ||
54 | case BTF_KIND_DECL_TAG: return "decl_tag"; | ||
55 | case BTF_KIND_TYPE_TAG: return "type_tag"; | ||
56 | + case BTF_KIND_ENUM64: return "enum64"; | ||
57 | default: return "unknown"; | ||
58 | } | ||
59 | } | ||
60 | @@ -2634,12 +2635,13 @@ static bool btf_needs_sanitization(struct bpf_object *obj) | ||
61 | bool has_func = kernel_supports(obj, FEAT_BTF_FUNC); | ||
62 | bool has_decl_tag = kernel_supports(obj, FEAT_BTF_DECL_TAG); | ||
63 | bool has_type_tag = kernel_supports(obj, FEAT_BTF_TYPE_TAG); | ||
64 | + bool has_enum64 = kernel_supports(obj, FEAT_BTF_ENUM64); | ||
65 | |||
66 | return !has_func || !has_datasec || !has_func_global || !has_float || | ||
67 | - !has_decl_tag || !has_type_tag; | ||
68 | + !has_decl_tag || !has_type_tag || !has_enum64; | ||
69 | } | ||
70 | |||
71 | -static void bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf) | ||
72 | +static int bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf) | ||
73 | { | ||
74 | bool has_func_global = kernel_supports(obj, FEAT_BTF_GLOBAL_FUNC); | ||
75 | bool has_datasec = kernel_supports(obj, FEAT_BTF_DATASEC); | ||
76 | @@ -2647,6 +2649,8 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf) | ||
77 | bool has_func = kernel_supports(obj, FEAT_BTF_FUNC); | ||
78 | bool has_decl_tag = kernel_supports(obj, FEAT_BTF_DECL_TAG); | ||
79 | bool has_type_tag = kernel_supports(obj, FEAT_BTF_TYPE_TAG); | ||
80 | + bool has_enum64 = kernel_supports(obj, FEAT_BTF_ENUM64); | ||
81 | + __u32 enum64_placeholder_id = 0; | ||
82 | struct btf_type *t; | ||
83 | int i, j, vlen; | ||
84 | |||
85 | @@ -2709,8 +2713,32 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj, struct btf *btf) | ||
86 | /* replace TYPE_TAG with a CONST */ | ||
87 | t->name_off = 0; | ||
88 | t->info = BTF_INFO_ENC(BTF_KIND_CONST, 0, 0); | ||
89 | - } | ||
90 | + } else if (!has_enum64 && btf_is_enum(t)) { | ||
91 | + /* clear the kflag */ | ||
92 | + t->info = btf_type_info(btf_kind(t), btf_vlen(t), false); | ||
93 | + } else if (!has_enum64 && btf_is_enum64(t)) { | ||
94 | + /* replace ENUM64 with a union */ | ||
95 | + struct btf_member *m; | ||
96 | + | ||
97 | + if (enum64_placeholder_id == 0) { | ||
98 | + enum64_placeholder_id = btf__add_int(btf, "enum64_placeholder", 1, 0); | ||
99 | + if (enum64_placeholder_id < 0) | ||
100 | + return enum64_placeholder_id; | ||
101 | + | ||
102 | + t = (struct btf_type *)btf__type_by_id(btf, i); | ||
103 | + } | ||
104 | + | ||
105 | + m = btf_members(t); | ||
106 | + vlen = btf_vlen(t); | ||
107 | + t->info = BTF_INFO_ENC(BTF_KIND_UNION, 0, vlen); | ||
108 | + for (j = 0; j < vlen; j++, m++) { | ||
109 | + m->type = enum64_placeholder_id; | ||
110 | + m->offset = 0; | ||
111 | + } | ||
112 | + } | ||
113 | } | ||
114 | + | ||
115 | + return 0; | ||
116 | } | ||
117 | |||
118 | static bool libbpf_needs_btf(const struct bpf_object *obj) | ||
119 | @@ -3008,7 +3036,9 @@ static int bpf_object__sanitize_and_load_btf(struct bpf_object *obj) | ||
120 | |||
121 | /* enforce 8-byte pointers for BPF-targeted BTFs */ | ||
122 | btf__set_pointer_size(obj->btf, 8); | ||
123 | - bpf_object__sanitize_btf(obj, kern_btf); | ||
124 | + err = bpf_object__sanitize_btf(obj, kern_btf); | ||
125 | + if (err) | ||
126 | + return err; | ||
127 | } | ||
128 | |||
129 | if (obj->gen_loader) { | ||
130 | @@ -3515,6 +3545,10 @@ static enum kcfg_type find_kcfg_type(const struct btf *btf, int id, | ||
131 | if (strcmp(name, "libbpf_tristate")) | ||
132 | return KCFG_UNKNOWN; | ||
133 | return KCFG_TRISTATE; | ||
134 | + case BTF_KIND_ENUM64: | ||
135 | + if (strcmp(name, "libbpf_tristate")) | ||
136 | + return KCFG_UNKNOWN; | ||
137 | + return KCFG_TRISTATE; | ||
138 | case BTF_KIND_ARRAY: | ||
139 | if (btf_array(t)->nelems == 0) | ||
140 | return KCFG_UNKNOWN; | ||
141 | @@ -4662,6 +4696,17 @@ static int probe_perf_link(void) | ||
142 | return link_fd < 0 && err == -EBADF; | ||
143 | } | ||
144 | |||
145 | +static int probe_kern_btf_enum64(void) | ||
146 | +{ | ||
147 | + static const char strs[] = "\0enum64"; | ||
148 | + __u32 types[] = { | ||
149 | + BTF_TYPE_ENC(1, BTF_INFO_ENC(BTF_KIND_ENUM64, 0, 0), 8), | ||
150 | + }; | ||
151 | + | ||
152 | + return probe_fd(libbpf__load_raw_btf((char *)types, sizeof(types), | ||
153 | + strs, sizeof(strs))); | ||
154 | +} | ||
155 | + | ||
156 | enum kern_feature_result { | ||
157 | FEAT_UNKNOWN = 0, | ||
158 | FEAT_SUPPORTED = 1, | ||
159 | @@ -4724,6 +4769,9 @@ static struct kern_feature_desc { | ||
160 | [FEAT_MEMCG_ACCOUNT] = { | ||
161 | "memcg-based memory accounting", probe_memcg_account, | ||
162 | }, | ||
163 | + [FEAT_BTF_ENUM64] = { | ||
164 | + "BTF_KIND_ENUM64 support", probe_kern_btf_enum64, | ||
165 | + }, | ||
166 | }; | ||
167 | |||
168 | bool kernel_supports(const struct bpf_object *obj, enum kern_feature_id feat_id) | ||
169 | diff --git a/src/libbpf_internal.h b/src/libbpf_internal.h | ||
170 | index bc86b82..2b72531 100644 | ||
171 | --- a/src/libbpf_internal.h | ||
172 | +++ b/src/libbpf_internal.h | ||
173 | @@ -329,6 +329,8 @@ enum kern_feature_id { | ||
174 | FEAT_BTF_TYPE_TAG, | ||
175 | /* memcg-based accounting for BPF maps and progs */ | ||
176 | FEAT_MEMCG_ACCOUNT, | ||
177 | + /* BTF_KIND_ENUM64 support and BTF_KIND_ENUM kflag support */ | ||
178 | + FEAT_BTF_ENUM64, | ||
179 | __FEAT_CNT, | ||
180 | }; | ||
181 | |||
182 | -- | ||
183 | 2.40.0 | ||
diff --git a/recipes-kernel/libbpf/libbpf/0001-libbpf-Refactor-btf__add_enum-for-future-code-sharin.patch b/recipes-kernel/libbpf/libbpf/0001-libbpf-Refactor-btf__add_enum-for-future-code-sharin.patch new file mode 100644 index 0000000..8bb1787 --- /dev/null +++ b/recipes-kernel/libbpf/libbpf/0001-libbpf-Refactor-btf__add_enum-for-future-code-sharin.patch | |||
@@ -0,0 +1,83 @@ | |||
1 | From 25fd7a1cf58f79db2bd84c6a9de9457107f1ed21 Mon Sep 17 00:00:00 2001 | ||
2 | From: Yonghong Song <yhs@fb.com> | ||
3 | Date: Mon, 6 Jun 2022 23:26:15 -0700 | ||
4 | Subject: [PATCH] libbpf: Refactor btf__add_enum() for future code sharing | ||
5 | |||
6 | Refactor btf__add_enum() function to create a separate | ||
7 | function btf_add_enum_common() so later the common function | ||
8 | can be used to add enum64 btf type. There is no functionality | ||
9 | change for this patch. | ||
10 | |||
11 | Acked-by: Andrii Nakryiko <andrii@kernel.org> | ||
12 | Signed-off-by: Yonghong Song <yhs@fb.com> | ||
13 | Link: https://lore.kernel.org/r/20220607062615.3718063-1-yhs@fb.com | ||
14 | Signed-off-by: Alexei Starovoitov <ast@kernel.org> | ||
15 | |||
16 | Upstream-Status: Backport [https://github.com/libbpf/libbpf/commit/25fd7a1cf58f79db2bd84c6a9de9457107f1ed21] | ||
17 | |||
18 | Signed-off-by: Soumya Sambu <soumya.sambu@windriver.com> | ||
19 | --- | ||
20 | src/btf.c | 36 +++++++++++++++++++++--------------- | ||
21 | 1 file changed, 21 insertions(+), 15 deletions(-) | ||
22 | |||
23 | diff --git a/src/btf.c b/src/btf.c | ||
24 | index 1383e26..5e0bf3c 100644 | ||
25 | --- a/src/btf.c | ||
26 | +++ b/src/btf.c | ||
27 | @@ -2115,20 +2115,8 @@ int btf__add_field(struct btf *btf, const char *name, int type_id, | ||
28 | return 0; | ||
29 | } | ||
30 | |||
31 | -/* | ||
32 | - * Append new BTF_KIND_ENUM type with: | ||
33 | - * - *name* - name of the enum, can be NULL or empty for anonymous enums; | ||
34 | - * - *byte_sz* - size of the enum, in bytes. | ||
35 | - * | ||
36 | - * Enum initially has no enum values in it (and corresponds to enum forward | ||
37 | - * declaration). Enumerator values can be added by btf__add_enum_value() | ||
38 | - * immediately after btf__add_enum() succeeds. | ||
39 | - * | ||
40 | - * Returns: | ||
41 | - * - >0, type ID of newly added BTF type; | ||
42 | - * - <0, on error. | ||
43 | - */ | ||
44 | -int btf__add_enum(struct btf *btf, const char *name, __u32 byte_sz) | ||
45 | +static int btf_add_enum_common(struct btf *btf, const char *name, __u32 byte_sz, | ||
46 | + bool is_signed, __u8 kind) | ||
47 | { | ||
48 | struct btf_type *t; | ||
49 | int sz, name_off = 0; | ||
50 | @@ -2153,12 +2141,30 @@ int btf__add_enum(struct btf *btf, const char *name, __u32 byte_sz) | ||
51 | |||
52 | /* start out with vlen=0; it will be adjusted when adding enum values */ | ||
53 | t->name_off = name_off; | ||
54 | - t->info = btf_type_info(BTF_KIND_ENUM, 0, 0); | ||
55 | + t->info = btf_type_info(kind, 0, is_signed); | ||
56 | t->size = byte_sz; | ||
57 | |||
58 | return btf_commit_type(btf, sz); | ||
59 | } | ||
60 | |||
61 | +/* | ||
62 | + * Append new BTF_KIND_ENUM type with: | ||
63 | + * - *name* - name of the enum, can be NULL or empty for anonymous enums; | ||
64 | + * - *byte_sz* - size of the enum, in bytes. | ||
65 | + * | ||
66 | + * Enum initially has no enum values in it (and corresponds to enum forward | ||
67 | + * declaration). Enumerator values can be added by btf__add_enum_value() | ||
68 | + * immediately after btf__add_enum() succeeds. | ||
69 | + * | ||
70 | + * Returns: | ||
71 | + * - >0, type ID of newly added BTF type; | ||
72 | + * - <0, on error. | ||
73 | + */ | ||
74 | +int btf__add_enum(struct btf *btf, const char *name, __u32 byte_sz) | ||
75 | +{ | ||
76 | + return btf_add_enum_common(btf, name, byte_sz, false, BTF_KIND_ENUM); | ||
77 | +} | ||
78 | + | ||
79 | /* | ||
80 | * Append new enum value for the current ENUM type with: | ||
81 | * - *name* - name of the enumerator value, can't be NULL or empty; | ||
82 | -- | ||
83 | 2.40.0 | ||
diff --git a/recipes-kernel/libbpf/libbpf_%.bbappend b/recipes-kernel/libbpf/libbpf_%.bbappend index b5a6319..2a17de5 100644 --- a/recipes-kernel/libbpf/libbpf_%.bbappend +++ b/recipes-kernel/libbpf/libbpf_%.bbappend | |||
@@ -3,7 +3,14 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/libbpf:" | |||
3 | LIC_FILES_CHKSUM = "file://LICENSE.LGPL-2.1;md5=b370887980db5dd40659b50909238dbd" | 3 | LIC_FILES_CHKSUM = "file://LICENSE.LGPL-2.1;md5=b370887980db5dd40659b50909238dbd" |
4 | 4 | ||
5 | SRC_URI += "\ | 5 | SRC_URI += "\ |
6 | file://0001-libbpf-Introduce-bpf_-btf-link-map-prog-_get_info_by.patch" | 6 | file://0001-libbpf-Introduce-bpf_-btf-link-map-prog-_get_info_by.patch \ |
7 | file://0001-bpf-Add-multi-kprobe-link.patch \ | ||
8 | file://0001-libbpf-Add-bpf_link_create-support-for-multi-kprobes.patch \ | ||
9 | file://0001-bpf-Add-btf-enum64-support.patch \ | ||
10 | file://0001-bpf-Add-cookie-support-to-programs-attached-with-kpr.patch \ | ||
11 | file://0001-libbpf-Add-enum64-sanitization.patch \ | ||
12 | file://0001-libbpf-Refactor-btf__add_enum-for-future-code-sharin.patch \ | ||
13 | file://0001-libbpf-Add-enum64-parsing-and-new-enum64-public-API.patch" | ||
7 | 14 | ||
8 | S = "${WORKDIR}/git" | 15 | S = "${WORKDIR}/git" |
9 | 16 | ||