summaryrefslogtreecommitdiffstats
path: root/tools/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/bitmap.c4
-rw-r--r--tools/lib/bpf/libbpf.c32
-rw-r--r--tools/lib/bpf/libbpf_internal.h4
-rw-r--r--tools/lib/bpf/libbpf_probes.c13
4 files changed, 27 insertions, 26 deletions
diff --git a/tools/lib/bitmap.c b/tools/lib/bitmap.c
index 38748b0e342f..38494782be06 100644
--- a/tools/lib/bitmap.c
+++ b/tools/lib/bitmap.c
@@ -1,9 +1,7 @@
1// SPDX-License-Identifier: GPL-2.0-only
1/* 2/*
2 * From lib/bitmap.c 3 * From lib/bitmap.c
3 * Helper functions for bitmap.h. 4 * Helper functions for bitmap.h.
4 *
5 * This source code is licensed under the GNU General Public License,
6 * Version 2. See the file COPYING for more details.
7 */ 5 */
8#include <linux/bitmap.h> 6#include <linux/bitmap.h>
9 7
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 197b574406b3..151f7ac1882e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1645,14 +1645,16 @@ static int bpf_object__probe_btf_func(struct bpf_object *obj)
1645 /* FUNC x */ /* [3] */ 1645 /* FUNC x */ /* [3] */
1646 BTF_TYPE_ENC(5, BTF_INFO_ENC(BTF_KIND_FUNC, 0, 0), 2), 1646 BTF_TYPE_ENC(5, BTF_INFO_ENC(BTF_KIND_FUNC, 0, 0), 2),
1647 }; 1647 };
1648 int res; 1648 int btf_fd;
1649 1649
1650 res = libbpf__probe_raw_btf((char *)types, sizeof(types), 1650 btf_fd = libbpf__load_raw_btf((char *)types, sizeof(types),
1651 strs, sizeof(strs)); 1651 strs, sizeof(strs));
1652 if (res < 0) 1652 if (btf_fd >= 0) {
1653 return res;
1654 if (res > 0)
1655 obj->caps.btf_func = 1; 1653 obj->caps.btf_func = 1;
1654 close(btf_fd);
1655 return 1;
1656 }
1657
1656 return 0; 1658 return 0;
1657} 1659}
1658 1660
@@ -1670,14 +1672,16 @@ static int bpf_object__probe_btf_datasec(struct bpf_object *obj)
1670 BTF_TYPE_ENC(3, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4), 1672 BTF_TYPE_ENC(3, BTF_INFO_ENC(BTF_KIND_DATASEC, 0, 1), 4),
1671 BTF_VAR_SECINFO_ENC(2, 0, 4), 1673 BTF_VAR_SECINFO_ENC(2, 0, 4),
1672 }; 1674 };
1673 int res; 1675 int btf_fd;
1674 1676
1675 res = libbpf__probe_raw_btf((char *)types, sizeof(types), 1677 btf_fd = libbpf__load_raw_btf((char *)types, sizeof(types),
1676 strs, sizeof(strs)); 1678 strs, sizeof(strs));
1677 if (res < 0) 1679 if (btf_fd >= 0) {
1678 return res;
1679 if (res > 0)
1680 obj->caps.btf_datasec = 1; 1680 obj->caps.btf_datasec = 1;
1681 close(btf_fd);
1682 return 1;
1683 }
1684
1681 return 0; 1685 return 0;
1682} 1686}
1683 1687
@@ -3206,6 +3210,10 @@ static const struct {
3206 BPF_CGROUP_UDP4_SENDMSG), 3210 BPF_CGROUP_UDP4_SENDMSG),
3207 BPF_EAPROG_SEC("cgroup/sendmsg6", BPF_PROG_TYPE_CGROUP_SOCK_ADDR, 3211 BPF_EAPROG_SEC("cgroup/sendmsg6", BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
3208 BPF_CGROUP_UDP6_SENDMSG), 3212 BPF_CGROUP_UDP6_SENDMSG),
3213 BPF_EAPROG_SEC("cgroup/recvmsg4", BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
3214 BPF_CGROUP_UDP4_RECVMSG),
3215 BPF_EAPROG_SEC("cgroup/recvmsg6", BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
3216 BPF_CGROUP_UDP6_RECVMSG),
3209 BPF_EAPROG_SEC("cgroup/sysctl", BPF_PROG_TYPE_CGROUP_SYSCTL, 3217 BPF_EAPROG_SEC("cgroup/sysctl", BPF_PROG_TYPE_CGROUP_SYSCTL,
3210 BPF_CGROUP_SYSCTL), 3218 BPF_CGROUP_SYSCTL),
3211}; 3219};
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index f3025b4d90e1..dfab8012185c 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -34,7 +34,7 @@ do { \
34#define pr_info(fmt, ...) __pr(LIBBPF_INFO, fmt, ##__VA_ARGS__) 34#define pr_info(fmt, ...) __pr(LIBBPF_INFO, fmt, ##__VA_ARGS__)
35#define pr_debug(fmt, ...) __pr(LIBBPF_DEBUG, fmt, ##__VA_ARGS__) 35#define pr_debug(fmt, ...) __pr(LIBBPF_DEBUG, fmt, ##__VA_ARGS__)
36 36
37int libbpf__probe_raw_btf(const char *raw_types, size_t types_len, 37int libbpf__load_raw_btf(const char *raw_types, size_t types_len,
38 const char *str_sec, size_t str_len); 38 const char *str_sec, size_t str_len);
39 39
40#endif /* __LIBBPF_LIBBPF_INTERNAL_H */ 40#endif /* __LIBBPF_LIBBPF_INTERNAL_H */
diff --git a/tools/lib/bpf/libbpf_probes.c b/tools/lib/bpf/libbpf_probes.c
index 5e2aa83f637a..6635a31a7a16 100644
--- a/tools/lib/bpf/libbpf_probes.c
+++ b/tools/lib/bpf/libbpf_probes.c
@@ -133,8 +133,8 @@ bool bpf_probe_prog_type(enum bpf_prog_type prog_type, __u32 ifindex)
133 return errno != EINVAL && errno != EOPNOTSUPP; 133 return errno != EINVAL && errno != EOPNOTSUPP;
134} 134}
135 135
136int libbpf__probe_raw_btf(const char *raw_types, size_t types_len, 136int libbpf__load_raw_btf(const char *raw_types, size_t types_len,
137 const char *str_sec, size_t str_len) 137 const char *str_sec, size_t str_len)
138{ 138{
139 struct btf_header hdr = { 139 struct btf_header hdr = {
140 .magic = BTF_MAGIC, 140 .magic = BTF_MAGIC,
@@ -157,14 +157,9 @@ int libbpf__probe_raw_btf(const char *raw_types, size_t types_len,
157 memcpy(raw_btf + hdr.hdr_len + hdr.type_len, str_sec, hdr.str_len); 157 memcpy(raw_btf + hdr.hdr_len + hdr.type_len, str_sec, hdr.str_len);
158 158
159 btf_fd = bpf_load_btf(raw_btf, btf_len, NULL, 0, false); 159 btf_fd = bpf_load_btf(raw_btf, btf_len, NULL, 0, false);
160 if (btf_fd < 0) {
161 free(raw_btf);
162 return 0;
163 }
164 160
165 close(btf_fd);
166 free(raw_btf); 161 free(raw_btf);
167 return 1; 162 return btf_fd;
168} 163}
169 164
170static int load_sk_storage_btf(void) 165static int load_sk_storage_btf(void)
@@ -190,7 +185,7 @@ static int load_sk_storage_btf(void)
190 BTF_MEMBER_ENC(23, 2, 32),/* struct bpf_spin_lock l; */ 185 BTF_MEMBER_ENC(23, 2, 32),/* struct bpf_spin_lock l; */
191 }; 186 };
192 187
193 return libbpf__probe_raw_btf((char *)types, sizeof(types), 188 return libbpf__load_raw_btf((char *)types, sizeof(types),
194 strs, sizeof(strs)); 189 strs, sizeof(strs));
195} 190}
196 191