aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf/libbpf.c
diff options
context:
space:
mode:
authorMichal Rostecki <mrostecki@opensuse.org>2019-05-29 14:31:09 -0400
committerAlexei Starovoitov <ast@kernel.org>2019-05-31 20:03:39 -0400
commitcfd4921049269ee6765b4a1cb820b95d0df5dda5 (patch)
tree7c5a15cd500f3fd35f8357672f97fd0ab8b0e74e /tools/lib/bpf/libbpf.c
parent5fac1718e706d94a7078addee9075cfaea00ca8c (diff)
libbpf: Return btf_fd for load_sk_storage_btf
Before this change, function load_sk_storage_btf expected that libbpf__probe_raw_btf was returning a BTF descriptor, but in fact it was returning an information about whether the probe was successful (0 or 1). load_sk_storage_btf was using that value as an argument of the close function, which was resulting in closing stdout and thus terminating the process which called that function. That bug was visible in bpftool. `bpftool feature` subcommand was always exiting too early (because of closed stdout) and it didn't display all requested probes. `bpftool -j feature` or `bpftool -p feature` were not returning a valid json object. This change renames the libbpf__probe_raw_btf function to libbpf__load_raw_btf, which now returns a BTF descriptor, as expected in load_sk_storage_btf. v2: - Fix typo in the commit message. v3: - Simplify BTF descriptor handling in bpf_object__probe_btf_* functions. - Rename libbpf__probe_raw_btf function to libbpf__load_raw_btf and return a BTF descriptor. v4: - Fix typo in the commit message. Fixes: d7c4b3980c18 ("libbpf: detect supported kernel BTF features and sanitize BTF") Signed-off-by: Michal Rostecki <mrostecki@opensuse.org> Acked-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r--tools/lib/bpf/libbpf.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 197b574406b3..5d046cc7b207 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